@lace-cloud/host 0.18.0 → 0.19.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/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
+ import { MessageBridge } from '@lace-cloud/proto';
2
+ export { Diagnostic, EngineProtocolMismatchError } from '@lace-cloud/proto';
1
3
  import * as grpc from '@grpc/grpc-js';
2
- import { Metadata, Client, ServiceError, ClientUnaryCall, CallOptions, ClientReadableStream, ChannelCredentials, ClientOptions } from '@grpc/grpc-js';
3
- import { MessageBridge, Diagnostic as Diagnostic$1 } from '@lace-cloud/proto';
4
- export { Diagnostic } from '@lace-cloud/proto';
4
+ import { Metadata, ServiceError, Client, ClientUnaryCall, CallOptions, ClientReadableStream, ChannelCredentials, ClientOptions } from '@grpc/grpc-js';
5
5
  import { ChildProcess } from 'node:child_process';
6
6
  import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
7
7
  import { EventEmitter } from 'node:events';
@@ -13,7 +13,7 @@ type LiveCall = {
13
13
  type EngineStreamCall = LiveCall & {
14
14
  on(event: 'data', listener: (event: unknown) => void): unknown;
15
15
  on(event: 'end', listener: () => void): unknown;
16
- on(event: 'error', listener: (err: Error) => void): unknown;
16
+ on(event: 'error', listener: (err: ServiceError) => void): unknown;
17
17
  };
18
18
  /**
19
19
  * The subset of `LaceTransport` the bridge forwards through: the two
@@ -23,7 +23,7 @@ type EngineStreamCall = LiveCall & {
23
23
  */
24
24
  type EngineTransport = {
25
25
  readonly client: {
26
- makeUnaryRequest(method: string, serialize: (value: unknown) => Buffer, deserialize: (value: Buffer) => unknown, argument: unknown, metadata: Metadata, callback: (error: Error | null, response?: unknown) => void): unknown;
26
+ makeUnaryRequest(method: string, serialize: (value: unknown) => Buffer, deserialize: (value: Buffer) => unknown, argument: unknown, metadata: Metadata, callback: (error: ServiceError | null, response?: unknown) => void): unknown;
27
27
  makeServerStreamRequest(method: string, serialize: (value: unknown) => Buffer, deserialize: (value: Buffer) => unknown, argument: unknown, metadata: Metadata): EngineStreamCall;
28
28
  };
29
29
  metadata(): Metadata;
@@ -40,6 +40,15 @@ type EngineHandshake = {
40
40
  port: number;
41
41
  token: string;
42
42
  };
43
+ type EngineInitialize = {
44
+ serverVersion: string;
45
+ protocolVersion: string;
46
+ commandPaths: readonly string[];
47
+ };
48
+ type EngineCredential = {
49
+ apiKey: string;
50
+ apiBaseUrl: string;
51
+ };
43
52
  type ServerState = 'stopped' | 'starting' | 'running' | 'error';
44
53
 
45
54
  /**
@@ -49,11 +58,214 @@ type ServerState = 'stopped' | 'starting' | 'running' | 'error';
49
58
  * LACE_ENGINE_PORT=<port>
50
59
  * LACE_ENGINE_TOKEN=<64 hex chars>
51
60
  * LACE_ENGINE_READY
61
+ *
62
+ * The engine's stdin is a pipe whose write end this process owns, and its
63
+ * lifetime is the engine's lifetime: the engine reads it and shuts down at end
64
+ * of file, so a spawner that dies — even by SIGKILL — takes its engine with it
65
+ * when the kernel closes the pipe. This module never ends the pipe on its own;
66
+ * the owner ends it through `endEngine` when the engine should stop, and only
67
+ * then, so the engine's own shutdown runs before any signal is sent.
52
68
  */
53
69
  declare function spawnEngine(binaryPath: string, log: (msg: string) => void): Promise<{
54
70
  process: ChildProcess;
55
71
  handshake: EngineHandshake;
56
72
  }>;
73
+ /**
74
+ * End an engine spawned by `spawnEngine`: close its stdin, which is the
75
+ * engine's signal to shut down and exit on its own, and resolve once it has.
76
+ * A signal is sent only to an engine still running after `graceMs`.
77
+ */
78
+ declare function endEngine(proc: ChildProcess, graceMs?: number): Promise<void>;
79
+
80
+ /**
81
+ * `Any` contains an arbitrary serialized protocol buffer message along with a
82
+ * URL that describes the type of the serialized message.
83
+ *
84
+ * Protobuf library provides support to pack/unpack Any values in the form
85
+ * of utility functions or additional generated methods of the Any type.
86
+ *
87
+ * Example 1: Pack and unpack a message in C++.
88
+ *
89
+ * Foo foo = ...;
90
+ * Any any;
91
+ * any.PackFrom(foo);
92
+ * ...
93
+ * if (any.UnpackTo(&foo)) {
94
+ * ...
95
+ * }
96
+ *
97
+ * Example 2: Pack and unpack a message in Java.
98
+ *
99
+ * Foo foo = ...;
100
+ * Any any = Any.pack(foo);
101
+ * ...
102
+ * if (any.is(Foo.class)) {
103
+ * foo = any.unpack(Foo.class);
104
+ * }
105
+ * // or ...
106
+ * if (any.isSameTypeAs(Foo.getDefaultInstance())) {
107
+ * foo = any.unpack(Foo.getDefaultInstance());
108
+ * }
109
+ *
110
+ * Example 3: Pack and unpack a message in Python.
111
+ *
112
+ * foo = Foo(...)
113
+ * any = Any()
114
+ * any.Pack(foo)
115
+ * ...
116
+ * if any.Is(Foo.DESCRIPTOR):
117
+ * any.Unpack(foo)
118
+ * ...
119
+ *
120
+ * Example 4: Pack and unpack a message in Go
121
+ *
122
+ * foo := &pb.Foo{...}
123
+ * any, err := anypb.New(foo)
124
+ * if err != nil {
125
+ * ...
126
+ * }
127
+ * ...
128
+ * foo := &pb.Foo{}
129
+ * if err := any.UnmarshalTo(foo); err != nil {
130
+ * ...
131
+ * }
132
+ *
133
+ * The pack methods provided by protobuf library will by default use
134
+ * 'type.googleapis.com/full.type.name' as the type URL and the unpack
135
+ * methods only use the fully qualified type name after the last '/'
136
+ * in the type URL, for example "foo.bar.com/x/y.z" will yield type
137
+ * name "y.z".
138
+ *
139
+ * JSON
140
+ * ====
141
+ * The JSON representation of an `Any` value uses the regular
142
+ * representation of the deserialized, embedded message, with an
143
+ * additional field `@type` which contains the type URL. Example:
144
+ *
145
+ * package google.profile;
146
+ * message Person {
147
+ * string first_name = 1;
148
+ * string last_name = 2;
149
+ * }
150
+ *
151
+ * {
152
+ * "@type": "type.googleapis.com/google.profile.Person",
153
+ * "firstName": <string>,
154
+ * "lastName": <string>
155
+ * }
156
+ *
157
+ * If the embedded message type is well-known and has a custom JSON
158
+ * representation, that representation will be embedded adding a field
159
+ * `value` which holds the custom JSON in addition to the `@type`
160
+ * field. Example (for message [google.protobuf.Duration][]):
161
+ *
162
+ * {
163
+ * "@type": "type.googleapis.com/google.protobuf.Duration",
164
+ * "value": "1.212s"
165
+ * }
166
+ */
167
+ interface Any {
168
+ /**
169
+ * A URL/resource name that uniquely identifies the type of the serialized
170
+ * protocol buffer message. This string must contain at least
171
+ * one "/" character. The last segment of the URL's path must represent
172
+ * the fully qualified name of the type (as in
173
+ * `path/google.protobuf.Duration`). The name should be in a canonical form
174
+ * (e.g., leading "." is not accepted).
175
+ *
176
+ * In practice, teams usually precompile into the binary all types that they
177
+ * expect it to use in the context of Any. However, for URLs which use the
178
+ * scheme `http`, `https`, or no scheme, one can optionally set up a type
179
+ * server that maps type URLs to message definitions as follows:
180
+ *
181
+ * * If no scheme is provided, `https` is assumed.
182
+ * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
183
+ * value in binary format, or produce an error.
184
+ * * Applications are allowed to cache lookup results based on the
185
+ * URL, or have them precompiled into a binary to avoid any
186
+ * lookup. Therefore, binary compatibility needs to be preserved
187
+ * on changes to types. (Use versioned type names to manage
188
+ * breaking changes.)
189
+ *
190
+ * Note: this functionality is not currently available in the official
191
+ * protobuf release, and it is not used for type URLs beginning with
192
+ * type.googleapis.com. As of May 2023, there are no widely used type server
193
+ * implementations and no plans to implement one.
194
+ *
195
+ * Schemes other than `http`, `https` (or the empty scheme) might be
196
+ * used with implementation specific semantics.
197
+ */
198
+ type_url: string;
199
+ /** Must be a valid serialized protocol buffer of the above specified type. */
200
+ value: Buffer;
201
+ }
202
+ declare const Any: MessageFns$4<Any>;
203
+ type Builtin$4 = Date | Function | Uint8Array | string | number | boolean | undefined;
204
+ type DeepPartial$4<T> = T extends Builtin$4 ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial$4<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial$4<U>> : T extends {} ? {
205
+ [K in keyof T]?: DeepPartial$4<T[K]>;
206
+ } : Partial<T>;
207
+ type KeysOfUnion$4<T> = T extends T ? keyof T : never;
208
+ type Exact$4<P, I extends P> = P extends Builtin$4 ? P : P & {
209
+ [K in keyof P]: Exact$4<P[K], I[K]>;
210
+ } & {
211
+ [K in Exclude<keyof I, KeysOfUnion$4<P>>]: never;
212
+ };
213
+ interface MessageFns$4<T> {
214
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
215
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
216
+ fromJSON(object: any): T;
217
+ toJSON(message: T): unknown;
218
+ create<I extends Exact$4<DeepPartial$4<T>, I>>(base?: I): T;
219
+ fromPartial<I extends Exact$4<DeepPartial$4<T>, I>>(object: I): T;
220
+ }
221
+
222
+ /**
223
+ * The `Status` type defines a logical error model that is suitable for
224
+ * different programming environments, including REST APIs and RPC APIs. It is
225
+ * used by [gRPC](https://github.com/grpc). Each `Status` message contains
226
+ * three pieces of data: error code, error message, and error details.
227
+ *
228
+ * You can find out more about this error model and how to work with it in the
229
+ * [API Design Guide](https://cloud.google.com/apis/design/errors).
230
+ */
231
+ interface Status {
232
+ /**
233
+ * The status code, which should be an enum value of
234
+ * [google.rpc.Code][google.rpc.Code].
235
+ */
236
+ code: number;
237
+ /**
238
+ * A developer-facing error message, which should be in English. Any
239
+ * user-facing error message should be localized and sent in the
240
+ * [google.rpc.Status.details][google.rpc.Status.details] field, or localized
241
+ * by the client.
242
+ */
243
+ message: string;
244
+ /**
245
+ * A list of messages that carry the error details. There is a common set of
246
+ * message types for APIs to use.
247
+ */
248
+ details: Any[];
249
+ }
250
+ declare const Status: MessageFns$3<Status>;
251
+ type Builtin$3 = Date | Function | Uint8Array | string | number | boolean | undefined;
252
+ type DeepPartial$3<T> = T extends Builtin$3 ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial$3<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial$3<U>> : T extends {} ? {
253
+ [K in keyof T]?: DeepPartial$3<T[K]>;
254
+ } : Partial<T>;
255
+ type KeysOfUnion$3<T> = T extends T ? keyof T : never;
256
+ type Exact$3<P, I extends P> = P extends Builtin$3 ? P : P & {
257
+ [K in keyof P]: Exact$3<P[K], I[K]>;
258
+ } & {
259
+ [K in Exclude<keyof I, KeysOfUnion$3<P>>]: never;
260
+ };
261
+ interface MessageFns$3<T> {
262
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
263
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
264
+ fromJSON(object: any): T;
265
+ toJSON(message: T): unknown;
266
+ create<I extends Exact$3<DeepPartial$3<T>, I>>(base?: I): T;
267
+ fromPartial<I extends Exact$3<DeepPartial$3<T>, I>>(object: I): T;
268
+ }
57
269
 
58
270
  /**
59
271
  * A generic empty message that you can re-use to avoid defining duplicated
@@ -87,6 +299,11 @@ interface MessageFns$2<T> {
87
299
  }
88
300
 
89
301
  interface Bundle {
302
+ /**
303
+ * The format of this encoding: "2.0", at which every Expression carries
304
+ * the module references the engine read from it. The engine writes every
305
+ * Bundle at it; an encoding of an earlier version carries none.
306
+ */
90
307
  schema_version: string;
91
308
  kind: string;
92
309
  entry: string;
@@ -239,8 +456,33 @@ declare const OutputRef: MessageFns$1<OutputRef>;
239
456
  interface Expression {
240
457
  lang: string;
241
458
  value: string;
459
+ /**
460
+ * The module calls `value` reads, in source order: what the engine's
461
+ * one reader of references reads from the parse of `value`. The engine
462
+ * fills them each time it encodes an Expression and reads none back, so
463
+ * a consumer takes a reference from here and never from `value`.
464
+ */
465
+ module_references: ModuleReference[];
242
466
  }
243
467
  declare const Expression: MessageFns$1<Expression>;
468
+ /** ModuleReference is one module.<call> an expression reads. */
469
+ interface ModuleReference {
470
+ /** The call read: module.<call>. */
471
+ call: string;
472
+ /**
473
+ * The output read off the call: the first attribute after the call and
474
+ * any instance key in the text, module.<call>.<output> or
475
+ * module.<call>[0].<output>. Unset when the reference reads the whole
476
+ * call: module.<call> alone, through a splat, or by a key an expression
477
+ * computes.
478
+ */
479
+ output?: string | undefined;
480
+ /** An instance key follows the call: [0], ["k"] or [<expression>]. */
481
+ instance_key: boolean;
482
+ /** A splat follows the call or its instance key: [*] or .*. */
483
+ splat: boolean;
484
+ }
485
+ declare const ModuleReference: MessageFns$1<ModuleReference>;
244
486
  interface TerraformBlock {
245
487
  required_version: string;
246
488
  required_providers: {
@@ -307,19 +549,116 @@ declare enum DiagnosticSeverity {
307
549
  DIAGNOSTIC_SEVERITY_INFO = 3,
308
550
  UNRECOGNIZED = -1
309
551
  }
552
+ /**
553
+ * Reason is the one vocabulary of what a failure asks of the developer.
554
+ * The engine attaches it to a refused RPC as a `ReasonDetail` in the
555
+ * status' error details, and a command's failure document names it; a
556
+ * client branches on it, never on the message's text. A failure the API
557
+ * decided carries the API's own code (`ReasonDetail.api_code`), and a
558
+ * reason only where that code has one: every code that asks the developer
559
+ * to sign in again is `REASON_UNAUTHENTICATED`.
560
+ */
561
+ declare enum Reason {
562
+ REASON_UNSPECIFIED = 0,
563
+ /** REASON_NOT_LACE_FORM - Placement: the resolved tree's own certification verdict is not Lace-form. */
564
+ REASON_NOT_LACE_FORM = 1,
565
+ /** REASON_HASH_MISMATCH - Placement: the downloaded tree does not hash to what the registry vouched for. */
566
+ REASON_HASH_MISMATCH = 2,
567
+ /** REASON_REGISTRY_UNAVAILABLE - Placement: the registry could not be reached or answered with no verdict. */
568
+ REASON_REGISTRY_UNAVAILABLE = 3,
569
+ /** REASON_ROOT_LOCKED - SessionOpen: the root's canvas is open in another window. */
570
+ REASON_ROOT_LOCKED = 4,
571
+ /** REASON_UNSAVED - Generate: the session has unsaved edits; save first. */
572
+ REASON_UNSAVED = 5,
573
+ /** REASON_CONFLICT - Generate: the tree moved under the session's base; Keep or Reload first. */
574
+ REASON_CONFLICT = 6,
575
+ /**
576
+ * REASON_SOURCE_REFUSED - Every mutation, save and generate: the session's source tf is refused.
577
+ * module convert and stack import: the tree's tf does not parse, has a
578
+ * non-empty residual report, or its Bundle fails its own validation.
579
+ * stack apply / stack destroy / registry register: a source in the stack
580
+ * does not read, checked before the certification.
581
+ */
582
+ REASON_SOURCE_REFUSED = 7,
583
+ /**
584
+ * REASON_NOT_GIT_REPOSITORY - Generate, module convert, stack import and module fmt: the authoring
585
+ * root is not inside a git working tree.
586
+ */
587
+ REASON_NOT_GIT_REPOSITORY = 8,
588
+ /** REASON_GENERATE_IN_PROGRESS - Generate: a Generate is already running on the session. */
589
+ REASON_GENERATE_IN_PROGRESS = 9,
590
+ /** REASON_NO_ORGANIZATION - A scoped command: no organization is selected. */
591
+ REASON_NO_ORGANIZATION = 10,
592
+ /** REASON_NO_TEAM - A team-scoped command: no team is selected in the organization. */
593
+ REASON_NO_TEAM = 11,
594
+ /**
595
+ * REASON_NO_CERTIFICATION - stack apply / stack destroy / registry register: the root has no
596
+ * certification.
597
+ */
598
+ REASON_NO_CERTIFICATION = 12,
599
+ /**
600
+ * REASON_STALE_CERTIFICATION - stack apply / stack destroy / registry register: the certification
601
+ * does not certify the tree on disk — the tree changed since validate,
602
+ * another lace version wrote it, or its files are torn or mixed from two
603
+ * validates. Running validate again replaces it.
604
+ */
605
+ REASON_STALE_CERTIFICATION = 13,
606
+ /**
607
+ * REASON_TOOL_MISSING - module scan / module docs / module fmt / module validate / module
608
+ * convert / stack import / stack preview: the tool the command runs
609
+ * (tfsec, terraform-docs, the pinned terraform) is not available. convert
610
+ * and stack import run the pinned terraform through the validate each
611
+ * closes on.
612
+ */
613
+ REASON_TOOL_MISSING = 14,
614
+ /**
615
+ * REASON_CROSS_SCOPE - ApplyAction: a wire whose source and target are owned by different
616
+ * modules crosses a group's boundary, which no single-scope edit makes.
617
+ * It is a refusal of the batch's content, carried on its GraphError.
618
+ */
619
+ REASON_CROSS_SCOPE = 15,
620
+ /**
621
+ * REASON_UNAUTHENTICATED - The developer must sign in: a command or a placement that needs
622
+ * credentials finds none (no `lace login`, no LACE_TOKEN), decided
623
+ * before any request; or the API refuses the ones sent with its code
624
+ * `unauthenticated`, which `ReasonDetail.api_code` then names.
625
+ */
626
+ REASON_UNAUTHENTICATED = 16,
627
+ UNRECOGNIZED = -1
628
+ }
310
629
  declare enum ConflictChoice {
311
630
  CONFLICT_CHOICE_UNSPECIFIED = 0,
312
631
  CONFLICT_CHOICE_KEEP = 1,
313
632
  CONFLICT_CHOICE_RELOAD = 2,
314
633
  UNRECOGNIZED = -1
315
634
  }
635
+ /**
636
+ * ReasonDetail rides a refused RPC's status as its one error detail:
637
+ * `grpc-status-details-bin` over gRPC, `details[]` over Connect. A
638
+ * failure Lace decided sets `reason`; one the API decided sets `api_code`
639
+ * to the API's own closed code, passed through unchanged, with the status
640
+ * code that HTTP status maps to, and `reason` where that code has one
641
+ * (`REASON_UNAUTHENTICATED` for the API's `unauthenticated`).
642
+ */
643
+ interface ReasonDetail {
644
+ reason: Reason;
645
+ api_code: string;
646
+ }
647
+ declare const ReasonDetail: MessageFns<ReasonDetail>;
316
648
  interface InitializeRequest {
317
649
  client_version: string;
650
+ /**
651
+ * The protocol version the client speaks: the decimal of
652
+ * PROTOCOL_VERSION_CURRENT as the client was built with it. The engine
653
+ * refuses any other value than its own with FAILED_PRECONDITION, naming
654
+ * both.
655
+ */
318
656
  protocol_version: string;
319
657
  }
320
658
  declare const InitializeRequest: MessageFns<InitializeRequest>;
321
659
  interface InitializeResponse {
322
660
  server_version: string;
661
+ /** the decimal of PROTOCOL_VERSION_CURRENT as the engine was built with it */
323
662
  protocol_version: string;
324
663
  supported_protocols: string[];
325
664
  /** space-joined paths of the non-hidden command tree */
@@ -330,6 +669,13 @@ interface ShutdownResponse {
330
669
  status: string;
331
670
  }
332
671
  declare const ShutdownResponse: MessageFns<ShutdownResponse>;
672
+ interface ReadCredentialResponse {
673
+ /** empty when signed out */
674
+ api_key: string;
675
+ /** the API the engine's own commands call */
676
+ api_base_url: string;
677
+ }
678
+ declare const ReadCredentialResponse: MessageFns<ReadCredentialResponse>;
333
679
  interface SessionOpenRequest {
334
680
  ephemeral?: EphemeralSession | undefined;
335
681
  root?: RootSession | undefined;
@@ -360,6 +706,13 @@ interface SessionSaveRequest {
360
706
  }
361
707
  declare const SessionSaveRequest: MessageFns<SessionSaveRequest>;
362
708
  interface SessionSaveResponse {
709
+ /**
710
+ * The revision of the state the save left: the `BundleState.revision`
711
+ * of the frame that carries it, or the session's current revision when
712
+ * nothing was unsaved. A subscriber holds the save once it has received
713
+ * a frame at this revision or a later one.
714
+ */
715
+ revision: number;
363
716
  }
364
717
  declare const SessionSaveResponse: MessageFns<SessionSaveResponse>;
365
718
  interface SessionCloseRequest {
@@ -372,12 +725,25 @@ interface SessionCloseResponse {
372
725
  declare const SessionCloseResponse: MessageFns<SessionCloseResponse>;
373
726
  interface SessionGenerateRequest {
374
727
  session_id: string;
728
+ /**
729
+ * Client-chosen, unique per engine connection, as `invoke_id` is:
730
+ * required, and an id still live is AlreadyExists. Every generate event
731
+ * this call publishes carries it.
732
+ */
733
+ generate_id: string;
375
734
  }
376
735
  declare const SessionGenerateRequest: MessageFns<SessionGenerateRequest>;
377
736
  interface SessionGenerateResponse {
378
737
  files_written: string[];
379
738
  /** the `module validate -o json` document for the written tree */
380
739
  validate_json: string;
740
+ /**
741
+ * The revision of the state the Generate left: the
742
+ * `BundleState.revision` of the frame that carries it, or the session's
743
+ * current revision when it changed nothing. A subscriber holds the
744
+ * Generate once it has received a frame at this revision or a later one.
745
+ */
746
+ revision: number;
381
747
  }
382
748
  declare const SessionGenerateResponse: MessageFns<SessionGenerateResponse>;
383
749
  interface SessionResolveConflictRequest {
@@ -402,23 +768,51 @@ interface Diagnostic {
402
768
  module_key: string;
403
769
  instance_id: string;
404
770
  input_name: string;
771
+ /**
772
+ * The rule the finding breaks, when its source names one: a workspace
773
+ * rule's code, a scan's rule id. Empty for a finding with no rule.
774
+ */
775
+ code: string;
405
776
  }
406
777
  declare const Diagnostic: MessageFns<Diagnostic>;
778
+ /**
779
+ * ConnectAction wires `source`'s output to `target`'s input. A wire is an
780
+ * edit of one module: `scope` owns the target and `source_scope` owns the
781
+ * source, both required, and a wire whose two scopes differ crosses a
782
+ * group's boundary: the batch is refused (`success=false`) with a
783
+ * GraphError carrying `REASON_CROSS_SCOPE`.
784
+ */
407
785
  interface ConnectAction {
408
786
  source: string;
409
787
  target: string;
410
788
  source_output: string;
411
789
  target_input: string;
790
+ scope: string;
791
+ source_scope: string;
412
792
  }
413
793
  declare const ConnectAction: MessageFns<ConnectAction>;
794
+ /**
795
+ * AutoConnectAction wires `source` to `target` by the engine's matching
796
+ * rules, as one batch entry: every output of `source` is scored against
797
+ * every required input of `target` that has no binding
798
+ * (`WiringCandidate.score`), and the pairs are taken from the highest
799
+ * score down, each output and each input wired at most once. Pairs that
800
+ * tie at one score for an input or an output they share are not wired,
801
+ * nor is any port they name: they come back in `BundleApplyResult.ties`
802
+ * for the caller to choose between. A pair of instances with no scored
803
+ * pair at all is refused. Its two scopes are a ConnectAction's.
804
+ */
414
805
  interface AutoConnectAction {
415
806
  source: string;
416
807
  target: string;
808
+ scope: string;
809
+ source_scope: string;
417
810
  }
418
811
  declare const AutoConnectAction: MessageFns<AutoConnectAction>;
419
812
  interface DisconnectAction {
420
813
  target: string;
421
814
  input_name: string;
815
+ scope: string;
422
816
  }
423
817
  declare const DisconnectAction: MessageFns<DisconnectAction>;
424
818
  interface UpdateInputAction {
@@ -428,11 +822,13 @@ interface UpdateInputAction {
428
822
  value: any | undefined;
429
823
  variable: string;
430
824
  expression: string;
825
+ scope: string;
431
826
  }
432
827
  declare const UpdateInputAction: MessageFns<UpdateInputAction>;
433
828
  interface UpdateAllInputsAction {
434
829
  instance_id: string;
435
830
  inputs: InputEntry[];
831
+ scope: string;
436
832
  }
437
833
  declare const UpdateAllInputsAction: MessageFns<UpdateAllInputsAction>;
438
834
  interface InputEntry {
@@ -446,14 +842,17 @@ declare const InputEntry: MessageFns<InputEntry>;
446
842
  interface RenameInstanceAction {
447
843
  old_id: string;
448
844
  new_id: string;
845
+ scope: string;
449
846
  }
450
847
  declare const RenameInstanceAction: MessageFns<RenameInstanceAction>;
451
848
  interface DeleteInstanceAction {
452
849
  instance_id: string;
850
+ scope: string;
453
851
  }
454
852
  declare const DeleteInstanceAction: MessageFns<DeleteInstanceAction>;
455
853
  interface CopyInstancesAction {
456
854
  instance_ids: string[];
855
+ scope: string;
457
856
  }
458
857
  declare const CopyInstancesAction: MessageFns<CopyInstancesAction>;
459
858
  /**
@@ -464,15 +863,17 @@ declare const CopyInstancesAction: MessageFns<CopyInstancesAction>;
464
863
  */
465
864
  interface CreateGroupAction {
466
865
  node_ids: string[];
866
+ scope: string;
467
867
  }
468
868
  declare const CreateGroupAction: MessageFns<CreateGroupAction>;
469
869
  /**
470
- * UngroupAction dissolves the group `group_id` in the current scope: its
471
- * Use is removed and the module it pointed at has its children promoted
472
- * into the parent. Mirrors workspace.UngroupAction.
870
+ * UngroupAction dissolves the group `group_id` in `scope`: its Use is
871
+ * removed and the module it pointed at has its children promoted into
872
+ * the parent. Mirrors workspace.UngroupAction.
473
873
  */
474
874
  interface UngroupAction {
475
875
  group_id: string;
876
+ scope: string;
476
877
  }
477
878
  declare const UngroupAction: MessageFns<UngroupAction>;
478
879
  interface SetVariablesAction {
@@ -515,6 +916,7 @@ declare const LocalEntry: MessageFns<LocalEntry>;
515
916
  interface SetDependsOnAction {
516
917
  instance_id: string;
517
918
  depends_on: string[];
919
+ scope: string;
518
920
  }
519
921
  declare const SetDependsOnAction: MessageFns<SetDependsOnAction>;
520
922
  /**
@@ -528,6 +930,7 @@ interface SetUseProvidersAction {
528
930
  providers: {
529
931
  [key: string]: string;
530
932
  };
933
+ scope: string;
531
934
  }
532
935
  declare const SetUseProvidersAction: MessageFns<SetUseProvidersAction>;
533
936
  /**
@@ -584,15 +987,63 @@ interface ApplyActionRequest {
584
987
  actions: Action[];
585
988
  }
586
989
  declare const ApplyActionRequest: MessageFns<ApplyActionRequest>;
990
+ /**
991
+ * WiringCandidate is one output → input pair the matcher scores between
992
+ * two instances of one module: `source_instance`'s `output` could feed
993
+ * `target_instance`'s `input`, a required input with no binding. `score`
994
+ * is the matcher's: 100 for the same name, 90 for the same last
995
+ * `_`-separated word, 50 when one name contains the other, 30 for the
996
+ * same type alone; a pair that scores nothing is no candidate.
997
+ */
998
+ interface WiringCandidate {
999
+ source_instance: string;
1000
+ output: string;
1001
+ target_instance: string;
1002
+ input: string;
1003
+ score: number;
1004
+ }
1005
+ declare const WiringCandidate: MessageFns<WiringCandidate>;
1006
+ interface ReadWiringCandidatesRequest {
1007
+ session_id: string;
1008
+ /** The key of the module whose instances are matched (an action's `scope`). */
1009
+ scope: string;
1010
+ /**
1011
+ * Narrows the pairs to those reading this instance's outputs; unset,
1012
+ * every instance of the scope is a source.
1013
+ */
1014
+ source_instance?: string | undefined;
1015
+ /**
1016
+ * Narrows the pairs to those feeding this instance's inputs; unset,
1017
+ * every instance of the scope is a target.
1018
+ */
1019
+ target_instance?: string | undefined;
1020
+ }
1021
+ declare const ReadWiringCandidatesRequest: MessageFns<ReadWiringCandidatesRequest>;
1022
+ interface ReadWiringCandidatesResponse {
1023
+ /**
1024
+ * Highest score first; equal scores in source instance, output, target
1025
+ * instance, input order.
1026
+ */
1027
+ candidates: WiringCandidate[];
1028
+ }
1029
+ declare const ReadWiringCandidatesResponse: MessageFns<ReadWiringCandidatesResponse>;
587
1030
  interface InvokeRequest {
588
1031
  /** client-chosen, unique per engine connection */
589
1032
  invoke_id: string;
590
- /** empty ⇒ sessionless: Workspace commands exit 2 "requires a canvas session" */
591
- session_id: string;
592
1033
  /** e.g. ["stack","preview"] */
593
1034
  path: string[];
594
1035
  /** positionals + flags from toArgv; never -o/--output */
595
1036
  argv: string[];
1037
+ /**
1038
+ * The absolute directory the command runs in, as a terminal invocation
1039
+ * has one: every relative path argument resolves against it. Required,
1040
+ * and it must name an existing directory. The engine picks the
1041
+ * Workspace: the session's own when its pool holds a root session open
1042
+ * on this directory, whatever spelling names it, else the disk
1043
+ * Workspace a terminal invocation builds. A command that reads no
1044
+ * directory is sent with the developer's home.
1045
+ */
1046
+ working_directory: string;
596
1047
  }
597
1048
  declare const InvokeRequest: MessageFns<InvokeRequest>;
598
1049
  interface InvokeEvent {
@@ -604,6 +1055,15 @@ interface InvokeExit {
604
1055
  code: number;
605
1056
  /** tail ≤ 8 KiB */
606
1057
  stderr_tail: string;
1058
+ /**
1059
+ * The command's final document, as its `CommandResult` carries it: the
1060
+ * last JSON document the command wrote to stdout, compact. A failed
1061
+ * command's is its failure document, `{reason, message}` plus the
1062
+ * fields its reason carries; a client tells a failure from a result by
1063
+ * the document's own shape and never reads `stderr_tail` for why. Empty
1064
+ * when the command wrote none.
1065
+ */
1066
+ document: string;
607
1067
  }
608
1068
  declare const InvokeExit: MessageFns<InvokeExit>;
609
1069
  interface CancelInvokeRequest {
@@ -621,12 +1081,16 @@ declare const SubscribeRequest: MessageFns<SubscribeRequest>;
621
1081
  interface GenerateProgress {
622
1082
  stage: string;
623
1083
  message: string;
1084
+ /** the Generate this event belongs to */
1085
+ generate_id: string;
624
1086
  }
625
1087
  declare const GenerateProgress: MessageFns<GenerateProgress>;
626
1088
  interface GenerateSuccess {
627
1089
  files_written: string[];
628
1090
  /** the `module validate -o json` document for the written tree */
629
1091
  validate_json: string;
1092
+ /** the Generate this event belongs to */
1093
+ generate_id: string;
630
1094
  }
631
1095
  declare const GenerateSuccess: MessageFns<GenerateSuccess>;
632
1096
  interface GenerateError {
@@ -637,6 +1101,14 @@ interface GenerateError {
637
1101
  * precondition check or its pre-write re-walk.
638
1102
  */
639
1103
  conflict: Conflict | undefined;
1104
+ /** the Generate this event belongs to */
1105
+ generate_id: string;
1106
+ /**
1107
+ * Why the Generate was refused, the same reason its failed call carries
1108
+ * in its status' error details; unspecified for a failure with no entry
1109
+ * in the vocabulary.
1110
+ */
1111
+ reason: Reason;
640
1112
  }
641
1113
  declare const GenerateError: MessageFns<GenerateError>;
642
1114
  interface Conflict {
@@ -644,16 +1116,40 @@ interface Conflict {
644
1116
  tree_hash: string;
645
1117
  }
646
1118
  declare const Conflict: MessageFns<Conflict>;
1119
+ /**
1120
+ * CommandResult is the result of one command that ran in a session's
1121
+ * root: every `Invoke` whose working directory resolved to a session
1122
+ * publishes exactly one to that session's subscribers when the command
1123
+ * exits, and one whose working directory resolved to no session publishes
1124
+ * nothing. The engine has no knowledge of which command it was: the event
1125
+ * is the path, the exit code and the final document, whatever the
1126
+ * command. The session keeps the last one per path, and a subscriber that
1127
+ * joins later receives the kept set after its first state.
1128
+ */
1129
+ interface CommandResult {
1130
+ /** space-joined, as `command_paths` names it, e.g. "module validate" */
1131
+ path: string;
1132
+ exit_code: number;
1133
+ /**
1134
+ * The last JSON document the command wrote to stdout, compact: a
1135
+ * command that streams NDJSON publishes its closing document and none
1136
+ * of the lines before it. Empty when the command wrote none.
1137
+ */
1138
+ document: string;
1139
+ }
1140
+ declare const CommandResult: MessageFns<CommandResult>;
647
1141
  /**
648
1142
  * BundleStateEvent is the element yielded by the Subscribe stream. Every
649
- * session-state change publishes a full BundleState; generate events pass
650
- * through as their own cases.
1143
+ * session-state change publishes a full BundleState; generate events and
1144
+ * command results pass through as their own cases. Conflict, unsaved,
1145
+ * ungenerated and the tree hash ride on BundleState.
651
1146
  */
652
1147
  interface BundleStateEvent {
653
1148
  state?: BundleState | undefined;
654
1149
  generate_progress?: GenerateProgress | undefined;
655
1150
  generate_success?: GenerateSuccess | undefined;
656
1151
  generate_error?: GenerateError | undefined;
1152
+ command_result?: CommandResult | undefined;
657
1153
  }
658
1154
  declare const BundleStateEvent: MessageFns<BundleStateEvent>;
659
1155
  /**
@@ -695,12 +1191,28 @@ interface BundleState {
695
1191
  ungenerated: boolean;
696
1192
  /**
697
1193
  * True when the source tf this session opened, or last observed live,
698
- * is refused (unparsable or a Lossless refusal). The engine refuses
1194
+ * is refused (unparsable or lossy). The engine refuses
699
1195
  * every mutation while this holds — edit, undo, redo, save, generate,
700
1196
  * and SessionResolveConflict's Keep/Reload alike — until a live tf
701
1197
  * change parses and clears it.
702
1198
  */
703
1199
  source_refused: boolean;
1200
+ /**
1201
+ * The hash of the root's tree as the session last observed it: the
1202
+ * same hash `module validate` reports as `treeHash`, so a client tells
1203
+ * whether the tree moved since a report by comparing the two. Empty
1204
+ * for an ephemeral session, and for a tree that cannot be hashed.
1205
+ */
1206
+ tree_hash: string;
1207
+ /**
1208
+ * The session's state revision: a per-session counter that advances by
1209
+ * one with every state frame the session publishes, and frames reach a
1210
+ * subscriber in revision order. The state a SessionOpen or a Subscribe
1211
+ * starts with carries the session's current revision. A client compares
1212
+ * it with `BundleApplyResult.revision` to tell whether the frame it
1213
+ * holds already shows a batch it applied.
1214
+ */
1215
+ revision: number;
704
1216
  }
705
1217
  declare const BundleState: MessageFns<BundleState>;
706
1218
  /**
@@ -720,6 +1232,20 @@ interface BundleApplyResult {
720
1232
  success: boolean;
721
1233
  errors: GraphError[];
722
1234
  created: CreatedRef[];
1235
+ /**
1236
+ * The revision of the state the batch produced: the
1237
+ * `BundleState.revision` of the frame that carries it. For a batch
1238
+ * that changed nothing or was refused, the session's current revision.
1239
+ * A subscriber holds the batch's own write once it has received a
1240
+ * frame at this revision or a later one.
1241
+ */
1242
+ revision: number;
1243
+ /**
1244
+ * The pairs an `auto_connect` of the batch did not wire because they
1245
+ * tie: two or more pairs at one score sharing an input or an output.
1246
+ * No port a tied pair names was wired.
1247
+ */
1248
+ ties: WiringCandidate[];
723
1249
  }
724
1250
  declare const BundleApplyResult: MessageFns<BundleApplyResult>;
725
1251
  /**
@@ -746,16 +1272,22 @@ interface CreatedRef {
746
1272
  }
747
1273
  declare const CreatedRef: MessageFns<CreatedRef>;
748
1274
  /**
749
- * GraphError describes an IR-level validation failure that rejected an
750
- * action. Mutation-boundary errors never reach the canvas; they are
751
- * returned synchronously to the action RPC caller. The canvas renders
752
- * no validator of its own — it surfaces BundleState.diagnostics.
1275
+ * GraphError is a refusal of a batch's content: one action the working IR
1276
+ * would not take, located at the module, instance and input it addressed,
1277
+ * with its sentence and, where the refusal has an entry in the one
1278
+ * vocabulary, its reason (`REASON_CROSS_SCOPE` for a wire across a
1279
+ * group's boundary; `REASON_UNSPECIFIED` otherwise). A client branches on
1280
+ * the reason, never on the message. Mutation-boundary errors never reach
1281
+ * the canvas; they are returned synchronously to the action RPC caller.
1282
+ * The canvas renders no validator of its own — it surfaces
1283
+ * BundleState.diagnostics.
753
1284
  */
754
1285
  interface GraphError {
755
1286
  module_key: string;
756
1287
  instance_id: string;
757
1288
  input_name: string;
758
1289
  message: string;
1290
+ reason: Reason;
759
1291
  }
760
1292
  declare const GraphError: MessageFns<GraphError>;
761
1293
  interface ProviderReqView {
@@ -842,6 +1374,28 @@ declare const LaceEngineService: {
842
1374
  readonly responseSerialize: (value: ShutdownResponse) => Buffer;
843
1375
  readonly responseDeserialize: (value: Buffer) => ShutdownResponse;
844
1376
  };
1377
+ /**
1378
+ * Answers the credential this engine holds: the API key `lace login`
1379
+ * saved or `LACE_TOKEN` supplies, read fresh on every call so a `lace
1380
+ * login` or `lace logout` takes effect at once (empty when signed out),
1381
+ * beside the base URL of the API that key is for, the one the engine's
1382
+ * own commands call (the CLI's `config.ResolveBaseURL`). The host
1383
+ * that spawned the engine builds its own authenticated transport to
1384
+ * Lace's API from the two, for the chat package, and never restates
1385
+ * which API; the engine knows nothing of what the host does with them. Served, like every RPC,
1386
+ * only to the bearer of the handshake's session token, and never
1387
+ * forwarded across the webview bridge (`BRIDGE_METHODS`,
1388
+ * @lace-cloud/proto's engine-bridge.ts).
1389
+ */
1390
+ readonly readCredential: {
1391
+ readonly path: "/lace.engine.LaceEngine/ReadCredential";
1392
+ readonly requestStream: false;
1393
+ readonly responseStream: false;
1394
+ readonly requestSerialize: (value: Empty) => Buffer;
1395
+ readonly requestDeserialize: (value: Buffer) => Empty;
1396
+ readonly responseSerialize: (value: ReadCredentialResponse) => Buffer;
1397
+ readonly responseDeserialize: (value: Buffer) => ReadCredentialResponse;
1398
+ };
845
1399
  /**
846
1400
  * Session lifecycle. Never fails on a refused source tf — a refused tf
847
1401
  * opens the session source-refused (`BundleState.source_refused`) with
@@ -891,7 +1445,11 @@ declare const LaceEngineService: {
891
1445
  * Writes the session's saved Bundle to HCL and re-bases the session
892
1446
  * onto the written tree's hash. Refuses (FailedPrecondition) while the
893
1447
  * session is ephemeral, holds the git guard, is source-refused, has an
894
- * open conflict, or has unsaved edits.
1448
+ * open conflict, has unsaved edits, or is already running a Generate
1449
+ * (one at a time per session). Every Generate that reaches a session
1450
+ * publishes its events to that session's subscribers under its own
1451
+ * `generate_id`: its progress, and exactly one closing `generate_success`
1452
+ * or `generate_error` — a refusal included, which also fails the call.
895
1453
  */
896
1454
  readonly sessionGenerate: {
897
1455
  readonly path: "/lace.engine.LaceEngine/SessionGenerate";
@@ -919,9 +1477,13 @@ declare const LaceEngineService: {
919
1477
  * Single unified mutation RPC. Every canvas mutation (connect, update
920
1478
  * input, create group, undo, redo, place module from registry, ...)
921
1479
  * travels through ApplyAction carrying one or more `Action` oneof
922
- * cases. Returns `BundleApplyResult { success, errors }`; on success
923
- * the corresponding `BundleState` snapshot is published to every
924
- * Subscribe stream on this session (including the caller's). Refused
1480
+ * cases. Returns `BundleApplyResult { success, errors, created,
1481
+ * revision }`. A batch is applied whole or not at all: a batch any
1482
+ * action of which is refused is refused whole and publishes nothing; a
1483
+ * batch that changes nothing publishes nothing and adds no undo entry;
1484
+ * an applied batch is one undo entry and one `BundleState` frame,
1485
+ * published to every Subscribe stream on this session (including the
1486
+ * caller's) at the revision the result names. Refused
925
1487
  * (FailedPrecondition) while the session is source-refused.
926
1488
  */
927
1489
  readonly applyAction: {
@@ -933,6 +1495,22 @@ declare const LaceEngineService: {
933
1495
  readonly responseSerialize: (value: BundleApplyResult) => Buffer;
934
1496
  readonly responseDeserialize: (value: Buffer) => BundleApplyResult;
935
1497
  };
1498
+ /**
1499
+ * Reads the output → input pairs the engine's matcher scores between the
1500
+ * instances of one module of a session's working IR: the pairs an
1501
+ * `auto_connect` chooses among, with the scores it chooses by. The
1502
+ * matching rules have this one home; a client that picks a wire for a
1503
+ * request in words ranks these and sends the pair as a `connect`.
1504
+ */
1505
+ readonly readWiringCandidates: {
1506
+ readonly path: "/lace.engine.LaceEngine/ReadWiringCandidates";
1507
+ readonly requestStream: false;
1508
+ readonly responseStream: false;
1509
+ readonly requestSerialize: (value: ReadWiringCandidatesRequest) => Buffer;
1510
+ readonly requestDeserialize: (value: Buffer) => ReadWiringCandidatesRequest;
1511
+ readonly responseSerialize: (value: ReadWiringCandidatesResponse) => Buffer;
1512
+ readonly responseDeserialize: (value: Buffer) => ReadWiringCandidatesResponse;
1513
+ };
936
1514
  /**
937
1515
  * Runs one CLI command in-process against a fresh command tree. The command's `-o json` output is the stream:
938
1516
  * each top-level JSON value on stdout is one `json` event; `exit` is always last.
@@ -958,9 +1536,11 @@ declare const LaceEngineService: {
958
1536
  };
959
1537
  /**
960
1538
  * Server-push events scoped to one session. Yields `BundleStateEvent`
961
- * — full `BundleState` snapshots per session-state change, plus
962
- * generate-phase pass-throughs. Initial emission is the current
963
- * BundleState, which acts as the "subscribed" ready signal.
1539
+ * — full `BundleState` snapshots per session-state change, generate-phase
1540
+ * pass-throughs, and the result of every command that ran in the
1541
+ * session's root (`CommandResult`). Initial emission is the current
1542
+ * BundleState, which acts as the "subscribed" ready signal, followed by
1543
+ * the last `CommandResult` the session keeps per command path.
964
1544
  *
965
1545
  * Consumers (portal + extension canvas engines) project locally via
966
1546
  * `@lace-cloud/proto`'s `projectCanvasView(bundle, arrangement?, meta)`.
@@ -985,6 +1565,22 @@ interface LaceEngineClient extends Client {
985
1565
  shutdown(request: Empty, callback: (error: ServiceError | null, response: ShutdownResponse) => void): ClientUnaryCall;
986
1566
  shutdown(request: Empty, metadata: Metadata, callback: (error: ServiceError | null, response: ShutdownResponse) => void): ClientUnaryCall;
987
1567
  shutdown(request: Empty, metadata: Metadata, options: Partial<CallOptions>, callback: (error: ServiceError | null, response: ShutdownResponse) => void): ClientUnaryCall;
1568
+ /**
1569
+ * Answers the credential this engine holds: the API key `lace login`
1570
+ * saved or `LACE_TOKEN` supplies, read fresh on every call so a `lace
1571
+ * login` or `lace logout` takes effect at once (empty when signed out),
1572
+ * beside the base URL of the API that key is for, the one the engine's
1573
+ * own commands call (the CLI's `config.ResolveBaseURL`). The host
1574
+ * that spawned the engine builds its own authenticated transport to
1575
+ * Lace's API from the two, for the chat package, and never restates
1576
+ * which API; the engine knows nothing of what the host does with them. Served, like every RPC,
1577
+ * only to the bearer of the handshake's session token, and never
1578
+ * forwarded across the webview bridge (`BRIDGE_METHODS`,
1579
+ * @lace-cloud/proto's engine-bridge.ts).
1580
+ */
1581
+ readCredential(request: Empty, callback: (error: ServiceError | null, response: ReadCredentialResponse) => void): ClientUnaryCall;
1582
+ readCredential(request: Empty, metadata: Metadata, callback: (error: ServiceError | null, response: ReadCredentialResponse) => void): ClientUnaryCall;
1583
+ readCredential(request: Empty, metadata: Metadata, options: Partial<CallOptions>, callback: (error: ServiceError | null, response: ReadCredentialResponse) => void): ClientUnaryCall;
988
1584
  /**
989
1585
  * Session lifecycle. Never fails on a refused source tf — a refused tf
990
1586
  * opens the session source-refused (`BundleState.source_refused`) with
@@ -1010,7 +1606,11 @@ interface LaceEngineClient extends Client {
1010
1606
  * Writes the session's saved Bundle to HCL and re-bases the session
1011
1607
  * onto the written tree's hash. Refuses (FailedPrecondition) while the
1012
1608
  * session is ephemeral, holds the git guard, is source-refused, has an
1013
- * open conflict, or has unsaved edits.
1609
+ * open conflict, has unsaved edits, or is already running a Generate
1610
+ * (one at a time per session). Every Generate that reaches a session
1611
+ * publishes its events to that session's subscribers under its own
1612
+ * `generate_id`: its progress, and exactly one closing `generate_success`
1613
+ * or `generate_error` — a refusal included, which also fails the call.
1014
1614
  */
1015
1615
  sessionGenerate(request: SessionGenerateRequest, callback: (error: ServiceError | null, response: SessionGenerateResponse) => void): ClientUnaryCall;
1016
1616
  sessionGenerate(request: SessionGenerateRequest, metadata: Metadata, callback: (error: ServiceError | null, response: SessionGenerateResponse) => void): ClientUnaryCall;
@@ -1026,14 +1626,28 @@ interface LaceEngineClient extends Client {
1026
1626
  * Single unified mutation RPC. Every canvas mutation (connect, update
1027
1627
  * input, create group, undo, redo, place module from registry, ...)
1028
1628
  * travels through ApplyAction carrying one or more `Action` oneof
1029
- * cases. Returns `BundleApplyResult { success, errors }`; on success
1030
- * the corresponding `BundleState` snapshot is published to every
1031
- * Subscribe stream on this session (including the caller's). Refused
1629
+ * cases. Returns `BundleApplyResult { success, errors, created,
1630
+ * revision }`. A batch is applied whole or not at all: a batch any
1631
+ * action of which is refused is refused whole and publishes nothing; a
1632
+ * batch that changes nothing publishes nothing and adds no undo entry;
1633
+ * an applied batch is one undo entry and one `BundleState` frame,
1634
+ * published to every Subscribe stream on this session (including the
1635
+ * caller's) at the revision the result names. Refused
1032
1636
  * (FailedPrecondition) while the session is source-refused.
1033
1637
  */
1034
1638
  applyAction(request: ApplyActionRequest, callback: (error: ServiceError | null, response: BundleApplyResult) => void): ClientUnaryCall;
1035
1639
  applyAction(request: ApplyActionRequest, metadata: Metadata, callback: (error: ServiceError | null, response: BundleApplyResult) => void): ClientUnaryCall;
1036
1640
  applyAction(request: ApplyActionRequest, metadata: Metadata, options: Partial<CallOptions>, callback: (error: ServiceError | null, response: BundleApplyResult) => void): ClientUnaryCall;
1641
+ /**
1642
+ * Reads the output → input pairs the engine's matcher scores between the
1643
+ * instances of one module of a session's working IR: the pairs an
1644
+ * `auto_connect` chooses among, with the scores it chooses by. The
1645
+ * matching rules have this one home; a client that picks a wire for a
1646
+ * request in words ranks these and sends the pair as a `connect`.
1647
+ */
1648
+ readWiringCandidates(request: ReadWiringCandidatesRequest, callback: (error: ServiceError | null, response: ReadWiringCandidatesResponse) => void): ClientUnaryCall;
1649
+ readWiringCandidates(request: ReadWiringCandidatesRequest, metadata: Metadata, callback: (error: ServiceError | null, response: ReadWiringCandidatesResponse) => void): ClientUnaryCall;
1650
+ readWiringCandidates(request: ReadWiringCandidatesRequest, metadata: Metadata, options: Partial<CallOptions>, callback: (error: ServiceError | null, response: ReadWiringCandidatesResponse) => void): ClientUnaryCall;
1037
1651
  /**
1038
1652
  * Runs one CLI command in-process against a fresh command tree. The command's `-o json` output is the stream:
1039
1653
  * each top-level JSON value on stdout is one `json` event; `exit` is always last.
@@ -1046,9 +1660,11 @@ interface LaceEngineClient extends Client {
1046
1660
  cancelInvoke(request: CancelInvokeRequest, metadata: Metadata, options: Partial<CallOptions>, callback: (error: ServiceError | null, response: CancelInvokeResponse) => void): ClientUnaryCall;
1047
1661
  /**
1048
1662
  * Server-push events scoped to one session. Yields `BundleStateEvent`
1049
- * — full `BundleState` snapshots per session-state change, plus
1050
- * generate-phase pass-throughs. Initial emission is the current
1051
- * BundleState, which acts as the "subscribed" ready signal.
1663
+ * — full `BundleState` snapshots per session-state change, generate-phase
1664
+ * pass-throughs, and the result of every command that ran in the
1665
+ * session's root (`CommandResult`). Initial emission is the current
1666
+ * BundleState, which acts as the "subscribed" ready signal, followed by
1667
+ * the last `CommandResult` the session keeps per command path.
1052
1668
  *
1053
1669
  * Consumers (portal + extension canvas engines) project locally via
1054
1670
  * `@lace-cloud/proto`'s `projectCanvasView(bundle, arrangement?, meta)`.
@@ -1082,6 +1698,33 @@ interface MessageFns<T> {
1082
1698
  fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
1083
1699
  }
1084
1700
 
1701
+ type RpcErrorCategory = 'engine_unavailable' | 'server_error' | 'timeout';
1702
+ /**
1703
+ * A failed engine call, classified: `category` says how it failed (the
1704
+ * engine is gone, it timed out, or it answered with an error), `reason` and
1705
+ * `apiCode` why, as the engine's status details name it — the refusal's
1706
+ * entry in the one vocabulary (`REASON_UNSPECIFIED` when it named none or no
1707
+ * status came back) and, for a failure the API decided, the API's own code.
1708
+ * A host branches on these, never on `message`.
1709
+ */
1710
+ declare class RpcError extends Error {
1711
+ readonly category: RpcErrorCategory;
1712
+ readonly method: string;
1713
+ readonly cause?: unknown | undefined;
1714
+ readonly reason: Reason;
1715
+ readonly apiCode?: string | undefined;
1716
+ constructor(message: string, category: RpcErrorCategory, method: string, cause?: unknown | undefined, reason?: Reason, apiCode?: string | undefined);
1717
+ }
1718
+ /**
1719
+ * Classifies a failed engine call by data alone: a gRPC status by its code,
1720
+ * with the reason and API code its details carry (`readReasonDetail`, the
1721
+ * reader the bridge's error frame uses); an `RpcError` is already
1722
+ * classified and comes back as it is; anything else carries no status and
1723
+ * is `server_error`. No message text is read.
1724
+ */
1725
+ declare function classifyRpcError(err: unknown, method: string): RpcError;
1726
+ declare function requireClient<T>(client: T | null | undefined, action: string): T;
1727
+
1085
1728
  declare class LaceTransport {
1086
1729
  private inner;
1087
1730
  private token;
@@ -1090,42 +1733,13 @@ declare class LaceTransport {
1090
1733
  get client(): LaceEngineClient;
1091
1734
  metadata(): grpc.Metadata;
1092
1735
  private unary;
1093
- initialize(clientVersion: string): Promise<{
1094
- serverVersion: string;
1095
- }>;
1736
+ initialize(clientVersion: string): Promise<EngineInitialize>;
1096
1737
  shutdown(): Promise<void>;
1738
+ readCredential(): Promise<EngineCredential>;
1097
1739
  subscribeStream(sessionId: string): grpc.ClientReadableStream<BundleStateEvent>;
1098
- /** The Subscribe stream narrowed to the engine facts chat reads. */
1099
- subscribeFacts(sessionId: string): FactsStream;
1100
1740
  dispose(): void;
1101
1741
  }
1102
1742
 
1103
- type ChatEngineEvent = {
1104
- /** The findings of one session state; `[]` when the state has none. */
1105
- diagnostics?: Diagnostic$1[];
1106
- generate_error?: {
1107
- message: string;
1108
- diagnostics: Diagnostic$1[];
1109
- };
1110
- };
1111
- interface FactsStream {
1112
- on(ev: 'data', cb: (e: ChatEngineEvent) => void): void;
1113
- on(ev: 'end', cb: () => void): void;
1114
- on(ev: 'error', cb: (err: Error) => void): void;
1115
- cancel(): void;
1116
- }
1117
- type FactsSource = Pick<LaceTransport, 'subscribeFacts'>;
1118
-
1119
- type RpcErrorCategory = 'engine_unavailable' | 'server_error' | 'timeout';
1120
- declare class RpcError extends Error {
1121
- readonly category: RpcErrorCategory;
1122
- readonly method: string;
1123
- readonly cause?: unknown | undefined;
1124
- constructor(message: string, category: RpcErrorCategory, method: string, cause?: unknown | undefined);
1125
- }
1126
- declare function classifyRpcError(err: unknown, method: string): RpcError;
1127
- declare function requireClient<T>(client: T | null | undefined, action: string): T;
1128
-
1129
1743
  type ServerManagerOpts = {
1130
1744
  log: (msg: string) => void;
1131
1745
  getBinaryPath: () => string;
@@ -1134,6 +1748,8 @@ type ServerManagerOpts = {
1134
1748
  declare class ServerManager extends EventEmitter {
1135
1749
  private process;
1136
1750
  private _transport;
1751
+ private _handshake;
1752
+ private _initialized;
1137
1753
  private state;
1138
1754
  private restartCount;
1139
1755
  private restartScheduled;
@@ -1142,14 +1758,29 @@ declare class ServerManager extends EventEmitter {
1142
1758
  private readonly getBinaryPath;
1143
1759
  private readonly getAutoRestart;
1144
1760
  constructor(opts: ServerManagerOpts);
1761
+ /** The connection to the running engine; null whenever none is running. */
1145
1762
  get transport(): LaceTransport | null;
1763
+ /** What the running engine printed on its handshake; null whenever none is running. */
1764
+ get handshake(): EngineHandshake | null;
1765
+ /** What the running engine answered `Initialize` with; null whenever none is running. */
1766
+ get initialized(): EngineInitialize | null;
1146
1767
  get currentState(): ServerState;
1768
+ /**
1769
+ * Spawns the engine and connects to it. The handshake's protocol version
1770
+ * is compared with the one this library speaks before any RPC is sent
1771
+ * (`checkEngineProtocol`, `@lace-cloud/proto`, the check the canvas makes
1772
+ * of `Initialize`'s answer): an engine that names another rejects with
1773
+ * `EngineProtocolMismatchError`.
1774
+ * An engine a failed start spawned is ended before the rejection.
1775
+ */
1147
1776
  start(): Promise<void>;
1148
1777
  stop(): Promise<void>;
1149
1778
  restart(): Promise<void>;
1150
- dispose(): void;
1779
+ dispose(): Promise<void>;
1780
+ private engineEnded;
1781
+ private release;
1151
1782
  private setState;
1152
1783
  private maybeRestart;
1153
1784
  }
1154
1785
 
1155
- export { Action, ApplyActionRequest, BundleApplyResult, BundleState, BundleStateEvent, type ChatEngineEvent, type EngineHandshake, type EngineTransport, type FactsSource, type FactsStream, InitializeResponse, LaceTransport, RpcError, type RpcErrorCategory, ServerManager, type ServerState, classifyRpcError, requireClient, serveEngineBridge, spawnEngine };
1786
+ export { Action, ApplyActionRequest, BundleApplyResult, BundleState, BundleStateEvent, type EngineCredential, type EngineHandshake, type EngineInitialize, type EngineTransport, InitializeResponse, InvokeRequest, LaceTransport, ReadWiringCandidatesRequest, ReadWiringCandidatesResponse, ReasonDetail, RpcError, type RpcErrorCategory, ServerManager, type ServerState, SessionCloseResponse, SessionOpenResponse, Status, classifyRpcError, endEngine, requireClient, serveEngineBridge, spawnEngine };