@lace-cloud/canvas 0.24.0 → 0.26.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.
@@ -32,6 +32,7 @@ __export(engine_exports, {
32
32
  InputMode: () => InputMode,
33
33
  Reason: () => Reason,
34
34
  SCHEMAS: () => SCHEMAS,
35
+ answering: () => answering,
35
36
  autosave: () => autosave,
36
37
  bridgeCaller: () => bridgeCaller,
37
38
  carriesFailure: () => carriesFailure,
@@ -42,6 +43,7 @@ __export(engine_exports, {
42
43
  defineCommand: () => defineCommand,
43
44
  diagnosticsOf: () => diagnosticsOf,
44
45
  diagnosticsOfDocument: () => diagnosticsOfDocument,
46
+ failureSays: () => failureSays,
45
47
  foldReport: () => foldReport,
46
48
  isBoundPath: () => isBoundPath,
47
49
  liveSlots: () => liveSlots,
@@ -3606,7 +3608,7 @@ function conflictChoiceToJSON(object) {
3606
3608
  }
3607
3609
  }
3608
3610
  function createBaseReasonDetail() {
3609
- return { reason: 0, api_code: "" };
3611
+ return { reason: 0, api_code: "", request_id: "" };
3610
3612
  }
3611
3613
  var ReasonDetail = {
3612
3614
  encode(message, writer = new import_wire4.BinaryWriter()) {
@@ -3616,6 +3618,9 @@ var ReasonDetail = {
3616
3618
  if (message.api_code !== "") {
3617
3619
  writer.uint32(18).string(message.api_code);
3618
3620
  }
3621
+ if (message.request_id !== "") {
3622
+ writer.uint32(26).string(message.request_id);
3623
+ }
3619
3624
  return writer;
3620
3625
  },
3621
3626
  decode(input, length) {
@@ -3639,6 +3644,13 @@ var ReasonDetail = {
3639
3644
  message.api_code = reader.string();
3640
3645
  continue;
3641
3646
  }
3647
+ case 3: {
3648
+ if (tag !== 26) {
3649
+ break;
3650
+ }
3651
+ message.request_id = reader.string();
3652
+ continue;
3653
+ }
3642
3654
  }
3643
3655
  if ((tag & 7) === 4 || tag === 0) {
3644
3656
  break;
@@ -3650,7 +3662,8 @@ var ReasonDetail = {
3650
3662
  fromJSON(object) {
3651
3663
  return {
3652
3664
  reason: isSet3(object.reason) ? reasonFromJSON(object.reason) : 0,
3653
- api_code: isSet3(object.apiCode) ? globalThis.String(object.apiCode) : isSet3(object.api_code) ? globalThis.String(object.api_code) : ""
3665
+ api_code: isSet3(object.apiCode) ? globalThis.String(object.apiCode) : isSet3(object.api_code) ? globalThis.String(object.api_code) : "",
3666
+ request_id: isSet3(object.requestId) ? globalThis.String(object.requestId) : isSet3(object.request_id) ? globalThis.String(object.request_id) : ""
3654
3667
  };
3655
3668
  },
3656
3669
  toJSON(message) {
@@ -3661,6 +3674,9 @@ var ReasonDetail = {
3661
3674
  if (message.api_code !== "") {
3662
3675
  obj.apiCode = message.api_code;
3663
3676
  }
3677
+ if (message.request_id !== "") {
3678
+ obj.requestId = message.request_id;
3679
+ }
3664
3680
  return obj;
3665
3681
  },
3666
3682
  create(base) {
@@ -3670,6 +3686,7 @@ var ReasonDetail = {
3670
3686
  const message = createBaseReasonDetail();
3671
3687
  message.reason = object.reason ?? 0;
3672
3688
  message.api_code = object.api_code ?? "";
3689
+ message.request_id = object.request_id ?? "";
3673
3690
  return message;
3674
3691
  }
3675
3692
  };
@@ -8028,7 +8045,7 @@ var InvokeRequest = {
8028
8045
  }
8029
8046
  };
8030
8047
  function createBaseInvokeEvent() {
8031
- return { json: void 0, exit: void 0 };
8048
+ return { json: void 0, exit: void 0, started: void 0 };
8032
8049
  }
8033
8050
  var InvokeEvent = {
8034
8051
  encode(message, writer = new import_wire4.BinaryWriter()) {
@@ -8038,6 +8055,9 @@ var InvokeEvent = {
8038
8055
  if (message.exit !== void 0) {
8039
8056
  InvokeExit.encode(message.exit, writer.uint32(18).fork()).join();
8040
8057
  }
8058
+ if (message.started !== void 0) {
8059
+ InvokeStarted.encode(message.started, writer.uint32(26).fork()).join();
8060
+ }
8041
8061
  return writer;
8042
8062
  },
8043
8063
  decode(input, length) {
@@ -8061,6 +8081,13 @@ var InvokeEvent = {
8061
8081
  message.exit = InvokeExit.decode(reader, reader.uint32());
8062
8082
  continue;
8063
8083
  }
8084
+ case 3: {
8085
+ if (tag !== 26) {
8086
+ break;
8087
+ }
8088
+ message.started = InvokeStarted.decode(reader, reader.uint32());
8089
+ continue;
8090
+ }
8064
8091
  }
8065
8092
  if ((tag & 7) === 4 || tag === 0) {
8066
8093
  break;
@@ -8072,7 +8099,8 @@ var InvokeEvent = {
8072
8099
  fromJSON(object) {
8073
8100
  return {
8074
8101
  json: isSet3(object.json) ? globalThis.String(object.json) : void 0,
8075
- exit: isSet3(object.exit) ? InvokeExit.fromJSON(object.exit) : void 0
8102
+ exit: isSet3(object.exit) ? InvokeExit.fromJSON(object.exit) : void 0,
8103
+ started: isSet3(object.started) ? InvokeStarted.fromJSON(object.started) : void 0
8076
8104
  };
8077
8105
  },
8078
8106
  toJSON(message) {
@@ -8083,6 +8111,9 @@ var InvokeEvent = {
8083
8111
  if (message.exit !== void 0) {
8084
8112
  obj.exit = InvokeExit.toJSON(message.exit);
8085
8113
  }
8114
+ if (message.started !== void 0) {
8115
+ obj.started = InvokeStarted.toJSON(message.started);
8116
+ }
8086
8117
  return obj;
8087
8118
  },
8088
8119
  create(base) {
@@ -8092,6 +8123,44 @@ var InvokeEvent = {
8092
8123
  const message = createBaseInvokeEvent();
8093
8124
  message.json = object.json ?? void 0;
8094
8125
  message.exit = object.exit !== void 0 && object.exit !== null ? InvokeExit.fromPartial(object.exit) : void 0;
8126
+ message.started = object.started !== void 0 && object.started !== null ? InvokeStarted.fromPartial(object.started) : void 0;
8127
+ return message;
8128
+ }
8129
+ };
8130
+ function createBaseInvokeStarted() {
8131
+ return {};
8132
+ }
8133
+ var InvokeStarted = {
8134
+ encode(_, writer = new import_wire4.BinaryWriter()) {
8135
+ return writer;
8136
+ },
8137
+ decode(input, length) {
8138
+ const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
8139
+ const end = length === void 0 ? reader.len : reader.pos + length;
8140
+ const message = createBaseInvokeStarted();
8141
+ while (reader.pos < end) {
8142
+ const tag = reader.uint32();
8143
+ switch (tag >>> 3) {
8144
+ }
8145
+ if ((tag & 7) === 4 || tag === 0) {
8146
+ break;
8147
+ }
8148
+ reader.skip(tag & 7);
8149
+ }
8150
+ return message;
8151
+ },
8152
+ fromJSON(_) {
8153
+ return {};
8154
+ },
8155
+ toJSON(_) {
8156
+ const obj = {};
8157
+ return obj;
8158
+ },
8159
+ create(base) {
8160
+ return InvokeStarted.fromPartial(base ?? {});
8161
+ },
8162
+ fromPartial(_) {
8163
+ const message = createBaseInvokeStarted();
8095
8164
  return message;
8096
8165
  }
8097
8166
  };
@@ -10370,8 +10439,9 @@ var LaceEngineDefinition = {
10370
10439
  options: {}
10371
10440
  },
10372
10441
  /**
10373
- * Runs one CLI command in-process against a fresh command tree. The command's `-o json` output is the stream:
10374
- * each top-level JSON value on stdout is one `json` event; `exit` is always last.
10442
+ * Runs one CLI command in-process against a fresh command tree. `started` is first, once the engine has accepted
10443
+ * the request and before the command runs; the command's `-o json` output follows: each top-level JSON value on
10444
+ * stdout is one `json` event; `exit` is always last.
10375
10445
  */
10376
10446
  invoke: {
10377
10447
  name: "Invoke",
@@ -10446,6 +10516,7 @@ function isSet3(value) {
10446
10516
  }
10447
10517
 
10448
10518
  // src/ports.ts
10519
+ var import_proto = require("@lace-cloud/proto");
10449
10520
  var ApplyUnobservedError = class extends Error {
10450
10521
  constructor(end) {
10451
10522
  super(`unobserved: the source stopped (${end.kind}) before the frame that carries the write`);
@@ -10465,7 +10536,9 @@ var ConnectError = class extends Error {
10465
10536
  super(`[${code}] ${message}`);
10466
10537
  this.code = code;
10467
10538
  this.reason = detail.reason;
10468
- this.apiCode = detail.api_code === "" ? void 0 : detail.api_code;
10539
+ const { apiCode, requestId } = (0, import_proto.apiFields)(detail);
10540
+ this.apiCode = apiCode;
10541
+ this.requestId = requestId;
10469
10542
  this.name = "ConnectError";
10470
10543
  }
10471
10544
  };
@@ -10742,7 +10815,8 @@ function parseBridgeResponse(raw) {
10742
10815
  return null;
10743
10816
  }
10744
10817
  const apiCode = "apiCode" in raw && typeof raw.apiCode === "string" ? raw.apiCode : void 0;
10745
- return { kind, id, code, message, reason, apiCode };
10818
+ const requestId = "requestId" in raw && typeof raw.requestId === "string" ? raw.requestId : void 0;
10819
+ return { kind, id, code, message, reason, apiCode, requestId };
10746
10820
  }
10747
10821
  return null;
10748
10822
  }
@@ -10750,7 +10824,11 @@ function frameError(frame) {
10750
10824
  return new ConnectError(
10751
10825
  frame.code,
10752
10826
  frame.message,
10753
- ReasonDetail.fromJSON({ reason: frame.reason, api_code: frame.apiCode })
10827
+ ReasonDetail.fromJSON({
10828
+ reason: frame.reason,
10829
+ api_code: frame.apiCode,
10830
+ request_id: frame.requestId
10831
+ })
10754
10832
  );
10755
10833
  }
10756
10834
  function bridgeCaller(bridge) {
@@ -10835,7 +10913,7 @@ function bridgeCaller(bridge) {
10835
10913
  }
10836
10914
 
10837
10915
  // src/adapters/engine/mapping.ts
10838
- var import_proto = require("@lace-cloud/proto");
10916
+ var import_proto2 = require("@lace-cloud/proto");
10839
10917
 
10840
10918
  // src/contracts/commands.gen.ts
10841
10919
  var COMMANDS = {
@@ -12171,7 +12249,8 @@ var commandFailureSchema = import_zod.z.strictObject({
12171
12249
  tool: import_zod.z.string().optional(),
12172
12250
  importResiduals: import_zod.z.array(importResidualSchema).optional(),
12173
12251
  addresses: import_zod.z.array(import_zod.z.string()).optional(),
12174
- apiCode: import_zod.z.string().optional()
12252
+ apiCode: import_zod.z.string().optional(),
12253
+ requestId: import_zod.z.string().optional()
12175
12254
  });
12176
12255
  var moduleValidateDeviationSchema = import_zod.z.object({
12177
12256
  notCompositional: import_zod.z.boolean(),
@@ -12610,18 +12689,16 @@ var stackScanSchema = import_zod.z.object({
12610
12689
  driftCount: import_zod.z.number(),
12611
12690
  scannedAt: import_zod.z.string(),
12612
12691
  undeterminedReason: import_zod.z.string().nullable(),
12692
+ undeterminedMessage: import_zod.z.string().nullable(),
12613
12693
  standingDriftFindings: import_zod.z.number(),
12614
12694
  footprintDestroyed: import_zod.z.boolean(),
12615
12695
  drift: driftSchema
12616
12696
  }).nullable()
12617
12697
  });
12618
- var stackImportSchema = import_zod.z.object({
12698
+ var stackImportSchema = moduleConvertResultSchema.extend({
12619
12699
  stack: stackIdentSchema,
12620
- written: import_zod.z.array(import_zod.z.string()),
12621
- removed: import_zod.z.array(import_zod.z.string()),
12622
12700
  importBlocks: import_zod.z.number(),
12623
- importResiduals: import_zod.z.array(importResidualSchema),
12624
- validate: moduleValidateResultSchema
12701
+ importResiduals: import_zod.z.array(importResidualSchema)
12625
12702
  });
12626
12703
  var artifactRefSchema = import_zod.z.object({ url: import_zod.z.string(), key: import_zod.z.string() });
12627
12704
  var runPlanSchema = import_zod.z.object({
@@ -12783,9 +12860,9 @@ function isolated(report) {
12783
12860
  async function initialize(caller) {
12784
12861
  const initialize2 = await caller.unary("Initialize", {
12785
12862
  client_version: "@lace-cloud/canvas",
12786
- protocol_version: import_proto.ENGINE_PROTOCOL_VERSION
12863
+ protocol_version: import_proto2.ENGINE_PROTOCOL_VERSION
12787
12864
  });
12788
- (0, import_proto.checkEngineProtocol)(initialize2.server_version, initialize2.protocol_version);
12865
+ (0, import_proto2.checkEngineProtocol)(initialize2.server_version, initialize2.protocol_version);
12789
12866
  return new Set(initialize2.command_paths);
12790
12867
  }
12791
12868
  async function openEngineCommands(caller, { cwd }) {
@@ -12810,7 +12887,7 @@ async function openEngineSession(caller, target, options = {}) {
12810
12887
  let stopped = null;
12811
12888
  const revisionWaiters = /* @__PURE__ */ new Set();
12812
12889
  function adopt(state) {
12813
- const published = state.bundle ?? import_proto.EMPTY_BUNDLE;
12890
+ const published = state.bundle ?? import_proto2.EMPTY_BUNDLE;
12814
12891
  const bundle = currentSource && deepEqual(currentSource.bundle, published) ? currentSource.bundle : published;
12815
12892
  sessionGenerating = state.generating;
12816
12893
  currentSource = {
@@ -12822,7 +12899,7 @@ async function openEngineSession(caller, target, options = {}) {
12822
12899
  conflict: state.conflict ? { baseTreeHash: state.conflict.base_tree_hash, treeHash: state.conflict.tree_hash } : null,
12823
12900
  sourceRefused: state.source_refused,
12824
12901
  generating: generating(),
12825
- diagnostics: state.diagnostics.map(import_proto.convertDiagnostic),
12902
+ diagnostics: state.diagnostics.map(import_proto2.convertDiagnostic),
12826
12903
  treeHash: state.tree_hash
12827
12904
  };
12828
12905
  for (const listener of sourceListeners) deliver(listener, currentSource);
@@ -12858,6 +12935,7 @@ async function openEngineSession(caller, target, options = {}) {
12858
12935
  revisionWaiters.clear();
12859
12936
  }
12860
12937
  function publishCommandResult(result) {
12938
+ commandResults.delete(result.path);
12861
12939
  commandResults.set(result.path, result);
12862
12940
  for (const listener of commandResultListeners) deliver(listener, result);
12863
12941
  }
@@ -13004,7 +13082,7 @@ function commandsPort(caller, commandPaths, ownCwd) {
13004
13082
  working_directory: cwd
13005
13083
  };
13006
13084
  async function* run() {
13007
- for await (const event of caller.stream("Invoke", request, signal)) {
13085
+ for await (const event of untilExit()) {
13008
13086
  if (event.json !== void 0) {
13009
13087
  const data = JSON.parse(event.json);
13010
13088
  if (carriesFailure(data)) continue;
@@ -13022,8 +13100,28 @@ function commandsPort(caller, commandPaths, ownCwd) {
13022
13100
  return;
13023
13101
  }
13024
13102
  }
13025
- if (signal.aborted) throw new CommandDetachedError();
13026
- throw new CommandUnobservedError();
13103
+ }
13104
+ async function* untilExit() {
13105
+ let started = false;
13106
+ const stopped = (error) => {
13107
+ if (signal.aborted) return new CommandDetachedError();
13108
+ if (started) return new CommandUnobservedError();
13109
+ return error;
13110
+ };
13111
+ try {
13112
+ for await (const event of caller.stream("Invoke", request, signal)) {
13113
+ started || (started = event.started !== void 0);
13114
+ yield event;
13115
+ }
13116
+ } catch (error) {
13117
+ throw stopped(error);
13118
+ }
13119
+ throw stopped(
13120
+ new ConnectError(
13121
+ "internal",
13122
+ "the engine ended the Invoke stream before it started the command"
13123
+ )
13124
+ );
13027
13125
  }
13028
13126
  return {
13029
13127
  events: run(),
@@ -13097,407 +13195,71 @@ function convertCreatedRef(r) {
13097
13195
  return { scope: r.scope, id: r.id, moduleKey: r.module_key, sourceId: r.source_id };
13098
13196
  }
13099
13197
 
13100
- // src/core/define-command.ts
13101
- function errorNotice(err) {
13102
- if (err instanceof CommandExitError) {
13103
- return err.failure ? [err.stderrTail, err.failure] : [err.stderrTail];
13104
- }
13105
- if (err instanceof Error) return [err.message];
13106
- return [String(err)];
13198
+ // src/core/diagnostics.ts
13199
+ var NOT_LACE_SHAPE = "not_lace_shape";
13200
+ function holdsLaceShapeRefusal(diagnostics) {
13201
+ return diagnostics.some((d) => d.code === NOT_LACE_SHAPE);
13107
13202
  }
13108
- function defineCommand(binding) {
13109
- return {
13110
- kind: "command",
13111
- path: binding.path,
13112
- confirms: binding.confirm !== void 0,
13113
- resultKind: binding.result.kind,
13114
- invalidates: binding.invalidates,
13115
- partialArgs(ctx, target) {
13116
- return binding.args(ctx, target);
13117
- },
13118
- confirmSpec(ctx, target, formArgs) {
13119
- if (!binding.confirm) return void 0;
13120
- const merged = completeArgs(binding.path, { ...binding.args(ctx, target), ...formArgs });
13121
- if (!merged.ok) return void 0;
13122
- return binding.confirm(ctx, merged.args, target);
13123
- },
13124
- async start(rt, ctx, target, formArgs, signal) {
13125
- const merged = completeArgs(binding.path, { ...binding.args(ctx, target), ...formArgs });
13126
- if (!merged.ok) return null;
13127
- const commands = rt.ports.commands;
13128
- if (!commands) return null;
13129
- const invocation = commands.invoke(binding.path, merged.args, signal, rt.cwd);
13130
- rt.begin();
13131
- if (binding.invalidates === "start+settle") rt.tick();
13132
- void (async () => {
13133
- try {
13134
- for await (const event of invocation.events) {
13135
- binding.result.consume(rt, event);
13136
- }
13137
- if (binding.invalidates) rt.tick();
13138
- } catch (err) {
13139
- if (!rt.fail(err) && !(err instanceof CommandDetachedError)) {
13140
- rt.ports.presenter.notify("error", ...errorNotice(err));
13141
- }
13142
- if (binding.invalidates) rt.tick();
13143
- } finally {
13144
- rt.settled?.();
13145
- }
13146
- })();
13147
- return { cancel: () => invocation.cancel() };
13148
- }
13149
- };
13203
+ function findingKey(d) {
13204
+ return JSON.stringify([
13205
+ d.file,
13206
+ d.line,
13207
+ d.message,
13208
+ d.module_key,
13209
+ d.instance_id,
13210
+ d.input_name,
13211
+ d.address
13212
+ ]);
13150
13213
  }
13151
-
13152
- // src/core/actions.ts
13153
- function slotSink(kind) {
13154
- return { kind, consume: (rt, e) => rt.write(kind, rt.token, e) };
13214
+ function uniqueDiagnostics(diagnostics) {
13215
+ const seen = /* @__PURE__ */ new Set();
13216
+ return diagnostics.filter((d) => {
13217
+ const key = findingKey(d);
13218
+ if (seen.has(key)) return false;
13219
+ seen.add(key);
13220
+ return true;
13221
+ });
13155
13222
  }
13156
- var apply = defineCommand({
13157
- kind: "command",
13158
- path: "stack apply",
13159
- args: (ctx) => ({ stack: ctx.stack?.id }),
13160
- // The run sink ticks at both start and settle, so a read keyed on the
13161
- // tick (a host's run list, the describe overlay) sees the in-flight run
13162
- // as soon as it starts, not only once it ends.
13163
- invalidates: "start+settle",
13164
- result: slotSink("run")
13165
- });
13166
- var destroy = defineCommand({
13167
- kind: "command",
13168
- path: "stack destroy",
13169
- args: (ctx) => ({ stack: ctx.stack?.id, yes: true }),
13170
- // The typed confirmation is the stack's slug — the human-facing name a
13171
- // user actually reads off the host's stack list — never its id, which
13172
- // `args.stack` carries for the command itself but nobody types from
13173
- // memory.
13174
- confirm: (ctx) => ({
13175
- text: `Destroy ${ctx.stack?.slug}? This runs terraform destroy on the runner.`,
13176
- typed: ctx.stack?.slug
13177
- }),
13178
- invalidates: "start+settle",
13179
- result: slotSink("run")
13180
- });
13181
- function scanNotice(e) {
13182
- const { slug } = e.stack;
13183
- const settled = e.settled;
13184
- if (!settled) {
13185
- return e.triggered ? `Drift scan triggered for stack ${slug} (${e.stack.id}).` : `Drift scan already in progress for stack ${slug}.`;
13186
- }
13187
- if (settled.undeterminedReason !== null) return void 0;
13188
- if (settled.footprintDestroyed) {
13189
- return `Drift scan complete for stack ${slug}: IN_SYNC (0 drifted) \u2014 its resources were destroyed, so there was nothing to compare.`;
13190
- }
13191
- if (settled.standingDriftFindings > 0) {
13192
- return `Drift scan complete for stack ${slug}: the scan observed no drift, but ${settled.standingDriftFindings} drift finding(s) from earlier scans still stand \u2014 the stack remains DRIFTED.`;
13193
- }
13194
- return `Drift scan complete for stack ${slug}: ${settled.driftStatus} (${settled.driftCount} drifted).`;
13223
+ function diagnosticsOf(sourceDiagnostics, reportFindings) {
13224
+ return uniqueDiagnostics([...sourceDiagnostics, ...reportFindings]);
13195
13225
  }
13196
- var scan = defineCommand({
13197
- kind: "command",
13198
- path: "stack scan",
13199
- args: (ctx) => ({ stack: ctx.stack?.id, wait: true }),
13200
- invalidates: true,
13201
- result: {
13202
- kind: "notify",
13203
- consume: (rt, e) => {
13204
- const notice = scanNotice(e);
13205
- if (notice !== void 0) rt.ports.presenter.notify("info", notice);
13206
- }
13226
+
13227
+ // src/core/report-fold.ts
13228
+ var REPORT_PATHS = ["module validate", "module convert", "module scan"];
13229
+ var FOLDS_AS = new Map([
13230
+ ...REPORT_PATHS.map((path) => [path, path]),
13231
+ ["stack import", "module convert"]
13232
+ ]);
13233
+ var EMPTY_REPORT_FOLD = /* @__PURE__ */ new Map();
13234
+ function readEntry(path, exitCode, data) {
13235
+ if (carriesFailure(data)) {
13236
+ return { kind: "failure", path, exitCode, failure: parseCommandFailure(data) };
13207
13237
  }
13208
- });
13209
- var create = defineCommand({
13210
- kind: "command",
13211
- path: "stack create",
13212
- args: (ctx) => ({ source: ctx.root }),
13213
- invalidates: true,
13214
- result: {
13215
- kind: "notify",
13216
- consume: (rt, e) => rt.ports.presenter.notify("info", `Created stack ${e.slug}`)
13238
+ switch (path) {
13239
+ case "module validate":
13240
+ return { kind: "result", path, exitCode, document: parseBound(path, data) };
13241
+ case "module convert":
13242
+ return { kind: "result", path, exitCode, document: parseBound(path, data) };
13243
+ case "module scan":
13244
+ return { kind: "result", path, exitCode, document: parseBound(path, data) };
13217
13245
  }
13218
- });
13219
- function residualAddresses(residuals) {
13220
- return residuals.map((r) => r.address).join(", ");
13221
13246
  }
13222
- function treeChanges(e) {
13223
- return [
13224
- ...e.written.length === 0 ? [] : [`rewriting ${e.written.join(", ")} in place`],
13225
- ...e.removed.length === 0 ? [] : [`removing ${e.removed.join(", ")}`]
13226
- ];
13247
+ function foldReport(prev, result) {
13248
+ const path = FOLDS_AS.get(result.path);
13249
+ if (path === void 0) return prev;
13250
+ const next = new Map(prev);
13251
+ if (result.document === "") next.delete(path);
13252
+ else next.set(path, readEntry(path, result.exitCode, JSON.parse(result.document)));
13253
+ return next;
13227
13254
  }
13228
- function importNotice(e) {
13229
- const { slug } = e.stack;
13230
- const changes = treeChanges(e);
13231
- const changed = changes.length > 0;
13232
- const files = changed ? `, ${changes.join(" and ")}` : "";
13233
- const imported = `Imported ${e.importBlocks} resource(s) into ${slug}${files}.`;
13234
- if (e.validate.exitClass !== "ok") {
13235
- return ["warn", `${imported} The tree did not validate: fix it before you commit it.`];
13236
- }
13237
- const adopt = changed ? ` Review the change in git, commit it, then apply ${slug} to adopt them.` : "";
13238
- if (e.importResiduals.length === 0) return ["info", `${imported}${adopt}`];
13239
- return [
13240
- "warn",
13241
- `${imported}${adopt} Not adopted: ${residualAddresses(e.importResiduals)}; supply their import ids before applying, or the apply creates them anew.`
13242
- ];
13243
- }
13244
- var importResult = {
13245
- kind: "notify",
13246
- consume: (rt, e) => rt.ports.presenter.notify(...importNotice(e))
13247
- };
13248
- var importStack = defineCommand({
13249
- kind: "command",
13250
- path: "stack import",
13251
- args: (ctx) => ({ stack: ctx.stack?.id }),
13252
- invalidates: true,
13253
- result: importResult
13254
- });
13255
- var importPartial = defineCommand({
13256
- kind: "command",
13257
- path: "stack import",
13258
- args: (ctx) => ({ stack: ctx.stack?.id, allowPartial: true }),
13259
- confirm: (ctx, _args, target) => ({
13260
- text: `Import into ${ctx.stack?.slug} without adopting ${residualAddresses(target.failure?.importResiduals ?? [])}? Lace writes no import block for them, so the stack's apply creates them anew beside the live ones.`
13261
- }),
13262
- invalidates: true,
13263
- result: importResult
13264
- });
13265
- var validate = defineCommand({
13266
- kind: "command",
13267
- path: "module validate",
13268
- args: () => ({}),
13269
- result: {
13270
- kind: "notify",
13271
- consume: (rt, e) => {
13272
- if (e.exitClass === "ok") rt.ports.presenter.notify("info", `Valid for Lace \u2014 ${e.verdict}`);
13273
- }
13274
- }
13275
- });
13276
- var convert = defineCommand({
13277
- kind: "command",
13278
- path: "module convert",
13279
- args: () => ({}),
13280
- result: {
13281
- kind: "notify",
13282
- consume: (rt, e) => rt.ports.presenter.notify(
13283
- "info",
13284
- e.changed ? `Converted \u2014 ${e.written.length} file(s) written` : "Already lace-style \u2014 nothing to write"
13285
- )
13286
- }
13287
- });
13288
- var preview = defineCommand({
13289
- kind: "command",
13290
- path: "stack preview",
13291
- args: (ctx) => ({ stack: ctx.stack?.id }),
13292
- result: slotSink("preview")
13293
- });
13294
- var runCancel = defineCommand({
13295
- kind: "command",
13296
- path: "run cancel",
13297
- args: (_ctx, target) => ({ run: target.runId }),
13298
- invalidates: true,
13299
- result: {
13300
- kind: "notify",
13301
- consume: (rt, e) => rt.ports.presenter.notify("info", `Run ${e.id} ${e.status}`)
13302
- }
13303
- });
13304
- var followLogs = defineCommand({
13305
- kind: "command",
13306
- path: "run logs",
13307
- args: (_ctx, target) => ({ run: target.runId, follow: true }),
13308
- result: slotSink("follow")
13309
- });
13310
- var MODULE_COMMAND_ACTIONS = [
13311
- {
13312
- id: "validate",
13313
- label: "Validate",
13314
- icon: "validate",
13315
- section: "check",
13316
- placement: "toolbar",
13317
- requiredPorts: ["commands"],
13318
- requiredContext: ["root"],
13319
- binding: validate
13320
- },
13321
- {
13322
- id: "convert",
13323
- label: "Convert",
13324
- icon: "convert",
13325
- section: "check",
13326
- placement: "toolbar",
13327
- requiredPorts: ["commands"],
13328
- requiredContext: ["root"],
13329
- binding: convert
13330
- },
13331
- // Convert on the source-refused banner while the tree is out of lace
13332
- // shape: the same `module convert` the toolbar runs, and the choice the
13333
- // banner says of it. The engine re-derives the tree it writes, which
13334
- // accepts it and lifts the lock.
13335
- {
13336
- id: "convert-refused",
13337
- label: "Convert",
13338
- choice: "Convert restructures it in place; a stack's apply creates only what its state does not hold yet.",
13339
- icon: "convert",
13340
- placement: { row: "source-refused" },
13341
- requiredPorts: ["commands"],
13342
- requiredContext: ["root", "needsConversion"],
13343
- binding: convert
13344
- }
13345
- ];
13346
- var STACK_COMMAND_ACTIONS = [
13347
- {
13348
- id: "apply",
13349
- label: "Apply",
13350
- placement: "toolbar",
13351
- requiredPorts: ["commands"],
13352
- // `stack apply` gates on the tf and certification of the directory it
13353
- // runs in (submit.Prepare(env.Root)) before it ever reaches the
13354
- // runner, so a mount with no root can't run it even with a stack
13355
- // chosen — the same root gate `validate`/`convert` need. It ships
13356
- // whatever tf is on disk, not the canvas's own working IR.
13357
- requiredContext: ["root", "stack"],
13358
- binding: apply
13359
- },
13360
- {
13361
- id: "destroy",
13362
- label: "Destroy",
13363
- placement: "toolbar",
13364
- requiredPorts: ["commands"],
13365
- // `stack destroy` shares the CLI's `executeRun` with `stack apply` and
13366
- // runs under `env.Root`, so it needs the identical context tuple.
13367
- requiredContext: ["root", "stack"],
13368
- binding: destroy
13369
- },
13370
- {
13371
- id: "scan",
13372
- label: "Scan for drift",
13373
- placement: "toolbar",
13374
- requiredPorts: ["commands"],
13375
- requiredContext: ["stack"],
13376
- binding: scan
13377
- },
13378
- {
13379
- id: "create",
13380
- label: "Create stack",
13381
- placement: "toolbar",
13382
- requiredPorts: ["commands"],
13383
- requiredContext: ["root"],
13384
- binding: create
13385
- },
13386
- {
13387
- id: "import",
13388
- label: "Import existing resources",
13389
- placement: "toolbar",
13390
- requiredPorts: ["commands"],
13391
- // `stack import` writes the directory it runs in, the same way
13392
- // Convert does.
13393
- requiredContext: ["root", "stack"],
13394
- binding: importStack
13395
- },
13396
- {
13397
- id: "import-partial",
13398
- label: "Import the rest",
13399
- placement: { row: "failure" },
13400
- requiredPorts: ["commands"],
13401
- requiredContext: ["root", "stack"],
13402
- answers: ["import_residual"],
13403
- binding: importPartial
13404
- },
13405
- {
13406
- id: "preview",
13407
- label: "Preview",
13408
- placement: "toolbar",
13409
- requiredPorts: ["commands"],
13410
- // `stack preview` plans the tf of the directory it runs in — a stack
13411
- // alone isn't enough, the mount needs the root too.
13412
- requiredContext: ["root", "stack"],
13413
- binding: preview
13414
- },
13415
- {
13416
- id: "run-cancel",
13417
- label: "Cancel",
13418
- placement: { row: "runs" },
13419
- requiredPorts: ["commands"],
13420
- requiredTarget: ["runId"],
13421
- binding: runCancel
13422
- },
13423
- {
13424
- id: "follow-logs",
13425
- label: "Follow logs",
13426
- placement: { row: "runs" },
13427
- requiredPorts: ["commands"],
13428
- requiredTarget: ["runId"],
13429
- binding: followLogs
13430
- }
13431
- ];
13432
- var CORE_COMMAND_ACTIONS = [
13433
- ...STACK_COMMAND_ACTIONS,
13434
- ...MODULE_COMMAND_ACTIONS
13435
- ];
13436
-
13437
- // src/core/diagnostics.ts
13438
- var NOT_LACE_SHAPE = "not_lace_shape";
13439
- function holdsLaceShapeRefusal(diagnostics) {
13440
- return diagnostics.some((d) => d.code === NOT_LACE_SHAPE);
13441
- }
13442
- function findingKey(d) {
13443
- return JSON.stringify([
13444
- d.file,
13445
- d.line,
13446
- d.message,
13447
- d.module_key,
13448
- d.instance_id,
13449
- d.input_name,
13450
- d.address
13451
- ]);
13452
- }
13453
- function uniqueDiagnostics(diagnostics) {
13454
- const seen = /* @__PURE__ */ new Set();
13455
- return diagnostics.filter((d) => {
13456
- const key = findingKey(d);
13457
- if (seen.has(key)) return false;
13458
- seen.add(key);
13459
- return true;
13460
- });
13461
- }
13462
- function diagnosticsOf(sourceDiagnostics, reportFindings) {
13463
- return uniqueDiagnostics([...sourceDiagnostics, ...reportFindings]);
13464
- }
13465
-
13466
- // src/core/report-fold.ts
13467
- var REPORT_PATHS = ["module validate", "module convert", "module scan"];
13468
- var REPORT_PATH_SET = new Set(REPORT_PATHS);
13469
- function isReportPath(path) {
13470
- return REPORT_PATH_SET.has(path);
13471
- }
13472
- var EMPTY_REPORT_FOLD = /* @__PURE__ */ new Map();
13473
- function readEntry(path, exitCode, data) {
13474
- if (carriesFailure(data)) {
13475
- return { kind: "failure", path, exitCode, failure: parseCommandFailure(data) };
13476
- }
13477
- switch (path) {
13478
- case "module validate":
13479
- return { kind: "result", path, exitCode, document: parseBound(path, data) };
13480
- case "module convert":
13481
- return { kind: "result", path, exitCode, document: parseBound(path, data) };
13482
- case "module scan":
13483
- return { kind: "result", path, exitCode, document: parseBound(path, data) };
13484
- }
13485
- }
13486
- function foldReport(prev, result) {
13487
- if (!isReportPath(result.path)) return prev;
13488
- const next = new Map(prev);
13489
- if (result.document === "") next.delete(result.path);
13490
- else next.set(result.path, readEntry(result.path, result.exitCode, JSON.parse(result.document)));
13491
- return next;
13492
- }
13493
- function treeHashOf(entry) {
13494
- if (entry.kind === "failure") return void 0;
13495
- switch (entry.path) {
13496
- case "module validate":
13497
- case "module scan":
13498
- return entry.document.treeHash;
13499
- case "module convert":
13500
- return entry.document.validate.treeHash;
13255
+ function treeHashOf(entry) {
13256
+ if (entry.kind === "failure") return void 0;
13257
+ switch (entry.path) {
13258
+ case "module validate":
13259
+ case "module scan":
13260
+ return entry.document.treeHash;
13261
+ case "module convert":
13262
+ return entry.document.validate.treeHash;
13501
13263
  }
13502
13264
  }
13503
13265
  function currentReport(fold, treeHash) {
@@ -13607,148 +13369,527 @@ function reduceRun(prev, token, event) {
13607
13369
  phases: closePhases(phases)
13608
13370
  };
13609
13371
  }
13610
- return { token, outcome: { kind: "running" }, lastLog, submitted, phases };
13611
- }
13612
- function exitSays(error) {
13613
- return error.failure ? { message: error.stderrTail, failure: error.failure } : { message: error.stderrTail };
13614
- }
13615
- function settleRun(prev, token, error) {
13616
- const carried = prev && prev.token === token ? prev : null;
13617
- const lastLog = carried?.lastLog ?? null;
13618
- const submitted = carried?.submitted ?? false;
13619
- const phases = closePhases(carried?.phases ?? []);
13620
- if (error instanceof CommandDetachedError || error instanceof CommandUnobservedError)
13621
- return { token, outcome: { kind: "detached", submitted }, lastLog, submitted, phases };
13622
- if (error instanceof CommandExitError) {
13623
- if (error.code === 130)
13624
- return { token, outcome: { kind: "cancelled" }, lastLog, submitted, phases };
13625
- if (error.code === 143)
13626
- return { token, outcome: { kind: "detached", submitted }, lastLog, submitted, phases };
13627
- if (error.code === 7)
13628
- return {
13629
- token,
13630
- outcome: { kind: "blocked", ...exitSays(error) },
13631
- lastLog,
13632
- submitted,
13633
- phases
13634
- };
13635
- return {
13636
- token,
13637
- outcome: { kind: "failed", ...exitSays(error) },
13638
- lastLog,
13639
- submitted,
13640
- phases
13641
- };
13372
+ return { token, outcome: { kind: "running" }, lastLog, submitted, phases };
13373
+ }
13374
+ function failureSays(error, command) {
13375
+ if (error instanceof CommandExitError) {
13376
+ return error.failure ? { message: error.failure.message, failure: error.failure } : { message: error.stderrTail };
13377
+ }
13378
+ if (error instanceof CommandUnobservedError && command.kind === "read") {
13379
+ return { message: `the stream ended before \`lace ${command.path}\` finished; run it again` };
13380
+ }
13381
+ return { message: error instanceof Error ? error.message : String(error) };
13382
+ }
13383
+ var RUN = { kind: "write" };
13384
+ function settleRun(prev, token, error) {
13385
+ const carried = prev && prev.token === token ? prev : null;
13386
+ const lastLog = carried?.lastLog ?? null;
13387
+ const submitted = carried?.submitted ?? false;
13388
+ const phases = closePhases(carried?.phases ?? []);
13389
+ if (error instanceof CommandDetachedError || error instanceof CommandUnobservedError)
13390
+ return { token, outcome: { kind: "detached", submitted }, lastLog, submitted, phases };
13391
+ if (error instanceof CommandExitError) {
13392
+ if (error.code === 130)
13393
+ return { token, outcome: { kind: "cancelled" }, lastLog, submitted, phases };
13394
+ if (error.code === 143)
13395
+ return { token, outcome: { kind: "detached", submitted }, lastLog, submitted, phases };
13396
+ if (error.code === 7)
13397
+ return {
13398
+ token,
13399
+ outcome: { kind: "blocked", ...failureSays(error, RUN) },
13400
+ lastLog,
13401
+ submitted,
13402
+ phases
13403
+ };
13404
+ }
13405
+ return {
13406
+ token,
13407
+ outcome: { kind: "failed", ...failureSays(error, RUN) },
13408
+ lastLog,
13409
+ submitted,
13410
+ phases
13411
+ };
13412
+ }
13413
+ function reducePreview(_prev, token, event) {
13414
+ return { token, data: event };
13415
+ }
13416
+ function reduceReport(prev, session, result) {
13417
+ const fold = foldReport(prev?.sessions.get(session) ?? EMPTY_REPORT_FOLD, result);
13418
+ return { sessions: new Map(prev?.sessions).set(session, fold) };
13419
+ }
13420
+ function reduceFollow(prev, token, event) {
13421
+ const carried = prev && prev.token === token ? prev : null;
13422
+ const runId = carried?.runId ?? "";
13423
+ const lines = carried?.lines ?? [];
13424
+ if (event.type === "log") return { token, runId, lines: [...lines, event.text], done: false };
13425
+ return { token, runId, lines, done: true };
13426
+ }
13427
+ function createResultStore() {
13428
+ let slots = {
13429
+ run: null,
13430
+ preview: null,
13431
+ report: null,
13432
+ follow: null,
13433
+ running: /* @__PURE__ */ new Map()
13434
+ };
13435
+ let tick = 0;
13436
+ const listeners = /* @__PURE__ */ new Set();
13437
+ const notify = () => {
13438
+ for (const listener of listeners) listener();
13439
+ };
13440
+ const retiredTokens = /* @__PURE__ */ new WeakSet();
13441
+ return {
13442
+ getSnapshot() {
13443
+ return slots;
13444
+ },
13445
+ getTick() {
13446
+ return tick;
13447
+ },
13448
+ subscribe(listener) {
13449
+ listeners.add(listener);
13450
+ return () => listeners.delete(listener);
13451
+ },
13452
+ write(kind, token, value, readOver) {
13453
+ if (retiredTokens.has(token)) return;
13454
+ slots = { ...slots, [kind]: applySlot(kind, slots[kind], token, value, readOver) };
13455
+ notify();
13456
+ },
13457
+ fail(kind, token, error) {
13458
+ if (kind !== "run") return false;
13459
+ if (retiredTokens.has(token) || !slots.run) return true;
13460
+ slots = { ...slots, run: stamp(settleRun(slots.run, token, error), slots.run.readOver) };
13461
+ notify();
13462
+ return true;
13463
+ },
13464
+ begin(kind, token, readOver, started) {
13465
+ if (kind === "run") {
13466
+ slots = {
13467
+ ...slots,
13468
+ run: {
13469
+ token,
13470
+ outcome: { kind: "running" },
13471
+ lastLog: null,
13472
+ submitted: false,
13473
+ phases: [],
13474
+ readOver
13475
+ }
13476
+ };
13477
+ } else if (kind === "follow") {
13478
+ slots = {
13479
+ ...slots,
13480
+ follow: { token, runId: started.target.runId ?? "", lines: [], done: false, readOver }
13481
+ };
13482
+ } else if (kind === "notify") {
13483
+ const { on, path, label } = started;
13484
+ slots = { ...slots, running: new Map(slots.running).set(on, { token, path, label }) };
13485
+ } else {
13486
+ return;
13487
+ }
13488
+ notify();
13489
+ },
13490
+ detach(kind, token) {
13491
+ if (kind === "follow" && slots.follow?.token === token) {
13492
+ slots = { ...slots, follow: null };
13493
+ notify();
13494
+ } else if (kind === "report" && slots.report?.sessions.has(token)) {
13495
+ const sessions = new Map(slots.report.sessions);
13496
+ sessions.delete(token);
13497
+ slots = {
13498
+ ...slots,
13499
+ report: sessions.size > 0 ? { sessions, readOver: slots.report.readOver } : null
13500
+ };
13501
+ notify();
13502
+ } else if (kind === "run" && slots.run?.token === token) {
13503
+ const settled = settleRun(slots.run, token, new CommandDetachedError());
13504
+ slots = { ...slots, run: stamp(settled, slots.run.readOver) };
13505
+ notify();
13506
+ } else if (kind === "notify") {
13507
+ const running = new Map([...slots.running].filter(([, mark]) => mark.token !== token));
13508
+ if (running.size !== slots.running.size) {
13509
+ slots = { ...slots, running };
13510
+ notify();
13511
+ }
13512
+ }
13513
+ retiredTokens.add(token);
13514
+ },
13515
+ busy(kind, on) {
13516
+ if (kind === "run") {
13517
+ return slots.run?.outcome.kind === "running" ? { kind: "run" } : void 0;
13518
+ }
13519
+ if (kind !== "notify") return void 0;
13520
+ const running = slots.running.get(on);
13521
+ return running ? { kind: "notify", running } : void 0;
13522
+ },
13523
+ bumpTick() {
13524
+ tick += 1;
13525
+ notify();
13526
+ }
13527
+ };
13528
+ }
13529
+
13530
+ // src/core/define-command.ts
13531
+ function defineCommand(binding) {
13532
+ return {
13533
+ kind: "command",
13534
+ path: binding.path,
13535
+ confirms: binding.confirm !== void 0,
13536
+ resultKind: binding.result.kind,
13537
+ invalidates: binding.invalidates,
13538
+ partialArgs(ctx, target) {
13539
+ return binding.args(ctx, target);
13540
+ },
13541
+ confirmSpec(ctx, target, formArgs) {
13542
+ if (!binding.confirm) return void 0;
13543
+ const merged = completeArgs(binding.path, { ...binding.args(ctx, target), ...formArgs });
13544
+ if (!merged.ok) return void 0;
13545
+ return binding.confirm(ctx, merged.args, target);
13546
+ },
13547
+ async start(rt, ctx, target, formArgs, signal) {
13548
+ const merged = completeArgs(binding.path, { ...binding.args(ctx, target), ...formArgs });
13549
+ if (!merged.ok) return null;
13550
+ const commands = rt.ports.commands;
13551
+ if (!commands) return null;
13552
+ const invocation = commands.invoke(binding.path, merged.args, signal, rt.cwd);
13553
+ rt.begin();
13554
+ if (binding.invalidates === "start+settle") rt.tick();
13555
+ void (async () => {
13556
+ let rendered = false;
13557
+ try {
13558
+ for await (const event of invocation.events) {
13559
+ rendered = true;
13560
+ binding.result.consume(rt, event);
13561
+ }
13562
+ if (binding.invalidates) rt.tick();
13563
+ } catch (err) {
13564
+ const settledByDocument = rendered && binding.result.kind === "notify" && (err instanceof CommandExitError || err instanceof CommandUnobservedError);
13565
+ if (!rt.fail(err) && !(err instanceof CommandDetachedError) && !settledByDocument) {
13566
+ const { message, failure } = failureSays(
13567
+ err,
13568
+ binding.result.kind === "preview" || binding.result.kind === "follow" ? { kind: "read", path: binding.path } : { kind: "write" }
13569
+ );
13570
+ rt.ports.presenter.notify("error", message, ...failure ? [failure] : []);
13571
+ }
13572
+ if (binding.invalidates) rt.tick();
13573
+ } finally {
13574
+ rt.settled?.();
13575
+ }
13576
+ })();
13577
+ return { cancel: () => invocation.cancel() };
13578
+ }
13579
+ };
13580
+ }
13581
+
13582
+ // src/core/actions.ts
13583
+ function whyNotValid(v) {
13584
+ if (v.failure) return v.failure.message;
13585
+ const errors = v.diagnostics.filter((d) => d.severity === "error");
13586
+ if (errors.length === 0) return void 0;
13587
+ return `${errors[0].message} (${errors.length} ${errors.length === 1 ? "error" : "errors"})`;
13588
+ }
13589
+ function didNotValidate(v) {
13590
+ const why = whyNotValid(v);
13591
+ return why === void 0 ? "The tree did not validate: fix it before you commit it." : `The tree did not validate: ${why}. Fix it before you commit it.`;
13592
+ }
13593
+ function beside(v) {
13594
+ return v.failure ? [v.failure] : [];
13595
+ }
13596
+ function slotSink(kind) {
13597
+ return { kind, consume: (rt, e) => rt.write(kind, rt.token, e) };
13598
+ }
13599
+ var apply = defineCommand({
13600
+ kind: "command",
13601
+ path: "stack apply",
13602
+ args: (ctx) => ({ stack: ctx.stack?.id }),
13603
+ // The run sink ticks at both start and settle, so a read keyed on the
13604
+ // tick (a host's run list, the describe overlay) sees the in-flight run
13605
+ // as soon as it starts, not only once it ends.
13606
+ invalidates: "start+settle",
13607
+ result: slotSink("run")
13608
+ });
13609
+ var destroy = defineCommand({
13610
+ kind: "command",
13611
+ path: "stack destroy",
13612
+ args: (ctx) => ({ stack: ctx.stack?.id, yes: true }),
13613
+ // The typed confirmation is the stack's slug — the human-facing name a
13614
+ // user actually reads off the host's stack list — never its id, which
13615
+ // `args.stack` carries for the command itself but nobody types from
13616
+ // memory.
13617
+ confirm: (ctx) => ({
13618
+ text: `Destroy ${ctx.stack?.slug}? This runs terraform destroy on the runner.`,
13619
+ typed: ctx.stack?.slug
13620
+ }),
13621
+ invalidates: "start+settle",
13622
+ result: slotSink("run")
13623
+ });
13624
+ function scanNotice(e) {
13625
+ const { slug } = e.stack;
13626
+ const settled = e.settled;
13627
+ if (!settled) {
13628
+ return [
13629
+ "info",
13630
+ e.triggered ? `Drift scan triggered for stack ${slug} (${e.stack.id}).` : `Drift scan already in progress for stack ${slug}.`
13631
+ ];
13632
+ }
13633
+ if (settled.undeterminedMessage !== null) return ["warn", settled.undeterminedMessage];
13634
+ if (settled.footprintDestroyed) {
13635
+ return [
13636
+ "info",
13637
+ `Drift scan complete for stack ${slug}: IN_SYNC (0 drifted) \u2014 its resources were destroyed, so there was nothing to compare.`
13638
+ ];
13639
+ }
13640
+ if (settled.standingDriftFindings > 0) {
13641
+ return [
13642
+ "info",
13643
+ `Drift scan complete for stack ${slug}: the scan observed no drift, but ${settled.standingDriftFindings} drift finding(s) from earlier scans still stand \u2014 the stack remains DRIFTED.`
13644
+ ];
13645
+ }
13646
+ return [
13647
+ "info",
13648
+ `Drift scan complete for stack ${slug}: ${settled.driftStatus} (${settled.driftCount} drifted).`
13649
+ ];
13650
+ }
13651
+ var scan = defineCommand({
13652
+ kind: "command",
13653
+ path: "stack scan",
13654
+ args: (ctx) => ({ stack: ctx.stack?.id, wait: true }),
13655
+ invalidates: true,
13656
+ result: {
13657
+ kind: "notify",
13658
+ consume: (rt, e) => rt.ports.presenter.notify(...scanNotice(e))
13659
+ }
13660
+ });
13661
+ var create = defineCommand({
13662
+ kind: "command",
13663
+ path: "stack create",
13664
+ args: (ctx) => ({ source: ctx.root }),
13665
+ invalidates: true,
13666
+ result: {
13667
+ kind: "notify",
13668
+ consume: (rt, e) => rt.ports.presenter.notify("info", `Created stack ${e.slug}`)
13669
+ }
13670
+ });
13671
+ function residualAddresses(residuals) {
13672
+ return residuals.map((r) => r.address).join(", ");
13673
+ }
13674
+ function treeChanges(e) {
13675
+ return [
13676
+ ...e.written.length === 0 ? [] : [`rewriting ${e.written.join(", ")} in place`],
13677
+ ...e.removed.length === 0 ? [] : [`removing ${e.removed.join(", ")}`]
13678
+ ];
13679
+ }
13680
+ function importNotice(e) {
13681
+ const { slug } = e.stack;
13682
+ const changes = treeChanges(e);
13683
+ const files = changes.length > 0 ? `, ${changes.join(" and ")}` : "";
13684
+ const imported = `Imported ${e.importBlocks} resource(s) into ${slug}${files}.`;
13685
+ if (e.validate.exitClass !== "ok") {
13686
+ return ["warn", `${imported} ${didNotValidate(e.validate)}`, ...beside(e.validate)];
13687
+ }
13688
+ const adopt = e.changed ? ` Review the change in git, commit it, then apply ${slug} to adopt them.` : "";
13689
+ if (e.importResiduals.length === 0) return ["info", `${imported}${adopt}`];
13690
+ return [
13691
+ "warn",
13692
+ `${imported}${adopt} Not adopted: ${residualAddresses(e.importResiduals)}; supply their import ids before applying, or the apply creates them anew.`
13693
+ ];
13694
+ }
13695
+ var importResult = {
13696
+ kind: "notify",
13697
+ consume: (rt, e) => rt.ports.presenter.notify(...importNotice(e))
13698
+ };
13699
+ var importStack = defineCommand({
13700
+ kind: "command",
13701
+ path: "stack import",
13702
+ args: (ctx) => ({ stack: ctx.stack?.id }),
13703
+ invalidates: true,
13704
+ result: importResult
13705
+ });
13706
+ var importPartial = defineCommand({
13707
+ kind: "command",
13708
+ path: "stack import",
13709
+ args: (ctx) => ({ stack: ctx.stack?.id, allowPartial: true }),
13710
+ confirm: (ctx, _args, target) => ({
13711
+ text: `Import into ${ctx.stack?.slug} without adopting ${residualAddresses(target.failure?.importResiduals ?? [])}? Lace writes no import block for them, so the stack's apply creates them anew beside the live ones.`
13712
+ }),
13713
+ invalidates: true,
13714
+ result: importResult
13715
+ });
13716
+ function validateNotice(v) {
13717
+ if (v.exitClass === "ok") return ["info", `Valid for Lace \u2014 ${v.verdict}`];
13718
+ if (v.failure) return ["error", v.failure.message, v.failure];
13719
+ const why = whyNotValid(v);
13720
+ return ["warn", why === void 0 ? "Not valid for Lace" : `Not valid: ${why}`];
13721
+ }
13722
+ function convertNotice(e) {
13723
+ const converted = e.changed ? `Converted \u2014 ${e.written.length} file(s) written` : "Already lace-style \u2014 nothing to write";
13724
+ if (e.validate.exitClass === "ok") return ["info", converted];
13725
+ return ["warn", `${converted}. ${didNotValidate(e.validate)}`, ...beside(e.validate)];
13726
+ }
13727
+ var validate = defineCommand({
13728
+ kind: "command",
13729
+ path: "module validate",
13730
+ args: () => ({}),
13731
+ result: {
13732
+ kind: "notify",
13733
+ consume: (rt, e) => rt.ports.presenter.notify(...validateNotice(e))
13734
+ }
13735
+ });
13736
+ var convert = defineCommand({
13737
+ kind: "command",
13738
+ path: "module convert",
13739
+ args: () => ({}),
13740
+ result: {
13741
+ kind: "notify",
13742
+ consume: (rt, e) => rt.ports.presenter.notify(...convertNotice(e))
13743
+ }
13744
+ });
13745
+ var preview = defineCommand({
13746
+ kind: "command",
13747
+ path: "stack preview",
13748
+ args: (ctx) => ({ stack: ctx.stack?.id }),
13749
+ result: slotSink("preview")
13750
+ });
13751
+ var runCancel = defineCommand({
13752
+ kind: "command",
13753
+ path: "run cancel",
13754
+ args: (_ctx, target) => ({ run: target.runId }),
13755
+ invalidates: true,
13756
+ result: {
13757
+ kind: "notify",
13758
+ consume: (rt, e) => rt.ports.presenter.notify("info", `Run ${e.id} ${e.status}`)
13759
+ }
13760
+ });
13761
+ var followLogs = defineCommand({
13762
+ kind: "command",
13763
+ path: "run logs",
13764
+ args: (_ctx, target) => ({ run: target.runId, follow: true }),
13765
+ result: slotSink("follow")
13766
+ });
13767
+ var MODULE_COMMAND_ACTIONS = [
13768
+ {
13769
+ id: "validate",
13770
+ label: "Validate",
13771
+ icon: "validate",
13772
+ section: "check",
13773
+ placement: "toolbar",
13774
+ requiredPorts: ["commands"],
13775
+ requiredContext: ["root"],
13776
+ binding: validate
13777
+ },
13778
+ {
13779
+ id: "convert",
13780
+ label: "Convert",
13781
+ icon: "convert",
13782
+ section: "check",
13783
+ placement: "toolbar",
13784
+ requiredPorts: ["commands"],
13785
+ requiredContext: ["root"],
13786
+ binding: convert
13787
+ },
13788
+ // Convert on the source-refused banner while the tree is out of lace
13789
+ // shape: the same `module convert` the toolbar runs, and the choice the
13790
+ // banner says of it. The engine re-derives the tree it writes, which
13791
+ // accepts it and lifts the lock.
13792
+ {
13793
+ id: "convert-refused",
13794
+ label: "Convert",
13795
+ choice: "Convert restructures it in place; a stack's apply creates only what its state does not hold yet.",
13796
+ icon: "convert",
13797
+ placement: { row: "source-refused" },
13798
+ requiredPorts: ["commands"],
13799
+ requiredContext: ["root", "needsConversion"],
13800
+ binding: convert
13801
+ }
13802
+ ];
13803
+ var STACK_COMMAND_ACTIONS = [
13804
+ {
13805
+ id: "apply",
13806
+ label: "Apply",
13807
+ placement: "toolbar",
13808
+ requiredPorts: ["commands"],
13809
+ // `stack apply` gates on the tf and certification of the directory it
13810
+ // runs in (submit.Prepare(env.Root)) before it ever reaches the
13811
+ // runner, so a mount with no root can't run it even with a stack
13812
+ // chosen — the same root gate `validate`/`convert` need. It ships
13813
+ // whatever tf is on disk, not the canvas's own working IR.
13814
+ requiredContext: ["root", "stack"],
13815
+ binding: apply
13816
+ },
13817
+ {
13818
+ id: "destroy",
13819
+ label: "Destroy",
13820
+ placement: "toolbar",
13821
+ requiredPorts: ["commands"],
13822
+ // `stack destroy` shares the CLI's `executeRun` with `stack apply` and
13823
+ // runs under `env.Root`, so it needs the identical context tuple.
13824
+ requiredContext: ["root", "stack"],
13825
+ binding: destroy
13826
+ },
13827
+ {
13828
+ id: "scan",
13829
+ label: "Scan for drift",
13830
+ placement: "toolbar",
13831
+ requiredPorts: ["commands"],
13832
+ requiredContext: ["stack"],
13833
+ binding: scan
13834
+ },
13835
+ {
13836
+ id: "create",
13837
+ label: "Create stack",
13838
+ placement: "toolbar",
13839
+ requiredPorts: ["commands"],
13840
+ requiredContext: ["root"],
13841
+ binding: create
13842
+ },
13843
+ {
13844
+ id: "import",
13845
+ label: "Import existing resources",
13846
+ placement: "toolbar",
13847
+ requiredPorts: ["commands"],
13848
+ // `stack import` writes the directory it runs in, the same way
13849
+ // Convert does.
13850
+ requiredContext: ["root", "stack"],
13851
+ binding: importStack
13852
+ },
13853
+ {
13854
+ id: "import-partial",
13855
+ label: "Import the rest",
13856
+ placement: { row: "failure" },
13857
+ requiredPorts: ["commands"],
13858
+ requiredContext: ["root", "stack"],
13859
+ answers: ["import_residual"],
13860
+ binding: importPartial
13861
+ },
13862
+ {
13863
+ id: "preview",
13864
+ label: "Preview",
13865
+ placement: "toolbar",
13866
+ requiredPorts: ["commands"],
13867
+ // `stack preview` plans the tf of the directory it runs in — a stack
13868
+ // alone isn't enough, the mount needs the root too.
13869
+ requiredContext: ["root", "stack"],
13870
+ binding: preview
13871
+ },
13872
+ {
13873
+ id: "run-cancel",
13874
+ label: "Cancel",
13875
+ placement: { row: "runs" },
13876
+ requiredPorts: ["commands"],
13877
+ requiredTarget: ["runId"],
13878
+ binding: runCancel
13879
+ },
13880
+ {
13881
+ id: "follow-logs",
13882
+ label: "Follow logs",
13883
+ placement: { row: "runs" },
13884
+ requiredPorts: ["commands"],
13885
+ requiredTarget: ["runId"],
13886
+ binding: followLogs
13642
13887
  }
13643
- return {
13644
- token,
13645
- outcome: { kind: "failed", message: error instanceof Error ? error.message : String(error) },
13646
- lastLog,
13647
- submitted,
13648
- phases
13649
- };
13650
- }
13651
- function reducePreview(_prev, token, event) {
13652
- return { token, data: event };
13653
- }
13654
- function reduceReport(prev, session, result) {
13655
- const fold = foldReport(prev?.sessions.get(session) ?? EMPTY_REPORT_FOLD, result);
13656
- return { sessions: new Map(prev?.sessions).set(session, fold) };
13657
- }
13658
- function reduceFollow(prev, token, event) {
13659
- const carried = prev && prev.token === token ? prev : null;
13660
- const runId = carried?.runId ?? "";
13661
- const lines = carried?.lines ?? [];
13662
- if (event.type === "log") return { token, runId, lines: [...lines, event.text], done: false };
13663
- return { token, runId, lines, done: true };
13664
- }
13665
- function createResultStore() {
13666
- let slots = {
13667
- run: null,
13668
- preview: null,
13669
- report: null,
13670
- follow: null
13671
- };
13672
- let tick = 0;
13673
- const listeners = /* @__PURE__ */ new Set();
13674
- const notify = () => {
13675
- for (const listener of listeners) listener();
13676
- };
13677
- const retiredTokens = /* @__PURE__ */ new WeakSet();
13678
- return {
13679
- getSnapshot() {
13680
- return slots;
13681
- },
13682
- getTick() {
13683
- return tick;
13684
- },
13685
- subscribe(listener) {
13686
- listeners.add(listener);
13687
- return () => listeners.delete(listener);
13688
- },
13689
- write(kind, token, value, readOver) {
13690
- if (retiredTokens.has(token)) return;
13691
- slots = { ...slots, [kind]: applySlot(kind, slots[kind], token, value, readOver) };
13692
- notify();
13693
- },
13694
- fail(kind, token, error) {
13695
- if (kind !== "run") return false;
13696
- if (retiredTokens.has(token) || !slots.run) return true;
13697
- slots = { ...slots, run: stamp(settleRun(slots.run, token, error), slots.run.readOver) };
13698
- notify();
13699
- return true;
13700
- },
13701
- begin(kind, token, readOver, target) {
13702
- if (kind === "run") {
13703
- slots = {
13704
- ...slots,
13705
- run: {
13706
- token,
13707
- outcome: { kind: "running" },
13708
- lastLog: null,
13709
- submitted: false,
13710
- phases: [],
13711
- readOver
13712
- }
13713
- };
13714
- } else if (kind === "follow") {
13715
- slots = {
13716
- ...slots,
13717
- follow: { token, runId: target.runId ?? "", lines: [], done: false, readOver }
13718
- };
13719
- } else {
13720
- return;
13721
- }
13722
- notify();
13723
- },
13724
- detach(kind, token) {
13725
- if (kind === "follow" && slots.follow?.token === token) {
13726
- slots = { ...slots, follow: null };
13727
- notify();
13728
- } else if (kind === "report" && slots.report?.sessions.has(token)) {
13729
- const sessions = new Map(slots.report.sessions);
13730
- sessions.delete(token);
13731
- slots = {
13732
- ...slots,
13733
- report: sessions.size > 0 ? { sessions, readOver: slots.report.readOver } : null
13734
- };
13735
- notify();
13736
- } else if (kind === "run" && slots.run?.token === token) {
13737
- const settled = settleRun(slots.run, token, new CommandDetachedError());
13738
- slots = { ...slots, run: stamp(settled, slots.run.readOver) };
13739
- notify();
13740
- }
13741
- retiredTokens.add(token);
13742
- },
13743
- isBusy(kind) {
13744
- return kind === "run" && slots.run?.outcome.kind === "running";
13745
- },
13746
- bumpTick() {
13747
- tick += 1;
13748
- notify();
13749
- }
13750
- };
13751
- }
13888
+ ];
13889
+ var CORE_COMMAND_ACTIONS = [
13890
+ ...STACK_COMMAND_ACTIONS,
13891
+ ...MODULE_COMMAND_ACTIONS
13892
+ ];
13752
13893
 
13753
13894
  // src/registry.ts
13754
13895
  var CONTEXT_NEEDS = {
@@ -13779,7 +13920,16 @@ var TARGET_NEEDS = {
13779
13920
  runId: "a run",
13780
13921
  failure: "a failed command"
13781
13922
  };
13782
- var BUSY_REASON = "A run is in progress";
13923
+ function busyReason(busy) {
13924
+ return busy.kind === "run" ? "A run is in progress" : `${busy.running.label} is running`;
13925
+ }
13926
+ function runsOn(action, ctx, target) {
13927
+ if (action.requiredTarget?.includes("runId")) return `run:${target.runId}`;
13928
+ const required = action.requiredContext ?? [];
13929
+ if (required.includes("stack")) return `stack:${ctx.stack?.id}`;
13930
+ if (required.includes("root")) return `root:${ctx.root}`;
13931
+ return "";
13932
+ }
13783
13933
  function keySatisfied(ctx, key) {
13784
13934
  if (key === "editable") return ctx.editable === true;
13785
13935
  if (key === "saved") return ctx.view?.unsaved === false;
@@ -13801,8 +13951,8 @@ function keySatisfied(ctx, key) {
13801
13951
  if (key === "redoable") return ctx.view?.can_redo === true;
13802
13952
  return ctx[key] !== void 0;
13803
13953
  }
13804
- function disabledReason(action, ctx, isBusy) {
13805
- if (isBusy) return BUSY_REASON;
13954
+ function disabledReason(action, ctx, busy) {
13955
+ if (busy) return busyReason(busy);
13806
13956
  for (const { key, reason } of action.enabledWhen ?? []) {
13807
13957
  if (!keySatisfied(ctx, key)) return reason;
13808
13958
  }
@@ -13823,6 +13973,16 @@ function asksConfirm(binding) {
13823
13973
  return binding.confirm !== void 0;
13824
13974
  }
13825
13975
  }
13976
+ var FAILURE_ROW = "failure";
13977
+ function placedOn(action, row) {
13978
+ return typeof action.placement === "object" && action.placement.row === row;
13979
+ }
13980
+ function answersFailure(action, failure) {
13981
+ return action.answers?.includes(failure.reason) === true;
13982
+ }
13983
+ function answering(actions, failure) {
13984
+ return actions.filter((a) => placedOn(a, FAILURE_ROW) && answersFailure(a, failure));
13985
+ }
13826
13986
  function unmetRequirement(action, ports, ctx, target) {
13827
13987
  const { label, binding } = action;
13828
13988
  const port = missingPort(ports, action.requiredPorts);
@@ -13834,11 +13994,9 @@ function unmetRequirement(action, ports, ctx, target) {
13834
13994
  if (key !== void 0) return `${label} needs ${CONTEXT_NEEDS[key]}`;
13835
13995
  const targetKey = (action.requiredTarget ?? []).find((k) => target[k] === void 0);
13836
13996
  if (targetKey !== void 0) return `${label} needs ${TARGET_NEEDS[targetKey]}`;
13837
- if (action.answers !== void 0) {
13997
+ if (placedOn(action, FAILURE_ROW) || action.answers !== void 0) {
13838
13998
  if (target.failure === void 0) return `${label} needs ${TARGET_NEEDS.failure}`;
13839
- if (!action.answers.includes(target.failure.reason)) {
13840
- return `${label} does not answer this failure`;
13841
- }
13999
+ if (!answersFailure(action, target.failure)) return `${label} does not answer this failure`;
13842
14000
  }
13843
14001
  if (binding.kind === "command" && !availableCommands(ports).has(binding.path)) {
13844
14002
  return `${label} runs lace ${binding.path}, which this host does not route`;
@@ -13869,7 +14027,19 @@ function createActionRunner(ports, store, options = {}) {
13869
14027
  const handles = /* @__PURE__ */ new Map();
13870
14028
  const tokens = /* @__PURE__ */ new Map();
13871
14029
  const clipboard = createClipboardStore();
13872
- const notifyControllers = /* @__PURE__ */ new Set();
14030
+ const notifyControllers = /* @__PURE__ */ new Map();
14031
+ let edits = 0;
14032
+ const editingListeners = /* @__PURE__ */ new Set();
14033
+ async function asEdit(edit) {
14034
+ edits += 1;
14035
+ if (edits === 1) for (const listener of editingListeners) listener(true);
14036
+ try {
14037
+ return await edit();
14038
+ } finally {
14039
+ edits -= 1;
14040
+ if (edits === 0) for (const listener of editingListeners) listener(false);
14041
+ }
14042
+ }
13873
14043
  async function applyWith(editor, actions) {
13874
14044
  let result;
13875
14045
  try {
@@ -13909,13 +14079,14 @@ function createActionRunner(ports, store, options = {}) {
13909
14079
  async function applyActions(actions) {
13910
14080
  const editor = ports.editor;
13911
14081
  if (!editor) return;
13912
- return applyWith(editor, actions);
14082
+ return asEdit(() => applyWith(editor, actions));
13913
14083
  }
13914
14084
  function askConfirm(spec) {
13915
14085
  const confirm = ports.presenter.confirm;
13916
14086
  return confirm ? confirm(spec) : Promise.resolve(false);
13917
14087
  }
13918
- function runtimeFor(token, readOver, cwd, run, onSettle) {
14088
+ function runtimeFor(token, readOver, cwd, command, onSettle) {
14089
+ const run = command?.run;
13919
14090
  return {
13920
14091
  ports,
13921
14092
  token,
@@ -13926,7 +14097,7 @@ function createActionRunner(ports, store, options = {}) {
13926
14097
  if (run && line !== void 0) options.onRunLog?.(line, run);
13927
14098
  },
13928
14099
  begin: () => {
13929
- if (run) store.begin(run.resultKind, token, readOver, run.target);
14100
+ if (command) store.begin(command.run.resultKind, token, readOver, command.started);
13930
14101
  },
13931
14102
  fail: (error) => run ? store.fail(run.resultKind, token, error) : false,
13932
14103
  detach: (kind, tok) => store.detach(kind, tok),
@@ -13937,6 +14108,15 @@ function createActionRunner(ports, store, options = {}) {
13937
14108
  function readOverOf(ctx) {
13938
14109
  return { stack: ctx.stack?.id };
13939
14110
  }
14111
+ function busyOn(resultKind, action, ctx, target) {
14112
+ const on = runsOn(action, ctx, target);
14113
+ return { on, busy: store.busy(resultKind, on) };
14114
+ }
14115
+ function busyOf(action, ctx, target) {
14116
+ const binding = action.binding;
14117
+ if (binding.kind !== "command") return void 0;
14118
+ return busyOn(binding.resultKind, action, ctx, target).busy;
14119
+ }
13940
14120
  function cwdOf(action, ctx) {
13941
14121
  return (action.requiredContext ?? []).includes("root") ? ctx.root : void 0;
13942
14122
  }
@@ -13949,24 +14129,33 @@ function createActionRunner(ports, store, options = {}) {
13949
14129
  handles.delete(kind);
13950
14130
  tokens.delete(kind);
13951
14131
  }
14132
+ function tellFailure(error) {
14133
+ if (error instanceof CommandDetachedError) return;
14134
+ ports.presenter.notify("error", error instanceof Error ? error.message : String(error));
14135
+ }
13952
14136
  async function startCommand(action, ctx, target, formArgs) {
13953
14137
  const binding = action.binding;
13954
14138
  if (binding.kind !== "command") return;
13955
14139
  const spec = binding.confirmSpec(ctx, target, formArgs);
13956
14140
  if (spec && !await askConfirm(spec)) return;
13957
- if (store.isBusy(binding.resultKind)) {
13958
- ports.presenter.notify("warn", BUSY_REASON);
14141
+ const { on, busy } = busyOn(binding.resultKind, action, ctx, target);
14142
+ if (busy) {
14143
+ ports.presenter.notify("warn", busyReason(busy));
13959
14144
  return;
13960
14145
  }
13961
14146
  const readOver = readOverOf(ctx);
13962
14147
  const cwd = cwdOf(action, ctx);
13963
14148
  const token = {};
13964
14149
  const run = { token, path: binding.path, resultKind: binding.resultKind, ctx, target };
14150
+ const started = { target, on, path: binding.path, label: action.label };
13965
14151
  const controller = new AbortController();
13966
14152
  if (binding.resultKind === "notify") {
13967
- notifyControllers.add(controller);
14153
+ notifyControllers.set(controller, token);
13968
14154
  await binding.start(
13969
- runtimeFor(token, readOver, cwd, run, () => notifyControllers.delete(controller)),
14155
+ runtimeFor(token, readOver, cwd, { run, started }, () => {
14156
+ notifyControllers.delete(controller);
14157
+ store.detach("notify", token);
14158
+ }),
13970
14159
  ctx,
13971
14160
  target,
13972
14161
  formArgs,
@@ -13978,7 +14167,7 @@ function createActionRunner(ports, store, options = {}) {
13978
14167
  controllers.set(binding.resultKind, controller);
13979
14168
  tokens.set(binding.resultKind, token);
13980
14169
  const handle = await binding.start(
13981
- runtimeFor(token, readOver, cwd, run),
14170
+ runtimeFor(token, readOver, cwd, { run, started }),
13982
14171
  ctx,
13983
14172
  target,
13984
14173
  formArgs,
@@ -14003,7 +14192,7 @@ function createActionRunner(ports, store, options = {}) {
14003
14192
  missing: completion.missing,
14004
14193
  submit: (values) => {
14005
14194
  options.onPendingFormChange?.(null);
14006
- void startCommand(action, ctx, target, values);
14195
+ void startCommand(action, ctx, target, values).catch(tellFailure);
14007
14196
  },
14008
14197
  cancel: () => options.onPendingFormChange?.(null)
14009
14198
  });
@@ -14027,7 +14216,7 @@ function createActionRunner(ports, store, options = {}) {
14027
14216
  ...envExtras
14028
14217
  };
14029
14218
  if (binding.result === "apply") {
14030
- return binding.run(env);
14219
+ return asEdit(() => binding.run(env));
14031
14220
  }
14032
14221
  if (binding.result === "generate") {
14033
14222
  for await (const event of binding.run(env)) {
@@ -14055,8 +14244,7 @@ function createActionRunner(ports, store, options = {}) {
14055
14244
  ports.presenter.notify("warn", unmet);
14056
14245
  return;
14057
14246
  }
14058
- const isBusy = action.binding.kind === "command" && store.isBusy(action.binding.resultKind);
14059
- const reason = disabledReason(action, ctx, isBusy);
14247
+ const reason = disabledReason(action, ctx, busyOf(action, ctx, target));
14060
14248
  if (reason !== void 0) {
14061
14249
  ports.presenter.notify("warn", reason);
14062
14250
  return;
@@ -14077,13 +14265,24 @@ function createActionRunner(ports, store, options = {}) {
14077
14265
  return;
14078
14266
  }
14079
14267
  } catch (error) {
14080
- if (error instanceof CommandDetachedError) return;
14081
- ports.presenter.notify("error", error instanceof Error ? error.message : String(error));
14268
+ tellFailure(error);
14082
14269
  }
14083
14270
  },
14084
14271
  apply(actions) {
14085
14272
  return applyActions(actions);
14086
14273
  },
14274
+ editing() {
14275
+ return edits > 0;
14276
+ },
14277
+ onEditingChange(listener) {
14278
+ editingListeners.add(listener);
14279
+ return () => {
14280
+ editingListeners.delete(listener);
14281
+ };
14282
+ },
14283
+ busy(action, ctx, target) {
14284
+ return busyOf(action, ctx, target);
14285
+ },
14087
14286
  async cancel(kind) {
14088
14287
  const handle = handles.get(kind);
14089
14288
  if (!handle) return;
@@ -14095,7 +14294,10 @@ function createActionRunner(ports, store, options = {}) {
14095
14294
  },
14096
14295
  dispose() {
14097
14296
  for (const kind of [...controllers.keys()]) detachSlot(kind);
14098
- for (const controller of notifyControllers) controller.abort();
14297
+ for (const [controller, token] of notifyControllers) {
14298
+ controller.abort();
14299
+ store.detach("notify", token);
14300
+ }
14099
14301
  notifyControllers.clear();
14100
14302
  }
14101
14303
  };
@@ -14201,6 +14403,7 @@ function autosave(source, save, policy, report) {
14201
14403
  InputMode,
14202
14404
  Reason,
14203
14405
  SCHEMAS,
14406
+ answering,
14204
14407
  autosave,
14205
14408
  bridgeCaller,
14206
14409
  carriesFailure,
@@ -14211,6 +14414,7 @@ function autosave(source, save, policy, report) {
14211
14414
  defineCommand,
14212
14415
  diagnosticsOf,
14213
14416
  diagnosticsOfDocument,
14417
+ failureSays,
14214
14418
  foldReport,
14215
14419
  isBoundPath,
14216
14420
  liveSlots,