@lace-cloud/canvas 0.25.0 → 0.27.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 +7 -5
- package/dist/{chunk-YLJWYH7B.mjs → chunk-F3X6TTZ6.mjs} +790 -577
- package/dist/chunk-F3X6TTZ6.mjs.map +1 -0
- package/dist/engine/index.cjs +736 -534
- 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 +3 -1
- package/dist/index.cjs +3747 -3448
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +331 -242
- package/dist/index.mjs.map +1 -1
- package/dist/{registry-CdHLt_qh.d.mts → registry-D7G7pqU4.d.mts} +71 -8
- package/dist/{registry-CdHLt_qh.d.ts → registry-D7G7pqU4.d.ts} +71 -8
- package/package.json +3 -3
- package/dist/chunk-YLJWYH7B.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,6 +12643,7 @@ 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
|
|
@@ -12958,7 +13036,7 @@ function commandsPort(caller, commandPaths, ownCwd) {
|
|
|
12958
13036
|
working_directory: cwd
|
|
12959
13037
|
};
|
|
12960
13038
|
async function* run() {
|
|
12961
|
-
for await (const event of
|
|
13039
|
+
for await (const event of untilExit()) {
|
|
12962
13040
|
if (event.json !== void 0) {
|
|
12963
13041
|
const data = JSON.parse(event.json);
|
|
12964
13042
|
if (carriesFailure(data)) continue;
|
|
@@ -12976,8 +13054,28 @@ function commandsPort(caller, commandPaths, ownCwd) {
|
|
|
12976
13054
|
return;
|
|
12977
13055
|
}
|
|
12978
13056
|
}
|
|
12979
|
-
|
|
12980
|
-
|
|
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
|
+
);
|
|
12981
13079
|
}
|
|
12982
13080
|
return {
|
|
12983
13081
|
events: run(),
|
|
@@ -13051,407 +13149,71 @@ function convertCreatedRef(r) {
|
|
|
13051
13149
|
return { scope: r.scope, id: r.id, moduleKey: r.module_key, sourceId: r.source_id };
|
|
13052
13150
|
}
|
|
13053
13151
|
|
|
13054
|
-
// src/core/
|
|
13055
|
-
|
|
13056
|
-
|
|
13057
|
-
|
|
13058
|
-
}
|
|
13059
|
-
if (err instanceof Error) return [err.message];
|
|
13060
|
-
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);
|
|
13061
13156
|
}
|
|
13062
|
-
function
|
|
13063
|
-
return
|
|
13064
|
-
|
|
13065
|
-
|
|
13066
|
-
|
|
13067
|
-
|
|
13068
|
-
|
|
13069
|
-
|
|
13070
|
-
|
|
13071
|
-
|
|
13072
|
-
confirmSpec(ctx, target, formArgs) {
|
|
13073
|
-
if (!binding.confirm) return void 0;
|
|
13074
|
-
const merged = completeArgs(binding.path, { ...binding.args(ctx, target), ...formArgs });
|
|
13075
|
-
if (!merged.ok) return void 0;
|
|
13076
|
-
return binding.confirm(ctx, merged.args, target);
|
|
13077
|
-
},
|
|
13078
|
-
async start(rt, ctx, target, formArgs, signal) {
|
|
13079
|
-
const merged = completeArgs(binding.path, { ...binding.args(ctx, target), ...formArgs });
|
|
13080
|
-
if (!merged.ok) return null;
|
|
13081
|
-
const commands = rt.ports.commands;
|
|
13082
|
-
if (!commands) return null;
|
|
13083
|
-
const invocation = commands.invoke(binding.path, merged.args, signal, rt.cwd);
|
|
13084
|
-
rt.begin();
|
|
13085
|
-
if (binding.invalidates === "start+settle") rt.tick();
|
|
13086
|
-
void (async () => {
|
|
13087
|
-
try {
|
|
13088
|
-
for await (const event of invocation.events) {
|
|
13089
|
-
binding.result.consume(rt, event);
|
|
13090
|
-
}
|
|
13091
|
-
if (binding.invalidates) rt.tick();
|
|
13092
|
-
} catch (err) {
|
|
13093
|
-
if (!rt.fail(err) && !(err instanceof CommandDetachedError)) {
|
|
13094
|
-
rt.ports.presenter.notify("error", ...errorNotice(err));
|
|
13095
|
-
}
|
|
13096
|
-
if (binding.invalidates) rt.tick();
|
|
13097
|
-
} finally {
|
|
13098
|
-
rt.settled?.();
|
|
13099
|
-
}
|
|
13100
|
-
})();
|
|
13101
|
-
return { cancel: () => invocation.cancel() };
|
|
13102
|
-
}
|
|
13103
|
-
};
|
|
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
|
+
]);
|
|
13104
13167
|
}
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
|
|
13108
|
-
|
|
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
|
+
});
|
|
13109
13176
|
}
|
|
13110
|
-
|
|
13111
|
-
|
|
13112
|
-
path: "stack apply",
|
|
13113
|
-
args: (ctx) => ({ stack: ctx.stack?.id }),
|
|
13114
|
-
// The run sink ticks at both start and settle, so a read keyed on the
|
|
13115
|
-
// tick (a host's run list, the describe overlay) sees the in-flight run
|
|
13116
|
-
// as soon as it starts, not only once it ends.
|
|
13117
|
-
invalidates: "start+settle",
|
|
13118
|
-
result: slotSink("run")
|
|
13119
|
-
});
|
|
13120
|
-
var destroy = defineCommand({
|
|
13121
|
-
kind: "command",
|
|
13122
|
-
path: "stack destroy",
|
|
13123
|
-
args: (ctx) => ({ stack: ctx.stack?.id, yes: true }),
|
|
13124
|
-
// The typed confirmation is the stack's slug — the human-facing name a
|
|
13125
|
-
// user actually reads off the host's stack list — never its id, which
|
|
13126
|
-
// `args.stack` carries for the command itself but nobody types from
|
|
13127
|
-
// memory.
|
|
13128
|
-
confirm: (ctx) => ({
|
|
13129
|
-
text: `Destroy ${ctx.stack?.slug}? This runs terraform destroy on the runner.`,
|
|
13130
|
-
typed: ctx.stack?.slug
|
|
13131
|
-
}),
|
|
13132
|
-
invalidates: "start+settle",
|
|
13133
|
-
result: slotSink("run")
|
|
13134
|
-
});
|
|
13135
|
-
function scanNotice(e) {
|
|
13136
|
-
const { slug } = e.stack;
|
|
13137
|
-
const settled = e.settled;
|
|
13138
|
-
if (!settled) {
|
|
13139
|
-
return e.triggered ? `Drift scan triggered for stack ${slug} (${e.stack.id}).` : `Drift scan already in progress for stack ${slug}.`;
|
|
13140
|
-
}
|
|
13141
|
-
if (settled.undeterminedReason !== null) return void 0;
|
|
13142
|
-
if (settled.footprintDestroyed) {
|
|
13143
|
-
return `Drift scan complete for stack ${slug}: IN_SYNC (0 drifted) \u2014 its resources were destroyed, so there was nothing to compare.`;
|
|
13144
|
-
}
|
|
13145
|
-
if (settled.standingDriftFindings > 0) {
|
|
13146
|
-
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.`;
|
|
13147
|
-
}
|
|
13148
|
-
return `Drift scan complete for stack ${slug}: ${settled.driftStatus} (${settled.driftCount} drifted).`;
|
|
13177
|
+
function diagnosticsOf(sourceDiagnostics, reportFindings) {
|
|
13178
|
+
return uniqueDiagnostics([...sourceDiagnostics, ...reportFindings]);
|
|
13149
13179
|
}
|
|
13150
|
-
|
|
13151
|
-
|
|
13152
|
-
|
|
13153
|
-
|
|
13154
|
-
|
|
13155
|
-
|
|
13156
|
-
|
|
13157
|
-
|
|
13158
|
-
|
|
13159
|
-
|
|
13160
|
-
}
|
|
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) };
|
|
13161
13191
|
}
|
|
13162
|
-
|
|
13163
|
-
|
|
13164
|
-
|
|
13165
|
-
|
|
13166
|
-
|
|
13167
|
-
|
|
13168
|
-
|
|
13169
|
-
kind: "notify",
|
|
13170
|
-
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) };
|
|
13171
13199
|
}
|
|
13172
|
-
});
|
|
13173
|
-
function residualAddresses(residuals) {
|
|
13174
|
-
return residuals.map((r) => r.address).join(", ");
|
|
13175
13200
|
}
|
|
13176
|
-
function
|
|
13177
|
-
|
|
13178
|
-
|
|
13179
|
-
|
|
13180
|
-
|
|
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;
|
|
13181
13208
|
}
|
|
13182
|
-
function
|
|
13183
|
-
|
|
13184
|
-
|
|
13185
|
-
|
|
13186
|
-
|
|
13187
|
-
|
|
13188
|
-
|
|
13189
|
-
|
|
13190
|
-
const adopt = e.changed ? ` Review the change in git, commit it, then apply ${slug} to adopt them.` : "";
|
|
13191
|
-
if (e.importResiduals.length === 0) return ["info", `${imported}${adopt}`];
|
|
13192
|
-
return [
|
|
13193
|
-
"warn",
|
|
13194
|
-
`${imported}${adopt} Not adopted: ${residualAddresses(e.importResiduals)}; supply their import ids before applying, or the apply creates them anew.`
|
|
13195
|
-
];
|
|
13196
|
-
}
|
|
13197
|
-
var importResult = {
|
|
13198
|
-
kind: "notify",
|
|
13199
|
-
consume: (rt, e) => rt.ports.presenter.notify(...importNotice(e))
|
|
13200
|
-
};
|
|
13201
|
-
var importStack = defineCommand({
|
|
13202
|
-
kind: "command",
|
|
13203
|
-
path: "stack import",
|
|
13204
|
-
args: (ctx) => ({ stack: ctx.stack?.id }),
|
|
13205
|
-
invalidates: true,
|
|
13206
|
-
result: importResult
|
|
13207
|
-
});
|
|
13208
|
-
var importPartial = defineCommand({
|
|
13209
|
-
kind: "command",
|
|
13210
|
-
path: "stack import",
|
|
13211
|
-
args: (ctx) => ({ stack: ctx.stack?.id, allowPartial: true }),
|
|
13212
|
-
confirm: (ctx, _args, target) => ({
|
|
13213
|
-
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.`
|
|
13214
|
-
}),
|
|
13215
|
-
invalidates: true,
|
|
13216
|
-
result: importResult
|
|
13217
|
-
});
|
|
13218
|
-
var validate = defineCommand({
|
|
13219
|
-
kind: "command",
|
|
13220
|
-
path: "module validate",
|
|
13221
|
-
args: () => ({}),
|
|
13222
|
-
result: {
|
|
13223
|
-
kind: "notify",
|
|
13224
|
-
consume: (rt, e) => {
|
|
13225
|
-
if (e.exitClass === "ok") rt.ports.presenter.notify("info", `Valid for Lace \u2014 ${e.verdict}`);
|
|
13226
|
-
}
|
|
13227
|
-
}
|
|
13228
|
-
});
|
|
13229
|
-
var convert = defineCommand({
|
|
13230
|
-
kind: "command",
|
|
13231
|
-
path: "module convert",
|
|
13232
|
-
args: () => ({}),
|
|
13233
|
-
result: {
|
|
13234
|
-
kind: "notify",
|
|
13235
|
-
consume: (rt, e) => rt.ports.presenter.notify(
|
|
13236
|
-
"info",
|
|
13237
|
-
e.changed ? `Converted \u2014 ${e.written.length} file(s) written` : "Already lace-style \u2014 nothing to write"
|
|
13238
|
-
)
|
|
13239
|
-
}
|
|
13240
|
-
});
|
|
13241
|
-
var preview = defineCommand({
|
|
13242
|
-
kind: "command",
|
|
13243
|
-
path: "stack preview",
|
|
13244
|
-
args: (ctx) => ({ stack: ctx.stack?.id }),
|
|
13245
|
-
result: slotSink("preview")
|
|
13246
|
-
});
|
|
13247
|
-
var runCancel = defineCommand({
|
|
13248
|
-
kind: "command",
|
|
13249
|
-
path: "run cancel",
|
|
13250
|
-
args: (_ctx, target) => ({ run: target.runId }),
|
|
13251
|
-
invalidates: true,
|
|
13252
|
-
result: {
|
|
13253
|
-
kind: "notify",
|
|
13254
|
-
consume: (rt, e) => rt.ports.presenter.notify("info", `Run ${e.id} ${e.status}`)
|
|
13255
|
-
}
|
|
13256
|
-
});
|
|
13257
|
-
var followLogs = defineCommand({
|
|
13258
|
-
kind: "command",
|
|
13259
|
-
path: "run logs",
|
|
13260
|
-
args: (_ctx, target) => ({ run: target.runId, follow: true }),
|
|
13261
|
-
result: slotSink("follow")
|
|
13262
|
-
});
|
|
13263
|
-
var MODULE_COMMAND_ACTIONS = [
|
|
13264
|
-
{
|
|
13265
|
-
id: "validate",
|
|
13266
|
-
label: "Validate",
|
|
13267
|
-
icon: "validate",
|
|
13268
|
-
section: "check",
|
|
13269
|
-
placement: "toolbar",
|
|
13270
|
-
requiredPorts: ["commands"],
|
|
13271
|
-
requiredContext: ["root"],
|
|
13272
|
-
binding: validate
|
|
13273
|
-
},
|
|
13274
|
-
{
|
|
13275
|
-
id: "convert",
|
|
13276
|
-
label: "Convert",
|
|
13277
|
-
icon: "convert",
|
|
13278
|
-
section: "check",
|
|
13279
|
-
placement: "toolbar",
|
|
13280
|
-
requiredPorts: ["commands"],
|
|
13281
|
-
requiredContext: ["root"],
|
|
13282
|
-
binding: convert
|
|
13283
|
-
},
|
|
13284
|
-
// Convert on the source-refused banner while the tree is out of lace
|
|
13285
|
-
// shape: the same `module convert` the toolbar runs, and the choice the
|
|
13286
|
-
// banner says of it. The engine re-derives the tree it writes, which
|
|
13287
|
-
// accepts it and lifts the lock.
|
|
13288
|
-
{
|
|
13289
|
-
id: "convert-refused",
|
|
13290
|
-
label: "Convert",
|
|
13291
|
-
choice: "Convert restructures it in place; a stack's apply creates only what its state does not hold yet.",
|
|
13292
|
-
icon: "convert",
|
|
13293
|
-
placement: { row: "source-refused" },
|
|
13294
|
-
requiredPorts: ["commands"],
|
|
13295
|
-
requiredContext: ["root", "needsConversion"],
|
|
13296
|
-
binding: convert
|
|
13297
|
-
}
|
|
13298
|
-
];
|
|
13299
|
-
var STACK_COMMAND_ACTIONS = [
|
|
13300
|
-
{
|
|
13301
|
-
id: "apply",
|
|
13302
|
-
label: "Apply",
|
|
13303
|
-
placement: "toolbar",
|
|
13304
|
-
requiredPorts: ["commands"],
|
|
13305
|
-
// `stack apply` gates on the tf and certification of the directory it
|
|
13306
|
-
// runs in (submit.Prepare(env.Root)) before it ever reaches the
|
|
13307
|
-
// runner, so a mount with no root can't run it even with a stack
|
|
13308
|
-
// chosen — the same root gate `validate`/`convert` need. It ships
|
|
13309
|
-
// whatever tf is on disk, not the canvas's own working IR.
|
|
13310
|
-
requiredContext: ["root", "stack"],
|
|
13311
|
-
binding: apply
|
|
13312
|
-
},
|
|
13313
|
-
{
|
|
13314
|
-
id: "destroy",
|
|
13315
|
-
label: "Destroy",
|
|
13316
|
-
placement: "toolbar",
|
|
13317
|
-
requiredPorts: ["commands"],
|
|
13318
|
-
// `stack destroy` shares the CLI's `executeRun` with `stack apply` and
|
|
13319
|
-
// runs under `env.Root`, so it needs the identical context tuple.
|
|
13320
|
-
requiredContext: ["root", "stack"],
|
|
13321
|
-
binding: destroy
|
|
13322
|
-
},
|
|
13323
|
-
{
|
|
13324
|
-
id: "scan",
|
|
13325
|
-
label: "Scan for drift",
|
|
13326
|
-
placement: "toolbar",
|
|
13327
|
-
requiredPorts: ["commands"],
|
|
13328
|
-
requiredContext: ["stack"],
|
|
13329
|
-
binding: scan
|
|
13330
|
-
},
|
|
13331
|
-
{
|
|
13332
|
-
id: "create",
|
|
13333
|
-
label: "Create stack",
|
|
13334
|
-
placement: "toolbar",
|
|
13335
|
-
requiredPorts: ["commands"],
|
|
13336
|
-
requiredContext: ["root"],
|
|
13337
|
-
binding: create
|
|
13338
|
-
},
|
|
13339
|
-
{
|
|
13340
|
-
id: "import",
|
|
13341
|
-
label: "Import existing resources",
|
|
13342
|
-
placement: "toolbar",
|
|
13343
|
-
requiredPorts: ["commands"],
|
|
13344
|
-
// `stack import` writes the directory it runs in, the same way
|
|
13345
|
-
// Convert does.
|
|
13346
|
-
requiredContext: ["root", "stack"],
|
|
13347
|
-
binding: importStack
|
|
13348
|
-
},
|
|
13349
|
-
{
|
|
13350
|
-
id: "import-partial",
|
|
13351
|
-
label: "Import the rest",
|
|
13352
|
-
placement: { row: "failure" },
|
|
13353
|
-
requiredPorts: ["commands"],
|
|
13354
|
-
requiredContext: ["root", "stack"],
|
|
13355
|
-
answers: ["import_residual"],
|
|
13356
|
-
binding: importPartial
|
|
13357
|
-
},
|
|
13358
|
-
{
|
|
13359
|
-
id: "preview",
|
|
13360
|
-
label: "Preview",
|
|
13361
|
-
placement: "toolbar",
|
|
13362
|
-
requiredPorts: ["commands"],
|
|
13363
|
-
// `stack preview` plans the tf of the directory it runs in — a stack
|
|
13364
|
-
// alone isn't enough, the mount needs the root too.
|
|
13365
|
-
requiredContext: ["root", "stack"],
|
|
13366
|
-
binding: preview
|
|
13367
|
-
},
|
|
13368
|
-
{
|
|
13369
|
-
id: "run-cancel",
|
|
13370
|
-
label: "Cancel",
|
|
13371
|
-
placement: { row: "runs" },
|
|
13372
|
-
requiredPorts: ["commands"],
|
|
13373
|
-
requiredTarget: ["runId"],
|
|
13374
|
-
binding: runCancel
|
|
13375
|
-
},
|
|
13376
|
-
{
|
|
13377
|
-
id: "follow-logs",
|
|
13378
|
-
label: "Follow logs",
|
|
13379
|
-
placement: { row: "runs" },
|
|
13380
|
-
requiredPorts: ["commands"],
|
|
13381
|
-
requiredTarget: ["runId"],
|
|
13382
|
-
binding: followLogs
|
|
13383
|
-
}
|
|
13384
|
-
];
|
|
13385
|
-
var CORE_COMMAND_ACTIONS = [
|
|
13386
|
-
...STACK_COMMAND_ACTIONS,
|
|
13387
|
-
...MODULE_COMMAND_ACTIONS
|
|
13388
|
-
];
|
|
13389
|
-
|
|
13390
|
-
// src/core/diagnostics.ts
|
|
13391
|
-
var NOT_LACE_SHAPE = "not_lace_shape";
|
|
13392
|
-
function holdsLaceShapeRefusal(diagnostics) {
|
|
13393
|
-
return diagnostics.some((d) => d.code === NOT_LACE_SHAPE);
|
|
13394
|
-
}
|
|
13395
|
-
function findingKey(d) {
|
|
13396
|
-
return JSON.stringify([
|
|
13397
|
-
d.file,
|
|
13398
|
-
d.line,
|
|
13399
|
-
d.message,
|
|
13400
|
-
d.module_key,
|
|
13401
|
-
d.instance_id,
|
|
13402
|
-
d.input_name,
|
|
13403
|
-
d.address
|
|
13404
|
-
]);
|
|
13405
|
-
}
|
|
13406
|
-
function uniqueDiagnostics(diagnostics) {
|
|
13407
|
-
const seen = /* @__PURE__ */ new Set();
|
|
13408
|
-
return diagnostics.filter((d) => {
|
|
13409
|
-
const key = findingKey(d);
|
|
13410
|
-
if (seen.has(key)) return false;
|
|
13411
|
-
seen.add(key);
|
|
13412
|
-
return true;
|
|
13413
|
-
});
|
|
13414
|
-
}
|
|
13415
|
-
function diagnosticsOf(sourceDiagnostics, reportFindings) {
|
|
13416
|
-
return uniqueDiagnostics([...sourceDiagnostics, ...reportFindings]);
|
|
13417
|
-
}
|
|
13418
|
-
|
|
13419
|
-
// src/core/report-fold.ts
|
|
13420
|
-
var REPORT_PATHS = ["module validate", "module convert", "module scan"];
|
|
13421
|
-
var FOLDS_AS = new Map([
|
|
13422
|
-
...REPORT_PATHS.map((path) => [path, path]),
|
|
13423
|
-
["stack import", "module convert"]
|
|
13424
|
-
]);
|
|
13425
|
-
var EMPTY_REPORT_FOLD = /* @__PURE__ */ new Map();
|
|
13426
|
-
function readEntry(path, exitCode, data) {
|
|
13427
|
-
if (carriesFailure(data)) {
|
|
13428
|
-
return { kind: "failure", path, exitCode, failure: parseCommandFailure(data) };
|
|
13429
|
-
}
|
|
13430
|
-
switch (path) {
|
|
13431
|
-
case "module validate":
|
|
13432
|
-
return { kind: "result", path, exitCode, document: parseBound(path, data) };
|
|
13433
|
-
case "module convert":
|
|
13434
|
-
return { kind: "result", path, exitCode, document: parseBound(path, data) };
|
|
13435
|
-
case "module scan":
|
|
13436
|
-
return { kind: "result", path, exitCode, document: parseBound(path, data) };
|
|
13437
|
-
}
|
|
13438
|
-
}
|
|
13439
|
-
function foldReport(prev, result) {
|
|
13440
|
-
const path = FOLDS_AS.get(result.path);
|
|
13441
|
-
if (path === void 0) return prev;
|
|
13442
|
-
const next = new Map(prev);
|
|
13443
|
-
if (result.document === "") next.delete(path);
|
|
13444
|
-
else next.set(path, readEntry(path, result.exitCode, JSON.parse(result.document)));
|
|
13445
|
-
return next;
|
|
13446
|
-
}
|
|
13447
|
-
function treeHashOf(entry) {
|
|
13448
|
-
if (entry.kind === "failure") return void 0;
|
|
13449
|
-
switch (entry.path) {
|
|
13450
|
-
case "module validate":
|
|
13451
|
-
case "module scan":
|
|
13452
|
-
return entry.document.treeHash;
|
|
13453
|
-
case "module convert":
|
|
13454
|
-
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;
|
|
13455
13217
|
}
|
|
13456
13218
|
}
|
|
13457
13219
|
function currentReport(fold, treeHash) {
|
|
@@ -13545,164 +13307,552 @@ function reduceRun(prev, token, event) {
|
|
|
13545
13307
|
phases
|
|
13546
13308
|
};
|
|
13547
13309
|
}
|
|
13548
|
-
if (event.error)
|
|
13310
|
+
if (!event.error)
|
|
13549
13311
|
return {
|
|
13550
13312
|
token,
|
|
13551
|
-
outcome: { kind: "
|
|
13313
|
+
outcome: { kind: "succeeded" },
|
|
13552
13314
|
lastLog,
|
|
13553
13315
|
submitted,
|
|
13554
13316
|
phases: closePhases(phases)
|
|
13555
13317
|
};
|
|
13556
|
-
return {
|
|
13557
|
-
token,
|
|
13558
|
-
outcome: { kind: "succeeded" },
|
|
13559
|
-
lastLog,
|
|
13560
|
-
submitted,
|
|
13561
|
-
phases: closePhases(phases)
|
|
13562
|
-
};
|
|
13563
13318
|
}
|
|
13564
|
-
return { token, outcome: { kind: "running" }, lastLog, submitted, phases };
|
|
13565
|
-
}
|
|
13566
|
-
function
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
if (error instanceof
|
|
13577
|
-
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
|
|
13584
|
-
|
|
13585
|
-
|
|
13586
|
-
|
|
13587
|
-
|
|
13588
|
-
|
|
13589
|
-
|
|
13590
|
-
|
|
13591
|
-
outcome: { kind: "
|
|
13592
|
-
|
|
13593
|
-
submitted,
|
|
13594
|
-
|
|
13595
|
-
|
|
13319
|
+
return { token, outcome: { kind: "running" }, lastLog, submitted, phases };
|
|
13320
|
+
}
|
|
13321
|
+
function runningFor(slot, token) {
|
|
13322
|
+
if (slot?.token !== token) return false;
|
|
13323
|
+
return "done" in slot ? !slot.done : slot.outcome.kind === "running";
|
|
13324
|
+
}
|
|
13325
|
+
function failureSays(error, command) {
|
|
13326
|
+
if (error instanceof CommandExitError) {
|
|
13327
|
+
if (error.failure) return { message: error.failure.message, failure: error.failure };
|
|
13328
|
+
const stderr = error.stderrTail.trim();
|
|
13329
|
+
return { message: stderr || `the command exited with code ${error.code} and wrote nothing` };
|
|
13330
|
+
}
|
|
13331
|
+
if (error instanceof CommandUnobservedError && command.kind === "read") {
|
|
13332
|
+
return { message: `the stream ended before \`lace ${command.path}\` finished; run it again` };
|
|
13333
|
+
}
|
|
13334
|
+
return { message: error instanceof Error ? error.message : String(error) };
|
|
13335
|
+
}
|
|
13336
|
+
var RUN = { kind: "write" };
|
|
13337
|
+
function settleRun(prev, token, error) {
|
|
13338
|
+
const carried = prev && prev.token === token ? prev : null;
|
|
13339
|
+
const lastLog = carried?.lastLog ?? null;
|
|
13340
|
+
const submitted = carried?.submitted ?? false;
|
|
13341
|
+
const phases = closePhases(carried?.phases ?? []);
|
|
13342
|
+
if (error instanceof CommandDetachedError || error instanceof CommandUnobservedError)
|
|
13343
|
+
return { token, outcome: { kind: "detached", submitted }, lastLog, submitted, phases };
|
|
13344
|
+
if (error instanceof CommandExitError) {
|
|
13345
|
+
if (error.code === 130)
|
|
13346
|
+
return { token, outcome: { kind: "cancelled" }, lastLog, submitted, phases };
|
|
13347
|
+
if (error.code === 143)
|
|
13348
|
+
return { token, outcome: { kind: "detached", submitted }, lastLog, submitted, phases };
|
|
13349
|
+
if (error.code === 7)
|
|
13350
|
+
return {
|
|
13351
|
+
token,
|
|
13352
|
+
outcome: { kind: "blocked", ...failureSays(error, RUN) },
|
|
13353
|
+
lastLog,
|
|
13354
|
+
submitted,
|
|
13355
|
+
phases
|
|
13356
|
+
};
|
|
13357
|
+
}
|
|
13358
|
+
return {
|
|
13359
|
+
token,
|
|
13360
|
+
outcome: { kind: "failed", ...failureSays(error, RUN) },
|
|
13361
|
+
lastLog,
|
|
13362
|
+
submitted,
|
|
13363
|
+
phases
|
|
13364
|
+
};
|
|
13365
|
+
}
|
|
13366
|
+
function reducePreview(_prev, token, event) {
|
|
13367
|
+
return { token, outcome: { kind: "succeeded", data: event } };
|
|
13368
|
+
}
|
|
13369
|
+
function reduceReport(prev, session, result) {
|
|
13370
|
+
const fold = foldReport(prev?.sessions.get(session) ?? EMPTY_REPORT_FOLD, result);
|
|
13371
|
+
return { sessions: new Map(prev?.sessions).set(session, fold) };
|
|
13372
|
+
}
|
|
13373
|
+
function reduceFollow(prev, token, event) {
|
|
13374
|
+
const carried = prev && prev.token === token ? prev : null;
|
|
13375
|
+
const runId = carried?.runId ?? "";
|
|
13376
|
+
const lines = carried?.lines ?? [];
|
|
13377
|
+
if (event.type === "log") return { token, runId, lines: [...lines, event.text], done: false };
|
|
13378
|
+
return { token, runId, lines, done: true };
|
|
13379
|
+
}
|
|
13380
|
+
function endStream(current, kind, token, error) {
|
|
13381
|
+
const { run, preview: preview2, follow } = current;
|
|
13382
|
+
if (kind === "run" && runningFor(run, token))
|
|
13383
|
+
return { ...current, run: stamp(settleRun(run, token, error), run.readOver) };
|
|
13384
|
+
if (kind === "preview" && runningFor(preview2, token)) return { ...current, preview: null };
|
|
13385
|
+
if (kind === "follow" && runningFor(follow, token))
|
|
13386
|
+
return { ...current, follow: { ...follow, done: true } };
|
|
13387
|
+
return current;
|
|
13388
|
+
}
|
|
13389
|
+
function createResultStore() {
|
|
13390
|
+
let slots = {
|
|
13391
|
+
run: null,
|
|
13392
|
+
preview: null,
|
|
13393
|
+
report: null,
|
|
13394
|
+
follow: null,
|
|
13395
|
+
running: /* @__PURE__ */ new Map()
|
|
13396
|
+
};
|
|
13397
|
+
let tick = 0;
|
|
13398
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
13399
|
+
const notify = () => {
|
|
13400
|
+
for (const listener of listeners) listener();
|
|
13401
|
+
};
|
|
13402
|
+
const retiredTokens = /* @__PURE__ */ new WeakSet();
|
|
13403
|
+
return {
|
|
13404
|
+
getSnapshot() {
|
|
13405
|
+
return slots;
|
|
13406
|
+
},
|
|
13407
|
+
getTick() {
|
|
13408
|
+
return tick;
|
|
13409
|
+
},
|
|
13410
|
+
subscribe(listener) {
|
|
13411
|
+
listeners.add(listener);
|
|
13412
|
+
return () => listeners.delete(listener);
|
|
13413
|
+
},
|
|
13414
|
+
write(kind, token, value, readOver) {
|
|
13415
|
+
if (retiredTokens.has(token)) return;
|
|
13416
|
+
slots = { ...slots, [kind]: applySlot(kind, slots[kind], token, value, readOver) };
|
|
13417
|
+
notify();
|
|
13418
|
+
},
|
|
13419
|
+
fail(kind, token, error) {
|
|
13420
|
+
const rendered = kind === "run";
|
|
13421
|
+
if (retiredTokens.has(token)) return rendered;
|
|
13422
|
+
const next = endStream(slots, kind, token, error);
|
|
13423
|
+
if (next !== slots) {
|
|
13424
|
+
slots = next;
|
|
13425
|
+
notify();
|
|
13426
|
+
}
|
|
13427
|
+
return rendered;
|
|
13428
|
+
},
|
|
13429
|
+
begin(kind, token, readOver, started) {
|
|
13430
|
+
if (kind === "run") {
|
|
13431
|
+
slots = {
|
|
13432
|
+
...slots,
|
|
13433
|
+
run: {
|
|
13434
|
+
token,
|
|
13435
|
+
outcome: { kind: "running" },
|
|
13436
|
+
lastLog: null,
|
|
13437
|
+
submitted: false,
|
|
13438
|
+
phases: [],
|
|
13439
|
+
readOver
|
|
13440
|
+
}
|
|
13441
|
+
};
|
|
13442
|
+
} else if (kind === "preview") {
|
|
13443
|
+
slots = { ...slots, preview: { token, outcome: { kind: "running" }, readOver } };
|
|
13444
|
+
} else if (kind === "follow") {
|
|
13445
|
+
slots = {
|
|
13446
|
+
...slots,
|
|
13447
|
+
follow: { token, runId: started.target.runId ?? "", lines: [], done: false, readOver }
|
|
13448
|
+
};
|
|
13449
|
+
} else if (kind === "notify") {
|
|
13450
|
+
const { on, path, label } = started;
|
|
13451
|
+
slots = { ...slots, running: new Map(slots.running).set(on, { token, path, label }) };
|
|
13452
|
+
} else {
|
|
13453
|
+
return;
|
|
13454
|
+
}
|
|
13455
|
+
notify();
|
|
13456
|
+
},
|
|
13457
|
+
detach(kind, token) {
|
|
13458
|
+
let next = endStream(slots, kind, token, new CommandDetachedError());
|
|
13459
|
+
if (kind === "follow" && next.follow?.token === token) {
|
|
13460
|
+
next = { ...next, follow: null };
|
|
13461
|
+
} else if (kind === "report" && next.report?.sessions.has(token)) {
|
|
13462
|
+
const sessions = new Map(next.report.sessions);
|
|
13463
|
+
sessions.delete(token);
|
|
13464
|
+
next = {
|
|
13465
|
+
...next,
|
|
13466
|
+
report: sessions.size > 0 ? { sessions, readOver: next.report.readOver } : null
|
|
13467
|
+
};
|
|
13468
|
+
} else if (kind === "notify") {
|
|
13469
|
+
const running = new Map([...next.running].filter(([, mark]) => mark.token !== token));
|
|
13470
|
+
if (running.size !== next.running.size) next = { ...next, running };
|
|
13471
|
+
}
|
|
13472
|
+
if (next !== slots) {
|
|
13473
|
+
slots = next;
|
|
13474
|
+
notify();
|
|
13475
|
+
}
|
|
13476
|
+
retiredTokens.add(token);
|
|
13477
|
+
},
|
|
13478
|
+
busy(kind, on) {
|
|
13479
|
+
if (kind === "run") {
|
|
13480
|
+
return slots.run?.outcome.kind === "running" ? { kind: "run" } : void 0;
|
|
13481
|
+
}
|
|
13482
|
+
if (kind !== "notify") return void 0;
|
|
13483
|
+
const running = slots.running.get(on);
|
|
13484
|
+
return running ? { kind: "notify", running } : void 0;
|
|
13485
|
+
},
|
|
13486
|
+
bumpTick() {
|
|
13487
|
+
tick += 1;
|
|
13488
|
+
notify();
|
|
13489
|
+
}
|
|
13490
|
+
};
|
|
13491
|
+
}
|
|
13492
|
+
|
|
13493
|
+
// src/core/define-command.ts
|
|
13494
|
+
function defineCommand(binding) {
|
|
13495
|
+
return {
|
|
13496
|
+
kind: "command",
|
|
13497
|
+
path: binding.path,
|
|
13498
|
+
confirms: binding.confirm !== void 0,
|
|
13499
|
+
resultKind: binding.result.kind,
|
|
13500
|
+
invalidates: binding.invalidates,
|
|
13501
|
+
partialArgs(ctx, target) {
|
|
13502
|
+
return binding.args(ctx, target);
|
|
13503
|
+
},
|
|
13504
|
+
confirmSpec(ctx, target, formArgs) {
|
|
13505
|
+
if (!binding.confirm) return void 0;
|
|
13506
|
+
const merged = completeArgs(binding.path, { ...binding.args(ctx, target), ...formArgs });
|
|
13507
|
+
if (!merged.ok) return void 0;
|
|
13508
|
+
return binding.confirm(ctx, merged.args, target);
|
|
13509
|
+
},
|
|
13510
|
+
async start(rt, ctx, target, formArgs, signal) {
|
|
13511
|
+
const merged = completeArgs(binding.path, { ...binding.args(ctx, target), ...formArgs });
|
|
13512
|
+
if (!merged.ok) return null;
|
|
13513
|
+
const commands = rt.ports.commands;
|
|
13514
|
+
if (!commands) return null;
|
|
13515
|
+
const invocation = commands.invoke(binding.path, merged.args, signal, rt.cwd);
|
|
13516
|
+
rt.begin();
|
|
13517
|
+
if (binding.invalidates === "start+settle") rt.tick();
|
|
13518
|
+
void (async () => {
|
|
13519
|
+
let rendered = false;
|
|
13520
|
+
try {
|
|
13521
|
+
for await (const event of invocation.events) {
|
|
13522
|
+
rendered = true;
|
|
13523
|
+
binding.result.consume(rt, event);
|
|
13524
|
+
}
|
|
13525
|
+
if (binding.invalidates) rt.tick();
|
|
13526
|
+
} catch (err) {
|
|
13527
|
+
const settledByDocument = rendered && binding.result.kind === "notify" && (err instanceof CommandExitError || err instanceof CommandUnobservedError);
|
|
13528
|
+
if (!rt.fail(err) && !(err instanceof CommandDetachedError) && !settledByDocument) {
|
|
13529
|
+
const { message, failure } = failureSays(
|
|
13530
|
+
err,
|
|
13531
|
+
binding.result.kind === "preview" || binding.result.kind === "follow" ? { kind: "read", path: binding.path } : { kind: "write" }
|
|
13532
|
+
);
|
|
13533
|
+
rt.ports.presenter.notify("error", message, ...failure ? [failure] : []);
|
|
13534
|
+
}
|
|
13535
|
+
if (binding.invalidates) rt.tick();
|
|
13536
|
+
} finally {
|
|
13537
|
+
rt.settled?.();
|
|
13538
|
+
}
|
|
13539
|
+
})();
|
|
13540
|
+
return { cancel: () => invocation.cancel() };
|
|
13541
|
+
}
|
|
13542
|
+
};
|
|
13543
|
+
}
|
|
13544
|
+
|
|
13545
|
+
// src/core/actions.ts
|
|
13546
|
+
function whyNotValid(v) {
|
|
13547
|
+
if (v.failure) return v.failure.message;
|
|
13548
|
+
const errors = v.diagnostics.filter((d) => d.severity === "error");
|
|
13549
|
+
if (errors.length === 0) return void 0;
|
|
13550
|
+
return `${errors[0].message} (${errors.length} ${errors.length === 1 ? "error" : "errors"})`;
|
|
13551
|
+
}
|
|
13552
|
+
function didNotValidate(v) {
|
|
13553
|
+
const why = whyNotValid(v);
|
|
13554
|
+
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.`;
|
|
13555
|
+
}
|
|
13556
|
+
function beside(v) {
|
|
13557
|
+
return v.failure ? [v.failure] : [];
|
|
13558
|
+
}
|
|
13559
|
+
function slotSink(kind) {
|
|
13560
|
+
return { kind, consume: (rt, e) => rt.write(kind, rt.token, e) };
|
|
13561
|
+
}
|
|
13562
|
+
var apply = defineCommand({
|
|
13563
|
+
kind: "command",
|
|
13564
|
+
path: "stack apply",
|
|
13565
|
+
args: (ctx) => ({ stack: ctx.stack?.id }),
|
|
13566
|
+
// The run sink ticks at both start and settle, so a read keyed on the
|
|
13567
|
+
// tick (a host's run list, the describe overlay) sees the in-flight run
|
|
13568
|
+
// as soon as it starts, not only once it ends.
|
|
13569
|
+
invalidates: "start+settle",
|
|
13570
|
+
result: slotSink("run")
|
|
13571
|
+
});
|
|
13572
|
+
var destroy = defineCommand({
|
|
13573
|
+
kind: "command",
|
|
13574
|
+
path: "stack destroy",
|
|
13575
|
+
args: (ctx) => ({ stack: ctx.stack?.id, yes: true }),
|
|
13576
|
+
// The typed confirmation is the stack's slug — the human-facing name a
|
|
13577
|
+
// user actually reads off the host's stack list — never its id, which
|
|
13578
|
+
// `args.stack` carries for the command itself but nobody types from
|
|
13579
|
+
// memory.
|
|
13580
|
+
confirm: (ctx) => ({
|
|
13581
|
+
text: `Destroy ${ctx.stack?.slug}? This runs terraform destroy on the runner.`,
|
|
13582
|
+
typed: ctx.stack?.slug
|
|
13583
|
+
}),
|
|
13584
|
+
invalidates: "start+settle",
|
|
13585
|
+
result: slotSink("run")
|
|
13586
|
+
});
|
|
13587
|
+
function scanNotice(e) {
|
|
13588
|
+
const { slug } = e.stack;
|
|
13589
|
+
const settled = e.settled;
|
|
13590
|
+
if (!settled) {
|
|
13591
|
+
return [
|
|
13592
|
+
"info",
|
|
13593
|
+
e.triggered ? `Drift scan triggered for stack ${slug} (${e.stack.id}).` : `Drift scan already in progress for stack ${slug}.`
|
|
13594
|
+
];
|
|
13595
|
+
}
|
|
13596
|
+
if (settled.undeterminedMessage !== null) return ["warn", settled.undeterminedMessage];
|
|
13597
|
+
if (settled.footprintDestroyed) {
|
|
13598
|
+
return [
|
|
13599
|
+
"info",
|
|
13600
|
+
`Drift scan complete for stack ${slug}: IN_SYNC (0 drifted) \u2014 its resources were destroyed, so there was nothing to compare.`
|
|
13601
|
+
];
|
|
13602
|
+
}
|
|
13603
|
+
if (settled.standingDriftFindings > 0) {
|
|
13604
|
+
return [
|
|
13605
|
+
"info",
|
|
13606
|
+
`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.`
|
|
13607
|
+
];
|
|
13608
|
+
}
|
|
13609
|
+
return [
|
|
13610
|
+
"info",
|
|
13611
|
+
`Drift scan complete for stack ${slug}: ${settled.driftStatus} (${settled.driftCount} drifted).`
|
|
13612
|
+
];
|
|
13613
|
+
}
|
|
13614
|
+
var scan = defineCommand({
|
|
13615
|
+
kind: "command",
|
|
13616
|
+
path: "stack scan",
|
|
13617
|
+
args: (ctx) => ({ stack: ctx.stack?.id, wait: true }),
|
|
13618
|
+
invalidates: true,
|
|
13619
|
+
result: {
|
|
13620
|
+
kind: "notify",
|
|
13621
|
+
consume: (rt, e) => rt.ports.presenter.notify(...scanNotice(e))
|
|
13622
|
+
}
|
|
13623
|
+
});
|
|
13624
|
+
var create = defineCommand({
|
|
13625
|
+
kind: "command",
|
|
13626
|
+
path: "stack create",
|
|
13627
|
+
args: (ctx) => ({ source: ctx.root }),
|
|
13628
|
+
invalidates: true,
|
|
13629
|
+
result: {
|
|
13630
|
+
kind: "notify",
|
|
13631
|
+
consume: (rt, e) => rt.ports.presenter.notify("info", `Created stack ${e.slug}`)
|
|
13632
|
+
}
|
|
13633
|
+
});
|
|
13634
|
+
function residualAddresses(residuals) {
|
|
13635
|
+
return residuals.map((r) => r.address).join(", ");
|
|
13636
|
+
}
|
|
13637
|
+
function treeChanges(e) {
|
|
13638
|
+
return [
|
|
13639
|
+
...e.written.length === 0 ? [] : [`rewriting ${e.written.join(", ")} in place`],
|
|
13640
|
+
...e.removed.length === 0 ? [] : [`removing ${e.removed.join(", ")}`]
|
|
13641
|
+
];
|
|
13642
|
+
}
|
|
13643
|
+
function importNotice(e) {
|
|
13644
|
+
const { slug } = e.stack;
|
|
13645
|
+
const changes = treeChanges(e);
|
|
13646
|
+
const files = changes.length > 0 ? `, ${changes.join(" and ")}` : "";
|
|
13647
|
+
const imported = `Imported ${e.importBlocks} resource(s) into ${slug}${files}.`;
|
|
13648
|
+
if (e.validate.exitClass !== "ok") {
|
|
13649
|
+
return ["warn", `${imported} ${didNotValidate(e.validate)}`, ...beside(e.validate)];
|
|
13650
|
+
}
|
|
13651
|
+
const adopt = e.changed ? ` Review the change in git, commit it, then apply ${slug} to adopt them.` : "";
|
|
13652
|
+
if (e.importResiduals.length === 0) return ["info", `${imported}${adopt}`];
|
|
13653
|
+
return [
|
|
13654
|
+
"warn",
|
|
13655
|
+
`${imported}${adopt} Not adopted: ${residualAddresses(e.importResiduals)}; supply their import ids before applying, or the apply creates them anew.`
|
|
13656
|
+
];
|
|
13657
|
+
}
|
|
13658
|
+
var importResult = {
|
|
13659
|
+
kind: "notify",
|
|
13660
|
+
consume: (rt, e) => rt.ports.presenter.notify(...importNotice(e))
|
|
13661
|
+
};
|
|
13662
|
+
var importStack = defineCommand({
|
|
13663
|
+
kind: "command",
|
|
13664
|
+
path: "stack import",
|
|
13665
|
+
args: (ctx) => ({ stack: ctx.stack?.id }),
|
|
13666
|
+
invalidates: true,
|
|
13667
|
+
result: importResult
|
|
13668
|
+
});
|
|
13669
|
+
var importPartial = defineCommand({
|
|
13670
|
+
kind: "command",
|
|
13671
|
+
path: "stack import",
|
|
13672
|
+
args: (ctx) => ({ stack: ctx.stack?.id, allowPartial: true }),
|
|
13673
|
+
confirm: (ctx, _args, target) => ({
|
|
13674
|
+
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.`
|
|
13675
|
+
}),
|
|
13676
|
+
invalidates: true,
|
|
13677
|
+
result: importResult
|
|
13678
|
+
});
|
|
13679
|
+
function validateNotice(v) {
|
|
13680
|
+
if (v.exitClass === "ok") return ["info", `Valid for Lace \u2014 ${v.verdict}`];
|
|
13681
|
+
if (v.failure) return ["error", v.failure.message, v.failure];
|
|
13682
|
+
const why = whyNotValid(v);
|
|
13683
|
+
return ["warn", why === void 0 ? "Not valid for Lace" : `Not valid: ${why}`];
|
|
13684
|
+
}
|
|
13685
|
+
function convertNotice(e) {
|
|
13686
|
+
const converted = e.changed ? `Converted \u2014 ${e.written.length} file(s) written` : "Already lace-style \u2014 nothing to write";
|
|
13687
|
+
if (e.validate.exitClass === "ok") return ["info", converted];
|
|
13688
|
+
return ["warn", `${converted}. ${didNotValidate(e.validate)}`, ...beside(e.validate)];
|
|
13689
|
+
}
|
|
13690
|
+
var validate = defineCommand({
|
|
13691
|
+
kind: "command",
|
|
13692
|
+
path: "module validate",
|
|
13693
|
+
args: () => ({}),
|
|
13694
|
+
result: {
|
|
13695
|
+
kind: "notify",
|
|
13696
|
+
consume: (rt, e) => rt.ports.presenter.notify(...validateNotice(e))
|
|
13697
|
+
}
|
|
13698
|
+
});
|
|
13699
|
+
var convert = defineCommand({
|
|
13700
|
+
kind: "command",
|
|
13701
|
+
path: "module convert",
|
|
13702
|
+
args: () => ({}),
|
|
13703
|
+
result: {
|
|
13704
|
+
kind: "notify",
|
|
13705
|
+
consume: (rt, e) => rt.ports.presenter.notify(...convertNotice(e))
|
|
13706
|
+
}
|
|
13707
|
+
});
|
|
13708
|
+
var preview = defineCommand({
|
|
13709
|
+
kind: "command",
|
|
13710
|
+
path: "stack preview",
|
|
13711
|
+
args: (ctx) => ({ stack: ctx.stack?.id }),
|
|
13712
|
+
result: slotSink("preview")
|
|
13713
|
+
});
|
|
13714
|
+
var runCancel = defineCommand({
|
|
13715
|
+
kind: "command",
|
|
13716
|
+
path: "run cancel",
|
|
13717
|
+
args: (_ctx, target) => ({ run: target.runId }),
|
|
13718
|
+
invalidates: true,
|
|
13719
|
+
result: {
|
|
13720
|
+
kind: "notify",
|
|
13721
|
+
consume: (rt, e) => rt.ports.presenter.notify("info", `Run ${e.id} ${e.status}`)
|
|
13722
|
+
}
|
|
13723
|
+
});
|
|
13724
|
+
var followLogs = defineCommand({
|
|
13725
|
+
kind: "command",
|
|
13726
|
+
path: "run logs",
|
|
13727
|
+
args: (_ctx, target) => ({ run: target.runId, follow: true }),
|
|
13728
|
+
result: slotSink("follow")
|
|
13729
|
+
});
|
|
13730
|
+
var MODULE_COMMAND_ACTIONS = [
|
|
13731
|
+
{
|
|
13732
|
+
id: "validate",
|
|
13733
|
+
label: "Validate",
|
|
13734
|
+
icon: "validate",
|
|
13735
|
+
section: "check",
|
|
13736
|
+
placement: "toolbar",
|
|
13737
|
+
requiredPorts: ["commands"],
|
|
13738
|
+
requiredContext: ["root"],
|
|
13739
|
+
binding: validate
|
|
13740
|
+
},
|
|
13741
|
+
{
|
|
13742
|
+
id: "convert",
|
|
13743
|
+
label: "Convert",
|
|
13744
|
+
icon: "convert",
|
|
13745
|
+
section: "check",
|
|
13746
|
+
placement: "toolbar",
|
|
13747
|
+
requiredPorts: ["commands"],
|
|
13748
|
+
requiredContext: ["root"],
|
|
13749
|
+
binding: convert
|
|
13750
|
+
},
|
|
13751
|
+
// Convert on the source-refused banner while the tree is out of lace
|
|
13752
|
+
// shape: the same `module convert` the toolbar runs, and the choice the
|
|
13753
|
+
// banner says of it. The engine re-derives the tree it writes, which
|
|
13754
|
+
// accepts it and lifts the lock.
|
|
13755
|
+
{
|
|
13756
|
+
id: "convert-refused",
|
|
13757
|
+
label: "Convert",
|
|
13758
|
+
choice: "Convert restructures it in place; a stack's apply creates only what its state does not hold yet.",
|
|
13759
|
+
icon: "convert",
|
|
13760
|
+
placement: { row: "source-refused" },
|
|
13761
|
+
requiredPorts: ["commands"],
|
|
13762
|
+
requiredContext: ["root", "needsConversion"],
|
|
13763
|
+
binding: convert
|
|
13764
|
+
}
|
|
13765
|
+
];
|
|
13766
|
+
var STACK_COMMAND_ACTIONS = [
|
|
13767
|
+
{
|
|
13768
|
+
id: "apply",
|
|
13769
|
+
label: "Apply",
|
|
13770
|
+
placement: "toolbar",
|
|
13771
|
+
requiredPorts: ["commands"],
|
|
13772
|
+
// `stack apply` gates on the tf and certification of the directory it
|
|
13773
|
+
// runs in (submit.Prepare(env.Root)) before it ever reaches the
|
|
13774
|
+
// runner, so a mount with no root can't run it even with a stack
|
|
13775
|
+
// chosen — the same root gate `validate`/`convert` need. It ships
|
|
13776
|
+
// whatever tf is on disk, not the canvas's own working IR.
|
|
13777
|
+
requiredContext: ["root", "stack"],
|
|
13778
|
+
binding: apply
|
|
13779
|
+
},
|
|
13780
|
+
{
|
|
13781
|
+
id: "destroy",
|
|
13782
|
+
label: "Destroy",
|
|
13783
|
+
placement: "toolbar",
|
|
13784
|
+
requiredPorts: ["commands"],
|
|
13785
|
+
// `stack destroy` shares the CLI's `executeRun` with `stack apply` and
|
|
13786
|
+
// runs under `env.Root`, so it needs the identical context tuple.
|
|
13787
|
+
requiredContext: ["root", "stack"],
|
|
13788
|
+
binding: destroy
|
|
13789
|
+
},
|
|
13790
|
+
{
|
|
13791
|
+
id: "scan",
|
|
13792
|
+
label: "Scan for drift",
|
|
13793
|
+
placement: "toolbar",
|
|
13794
|
+
requiredPorts: ["commands"],
|
|
13795
|
+
requiredContext: ["stack"],
|
|
13796
|
+
binding: scan
|
|
13797
|
+
},
|
|
13798
|
+
{
|
|
13799
|
+
id: "create",
|
|
13800
|
+
label: "Create stack",
|
|
13801
|
+
placement: "toolbar",
|
|
13802
|
+
requiredPorts: ["commands"],
|
|
13803
|
+
requiredContext: ["root"],
|
|
13804
|
+
binding: create
|
|
13805
|
+
},
|
|
13806
|
+
{
|
|
13807
|
+
id: "import",
|
|
13808
|
+
label: "Import existing resources",
|
|
13809
|
+
placement: "toolbar",
|
|
13810
|
+
requiredPorts: ["commands"],
|
|
13811
|
+
// `stack import` writes the directory it runs in, the same way
|
|
13812
|
+
// Convert does.
|
|
13813
|
+
requiredContext: ["root", "stack"],
|
|
13814
|
+
binding: importStack
|
|
13815
|
+
},
|
|
13816
|
+
{
|
|
13817
|
+
id: "import-partial",
|
|
13818
|
+
label: "Import the rest",
|
|
13819
|
+
placement: { row: "failure" },
|
|
13820
|
+
requiredPorts: ["commands"],
|
|
13821
|
+
requiredContext: ["root", "stack"],
|
|
13822
|
+
answers: ["import_residual"],
|
|
13823
|
+
binding: importPartial
|
|
13824
|
+
},
|
|
13825
|
+
{
|
|
13826
|
+
id: "preview",
|
|
13827
|
+
label: "Preview",
|
|
13828
|
+
placement: "toolbar",
|
|
13829
|
+
requiredPorts: ["commands"],
|
|
13830
|
+
// `stack preview` plans the tf of the directory it runs in — a stack
|
|
13831
|
+
// alone isn't enough, the mount needs the root too.
|
|
13832
|
+
requiredContext: ["root", "stack"],
|
|
13833
|
+
binding: preview
|
|
13834
|
+
},
|
|
13835
|
+
{
|
|
13836
|
+
id: "run-cancel",
|
|
13837
|
+
label: "Cancel",
|
|
13838
|
+
placement: { row: "runs" },
|
|
13839
|
+
requiredPorts: ["commands"],
|
|
13840
|
+
requiredTarget: ["runId"],
|
|
13841
|
+
binding: runCancel
|
|
13842
|
+
},
|
|
13843
|
+
{
|
|
13844
|
+
id: "follow-logs",
|
|
13845
|
+
label: "Follow logs",
|
|
13846
|
+
placement: { row: "runs" },
|
|
13847
|
+
requiredPorts: ["commands"],
|
|
13848
|
+
requiredTarget: ["runId"],
|
|
13849
|
+
binding: followLogs
|
|
13596
13850
|
}
|
|
13597
|
-
|
|
13598
|
-
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
phases
|
|
13603
|
-
};
|
|
13604
|
-
}
|
|
13605
|
-
function reducePreview(_prev, token, event) {
|
|
13606
|
-
return { token, data: event };
|
|
13607
|
-
}
|
|
13608
|
-
function reduceReport(prev, session, result) {
|
|
13609
|
-
const fold = foldReport(prev?.sessions.get(session) ?? EMPTY_REPORT_FOLD, result);
|
|
13610
|
-
return { sessions: new Map(prev?.sessions).set(session, fold) };
|
|
13611
|
-
}
|
|
13612
|
-
function reduceFollow(prev, token, event) {
|
|
13613
|
-
const carried = prev && prev.token === token ? prev : null;
|
|
13614
|
-
const runId = carried?.runId ?? "";
|
|
13615
|
-
const lines = carried?.lines ?? [];
|
|
13616
|
-
if (event.type === "log") return { token, runId, lines: [...lines, event.text], done: false };
|
|
13617
|
-
return { token, runId, lines, done: true };
|
|
13618
|
-
}
|
|
13619
|
-
function createResultStore() {
|
|
13620
|
-
let slots = {
|
|
13621
|
-
run: null,
|
|
13622
|
-
preview: null,
|
|
13623
|
-
report: null,
|
|
13624
|
-
follow: null
|
|
13625
|
-
};
|
|
13626
|
-
let tick = 0;
|
|
13627
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
13628
|
-
const notify = () => {
|
|
13629
|
-
for (const listener of listeners) listener();
|
|
13630
|
-
};
|
|
13631
|
-
const retiredTokens = /* @__PURE__ */ new WeakSet();
|
|
13632
|
-
return {
|
|
13633
|
-
getSnapshot() {
|
|
13634
|
-
return slots;
|
|
13635
|
-
},
|
|
13636
|
-
getTick() {
|
|
13637
|
-
return tick;
|
|
13638
|
-
},
|
|
13639
|
-
subscribe(listener) {
|
|
13640
|
-
listeners.add(listener);
|
|
13641
|
-
return () => listeners.delete(listener);
|
|
13642
|
-
},
|
|
13643
|
-
write(kind, token, value, readOver) {
|
|
13644
|
-
if (retiredTokens.has(token)) return;
|
|
13645
|
-
slots = { ...slots, [kind]: applySlot(kind, slots[kind], token, value, readOver) };
|
|
13646
|
-
notify();
|
|
13647
|
-
},
|
|
13648
|
-
fail(kind, token, error) {
|
|
13649
|
-
if (kind !== "run") return false;
|
|
13650
|
-
if (retiredTokens.has(token) || !slots.run) return true;
|
|
13651
|
-
slots = { ...slots, run: stamp(settleRun(slots.run, token, error), slots.run.readOver) };
|
|
13652
|
-
notify();
|
|
13653
|
-
return true;
|
|
13654
|
-
},
|
|
13655
|
-
begin(kind, token, readOver, target) {
|
|
13656
|
-
if (kind === "run") {
|
|
13657
|
-
slots = {
|
|
13658
|
-
...slots,
|
|
13659
|
-
run: {
|
|
13660
|
-
token,
|
|
13661
|
-
outcome: { kind: "running" },
|
|
13662
|
-
lastLog: null,
|
|
13663
|
-
submitted: false,
|
|
13664
|
-
phases: [],
|
|
13665
|
-
readOver
|
|
13666
|
-
}
|
|
13667
|
-
};
|
|
13668
|
-
} else if (kind === "follow") {
|
|
13669
|
-
slots = {
|
|
13670
|
-
...slots,
|
|
13671
|
-
follow: { token, runId: target.runId ?? "", lines: [], done: false, readOver }
|
|
13672
|
-
};
|
|
13673
|
-
} else {
|
|
13674
|
-
return;
|
|
13675
|
-
}
|
|
13676
|
-
notify();
|
|
13677
|
-
},
|
|
13678
|
-
detach(kind, token) {
|
|
13679
|
-
if (kind === "follow" && slots.follow?.token === token) {
|
|
13680
|
-
slots = { ...slots, follow: null };
|
|
13681
|
-
notify();
|
|
13682
|
-
} else if (kind === "report" && slots.report?.sessions.has(token)) {
|
|
13683
|
-
const sessions = new Map(slots.report.sessions);
|
|
13684
|
-
sessions.delete(token);
|
|
13685
|
-
slots = {
|
|
13686
|
-
...slots,
|
|
13687
|
-
report: sessions.size > 0 ? { sessions, readOver: slots.report.readOver } : null
|
|
13688
|
-
};
|
|
13689
|
-
notify();
|
|
13690
|
-
} else if (kind === "run" && slots.run?.token === token) {
|
|
13691
|
-
const settled = settleRun(slots.run, token, new CommandDetachedError());
|
|
13692
|
-
slots = { ...slots, run: stamp(settled, slots.run.readOver) };
|
|
13693
|
-
notify();
|
|
13694
|
-
}
|
|
13695
|
-
retiredTokens.add(token);
|
|
13696
|
-
},
|
|
13697
|
-
isBusy(kind) {
|
|
13698
|
-
return kind === "run" && slots.run?.outcome.kind === "running";
|
|
13699
|
-
},
|
|
13700
|
-
bumpTick() {
|
|
13701
|
-
tick += 1;
|
|
13702
|
-
notify();
|
|
13703
|
-
}
|
|
13704
|
-
};
|
|
13705
|
-
}
|
|
13851
|
+
];
|
|
13852
|
+
var CORE_COMMAND_ACTIONS = [
|
|
13853
|
+
...STACK_COMMAND_ACTIONS,
|
|
13854
|
+
...MODULE_COMMAND_ACTIONS
|
|
13855
|
+
];
|
|
13706
13856
|
|
|
13707
13857
|
// src/registry.ts
|
|
13708
13858
|
var CONTEXT_NEEDS = {
|
|
@@ -13733,7 +13883,16 @@ var TARGET_NEEDS = {
|
|
|
13733
13883
|
runId: "a run",
|
|
13734
13884
|
failure: "a failed command"
|
|
13735
13885
|
};
|
|
13736
|
-
|
|
13886
|
+
function busyReason(busy) {
|
|
13887
|
+
return busy.kind === "run" ? "A run is in progress" : `${busy.running.label} is running`;
|
|
13888
|
+
}
|
|
13889
|
+
function runsOn(action, ctx, target) {
|
|
13890
|
+
if (action.requiredTarget?.includes("runId")) return `run:${target.runId}`;
|
|
13891
|
+
const required = action.requiredContext ?? [];
|
|
13892
|
+
if (required.includes("stack")) return `stack:${ctx.stack?.id}`;
|
|
13893
|
+
if (required.includes("root")) return `root:${ctx.root}`;
|
|
13894
|
+
return "";
|
|
13895
|
+
}
|
|
13737
13896
|
function keySatisfied(ctx, key) {
|
|
13738
13897
|
if (key === "editable") return ctx.editable === true;
|
|
13739
13898
|
if (key === "saved") return ctx.view?.unsaved === false;
|
|
@@ -13758,13 +13917,24 @@ function keySatisfied(ctx, key) {
|
|
|
13758
13917
|
function contextSatisfied(ctx, required) {
|
|
13759
13918
|
return required.every((key) => keySatisfied(ctx, key));
|
|
13760
13919
|
}
|
|
13761
|
-
function disabledReason(action, ctx,
|
|
13762
|
-
if (
|
|
13920
|
+
function disabledReason(action, ctx, busy) {
|
|
13921
|
+
if (busy) return busyReason(busy);
|
|
13763
13922
|
for (const { key, reason } of action.enabledWhen ?? []) {
|
|
13764
13923
|
if (!keySatisfied(ctx, key)) return reason;
|
|
13765
13924
|
}
|
|
13766
13925
|
return void 0;
|
|
13767
13926
|
}
|
|
13927
|
+
function busyLabelOf(action, ctx, busy) {
|
|
13928
|
+
if (action.busy && keySatisfied(ctx, action.busy.when)) return action.busy.label;
|
|
13929
|
+
if (busy === void 0 || action.binding.kind !== "command") return void 0;
|
|
13930
|
+
return busy.kind === "run" || busy.running.path === action.binding.path ? action.label : void 0;
|
|
13931
|
+
}
|
|
13932
|
+
function actionState(action, ctx, busy) {
|
|
13933
|
+
return {
|
|
13934
|
+
disabledReason: disabledReason(action, ctx, busy),
|
|
13935
|
+
busyLabel: busyLabelOf(action, ctx, busy)
|
|
13936
|
+
};
|
|
13937
|
+
}
|
|
13768
13938
|
function missingPort(ports, required) {
|
|
13769
13939
|
return required.find((name) => ports[name] === void 0);
|
|
13770
13940
|
}
|
|
@@ -13863,7 +14033,19 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13863
14033
|
const handles = /* @__PURE__ */ new Map();
|
|
13864
14034
|
const tokens = /* @__PURE__ */ new Map();
|
|
13865
14035
|
const clipboard = createClipboardStore();
|
|
13866
|
-
const notifyControllers = /* @__PURE__ */ new
|
|
14036
|
+
const notifyControllers = /* @__PURE__ */ new Map();
|
|
14037
|
+
let edits = 0;
|
|
14038
|
+
const editingListeners = /* @__PURE__ */ new Set();
|
|
14039
|
+
async function asEdit(edit) {
|
|
14040
|
+
edits += 1;
|
|
14041
|
+
if (edits === 1) for (const listener of editingListeners) listener(true);
|
|
14042
|
+
try {
|
|
14043
|
+
return await edit();
|
|
14044
|
+
} finally {
|
|
14045
|
+
edits -= 1;
|
|
14046
|
+
if (edits === 0) for (const listener of editingListeners) listener(false);
|
|
14047
|
+
}
|
|
14048
|
+
}
|
|
13867
14049
|
async function applyWith(editor, actions) {
|
|
13868
14050
|
let result;
|
|
13869
14051
|
try {
|
|
@@ -13903,13 +14085,14 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13903
14085
|
async function applyActions(actions) {
|
|
13904
14086
|
const editor = ports.editor;
|
|
13905
14087
|
if (!editor) return;
|
|
13906
|
-
return applyWith(editor, actions);
|
|
14088
|
+
return asEdit(() => applyWith(editor, actions));
|
|
13907
14089
|
}
|
|
13908
14090
|
function askConfirm(spec) {
|
|
13909
14091
|
const confirm = ports.presenter.confirm;
|
|
13910
14092
|
return confirm ? confirm(spec) : Promise.resolve(false);
|
|
13911
14093
|
}
|
|
13912
|
-
function runtimeFor(token, readOver, cwd,
|
|
14094
|
+
function runtimeFor(token, readOver, cwd, command, onSettle) {
|
|
14095
|
+
const run = command?.run;
|
|
13913
14096
|
return {
|
|
13914
14097
|
ports,
|
|
13915
14098
|
token,
|
|
@@ -13920,7 +14103,7 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13920
14103
|
if (run && line !== void 0) options.onRunLog?.(line, run);
|
|
13921
14104
|
},
|
|
13922
14105
|
begin: () => {
|
|
13923
|
-
if (
|
|
14106
|
+
if (command) store.begin(command.run.resultKind, token, readOver, command.started);
|
|
13924
14107
|
},
|
|
13925
14108
|
fail: (error) => run ? store.fail(run.resultKind, token, error) : false,
|
|
13926
14109
|
detach: (kind, tok) => store.detach(kind, tok),
|
|
@@ -13931,6 +14114,15 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13931
14114
|
function readOverOf(ctx) {
|
|
13932
14115
|
return { stack: ctx.stack?.id };
|
|
13933
14116
|
}
|
|
14117
|
+
function busyOn(resultKind, action, ctx, target) {
|
|
14118
|
+
const on = runsOn(action, ctx, target);
|
|
14119
|
+
return { on, busy: store.busy(resultKind, on) };
|
|
14120
|
+
}
|
|
14121
|
+
function busyOf(action, ctx, target) {
|
|
14122
|
+
const binding = action.binding;
|
|
14123
|
+
if (binding.kind !== "command") return void 0;
|
|
14124
|
+
return busyOn(binding.resultKind, action, ctx, target).busy;
|
|
14125
|
+
}
|
|
13934
14126
|
function cwdOf(action, ctx) {
|
|
13935
14127
|
return (action.requiredContext ?? []).includes("root") ? ctx.root : void 0;
|
|
13936
14128
|
}
|
|
@@ -13952,19 +14144,24 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13952
14144
|
if (binding.kind !== "command") return;
|
|
13953
14145
|
const spec = binding.confirmSpec(ctx, target, formArgs);
|
|
13954
14146
|
if (spec && !await askConfirm(spec)) return;
|
|
13955
|
-
|
|
13956
|
-
|
|
14147
|
+
const { on, busy } = busyOn(binding.resultKind, action, ctx, target);
|
|
14148
|
+
if (busy) {
|
|
14149
|
+
ports.presenter.notify("warn", busyReason(busy));
|
|
13957
14150
|
return;
|
|
13958
14151
|
}
|
|
13959
14152
|
const readOver = readOverOf(ctx);
|
|
13960
14153
|
const cwd = cwdOf(action, ctx);
|
|
13961
14154
|
const token = {};
|
|
13962
14155
|
const run = { token, path: binding.path, resultKind: binding.resultKind, ctx, target };
|
|
14156
|
+
const started = { target, on, path: binding.path, label: action.label };
|
|
13963
14157
|
const controller = new AbortController();
|
|
13964
14158
|
if (binding.resultKind === "notify") {
|
|
13965
|
-
notifyControllers.
|
|
14159
|
+
notifyControllers.set(controller, token);
|
|
13966
14160
|
await binding.start(
|
|
13967
|
-
runtimeFor(token, readOver, cwd, run, () =>
|
|
14161
|
+
runtimeFor(token, readOver, cwd, { run, started }, () => {
|
|
14162
|
+
notifyControllers.delete(controller);
|
|
14163
|
+
store.detach("notify", token);
|
|
14164
|
+
}),
|
|
13968
14165
|
ctx,
|
|
13969
14166
|
target,
|
|
13970
14167
|
formArgs,
|
|
@@ -13976,7 +14173,7 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
13976
14173
|
controllers.set(binding.resultKind, controller);
|
|
13977
14174
|
tokens.set(binding.resultKind, token);
|
|
13978
14175
|
const handle = await binding.start(
|
|
13979
|
-
runtimeFor(token, readOver, cwd, run),
|
|
14176
|
+
runtimeFor(token, readOver, cwd, { run, started }),
|
|
13980
14177
|
ctx,
|
|
13981
14178
|
target,
|
|
13982
14179
|
formArgs,
|
|
@@ -14025,7 +14222,7 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
14025
14222
|
...envExtras
|
|
14026
14223
|
};
|
|
14027
14224
|
if (binding.result === "apply") {
|
|
14028
|
-
return binding.run(env);
|
|
14225
|
+
return asEdit(() => binding.run(env));
|
|
14029
14226
|
}
|
|
14030
14227
|
if (binding.result === "generate") {
|
|
14031
14228
|
for await (const event of binding.run(env)) {
|
|
@@ -14053,8 +14250,7 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
14053
14250
|
ports.presenter.notify("warn", unmet);
|
|
14054
14251
|
return;
|
|
14055
14252
|
}
|
|
14056
|
-
const
|
|
14057
|
-
const reason = disabledReason(action, ctx, isBusy);
|
|
14253
|
+
const reason = disabledReason(action, ctx, busyOf(action, ctx, target));
|
|
14058
14254
|
if (reason !== void 0) {
|
|
14059
14255
|
ports.presenter.notify("warn", reason);
|
|
14060
14256
|
return;
|
|
@@ -14081,6 +14277,18 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
14081
14277
|
apply(actions) {
|
|
14082
14278
|
return applyActions(actions);
|
|
14083
14279
|
},
|
|
14280
|
+
editing() {
|
|
14281
|
+
return edits > 0;
|
|
14282
|
+
},
|
|
14283
|
+
onEditingChange(listener) {
|
|
14284
|
+
editingListeners.add(listener);
|
|
14285
|
+
return () => {
|
|
14286
|
+
editingListeners.delete(listener);
|
|
14287
|
+
};
|
|
14288
|
+
},
|
|
14289
|
+
busy(action, ctx, target) {
|
|
14290
|
+
return busyOf(action, ctx, target);
|
|
14291
|
+
},
|
|
14084
14292
|
async cancel(kind) {
|
|
14085
14293
|
const handle = handles.get(kind);
|
|
14086
14294
|
if (!handle) return;
|
|
@@ -14092,7 +14300,10 @@ function createActionRunner(ports, store, options = {}) {
|
|
|
14092
14300
|
},
|
|
14093
14301
|
dispose() {
|
|
14094
14302
|
for (const kind of [...controllers.keys()]) detachSlot(kind);
|
|
14095
|
-
for (const controller of notifyControllers)
|
|
14303
|
+
for (const [controller, token] of notifyControllers) {
|
|
14304
|
+
controller.abort();
|
|
14305
|
+
store.detach("notify", token);
|
|
14306
|
+
}
|
|
14096
14307
|
notifyControllers.clear();
|
|
14097
14308
|
}
|
|
14098
14309
|
};
|
|
@@ -14190,6 +14401,7 @@ export {
|
|
|
14190
14401
|
diagnosticsOf,
|
|
14191
14402
|
keySatisfied,
|
|
14192
14403
|
disabledReason,
|
|
14404
|
+
actionState,
|
|
14193
14405
|
answering,
|
|
14194
14406
|
resolveContributions,
|
|
14195
14407
|
rowActions,
|
|
@@ -14210,10 +14422,6 @@ export {
|
|
|
14210
14422
|
parseBound,
|
|
14211
14423
|
carriesFailure,
|
|
14212
14424
|
parseCommandFailure,
|
|
14213
|
-
defineCommand,
|
|
14214
|
-
MODULE_COMMAND_ACTIONS,
|
|
14215
|
-
CORE_COMMAND_ACTIONS,
|
|
14216
|
-
isPlainObject,
|
|
14217
14425
|
EMPTY_REPORT_FOLD,
|
|
14218
14426
|
foldReport,
|
|
14219
14427
|
currentReport,
|
|
@@ -14221,11 +14429,16 @@ export {
|
|
|
14221
14429
|
reportDiagnostics,
|
|
14222
14430
|
liveSlots,
|
|
14223
14431
|
reduceRun,
|
|
14432
|
+
failureSays,
|
|
14224
14433
|
settleRun,
|
|
14225
14434
|
reducePreview,
|
|
14226
14435
|
reduceReport,
|
|
14227
14436
|
reduceFollow,
|
|
14228
14437
|
createResultStore,
|
|
14438
|
+
defineCommand,
|
|
14439
|
+
MODULE_COMMAND_ACTIONS,
|
|
14440
|
+
CORE_COMMAND_ACTIONS,
|
|
14441
|
+
isPlainObject,
|
|
14229
14442
|
createActionRunner,
|
|
14230
14443
|
connectCaller,
|
|
14231
14444
|
bridgeCaller,
|
|
@@ -14234,4 +14447,4 @@ export {
|
|
|
14234
14447
|
AutosaveEndedError,
|
|
14235
14448
|
autosave
|
|
14236
14449
|
};
|
|
14237
|
-
//# sourceMappingURL=chunk-
|
|
14450
|
+
//# sourceMappingURL=chunk-F3X6TTZ6.mjs.map
|