@lace-cloud/host 0.35.0 → 0.37.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,5 +1,5 @@
1
1
  import { MessageBridge } from '@lace-cloud/proto';
2
- export { Diagnostic, EngineProtocolMismatchError } from '@lace-cloud/proto';
2
+ export { Diagnostic, EngineIdentityMismatchError } from '@lace-cloud/proto';
3
3
  import * as grpc from '@grpc/grpc-js';
4
4
  import { Metadata, ServiceError, Client, ClientUnaryCall, CallOptions, ClientReadableStream, ChannelCredentials, ClientOptions } from '@grpc/grpc-js';
5
5
  import { ChildProcess } from 'node:child_process';
@@ -37,6 +37,7 @@ declare function serveEngineBridge(bridge: MessageBridge, transport: EngineTrans
37
37
  type EngineHandshake = {
38
38
  version: string;
39
39
  protocolVersion: string;
40
+ contract: string;
40
41
  port: number;
41
42
  token: string;
42
43
  };
@@ -70,13 +71,20 @@ declare class EngineSpawnError extends Error {
70
71
  get code(): string | undefined;
71
72
  }
72
73
  /**
73
- * Spawn `lace engine` and parse the 5-line handshake:
74
+ * Spawn `lace engine` and parse its handshake:
74
75
  * LACE_ENGINE_VERSION=<semver>
75
76
  * LACE_ENGINE_PROTOCOL_VERSION=<integer>
77
+ * LACE_ENGINE_CONTRACT=<64 hex chars>
76
78
  * LACE_ENGINE_PORT=<port>
77
79
  * LACE_ENGINE_TOKEN=<64 hex chars>
78
80
  * LACE_ENGINE_READY
79
81
  *
82
+ * READY settles the handshake once the version, protocol, port and token
83
+ * are set. The contract line is not required for it: an engine that names
84
+ * no contract settles with `contract` '', and the protocol check
85
+ * (`checkEngineIdentity`) refuses it by name rather than a handshake
86
+ * failure that names nothing.
87
+ *
80
88
  * Each stdout line is logged as the engine wrote it, the handshake's and every
81
89
  * one after it until the engine's end, except a token line, which is logged
82
90
  * masked. A binary that cannot be started rejects with
@@ -441,6 +449,8 @@ declare enum Reason {
441
449
  * `.terraform.lock.hcl`; `lace module lock` writes it.
442
450
  */
443
451
  REASON_NO_LOCKFILE = 22,
452
+ /** REASON_NO_COMMIT - stack create --source: the directory's repository has no commit yet. */
453
+ REASON_NO_COMMIT = 23,
444
454
  UNRECOGNIZED = -1
445
455
  }
446
456
 
@@ -740,6 +750,13 @@ interface InitializeResponse {
740
750
  supported_protocols: string[];
741
751
  /** space-joined paths of the non-hidden command tree */
742
752
  command_paths: string[];
753
+ /**
754
+ * The digest of the contract the engine serves (scripts/lib/engine-contract.mjs):
755
+ * the command tree, the `--output json` documents and the failure
756
+ * envelopes the CLI's tests record. A client built from another contract
757
+ * refuses the engine; the engine compares no contract of the client's.
758
+ */
759
+ contract: string;
743
760
  }
744
761
  declare const InitializeResponse: MessageFns<InitializeResponse>;
745
762
  interface ShutdownResponse {
@@ -1153,8 +1170,8 @@ declare const ApplyActionRequest: MessageFns<ApplyActionRequest>;
1153
1170
  * two instances of one module: `source_instance`'s `output` could feed
1154
1171
  * `target_instance`'s `input`, a required input with no binding. `score`
1155
1172
  * is the matcher's: 100 for the same name, 90 for the same last
1156
- * `_`-separated word, 50 when one name contains the other, 30 for the
1157
- * same type alone; a pair that scores nothing is no candidate.
1173
+ * `_`-separated word, 50 when one name contains the other; a pair that
1174
+ * scores nothing is no candidate.
1158
1175
  */
1159
1176
  interface WiringCandidate {
1160
1177
  source_instance: string;
@@ -1475,6 +1492,11 @@ interface CreatedRef {
1475
1492
  * the source child ID. Empty otherwise.
1476
1493
  */
1477
1494
  source_id: string;
1495
+ /**
1496
+ * Set when the child was promoted out of a dissolved group (ungroup): the
1497
+ * group's id in `scope`, which with source_id names the child. Empty otherwise.
1498
+ */
1499
+ group_id: string;
1478
1500
  }
1479
1501
  declare const CreatedRef: MessageFns<CreatedRef>;
1480
1502
  /**
@@ -1954,10 +1976,10 @@ declare class ServerManager extends EventEmitter {
1954
1976
  get currentState(): ServerState;
1955
1977
  /**
1956
1978
  * Spawns the engine and connects to it. The handshake's protocol version
1957
- * is compared with the one this library speaks before any RPC is sent
1958
- * (`checkEngineProtocol`, `@lace-cloud/proto`, the check the canvas makes
1959
- * of `Initialize`'s answer): an engine that names another rejects with
1960
- * `EngineProtocolMismatchError`. A binary that cannot be started rejects
1979
+ * and contract are compared with the ones this library was built from
1980
+ * before any RPC is sent (`checkEngineIdentity`, `@lace-cloud/proto`, the
1981
+ * check the canvas makes of `Initialize`'s answer): an engine that names
1982
+ * another, or no contract, rejects with `EngineIdentityMismatchError`. A binary that cannot be started rejects
1961
1983
  * with `EngineSpawnError`, whose `code` is the spawn error's (`ENOENT`
1962
1984
  * when no executable is found, `EINVAL` when Windows refuses to start a
1963
1985
  * `.cmd` or `.bat`).
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MessageBridge } from '@lace-cloud/proto';
2
- export { Diagnostic, EngineProtocolMismatchError } from '@lace-cloud/proto';
2
+ export { Diagnostic, EngineIdentityMismatchError } from '@lace-cloud/proto';
3
3
  import * as grpc from '@grpc/grpc-js';
4
4
  import { Metadata, ServiceError, Client, ClientUnaryCall, CallOptions, ClientReadableStream, ChannelCredentials, ClientOptions } from '@grpc/grpc-js';
5
5
  import { ChildProcess } from 'node:child_process';
@@ -37,6 +37,7 @@ declare function serveEngineBridge(bridge: MessageBridge, transport: EngineTrans
37
37
  type EngineHandshake = {
38
38
  version: string;
39
39
  protocolVersion: string;
40
+ contract: string;
40
41
  port: number;
41
42
  token: string;
42
43
  };
@@ -70,13 +71,20 @@ declare class EngineSpawnError extends Error {
70
71
  get code(): string | undefined;
71
72
  }
72
73
  /**
73
- * Spawn `lace engine` and parse the 5-line handshake:
74
+ * Spawn `lace engine` and parse its handshake:
74
75
  * LACE_ENGINE_VERSION=<semver>
75
76
  * LACE_ENGINE_PROTOCOL_VERSION=<integer>
77
+ * LACE_ENGINE_CONTRACT=<64 hex chars>
76
78
  * LACE_ENGINE_PORT=<port>
77
79
  * LACE_ENGINE_TOKEN=<64 hex chars>
78
80
  * LACE_ENGINE_READY
79
81
  *
82
+ * READY settles the handshake once the version, protocol, port and token
83
+ * are set. The contract line is not required for it: an engine that names
84
+ * no contract settles with `contract` '', and the protocol check
85
+ * (`checkEngineIdentity`) refuses it by name rather than a handshake
86
+ * failure that names nothing.
87
+ *
80
88
  * Each stdout line is logged as the engine wrote it, the handshake's and every
81
89
  * one after it until the engine's end, except a token line, which is logged
82
90
  * masked. A binary that cannot be started rejects with
@@ -441,6 +449,8 @@ declare enum Reason {
441
449
  * `.terraform.lock.hcl`; `lace module lock` writes it.
442
450
  */
443
451
  REASON_NO_LOCKFILE = 22,
452
+ /** REASON_NO_COMMIT - stack create --source: the directory's repository has no commit yet. */
453
+ REASON_NO_COMMIT = 23,
444
454
  UNRECOGNIZED = -1
445
455
  }
446
456
 
@@ -740,6 +750,13 @@ interface InitializeResponse {
740
750
  supported_protocols: string[];
741
751
  /** space-joined paths of the non-hidden command tree */
742
752
  command_paths: string[];
753
+ /**
754
+ * The digest of the contract the engine serves (scripts/lib/engine-contract.mjs):
755
+ * the command tree, the `--output json` documents and the failure
756
+ * envelopes the CLI's tests record. A client built from another contract
757
+ * refuses the engine; the engine compares no contract of the client's.
758
+ */
759
+ contract: string;
743
760
  }
744
761
  declare const InitializeResponse: MessageFns<InitializeResponse>;
745
762
  interface ShutdownResponse {
@@ -1153,8 +1170,8 @@ declare const ApplyActionRequest: MessageFns<ApplyActionRequest>;
1153
1170
  * two instances of one module: `source_instance`'s `output` could feed
1154
1171
  * `target_instance`'s `input`, a required input with no binding. `score`
1155
1172
  * is the matcher's: 100 for the same name, 90 for the same last
1156
- * `_`-separated word, 50 when one name contains the other, 30 for the
1157
- * same type alone; a pair that scores nothing is no candidate.
1173
+ * `_`-separated word, 50 when one name contains the other; a pair that
1174
+ * scores nothing is no candidate.
1158
1175
  */
1159
1176
  interface WiringCandidate {
1160
1177
  source_instance: string;
@@ -1475,6 +1492,11 @@ interface CreatedRef {
1475
1492
  * the source child ID. Empty otherwise.
1476
1493
  */
1477
1494
  source_id: string;
1495
+ /**
1496
+ * Set when the child was promoted out of a dissolved group (ungroup): the
1497
+ * group's id in `scope`, which with source_id names the child. Empty otherwise.
1498
+ */
1499
+ group_id: string;
1478
1500
  }
1479
1501
  declare const CreatedRef: MessageFns<CreatedRef>;
1480
1502
  /**
@@ -1954,10 +1976,10 @@ declare class ServerManager extends EventEmitter {
1954
1976
  get currentState(): ServerState;
1955
1977
  /**
1956
1978
  * Spawns the engine and connects to it. The handshake's protocol version
1957
- * is compared with the one this library speaks before any RPC is sent
1958
- * (`checkEngineProtocol`, `@lace-cloud/proto`, the check the canvas makes
1959
- * of `Initialize`'s answer): an engine that names another rejects with
1960
- * `EngineProtocolMismatchError`. A binary that cannot be started rejects
1979
+ * and contract are compared with the ones this library was built from
1980
+ * before any RPC is sent (`checkEngineIdentity`, `@lace-cloud/proto`, the
1981
+ * check the canvas makes of `Initialize`'s answer): an engine that names
1982
+ * another, or no contract, rejects with `EngineIdentityMismatchError`. A binary that cannot be started rejects
1961
1983
  * with `EngineSpawnError`, whose `code` is the spawn error's (`ENOENT`
1962
1984
  * when no executable is found, `EINVAL` when Windows refuses to start a
1963
1985
  * `.cmd` or `.bat`).
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import { EngineProtocolMismatchError } from "@lace-cloud/proto";
2
+ import { EngineIdentityMismatchError } from "@lace-cloud/proto";
3
3
 
4
4
  // src/bridge-server.ts
5
5
  import {
@@ -553,6 +553,9 @@ function reasonFromJSON(object) {
553
553
  case 22:
554
554
  case "REASON_NO_LOCKFILE":
555
555
  return 22 /* REASON_NO_LOCKFILE */;
556
+ case 23:
557
+ case "REASON_NO_COMMIT":
558
+ return 23 /* REASON_NO_COMMIT */;
556
559
  case -1:
557
560
  case "UNRECOGNIZED":
558
561
  default:
@@ -607,6 +610,8 @@ function reasonToJSON(object) {
607
610
  return "REASON_ALREADY_IMPORTED";
608
611
  case 22 /* REASON_NO_LOCKFILE */:
609
612
  return "REASON_NO_LOCKFILE";
613
+ case 23 /* REASON_NO_COMMIT */:
614
+ return "REASON_NO_COMMIT";
610
615
  case -1 /* UNRECOGNIZED */:
611
616
  default:
612
617
  return "UNRECOGNIZED";
@@ -3679,7 +3684,7 @@ var InitializeRequest = {
3679
3684
  }
3680
3685
  };
3681
3686
  function createBaseInitializeResponse() {
3682
- return { server_version: "", protocol_version: "", supported_protocols: [], command_paths: [] };
3687
+ return { server_version: "", protocol_version: "", supported_protocols: [], command_paths: [], contract: "" };
3683
3688
  }
3684
3689
  var InitializeResponse = {
3685
3690
  encode(message, writer = new BinaryWriter4()) {
@@ -3695,6 +3700,9 @@ var InitializeResponse = {
3695
3700
  for (const v of message.command_paths) {
3696
3701
  writer.uint32(42).string(v);
3697
3702
  }
3703
+ if (message.contract !== "") {
3704
+ writer.uint32(50).string(message.contract);
3705
+ }
3698
3706
  return writer;
3699
3707
  },
3700
3708
  decode(input, length) {
@@ -3732,6 +3740,13 @@ var InitializeResponse = {
3732
3740
  message.command_paths.push(reader.string());
3733
3741
  continue;
3734
3742
  }
3743
+ case 6: {
3744
+ if (tag !== 50) {
3745
+ break;
3746
+ }
3747
+ message.contract = reader.string();
3748
+ continue;
3749
+ }
3735
3750
  }
3736
3751
  if ((tag & 7) === 4 || tag === 0) {
3737
3752
  break;
@@ -3745,7 +3760,8 @@ var InitializeResponse = {
3745
3760
  server_version: isSet3(object.serverVersion) ? globalThis.String(object.serverVersion) : isSet3(object.server_version) ? globalThis.String(object.server_version) : "",
3746
3761
  protocol_version: isSet3(object.protocolVersion) ? globalThis.String(object.protocolVersion) : isSet3(object.protocol_version) ? globalThis.String(object.protocol_version) : "",
3747
3762
  supported_protocols: globalThis.Array.isArray(object?.supportedProtocols) ? object.supportedProtocols.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.supported_protocols) ? object.supported_protocols.map((e) => globalThis.String(e)) : [],
3748
- command_paths: globalThis.Array.isArray(object?.commandPaths) ? object.commandPaths.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.command_paths) ? object.command_paths.map((e) => globalThis.String(e)) : []
3763
+ command_paths: globalThis.Array.isArray(object?.commandPaths) ? object.commandPaths.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.command_paths) ? object.command_paths.map((e) => globalThis.String(e)) : [],
3764
+ contract: isSet3(object.contract) ? globalThis.String(object.contract) : ""
3749
3765
  };
3750
3766
  },
3751
3767
  toJSON(message) {
@@ -3762,6 +3778,9 @@ var InitializeResponse = {
3762
3778
  if (message.command_paths?.length) {
3763
3779
  obj.commandPaths = message.command_paths;
3764
3780
  }
3781
+ if (message.contract !== "") {
3782
+ obj.contract = message.contract;
3783
+ }
3765
3784
  return obj;
3766
3785
  },
3767
3786
  create(base) {
@@ -3773,6 +3792,7 @@ var InitializeResponse = {
3773
3792
  message.protocol_version = object.protocol_version ?? "";
3774
3793
  message.supported_protocols = object.supported_protocols?.map((e) => e) || [];
3775
3794
  message.command_paths = object.command_paths?.map((e) => e) || [];
3795
+ message.contract = object.contract ?? "";
3776
3796
  return message;
3777
3797
  }
3778
3798
  };
@@ -9262,7 +9282,7 @@ var BundleApplyResult = {
9262
9282
  }
9263
9283
  };
9264
9284
  function createBaseCreatedRef() {
9265
- return { scope: "", id: "", module_key: "", source_id: "" };
9285
+ return { scope: "", id: "", module_key: "", source_id: "", group_id: "" };
9266
9286
  }
9267
9287
  var CreatedRef = {
9268
9288
  encode(message, writer = new BinaryWriter4()) {
@@ -9278,6 +9298,9 @@ var CreatedRef = {
9278
9298
  if (message.source_id !== "") {
9279
9299
  writer.uint32(34).string(message.source_id);
9280
9300
  }
9301
+ if (message.group_id !== "") {
9302
+ writer.uint32(42).string(message.group_id);
9303
+ }
9281
9304
  return writer;
9282
9305
  },
9283
9306
  decode(input, length) {
@@ -9315,6 +9338,13 @@ var CreatedRef = {
9315
9338
  message.source_id = reader.string();
9316
9339
  continue;
9317
9340
  }
9341
+ case 5: {
9342
+ if (tag !== 42) {
9343
+ break;
9344
+ }
9345
+ message.group_id = reader.string();
9346
+ continue;
9347
+ }
9318
9348
  }
9319
9349
  if ((tag & 7) === 4 || tag === 0) {
9320
9350
  break;
@@ -9328,7 +9358,8 @@ var CreatedRef = {
9328
9358
  scope: isSet3(object.scope) ? globalThis.String(object.scope) : "",
9329
9359
  id: isSet3(object.id) ? globalThis.String(object.id) : "",
9330
9360
  module_key: isSet3(object.moduleKey) ? globalThis.String(object.moduleKey) : isSet3(object.module_key) ? globalThis.String(object.module_key) : "",
9331
- source_id: isSet3(object.sourceId) ? globalThis.String(object.sourceId) : isSet3(object.source_id) ? globalThis.String(object.source_id) : ""
9361
+ source_id: isSet3(object.sourceId) ? globalThis.String(object.sourceId) : isSet3(object.source_id) ? globalThis.String(object.source_id) : "",
9362
+ group_id: isSet3(object.groupId) ? globalThis.String(object.groupId) : isSet3(object.group_id) ? globalThis.String(object.group_id) : ""
9332
9363
  };
9333
9364
  },
9334
9365
  toJSON(message) {
@@ -9345,6 +9376,9 @@ var CreatedRef = {
9345
9376
  if (message.source_id !== "") {
9346
9377
  obj.sourceId = message.source_id;
9347
9378
  }
9379
+ if (message.group_id !== "") {
9380
+ obj.groupId = message.group_id;
9381
+ }
9348
9382
  return obj;
9349
9383
  },
9350
9384
  create(base) {
@@ -9356,6 +9390,7 @@ var CreatedRef = {
9356
9390
  message.id = object.id ?? "";
9357
9391
  message.module_key = object.module_key ?? "";
9358
9392
  message.source_id = object.source_id ?? "";
9393
+ message.group_id = object.group_id ?? "";
9359
9394
  return message;
9360
9395
  }
9361
9396
  };
@@ -10868,6 +10903,7 @@ function endEngine(proc, graceMs = EXIT_GRACE_MS) {
10868
10903
  var HANDSHAKE_TIMEOUT_MS = 1e4;
10869
10904
  var VERSION_RE = /^LACE_ENGINE_VERSION=(.+)$/;
10870
10905
  var PROTOCOL_RE = /^LACE_ENGINE_PROTOCOL_VERSION=(\d+)$/;
10906
+ var CONTRACT_RE = /^LACE_ENGINE_CONTRACT=([0-9a-f]{64})$/;
10871
10907
  var PORT_RE = /^LACE_ENGINE_PORT=(\d+)$/;
10872
10908
  var TOKEN_PREFIX = "LACE_ENGINE_TOKEN=";
10873
10909
  var TOKEN_RE = new RegExp(`^${TOKEN_PREFIX}([0-9a-fA-F]{64})$`);
@@ -10904,6 +10940,7 @@ function spawnEngine(binaryPath, log) {
10904
10940
  const rl = readline.createInterface({ input: proc.stdout });
10905
10941
  let version;
10906
10942
  let protocolVersion;
10943
+ let contract = "";
10907
10944
  let port;
10908
10945
  let token;
10909
10946
  let settled = false;
@@ -10931,6 +10968,11 @@ function spawnEngine(binaryPath, log) {
10931
10968
  protocolVersion = match[1];
10932
10969
  return;
10933
10970
  }
10971
+ match = line.match(CONTRACT_RE);
10972
+ if (match) {
10973
+ contract = match[1];
10974
+ return;
10975
+ }
10934
10976
  match = line.match(PORT_RE);
10935
10977
  if (match) {
10936
10978
  port = Number(match[1]);
@@ -10950,7 +10992,7 @@ function spawnEngine(binaryPath, log) {
10950
10992
  clearTimeout(timer);
10951
10993
  resolve({
10952
10994
  process: proc,
10953
- handshake: { version, protocolVersion, port, token }
10995
+ handshake: { version, protocolVersion, contract, port, token }
10954
10996
  });
10955
10997
  }
10956
10998
  });
@@ -11017,7 +11059,7 @@ function requireClient(client, action) {
11017
11059
 
11018
11060
  // src/server-manager.ts
11019
11061
  import { EventEmitter } from "events";
11020
- import { checkEngineProtocol } from "@lace-cloud/proto";
11062
+ import { checkEngineIdentity } from "@lace-cloud/proto";
11021
11063
 
11022
11064
  // src/transport.ts
11023
11065
  import * as grpc from "@grpc/grpc-js";
@@ -11115,10 +11157,10 @@ var ServerManager = class extends EventEmitter {
11115
11157
  }
11116
11158
  /**
11117
11159
  * Spawns the engine and connects to it. The handshake's protocol version
11118
- * is compared with the one this library speaks before any RPC is sent
11119
- * (`checkEngineProtocol`, `@lace-cloud/proto`, the check the canvas makes
11120
- * of `Initialize`'s answer): an engine that names another rejects with
11121
- * `EngineProtocolMismatchError`. A binary that cannot be started rejects
11160
+ * and contract are compared with the ones this library was built from
11161
+ * before any RPC is sent (`checkEngineIdentity`, `@lace-cloud/proto`, the
11162
+ * check the canvas makes of `Initialize`'s answer): an engine that names
11163
+ * another, or no contract, rejects with `EngineIdentityMismatchError`. A binary that cannot be started rejects
11122
11164
  * with `EngineSpawnError`, whose `code` is the spawn error's (`ENOENT`
11123
11165
  * when no executable is found, `EINVAL` when Windows refuses to start a
11124
11166
  * `.cmd` or `.bat`).
@@ -11145,7 +11187,11 @@ var ServerManager = class extends EventEmitter {
11145
11187
  this.maybeRestart();
11146
11188
  }
11147
11189
  });
11148
- checkEngineProtocol(handshake.version, handshake.protocolVersion);
11190
+ checkEngineIdentity({
11191
+ version: handshake.version,
11192
+ protocol: handshake.protocolVersion,
11193
+ contract: handshake.contract
11194
+ });
11149
11195
  this._handshake = handshake;
11150
11196
  this._transport = new LaceTransport(handshake.port, handshake.token);
11151
11197
  this._initialized = await this._transport.initialize(handshake.version);
@@ -11226,7 +11272,7 @@ var ServerManager = class extends EventEmitter {
11226
11272
  export {
11227
11273
  BundleState,
11228
11274
  BundleStateEvent,
11229
- EngineProtocolMismatchError,
11275
+ EngineIdentityMismatchError,
11230
11276
  EngineSpawnError,
11231
11277
  InitializeResponse,
11232
11278
  InvokeEvent,