@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.
- package/README.md +15 -7
- package/dist/{chunk-HZWABSPP.mjs → chunk-ID563WHD.mjs} +795 -583
- package/dist/chunk-ID563WHD.mjs.map +1 -0
- package/dist/engine/index.cjs +784 -580
- package/dist/engine/index.cjs.map +1 -1
- package/dist/engine/index.d.mts +2 -2
- package/dist/engine/index.d.ts +2 -2
- package/dist/engine/index.mjs +5 -1
- package/dist/index.cjs +1261 -962
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +3 -9
- package/dist/index.d.ts +3 -9
- package/dist/index.mjs +333 -242
- package/dist/index.mjs.map +1 -1
- package/dist/{mapping-Z-STJQRP.d.mts → registry-BhFAgvlq.d.mts} +96 -16
- package/dist/{mapping-Z-STJQRP.d.ts → registry-BhFAgvlq.d.ts} +96 -16
- package/package.json +3 -3
- package/dist/chunk-HZWABSPP.mjs.map +0 -1
|
@@ -3543,7 +3543,7 @@ function conflictChoiceToJSON(object) {
|
|
|
3543
3543
|
}
|
|
3544
3544
|
}
|
|
3545
3545
|
function createBaseReasonDetail() {
|
|
3546
|
-
return { reason: 0, api_code: "" };
|
|
3546
|
+
return { reason: 0, api_code: "", request_id: "" };
|
|
3547
3547
|
}
|
|
3548
3548
|
var ReasonDetail = {
|
|
3549
3549
|
encode(message, writer = new BinaryWriter4()) {
|
|
@@ -3553,6 +3553,9 @@ var ReasonDetail = {
|
|
|
3553
3553
|
if (message.api_code !== "") {
|
|
3554
3554
|
writer.uint32(18).string(message.api_code);
|
|
3555
3555
|
}
|
|
3556
|
+
if (message.request_id !== "") {
|
|
3557
|
+
writer.uint32(26).string(message.request_id);
|
|
3558
|
+
}
|
|
3556
3559
|
return writer;
|
|
3557
3560
|
},
|
|
3558
3561
|
decode(input, length) {
|
|
@@ -3576,6 +3579,13 @@ var ReasonDetail = {
|
|
|
3576
3579
|
message.api_code = reader.string();
|
|
3577
3580
|
continue;
|
|
3578
3581
|
}
|
|
3582
|
+
case 3: {
|
|
3583
|
+
if (tag !== 26) {
|
|
3584
|
+
break;
|
|
3585
|
+
}
|
|
3586
|
+
message.request_id = reader.string();
|
|
3587
|
+
continue;
|
|
3588
|
+
}
|
|
3579
3589
|
}
|
|
3580
3590
|
if ((tag & 7) === 4 || tag === 0) {
|
|
3581
3591
|
break;
|
|
@@ -3587,7 +3597,8 @@ var ReasonDetail = {
|
|
|
3587
3597
|
fromJSON(object) {
|
|
3588
3598
|
return {
|
|
3589
3599
|
reason: isSet3(object.reason) ? reasonFromJSON(object.reason) : 0,
|
|
3590
|
-
api_code: isSet3(object.apiCode) ? globalThis.String(object.apiCode) : isSet3(object.api_code) ? globalThis.String(object.api_code) : ""
|
|
3600
|
+
api_code: isSet3(object.apiCode) ? globalThis.String(object.apiCode) : isSet3(object.api_code) ? globalThis.String(object.api_code) : "",
|
|
3601
|
+
request_id: isSet3(object.requestId) ? globalThis.String(object.requestId) : isSet3(object.request_id) ? globalThis.String(object.request_id) : ""
|
|
3591
3602
|
};
|
|
3592
3603
|
},
|
|
3593
3604
|
toJSON(message) {
|
|
@@ -3598,6 +3609,9 @@ var ReasonDetail = {
|
|
|
3598
3609
|
if (message.api_code !== "") {
|
|
3599
3610
|
obj.apiCode = message.api_code;
|
|
3600
3611
|
}
|
|
3612
|
+
if (message.request_id !== "") {
|
|
3613
|
+
obj.requestId = message.request_id;
|
|
3614
|
+
}
|
|
3601
3615
|
return obj;
|
|
3602
3616
|
},
|
|
3603
3617
|
create(base) {
|
|
@@ -3607,6 +3621,7 @@ var ReasonDetail = {
|
|
|
3607
3621
|
const message = createBaseReasonDetail();
|
|
3608
3622
|
message.reason = object.reason ?? 0;
|
|
3609
3623
|
message.api_code = object.api_code ?? "";
|
|
3624
|
+
message.request_id = object.request_id ?? "";
|
|
3610
3625
|
return message;
|
|
3611
3626
|
}
|
|
3612
3627
|
};
|
|
@@ -7965,7 +7980,7 @@ var InvokeRequest = {
|
|
|
7965
7980
|
}
|
|
7966
7981
|
};
|
|
7967
7982
|
function createBaseInvokeEvent() {
|
|
7968
|
-
return { json: void 0, exit: void 0 };
|
|
7983
|
+
return { json: void 0, exit: void 0, started: void 0 };
|
|
7969
7984
|
}
|
|
7970
7985
|
var InvokeEvent = {
|
|
7971
7986
|
encode(message, writer = new BinaryWriter4()) {
|
|
@@ -7975,6 +7990,9 @@ var InvokeEvent = {
|
|
|
7975
7990
|
if (message.exit !== void 0) {
|
|
7976
7991
|
InvokeExit.encode(message.exit, writer.uint32(18).fork()).join();
|
|
7977
7992
|
}
|
|
7993
|
+
if (message.started !== void 0) {
|
|
7994
|
+
InvokeStarted.encode(message.started, writer.uint32(26).fork()).join();
|
|
7995
|
+
}
|
|
7978
7996
|
return writer;
|
|
7979
7997
|
},
|
|
7980
7998
|
decode(input, length) {
|
|
@@ -7998,6 +8016,13 @@ var InvokeEvent = {
|
|
|
7998
8016
|
message.exit = InvokeExit.decode(reader, reader.uint32());
|
|
7999
8017
|
continue;
|
|
8000
8018
|
}
|
|
8019
|
+
case 3: {
|
|
8020
|
+
if (tag !== 26) {
|
|
8021
|
+
break;
|
|
8022
|
+
}
|
|
8023
|
+
message.started = InvokeStarted.decode(reader, reader.uint32());
|
|
8024
|
+
continue;
|
|
8025
|
+
}
|
|
8001
8026
|
}
|
|
8002
8027
|
if ((tag & 7) === 4 || tag === 0) {
|
|
8003
8028
|
break;
|
|
@@ -8009,7 +8034,8 @@ var InvokeEvent = {
|
|
|
8009
8034
|
fromJSON(object) {
|
|
8010
8035
|
return {
|
|
8011
8036
|
json: isSet3(object.json) ? globalThis.String(object.json) : void 0,
|
|
8012
|
-
exit: isSet3(object.exit) ? InvokeExit.fromJSON(object.exit) : void 0
|
|
8037
|
+
exit: isSet3(object.exit) ? InvokeExit.fromJSON(object.exit) : void 0,
|
|
8038
|
+
started: isSet3(object.started) ? InvokeStarted.fromJSON(object.started) : void 0
|
|
8013
8039
|
};
|
|
8014
8040
|
},
|
|
8015
8041
|
toJSON(message) {
|
|
@@ -8020,6 +8046,9 @@ var InvokeEvent = {
|
|
|
8020
8046
|
if (message.exit !== void 0) {
|
|
8021
8047
|
obj.exit = InvokeExit.toJSON(message.exit);
|
|
8022
8048
|
}
|
|
8049
|
+
if (message.started !== void 0) {
|
|
8050
|
+
obj.started = InvokeStarted.toJSON(message.started);
|
|
8051
|
+
}
|
|
8023
8052
|
return obj;
|
|
8024
8053
|
},
|
|
8025
8054
|
create(base) {
|
|
@@ -8029,6 +8058,44 @@ var InvokeEvent = {
|
|
|
8029
8058
|
const message = createBaseInvokeEvent();
|
|
8030
8059
|
message.json = object.json ?? void 0;
|
|
8031
8060
|
message.exit = object.exit !== void 0 && object.exit !== null ? InvokeExit.fromPartial(object.exit) : void 0;
|
|
8061
|
+
message.started = object.started !== void 0 && object.started !== null ? InvokeStarted.fromPartial(object.started) : void 0;
|
|
8062
|
+
return message;
|
|
8063
|
+
}
|
|
8064
|
+
};
|
|
8065
|
+
function createBaseInvokeStarted() {
|
|
8066
|
+
return {};
|
|
8067
|
+
}
|
|
8068
|
+
var InvokeStarted = {
|
|
8069
|
+
encode(_, writer = new BinaryWriter4()) {
|
|
8070
|
+
return writer;
|
|
8071
|
+
},
|
|
8072
|
+
decode(input, length) {
|
|
8073
|
+
const reader = input instanceof BinaryReader4 ? input : new BinaryReader4(input);
|
|
8074
|
+
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
8075
|
+
const message = createBaseInvokeStarted();
|
|
8076
|
+
while (reader.pos < end) {
|
|
8077
|
+
const tag = reader.uint32();
|
|
8078
|
+
switch (tag >>> 3) {
|
|
8079
|
+
}
|
|
8080
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
8081
|
+
break;
|
|
8082
|
+
}
|
|
8083
|
+
reader.skip(tag & 7);
|
|
8084
|
+
}
|
|
8085
|
+
return message;
|
|
8086
|
+
},
|
|
8087
|
+
fromJSON(_) {
|
|
8088
|
+
return {};
|
|
8089
|
+
},
|
|
8090
|
+
toJSON(_) {
|
|
8091
|
+
const obj = {};
|
|
8092
|
+
return obj;
|
|
8093
|
+
},
|
|
8094
|
+
create(base) {
|
|
8095
|
+
return InvokeStarted.fromPartial(base ?? {});
|
|
8096
|
+
},
|
|
8097
|
+
fromPartial(_) {
|
|
8098
|
+
const message = createBaseInvokeStarted();
|
|
8032
8099
|
return message;
|
|
8033
8100
|
}
|
|
8034
8101
|
};
|
|
@@ -10307,8 +10374,9 @@ var LaceEngineDefinition = {
|
|
|
10307
10374
|
options: {}
|
|
10308
10375
|
},
|
|
10309
10376
|
/**
|
|
10310
|
-
* Runs one CLI command in-process against a fresh command tree.
|
|
10311
|
-
*
|
|
10377
|
+
* Runs one CLI command in-process against a fresh command tree. `started` is first, once the engine has accepted
|
|
10378
|
+
* the request and before the command runs; the command's `-o json` output follows: each top-level JSON value on
|
|
10379
|
+
* stdout is one `json` event; `exit` is always last.
|
|
10312
10380
|
*/
|
|
10313
10381
|
invoke: {
|
|
10314
10382
|
name: "Invoke",
|
|
@@ -10383,6 +10451,7 @@ function isSet3(value) {
|
|
|
10383
10451
|
}
|
|
10384
10452
|
|
|
10385
10453
|
// src/ports.ts
|
|
10454
|
+
import { apiFields } from "@lace-cloud/proto";
|
|
10386
10455
|
function currentFrame(source) {
|
|
10387
10456
|
return new Promise((resolve) => {
|
|
10388
10457
|
let settled = false;
|
|
@@ -10416,7 +10485,9 @@ var ConnectError = class extends Error {
|
|
|
10416
10485
|
super(`[${code}] ${message}`);
|
|
10417
10486
|
this.code = code;
|
|
10418
10487
|
this.reason = detail.reason;
|
|
10419
|
-
|
|
10488
|
+
const { apiCode, requestId } = apiFields(detail);
|
|
10489
|
+
this.apiCode = apiCode;
|
|
10490
|
+
this.requestId = requestId;
|
|
10420
10491
|
this.name = "ConnectError";
|
|
10421
10492
|
}
|
|
10422
10493
|
};
|
|
@@ -10693,7 +10764,8 @@ function parseBridgeResponse(raw) {
|
|
|
10693
10764
|
return null;
|
|
10694
10765
|
}
|
|
10695
10766
|
const apiCode = "apiCode" in raw && typeof raw.apiCode === "string" ? raw.apiCode : void 0;
|
|
10696
|
-
|
|
10767
|
+
const requestId = "requestId" in raw && typeof raw.requestId === "string" ? raw.requestId : void 0;
|
|
10768
|
+
return { kind, id, code, message, reason, apiCode, requestId };
|
|
10697
10769
|
}
|
|
10698
10770
|
return null;
|
|
10699
10771
|
}
|
|
@@ -10701,7 +10773,11 @@ function frameError(frame) {
|
|
|
10701
10773
|
return new ConnectError(
|
|
10702
10774
|
frame.code,
|
|
10703
10775
|
frame.message,
|
|
10704
|
-
ReasonDetail.fromJSON({
|
|
10776
|
+
ReasonDetail.fromJSON({
|
|
10777
|
+
reason: frame.reason,
|
|
10778
|
+
api_code: frame.apiCode,
|
|
10779
|
+
request_id: frame.requestId
|
|
10780
|
+
})
|
|
10705
10781
|
);
|
|
10706
10782
|
}
|
|
10707
10783
|
function bridgeCaller(bridge) {
|
|
@@ -12127,7 +12203,8 @@ var commandFailureSchema = z.strictObject({
|
|
|
12127
12203
|
tool: z.string().optional(),
|
|
12128
12204
|
importResiduals: z.array(importResidualSchema).optional(),
|
|
12129
12205
|
addresses: z.array(z.string()).optional(),
|
|
12130
|
-
apiCode: z.string().optional()
|
|
12206
|
+
apiCode: z.string().optional(),
|
|
12207
|
+
requestId: z.string().optional()
|
|
12131
12208
|
});
|
|
12132
12209
|
var moduleValidateDeviationSchema = z.object({
|
|
12133
12210
|
notCompositional: z.boolean(),
|
|
@@ -12566,18 +12643,16 @@ var stackScanSchema = z.object({
|
|
|
12566
12643
|
driftCount: z.number(),
|
|
12567
12644
|
scannedAt: z.string(),
|
|
12568
12645
|
undeterminedReason: z.string().nullable(),
|
|
12646
|
+
undeterminedMessage: z.string().nullable(),
|
|
12569
12647
|
standingDriftFindings: z.number(),
|
|
12570
12648
|
footprintDestroyed: z.boolean(),
|
|
12571
12649
|
drift: driftSchema
|
|
12572
12650
|
}).nullable()
|
|
12573
12651
|
});
|
|
12574
|
-
var stackImportSchema =
|
|
12652
|
+
var stackImportSchema = moduleConvertResultSchema.extend({
|
|
12575
12653
|
stack: stackIdentSchema,
|
|
12576
|
-
written: z.array(z.string()),
|
|
12577
|
-
removed: z.array(z.string()),
|
|
12578
12654
|
importBlocks: z.number(),
|
|
12579
|
-
importResiduals: z.array(importResidualSchema)
|
|
12580
|
-
validate: moduleValidateResultSchema
|
|
12655
|
+
importResiduals: z.array(importResidualSchema)
|
|
12581
12656
|
});
|
|
12582
12657
|
var artifactRefSchema = z.object({ url: z.string(), key: z.string() });
|
|
12583
12658
|
var runPlanSchema = z.object({
|
|
@@ -12814,6 +12889,7 @@ async function openEngineSession(caller, target, options = {}) {
|
|
|
12814
12889
|
revisionWaiters.clear();
|
|
12815
12890
|
}
|
|
12816
12891
|
function publishCommandResult(result) {
|
|
12892
|
+
commandResults.delete(result.path);
|
|
12817
12893
|
commandResults.set(result.path, result);
|
|
12818
12894
|
for (const listener of commandResultListeners) deliver(listener, result);
|
|
12819
12895
|
}
|
|
@@ -12960,7 +13036,7 @@ function commandsPort(caller, commandPaths, ownCwd) {
|
|
|
12960
13036
|
working_directory: cwd
|
|
12961
13037
|
};
|
|
12962
13038
|
async function* run() {
|
|
12963
|
-
for await (const event of
|
|
13039
|
+
for await (const event of untilExit()) {
|
|
12964
13040
|
if (event.json !== void 0) {
|
|
12965
13041
|
const data = JSON.parse(event.json);
|
|
12966
13042
|
if (carriesFailure(data)) continue;
|
|
@@ -12978,8 +13054,28 @@ function commandsPort(caller, commandPaths, ownCwd) {
|
|
|
12978
13054
|
return;
|
|
12979
13055
|
}
|
|
12980
13056
|
}
|
|
12981
|
-
|
|
12982
|
-
|
|
13057
|
+
}
|
|
13058
|
+
async function* untilExit() {
|
|
13059
|
+
let started = false;
|
|
13060
|
+
const stopped = (error) => {
|
|
13061
|
+
if (signal.aborted) return new CommandDetachedError();
|
|
13062
|
+
if (started) return new CommandUnobservedError();
|
|
13063
|
+
return error;
|
|
13064
|
+
};
|
|
13065
|
+
try {
|
|
13066
|
+
for await (const event of caller.stream("Invoke", request, signal)) {
|
|
13067
|
+
started || (started = event.started !== void 0);
|
|
13068
|
+
yield event;
|
|
13069
|
+
}
|
|
13070
|
+
} catch (error) {
|
|
13071
|
+
throw stopped(error);
|
|
13072
|
+
}
|
|
13073
|
+
throw stopped(
|
|
13074
|
+
new ConnectError(
|
|
13075
|
+
"internal",
|
|
13076
|
+
"the engine ended the Invoke stream before it started the command"
|
|
13077
|
+
)
|
|
13078
|
+
);
|
|
12983
13079
|
}
|
|
12984
13080
|
return {
|
|
12985
13081
|
events: run(),
|
|
@@ -13053,407 +13149,71 @@ function convertCreatedRef(r) {
|
|
|
13053
13149
|
return { scope: r.scope, id: r.id, moduleKey: r.module_key, sourceId: r.source_id };
|
|
13054
13150
|
}
|
|
13055
13151
|
|
|
13056
|
-
// src/core/
|
|
13057
|
-
|
|
13058
|
-
|
|
13059
|
-
|
|
13060
|
-
}
|
|
13061
|
-
if (err instanceof Error) return [err.message];
|
|
13062
|
-
return [String(err)];
|
|
13152
|
+
// src/core/diagnostics.ts
|
|
13153
|
+
var NOT_LACE_SHAPE = "not_lace_shape";
|
|
13154
|
+
function holdsLaceShapeRefusal(diagnostics) {
|
|
13155
|
+
return diagnostics.some((d) => d.code === NOT_LACE_SHAPE);
|
|
13063
13156
|
}
|
|
13064
|
-
function
|
|
13065
|
-
return
|
|
13066
|
-
|
|
13067
|
-
|
|
13068
|
-
|
|
13069
|
-
|
|
13070
|
-
|
|
13071
|
-
|
|
13072
|
-
|
|
13073
|
-
|
|
13074
|
-
confirmSpec(ctx, target, formArgs) {
|
|
13075
|
-
if (!binding.confirm) return void 0;
|
|
13076
|
-
const merged = completeArgs(binding.path, { ...binding.args(ctx, target), ...formArgs });
|
|
13077
|
-
if (!merged.ok) return void 0;
|
|
13078
|
-
return binding.confirm(ctx, merged.args, target);
|
|
13079
|
-
},
|
|
13080
|
-
async start(rt, ctx, target, formArgs, signal) {
|
|
13081
|
-
const merged = completeArgs(binding.path, { ...binding.args(ctx, target), ...formArgs });
|
|
13082
|
-
if (!merged.ok) return null;
|
|
13083
|
-
const commands = rt.ports.commands;
|
|
13084
|
-
if (!commands) return null;
|
|
13085
|
-
const invocation = commands.invoke(binding.path, merged.args, signal, rt.cwd);
|
|
13086
|
-
rt.begin();
|
|
13087
|
-
if (binding.invalidates === "start+settle") rt.tick();
|
|
13088
|
-
void (async () => {
|
|
13089
|
-
try {
|
|
13090
|
-
for await (const event of invocation.events) {
|
|
13091
|
-
binding.result.consume(rt, event);
|
|
13092
|
-
}
|
|
13093
|
-
if (binding.invalidates) rt.tick();
|
|
13094
|
-
} catch (err) {
|
|
13095
|
-
if (!rt.fail(err) && !(err instanceof CommandDetachedError)) {
|
|
13096
|
-
rt.ports.presenter.notify("error", ...errorNotice(err));
|
|
13097
|
-
}
|
|
13098
|
-
if (binding.invalidates) rt.tick();
|
|
13099
|
-
} finally {
|
|
13100
|
-
rt.settled?.();
|
|
13101
|
-
}
|
|
13102
|
-
})();
|
|
13103
|
-
return { cancel: () => invocation.cancel() };
|
|
13104
|
-
}
|
|
13105
|
-
};
|
|
13157
|
+
function findingKey(d) {
|
|
13158
|
+
return JSON.stringify([
|
|
13159
|
+
d.file,
|
|
13160
|
+
d.line,
|
|
13161
|
+
d.message,
|
|
13162
|
+
d.module_key,
|
|
13163
|
+
d.instance_id,
|
|
13164
|
+
d.input_name,
|
|
13165
|
+
d.address
|
|
13166
|
+
]);
|
|
13106
13167
|
}
|
|
13107
|
-
|
|
13108
|
-
|
|
13109
|
-
|
|
13110
|
-
|
|
13168
|
+
function uniqueDiagnostics(diagnostics) {
|
|
13169
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13170
|
+
return diagnostics.filter((d) => {
|
|
13171
|
+
const key = findingKey(d);
|
|
13172
|
+
if (seen.has(key)) return false;
|
|
13173
|
+
seen.add(key);
|
|
13174
|
+
return true;
|
|
13175
|
+
});
|
|
13111
13176
|
}
|
|
13112
|
-
|
|
13113
|
-
|
|
13114
|
-
path: "stack apply",
|
|
13115
|
-
args: (ctx) => ({ stack: ctx.stack?.id }),
|
|
13116
|
-
// The run sink ticks at both start and settle, so a read keyed on the
|
|
13117
|
-
// tick (a host's run list, the describe overlay) sees the in-flight run
|
|
13118
|
-
// as soon as it starts, not only once it ends.
|
|
13119
|
-
invalidates: "start+settle",
|
|
13120
|
-
result: slotSink("run")
|
|
13121
|
-
});
|
|
13122
|
-
var destroy = defineCommand({
|
|
13123
|
-
kind: "command",
|
|
13124
|
-
path: "stack destroy",
|
|
13125
|
-
args: (ctx) => ({ stack: ctx.stack?.id, yes: true }),
|
|
13126
|
-
// The typed confirmation is the stack's slug — the human-facing name a
|
|
13127
|
-
// user actually reads off the host's stack list — never its id, which
|
|
13128
|
-
// `args.stack` carries for the command itself but nobody types from
|
|
13129
|
-
// memory.
|
|
13130
|
-
confirm: (ctx) => ({
|
|
13131
|
-
text: `Destroy ${ctx.stack?.slug}? This runs terraform destroy on the runner.`,
|
|
13132
|
-
typed: ctx.stack?.slug
|
|
13133
|
-
}),
|
|
13134
|
-
invalidates: "start+settle",
|
|
13135
|
-
result: slotSink("run")
|
|
13136
|
-
});
|
|
13137
|
-
function scanNotice(e) {
|
|
13138
|
-
const { slug } = e.stack;
|
|
13139
|
-
const settled = e.settled;
|
|
13140
|
-
if (!settled) {
|
|
13141
|
-
return e.triggered ? `Drift scan triggered for stack ${slug} (${e.stack.id}).` : `Drift scan already in progress for stack ${slug}.`;
|
|
13142
|
-
}
|
|
13143
|
-
if (settled.undeterminedReason !== null) return void 0;
|
|
13144
|
-
if (settled.footprintDestroyed) {
|
|
13145
|
-
return `Drift scan complete for stack ${slug}: IN_SYNC (0 drifted) \u2014 its resources were destroyed, so there was nothing to compare.`;
|
|
13146
|
-
}
|
|
13147
|
-
if (settled.standingDriftFindings > 0) {
|
|
13148
|
-
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.`;
|
|
13149
|
-
}
|
|
13150
|
-
return `Drift scan complete for stack ${slug}: ${settled.driftStatus} (${settled.driftCount} drifted).`;
|
|
13177
|
+
function diagnosticsOf(sourceDiagnostics, reportFindings) {
|
|
13178
|
+
return uniqueDiagnostics([...sourceDiagnostics, ...reportFindings]);
|
|
13151
13179
|
}
|
|
13152
|
-
|
|
13153
|
-
|
|
13154
|
-
|
|
13155
|
-
|
|
13156
|
-
|
|
13157
|
-
|
|
13158
|
-
|
|
13159
|
-
|
|
13160
|
-
|
|
13161
|
-
|
|
13162
|
-
}
|
|
13180
|
+
|
|
13181
|
+
// src/core/report-fold.ts
|
|
13182
|
+
var REPORT_PATHS = ["module validate", "module convert", "module scan"];
|
|
13183
|
+
var FOLDS_AS = new Map([
|
|
13184
|
+
...REPORT_PATHS.map((path) => [path, path]),
|
|
13185
|
+
["stack import", "module convert"]
|
|
13186
|
+
]);
|
|
13187
|
+
var EMPTY_REPORT_FOLD = /* @__PURE__ */ new Map();
|
|
13188
|
+
function readEntry(path, exitCode, data) {
|
|
13189
|
+
if (carriesFailure(data)) {
|
|
13190
|
+
return { kind: "failure", path, exitCode, failure: parseCommandFailure(data) };
|
|
13163
13191
|
}
|
|
13164
|
-
|
|
13165
|
-
|
|
13166
|
-
|
|
13167
|
-
|
|
13168
|
-
|
|
13169
|
-
|
|
13170
|
-
|
|
13171
|
-
kind: "notify",
|
|
13172
|
-
consume: (rt, e) => rt.ports.presenter.notify("info", `Created stack ${e.slug}`)
|
|
13192
|
+
switch (path) {
|
|
13193
|
+
case "module validate":
|
|
13194
|
+
return { kind: "result", path, exitCode, document: parseBound(path, data) };
|
|
13195
|
+
case "module convert":
|
|
13196
|
+
return { kind: "result", path, exitCode, document: parseBound(path, data) };
|
|
13197
|
+
case "module scan":
|
|
13198
|
+
return { kind: "result", path, exitCode, document: parseBound(path, data) };
|
|
13173
13199
|
}
|
|
13174
|
-
});
|
|
13175
|
-
function residualAddresses(residuals) {
|
|
13176
|
-
return residuals.map((r) => r.address).join(", ");
|
|
13177
13200
|
}
|
|
13178
|
-
function
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
|
|
13201
|
+
function foldReport(prev, result) {
|
|
13202
|
+
const path = FOLDS_AS.get(result.path);
|
|
13203
|
+
if (path === void 0) return prev;
|
|
13204
|
+
const next = new Map(prev);
|
|
13205
|
+
if (result.document === "") next.delete(path);
|
|
13206
|
+
else next.set(path, readEntry(path, result.exitCode, JSON.parse(result.document)));
|
|
13207
|
+
return next;
|
|
13183
13208
|
}
|
|
13184
|
-
function
|
|
13185
|
-
|
|
13186
|
-
|
|
13187
|
-
|
|
13188
|
-
|
|
13189
|
-
|
|
13190
|
-
|
|
13191
|
-
|
|
13192
|
-
}
|
|
13193
|
-
const adopt = changed ? ` Review the change in git, commit it, then apply ${slug} to adopt them.` : "";
|
|
13194
|
-
if (e.importResiduals.length === 0) return ["info", `${imported}${adopt}`];
|
|
13195
|
-
return [
|
|
13196
|
-
"warn",
|
|
13197
|
-
`${imported}${adopt} Not adopted: ${residualAddresses(e.importResiduals)}; supply their import ids before applying, or the apply creates them anew.`
|
|
13198
|
-
];
|
|
13199
|
-
}
|
|
13200
|
-
var importResult = {
|
|
13201
|
-
kind: "notify",
|
|
13202
|
-
consume: (rt, e) => rt.ports.presenter.notify(...importNotice(e))
|
|
13203
|
-
};
|
|
13204
|
-
var importStack = defineCommand({
|
|
13205
|
-
kind: "command",
|
|
13206
|
-
path: "stack import",
|
|
13207
|
-
args: (ctx) => ({ stack: ctx.stack?.id }),
|
|
13208
|
-
invalidates: true,
|
|
13209
|
-
result: importResult
|
|
13210
|
-
});
|
|
13211
|
-
var importPartial = defineCommand({
|
|
13212
|
-
kind: "command",
|
|
13213
|
-
path: "stack import",
|
|
13214
|
-
args: (ctx) => ({ stack: ctx.stack?.id, allowPartial: true }),
|
|
13215
|
-
confirm: (ctx, _args, target) => ({
|
|
13216
|
-
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.`
|
|
13217
|
-
}),
|
|
13218
|
-
invalidates: true,
|
|
13219
|
-
result: importResult
|
|
13220
|
-
});
|
|
13221
|
-
var validate = defineCommand({
|
|
13222
|
-
kind: "command",
|
|
13223
|
-
path: "module validate",
|
|
13224
|
-
args: () => ({}),
|
|
13225
|
-
result: {
|
|
13226
|
-
kind: "notify",
|
|
13227
|
-
consume: (rt, e) => {
|
|
13228
|
-
if (e.exitClass === "ok") rt.ports.presenter.notify("info", `Valid for Lace \u2014 ${e.verdict}`);
|
|
13229
|
-
}
|
|
13230
|
-
}
|
|
13231
|
-
});
|
|
13232
|
-
var convert = defineCommand({
|
|
13233
|
-
kind: "command",
|
|
13234
|
-
path: "module convert",
|
|
13235
|
-
args: () => ({}),
|
|
13236
|
-
result: {
|
|
13237
|
-
kind: "notify",
|
|
13238
|
-
consume: (rt, e) => rt.ports.presenter.notify(
|
|
13239
|
-
"info",
|
|
13240
|
-
e.changed ? `Converted \u2014 ${e.written.length} file(s) written` : "Already lace-style \u2014 nothing to write"
|
|
13241
|
-
)
|
|
13242
|
-
}
|
|
13243
|
-
});
|
|
13244
|
-
var preview = defineCommand({
|
|
13245
|
-
kind: "command",
|
|
13246
|
-
path: "stack preview",
|
|
13247
|
-
args: (ctx) => ({ stack: ctx.stack?.id }),
|
|
13248
|
-
result: slotSink("preview")
|
|
13249
|
-
});
|
|
13250
|
-
var runCancel = defineCommand({
|
|
13251
|
-
kind: "command",
|
|
13252
|
-
path: "run cancel",
|
|
13253
|
-
args: (_ctx, target) => ({ run: target.runId }),
|
|
13254
|
-
invalidates: true,
|
|
13255
|
-
result: {
|
|
13256
|
-
kind: "notify",
|
|
13257
|
-
consume: (rt, e) => rt.ports.presenter.notify("info", `Run ${e.id} ${e.status}`)
|
|
13258
|
-
}
|
|
13259
|
-
});
|
|
13260
|
-
var followLogs = defineCommand({
|
|
13261
|
-
kind: "command",
|
|
13262
|
-
path: "run logs",
|
|
13263
|
-
args: (_ctx, target) => ({ run: target.runId, follow: true }),
|
|
13264
|
-
result: slotSink("follow")
|
|
13265
|
-
});
|
|
13266
|
-
var MODULE_COMMAND_ACTIONS = [
|
|
13267
|
-
{
|
|
13268
|
-
id: "validate",
|
|
13269
|
-
label: "Validate",
|
|
13270
|
-
icon: "validate",
|
|
13271
|
-
section: "check",
|
|
13272
|
-
placement: "toolbar",
|
|
13273
|
-
requiredPorts: ["commands"],
|
|
13274
|
-
requiredContext: ["root"],
|
|
13275
|
-
binding: validate
|
|
13276
|
-
},
|
|
13277
|
-
{
|
|
13278
|
-
id: "convert",
|
|
13279
|
-
label: "Convert",
|
|
13280
|
-
icon: "convert",
|
|
13281
|
-
section: "check",
|
|
13282
|
-
placement: "toolbar",
|
|
13283
|
-
requiredPorts: ["commands"],
|
|
13284
|
-
requiredContext: ["root"],
|
|
13285
|
-
binding: convert
|
|
13286
|
-
},
|
|
13287
|
-
// Convert on the source-refused banner while the tree is out of lace
|
|
13288
|
-
// shape: the same `module convert` the toolbar runs, and the choice the
|
|
13289
|
-
// banner says of it. The engine re-derives the tree it writes, which
|
|
13290
|
-
// accepts it and lifts the lock.
|
|
13291
|
-
{
|
|
13292
|
-
id: "convert-refused",
|
|
13293
|
-
label: "Convert",
|
|
13294
|
-
choice: "Convert restructures it in place; a stack's apply creates only what its state does not hold yet.",
|
|
13295
|
-
icon: "convert",
|
|
13296
|
-
placement: { row: "source-refused" },
|
|
13297
|
-
requiredPorts: ["commands"],
|
|
13298
|
-
requiredContext: ["root", "needsConversion"],
|
|
13299
|
-
binding: convert
|
|
13300
|
-
}
|
|
13301
|
-
];
|
|
13302
|
-
var STACK_COMMAND_ACTIONS = [
|
|
13303
|
-
{
|
|
13304
|
-
id: "apply",
|
|
13305
|
-
label: "Apply",
|
|
13306
|
-
placement: "toolbar",
|
|
13307
|
-
requiredPorts: ["commands"],
|
|
13308
|
-
// `stack apply` gates on the tf and certification of the directory it
|
|
13309
|
-
// runs in (submit.Prepare(env.Root)) before it ever reaches the
|
|
13310
|
-
// runner, so a mount with no root can't run it even with a stack
|
|
13311
|
-
// chosen — the same root gate `validate`/`convert` need. It ships
|
|
13312
|
-
// whatever tf is on disk, not the canvas's own working IR.
|
|
13313
|
-
requiredContext: ["root", "stack"],
|
|
13314
|
-
binding: apply
|
|
13315
|
-
},
|
|
13316
|
-
{
|
|
13317
|
-
id: "destroy",
|
|
13318
|
-
label: "Destroy",
|
|
13319
|
-
placement: "toolbar",
|
|
13320
|
-
requiredPorts: ["commands"],
|
|
13321
|
-
// `stack destroy` shares the CLI's `executeRun` with `stack apply` and
|
|
13322
|
-
// runs under `env.Root`, so it needs the identical context tuple.
|
|
13323
|
-
requiredContext: ["root", "stack"],
|
|
13324
|
-
binding: destroy
|
|
13325
|
-
},
|
|
13326
|
-
{
|
|
13327
|
-
id: "scan",
|
|
13328
|
-
label: "Scan for drift",
|
|
13329
|
-
placement: "toolbar",
|
|
13330
|
-
requiredPorts: ["commands"],
|
|
13331
|
-
requiredContext: ["stack"],
|
|
13332
|
-
binding: scan
|
|
13333
|
-
},
|
|
13334
|
-
{
|
|
13335
|
-
id: "create",
|
|
13336
|
-
label: "Create stack",
|
|
13337
|
-
placement: "toolbar",
|
|
13338
|
-
requiredPorts: ["commands"],
|
|
13339
|
-
requiredContext: ["root"],
|
|
13340
|
-
binding: create
|
|
13341
|
-
},
|
|
13342
|
-
{
|
|
13343
|
-
id: "import",
|
|
13344
|
-
label: "Import existing resources",
|
|
13345
|
-
placement: "toolbar",
|
|
13346
|
-
requiredPorts: ["commands"],
|
|
13347
|
-
// `stack import` writes the directory it runs in, the same way
|
|
13348
|
-
// Convert does.
|
|
13349
|
-
requiredContext: ["root", "stack"],
|
|
13350
|
-
binding: importStack
|
|
13351
|
-
},
|
|
13352
|
-
{
|
|
13353
|
-
id: "import-partial",
|
|
13354
|
-
label: "Import the rest",
|
|
13355
|
-
placement: { row: "failure" },
|
|
13356
|
-
requiredPorts: ["commands"],
|
|
13357
|
-
requiredContext: ["root", "stack"],
|
|
13358
|
-
answers: ["import_residual"],
|
|
13359
|
-
binding: importPartial
|
|
13360
|
-
},
|
|
13361
|
-
{
|
|
13362
|
-
id: "preview",
|
|
13363
|
-
label: "Preview",
|
|
13364
|
-
placement: "toolbar",
|
|
13365
|
-
requiredPorts: ["commands"],
|
|
13366
|
-
// `stack preview` plans the tf of the directory it runs in — a stack
|
|
13367
|
-
// alone isn't enough, the mount needs the root too.
|
|
13368
|
-
requiredContext: ["root", "stack"],
|
|
13369
|
-
binding: preview
|
|
13370
|
-
},
|
|
13371
|
-
{
|
|
13372
|
-
id: "run-cancel",
|
|
13373
|
-
label: "Cancel",
|
|
13374
|
-
placement: { row: "runs" },
|
|
13375
|
-
requiredPorts: ["commands"],
|
|
13376
|
-
requiredTarget: ["runId"],
|
|
13377
|
-
binding: runCancel
|
|
13378
|
-
},
|
|
13379
|
-
{
|
|
13380
|
-
id: "follow-logs",
|
|
13381
|
-
label: "Follow logs",
|
|
13382
|
-
placement: { row: "runs" },
|
|
13383
|
-
requiredPorts: ["commands"],
|
|
13384
|
-
requiredTarget: ["runId"],
|
|
13385
|
-
binding: followLogs
|
|
13386
|
-
}
|
|
13387
|
-
];
|
|
13388
|
-
var CORE_COMMAND_ACTIONS = [
|
|
13389
|
-
...STACK_COMMAND_ACTIONS,
|
|
13390
|
-
...MODULE_COMMAND_ACTIONS
|
|
13391
|
-
];
|
|
13392
|
-
|
|
13393
|
-
// src/core/diagnostics.ts
|
|
13394
|
-
var NOT_LACE_SHAPE = "not_lace_shape";
|
|
13395
|
-
function holdsLaceShapeRefusal(diagnostics) {
|
|
13396
|
-
return diagnostics.some((d) => d.code === NOT_LACE_SHAPE);
|
|
13397
|
-
}
|
|
13398
|
-
function findingKey(d) {
|
|
13399
|
-
return JSON.stringify([
|
|
13400
|
-
d.file,
|
|
13401
|
-
d.line,
|
|
13402
|
-
d.message,
|
|
13403
|
-
d.module_key,
|
|
13404
|
-
d.instance_id,
|
|
13405
|
-
d.input_name,
|
|
13406
|
-
d.address
|
|
13407
|
-
]);
|
|
13408
|
-
}
|
|
13409
|
-
function uniqueDiagnostics(diagnostics) {
|
|
13410
|
-
const seen = /* @__PURE__ */ new Set();
|
|
13411
|
-
return diagnostics.filter((d) => {
|
|
13412
|
-
const key = findingKey(d);
|
|
13413
|
-
if (seen.has(key)) return false;
|
|
13414
|
-
seen.add(key);
|
|
13415
|
-
return true;
|
|
13416
|
-
});
|
|
13417
|
-
}
|
|
13418
|
-
function diagnosticsOf(sourceDiagnostics, reportFindings) {
|
|
13419
|
-
return uniqueDiagnostics([...sourceDiagnostics, ...reportFindings]);
|
|
13420
|
-
}
|
|
13421
|
-
|
|
13422
|
-
// src/core/report-fold.ts
|
|
13423
|
-
var REPORT_PATHS = ["module validate", "module convert", "module scan"];
|
|
13424
|
-
var REPORT_PATH_SET = new Set(REPORT_PATHS);
|
|
13425
|
-
function isReportPath(path) {
|
|
13426
|
-
return REPORT_PATH_SET.has(path);
|
|
13427
|
-
}
|
|
13428
|
-
var EMPTY_REPORT_FOLD = /* @__PURE__ */ new Map();
|
|
13429
|
-
function readEntry(path, exitCode, data) {
|
|
13430
|
-
if (carriesFailure(data)) {
|
|
13431
|
-
return { kind: "failure", path, exitCode, failure: parseCommandFailure(data) };
|
|
13432
|
-
}
|
|
13433
|
-
switch (path) {
|
|
13434
|
-
case "module validate":
|
|
13435
|
-
return { kind: "result", path, exitCode, document: parseBound(path, data) };
|
|
13436
|
-
case "module convert":
|
|
13437
|
-
return { kind: "result", path, exitCode, document: parseBound(path, data) };
|
|
13438
|
-
case "module scan":
|
|
13439
|
-
return { kind: "result", path, exitCode, document: parseBound(path, data) };
|
|
13440
|
-
}
|
|
13441
|
-
}
|
|
13442
|
-
function foldReport(prev, result) {
|
|
13443
|
-
if (!isReportPath(result.path)) return prev;
|
|
13444
|
-
const next = new Map(prev);
|
|
13445
|
-
if (result.document === "") next.delete(result.path);
|
|
13446
|
-
else next.set(result.path, readEntry(result.path, result.exitCode, JSON.parse(result.document)));
|
|
13447
|
-
return next;
|
|
13448
|
-
}
|
|
13449
|
-
function treeHashOf(entry) {
|
|
13450
|
-
if (entry.kind === "failure") return void 0;
|
|
13451
|
-
switch (entry.path) {
|
|
13452
|
-
case "module validate":
|
|
13453
|
-
case "module scan":
|
|
13454
|
-
return entry.document.treeHash;
|
|
13455
|
-
case "module convert":
|
|
13456
|
-
return entry.document.validate.treeHash;
|
|
13209
|
+
function treeHashOf(entry) {
|
|
13210
|
+
if (entry.kind === "failure") return void 0;
|
|
13211
|
+
switch (entry.path) {
|
|
13212
|
+
case "module validate":
|
|
13213
|
+
case "module scan":
|
|
13214
|
+
return entry.document.treeHash;
|
|
13215
|
+
case "module convert":
|
|
13216
|
+
return entry.document.validate.treeHash;
|
|
13457
13217
|
}
|
|
13458
13218
|
}
|
|
13459
13219
|
function currentReport(fold, treeHash) {
|
|
@@ -13563,148 +13323,527 @@ function reduceRun(prev, token, event) {
|
|
|
13563
13323
|
phases: closePhases(phases)
|
|
13564
13324
|
};
|
|
13565
13325
|
}
|
|
13566
|
-
return { token, outcome: { kind: "running" }, lastLog, submitted, phases };
|
|
13567
|
-
}
|
|
13568
|
-
function
|
|
13569
|
-
|
|
13570
|
-
}
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
|
|
13577
|
-
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
|
|
13584
|
-
|
|
13585
|
-
|
|
13586
|
-
|
|
13587
|
-
|
|
13588
|
-
|
|
13589
|
-
|
|
13590
|
-
|
|
13591
|
-
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
|
|
13595
|
-
|
|
13596
|
-
|
|
13597
|
-
|
|
13326
|
+
return { token, outcome: { kind: "running" }, lastLog, submitted, phases };
|
|
13327
|
+
}
|
|
13328
|
+
function failureSays(error, command) {
|
|
13329
|
+
if (error instanceof CommandExitError) {
|
|
13330
|
+
return error.failure ? { message: error.failure.message, failure: error.failure } : { message: error.stderrTail };
|
|
13331
|
+
}
|
|
13332
|
+
if (error instanceof CommandUnobservedError && command.kind === "read") {
|
|
13333
|
+
return { message: `the stream ended before \`lace ${command.path}\` finished; run it again` };
|
|
13334
|
+
}
|
|
13335
|
+
return { message: error instanceof Error ? error.message : String(error) };
|
|
13336
|
+
}
|
|
13337
|
+
var RUN = { kind: "write" };
|
|
13338
|
+
function settleRun(prev, token, error) {
|
|
13339
|
+
const carried = prev && prev.token === token ? prev : null;
|
|
13340
|
+
const lastLog = carried?.lastLog ?? null;
|
|
13341
|
+
const submitted = carried?.submitted ?? false;
|
|
13342
|
+
const phases = closePhases(carried?.phases ?? []);
|
|
13343
|
+
if (error instanceof CommandDetachedError || error instanceof CommandUnobservedError)
|
|
13344
|
+
return { token, outcome: { kind: "detached", submitted }, lastLog, submitted, phases };
|
|
13345
|
+
if (error instanceof CommandExitError) {
|
|
13346
|
+
if (error.code === 130)
|
|
13347
|
+
return { token, outcome: { kind: "cancelled" }, lastLog, submitted, phases };
|
|
13348
|
+
if (error.code === 143)
|
|
13349
|
+
return { token, outcome: { kind: "detached", submitted }, lastLog, submitted, phases };
|
|
13350
|
+
if (error.code === 7)
|
|
13351
|
+
return {
|
|
13352
|
+
token,
|
|
13353
|
+
outcome: { kind: "blocked", ...failureSays(error, RUN) },
|
|
13354
|
+
lastLog,
|
|
13355
|
+
submitted,
|
|
13356
|
+
phases
|
|
13357
|
+
};
|
|
13358
|
+
}
|
|
13359
|
+
return {
|
|
13360
|
+
token,
|
|
13361
|
+
outcome: { kind: "failed", ...failureSays(error, RUN) },
|
|
13362
|
+
lastLog,
|
|
13363
|
+
submitted,
|
|
13364
|
+
phases
|
|
13365
|
+
};
|
|
13366
|
+
}
|
|
13367
|
+
function reducePreview(_prev, token, event) {
|
|
13368
|
+
return { token, data: event };
|
|
13369
|
+
}
|
|
13370
|
+
function reduceReport(prev, session, result) {
|
|
13371
|
+
const fold = foldReport(prev?.sessions.get(session) ?? EMPTY_REPORT_FOLD, result);
|
|
13372
|
+
return { sessions: new Map(prev?.sessions).set(session, fold) };
|
|
13373
|
+
}
|
|
13374
|
+
function reduceFollow(prev, token, event) {
|
|
13375
|
+
const carried = prev && prev.token === token ? prev : null;
|
|
13376
|
+
const runId = carried?.runId ?? "";
|
|
13377
|
+
const lines = carried?.lines ?? [];
|
|
13378
|
+
if (event.type === "log") return { token, runId, lines: [...lines, event.text], done: false };
|
|
13379
|
+
return { token, runId, lines, done: true };
|
|
13380
|
+
}
|
|
13381
|
+
function createResultStore() {
|
|
13382
|
+
let slots = {
|
|
13383
|
+
run: null,
|
|
13384
|
+
preview: null,
|
|
13385
|
+
report: null,
|
|
13386
|
+
follow: null,
|
|
13387
|
+
running: /* @__PURE__ */ new Map()
|
|
13388
|
+
};
|
|
13389
|
+
let tick = 0;
|
|
13390
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
13391
|
+
const notify = () => {
|
|
13392
|
+
for (const listener of listeners) listener();
|
|
13393
|
+
};
|
|
13394
|
+
const retiredTokens = /* @__PURE__ */ new WeakSet();
|
|
13395
|
+
return {
|
|
13396
|
+
getSnapshot() {
|
|
13397
|
+
return slots;
|
|
13398
|
+
},
|
|
13399
|
+
getTick() {
|
|
13400
|
+
return tick;
|
|
13401
|
+
},
|
|
13402
|
+
subscribe(listener) {
|
|
13403
|
+
listeners.add(listener);
|
|
13404
|
+
return () => listeners.delete(listener);
|
|
13405
|
+
},
|
|
13406
|
+
write(kind, token, value, readOver) {
|
|
13407
|
+
if (retiredTokens.has(token)) return;
|
|
13408
|
+
slots = { ...slots, [kind]: applySlot(kind, slots[kind], token, value, readOver) };
|
|
13409
|
+
notify();
|
|
13410
|
+
},
|
|
13411
|
+
fail(kind, token, error) {
|
|
13412
|
+
if (kind !== "run") return false;
|
|
13413
|
+
if (retiredTokens.has(token) || !slots.run) return true;
|
|
13414
|
+
slots = { ...slots, run: stamp(settleRun(slots.run, token, error), slots.run.readOver) };
|
|
13415
|
+
notify();
|
|
13416
|
+
return true;
|
|
13417
|
+
},
|
|
13418
|
+
begin(kind, token, readOver, started) {
|
|
13419
|
+
if (kind === "run") {
|
|
13420
|
+
slots = {
|
|
13421
|
+
...slots,
|
|
13422
|
+
run: {
|
|
13423
|
+
token,
|
|
13424
|
+
outcome: { kind: "running" },
|
|
13425
|
+
lastLog: null,
|
|
13426
|
+
submitted: false,
|
|
13427
|
+
phases: [],
|
|
13428
|
+
readOver
|
|
13429
|
+
}
|
|
13430
|
+
};
|
|
13431
|
+
} else if (kind === "follow") {
|
|
13432
|
+
slots = {
|
|
13433
|
+
...slots,
|
|
13434
|
+
follow: { token, runId: started.target.runId ?? "", lines: [], done: false, readOver }
|
|
13435
|
+
};
|
|
13436
|
+
} else if (kind === "notify") {
|
|
13437
|
+
const { on, path, label } = started;
|
|
13438
|
+
slots = { ...slots, running: new Map(slots.running).set(on, { token, path, label }) };
|
|
13439
|
+
} else {
|
|
13440
|
+
return;
|
|
13441
|
+
}
|
|
13442
|
+
notify();
|
|
13443
|
+
},
|
|
13444
|
+
detach(kind, token) {
|
|
13445
|
+
if (kind === "follow" && slots.follow?.token === token) {
|
|
13446
|
+
slots = { ...slots, follow: null };
|
|
13447
|
+
notify();
|
|
13448
|
+
} else if (kind === "report" && slots.report?.sessions.has(token)) {
|
|
13449
|
+
const sessions = new Map(slots.report.sessions);
|
|
13450
|
+
sessions.delete(token);
|
|
13451
|
+
slots = {
|
|
13452
|
+
...slots,
|
|
13453
|
+
report: sessions.size > 0 ? { sessions, readOver: slots.report.readOver } : null
|
|
13454
|
+
};
|
|
13455
|
+
notify();
|
|
13456
|
+
} else if (kind === "run" && slots.run?.token === token) {
|
|
13457
|
+
const settled = settleRun(slots.run, token, new CommandDetachedError());
|
|
13458
|
+
slots = { ...slots, run: stamp(settled, slots.run.readOver) };
|
|
13459
|
+
notify();
|
|
13460
|
+
} else if (kind === "notify") {
|
|
13461
|
+
const running = new Map([...slots.running].filter(([, mark]) => mark.token !== token));
|
|
13462
|
+
if (running.size !== slots.running.size) {
|
|
13463
|
+
slots = { ...slots, running };
|
|
13464
|
+
notify();
|
|
13465
|
+
}
|
|
13466
|
+
}
|
|
13467
|
+
retiredTokens.add(token);
|
|
13468
|
+
},
|
|
13469
|
+
busy(kind, on) {
|
|
13470
|
+
if (kind === "run") {
|
|
13471
|
+
return slots.run?.outcome.kind === "running" ? { kind: "run" } : void 0;
|
|
13472
|
+
}
|
|
13473
|
+
if (kind !== "notify") return void 0;
|
|
13474
|
+
const running = slots.running.get(on);
|
|
13475
|
+
return running ? { kind: "notify", running } : void 0;
|
|
13476
|
+
},
|
|
13477
|
+
bumpTick() {
|
|
13478
|
+
tick += 1;
|
|
13479
|
+
notify();
|
|
13480
|
+
}
|
|
13481
|
+
};
|
|
13482
|
+
}
|
|
13483
|
+
|
|
13484
|
+
// src/core/define-command.ts
|
|
13485
|
+
function defineCommand(binding) {
|
|
13486
|
+
return {
|
|
13487
|
+
kind: "command",
|
|
13488
|
+
path: binding.path,
|
|
13489
|
+
confirms: binding.confirm !== void 0,
|
|
13490
|
+
resultKind: binding.result.kind,
|
|
13491
|
+
invalidates: binding.invalidates,
|
|
13492
|
+
partialArgs(ctx, target) {
|
|
13493
|
+
return binding.args(ctx, target);
|
|
13494
|
+
},
|
|
13495
|
+
confirmSpec(ctx, target, formArgs) {
|
|
13496
|
+
if (!binding.confirm) return void 0;
|
|
13497
|
+
const merged = completeArgs(binding.path, { ...binding.args(ctx, target), ...formArgs });
|
|
13498
|
+
if (!merged.ok) return void 0;
|
|
13499
|
+
return binding.confirm(ctx, merged.args, target);
|
|
13500
|
+
},
|
|
13501
|
+
async start(rt, ctx, target, formArgs, signal) {
|
|
13502
|
+
const merged = completeArgs(binding.path, { ...binding.args(ctx, target), ...formArgs });
|
|
13503
|
+
if (!merged.ok) return null;
|
|
13504
|
+
const commands = rt.ports.commands;
|
|
13505
|
+
if (!commands) return null;
|
|
13506
|
+
const invocation = commands.invoke(binding.path, merged.args, signal, rt.cwd);
|
|
13507
|
+
rt.begin();
|
|
13508
|
+
if (binding.invalidates === "start+settle") rt.tick();
|
|
13509
|
+
void (async () => {
|
|
13510
|
+
let rendered = false;
|
|
13511
|
+
try {
|
|
13512
|
+
for await (const event of invocation.events) {
|
|
13513
|
+
rendered = true;
|
|
13514
|
+
binding.result.consume(rt, event);
|
|
13515
|
+
}
|
|
13516
|
+
if (binding.invalidates) rt.tick();
|
|
13517
|
+
} catch (err) {
|
|
13518
|
+
const settledByDocument = rendered && binding.result.kind === "notify" && (err instanceof CommandExitError || err instanceof CommandUnobservedError);
|
|
13519
|
+
if (!rt.fail(err) && !(err instanceof CommandDetachedError) && !settledByDocument) {
|
|
13520
|
+
const { message, failure } = failureSays(
|
|
13521
|
+
err,
|
|
13522
|
+
binding.result.kind === "preview" || binding.result.kind === "follow" ? { kind: "read", path: binding.path } : { kind: "write" }
|
|
13523
|
+
);
|
|
13524
|
+
rt.ports.presenter.notify("error", message, ...failure ? [failure] : []);
|
|
13525
|
+
}
|
|
13526
|
+
if (binding.invalidates) rt.tick();
|
|
13527
|
+
} finally {
|
|
13528
|
+
rt.settled?.();
|
|
13529
|
+
}
|
|
13530
|
+
})();
|
|
13531
|
+
return { cancel: () => invocation.cancel() };
|
|
13532
|
+
}
|
|
13533
|
+
};
|
|
13534
|
+
}
|
|
13535
|
+
|
|
13536
|
+
// src/core/actions.ts
|
|
13537
|
+
function whyNotValid(v) {
|
|
13538
|
+
if (v.failure) return v.failure.message;
|
|
13539
|
+
const errors = v.diagnostics.filter((d) => d.severity === "error");
|
|
13540
|
+
if (errors.length === 0) return void 0;
|
|
13541
|
+
return `${errors[0].message} (${errors.length} ${errors.length === 1 ? "error" : "errors"})`;
|
|
13542
|
+
}
|
|
13543
|
+
function didNotValidate(v) {
|
|
13544
|
+
const why = whyNotValid(v);
|
|
13545
|
+
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.`;
|
|
13546
|
+
}
|
|
13547
|
+
function beside(v) {
|
|
13548
|
+
return v.failure ? [v.failure] : [];
|
|
13549
|
+
}
|
|
13550
|
+
function slotSink(kind) {
|
|
13551
|
+
return { kind, consume: (rt, e) => rt.write(kind, rt.token, e) };
|
|
13552
|
+
}
|
|
13553
|
+
var apply = defineCommand({
|
|
13554
|
+
kind: "command",
|
|
13555
|
+
path: "stack apply",
|
|
13556
|
+
args: (ctx) => ({ stack: ctx.stack?.id }),
|
|
13557
|
+
// The run sink ticks at both start and settle, so a read keyed on the
|
|
13558
|
+
// tick (a host's run list, the describe overlay) sees the in-flight run
|
|
13559
|
+
// as soon as it starts, not only once it ends.
|
|
13560
|
+
invalidates: "start+settle",
|
|
13561
|
+
result: slotSink("run")
|
|
13562
|
+
});
|
|
13563
|
+
var destroy = defineCommand({
|
|
13564
|
+
kind: "command",
|
|
13565
|
+
path: "stack destroy",
|
|
13566
|
+
args: (ctx) => ({ stack: ctx.stack?.id, yes: true }),
|
|
13567
|
+
// The typed confirmation is the stack's slug — the human-facing name a
|
|
13568
|
+
// user actually reads off the host's stack list — never its id, which
|
|
13569
|
+
// `args.stack` carries for the command itself but nobody types from
|
|
13570
|
+
// memory.
|
|
13571
|
+
confirm: (ctx) => ({
|
|
13572
|
+
text: `Destroy ${ctx.stack?.slug}? This runs terraform destroy on the runner.`,
|
|
13573
|
+
typed: ctx.stack?.slug
|
|
13574
|
+
}),
|
|
13575
|
+
invalidates: "start+settle",
|
|
13576
|
+
result: slotSink("run")
|
|
13577
|
+
});
|
|
13578
|
+
function scanNotice(e) {
|
|
13579
|
+
const { slug } = e.stack;
|
|
13580
|
+
const settled = e.settled;
|
|
13581
|
+
if (!settled) {
|
|
13582
|
+
return [
|
|
13583
|
+
"info",
|
|
13584
|
+
e.triggered ? `Drift scan triggered for stack ${slug} (${e.stack.id}).` : `Drift scan already in progress for stack ${slug}.`
|
|
13585
|
+
];
|
|
13586
|
+
}
|
|
13587
|
+
if (settled.undeterminedMessage !== null) return ["warn", settled.undeterminedMessage];
|
|
13588
|
+
if (settled.footprintDestroyed) {
|
|
13589
|
+
return [
|
|
13590
|
+
"info",
|
|
13591
|
+
`Drift scan complete for stack ${slug}: IN_SYNC (0 drifted) \u2014 its resources were destroyed, so there was nothing to compare.`
|
|
13592
|
+
];
|
|
13593
|
+
}
|
|
13594
|
+
if (settled.standingDriftFindings > 0) {
|
|
13595
|
+
return [
|
|
13596
|
+
"info",
|
|
13597
|
+
`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.`
|
|
13598
|
+
];
|
|
13599
|
+
}
|
|
13600
|
+
return [
|
|
13601
|
+
"info",
|
|
13602
|
+
`Drift scan complete for stack ${slug}: ${settled.driftStatus} (${settled.driftCount} drifted).`
|
|
13603
|
+
];
|
|
13604
|
+
}
|
|
13605
|
+
var scan = defineCommand({
|
|
13606
|
+
kind: "command",
|
|
13607
|
+
path: "stack scan",
|
|
13608
|
+
args: (ctx) => ({ stack: ctx.stack?.id, wait: true }),
|
|
13609
|
+
invalidates: true,
|
|
13610
|
+
result: {
|
|
13611
|
+
kind: "notify",
|
|
13612
|
+
consume: (rt, e) => rt.ports.presenter.notify(...scanNotice(e))
|
|
13613
|
+
}
|
|
13614
|
+
});
|
|
13615
|
+
var create = defineCommand({
|
|
13616
|
+
kind: "command",
|
|
13617
|
+
path: "stack create",
|
|
13618
|
+
args: (ctx) => ({ source: ctx.root }),
|
|
13619
|
+
invalidates: true,
|
|
13620
|
+
result: {
|
|
13621
|
+
kind: "notify",
|
|
13622
|
+
consume: (rt, e) => rt.ports.presenter.notify("info", `Created stack ${e.slug}`)
|
|
13623
|
+
}
|
|
13624
|
+
});
|
|
13625
|
+
function residualAddresses(residuals) {
|
|
13626
|
+
return residuals.map((r) => r.address).join(", ");
|
|
13627
|
+
}
|
|
13628
|
+
function treeChanges(e) {
|
|
13629
|
+
return [
|
|
13630
|
+
...e.written.length === 0 ? [] : [`rewriting ${e.written.join(", ")} in place`],
|
|
13631
|
+
...e.removed.length === 0 ? [] : [`removing ${e.removed.join(", ")}`]
|
|
13632
|
+
];
|
|
13633
|
+
}
|
|
13634
|
+
function importNotice(e) {
|
|
13635
|
+
const { slug } = e.stack;
|
|
13636
|
+
const changes = treeChanges(e);
|
|
13637
|
+
const files = changes.length > 0 ? `, ${changes.join(" and ")}` : "";
|
|
13638
|
+
const imported = `Imported ${e.importBlocks} resource(s) into ${slug}${files}.`;
|
|
13639
|
+
if (e.validate.exitClass !== "ok") {
|
|
13640
|
+
return ["warn", `${imported} ${didNotValidate(e.validate)}`, ...beside(e.validate)];
|
|
13641
|
+
}
|
|
13642
|
+
const adopt = e.changed ? ` Review the change in git, commit it, then apply ${slug} to adopt them.` : "";
|
|
13643
|
+
if (e.importResiduals.length === 0) return ["info", `${imported}${adopt}`];
|
|
13644
|
+
return [
|
|
13645
|
+
"warn",
|
|
13646
|
+
`${imported}${adopt} Not adopted: ${residualAddresses(e.importResiduals)}; supply their import ids before applying, or the apply creates them anew.`
|
|
13647
|
+
];
|
|
13648
|
+
}
|
|
13649
|
+
var importResult = {
|
|
13650
|
+
kind: "notify",
|
|
13651
|
+
consume: (rt, e) => rt.ports.presenter.notify(...importNotice(e))
|
|
13652
|
+
};
|
|
13653
|
+
var importStack = defineCommand({
|
|
13654
|
+
kind: "command",
|
|
13655
|
+
path: "stack import",
|
|
13656
|
+
args: (ctx) => ({ stack: ctx.stack?.id }),
|
|
13657
|
+
invalidates: true,
|
|
13658
|
+
result: importResult
|
|
13659
|
+
});
|
|
13660
|
+
var importPartial = defineCommand({
|
|
13661
|
+
kind: "command",
|
|
13662
|
+
path: "stack import",
|
|
13663
|
+
args: (ctx) => ({ stack: ctx.stack?.id, allowPartial: true }),
|
|
13664
|
+
confirm: (ctx, _args, target) => ({
|
|
13665
|
+
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.`
|
|
13666
|
+
}),
|
|
13667
|
+
invalidates: true,
|
|
13668
|
+
result: importResult
|
|
13669
|
+
});
|
|
13670
|
+
function validateNotice(v) {
|
|
13671
|
+
if (v.exitClass === "ok") return ["info", `Valid for Lace \u2014 ${v.verdict}`];
|
|
13672
|
+
if (v.failure) return ["error", v.failure.message, v.failure];
|
|
13673
|
+
const why = whyNotValid(v);
|
|
13674
|
+
return ["warn", why === void 0 ? "Not valid for Lace" : `Not valid: ${why}`];
|
|
13675
|
+
}
|
|
13676
|
+
function convertNotice(e) {
|
|
13677
|
+
const converted = e.changed ? `Converted \u2014 ${e.written.length} file(s) written` : "Already lace-style \u2014 nothing to write";
|
|
13678
|
+
if (e.validate.exitClass === "ok") return ["info", converted];
|
|
13679
|
+
return ["warn", `${converted}. ${didNotValidate(e.validate)}`, ...beside(e.validate)];
|
|
13680
|
+
}
|
|
13681
|
+
var validate = defineCommand({
|
|
13682
|
+
kind: "command",
|
|
13683
|
+
path: "module validate",
|
|
13684
|
+
args: () => ({}),
|
|
13685
|
+
result: {
|
|
13686
|
+
kind: "notify",
|
|
13687
|
+
consume: (rt, e) => rt.ports.presenter.notify(...validateNotice(e))
|
|
13688
|
+
}
|
|
13689
|
+
});
|
|
13690
|
+
var convert = defineCommand({
|
|
13691
|
+
kind: "command",
|
|
13692
|
+
path: "module convert",
|
|
13693
|
+
args: () => ({}),
|
|
13694
|
+
result: {
|
|
13695
|
+
kind: "notify",
|
|
13696
|
+
consume: (rt, e) => rt.ports.presenter.notify(...convertNotice(e))
|
|
13697
|
+
}
|
|
13698
|
+
});
|
|
13699
|
+
var preview = defineCommand({
|
|
13700
|
+
kind: "command",
|
|
13701
|
+
path: "stack preview",
|
|
13702
|
+
args: (ctx) => ({ stack: ctx.stack?.id }),
|
|
13703
|
+
result: slotSink("preview")
|
|
13704
|
+
});
|
|
13705
|
+
var runCancel = defineCommand({
|
|
13706
|
+
kind: "command",
|
|
13707
|
+
path: "run cancel",
|
|
13708
|
+
args: (_ctx, target) => ({ run: target.runId }),
|
|
13709
|
+
invalidates: true,
|
|
13710
|
+
result: {
|
|
13711
|
+
kind: "notify",
|
|
13712
|
+
consume: (rt, e) => rt.ports.presenter.notify("info", `Run ${e.id} ${e.status}`)
|
|
13713
|
+
}
|
|
13714
|
+
});
|
|
13715
|
+
var followLogs = defineCommand({
|
|
13716
|
+
kind: "command",
|
|
13717
|
+
path: "run logs",
|
|
13718
|
+
args: (_ctx, target) => ({ run: target.runId, follow: true }),
|
|
13719
|
+
result: slotSink("follow")
|
|
13720
|
+
});
|
|
13721
|
+
var MODULE_COMMAND_ACTIONS = [
|
|
13722
|
+
{
|
|
13723
|
+
id: "validate",
|
|
13724
|
+
label: "Validate",
|
|
13725
|
+
icon: "validate",
|
|
13726
|
+
section: "check",
|
|
13727
|
+
placement: "toolbar",
|
|
13728
|
+
requiredPorts: ["commands"],
|
|
13729
|
+
requiredContext: ["root"],
|
|
13730
|
+
binding: validate
|
|
13731
|
+
},
|
|
13732
|
+
{
|
|
13733
|
+
id: "convert",
|
|
13734
|
+
label: "Convert",
|
|
13735
|
+
icon: "convert",
|
|
13736
|
+
section: "check",
|
|
13737
|
+
placement: "toolbar",
|
|
13738
|
+
requiredPorts: ["commands"],
|
|
13739
|
+
requiredContext: ["root"],
|
|
13740
|
+
binding: convert
|
|
13741
|
+
},
|
|
13742
|
+
// Convert on the source-refused banner while the tree is out of lace
|
|
13743
|
+
// shape: the same `module convert` the toolbar runs, and the choice the
|
|
13744
|
+
// banner says of it. The engine re-derives the tree it writes, which
|
|
13745
|
+
// accepts it and lifts the lock.
|
|
13746
|
+
{
|
|
13747
|
+
id: "convert-refused",
|
|
13748
|
+
label: "Convert",
|
|
13749
|
+
choice: "Convert restructures it in place; a stack's apply creates only what its state does not hold yet.",
|
|
13750
|
+
icon: "convert",
|
|
13751
|
+
placement: { row: "source-refused" },
|
|
13752
|
+
requiredPorts: ["commands"],
|
|
13753
|
+
requiredContext: ["root", "needsConversion"],
|
|
13754
|
+
binding: convert
|
|
13755
|
+
}
|
|
13756
|
+
];
|
|
13757
|
+
var STACK_COMMAND_ACTIONS = [
|
|
13758
|
+
{
|
|
13759
|
+
id: "apply",
|
|
13760
|
+
label: "Apply",
|
|
13761
|
+
placement: "toolbar",
|
|
13762
|
+
requiredPorts: ["commands"],
|
|
13763
|
+
// `stack apply` gates on the tf and certification of the directory it
|
|
13764
|
+
// runs in (submit.Prepare(env.Root)) before it ever reaches the
|
|
13765
|
+
// runner, so a mount with no root can't run it even with a stack
|
|
13766
|
+
// chosen — the same root gate `validate`/`convert` need. It ships
|
|
13767
|
+
// whatever tf is on disk, not the canvas's own working IR.
|
|
13768
|
+
requiredContext: ["root", "stack"],
|
|
13769
|
+
binding: apply
|
|
13770
|
+
},
|
|
13771
|
+
{
|
|
13772
|
+
id: "destroy",
|
|
13773
|
+
label: "Destroy",
|
|
13774
|
+
placement: "toolbar",
|
|
13775
|
+
requiredPorts: ["commands"],
|
|
13776
|
+
// `stack destroy` shares the CLI's `executeRun` with `stack apply` and
|
|
13777
|
+
// runs under `env.Root`, so it needs the identical context tuple.
|
|
13778
|
+
requiredContext: ["root", "stack"],
|
|
13779
|
+
binding: destroy
|
|
13780
|
+
},
|
|
13781
|
+
{
|
|
13782
|
+
id: "scan",
|
|
13783
|
+
label: "Scan for drift",
|
|
13784
|
+
placement: "toolbar",
|
|
13785
|
+
requiredPorts: ["commands"],
|
|
13786
|
+
requiredContext: ["stack"],
|
|
13787
|
+
binding: scan
|
|
13788
|
+
},
|
|
13789
|
+
{
|
|
13790
|
+
id: "create",
|
|
13791
|
+
label: "Create stack",
|
|
13792
|
+
placement: "toolbar",
|
|
13793
|
+
requiredPorts: ["commands"],
|
|
13794
|
+
requiredContext: ["root"],
|
|
13795
|
+
binding: create
|
|
13796
|
+
},
|
|
13797
|
+
{
|
|
13798
|
+
id: "import",
|
|
13799
|
+
label: "Import existing resources",
|
|
13800
|
+
placement: "toolbar",
|
|
13801
|
+
requiredPorts: ["commands"],
|
|
13802
|
+
// `stack import` writes the directory it runs in, the same way
|
|
13803
|
+
// Convert does.
|
|
13804
|
+
requiredContext: ["root", "stack"],
|
|
13805
|
+
binding: importStack
|
|
13806
|
+
},
|
|
13807
|
+
{
|
|
13808
|
+
id: "import-partial",
|
|
13809
|
+
label: "Import the rest",
|
|
13810
|
+
placement: { row: "failure" },
|
|
13811
|
+
requiredPorts: ["commands"],
|
|
13812
|
+
requiredContext: ["root", "stack"],
|
|
13813
|
+
answers: ["import_residual"],
|
|
13814
|
+
binding: importPartial
|
|
13815
|
+
},
|
|
13816
|
+
{
|
|
13817
|
+
id: "preview",
|
|
13818
|
+
label: "Preview",
|
|
13819
|
+
placement: "toolbar",
|
|
13820
|
+
requiredPorts: ["commands"],
|
|
13821
|
+
// `stack preview` plans the tf of the directory it runs in — a stack
|
|
13822
|
+
// alone isn't enough, the mount needs the root too.
|
|
13823
|
+
requiredContext: ["root", "stack"],
|
|
13824
|
+
binding: preview
|
|
13825
|
+
},
|
|
13826
|
+
{
|
|
13827
|
+
id: "run-cancel",
|
|
13828
|
+
label: "Cancel",
|
|
13829
|
+
placement: { row: "runs" },
|
|
13830
|
+
requiredPorts: ["commands"],
|
|
13831
|
+
requiredTarget: ["runId"],
|
|
13832
|
+
binding: runCancel
|
|
13833
|
+
},
|
|
13834
|
+
{
|
|
13835
|
+
id: "follow-logs",
|
|
13836
|
+
label: "Follow logs",
|
|
13837
|
+
placement: { row: "runs" },
|
|
13838
|
+
requiredPorts: ["commands"],
|
|
13839
|
+
requiredTarget: ["runId"],
|
|
13840
|
+
binding: followLogs
|
|
13598
13841
|
}
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
|
|
13603
|
-
|
|
13604
|
-
phases
|
|
13605
|
-
};
|
|
13606
|
-
}
|
|
13607
|
-
function reducePreview(_prev, token, event) {
|
|
13608
|
-
return { token, data: event };
|
|
13609
|
-
}
|
|
13610
|
-
function reduceReport(prev, session, result) {
|
|
13611
|
-
const fold = foldReport(prev?.sessions.get(session) ?? EMPTY_REPORT_FOLD, result);
|
|
13612
|
-
return { sessions: new Map(prev?.sessions).set(session, fold) };
|
|
13613
|
-
}
|
|
13614
|
-
function reduceFollow(prev, token, event) {
|
|
13615
|
-
const carried = prev && prev.token === token ? prev : null;
|
|
13616
|
-
const runId = carried?.runId ?? "";
|
|
13617
|
-
const lines = carried?.lines ?? [];
|
|
13618
|
-
if (event.type === "log") return { token, runId, lines: [...lines, event.text], done: false };
|
|
13619
|
-
return { token, runId, lines, done: true };
|
|
13620
|
-
}
|
|
13621
|
-
function createResultStore() {
|
|
13622
|
-
let slots = {
|
|
13623
|
-
run: null,
|
|
13624
|
-
preview: null,
|
|
13625
|
-
report: null,
|
|
13626
|
-
follow: null
|
|
13627
|
-
};
|
|
13628
|
-
let tick = 0;
|
|
13629
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
13630
|
-
const notify = () => {
|
|
13631
|
-
for (const listener of listeners) listener();
|
|
13632
|
-
};
|
|
13633
|
-
const retiredTokens = /* @__PURE__ */ new WeakSet();
|
|
13634
|
-
return {
|
|
13635
|
-
getSnapshot() {
|
|
13636
|
-
return slots;
|
|
13637
|
-
},
|
|
13638
|
-
getTick() {
|
|
13639
|
-
return tick;
|
|
13640
|
-
},
|
|
13641
|
-
subscribe(listener) {
|
|
13642
|
-
listeners.add(listener);
|
|
13643
|
-
return () => listeners.delete(listener);
|
|
13644
|
-
},
|
|
13645
|
-
write(kind, token, value, readOver) {
|
|
13646
|
-
if (retiredTokens.has(token)) return;
|
|
13647
|
-
slots = { ...slots, [kind]: applySlot(kind, slots[kind], token, value, readOver) };
|
|
13648
|
-
notify();
|
|
13649
|
-
},
|
|
13650
|
-
fail(kind, token, error) {
|
|
13651
|
-
if (kind !== "run") return false;
|
|
13652
|
-
if (retiredTokens.has(token) || !slots.run) return true;
|
|
13653
|
-
slots = { ...slots, run: stamp(settleRun(slots.run, token, error), slots.run.readOver) };
|
|
13654
|
-
notify();
|
|
13655
|
-
return true;
|
|
13656
|
-
},
|
|
13657
|
-
begin(kind, token, readOver, target) {
|
|
13658
|
-
if (kind === "run") {
|
|
13659
|
-
slots = {
|
|
13660
|
-
...slots,
|
|
13661
|
-
run: {
|
|
13662
|
-
token,
|
|
13663
|
-
outcome: { kind: "running" },
|
|
13664
|
-
lastLog: null,
|
|
13665
|
-
submitted: false,
|
|
13666
|
-
phases: [],
|
|
13667
|
-
readOver
|
|
13668
|
-
}
|
|
13669
|
-
};
|
|
13670
|
-
} else if (kind === "follow") {
|
|
13671
|
-
slots = {
|
|
13672
|
-
...slots,
|
|
13673
|
-
follow: { token, runId: target.runId ?? "", lines: [], done: false, readOver }
|
|
13674
|
-
};
|
|
13675
|
-
} else {
|
|
13676
|
-
return;
|
|
13677
|
-
}
|
|
13678
|
-
notify();
|
|
13679
|
-
},
|
|
13680
|
-
detach(kind, token) {
|
|
13681
|
-
if (kind === "follow" && slots.follow?.token === token) {
|
|
13682
|
-
slots = { ...slots, follow: null };
|
|
13683
|
-
notify();
|
|
13684
|
-
} else if (kind === "report" && slots.report?.sessions.has(token)) {
|
|
13685
|
-
const sessions = new Map(slots.report.sessions);
|
|
13686
|
-
sessions.delete(token);
|
|
13687
|
-
slots = {
|
|
13688
|
-
...slots,
|
|
13689
|
-
report: sessions.size > 0 ? { sessions, readOver: slots.report.readOver } : null
|
|
13690
|
-
};
|
|
13691
|
-
notify();
|
|
13692
|
-
} else if (kind === "run" && slots.run?.token === token) {
|
|
13693
|
-
const settled = settleRun(slots.run, token, new CommandDetachedError());
|
|
13694
|
-
slots = { ...slots, run: stamp(settled, slots.run.readOver) };
|
|
13695
|
-
notify();
|
|
13696
|
-
}
|
|
13697
|
-
retiredTokens.add(token);
|
|
13698
|
-
},
|
|
13699
|
-
isBusy(kind) {
|
|
13700
|
-
return kind === "run" && slots.run?.outcome.kind === "running";
|
|
13701
|
-
},
|
|
13702
|
-
bumpTick() {
|
|
13703
|
-
tick += 1;
|
|
13704
|
-
notify();
|
|
13705
|
-
}
|
|
13706
|
-
};
|
|
13707
|
-
}
|
|
13842
|
+
];
|
|
13843
|
+
var CORE_COMMAND_ACTIONS = [
|
|
13844
|
+
...STACK_COMMAND_ACTIONS,
|
|
13845
|
+
...MODULE_COMMAND_ACTIONS
|
|
13846
|
+
];
|
|
13708
13847
|
|
|
13709
13848
|
// src/registry.ts
|
|
13710
13849
|
var CONTEXT_NEEDS = {
|
|
@@ -13735,7 +13874,16 @@ var TARGET_NEEDS = {
|
|
|
13735
13874
|
runId: "a run",
|
|
13736
13875
|
failure: "a failed command"
|
|
13737
13876
|
};
|
|
13738
|
-
|
|
13877
|
+
function busyReason(busy) {
|
|
13878
|
+
return busy.kind === "run" ? "A run is in progress" : `${busy.running.label} is running`;
|
|
13879
|
+
}
|
|
13880
|
+
function runsOn(action, ctx, target) {
|
|
13881
|
+
if (action.requiredTarget?.includes("runId")) return `run:${target.runId}`;
|
|
13882
|
+
const required = action.requiredContext ?? [];
|
|
13883
|
+
if (required.includes("stack")) return `stack:${ctx.stack?.id}`;
|
|
13884
|
+
if (required.includes("root")) return `root:${ctx.root}`;
|
|
13885
|
+
return "";
|
|
13886
|
+
}
|
|
13739
13887
|
function keySatisfied(ctx, key) {
|
|
13740
13888
|
if (key === "editable") return ctx.editable === true;
|
|
13741
13889
|
if (key === "saved") return ctx.view?.unsaved === false;
|
|
@@ -13760,13 +13908,24 @@ function keySatisfied(ctx, key) {
|
|
|
13760
13908
|
function contextSatisfied(ctx, required) {
|
|
13761
13909
|
return required.every((key) => keySatisfied(ctx, key));
|
|
13762
13910
|
}
|
|
13763
|
-
function disabledReason(action, ctx,
|
|
13764
|
-
if (
|
|
13911
|
+
function disabledReason(action, ctx, busy) {
|
|
13912
|
+
if (busy) return busyReason(busy);
|
|
13765
13913
|
for (const { key, reason } of action.enabledWhen ?? []) {
|
|
13766
13914
|
if (!keySatisfied(ctx, key)) return reason;
|
|
13767
13915
|
}
|
|
13768
13916
|
return void 0;
|
|
13769
13917
|
}
|
|
13918
|
+
function busyLabelOf(action, ctx, busy) {
|
|
13919
|
+
if (action.busy && keySatisfied(ctx, action.busy.when)) return action.busy.label;
|
|
13920
|
+
if (busy === void 0 || action.binding.kind !== "command") return void 0;
|
|
13921
|
+
return busy.kind === "run" || busy.running.path === action.binding.path ? action.label : void 0;
|
|
13922
|
+
}
|
|
13923
|
+
function actionState(action, ctx, busy) {
|
|
13924
|
+
return {
|
|
13925
|
+
disabledReason: disabledReason(action, ctx, busy),
|
|
13926
|
+
busyLabel: busyLabelOf(action, ctx, busy)
|
|
13927
|
+
};
|
|
13928
|
+
}
|
|
13770
13929
|
function missingPort(ports, required) {
|
|
13771
13930
|
return required.find((name) => ports[name] === void 0);
|
|
13772
13931
|
}
|
|
@@ -13797,6 +13956,16 @@ function asksConfirm(binding) {
|
|
|
13797
13956
|
return binding.confirm !== void 0;
|
|
13798
13957
|
}
|
|
13799
13958
|
}
|
|
13959
|
+
var FAILURE_ROW = "failure";
|
|
13960
|
+
function placedOn(action, row) {
|
|
13961
|
+
return typeof action.placement === "object" && action.placement.row === row;
|
|
13962
|
+
}
|
|
13963
|
+
function answersFailure(action, failure) {
|
|
13964
|
+
return action.answers?.includes(failure.reason) === true;
|
|
13965
|
+
}
|
|
13966
|
+
function answering(actions, failure) {
|
|
13967
|
+
return actions.filter((a) => placedOn(a, FAILURE_ROW) && answersFailure(a, failure));
|
|
13968
|
+
}
|
|
13800
13969
|
function unmetRequirement(action, ports, ctx, target) {
|
|
13801
13970
|
const { label, binding } = action;
|
|
13802
13971
|
const port = missingPort(ports, action.requiredPorts);
|
|
@@ -13808,11 +13977,9 @@ function unmetRequirement(action, ports, ctx, target) {
|
|
|
13808
13977
|
if (key !== void 0) return `${label} needs ${CONTEXT_NEEDS[key]}`;
|
|
13809
13978
|
const targetKey = (action.requiredTarget ?? []).find((k) => target[k] === void 0);
|
|
13810
13979
|
if (targetKey !== void 0) return `${label} needs ${TARGET_NEEDS[targetKey]}`;
|
|
13811
|
-
if (action.answers !== void 0) {
|
|
13980
|
+
if (placedOn(action, FAILURE_ROW) || action.answers !== void 0) {
|
|
13812
13981
|
if (target.failure === void 0) return `${label} needs ${TARGET_NEEDS.failure}`;
|
|
13813
|
-
if (!action
|
|
13814
|
-
return `${label} does not answer this failure`;
|
|
13815
|
-
}
|
|
13982
|
+
if (!answersFailure(action, target.failure)) return `${label} does not answer this failure`;
|
|
13816
13983
|
}
|
|
13817
13984
|
if (binding.kind === "command" && !availableCommands(ports).has(binding.path)) {
|
|
13818
13985
|
return `${label} runs lace ${binding.path}, which this host does not route`;
|
|
@@ -13831,9 +13998,7 @@ function resolveContributions(all, ports, ctx, target = NO_TARGET) {
|
|
|
13831
13998
|
};
|
|
13832
13999
|
}
|
|
13833
14000
|
function rowActions(resolved, panelId) {
|
|
13834
|
-
return resolved.actions.filter(
|
|
13835
|
-
(a) => typeof a.placement === "object" && a.placement.row === panelId
|
|
13836
|
-
);
|
|
14001
|
+
return resolved.actions.filter((a) => placedOn(a, panelId));
|
|
13837
14002
|
}
|
|
13838
14003
|
|
|
13839
14004
|
// src/core/run-binding.ts
|
|
@@ -13859,7 +14024,19 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13859
14024
|
const handles = /* @__PURE__ */ new Map();
|
|
13860
14025
|
const tokens = /* @__PURE__ */ new Map();
|
|
13861
14026
|
const clipboard = createClipboardStore();
|
|
13862
|
-
const notifyControllers = /* @__PURE__ */ new
|
|
14027
|
+
const notifyControllers = /* @__PURE__ */ new Map();
|
|
14028
|
+
let edits = 0;
|
|
14029
|
+
const editingListeners = /* @__PURE__ */ new Set();
|
|
14030
|
+
async function asEdit(edit) {
|
|
14031
|
+
edits += 1;
|
|
14032
|
+
if (edits === 1) for (const listener of editingListeners) listener(true);
|
|
14033
|
+
try {
|
|
14034
|
+
return await edit();
|
|
14035
|
+
} finally {
|
|
14036
|
+
edits -= 1;
|
|
14037
|
+
if (edits === 0) for (const listener of editingListeners) listener(false);
|
|
14038
|
+
}
|
|
14039
|
+
}
|
|
13863
14040
|
async function applyWith(editor, actions) {
|
|
13864
14041
|
let result;
|
|
13865
14042
|
try {
|
|
@@ -13899,13 +14076,14 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13899
14076
|
async function applyActions(actions) {
|
|
13900
14077
|
const editor = ports.editor;
|
|
13901
14078
|
if (!editor) return;
|
|
13902
|
-
return applyWith(editor, actions);
|
|
14079
|
+
return asEdit(() => applyWith(editor, actions));
|
|
13903
14080
|
}
|
|
13904
14081
|
function askConfirm(spec) {
|
|
13905
14082
|
const confirm = ports.presenter.confirm;
|
|
13906
14083
|
return confirm ? confirm(spec) : Promise.resolve(false);
|
|
13907
14084
|
}
|
|
13908
|
-
function runtimeFor(token, readOver, cwd,
|
|
14085
|
+
function runtimeFor(token, readOver, cwd, command, onSettle) {
|
|
14086
|
+
const run = command?.run;
|
|
13909
14087
|
return {
|
|
13910
14088
|
ports,
|
|
13911
14089
|
token,
|
|
@@ -13916,7 +14094,7 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13916
14094
|
if (run && line !== void 0) options.onRunLog?.(line, run);
|
|
13917
14095
|
},
|
|
13918
14096
|
begin: () => {
|
|
13919
|
-
if (
|
|
14097
|
+
if (command) store.begin(command.run.resultKind, token, readOver, command.started);
|
|
13920
14098
|
},
|
|
13921
14099
|
fail: (error) => run ? store.fail(run.resultKind, token, error) : false,
|
|
13922
14100
|
detach: (kind, tok) => store.detach(kind, tok),
|
|
@@ -13927,6 +14105,15 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13927
14105
|
function readOverOf(ctx) {
|
|
13928
14106
|
return { stack: ctx.stack?.id };
|
|
13929
14107
|
}
|
|
14108
|
+
function busyOn(resultKind, action, ctx, target) {
|
|
14109
|
+
const on = runsOn(action, ctx, target);
|
|
14110
|
+
return { on, busy: store.busy(resultKind, on) };
|
|
14111
|
+
}
|
|
14112
|
+
function busyOf(action, ctx, target) {
|
|
14113
|
+
const binding = action.binding;
|
|
14114
|
+
if (binding.kind !== "command") return void 0;
|
|
14115
|
+
return busyOn(binding.resultKind, action, ctx, target).busy;
|
|
14116
|
+
}
|
|
13930
14117
|
function cwdOf(action, ctx) {
|
|
13931
14118
|
return (action.requiredContext ?? []).includes("root") ? ctx.root : void 0;
|
|
13932
14119
|
}
|
|
@@ -13939,24 +14126,33 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13939
14126
|
handles.delete(kind);
|
|
13940
14127
|
tokens.delete(kind);
|
|
13941
14128
|
}
|
|
14129
|
+
function tellFailure(error) {
|
|
14130
|
+
if (error instanceof CommandDetachedError) return;
|
|
14131
|
+
ports.presenter.notify("error", error instanceof Error ? error.message : String(error));
|
|
14132
|
+
}
|
|
13942
14133
|
async function startCommand(action, ctx, target, formArgs) {
|
|
13943
14134
|
const binding = action.binding;
|
|
13944
14135
|
if (binding.kind !== "command") return;
|
|
13945
14136
|
const spec = binding.confirmSpec(ctx, target, formArgs);
|
|
13946
14137
|
if (spec && !await askConfirm(spec)) return;
|
|
13947
|
-
|
|
13948
|
-
|
|
14138
|
+
const { on, busy } = busyOn(binding.resultKind, action, ctx, target);
|
|
14139
|
+
if (busy) {
|
|
14140
|
+
ports.presenter.notify("warn", busyReason(busy));
|
|
13949
14141
|
return;
|
|
13950
14142
|
}
|
|
13951
14143
|
const readOver = readOverOf(ctx);
|
|
13952
14144
|
const cwd = cwdOf(action, ctx);
|
|
13953
14145
|
const token = {};
|
|
13954
14146
|
const run = { token, path: binding.path, resultKind: binding.resultKind, ctx, target };
|
|
14147
|
+
const started = { target, on, path: binding.path, label: action.label };
|
|
13955
14148
|
const controller = new AbortController();
|
|
13956
14149
|
if (binding.resultKind === "notify") {
|
|
13957
|
-
notifyControllers.
|
|
14150
|
+
notifyControllers.set(controller, token);
|
|
13958
14151
|
await binding.start(
|
|
13959
|
-
runtimeFor(token, readOver, cwd, run, () =>
|
|
14152
|
+
runtimeFor(token, readOver, cwd, { run, started }, () => {
|
|
14153
|
+
notifyControllers.delete(controller);
|
|
14154
|
+
store.detach("notify", token);
|
|
14155
|
+
}),
|
|
13960
14156
|
ctx,
|
|
13961
14157
|
target,
|
|
13962
14158
|
formArgs,
|
|
@@ -13968,7 +14164,7 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13968
14164
|
controllers.set(binding.resultKind, controller);
|
|
13969
14165
|
tokens.set(binding.resultKind, token);
|
|
13970
14166
|
const handle = await binding.start(
|
|
13971
|
-
runtimeFor(token, readOver, cwd, run),
|
|
14167
|
+
runtimeFor(token, readOver, cwd, { run, started }),
|
|
13972
14168
|
ctx,
|
|
13973
14169
|
target,
|
|
13974
14170
|
formArgs,
|
|
@@ -13993,7 +14189,7 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13993
14189
|
missing: completion.missing,
|
|
13994
14190
|
submit: (values) => {
|
|
13995
14191
|
options.onPendingFormChange?.(null);
|
|
13996
|
-
void startCommand(action, ctx, target, values);
|
|
14192
|
+
void startCommand(action, ctx, target, values).catch(tellFailure);
|
|
13997
14193
|
},
|
|
13998
14194
|
cancel: () => options.onPendingFormChange?.(null)
|
|
13999
14195
|
});
|
|
@@ -14017,7 +14213,7 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
14017
14213
|
...envExtras
|
|
14018
14214
|
};
|
|
14019
14215
|
if (binding.result === "apply") {
|
|
14020
|
-
return binding.run(env);
|
|
14216
|
+
return asEdit(() => binding.run(env));
|
|
14021
14217
|
}
|
|
14022
14218
|
if (binding.result === "generate") {
|
|
14023
14219
|
for await (const event of binding.run(env)) {
|
|
@@ -14045,8 +14241,7 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
14045
14241
|
ports.presenter.notify("warn", unmet);
|
|
14046
14242
|
return;
|
|
14047
14243
|
}
|
|
14048
|
-
const
|
|
14049
|
-
const reason = disabledReason(action, ctx, isBusy);
|
|
14244
|
+
const reason = disabledReason(action, ctx, busyOf(action, ctx, target));
|
|
14050
14245
|
if (reason !== void 0) {
|
|
14051
14246
|
ports.presenter.notify("warn", reason);
|
|
14052
14247
|
return;
|
|
@@ -14067,13 +14262,24 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
14067
14262
|
return;
|
|
14068
14263
|
}
|
|
14069
14264
|
} catch (error) {
|
|
14070
|
-
|
|
14071
|
-
ports.presenter.notify("error", error instanceof Error ? error.message : String(error));
|
|
14265
|
+
tellFailure(error);
|
|
14072
14266
|
}
|
|
14073
14267
|
},
|
|
14074
14268
|
apply(actions) {
|
|
14075
14269
|
return applyActions(actions);
|
|
14076
14270
|
},
|
|
14271
|
+
editing() {
|
|
14272
|
+
return edits > 0;
|
|
14273
|
+
},
|
|
14274
|
+
onEditingChange(listener) {
|
|
14275
|
+
editingListeners.add(listener);
|
|
14276
|
+
return () => {
|
|
14277
|
+
editingListeners.delete(listener);
|
|
14278
|
+
};
|
|
14279
|
+
},
|
|
14280
|
+
busy(action, ctx, target) {
|
|
14281
|
+
return busyOf(action, ctx, target);
|
|
14282
|
+
},
|
|
14077
14283
|
async cancel(kind) {
|
|
14078
14284
|
const handle = handles.get(kind);
|
|
14079
14285
|
if (!handle) return;
|
|
@@ -14085,7 +14291,10 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
14085
14291
|
},
|
|
14086
14292
|
dispose() {
|
|
14087
14293
|
for (const kind of [...controllers.keys()]) detachSlot(kind);
|
|
14088
|
-
for (const controller of notifyControllers)
|
|
14294
|
+
for (const [controller, token] of notifyControllers) {
|
|
14295
|
+
controller.abort();
|
|
14296
|
+
store.detach("notify", token);
|
|
14297
|
+
}
|
|
14089
14298
|
notifyControllers.clear();
|
|
14090
14299
|
}
|
|
14091
14300
|
};
|
|
@@ -14183,6 +14392,8 @@ export {
|
|
|
14183
14392
|
diagnosticsOf,
|
|
14184
14393
|
keySatisfied,
|
|
14185
14394
|
disabledReason,
|
|
14395
|
+
actionState,
|
|
14396
|
+
answering,
|
|
14186
14397
|
resolveContributions,
|
|
14187
14398
|
rowActions,
|
|
14188
14399
|
Bundle,
|
|
@@ -14202,10 +14413,6 @@ export {
|
|
|
14202
14413
|
parseBound,
|
|
14203
14414
|
carriesFailure,
|
|
14204
14415
|
parseCommandFailure,
|
|
14205
|
-
defineCommand,
|
|
14206
|
-
MODULE_COMMAND_ACTIONS,
|
|
14207
|
-
CORE_COMMAND_ACTIONS,
|
|
14208
|
-
isPlainObject,
|
|
14209
14416
|
EMPTY_REPORT_FOLD,
|
|
14210
14417
|
foldReport,
|
|
14211
14418
|
currentReport,
|
|
@@ -14213,11 +14420,16 @@ export {
|
|
|
14213
14420
|
reportDiagnostics,
|
|
14214
14421
|
liveSlots,
|
|
14215
14422
|
reduceRun,
|
|
14423
|
+
failureSays,
|
|
14216
14424
|
settleRun,
|
|
14217
14425
|
reducePreview,
|
|
14218
14426
|
reduceReport,
|
|
14219
14427
|
reduceFollow,
|
|
14220
14428
|
createResultStore,
|
|
14429
|
+
defineCommand,
|
|
14430
|
+
MODULE_COMMAND_ACTIONS,
|
|
14431
|
+
CORE_COMMAND_ACTIONS,
|
|
14432
|
+
isPlainObject,
|
|
14221
14433
|
createActionRunner,
|
|
14222
14434
|
connectCaller,
|
|
14223
14435
|
bridgeCaller,
|
|
@@ -14226,4 +14438,4 @@ export {
|
|
|
14226
14438
|
AutosaveEndedError,
|
|
14227
14439
|
autosave
|
|
14228
14440
|
};
|
|
14229
|
-
//# sourceMappingURL=chunk-
|
|
14441
|
+
//# sourceMappingURL=chunk-ID563WHD.mjs.map
|