@xenosystem/blocks 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ops/index.js CHANGED
@@ -4004,6 +4004,495 @@ var diffPanel = createDiffPanel();
4004
4004
 
4005
4005
  // src/ops/diff/index.ts
4006
4006
  var DIFF_RUNTIME_UNITS = [];
4007
+
4008
+ // src/ops/gates/panel.ts
4009
+ import { createElement as createElement5 } from "react";
4010
+ import { createRoot as createRoot5 } from "react-dom/client";
4011
+
4012
+ // src/ops/gates/types.ts
4013
+ function isStageGate(value) {
4014
+ if (!value || typeof value !== "object") return false;
4015
+ const g = value;
4016
+ return typeof g.id === "string" && g.id.length > 0 && typeof g.runId === "string" && typeof g.stageCode === "string" && typeof g.stageName === "string" && typeof g.title === "string" && (g.state === "open" || g.state === "approved" || g.state === "rejected" || g.state === "superseded");
4017
+ }
4018
+
4019
+ // src/ops/gates/controller.ts
4020
+ var VALID_FILTERS = /* @__PURE__ */ new Set(["all", "open", "approved", "rejected", "superseded"]);
4021
+ function filterGates(gates, state, search) {
4022
+ const q = search.trim().toLowerCase();
4023
+ return gates.filter((g) => {
4024
+ if (state !== "all" && g.state !== state) return false;
4025
+ if (!q) return true;
4026
+ return [g.id, g.runId, g.stageCode, g.stageName, g.title, g.brand ?? "", g.note ?? ""].join(" ").toLowerCase().includes(q);
4027
+ });
4028
+ }
4029
+ var GateReviewController = class {
4030
+ host;
4031
+ listeners = /* @__PURE__ */ new Set();
4032
+ state = {
4033
+ gates: [],
4034
+ visible: [],
4035
+ filterState: "open",
4036
+ search: "",
4037
+ selectedId: null,
4038
+ noteDraft: "",
4039
+ validationError: null
4040
+ };
4041
+ constructor(options = {}) {
4042
+ this.host = options.host;
4043
+ }
4044
+ subscribe = (listener) => {
4045
+ this.listeners.add(listener);
4046
+ return () => {
4047
+ this.listeners.delete(listener);
4048
+ };
4049
+ };
4050
+ getState = () => this.state;
4051
+ commit(patch) {
4052
+ const gates = patch.gates ?? this.state.gates;
4053
+ const filterState = patch.filterState ?? this.state.filterState;
4054
+ const search = patch.search ?? this.state.search;
4055
+ const visible2 = filterGates(gates, filterState, search);
4056
+ let selectedId = patch.selectedId !== void 0 ? patch.selectedId : this.state.selectedId;
4057
+ if (selectedId && !gates.some((g) => g.id === selectedId)) selectedId = null;
4058
+ if (!selectedId && visible2.length > 0) selectedId = visible2[0].id;
4059
+ this.state = {
4060
+ ...this.state,
4061
+ ...patch,
4062
+ gates,
4063
+ filterState,
4064
+ search,
4065
+ visible: visible2,
4066
+ selectedId
4067
+ };
4068
+ for (const fn of this.listeners) fn();
4069
+ }
4070
+ setGates(raw) {
4071
+ if (!Array.isArray(raw)) return;
4072
+ const valid = raw.filter(isStageGate);
4073
+ this.commit({ gates: valid, validationError: null });
4074
+ }
4075
+ setFilter(input) {
4076
+ const nextFilterState = typeof input.state === "string" && VALID_FILTERS.has(input.state) ? input.state : void 0;
4077
+ const nextSearch = typeof input.search === "string" ? input.search : void 0;
4078
+ this.commit({
4079
+ ...nextFilterState !== void 0 ? { filterState: nextFilterState } : {},
4080
+ ...nextSearch !== void 0 ? { search: nextSearch } : {}
4081
+ });
4082
+ }
4083
+ select(gateId) {
4084
+ const gate = gateId ? this.state.gates.find((g) => g.id === gateId) ?? null : null;
4085
+ this.commit({ selectedId: gate?.id ?? null, noteDraft: "", validationError: null });
4086
+ if (gate) this.host?.emit("selection", { gateId: gate.id, runId: gate.runId });
4087
+ }
4088
+ setNoteDraft(note) {
4089
+ this.commit({ noteDraft: note, validationError: null });
4090
+ }
4091
+ /**
4092
+ * Emit an approval or rejection intent for the selected (or named) open gate.
4093
+ * Rejections MUST include a non-empty reason; returns `{ ok: false, error }` otherwise.
4094
+ */
4095
+ decide(decision, gateId, noteOverride) {
4096
+ const id = gateId ?? this.state.selectedId;
4097
+ const gate = id ? this.state.gates.find((g) => g.id === id) : void 0;
4098
+ if (!gate) {
4099
+ const error = "No gate selected.";
4100
+ this.commit({ validationError: error });
4101
+ return { ok: false, error };
4102
+ }
4103
+ if (gate.state !== "open") {
4104
+ const error = `Gate ${gate.id} is ${gate.state}, not open.`;
4105
+ this.commit({ validationError: error });
4106
+ return { ok: false, error };
4107
+ }
4108
+ const note = (noteOverride ?? this.state.noteDraft).trim();
4109
+ if (decision === "reject" && note.length === 0) {
4110
+ const error = "A reason is required to reject and requeue a stage gate.";
4111
+ this.commit({ validationError: error });
4112
+ return { ok: false, error };
4113
+ }
4114
+ const intent = {
4115
+ gateId: gate.id,
4116
+ runId: gate.runId,
4117
+ decision,
4118
+ note
4119
+ };
4120
+ this.commit({ noteDraft: "", validationError: null });
4121
+ this.host?.emit("decision", intent);
4122
+ return { ok: true, intent };
4123
+ }
4124
+ getSummary() {
4125
+ const counts = { open: 0, approved: 0, rejected: 0, superseded: 0 };
4126
+ for (const g of this.state.gates) counts[g.state] += 1;
4127
+ return { ...counts, total: this.state.gates.length, selectedId: this.state.selectedId };
4128
+ }
4129
+ };
4130
+
4131
+ // src/ops/gates/manifest.ts
4132
+ var GATE_REVIEW_PANEL_ID = "xeno.core.gates";
4133
+ var gateReviewManifest = {
4134
+ id: GATE_REVIEW_PANEL_ID,
4135
+ version: "0.1.0",
4136
+ title: "Stage Gates",
4137
+ icon: "shield-check",
4138
+ description: "Human approval queue for pipeline stages. Rejections require a written reason; decisions emit intents to the host.",
4139
+ defaultSlot: "right",
4140
+ inputs: [
4141
+ {
4142
+ id: "gates",
4143
+ name: "Gates",
4144
+ type: "array",
4145
+ description: "Array of XenoStageGate records waiting for or finished with human review.",
4146
+ multiple: false
4147
+ },
4148
+ {
4149
+ id: "filter",
4150
+ name: "Filter",
4151
+ type: "object",
4152
+ description: "Optional external filter { state?: all|open|approved|rejected|superseded, search?: string }.",
4153
+ multiple: false
4154
+ }
4155
+ ],
4156
+ outputs: [
4157
+ {
4158
+ id: "decision",
4159
+ name: "Decision",
4160
+ type: "object",
4161
+ description: "{ gateId, runId, decision: approve|reject, note } \u2014 pure intent. Rejecting requires a non-empty reason."
4162
+ },
4163
+ {
4164
+ id: "selection",
4165
+ name: "Selected Gate",
4166
+ type: "object",
4167
+ description: "{ gateId, runId } \u2014 emitted when the operator selects a gate to inspect."
4168
+ }
4169
+ ],
4170
+ commands: [
4171
+ {
4172
+ id: "get_summary",
4173
+ title: "Get Gate Summary",
4174
+ description: "Return counts by state (open, approved, rejected, superseded) and selected gate id.",
4175
+ parameters: {}
4176
+ },
4177
+ {
4178
+ id: "select_gate",
4179
+ title: "Select Gate",
4180
+ description: "Select a gate by id.",
4181
+ parameters: { gateId: { type: "string", description: "Gate id or empty to clear" } }
4182
+ },
4183
+ {
4184
+ id: "set_filter",
4185
+ title: "Set Filter",
4186
+ description: "Filter gates by state or search text.",
4187
+ parameters: {
4188
+ state: { type: "string", description: "all|open|approved|rejected|superseded" },
4189
+ search: { type: "string", description: "Case-insensitive substring match" }
4190
+ }
4191
+ }
4192
+ ],
4193
+ capabilities: [],
4194
+ config: [],
4195
+ sdk: "^1.0.0"
4196
+ };
4197
+
4198
+ // src/ops/gates/react/GateReviewPanelView.tsx
4199
+ import { useSyncExternalStore as useSyncExternalStore5 } from "react";
4200
+ import {
4201
+ Badge as Badge5,
4202
+ Column as Column5,
4203
+ EmptyState as EmptyState5,
4204
+ Note as Note3,
4205
+ ReadoutRow,
4206
+ Row as Row3,
4207
+ RowList as RowList3,
4208
+ ScrollArea as ScrollArea4,
4209
+ SearchField as SearchField4,
4210
+ SegmentedControl as SegmentedControl3,
4211
+ Stack as Stack3,
4212
+ StatusBadge,
4213
+ StatusBar as StatusBar5,
4214
+ Text as Text4,
4215
+ TextArea,
4216
+ TextButton as TextButton4,
4217
+ Toolbar as Toolbar5
4218
+ } from "@xenosystem/components/chrome";
4219
+
4220
+ // src/ops/gates/declaration.ts
4221
+ function gateReviewViewState(c) {
4222
+ const s = c.getState();
4223
+ const openCount = s.gates.filter((g) => g.state === "open").length;
4224
+ const selected = s.selectedId ? s.gates.find((g) => g.id === s.selectedId) ?? null : null;
4225
+ return {
4226
+ empty: s.visible.length === 0,
4227
+ filterState: s.filterState,
4228
+ search: s.search,
4229
+ visible: s.visible,
4230
+ selected,
4231
+ noteDraft: s.noteDraft,
4232
+ validationError: s.validationError,
4233
+ statusLabel: `${openCount} open \xB7 ${s.gates.length} total gates`
4234
+ };
4235
+ }
4236
+ function applyGateReviewUi(c, intent) {
4237
+ switch (intent.kind) {
4238
+ case "filterState":
4239
+ c.setFilter({ state: intent.state });
4240
+ break;
4241
+ case "search":
4242
+ c.setFilter({ search: intent.search });
4243
+ break;
4244
+ case "select":
4245
+ c.select(intent.gateId);
4246
+ break;
4247
+ case "note":
4248
+ c.setNoteDraft(intent.note);
4249
+ break;
4250
+ case "approve":
4251
+ c.decide("approve");
4252
+ break;
4253
+ case "reject":
4254
+ c.decide("reject");
4255
+ break;
4256
+ }
4257
+ }
4258
+ var gateReviewViewManifest = {
4259
+ ...gateReviewManifest,
4260
+ capabilities: [],
4261
+ inputs: [{ id: "view", name: "View state", type: "object", description: "GateReviewViewModel from the controller." }],
4262
+ outputs: [{ id: "ui", name: "UI intent", type: "object", description: "GateReviewUiIntent applied to the controller." }],
4263
+ commands: []
4264
+ };
4265
+ var EMPTY6 = {
4266
+ empty: true,
4267
+ filterState: "open",
4268
+ search: "",
4269
+ visible: [],
4270
+ selected: null,
4271
+ noteDraft: "",
4272
+ validationError: null,
4273
+ statusLabel: "0 open \xB7 0 total gates"
4274
+ };
4275
+ var GATE_REVIEW_BEHAVIOURS = {
4276
+ "ops/gateReviewPanelView": (inputs) => inputs.view ?? EMPTY6
4277
+ };
4278
+ var GATE_REVIEW_RUNTIME_UNITS = [];
4279
+ var GATE_REVIEW_DECLARATION = {
4280
+ format: "xeno.block@1",
4281
+ manifest: gateReviewViewManifest,
4282
+ behaviour: "ops/gateReviewPanelView",
4283
+ composition: {
4284
+ component: "chrome/Column",
4285
+ children: [
4286
+ {
4287
+ component: "chrome/Toolbar",
4288
+ props: {
4289
+ left: {
4290
+ node: {
4291
+ component: "chrome/SegmentedControl",
4292
+ props: {
4293
+ size: { value: "sm" },
4294
+ label: { value: "Gate state" },
4295
+ value: { input: "view.filterState" },
4296
+ options: {
4297
+ value: [
4298
+ { value: "open", label: "Open" },
4299
+ { value: "approved", label: "Approved" },
4300
+ { value: "rejected", label: "Rejected" },
4301
+ { value: "all", label: "All" }
4302
+ ]
4303
+ }
4304
+ },
4305
+ on: {
4306
+ onChange: { emit: "ui", value: { object: { kind: { value: "filterState" }, state: { arg: "" } } } }
4307
+ }
4308
+ }
4309
+ },
4310
+ right: {
4311
+ node: {
4312
+ component: "chrome/SearchField",
4313
+ props: {
4314
+ value: { input: "view.search" },
4315
+ placeholder: { value: "Filter gates\u2026" },
4316
+ label: { value: "Filter gates" }
4317
+ },
4318
+ on: {
4319
+ onChange: { emit: "ui", value: { object: { kind: { value: "search" }, search: { arg: "" } } } }
4320
+ }
4321
+ }
4322
+ }
4323
+ }
4324
+ },
4325
+ {
4326
+ component: "chrome/EmptyState",
4327
+ when: { input: "view.empty" },
4328
+ props: {
4329
+ title: { value: "No stage gates" },
4330
+ hint: { value: "Pending human approvals appear here when a run reaches a gate." }
4331
+ }
4332
+ },
4333
+ {
4334
+ component: "chrome/StatusBar",
4335
+ props: {
4336
+ left: {
4337
+ node: {
4338
+ component: "chrome/Text",
4339
+ props: { role: { value: "number" } },
4340
+ children: [{ component: "text", props: { text: { input: "view.statusLabel" } } }]
4341
+ }
4342
+ }
4343
+ }
4344
+ }
4345
+ ]
4346
+ }
4347
+ };
4348
+
4349
+ // src/ops/gates/react/GateReviewPanelView.tsx
4350
+ import { Fragment as Fragment5, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
4351
+ var STATE_OPTIONS = [
4352
+ { value: "open", label: "Open" },
4353
+ { value: "approved", label: "Approved" },
4354
+ { value: "rejected", label: "Rejected" },
4355
+ { value: "all", label: "All" }
4356
+ ];
4357
+ var toneOf2 = (state) => {
4358
+ switch (state) {
4359
+ case "approved":
4360
+ return "success";
4361
+ case "rejected":
4362
+ return "error";
4363
+ case "open":
4364
+ return "warning";
4365
+ case "superseded":
4366
+ return "neutral";
4367
+ }
4368
+ };
4369
+ function GateReviewPanelView({ controller }) {
4370
+ useSyncExternalStore5(controller.subscribe, controller.getState, controller.getState);
4371
+ const view = gateReviewViewState(controller);
4372
+ const ui5 = (intent) => applyGateReviewUi(controller, intent);
4373
+ return /* @__PURE__ */ jsxs5(Column5, { children: [
4374
+ /* @__PURE__ */ jsx5(
4375
+ Toolbar5,
4376
+ {
4377
+ left: /* @__PURE__ */ jsx5(
4378
+ SegmentedControl3,
4379
+ {
4380
+ size: "sm",
4381
+ label: "Gate state",
4382
+ options: STATE_OPTIONS,
4383
+ value: view.filterState,
4384
+ onChange: (value) => ui5({ kind: "filterState", state: value })
4385
+ }
4386
+ ),
4387
+ right: /* @__PURE__ */ jsx5(
4388
+ SearchField4,
4389
+ {
4390
+ value: view.search,
4391
+ placeholder: "Filter gates\u2026",
4392
+ label: "Filter gates",
4393
+ onChange: (search) => ui5({ kind: "search", search })
4394
+ }
4395
+ )
4396
+ }
4397
+ ),
4398
+ view.empty ? /* @__PURE__ */ jsx5(
4399
+ EmptyState5,
4400
+ {
4401
+ title: "No stage gates",
4402
+ hint: "Pending human approvals appear here when a run reaches a gate."
4403
+ }
4404
+ ) : /* @__PURE__ */ jsxs5(ScrollArea4, { children: [
4405
+ /* @__PURE__ */ jsx5(RowList3, { role: "listbox", "aria-label": "Stage gates", divided: true, children: view.visible.map((gate) => /* @__PURE__ */ jsx5(
4406
+ Row3,
4407
+ {
4408
+ noIcon: true,
4409
+ selected: view.selected?.id === gate.id,
4410
+ label: gate.title,
4411
+ meta: `${gate.stageCode} \xB7 ${gate.stageName}`,
4412
+ trailing: /* @__PURE__ */ jsx5(StatusBadge, { tone: toneOf2(gate.state), children: gate.state }),
4413
+ onClick: () => ui5({ kind: "select", gateId: gate.id })
4414
+ },
4415
+ gate.id
4416
+ )) }),
4417
+ view.selected ? /* @__PURE__ */ jsxs5(Stack3, { gap: 6, pad: "inset", children: [
4418
+ /* @__PURE__ */ jsx5(ReadoutRow, { label: "Run", value: view.selected.runId, mono: true }),
4419
+ /* @__PURE__ */ jsx5(ReadoutRow, { label: "Stage", value: `${view.selected.stageCode} \xB7 ${view.selected.stageName}` }),
4420
+ view.selected.verdict ? /* @__PURE__ */ jsx5(ReadoutRow, { label: "Verdict", value: /* @__PURE__ */ jsx5(Badge5, { children: view.selected.verdict }) }) : null,
4421
+ view.selected.state === "open" ? /* @__PURE__ */ jsxs5(Fragment5, { children: [
4422
+ /* @__PURE__ */ jsx5(
4423
+ TextArea,
4424
+ {
4425
+ label: "Review reason",
4426
+ placeholder: "Optional note for approval; required reason to reject and requeue\u2026",
4427
+ value: view.noteDraft,
4428
+ onChange: (note) => ui5({ kind: "note", note })
4429
+ }
4430
+ ),
4431
+ view.validationError ? /* @__PURE__ */ jsx5(Note3, { variant: "inset", children: view.validationError }) : null,
4432
+ /* @__PURE__ */ jsxs5(Stack3, { direction: "row", gap: 6, pad: "none", children: [
4433
+ /* @__PURE__ */ jsx5(TextButton4, { onClick: () => ui5({ kind: "approve" }), children: "Approve gate" }),
4434
+ /* @__PURE__ */ jsx5(TextButton4, { onClick: () => ui5({ kind: "reject" }), children: "Reject & requeue" })
4435
+ ] })
4436
+ ] }) : view.selected.note ? /* @__PURE__ */ jsx5(ReadoutRow, { label: "Decision note", value: view.selected.note }) : null
4437
+ ] }) : null
4438
+ ] }),
4439
+ /* @__PURE__ */ jsx5(StatusBar5, { left: /* @__PURE__ */ jsx5(Text4, { role: "number", children: view.statusLabel }) })
4440
+ ] });
4441
+ }
4442
+
4443
+ // src/ops/gates/panel.ts
4444
+ function createGateReviewPanel(options = {}) {
4445
+ return {
4446
+ manifest: gateReviewManifest,
4447
+ activate(host) {
4448
+ const controller = new GateReviewController({
4449
+ host: { emit: (portId, value) => host.emit(portId, value) }
4450
+ });
4451
+ let root = null;
4452
+ let unrender = null;
4453
+ return {
4454
+ render(el) {
4455
+ unrender?.();
4456
+ if (options.render) {
4457
+ unrender = options.render(el, controller);
4458
+ return;
4459
+ }
4460
+ root = createRoot5(el);
4461
+ root.render(createElement5(GateReviewPanelView, { controller }));
4462
+ unrender = () => {
4463
+ root?.unmount();
4464
+ root = null;
4465
+ };
4466
+ },
4467
+ onInput(portId, value) {
4468
+ if (portId === "gates") controller.setGates(value);
4469
+ else if (portId === "filter" && value && typeof value === "object") {
4470
+ controller.setFilter(value);
4471
+ }
4472
+ },
4473
+ async onCommand(commandId, params) {
4474
+ switch (commandId) {
4475
+ case "get_summary":
4476
+ return controller.getSummary();
4477
+ case "select_gate":
4478
+ controller.select(typeof params.gateId === "string" && params.gateId ? params.gateId : null);
4479
+ return true;
4480
+ case "set_filter":
4481
+ controller.setFilter({ state: params.state, search: params.search });
4482
+ return true;
4483
+ default:
4484
+ return null;
4485
+ }
4486
+ },
4487
+ dispose() {
4488
+ unrender?.();
4489
+ unrender = null;
4490
+ }
4491
+ };
4492
+ }
4493
+ };
4494
+ }
4495
+ var gateReviewPanel = createGateReviewPanel();
4007
4496
  export {
4008
4497
  ALL_STATUSES,
4009
4498
  BEHAVIOURS as CONSOLE_BEHAVIOURS,
@@ -4020,6 +4509,12 @@ export {
4020
4509
  DIFF_RUNTIME_UNITS,
4021
4510
  DiffController,
4022
4511
  DiffPanelView,
4512
+ GATE_REVIEW_BEHAVIOURS,
4513
+ GATE_REVIEW_DECLARATION,
4514
+ GATE_REVIEW_PANEL_ID,
4515
+ GATE_REVIEW_RUNTIME_UNITS,
4516
+ GateReviewController,
4517
+ GateReviewPanelView,
4023
4518
  LEVEL_ORDER,
4024
4519
  MESSAGE_ELISION,
4025
4520
  REDACTION_CARRY,
@@ -4043,6 +4538,7 @@ export {
4043
4538
  appendStepsAtPath,
4044
4539
  applyConsoleUi,
4045
4540
  applyDiffUi,
4541
+ applyGateReviewUi,
4046
4542
  applyRunsUi,
4047
4543
  applyTerminalUi,
4048
4544
  canCancel,
@@ -4057,6 +4553,7 @@ export {
4057
4553
  countChanges,
4058
4554
  createConsolePanel,
4059
4555
  createDiffPanel,
4556
+ createGateReviewPanel,
4060
4557
  createRunsPanel,
4061
4558
  createTerminalPanel,
4062
4559
  decodeRunPath,
@@ -4070,9 +4567,14 @@ export {
4070
4567
  flattenRunRows,
4071
4568
  formatDuration,
4072
4569
  formatRecord,
4570
+ gateReviewManifest,
4571
+ gateReviewPanel,
4572
+ gateReviewViewManifest,
4573
+ gateReviewViewState,
4073
4574
  isActive,
4074
4575
  isLive,
4075
4576
  isSettled,
4577
+ isStageGate,
4076
4578
  isTerminal,
4077
4579
  isWaiting,
4078
4580
  lifecycleOf,