@checkstack/automation-frontend 0.2.0 → 0.3.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/CHANGELOG.md +352 -0
- package/package.json +13 -9
- package/src/components/AutomationGroupCombobox.tsx +133 -0
- package/src/editor/ActionEditor.tsx +180 -90
- package/src/editor/ActionListEditor.tsx +27 -1
- package/src/editor/AddActionDialog.tsx +15 -45
- package/src/editor/AddConditionDialog.tsx +86 -0
- package/src/editor/AddTriggerDialog.tsx +97 -0
- package/src/editor/AutomationDefinitionEditor.tsx +41 -2
- package/src/editor/ConditionEditor.tsx +359 -70
- package/src/editor/ConditionsEditor.tsx +113 -44
- package/src/editor/ItemSheet.tsx +51 -0
- package/src/editor/RunReplayPicker.tsx +97 -0
- package/src/editor/ScriptServicesBooter.tsx +53 -0
- package/src/editor/ScriptTestRenderer.tsx +150 -0
- package/src/editor/SystemEntityPicker.test.ts +37 -0
- package/src/editor/SystemEntityPicker.tsx +109 -0
- package/src/editor/TriggersEditor.tsx +345 -137
- package/src/editor/action-helpers.test.ts +107 -0
- package/src/editor/action-helpers.ts +72 -0
- package/src/editor/action-leaf-cards.tsx +98 -1
- package/src/editor/condition-kind.test.ts +126 -0
- package/src/editor/condition-kind.ts +130 -0
- package/src/editor/item-summary.test.ts +171 -0
- package/src/editor/item-summary.ts +210 -0
- package/src/editor/picker-dialog.tsx +156 -0
- package/src/editor/registry-context.tsx +9 -2
- package/src/editor/script-actions.test.ts +184 -0
- package/src/editor/script-actions.ts +146 -0
- package/src/editor/system-entity-picker.logic.ts +23 -0
- package/src/editor/template-completion.test.ts +22 -3
- package/src/editor/template-completion.ts +16 -8
- package/src/editor/template-helpers.ts +4 -0
- package/src/editor/trigger-helpers.test.ts +28 -0
- package/src/editor/trigger-helpers.ts +17 -0
- package/src/editor/useScriptDiagnostics.ts +108 -0
- package/src/index.tsx +2 -0
- package/src/pages/AutomationEditPage.tsx +95 -47
- package/src/pages/AutomationListPage.tsx +172 -123
- package/src/pages/automation-grouping.test.ts +86 -0
- package/src/pages/automation-grouping.ts +65 -0
- package/src/script-context.test.ts +142 -1
- package/src/script-context.ts +115 -0
- package/tsconfig.json +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,357 @@
|
|
|
1
1
|
# @checkstack/automation-frontend
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b995afb: Redesign the automation visual editor to a Home-Assistant-style collapsed-card UX.
|
|
8
|
+
|
|
9
|
+
Every item in all three sections (actions, triggers, conditions) now renders as a compact summary row by default - icon, title, and a one-line summary derived from its config. Clicking the row opens the item's full configuration in a right-side sheet that edits the same live definition (no draft/commit step), so closing the sheet keeps the changes. The saved `definition` is unchanged - only the editor presentation - so the visual and YAML views still round-trip losslessly.
|
|
10
|
+
|
|
11
|
+
- `@checkstack/ui` `ActionCard` gains three optional, backward-compatible props: `onOpenSheet` (turns the card into a non-expanding summary row that opens a host-supplied sheet on header click), `summary` (the compact one-line hint shown under the title), and `actions` (a typed `ActionCardMenuItem[]` rendered as a three-dot overflow menu). The new `ActionCardMenuItem` type is exported. Existing inline-expand usages are unaffected when the new props are omitted.
|
|
12
|
+
- Per-card commands move into the overflow menu: Disable/Enable, a new Duplicate, and Delete. The drag grip stays on the action card header; actions keep dnd-kit reordering and the parallel id array. Triggers and conditions remain non-reorderable.
|
|
13
|
+
- Duplicate clones an item with fresh, unique ids (via the existing id helpers) and inserts it directly after the original, keeping the editor's parallel id array in sync.
|
|
14
|
+
- Composite actions (choose / parallel / repeat / sequence) keep nesting: a child card inside a parent's sheet opens its OWN sheet, stacking via Radix Dialog's portal + overlay.
|
|
15
|
+
- Cards with validation errors auto-open their sheet and show an error badge on the collapsed row, so problems are never hidden behind a collapsed row plus a closed sheet.
|
|
16
|
+
|
|
17
|
+
- b995afb: Show auto-generated trigger ids in the automation editor without clicking the field.
|
|
18
|
+
|
|
19
|
+
Previously, loading a stored definition (a seeded default, a GitOps-managed automation, or hand-written YAML) whose triggers carried no `id` left the Id field blank until the operator focused and blurred it. The editor now materializes the derived id eagerly on load - the same way the starter automation and "Add step" path already do - so the id is shown (and referenceable as `trigger.id`) immediately. The runtime already derived these ids, so saved definitions are unchanged.
|
|
20
|
+
|
|
21
|
+
The auto-incident migration also now writes explicit trigger ids (matching `deriveTriggerId(event)`) into the seeded sustained and flapping automations, so newly seeded defaults carry the same id the editor shows.
|
|
22
|
+
|
|
23
|
+
- 270ef29: Add progressive disclosure and a live system picker to the automation visual editor.
|
|
24
|
+
|
|
25
|
+
The saved `definition` is unchanged - only the editor layout - so the visual and YAML views still round-trip losslessly.
|
|
26
|
+
|
|
27
|
+
- Triggers: the event picker and trigger config stay prominent; the optional `id`, gating `filter`, and `for:` dwell move into a per-trigger "Advanced" disclosure that auto-opens when a filter or dwell is set.
|
|
28
|
+
- Actions: per-action metadata (`id`, `description`, `continue_on_error`) moves into an "Advanced" disclosure inside the action card so the action's own configuration leads. Enable/disable stays on the card header.
|
|
29
|
+
- Conditions: the kind selector is grouped so the structured kinds (`numeric_state` / `time` / `state`) lead, the logical combinators follow, and the raw-expression escape hatch is de-emphasised under "Advanced" - all kinds stay reachable.
|
|
30
|
+
- The `state` condition's `entity` is now a live system picker backed by the catalog `getSystems` RPC, with a manual-entry fallback so an id not in the catalog (or a `{{ template }}`) still round-trips losslessly.
|
|
31
|
+
|
|
32
|
+
- b995afb: Add grouping to automations so they are easier to find.
|
|
33
|
+
|
|
34
|
+
Each automation now carries an optional single free-text `group` label (HA-style "category"), stored as its own column on the `automations` row alongside `name` / `description` / `status` - it is NOT part of the definition / YAML. The automations list renders one collapsible section per group (sorted alphabetically, with an implicit "Ungrouped" bucket last), and the edit page gains a type-new-or-pick-existing group picker fed by the new `listAutomationGroups` query. `listAutomations` accepts an optional `group` filter.
|
|
35
|
+
|
|
36
|
+
Declaratively managed automations express their group via GitOps `metadata.labels.group`; the reconciler threads it onto the row (blank clears it).
|
|
37
|
+
|
|
38
|
+
A Drizzle migration adds the nullable `"group"` column and an index. Existing automations default to no group (Ungrouped) and behave exactly as before.
|
|
39
|
+
|
|
40
|
+
- 270ef29: Add live state in scope plus duration helpers to the automation sensing layer (Wave 2 Phase 14).
|
|
41
|
+
|
|
42
|
+
- `@checkstack/template-engine` ships four pure, synchronous duration filters: `minutes` and `hours` (number to milliseconds), `duration_since` (ms elapsed since an ISO timestamp), and `older_than(thresholdMs)` (boolean dwell check). They compute against real time at call time, so "now" is fresh per evaluation. Fail-safe on null/unparseable input.
|
|
43
|
+
- The dispatch engine pre-resolves live health state into scope before any condition or template evaluation (the engine is synchronous, so inline state queries are impossible). State is folded under a `health` namespace - `health.system.*` for the trigger's context system and `health.systems[<id>]` for ids listed in the automation's new `uses_state` field. One batched `getBulkHealthState` query per evaluation, wired at the fresh-run, resume, and trigger-gate sites. Fail-open: a missing client or provider error yields an empty namespace and a warning, never wedging unrelated automations.
|
|
44
|
+
- New `automationFilterExtensionPoint` lets plugins contribute pure template filters without forking the engine's default registry. Name collisions with built-ins are skipped with a warning.
|
|
45
|
+
- The editor variable-scope resolver and autocomplete catalogue now surface the `health.*` namespace and the new duration filters.
|
|
46
|
+
|
|
47
|
+
With this phase alone, an operator can build "notify me when a system has been unhealthy for 30 minutes" using an interval trigger plus a single `health.*` condition - no dwell timer required (the precise event-driven path lands in Phase 15).
|
|
48
|
+
|
|
49
|
+
- 270ef29: Add the `wait_until` action primitive (Wave 2 Phase 17) - suspend a running automation until a condition becomes true, with an optional timeout (HA's `wait_template`).
|
|
50
|
+
|
|
51
|
+
- New `wait_until: { condition, timeout_seconds?, continue_on_timeout? }` primitive. `continue_on_timeout` defaults to true (HA semantics). Added to the schema, the action union, and `detectActionKind`. (The wait is fully reactive - see the reactive-dispatch-pipeline changeset; there is no `poll_seconds`.)
|
|
52
|
+
- `condition` accepts any condition shape - a template string or the Phase 16 structured `numeric_state` / `time` / `state` variants.
|
|
53
|
+
- Reactive resume: if the condition is already true it continues inline; otherwise it persists a `kind: "until"` wait lock (carrying the condition + timeout policy in a new `wait_config` jsonb column). The reactive-dispatch-pipeline changeset replaces the original poll-based re-check with a wake-index + a single timeout timer, so the wait is woken by a relevant entity change rather than ticked on an interval. Resumes take the per-run advisory lock so a wake and a sweep can't double-resume.
|
|
54
|
+
- Survives restart: the wait lock is the source of truth, and the stalled sweeper applies the timeout policy as a backstop if the wake/timer signal is lost.
|
|
55
|
+
- Works nested inside `choose` / `parallel` / `repeat` via the existing resume-remainder mechanism.
|
|
56
|
+
- Editor: a `wait_until` action card (frontend) mirroring `wait_for_trigger` - a `ConditionEditor` plus timeout and continue-on-timeout inputs. The structured numeric/time/state ConditionEditor branches land with the rest of the sensing-layer editor work; the card uses the expression-based editor for now.
|
|
57
|
+
|
|
58
|
+
- 270ef29: Add the sensing-layer editor UX (Wave 2 Phase 19) - the visual widgets for the duration-aware and structured-condition building blocks from Phases 15-18.
|
|
59
|
+
|
|
60
|
+
- New `@checkstack/ui` components (each with a Storybook story):
|
|
61
|
+
- `DurationInput` - number + unit (`seconds` / `minutes` / `hours`) picker emitting the single-unit `Duration` object the backend accepts, so it round-trips losslessly through YAML.
|
|
62
|
+
- `TimeOfDayInput` - HH:MM (24h) input emitting the `"HH:mm"` string the `time` condition's `after` / `before` accept. Both are plain inputs (no animations), so no `usePerformance` gating is needed.
|
|
63
|
+
- `DynamicForm`'s `FormField` gains an additive `x-duration` / `format: "duration"` branch that renders `DurationInput` for schema-driven duration configs. (Additive alongside the existing dispatch; reconciles cleanly with the parallel branch's `FormField` edits.)
|
|
64
|
+
- The `ConditionEditor` kind selector gains `numeric_state` / `time` / `state` structured branches: an operator dropdown (above / below / between) + threshold for numeric, `TimeOfDayInput` + weekday toggles + timezone for time, and a status dropdown + optional `DurationInput` dwell for state. The raw-expression escape hatch is kept. Pure `kindOf` / `defaultForKind` helpers are split into a UI-free `condition-kind` module so they unit-test under bun (the UI barrel drags Monaco).
|
|
65
|
+
- The trigger card gains a `for:` dwell toggle + `DurationInput` (Phase 15's schema was already round-tripping in YAML).
|
|
66
|
+
|
|
67
|
+
Visual and YAML views stay lossless; structured conditions authored in either are editable in the other.
|
|
68
|
+
|
|
69
|
+
- 270ef29: Add the GitOps `Automation` entity kind (Wave 2 Phase 21).
|
|
70
|
+
|
|
71
|
+
- `automation-backend` registers an `Automation` kind with the GitOps entity-kind registry (`specSchema: AutomationDefinitionSchema`). Reconcile upserts by name (identity tracked via the returned entity id + provenance); reconciled rows are tagged `managed_by = "gitops"`. Delete is guarded to GitOps-managed rows. An automation's full definition - triggers (with `for:` dwells), structured conditions, the action catalog, mode, `concurrency_scope`, `uses_state`, `state_window_minutes` - can now be declared in Git.
|
|
72
|
+
- `automation-frontend`: the editor reads the GitOps provenance lock (`useProvenanceLock({ kind: "Automation", entityId })`) and, when locked, disables Save / Run-now / Delete and the form fields and shows a `GitOpsLockBanner`.
|
|
73
|
+
- Documented the `Automation` YAML format under the GitOps kinds reference, plus new automation platform overview + plugin-author ("extending") developer-guide pages.
|
|
74
|
+
|
|
75
|
+
- b995afb: Surface inline-script type errors as automation action badges.
|
|
76
|
+
|
|
77
|
+
Every inline `run_script` action in the automation editor is now type-checked
|
|
78
|
+
against its generated `context` types continuously - including actions whose
|
|
79
|
+
cards are collapsed - and any errors show up as the action card's error badge
|
|
80
|
+
(and in the definition issue list), the same surface structural validation
|
|
81
|
+
uses. Previously a type error was only visible as a red squiggle inside the
|
|
82
|
+
open Monaco editor, so a broken script behind a collapsed card (or one
|
|
83
|
+
invalidated by adding a new trigger) went unnoticed until runtime, where the
|
|
84
|
+
bad property access silently read `undefined`.
|
|
85
|
+
|
|
86
|
+
Validation runs entirely in the browser via the same standalone TypeScript
|
|
87
|
+
worker the editor uses (new `validateTypeScriptSources` export on
|
|
88
|
+
`@checkstack/ui`), so there is no backend round-trip. Each script is checked by
|
|
89
|
+
prepending its generated `context.d.ts` to the source, which keeps the
|
|
90
|
+
`context` global scoped to that one off-screen file and avoids colliding with
|
|
91
|
+
any open editor. When an automation already contains scripts, a hidden editor
|
|
92
|
+
boots the shared editor services on open so validation runs immediately rather
|
|
93
|
+
than only after the first script card is expanded.
|
|
94
|
+
|
|
95
|
+
This covers the automation currently open in the editor. Scripts in other
|
|
96
|
+
automations, or definitions authored via YAML/API, are not type-checked here -
|
|
97
|
+
that platform-wide coverage remains future work for a backend typecheck.
|
|
98
|
+
|
|
99
|
+
Also: action cards no longer auto-open their detail sheet when they have
|
|
100
|
+
validation issues; issues now surface only as the card badge, so multiple
|
|
101
|
+
flagged actions no longer pop several sheets open at once.
|
|
102
|
+
|
|
103
|
+
- b995afb: Improve the automation Run Script secret → env mapping editor and script IntelliSense.
|
|
104
|
+
|
|
105
|
+
- **Searchable secret picker with existence validation.** The secret → env mapping editor (`SecretEnvEditor`) now uses a searchable, keyboard-navigable combobox (modeled on `VariablePicker` / `PackageNameCombobox`, `isLowPower`-aware) populated from the secrets plugin's `listSecretNames`, replacing the plain `<input>` + `<datalist>`. A free-typed name still round-trips (a secret may be created later). When a row references a name that the loaded list does not contain, the row shows a non-blocking warning (red border + message); save is not prevented. The existence check lives in a pure, unit-tested `unknownSecretNames` helper.
|
|
106
|
+
- **Clearer field description.** The `secretEnv` field descriptions on the `run_script` / `run_shell` actions no longer show the stored `${{ secrets.NAME }}` template (which is confusing in a UI that takes a bare name); they now describe the actual UI behavior and how the value is injected (`process.env.<ENV_NAME>` / `$<ENV_NAME>`) and masked.
|
|
107
|
+
- **`process.env.<ENV_NAME>` autocomplete.** Declared `secretEnv` env-var names now autocomplete under `process.env.` in the Run Script (TypeScript) Monaco editor and are typed `string`, via an ambient `NodeJS.ProcessEnv` augmentation merged into the editor type definitions. New pure, unit-tested generators `generateSecretEnvTypes` and `secretEnvEnvNames` (exported from `@checkstack/automation-frontend`) drive this; the augmentation coexists with `@types/node`'s existing index signature.
|
|
108
|
+
- **Shared combobox-interaction helper.** The "opens-then-immediately-closes" popover guard (`comboboxAnchorProps` / `isAnchorInteraction`) is promoted from `@checkstack/script-packages-frontend` into `@checkstack/ui` so the new secret picker and the existing package/version comboboxes share one implementation; the package comboboxes now import it from `@checkstack/ui` and the local copy is removed.
|
|
109
|
+
|
|
110
|
+
- b995afb: Add type-picker modals for the automation editor's Triggers and Conditions sections, matching the Actions "Add step" picker.
|
|
111
|
+
|
|
112
|
+
Instead of immediately creating a default element, both sections now open a searchable, grouped picker dialog so the operator chooses the type up front. The "Add" button moves out of each card's header to a bottom button styled exactly like the Actions "+ Add step" button.
|
|
113
|
+
|
|
114
|
+
- Triggers: a new "Add trigger" picker over the registry's trigger events (grouped by category, searchable). On pick the trigger is created with a unique default id (deduped against siblings) and appended.
|
|
115
|
+
- Conditions: a new "Add condition" picker over the condition kinds (grouped Structured / Logical / Advanced, searchable). On pick a schema-seeded default for that kind is appended.
|
|
116
|
+
- The shared `PickerRow`, add button and search input are extracted into a reusable `picker-dialog` module; `AddActionDialog` now consumes them.
|
|
117
|
+
- Condition kinds gain a `CONDITION_KIND_META` registry (label, description, icon, group) as the single source of metadata for the picker.
|
|
118
|
+
- Since the type is now chosen up front, the redundant in-sheet selectors are removed: the trigger config sheet drops its editable "Event" dropdown (keeping a read-only owner/description context line), and the top-level condition sheet drops its kind selector (swap kind = delete + re-add). Nested combinator clauses and the action `condition`-guard body keep their inline kind selector.
|
|
119
|
+
- New automations now start empty (no pre-filled trigger or action); the empty-state hints guide the operator to add a trigger and steps via the pickers.
|
|
120
|
+
|
|
121
|
+
The saved `definition` is unchanged - only how items are added - so the visual and YAML views still round-trip losslessly. Triggers and conditions remain non-reorderable.
|
|
122
|
+
|
|
123
|
+
- b995afb: Add the entity state machine core (`defineEntity`) - the foundational primitive of the reactive automation engine - as a Model-B plugin-backed reactive WRAPPER with NO framework-owned current-state storage.
|
|
124
|
+
|
|
125
|
+
`defineEntity` owns NO current-state storage of its own. Each kind declares a required plugin `read` accessor pointing at wherever its state lives (its own durable table, or a value computed on read from its own durable tables), and `defineEntity` makes that state reactive. There is no framework current-state store and no "homeless" fallback: every kind is plugin-backed. This makes a non-reactive write structurally impossible and guarantees every transition is durably logged without duplicating the plugin's state.
|
|
126
|
+
|
|
127
|
+
- `@checkstack/automation-backend`:
|
|
128
|
+
|
|
129
|
+
- New `automation.entity` extension point exposing `defineEntity(input)`, `declareNonReactiveState(input)`, `onEntityChanged(...)`, and `registerChangeDeriver(...)`. automation-backend registers the impl in `register`, so other plugins can resolve it and declare entities during their own `register`/`init` (Proxy-buffered until the impl registers).
|
|
130
|
+
- **Driven single mutation entry point.** All reactive-state writes go through `handle.mutate({ id, opts?, apply: () => Promise<TState> })`. The handle snapshots `prev` via `read` BEFORE the write, runs the plugin's `apply` (the actual write, committed in the PLUGIN's own transaction, returning the resulting state), validates `next` (zod), masks run-originated writes through the run-secret registry, diffs prev to next, and on a real diff appends the field-level transition rows to `entity_transitions` and emits `ENTITY_CHANGED` - both AFTER the plugin write commits (never on a rolled-back / throwing write). A structurally-unchanged write is a no-op. `handle.remove({ id, opts?, apply: () => Promise<void> })` is the tombstone counterpart (records the tombstone transition, emits next = null).
|
|
131
|
+
- **Cross-plugin transaction boundary.** `apply` takes NO framework tx: a plugin-backed kind lives behind a DIFFERENT drizzle client than `entity_transitions`, and two clients cannot share one transaction. The plugin write is authoritative; the transition-log append runs in the framework's own transaction AFTER the plugin write commits. A failure between them leaves correct plugin state with a missing history row (a gap, never a corruption).
|
|
132
|
+
- **`get` / `getMany`** route to the kind's `read`; **`inStateSince` / `inStateForMs` / `transitionCount`** read the per-field `entity_transitions` log (generalizing Phase-13 health transitions to any entity).
|
|
133
|
+
- **No framework keyed store.** There is no generic `entity_state` table, no `createKeyedStore`, and no `entityKeyedStoreServiceRef`: kinds whose state has no domain table of their own (the `health` aggregate, the `slo` budget/streak view) compute their `read` on demand from their own durable data instead of materializing a framework copy. `entity_transitions` (the change-history log) is the framework's ONLY persistent table and is written for EVERY kind regardless of where current state lives.
|
|
134
|
+
- **`entityResolverFor(kind)`** routes scope enrichment + the reactive `wait_until` wake re-eval to each kind's `read` accessor. Generalized scope enrichment (`enrichScopeWithEntities`) folds any `state.<kind>.<id>` ref into `scope.state.<kind>.<id>.<field>`. The rich `scope.health.*` condition snapshot (status, latency, success rate, in-maintenance, transitions-in-window, ...) is resolved EXCLUSIVELY through the healthcheck RPC path (the health aggregate is computed on read, not stored as a framework row) and the generic entity pass never writes `scope.health`; `state.health.*` remains the minimal reactive entity view. These are two complementary projections by design, not a migration shim.
|
|
135
|
+
- **Horizontal-scale read-consistency guard.** A reactive entity's current state MUST be globally readable from shared/durable storage, never process-local memory (`.agent/rules/state-and-scale.md`). Enforced by the `checkstack/no-pod-local-entity-state` ESLint tripwire at the `defineEntity({ read })` boundary (wired at `warn`) and the deterministic `cross-pod-read-consistency.it.test.ts` integration test.
|
|
136
|
+
- Load-time validation hard-fails a malformed registration (non-`z.object` state, missing/duplicate `kind`, or a missing / non-function `read`).
|
|
137
|
+
- The `ENTITY_CHANGED` hook is internal (not exported); the change emitter buffers events produced during the init window and flushes them in order once the hook wiring is available in `afterPluginsReady`.
|
|
138
|
+
|
|
139
|
+
- `@checkstack/automation-common`:
|
|
140
|
+
|
|
141
|
+
- New `EntityChangedSchema` (the `ENTITY_CHANGED` payload - `kind`, `id`, `prev`, `next`, `delta`, `changedFields`, `actor`, `occurredAt`) and `DispatchJobSchema` (the Stage-2 `trigger` / `wake` dispatch job).
|
|
142
|
+
|
|
143
|
+
- `@checkstack/automation-frontend`: the `wait_until` editor no longer offers the inert `poll_seconds` field (reactive waits don't poll).
|
|
144
|
+
|
|
145
|
+
This phase adds the primitive only: domains are migrated in their own changesets. No external behavior changes for existing automations.
|
|
146
|
+
|
|
147
|
+
BREAKING CHANGES: There is no framework current-state store. Any out-of-tree plugin must own its entity state in its own durable storage (its own table, or a compute-on-read over it) and pass a `read` accessor to `defineEntity`. `createKeyedStore` / `KeyedStore` / `entityKeyedStoreServiceRef` / `EntityKeyedStoreService` do not exist, and there is no `entity_state` table. `handle.set` / `handle.patch` and the `indexes` option do not exist; all writes go through `handle.mutate` / `handle.remove`.
|
|
148
|
+
|
|
149
|
+
- b995afb: Fix `context.*` IntelliSense disappearing in the automation inline-script editor.
|
|
150
|
+
|
|
151
|
+
The action editor concatenates the scope-derived `declare const context`
|
|
152
|
+
global with the `secretEnv` `process.env` augmentation into a single Monaco
|
|
153
|
+
extra-lib. `generateSecretEnvTypes` emitted module-form output
|
|
154
|
+
(`declare global { … } export {};`), and the top-level `export {};` turned the
|
|
155
|
+
whole concatenated `.d.ts` into a module - which silently demoted
|
|
156
|
+
`declare const context` from a global ambient to a module-local binding, so
|
|
157
|
+
`context.trigger.payload` (and everything under `context`) stopped
|
|
158
|
+
autocompleting. Because the empty case also emitted `export {};`, every
|
|
159
|
+
automation script action was affected regardless of declared secrets. Health
|
|
160
|
+
check script editors were unaffected (they never merge the secretEnv lib).
|
|
161
|
+
|
|
162
|
+
`generateSecretEnvTypes` now emits a global-script-compatible ambient
|
|
163
|
+
augmentation (`declare namespace NodeJS { interface ProcessEnv { … } }`) and an
|
|
164
|
+
empty string when there is nothing to declare, so the merged extra-lib stays a
|
|
165
|
+
global script and `context` remains globally visible. A regression test guards
|
|
166
|
+
that the merged `context + secretEnv` output contains no top-level
|
|
167
|
+
`export`/`import`.
|
|
168
|
+
|
|
169
|
+
- 270ef29: Add in-UI script testing for automation `run_script` / `run_shell` actions.
|
|
170
|
+
|
|
171
|
+
A new `testScript` RPC runs a TypeScript or shell script against an
|
|
172
|
+
editable, auto-seeded sample context using the same sandboxed runner the
|
|
173
|
+
real action uses, so operators can test scripts directly in the editor
|
|
174
|
+
without dispatching a whole automation. Surfaces beneath any script field
|
|
175
|
+
flagged `x-script-testable` via the new `ScriptTestPanel` /
|
|
176
|
+
`ContextSampleEditor` components in `@checkstack/ui` and the
|
|
177
|
+
`scriptTestRenderer` prop threaded through `DynamicForm`.
|
|
178
|
+
|
|
179
|
+
- `@checkstack/automation-common`: adds the `testScript` contract +
|
|
180
|
+
`ScriptTest*` schemas (gated by `automation.manage`).
|
|
181
|
+
- `@checkstack/automation-backend`: implements `testScript` reusing the
|
|
182
|
+
shared ESM / shell runners; central-only, time-bounded.
|
|
183
|
+
- `@checkstack/backend-api`: new `x-script-testable` config-schema
|
|
184
|
+
metadata propagated to the frontend JSON Schema.
|
|
185
|
+
- `@checkstack/ui`: new `ScriptTestPanel` + `ContextSampleEditor`
|
|
186
|
+
components and a `scriptTestRenderer` prop on `DynamicForm`.
|
|
187
|
+
- `@checkstack/automation-frontend`: wires the test panel into the action
|
|
188
|
+
editor.
|
|
189
|
+
- `@checkstack/integration-script-backend`: marks the `run_script` /
|
|
190
|
+
`run_shell` script fields as testable.
|
|
191
|
+
|
|
192
|
+
- 270ef29: Extend in-UI script testing to health-check collectors, and add
|
|
193
|
+
load-from-run replay for automation script tests.
|
|
194
|
+
|
|
195
|
+
- Health-check collectors: a new `testCollectorScript` RPC runs the
|
|
196
|
+
inline-script (TypeScript) collector and the shell `script` collector
|
|
197
|
+
against an editable, auto-seeded sample context using the same
|
|
198
|
+
sandboxed runner the real collector uses. Surfaces beneath the
|
|
199
|
+
collector script fields in the collector editor (both marked
|
|
200
|
+
`x-script-testable`). Gated by `healthcheck.configuration.manage`.
|
|
201
|
+
- Automation replay: a new `getRunScopeForReplay` RPC reconstructs an
|
|
202
|
+
editable test context from a real run (trigger + persisted artifacts,
|
|
203
|
+
plus the durable scope snapshot when the run is still in-flight), and
|
|
204
|
+
the script-test panel gains a "Load from run" picker that seeds the
|
|
205
|
+
sample context from a past run.
|
|
206
|
+
|
|
207
|
+
Note: health-check executions do not persist the script / config /
|
|
208
|
+
check / system that produced a result, so there is no health-check
|
|
209
|
+
replay - auto-seed is the only context source for collector tests. This
|
|
210
|
+
is by design; see the feature plan.
|
|
211
|
+
|
|
212
|
+
- b995afb: Autocomplete the import specifier itself in script editors.
|
|
213
|
+
|
|
214
|
+
Lazy type acquisition only loads a package's types once its name is already in the buffer, so while you were still typing the import specifier (`import {} from "lod"`) there were no suggestions - the lazy-ATA catch-22. Script editors now suggest installed package names directly in import-specifier position; selecting one (e.g. `lodash`) inserts the name, and the existing ATA loop then loads its `@types/lodash` closure so members complete.
|
|
215
|
+
|
|
216
|
+
- `@checkstack/ui`: `CodeEditor`/`TypefoxEditor` gained an injected `importablePackages?: string[]` prop and a dedicated Monaco completion provider (registered once per `typescript`/`javascript` language, scoped to the editor's model, disposed on unmount). It fires ONLY when the cursor is inside an import/require module-specifier string - detected by a new pure, unit-tested helper `importSpecifierCompletionContext(lineUpToCursor)` that handles `from "…"`, bare `import "…"`, `require("…")`, and dynamic `import("…")`, returns the partial specifier + the replace range, and returns null once the string is closed or outside an import. Items are `kind: Module`, insert the bare name without touching the quotes, and coexist with (do not replace) the TS worker's own completions. Trigger characters: `"`, `'`, and `/` (for scoped subpaths); manual invoke (Ctrl+Space) also works. A new pure helper `importablePackageNames` filters a raw manifest name list (excludes `@types/*`, dedupes, sorts).
|
|
217
|
+
- `@checkstack/script-packages-frontend`: `useScriptPackageTypeAcquisition()` now also returns `importablePackages`, derived from the installed manifest (what is actually resolvable at runtime) with `@types/*` companions excluded - you import `lodash`, never `@types/lodash` (the `@types` package still backs the closure types).
|
|
218
|
+
- `@checkstack/automation-frontend` / `@checkstack/healthcheck-frontend`: pass `importablePackages` into `DynamicForm` alongside the existing `acquireTypes` wiring, so both the Run Script action editor and healthcheck collector editors get import-name completion.
|
|
219
|
+
|
|
220
|
+
The completion list is plugin-agnostic in `@checkstack/ui` (the names are injected); it never fires outside import-string positions, so normal completions are unaffected.
|
|
221
|
+
|
|
222
|
+
- b995afb: Fix package IntelliSense in script editors: lazy Automatic Type Acquisition (ATA) with proper `@types/*` resolution.
|
|
223
|
+
|
|
224
|
+
Script editors (automation "Run Script (TypeScript)" and healthcheck collectors) now provide real autocomplete for installed npm packages. Importing a package whose types live in DefinitelyTyped - e.g. `import { debounce } from "lodash"` (lodash ships no own types; `@types/lodash` does) - now yields member completions. Previously no package completions appeared at all.
|
|
225
|
+
|
|
226
|
+
Root cause: the old rollup wrapped each package's raw, multi-file `.d.ts` (with `export =`, `export as namespace`, and triple-slash `/// <reference path>` chains) inside a single `declare module "<name>" { ... }`, which the TypeScript worker silently rejected, and it truncated large type sets (lodash is ~866 KB across ~700 files) at a 256 KB cap.
|
|
227
|
+
|
|
228
|
+
The fix registers the REAL declaration files at their `node_modules/...` virtual paths and lets TypeScript's own NodeJs + `@types` resolution do the work:
|
|
229
|
+
|
|
230
|
+
- `@checkstack/script-packages-backend`: replaced `rollupPackageTypes` with a tree-driven closure extractor (`resolvePackageTypeClosure`). Given a bare specifier, it resolves against the materialized tree - own types via `package.json` `types`/`typings`/`exports` (bundled-types packages like `zod`/`dayjs`), the `@types/<mangled>` companion when it exists (`lodash` -> `@types/lodash`, scoped `@babel/core` -> `@types/babel__core`), or both, or neither (graceful empty, never a throw). It follows `/// <reference path|types>` and relative imports, includes each package's `package.json`, leaves every file UNWRAPPED, and surfaces a `truncated` flag instead of silently capping. Served from a new raw, HTTP-cacheable route `GET /api/script-packages/types/:lockfileHash/:specifier` (`Cache-Control: private, max-age=1y, immutable`), auth-gated by `script-packages.read`.
|
|
231
|
+
- `@checkstack/script-packages-common`: **BREAKING** - replaced the `listPackageTypes` RPC procedure and `PackageTypesSchema { name, version, dts }` with `PackageTypeClosureSchema` (a `{ path, content }` file-map plus `hasOwnTypes`/`hasAtTypes`/`notFound`/`truncated`) served over the cacheable HTTP route. Added a shared `buildTypeAcquisitionPath`/`parseTypeAcquisitionPath` path contract.
|
|
232
|
+
- `@checkstack/ui`: `CodeEditor`/`TypefoxEditor` gained an injected `acquireTypes` resolver + `acquireResetKey`. On debounced buffer change it parses bare `import`/`require` specifiers (pure, unit-tested) and lazily fetches + registers each NEW package's closure via `addExtraLib` at `file:///node_modules/...`, deduped by a shared acquired-set that resets when the install hash changes. Compiler options set `moduleResolution: NodeJs`, `baseUrl: "file:///"`, and `typeRoots` so a bare import resolves to its `@types` companion. The `context` ambient global keeps working unchanged.
|
|
233
|
+
- `@checkstack/script-packages-frontend`: replaced the old `useScriptPackageTypes` (which concatenated the broken `dts`) with `useScriptPackageTypeAcquisition()`, returning the `acquireTypes` resolver (targets the cacheable route, zod-validates the response) and the current `lockfileHash` as `acquireResetKey`.
|
|
234
|
+
- `@checkstack/automation-frontend` / `@checkstack/healthcheck-frontend`: wired the resolver into the Run Script and collector editors.
|
|
235
|
+
|
|
236
|
+
State & scale: the type closure is derived on read from the materialized package tree (no new durable state). The editor's acquired-set is pod-local UI bookkeeping; the route is keyed by the cluster-wide `lockfileHash`, so the browser HTTP cache is correct across pods and only refetches after a new install changes the hash.
|
|
237
|
+
|
|
238
|
+
- 270ef29: Wire up the script-packages RPC router, admin UI, and editor IntelliSense.
|
|
239
|
+
|
|
240
|
+
- `script-packages-backend`: the oRPC router implementing the full
|
|
241
|
+
contract (allowlist CRUD, registry config with encrypted write-only auth
|
|
242
|
+
token, `installNow` via the elected installer, size cap, storage backend
|
|
243
|
+
selection, install state, `getManifest` / `downloadBlob` for reconcilers,
|
|
244
|
+
and `listPackageTypes`), the `installNow` controller (election, size-cap
|
|
245
|
+
enforcement, `script-packages.changed` emit, blocked during migration),
|
|
246
|
+
the `.d.ts` rollup, the singleton config stores, and the full plugin
|
|
247
|
+
wiring (broadcast-hook reconcile + startup backstop).
|
|
248
|
+
- `script-packages-common`: admin route for the settings page.
|
|
249
|
+
- `script-packages-frontend`: the Settings -> Script Packages admin page
|
|
250
|
+
(allowlist, install state + size, registry/storage summary, satellite
|
|
251
|
+
sync) and the `useScriptPackageTypes()` hook.
|
|
252
|
+
- `automation-frontend` / `healthcheck-frontend`: merge installed-package
|
|
253
|
+
`.d.ts` into the script-editor `typeDefinitions` so `import` from an
|
|
254
|
+
allowlisted package autocompletes in every script field.
|
|
255
|
+
|
|
256
|
+
- b995afb: Fix the automation Run Script action's `secretEnv` (secret → env mapping) test wiring and tolerate bare secret names.
|
|
257
|
+
|
|
258
|
+
- `@checkstack/ui` `ScriptTestPanel` now accepts the script field's declared `secretEnv` and renders an optional per-secret test-override input. The `ScriptTestRenderer` callback (DynamicForm) receives the SIBLING `x-secret-env` mapping value, located by annotation (not by field name), so a testable script field forwards it to the panel. Previously the test path never sent `secretEnv`, so `buildTestSecretEnv` got `undefined` and `process.env.<env>` was undefined in an in-UI test. Now an override-less test injects `__SECRET_<NAME>__` placeholders, and any operator override is masked from the output. Real secret values are still NEVER resolved in the test path.
|
|
259
|
+
- `@checkstack/automation-frontend` forwards the action's `secretEnv` and the collected overrides to `testScript`.
|
|
260
|
+
- `@checkstack/secrets-common`: the `secretEnv` mapping VALUE now accepts EITHER a `${{ secrets.NAME }}` template OR a bare secret name, normalizing a bare name to the canonical `${{ secrets.NAME }}` template on parse. This is a forgiving / NARROWING input change (more inputs accepted; stored/output form is unchanged and still the template), not a breaking change. Existing data and YAML shorthand like `secretEnv: { secret: SECRET }` now pass config validation instead of failing with "Must contain a ${{ secrets.NAME }} reference". Partial inline interpolation (e.g. `u:${{ secrets.pw }}@host`) keeps working unchanged; values that are neither a secret reference nor a valid secret name are still rejected.
|
|
261
|
+
- `@checkstack/ui` `parseSecretName` tolerates a legacy bare secret name for display so the picker shows the same name for both the template and the bare form.
|
|
262
|
+
|
|
263
|
+
The healthcheck collector test panel was checked: its config has no `x-secret-env` field, so it needed no secret wiring (only the `onRun` signature change, which is backward compatible).
|
|
264
|
+
|
|
265
|
+
- 270ef29: Secrets platform Phase 2: secret -> env-var mapping with central resolve, inject, and mask.
|
|
266
|
+
|
|
267
|
+
- Script consumers declare a least-privilege `secretEnv` allowlist
|
|
268
|
+
(`{ ENV_NAME: "${{ secrets.NAME }}" }`). The automation `run_script` /
|
|
269
|
+
`run_shell` actions resolve ONLY the declared secrets via
|
|
270
|
+
`secretResolverRef.resolveForRun`, inject them into the runner env for
|
|
271
|
+
that run (memory-only; the ESM runner gained a per-run `env` option), and
|
|
272
|
+
mask their values out of stdout/stderr/result/error via the run-scoped
|
|
273
|
+
masking context. A missing required secret fails the run clearly. No
|
|
274
|
+
ambient secret access.
|
|
275
|
+
- Test panel: `testScript` / `testCollectorScript` inject named
|
|
276
|
+
`__SECRET_<NAME>__` placeholders by default, or user-supplied per-secret
|
|
277
|
+
overrides; real production values are never resolved in the test path,
|
|
278
|
+
and overrides are masked out of the result.
|
|
279
|
+
- Healthcheck collectors carry the `secretEnv` field for authoring +
|
|
280
|
+
the test panel; runtime injection on satellites lands in Phase 3.
|
|
281
|
+
- Editor UX: a new `@checkstack/ui` `SecretEnvEditor` renders `x-secret-env`
|
|
282
|
+
record fields with `${{ secrets.* }}` name autocomplete (from
|
|
283
|
+
`listSecretNames`), wired into the automation action editor and the
|
|
284
|
+
healthcheck collector editor. New `withConfigMeta` helper +
|
|
285
|
+
`x-secret-env` config-meta key in `@checkstack/backend-api`.
|
|
286
|
+
|
|
287
|
+
- b995afb: Add an optional `partitionBy` override to the windowed-count trigger gate.
|
|
288
|
+
|
|
289
|
+
A trigger's `window` block now accepts `partitionBy`, a bare expression (same flavour as `filter`, no `{{ }}`) that controls the key the occurrence count is bucketed by. When omitted, the gate keys by the trigger's built-in context key exactly as before (per system for health triggers), so existing automations are unchanged. When set, the expression is evaluated against the same trigger scope `filter` uses and coerced to a string - e.g. `trigger.payload.severity` for a per-severity rate, or `trigger.payload.systemId + ":" + trigger.payload.checkId` for a composite key. If the expression evaluates to null/undefined/empty or fails to evaluate, the gate falls back to the built-in context key (never global counting); eval errors are logged, matching the gate's fail-open posture.
|
|
290
|
+
|
|
291
|
+
Triggers can now declare `contextKeyLabel` (a UI hint, e.g. `"system"`) describing their built-in context dimension. It is surfaced through `TriggerInfo` so the editor's window "Partition by" field shows the default partition ("Leave blank to count per system" / "per automation" when a trigger has no context key). The healthcheck system triggers (`system_health_changed`, `system_degraded`, `system_healthy`, `check_failed`) and the built-in `numeric_state` trigger set it to `"system"`. This is a pure UI hint with no runtime behaviour.
|
|
292
|
+
|
|
293
|
+
The automation editor's window block gains a "Partition by" expression input (reusing the trigger filter's `trigger.payload.*` autocomplete), and the collapsed trigger card summary shows the partition when set.
|
|
294
|
+
|
|
295
|
+
- b995afb: Add a generic windowed-count / rate trigger gate, and express flapping detection on it.
|
|
296
|
+
|
|
297
|
+
Any trigger can now carry a `window: { count, minutes, refire }` block: the automation engine records each qualifying occurrence (after the structured config gate and the operator's `filter`) in a durable append log and counts rows within the trailing sliding window, scoped per context key (e.g. per system). `refire: "every"` (default) fires on every occurrence at/over the threshold; `refire: "once"` fires only on the crossing edge and re-arms as old occurrences age out. The gate runs in `maybeStartRun` after `filter` and before the `for:` dwell, so it composes with both.
|
|
298
|
+
|
|
299
|
+
Flapping is now an instance of this mechanism rather than a bespoke detector. The healthcheck `system_health_changed` raw change event plus a `filter` (`trigger.payload.newStatus != "healthy"`) plus `window: { count: 3, minutes: 60, refire: "once" }` reproduces flapping in the engine.
|
|
300
|
+
|
|
301
|
+
State-and-scale: window state lives in the new `automation_window_events` Postgres table (FK-cascade on the automation, the same delete-lifecycle as `automation_dwell_timers`). The count is read with pure SQL so every pod computes the same answer; the work-queue claim gives exactly one INSERT per emission, so there is no double-count. Rows older than the 24h schema cap are pruned by the existing stalled-sweeper. The `once` policy is best-effort under at-least-once redelivery (a redelivered emission can skip the exact crossing edge; `every` is redelivery-tolerant).
|
|
302
|
+
|
|
303
|
+
**BREAKING CHANGES:**
|
|
304
|
+
|
|
305
|
+
- The `healthcheck.flapping_detected` automation trigger and the `healthcheck.flapping_detected` hook are REMOVED. Flapping is now detected by the windowed-count gate on the `healthcheck.system_health_changed` trigger (`window` block, `refire: "once"`).
|
|
306
|
+
- Flapping is now PER-SYSTEM (the aggregated `health` entity), not per-`(system, configuration)`. Subscribe to `check_failed` with a `window` instead if you need per-check rate detection.
|
|
307
|
+
- The healthcheck `health_check_unhealthy_transitions` table is DROPPED (the per-check flapping audit log is no longer kept; counting moved into the engine).
|
|
308
|
+
- The backend-only `automation.subscriptions` service ref (`automationSubscriptionsRef` / `AutomationSubscriptions`) is REMOVED. The engine enumerates subscribers internally and the window gate runs per-automation inside `maybeStartRun`, so the external read-ref is no longer needed.
|
|
309
|
+
- Existing user-created flapping automations are AUTO-MIGRATED on boot: any trigger on `healthcheck.flapping_detected` is rewritten to `healthcheck.system_health_changed` + the canonical unhealthy-transition filter + `window: { count: transitions ?? 3, minutes: windowMinutes ?? 60, refire: "once" }`, dropping the old `config`. A pre-existing trigger filter is replaced with the canonical one (logged per row). An enabled automation that still references the removed event after migration logs a warning.
|
|
310
|
+
|
|
311
|
+
### Patch Changes
|
|
312
|
+
|
|
313
|
+
- Updated dependencies [b995afb]
|
|
314
|
+
- Updated dependencies [b995afb]
|
|
315
|
+
- Updated dependencies [270ef29]
|
|
316
|
+
- Updated dependencies [270ef29]
|
|
317
|
+
- Updated dependencies [270ef29]
|
|
318
|
+
- Updated dependencies [270ef29]
|
|
319
|
+
- Updated dependencies [270ef29]
|
|
320
|
+
- Updated dependencies [270ef29]
|
|
321
|
+
- Updated dependencies [270ef29]
|
|
322
|
+
- Updated dependencies [b995afb]
|
|
323
|
+
- Updated dependencies [b995afb]
|
|
324
|
+
- Updated dependencies [b995afb]
|
|
325
|
+
- Updated dependencies [b995afb]
|
|
326
|
+
- Updated dependencies [b995afb]
|
|
327
|
+
- Updated dependencies [b995afb]
|
|
328
|
+
- Updated dependencies [270ef29]
|
|
329
|
+
- Updated dependencies [270ef29]
|
|
330
|
+
- Updated dependencies [b995afb]
|
|
331
|
+
- Updated dependencies [270ef29]
|
|
332
|
+
- Updated dependencies [270ef29]
|
|
333
|
+
- Updated dependencies [b995afb]
|
|
334
|
+
- Updated dependencies [b995afb]
|
|
335
|
+
- Updated dependencies [b995afb]
|
|
336
|
+
- Updated dependencies [270ef29]
|
|
337
|
+
- Updated dependencies [270ef29]
|
|
338
|
+
- Updated dependencies [b995afb]
|
|
339
|
+
- Updated dependencies [270ef29]
|
|
340
|
+
- Updated dependencies [270ef29]
|
|
341
|
+
- Updated dependencies [270ef29]
|
|
342
|
+
- Updated dependencies [b995afb]
|
|
343
|
+
- Updated dependencies [b995afb]
|
|
344
|
+
- Updated dependencies [270ef29]
|
|
345
|
+
- Updated dependencies [b995afb]
|
|
346
|
+
- Updated dependencies [b995afb]
|
|
347
|
+
- Updated dependencies [b995afb]
|
|
348
|
+
- @checkstack/ui@1.12.0
|
|
349
|
+
- @checkstack/automation-common@0.3.0
|
|
350
|
+
- @checkstack/template-engine@0.3.0
|
|
351
|
+
- @checkstack/script-packages-frontend@0.2.0
|
|
352
|
+
- @checkstack/secrets-frontend@0.1.0
|
|
353
|
+
- @checkstack/gitops-frontend@0.4.7
|
|
354
|
+
|
|
3
355
|
## 0.2.0
|
|
4
356
|
|
|
5
357
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/automation-frontend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "Elastic-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.tsx",
|
|
@@ -13,13 +13,17 @@
|
|
|
13
13
|
"lint:code": "eslint . --max-warnings 0"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@checkstack/automation-common": "0.
|
|
17
|
-
"@checkstack/common": "
|
|
18
|
-
"@checkstack/
|
|
19
|
-
"@checkstack/
|
|
20
|
-
"@checkstack/
|
|
21
|
-
"@checkstack/
|
|
22
|
-
"@checkstack/
|
|
16
|
+
"@checkstack/automation-common": "0.2.0",
|
|
17
|
+
"@checkstack/catalog-common": "2.2.3",
|
|
18
|
+
"@checkstack/common": "0.12.0",
|
|
19
|
+
"@checkstack/frontend-api": "0.6.0",
|
|
20
|
+
"@checkstack/gitops-frontend": "0.4.6",
|
|
21
|
+
"@checkstack/integration-common": "0.6.0",
|
|
22
|
+
"@checkstack/script-packages-frontend": "0.1.0",
|
|
23
|
+
"@checkstack/secrets-frontend": "0.0.1",
|
|
24
|
+
"@checkstack/signal-frontend": "0.1.5",
|
|
25
|
+
"@checkstack/template-engine": "0.2.0",
|
|
26
|
+
"@checkstack/ui": "1.11.0",
|
|
23
27
|
"@dnd-kit/core": "^6.3.1",
|
|
24
28
|
"@dnd-kit/sortable": "^8.0.0",
|
|
25
29
|
"@dnd-kit/utilities": "^3.2.2",
|
|
@@ -33,6 +37,6 @@
|
|
|
33
37
|
"typescript": "^5.0.0",
|
|
34
38
|
"@types/react": "^18.2.0",
|
|
35
39
|
"@checkstack/tsconfig": "0.0.7",
|
|
36
|
-
"@checkstack/scripts": "0.3.
|
|
40
|
+
"@checkstack/scripts": "0.3.4"
|
|
37
41
|
}
|
|
38
42
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Tag, X } from "lucide-react";
|
|
3
|
+
import {
|
|
4
|
+
Input,
|
|
5
|
+
Popover,
|
|
6
|
+
PopoverAnchor,
|
|
7
|
+
PopoverContent,
|
|
8
|
+
comboboxAnchorProps,
|
|
9
|
+
isAnchorInteraction,
|
|
10
|
+
} from "@checkstack/ui";
|
|
11
|
+
|
|
12
|
+
export interface AutomationGroupComboboxProps {
|
|
13
|
+
/** Current group value (controlled). Empty string means "Ungrouped". */
|
|
14
|
+
value: string;
|
|
15
|
+
/** Called whenever the value changes (typing, picking, or clearing). */
|
|
16
|
+
onValueChange: (next: string) => void;
|
|
17
|
+
/** Distinct existing group values to suggest. */
|
|
18
|
+
suggestions: string[];
|
|
19
|
+
id?: string;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Type-new-or-pick-existing group field. Composes `Popover` + `Input` (no
|
|
26
|
+
* Combobox primitive exists) and mirrors `PackageNameCombobox`'s structure:
|
|
27
|
+
* a scrollable suggestion list filtered by the current input.
|
|
28
|
+
*
|
|
29
|
+
* Free-typed new groups are allowed (the input value IS the group). Selecting
|
|
30
|
+
* a suggestion fills the value and closes the list. Reuses the shared
|
|
31
|
+
* `comboboxInteraction` dismiss-guard so the very click that opens the list
|
|
32
|
+
* does not immediately close it (Radix treats the anchor as "outside").
|
|
33
|
+
*/
|
|
34
|
+
export const AutomationGroupCombobox: React.FC<AutomationGroupComboboxProps> = ({
|
|
35
|
+
value,
|
|
36
|
+
onValueChange,
|
|
37
|
+
suggestions,
|
|
38
|
+
id,
|
|
39
|
+
disabled,
|
|
40
|
+
placeholder,
|
|
41
|
+
}) => {
|
|
42
|
+
const [open, setOpen] = React.useState(false);
|
|
43
|
+
const inputRef = React.useRef<HTMLInputElement>(null);
|
|
44
|
+
|
|
45
|
+
const query = value.trim().toLowerCase();
|
|
46
|
+
const filtered = React.useMemo(() => {
|
|
47
|
+
const seen = new Set<string>();
|
|
48
|
+
return suggestions.filter((s) => {
|
|
49
|
+
const key = s.toLowerCase();
|
|
50
|
+
if (seen.has(key)) return false;
|
|
51
|
+
seen.add(key);
|
|
52
|
+
return query.length === 0 || key.includes(query);
|
|
53
|
+
});
|
|
54
|
+
}, [suggestions, query]);
|
|
55
|
+
|
|
56
|
+
// Don't offer a suggestion that exactly equals the current value (nothing
|
|
57
|
+
// to pick — the user already has it).
|
|
58
|
+
const showList =
|
|
59
|
+
filtered.length > 0 &&
|
|
60
|
+
!(filtered.length === 1 && filtered[0]?.toLowerCase() === query);
|
|
61
|
+
|
|
62
|
+
const handlePick = (group: string) => {
|
|
63
|
+
onValueChange(group);
|
|
64
|
+
setOpen(false);
|
|
65
|
+
inputRef.current?.focus();
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<Popover open={open && showList && !disabled} onOpenChange={setOpen}>
|
|
70
|
+
<PopoverAnchor asChild>
|
|
71
|
+
<div className="relative">
|
|
72
|
+
<Tag className="pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" />
|
|
73
|
+
<Input
|
|
74
|
+
ref={inputRef}
|
|
75
|
+
id={id}
|
|
76
|
+
value={value}
|
|
77
|
+
disabled={disabled}
|
|
78
|
+
onChange={(e) => {
|
|
79
|
+
onValueChange(e.target.value);
|
|
80
|
+
setOpen(true);
|
|
81
|
+
}}
|
|
82
|
+
onFocus={() => setOpen(true)}
|
|
83
|
+
placeholder={placeholder ?? "Ungrouped"}
|
|
84
|
+
autoComplete="off"
|
|
85
|
+
className="pl-8 pr-8"
|
|
86
|
+
{...comboboxAnchorProps}
|
|
87
|
+
/>
|
|
88
|
+
{value.length > 0 && !disabled && (
|
|
89
|
+
<button
|
|
90
|
+
type="button"
|
|
91
|
+
aria-label="Clear group"
|
|
92
|
+
onClick={() => {
|
|
93
|
+
onValueChange("");
|
|
94
|
+
setOpen(false);
|
|
95
|
+
inputRef.current?.focus();
|
|
96
|
+
}}
|
|
97
|
+
className="absolute right-2 top-1/2 -translate-y-1/2 rounded-sm text-muted-foreground hover:text-foreground"
|
|
98
|
+
>
|
|
99
|
+
<X className="h-3.5 w-3.5" />
|
|
100
|
+
</button>
|
|
101
|
+
)}
|
|
102
|
+
</div>
|
|
103
|
+
</PopoverAnchor>
|
|
104
|
+
<PopoverContent
|
|
105
|
+
align="start"
|
|
106
|
+
className="w-[--radix-popover-trigger-width] p-0"
|
|
107
|
+
onOpenAutoFocus={(e) => e.preventDefault()}
|
|
108
|
+
onCloseAutoFocus={(e) => e.preventDefault()}
|
|
109
|
+
onPointerDownOutside={(e) => {
|
|
110
|
+
if (isAnchorInteraction(e.target)) e.preventDefault();
|
|
111
|
+
}}
|
|
112
|
+
onFocusOutside={(e) => {
|
|
113
|
+
if (isAnchorInteraction(e.target)) e.preventDefault();
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
<div className="max-h-60 overflow-y-auto py-1">
|
|
117
|
+
{filtered.map((group) => (
|
|
118
|
+
<button
|
|
119
|
+
key={group}
|
|
120
|
+
type="button"
|
|
121
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
122
|
+
onClick={() => handlePick(group)}
|
|
123
|
+
className="flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm hover:bg-accent hover:text-accent-foreground"
|
|
124
|
+
>
|
|
125
|
+
<Tag className="h-3 w-3 shrink-0 text-muted-foreground" />
|
|
126
|
+
<span className="flex-1 truncate">{group}</span>
|
|
127
|
+
</button>
|
|
128
|
+
))}
|
|
129
|
+
</div>
|
|
130
|
+
</PopoverContent>
|
|
131
|
+
</Popover>
|
|
132
|
+
);
|
|
133
|
+
};
|