From 1a1f8b6b181dee278ecbc863d1a3fc194fe877d4 Mon Sep 17 00:00:00 2001 From: Leiter Consulting <152733483+LeiterConsulting@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:25:38 -0400 Subject: [PATCH] Release 1.0.2 with shared-source planning and verified native bindings --- CHANGELOG.md | 14 + README.md | 18 +- docs/README.md | 4 +- docs/architecture.md | 12 + docs/documentation-review.md | 6 + docs/installation.md | 8 +- docs/studio-support.md | 1 + docs/upgrade-guide.md | 2 + docs/user-guide.md | 6 +- docs/v1-readiness.md | 2 +- docs/validation.md | 38 ++- package-lock.json | 4 +- package.json | 2 +- splunk/constellation/bin/agent_service.py | 40 ++- splunk/constellation/bin/authoring_budget.py | 75 ++++- splunk/constellation/bin/board_batches.py | 205 +++++++++++++ splunk/constellation/bin/creation_recipes.py | 13 +- splunk/constellation/bin/dashboard_plan.py | 290 +++++++++++++++++++ splunk/constellation/bin/data_service.py | 18 +- splunk/constellation/bin/native_builders.py | 138 +++++++++ splunk/constellation/bin/native_intent.py | 9 + splunk/constellation/bin/native_shapes.py | 48 ++- splunk/constellation/bin/planning_sources.py | 93 ++++++ splunk/constellation/bin/table_aggregates.py | 76 +++++ splunk/constellation/bin/table_projection.py | 13 +- splunk/constellation/default/app.conf | 6 +- src/App.tsx | 2 +- tests/fixtures/native_chart_shapes.json | 4 + tests/test_authoring_budget.py | 10 + tests/test_creation_recipes.py | 5 + tests/test_dashboard_plan.py | 274 ++++++++++++++++++ tests/test_native_shapes.py | 5 +- tests/test_planning_sources.py | 65 +++++ tests/test_table_aggregates.py | 85 ++++++ tests/test_table_projection.py | 9 + 35 files changed, 1550 insertions(+), 50 deletions(-) create mode 100644 splunk/constellation/bin/board_batches.py create mode 100644 splunk/constellation/bin/dashboard_plan.py create mode 100644 splunk/constellation/bin/native_builders.py create mode 100644 splunk/constellation/bin/planning_sources.py create mode 100644 splunk/constellation/bin/table_aggregates.py create mode 100644 tests/test_dashboard_plan.py create mode 100644 tests/test_planning_sources.py create mode 100644 tests/test_table_aggregates.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fa051b..33ad120 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## 1.0.2 — October 30, 2026 + +- Compile eligible larger fresh SPL boards from a shared-source plan with explicit page membership, native bindings and destination-local row navigation. Keep the existing search and recovery budgets. +- Reuse compatible stats and identically bucketed timechart outputs without changing aliases, missing-value populations or explicit consumer projections. +- Remove unused model search declarations before dispatch, and reject overall KPI bindings to a grouped summary's last row. +- Separate basic larger Ollama/AITK source planning from page composition, combining compatible recipes and binding the second internal step to verified output fields within the existing recovery budget. +- Compute repeated aggregates once and retain their aliases through value copies. Keep one exact reference definition in focused repairs and expose explicitly named table additions after output verification. +- Compile unambiguous named numeric aggregate additions on selected ordinary tables locally, cloning shared sources and retaining all search/output validation. Ambiguous or compound requests retain model authoring. +- Validate numeric chart axes, both network endpoint sets and node-array alignment against actual output. Revalidate unchanged chain descendants when their parent changes. +- Give newly created stats-backed single values non-temporal display defaults and bounded precision for verified fractions, preserving explicit options and existing native work. +- Retain the general authoring path for requests outside the bounded initial planner; reject unavailable native chart families before inference. + +- Qualify three eight-page, 24-chart creation/editing cycles per provider with ordinary authors, plus focused browser edits, native saves, cancellation and calculation probes. See [validation](docs/validation.md#102--october-30-2026). + ## 1.0.1 — October 30, 2026 - Preview the active page's chart and input sources, including global inputs and auxiliary chart aliases, within the existing search limits. Resolve chain/report ancestry and cancel obsolete page work without changing native definitions. diff --git a/README.md b/README.md index 18ad13a..8d0cbee 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ Create and edit **Splunk Dashboard Studio** dashboards through a conversation beside a live canvas. Choose data your Splunk account can search, refine a selected chart or input, and save a normal native Studio dashboard. -**Version 1.0.1** · [Download](https://github.com/LeiterConsulting/constellation/releases/tag/v1.0.1) · [User guide](docs/user-guide.md) · [Documentation](docs/README.md) +**Version 1.0.2** · [Download](https://github.com/LeiterConsulting/constellation/releases/tag/v1.0.2) · [User guide](docs/user-guide.md) · [Documentation](docs/README.md) -**New in 1.0.1:** previews follow the active page, reuse fresh results and cancel obsolete work. Draft-save receipts distinguish uncertain delivery from genuine conflicts. [Release evidence](docs/validation.md#101--october-30-2026) records the bounded three-provider checks. +**New in 1.0.2:** shared-search planning for larger multi-page dashboards, stronger native chart bindings and verified additions to selected tables. The existing validation and recovery limits remain in place. [Release evidence](docs/validation.md#102--october-30-2026) records nine repeated ordinary-author flows across all three providers. ## Start here @@ -35,13 +35,13 @@ Constellation runs inside Splunk. It does not require a separate agent service o | File | Purpose | | --- | --- | -| [Installable app](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.1/constellation-1.0.1.tar.gz) | Install or update through Splunk app management. | -| [App and documentation bundle](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.1/constellation-1.0.1-handoff.zip) | The same app, user guide, screenshots and administrator/reference material. | -| [User guide · Markdown](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.1/constellation-1.0.1-user-guide.md) | Standalone guide text. The bundle includes its local images. | -| [User guide · PDF](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.1/constellation-1.0.1-user-guide.pdf) | Illustrated guide for reading or printing. | -| [MIT license](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.1/LICENSE) | First-party license accompanying the app and documentation. | -| [Dependency notices](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.1/constellation-1.0.1-third-party-notices.zip) | Upstream notices, also embedded in the app and included in the handoff. | -| [SHA256SUMS](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.1/SHA256SUMS) | Verify every release download. | +| [Installable app](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.2/constellation-1.0.2.tar.gz) | Install or update through Splunk app management. | +| [App and documentation bundle](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.2/constellation-1.0.2-handoff.zip) | The same app, user guide, screenshots and administrator/reference material. | +| [User guide · Markdown](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.2/constellation-1.0.2-user-guide.md) | Standalone guide text. The bundle includes its local images. | +| [User guide · PDF](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.2/constellation-1.0.2-user-guide.pdf) | Illustrated guide for reading or printing. | +| [MIT license](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.2/LICENSE) | First-party license accompanying the app and documentation. | +| [Dependency notices](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.2/constellation-1.0.2-third-party-notices.zip) | Upstream notices, also embedded in the app and included in the handoff. | +| [SHA256SUMS](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.2/SHA256SUMS) | Verify every release download. | ## Supported scope diff --git a/docs/README.md b/docs/README.md index 58a60e7..d658357 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,7 +2,7 @@ Before changing repository visibility, use the [publication review](publication-review.md). Upstream attribution sources are recorded in [dependency notices](../third_party/README.md). -Choose a path by what you need to do. These guides describe **Constellation 1.0.1**; historical records are kept separately. +Choose a path by what you need to do. These guides describe **Constellation 1.0.2**; historical records are kept separately. ## Use Constellation @@ -13,7 +13,7 @@ Choose a path by what you need to do. These guides describe **Constellation 1.0. 5. [Save a native dashboard](user-guide.md#use-the-result-in-splunk). 6. [Move artwork and dependencies](assets-and-portability.md). -The [illustrated user guide](user-guide.md) covers the complete workflow. Download its [PDF edition](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.1/constellation-1.0.1-user-guide.pdf) for offline reading. +The [illustrated user guide](user-guide.md) covers the complete workflow. Download its [PDF edition](https://github.com/LeiterConsulting/constellation/releases/download/v1.0.2/constellation-1.0.2-user-guide.pdf) for offline reading. [Glossary](glossary.md) explains draft, native copy, scope, token and snapshot. diff --git a/docs/architecture.md b/docs/architecture.md index 98be523..5fb9213 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -24,6 +24,8 @@ Paths below are under the Python app bin directory or src as appropriate. | Provider transport/messages | provider_service.py, provider_adapters.py, provider_messages.py | Native API formats, fixed/guarded endpoints, controlled errors | | Model capability/workload | model_capabilities.py, model_readiness.py, authoring_budget.py | Unknown capacity stays unknown; unsupported files fail before inference | | Native definition and intent | studio_contract.py, native_options.py, native_bindings.py, authoring_intent.py | Preserve unknown/unrelated work; gate new unsupported behavior | +| Larger initial boards | dashboard_plan.py, board_batches.py, planning_sources.py, native_builders.py | Explicit page membership, shared compatible outputs, bounded expansion and verified native bindings | +| Exact table edits | table_sort.py, table_aggregates.py, table_projection.py | Narrow literal intent, verified numeric inputs/outputs, shared-source isolation and unchanged unrelated work | | Source resolution and field evidence | source_service.py, data_service.py, token_service.py | Exact caller/report namespace, unresolved scope syntax, no result rows in model context | | Guarded searches and lifecycle | search_service.py, preview_jobs.py, population_guard.py, measurement_constraints.py | Read-only subset, bounded current-user jobs, explicit partial evidence | | Drafts/history/management | draft_service.py, draft_migrations.py, dashboard_library.py, draft_history.py | Ownership, revisions, no future-schema rewrite, recoverable deletion | @@ -35,6 +37,16 @@ Paths below are under the Python app bin directory or src as appropriate. The [design notes](reference/design-notes.md) and [upgrade contracts](reference/upgrade-contracts.md) retain detailed compiler strategies and versioned invariants. Verify actual module names when changing a boundary. +Version 1.0.2 adds a provider-neutral plan for eligible empty, inspected SPL canvases with explicit larger page/panel counts. The model chooses calculations and page membership; the compiler constructs native geometry, field bindings, shared searches and destination-local row navigation. The complete expansion must fit eight pages, 24 panels and eight affected sources, including filtered clones and network node dependencies. These are initial-plan bounds, not limits on imported native documents. Unsupported complex requests retain the general authoring path. + +Compatible typed stats recipes and timecharts can share a search only when their grouping, time buckets and aggregate aliases agree and every consumer projects explicit fields. Only exact literal aggregate subsets of raw SPL can join the same verified recipe pool; complex pipelines, different bucket settings, split-series charts, all-fields tables and dynamic frames are not merged. Unconsumed declarations in the new model plan are discarded before compilation or dispatch; every requested panel and every consumed output still passes the existing validators. Overall KPI cards cannot select the last row of a grouped summary; the basic batch path also excludes time buckets and raw rows for these cards. Route tokens avoid collisions with existing defaults and expressions. Measurement masks and all existing source, placement, intent and actual-output checks still apply. Rejected plans are repaired against the original blank document; accepted user work is never treated as disposable staging. + +Native bindings select explicit output fields or, for an explicit split timechart, the actual numeric series after `_time`. Network charts share separate chains for source-column membership (including null-target rows for sink nodes) and aligned node styling, while other consumers retain the original edge weights. New stats-backed single values receive non-temporal display defaults; fractional verified values receive bounded display precision only when the user has not specified it. These corrections change presentation, not queries, indexed rows or existing elements. + +For eligible larger basic aggregate requests through Ollama or AITK, a first internal call plans a recipe-only source pool. Compatible independent aggregates are combined before verification with the caller's searches. A second call composes pages against immutable source definitions and actual output-field choices; a source/field mismatch fails before final search validation. Only calculation definitions and field metadata pass to that call, without indexed rows. Both steps and any repair share the existing three-call, sixteen-query-check and elapsed-time admission budgets; no partial board is staged or saved. OpenAI and more complex native requests keep the single-plan path. Requests such as native table sparklines, which require richer formatting, retain general authoring. + +Repeated aggregate expressions use one native specifier followed by alias copies, retaining every requested output name and null value. This avoids native timechart rejection of conflicting renames for the same calculation. Focused edit repairs carry one exact reference definition, alongside the original verified focused receipt and durable brief, rather than duplicate full dashboards. Explicitly named new table columns are exposed only after their actual outputs verify; existing columns, formatting and interactions remain intact. + ## Authority and credentials Main and control handlers use only the caller's session. Two separate handlers receive system authentication: opt-in shared AITK inference and owner-only OpenAI credential custody. Selecting an execution namespace does not reduce the system token's authority; fixed endpoint code and administrator-only policy are the privilege boundary. diff --git a/docs/documentation-review.md b/docs/documentation-review.md index 58acfe5..1fbf932 100644 --- a/docs/documentation-review.md +++ b/docs/documentation-review.md @@ -1,5 +1,11 @@ # Documentation assessment and closeout +## 1.0.2 release edition — October 30, 2026 + +The README, current guides and release links identify 1.0.2 / build 62 and retain the exact lab-qualified app archive. The author guide adds concise examples for multi-page requests and calculated table columns. The validation record distinguishes repeated provider/API flows, operated browser checks, partial previews and separately labelled synthetic calculation probes. Historical evidence and screenshot provenance remain unchanged. + +The PDF is regenerated from this edition of the Markdown guide, rendered and visually inspected before distribution. The release includes matching Markdown/PDF guides, the offline handoff, MIT license, dependency notices and checksums. + ## 1.0.1 release edition — October 30, 2026 The README, documentation index, installation/upgrade steps, author guide and troubleshooting now describe 1.0.1, active-page preview bounds and save-conflict diagnosis. Release links and the app checksum identify build 61; the app retains the exact bytes used for the recorded patch qualification. Historical 1.0.0 evidence remains dated separately. diff --git a/docs/installation.md b/docs/installation.md index fd4e9dc..0b7a3c7 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -1,6 +1,6 @@ # Install Constellation -This guide is for Splunk administrators installing **1.0.1**. Authors can start with the [user guide](user-guide.md) once installation and provider access are ready. +This guide is for Splunk administrators installing **1.0.2**. Authors can start with the [user guide](user-guide.md) once installation and provider access are ready. ## Check the deployment @@ -17,16 +17,16 @@ Node/npm and a separate Python installation are **not required to install the re ## Download and verify -Get the app, **LICENSE**, **third-party-notices ZIP** and **SHA256SUMS** from [release v1.0.1](https://github.com/LeiterConsulting/constellation/releases/tag/v1.0.1). Install the app archive inside the documentation ZIP, or download the standalone tar.gz. +Get the app, **LICENSE**, **third-party-notices ZIP** and **SHA256SUMS** from [release v1.0.2](https://github.com/LeiterConsulting/constellation/releases/tag/v1.0.2). Install the app archive inside the documentation ZIP, or download the standalone tar.gz. ~~~sh -shasum -a 256 constellation-1.0.1.tar.gz +shasum -a 256 constellation-1.0.2.tar.gz ~~~ Compare the digest with its line in SHA256SUMS. The qualified app digest is: ~~~text -8f875e0a204630589df32c1bec8b8d4e6e4d50d49fd01b6951c38617b4b79515 +7df2620bb442ac4617f46cae677c29af1719d99984e5cddb010eb461288958fc ~~~ First-party code and documentation use the [MIT License](../LICENSE). The app embeds it and the collected [dependency notices](../third_party/README.md). Both are also supplied beside the installer and inside the handoff bundle; keep them with redistributed copies. diff --git a/docs/studio-support.md b/docs/studio-support.md index 8e3381a..86d2c3d 100644 --- a/docs/studio-support.md +++ b/docs/studio-support.md @@ -51,6 +51,7 @@ Search-result completion is not proof of analytical correctness. New actual-data | Ordinary preview in 1.0.1 | 200 rows / five seconds per query / eight consumer sources on the active page, including global/page inputs and chart aliases; chain/report ancestry resolves within each guarded request | | Preview windows | 15 minutes, one hour, 24 hours or seven days | | Field inspection | Bounded current-user sample; wide/large events can reduce retained rows; missing fields are not proof of absence | +| Larger initial plan, 1.0.2 | Eligible empty inspected SPL boards: eight pages / 24 panels / eight expanded affected sources, including filtered clones and auxiliary sources. Unsupported complex requests use general authoring; imported boards retain their native structure. | | Search freshness | Snapshots become stale after one minute; refresh for current results | | Chat references | Two files / 4 MB each | | Draft storage | 200 retained records including Trash/recovery; 11.5 MB snapshot bound | diff --git a/docs/upgrade-guide.md b/docs/upgrade-guide.md index ae470ea..a25be2a 100644 --- a/docs/upgrade-guide.md +++ b/docs/upgrade-guide.md @@ -22,6 +22,8 @@ Version 1.0.1 also retains schema 3 and portable format 5. Its optional save rec ## Verify after updating +Version 1.0.2 also retains schema 3, portable format 5 and the existing credential permissions. Larger initial-board planning requires no stored-document migration. Existing definitions and conversations are preserved. The [1.0.2 qualification](validation.md#102--october-30-2026) records the update checks separately from 1.0.1. + As an intended ordinary author: 1. Reopen a draft and its conversation, brief, page/input state and pending files. diff --git a/docs/user-guide.md b/docs/user-guide.md index eed15f8..0ffaebf 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -1,6 +1,6 @@ # Constellation user guide -Create a dashboard from a question and Splunk data, refine it through chat, and save a native Dashboard Studio copy. This guide describes version **1.0.1**. +Create a dashboard from a question and Splunk data, refine it through chat, and save a native Dashboard Studio copy. This guide describes version **1.0.2**. **Before you begin:** Constellation must be installed in Splunk, your account must be able to search the chosen data, and a provider must be configured. If **Settings** or **Test model** needs attention, follow [provider setup](providers.md) or ask your administrator. @@ -29,6 +29,8 @@ Turn on **Select element** and choose an element on the canvas. Alternatively, e > Change only this table: round latency to one decimal and keep its existing columns and row links. +For a calculated table column, name the measurement and the result you want. For example: “For only this selected table, add minimum and maximum latency columns named minimum_latency and maximum_latency alongside its existing columns.” Use **Inspect fields** if a measurement name or unit is unclear. The app checks new columns against the returned search fields. + **Keep exploring** offers follow-on requests. Selecting one fills the composer; you can edit it before sending. A suggestion is a proposed next step, not proof of a relationship in the data. Choose **Float** to move the conversation over the canvas, **Dock** to return it beside the canvas, or **Hide** to collapse it. **Show conversation** opens it again. @@ -55,6 +57,8 @@ Explain recorded units explicitly. A name hint is not evidence of a physical uni Use **Pages** to add or rename a page and give it a purpose. Page purposes help organize the conversation; they do not create an access boundary. +When creating several pages, state their names, purposes and required charts together. For example: “Create Overview, Trends and Device detail, with three charts on each page.” Related charts can share searches; larger requests may take more than one internal planning step. Watch progress or use **Stop**; the board changes only after validation. + For linked pages, name the source, destination and filter: > Create Overview and Service detail. Keep Overview unfiltered. Clicking a service in the summary should open Service detail filtered to that service. Add a return button to Overview. diff --git a/docs/v1-readiness.md b/docs/v1-readiness.md index 6eb61be..65a3af2 100644 --- a/docs/v1-readiness.md +++ b/docs/v1-readiness.md @@ -1,6 +1,6 @@ # Version 1.0 technical release checklist -The product owner explicitly made human/independent reviews non-blocking on October 29, 2026. The technical checks below record the original **1.0.0** decision for the [supported Enterprise profile](support-policy.md). Current release **1.0.1** adds active-page previews and guarded save receipts; its separate [patch qualification](validation.md#101--october-30-2026) records 637 Python / 151 frontend tests, nine repeated ordinary-author provider cycles and browser/native recovery checks. Exact-head CI is required for every release. +The product owner explicitly made human/independent reviews non-blocking on October 29, 2026. The technical checks below record the original **1.0.0** decision for the [supported Enterprise profile](support-policy.md). Current release **1.0.2** adds shared-search multi-page planning, stronger native bindings and verified table additions; its [patch qualification](validation.md#102--october-30-2026) records 672 Python / 151 frontend tests, nine eight-page ordinary-author provider cycles and browser/native/cancellation checks. Exact-head CI is required for every release. Original qualified package: **1.0.0 / build 60**, SHA-256 `d53d62e3ce929a5a912cd1d6dccddaecbdee96d65a35d7b4a4a7f44cb0ddebc7`. [Full evidence and retained failures](validation.md#100-technical-release-candidate--october-29-2026) explain each bounded check. diff --git a/docs/validation.md b/docs/validation.md index 547dd0e..afdcb5b 100644 --- a/docs/validation.md +++ b/docs/validation.md @@ -1,6 +1,42 @@ # Release evidence -Current release: **Constellation 1.0.1 / build 61**, qualified October 30, 2026. The patch retains the bounded Enterprise support profile. The earlier [1.0 record](reference/validation-1.0.md) preserves the original runtime, failures and upgrade/rollback evidence. Private hosts, keys, indexed rows, user files and lab screenshots remain outside Git. +Current release: **Constellation 1.0.2 / build 62**, qualified October 30, 2026. The patch retains the bounded Enterprise support profile. The earlier [1.0 record](reference/validation-1.0.md) preserves the original runtime, failures and upgrade/rollback evidence. Private hosts, keys, indexed rows, user files and lab screenshots remain outside Git. + +## 1.0.2 — October 30, 2026 + +The qualified app bytes are retained unchanged for the 1.0.2 release. The same archive was installed on the two existing single-head Enterprise targets without a restart. + +| Item | Recorded result | +| --- | --- | +| Package | 1.0.2 / build 62; SHA-256 `7df2620bb442ac4617f46cae677c29af1719d99984e5cddb010eb461288958fc` | +| Release | [v1.0.2](https://github.com/LeiterConsulting/constellation/releases/tag/v1.0.2) | +| Archive | 550 regular files / 5,596,190 bytes; one app root; no macOS sidecars, extended tar metadata or local evidence | +| Offline checks | 672 Python / 151 frontend tests passed; Node 22 production build and browser budget passed | +| AppInspect 4.2.1 precert | 0 errors / 0 failures / 0 future failures; 7 warning checks / 1 skipped; local precert, not Cloud certification | +| Larger ordinary-author cohort | Three fresh eight-page, 24-chart create/edit cycles per provider; all nine cycles and 27 turns passed on Enterprise 10.2.8 | +| Editing and persistence | Named min/max table additions, selected line-to-area conversion, unrelated-definition preservation, row/detail/return routing, exact conversation/draft reopen and private native save/readback | +| Ordinary-user browser | All three providers: element selection, focused chat title edit, row/detail/return navigation and refresh. Exact readback preserved unrelated native work. AITK also saved through the app dialog and opened the populated native table | +| Native graph bindings | Enterprise 10.4.4 ordinary-author creation/editing of three pages / nine network, Sankey and table charts using three shared sources; exact private save/reopen | +| Native rendering tier | All three graph-board pages rendered in native Studio using a separate administrator-owned private copy. This rendering tier is separate from the ordinary-author API/search/save evidence | +| Calculations | All nine boards exercised with actual bounded previews and separately labelled synthetic cutoff/missing-data probes; exact 150 retained, higher temperatures excluded, independent Wi-Fi and event populations retained | +| Cancellation and version gates | Stop during Ollama's second planning call returned cancellation, without a partial draft or delivered reply. All three providers rejected the unavailable native network family on the older target before inference | +| Preservation and cleanup | Existing hero definition/conversation/native view, administrator connections, AITK policy and author role unchanged. Four temporary users, two copied owner-only key records, one temporary role and all owned test views/configurations/jobs removed; key absence verified | + +The ordinary-author accounts had no administrator, credential-store or vendor AI configuration/command capabilities. Direct OpenAI used `gpt-6-luna`, Ollama used `qwen3-coder:latest`, and managed AITK used the lab's approved OpenAI connection. The repeated cohort used one real sensor dataset; a separate component/severity log dataset exercised native network bindings. It is not a cross-model or business-domain success-rate benchmark. + +| Provider | Creation times, three runs | Repairs across nine cohort turns | +| --- | --- | --- | +| OpenAI | 35.63 / 69.32 / 37.61 seconds | One creation repair for an invalid compose ID | +| Ollama | 109.42 / 78.33 / 78.04 seconds | None; two intentional internal planning calls per creation | +| Managed AITK | 73.24 / 71.28 / 86.94 seconds | None; two intentional internal planning calls per creation | + +These are observed wall times including caller-scoped inspection and validation, not a latency guarantee or controlled speed comparison. Eligible named table edits took 3.48–3.70 seconds with no inference; OpenAI's more complex pipelines retained model editing. Existing recovery limits remained three model calls, sixteen query checks and the elapsed-time admission budget. Native alias probes separately verified shared stats/timechart aliases under all four temporary accounts. + +The calculation checks covered 58 generated source definitions: 49 actual previews completed, and nine raw-detail previews remained explicitly partial at the row bound. Synthetic probes checked known values and populations separately. Neither bounded data inspection nor synthetic agreement proves every analytical decision is correct. + +Preparatory candidates exposed native target-only graph-node membership, invalid internal field names, repeated timechart specifiers with different aliases, redundant source fragments, overly large focused-repair context and omitted exact table aliases/projections. Fixes retain caller searches and native validation. A preparatory save conflict came from the test browser autosaving a draft while the API harness was writing it; conflict protection held and the harness was corrected. The cancellation probe initially expected the wrong result response; it was corrected to the existing HTTP 409 cancellation contract, without a runtime change. Superseded archives and private evidence remain local. + +The initial planner remains bounded to eligible empty inspected SPL canvases. Complex pipelines, native table-sparkline formatting and unsupported combinations retain general authoring. Existing drafts and graphs are preserved during installation rather than automatically rewritten. Full native parity, arbitrary providers/models, unaided-user acceptance, production performance, SHC and Cloud approval remain outside this qualification. ## 1.0.1 — October 30, 2026 diff --git a/package-lock.json b/package-lock.json index 5f93a76..04710fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "constellation", - "version": "1.0.1", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "constellation", - "version": "1.0.1", + "version": "1.0.2", "license": "MIT", "dependencies": { "@splunk/dashboard-context": "29.9.0", diff --git a/package.json b/package.json index e9ce362..e9ac3ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "constellation", - "version": "1.0.1", + "version": "1.0.2", "private": true, "type": "module", "scripts": { diff --git a/splunk/constellation/bin/agent_service.py b/splunk/constellation/bin/agent_service.py index ca7c857..0986c07 100644 --- a/splunk/constellation/bin/agent_service.py +++ b/splunk/constellation/bin/agent_service.py @@ -374,6 +374,19 @@ def assist(self, body): if scope is not None and not isinstance(scope, dict): raise ProviderError('Select a valid data context.') if scope and (selected_report or not body.get('dataContext')): scope = dict(scope, earliest=inferred_range(prompt) or scope.get('earliest', '-24h')) + if not document.get('visualizations') and not document.get('dataSources'): + from native_intent import unavailable_requested_types + unavailable = unavailable_requested_types(prompt, environment) + if unavailable: + cards = [] + if unavailable == ['splunk.networkGraph'] and 'splunk.linkgraph' in environment.get('visualizations', []): + alternative = re.sub(r'splunk\.networkGraph', 'splunk.linkgraph', prompt, flags=re.I) + alternative = re.sub(r'\bnetwork[ -]?graphs?\b', 'link graph', alternative, flags=re.I) + if len(alternative) <= 1200: cards = [{'label':'Use a link graph','prompt':alternative,'reason':'Use a relationship chart supported by this instance.'}] + return {'revision':revision,'message':'This instance does not support the requested native chart: '+', '.join(k.removeprefix('splunk.') for k in unavailable)+'. Choose a supported alternative or use a compatible Splunk instance before building.', + 'changes':[],'suggestions':cards if body.get('suggestionFormat')=='cards' else [c['prompt'] for c in cards], + 'repaired':False,'activity':['Checked requested native chart availability before inference'], + 'model':saved['model'],'recovery':recovery.evidence(),'brief':brief,'pagePurposes':purposes} self.progress('profile') profile = data.profile(scope) if scope else None if profile and getattr(getattr(data, '_source_resolver', None), 'used_report', False): @@ -455,9 +468,11 @@ def assist(self, body): context['formattingOnly'] = 'Format only existing numeric columns through formatTable. Omit absent or already-readable timestamps. Do not add aggregates, columns, search or binding edits.' from table_sort import exact_table_sort local_sort = exact_table_sort(prompt, focus.get('id'), document, profile, table_receipt, attachments) + from table_aggregates import exact_table_aggregates + local_aggregate = exact_table_aggregates(prompt,focus.get('id'),document,profile,table_receipt,attachments) from native_events import exact_event_set local_event = exact_event_set(prompt, focus.get('id'), document, attachments) - local_proposal = local_sort or local_event + local_proposal = local_sort or local_event or local_aggregate guidance = retrieve_guidance(prompt, document, environment, real_data=bool(profile), brief=brief, focus=focus) context['retrievedGuidance'] = guidance context['nativeAuthoring'] = authoring_contract(prompt, document, environment, brief, focus) @@ -566,6 +581,21 @@ def assist(self, body): if not format_only and isinstance(result['changes'], list) and any(isinstance(action, dict) and action.get('op') == 'formatTable' for action in result['changes']): raise ProviderError('formatTable is unavailable for this broader edit. Preserve the verified aggregation, add the requested calculation through a search/native query edit and display new output columns in the table projection. Use final SPL eval after aggregation for any requested formatting.') validate_data_claims(result, profile) + if getattr(budget,'board_sources',False): + from board_batches import source_actions, normalize_plan + # Searches are verified in the same caller-scoped recovery + # session, without staging a partial user document. The + # next call receives only recipes/output field metadata. + source_plan=normalize_plan(result['changes'],context) + source_changes=compile_actions(document,source_actions(source_plan,context,server_pool=True),profile) + source_candidate=apply_changes(document,source_changes) + validate_features(source_candidate,document,environment) + self.progress('search',attempt+1) + pool_receipts=data.validate_searches(source_candidate,document,profile) + if attempt==MAX_MODEL_CALLS-1: + raise ProviderError('The verified source pool needs a composition step within the recovery budget.',422,'recovery_budget') + budget.advance_sources(request,document,source_plan,pool_receipts) + continue if route_schema: if not isinstance(result['changes'],list)or len(result['changes'])!=1 or not isinstance(result['changes'][0],dict)or result['changes'][0].get('op')!='route' or any(result['changes'][0].get(key)not in route_schema['properties'][key]['enum']for key in ('sourceId','pageId','field')): raise ProviderError('Return exactly one complete route action using only the sourceId, pageId and verified field listed in routeOnly.',422,'route_plan') @@ -649,6 +679,12 @@ def assist(self, body): result['changes'] = proposal.changes validate_features(draft, document, environment) receipts = data.validate_searches(draft, document, profile) + precision = getattr(data, 'native_corrections', []) + if precision: + draft = proposal.stage(precision) + result['changes'] = proposal.changes + validate_features(draft, document, environment) + receipts = data.validate_searches(draft, document, profile) validate_requested_columns(prompt, body.get('selected', ''), draft, receipts, table_receipt) validate_creation_columns(prompt, draft, document, profile, receipts) if budget.phase == 'complete': validate_sparkline_request(prompt, draft, receipts) @@ -699,7 +735,7 @@ def assist(self, body): profile['independentMeasurements'] = data.independent_populations profile['retainSourceRows'] = retain_source_rows(prompt, brief) profile.update(profile_policy(prompt, brief, environment)) - if getattr(budget, 'compact', False) or getattr(budget, 'native_plan', False) or getattr(budget, 'menu_plan', False): + if getattr(budget, 'compact', False) or getattr(budget, 'native_plan', False) or getattr(budget, 'menu_plan', False) or getattr(budget, 'board_plan', False): # This turn began on an empty verified canvas. Its rejected # composition is transient, never accepted user work. Replan # compactly against the exact original, retaining receipts diff --git a/splunk/constellation/bin/authoring_budget.py b/splunk/constellation/bin/authoring_budget.py index cee05a9..7af8a10 100644 --- a/splunk/constellation/bin/authoring_budget.py +++ b/splunk/constellation/bin/authoring_budget.py @@ -37,6 +37,9 @@ def prepare(self, request, document): self.instructions = request['instructions'] self.schema = copy.deepcopy(request['text']['format']['schema']) context = dict(self.context, definition=model_document(document), modelLimits=dict(self.context.get('modelLimits', {}))) + from dashboard_plan import eligible as board_eligible + self.board_plan = bool(board_eligible(context, document) and all(part.get('type') == 'input_text' for item in request['input'] for part in item['content'])) + if self.board_plan: self.phase = 'complete' if self.phase == 'foundation': context['authoringStage'] = 'INTERNAL FOUNDATION: Build only one useful chart and its search on the first requested page. At most one search and one chart. Give that page its requested purpose. Defer other pages, charts, filters and navigation to the next internal stage. Do not ask the user to split the request. The draft will remain unchanged until all stages pass.' request['max_output_tokens'] = 3500 @@ -100,6 +103,15 @@ def prepare(self, request, document): request['instructions'] = native_instructions(self.native_flat) request['text']['format']['schema']['properties']['changes'].update(items=schema_for(context['request'], self.native_flat), minItems=1, maxItems=1) request['max_output_tokens'] = 4500 + if self.board_plan: + from dashboard_plan import schema_for as board_schema, INSTRUCTIONS as BOARD_INSTRUCTIONS, counts, page_names, page_types + self.compact = self.native_plan = False + request['instructions'] = BOARD_INSTRUCTIONS + request['text']['format']['schema']['properties']['changes'].update(items=board_schema(context), minItems=1, maxItems=1) + pages, panels, per = counts(context['request']) + context['creationRequirements'] = {'pages': pages, 'panels': panels, 'panelsPerPage': per, + 'pageNames': page_names(context['request'], pages), 'maximumExpandedSources': 8} + request['max_output_tokens'] = CREATE_OUTPUT_TOKENS if self.creation and context.get('dataProfile'): request['instructions'] += '\n\n' + CONCISE_CREATION properties = request['text']['format']['schema'].get('properties', {}) @@ -110,8 +122,11 @@ def prepare(self, request, document): for field, maximum in (('label', 48), ('prompt', 200), ('reason', 100)): if field in suggestion: suggestion[field]['maxLength'] = maximum content = request['input'][0]['content'] - if self.native_plan: + if self.native_plan or self.board_plan: context = {key: context[key] for key in ('request', 'definition', 'canvasState', 'environment', 'history', 'focus', 'pagePurposes', 'dashboardBrief', 'modelLimits', 'dataProfile', 'svgAssets') if key in context} + if self.board_plan: + context['creationRequirements'] = {'pages': pages, 'panels': panels, 'panelsPerPage': per, + 'pageNames': page_names(context['request'], pages), 'requiredTypesByPage': page_types(context['request']), 'maximumExpandedSources': 8} from native_creation import bound_profile context['dataProfile'] = bound_profile(context.get('dataProfile')) if self.compact: @@ -196,7 +211,17 @@ def prepare(self, request, document): # contracts are needed only by paths that can actually emit native edits; # specialized query/navigation compilers hold those properties unchanged. context['retrievedGuidance'] = self.context.get('retrievedGuidance', []) - if not (self.compact or self.native_plan or self.svg_plan or any(context.get(flag) for flag in ('formattingOnly', 'rowNavigationOnly', 'routeOnly', 'buttonRouteOnly', 'pageMetadataOnly', 'calculationOnly', 'tableSparklineOnly', 'newMenusOnly'))): + from board_batches import recipe_goal + self.board_batch = self.board_plan and self.provider in ('ollama','aitk') and recipe_goal(context) + self.board_sources = self.board_batch and not hasattr(self,'verified_pool') + if self.board_batch: + from board_batches import source_schema, layout_schema, pool_context, SOURCE_INSTRUCTIONS, LAYOUT_INSTRUCTIONS + request['instructions'] = SOURCE_INSTRUCTIONS if self.board_sources else LAYOUT_INSTRUCTIONS + schema = source_schema(context) if self.board_sources else layout_schema(context,self.verified_pool,self.pool_receipts) + request['text']['format']['schema']['properties']['changes'].update(items=schema,minItems=1,maxItems=1) + request['max_output_tokens'] = min(request['max_output_tokens'],3500 if self.board_sources else 6000) + if not self.board_sources: context['verifiedSourcePool'] = pool_context(self.verified_pool,self.pool_receipts) + if not (self.compact or self.native_plan or self.board_plan or self.svg_plan or any(context.get(flag) for flag in ('formattingOnly', 'rowNavigationOnly', 'routeOnly', 'buttonRouteOnly', 'pageMetadataOnly', 'calculationOnly', 'tableSparklineOnly', 'newMenusOnly'))): if 'nativeAuthoring' in self.context: context['nativeAuthoring'] = self.context['nativeAuthoring'] # A conservative estimate, not a tokenizer or a verified upstream limit. # Drop only rolling history; the durable brief and exact document remain. @@ -222,8 +247,31 @@ def advance(self, request, document): self.phase = 'complete' self.prepare(request, document) + def advance_sources(self, request, document, actions, receipts): + self.verified_pool = copy.deepcopy(actions[0]['sources']) + self.pool_receipts = copy.deepcopy(receipts) + try: + self.prepare(request,document) + except ProviderError: + # A composition-admission failure must still be repairable as a + # source-pool failure, never leave a half-promoted batch behind. + del self.verified_pool + del self.pool_receipts + self.prepare(request,document) + raise + self.stages += 1 + def actions(self, actions, document): """Keep page identity stable when completing this turn's new foundation.""" + if getattr(self, 'board_plan', False): + if getattr(self,'board_batch',False): + from board_batches import expand_layout + return expand_layout(actions,document,self.context,self.verified_pool,self.pool_receipts) + from dashboard_plan import expand + compiled = expand(actions, document, self.context.get('dataProfile'), self.context['request']) + self.plan_summary = {'pages':len(actions[0]['pages']), 'panels':len(actions[0]['panels']), + 'sources':sum(a.get('op')=='search' or (a.get('op')=='set' and a.get('path','').startswith('/dataSources/')) for a in compiled)} + return compiled if self.context.get('reportTransformOnly'): from report_actions import compile_plan return compile_plan(actions, document, self.context) @@ -284,6 +332,15 @@ def actions(self, actions, document): def feedback(self, request, envelope): """Keep the current candidate and latest feedback, not every failed reply.""" + if getattr(self, 'board_plan', False): + from native_creation import bound_profile + envelope = dict(envelope, rejectedOutput='', request='Return ONE complete corrected boardPlan for the SAME original goal. Keep every page, panel, binding and route; reuse compatible sources within the eight-source closure. The server compiles against the ORIGINAL blank document.') + envelope['recoveryFeedback'] = {key: value for key, value in envelope.get('recoveryFeedback', {}).items() if key not in ('candidateDefinition', 'placementHint')} + envelope['recoveryFeedback']['editsApplyTo'] = 'original' + if getattr(self,'board_batch',False): + stage = 'boardSources' if self.board_sources else 'boardLayout' + envelope['request'] = 'Return ONE complete corrected '+stage+' for the SAME original goal. Keep every requested calculation and panel; no partial dashboard has been accepted. '+('Correct the shared source pool before composition.' if self.board_sources else 'Use only the verifiedSourcePool and its actual field names; sources are held by the server.') + if 'dataProfile' in envelope['recoveryFeedback']: envelope['recoveryFeedback']['dataProfile'] = bound_profile(envelope['recoveryFeedback']['dataProfile']) if getattr(self, 'menu_plan', False): from native_creation import bound_profile envelope = dict(envelope, rejectedOutput='', request='Return a complete corrected menu/search plan for the SAME original request. The server recompiles against the original; include every requested new menu and its searches. Preserve all existing work.') @@ -341,6 +398,20 @@ def feedback(self, request, envelope): # The exact staged document already represents the parsed proposal. # Do not resend a second copy in its older action/wire representation. envelope = dict(envelope, rejectedOutput='') + candidate=envelope.get('recoveryFeedback',{}).get('candidateDefinition') + if not self.creation and self.context.get('focus',{}).get('kind')in('visualization','input','page')and isinstance(candidate,dict): + first=request['input'][0]['content'][0] + current=json.loads(first['text']) + if isinstance(current,dict)and 'definition'in current: + # One exact reference document, not original + candidate. + # The verified original focused receipt and durable brief + # remain available; server-side validation is unchanged. + reference=self.context['definition']if envelope['recoveryFeedback'].get('editsApplyTo')=='original'else candidate + current['definition']=model_document(reference) + first['text']=json.dumps(current,separators=(',',':')) + feedback={k:v for k,v in envelope['recoveryFeedback'].items()if k!='candidateDefinition'} + if not re.search(r'\b(?:move|resize|place|reposition|layout|width|height|overlap)\b',self.context['request'],re.I):feedback.pop('placementHint',None) + envelope=dict(envelope,recoveryFeedback=feedback,request='Correct the current request against definition, which holds the exact reference document for editsApplyTo. Preserve verified original focused calculations and all unrelated work. No new changes have been accepted.') request['input'] = request['input'][:1] entry = {'role': 'user', 'content': [{'type': 'input_text', 'text': ''}]} request['input'].append(entry) diff --git a/splunk/constellation/bin/board_batches.py b/splunk/constellation/bin/board_batches.py new file mode 100644 index 0000000..ca8c2fd --- /dev/null +++ b/splunk/constellation/bin/board_batches.py @@ -0,0 +1,205 @@ +"""Verify a larger source pool before asking a smaller model to bind panels. + +Both calls belong to the existing recovery session. No partial dashboard is +staged, persisted or delivered, and indexed values never enter the next prompt. +""" +import copy +import re +from compact_creation import exact, identifier +from creation_recipes import compile_recipe +from dashboard_plan import schema_for, expand, page_types +from measurement_constraints import pipeline_commands +from native_builders import BASIC +from native_intent import requested_types +from provider_service import ProviderError +from planning_sources import shared_stats + + +SOURCE_INSTRUCTIONS = '''Plan ONLY the shared searches for the COMPLETE original +dashboard request. Return message, changes:[ONE {op:"boardSources",sources:[{id, +recipe}]}], suggestions:[]. Do not create pages or panels yet. +The server will verify these searches, then request page composition internally. +Include ALL calculations needed anywhere in the original goal. Prefer a small +shared pool: independent overall KPI aggregates with groupBy:""; a separate +per-entity summary with its verified groupBy; shared timecharts; a raw detail +table only where requested. Reuse outputs rather than one query per tile. +Combine related independent metrics into the same stats/timechart, preserving +nulls and the population of each measure. Reserve room within eight expanded +sources for row-filtered detail clones and any native graph dependencies. +Use ONLY recipes for this basic aggregate task. No pipeline/native actions. +Recipe shapes: {kind:"stats",metrics:[{function:"avg",field:"numeric_input", +alias:"mean_input"}],groupBy:"entity_or_empty"}; {kind:"timechart",metrics:[...]}; +{kind:"table",columns:["_time","entity","measurement"]}. Do not add unused keys. +Metrics: avg,min,max,sum,median,stdev,count,latest,earliest. Each metric has exactly +function,field,alias. Use globally distinct aliases for different calculations. +Input fields must be exact +verified names, never output aliases. Give outputs stable distinct aliases and +include every requested min/max/average/count. Count with field:"" counts all +source observations; count with a measurement field counts that measurement. +An overall KPI source MUST NOT group by entity. Never reduce an overall value +to the last grouped row. A timechart includes _time and every requested series. +Never repeat or replace the server-held base. No entity/token filters: the server +adds destination-local filtering later. The server applies confirmed measurement +null masks; never overwrite, re-extract, refill or filter away a constrained input. +Independent measurements and source observations must retain their populations. +No invented data, health scores or thresholds. This is an internal plan, not a +completed dashboard or save. On feedback return the complete corrected pool for +the SAME goal. Use short stable source IDs and compact aliases; no prose outside +the response object. Actual searches still use caller permissions and existing limits. +''' + +LAYOUT_INSTRUCTIONS = '''Compose the COMPLETE original dashboard using only the +verifiedSourcePool. Return message, changes:[ONE {op:"boardLayout",title, +description,pages:[{label,purpose,columns:1 or 2}],panels:[{id,page:0,type,title, +source,bindings}],links:[{from:"table_id",to:1,field:"verified_entity"}]}],suggestions:[]. +Sources are held on the server: do not emit, replace or modify them. Their fields +are ACTUAL verified output names. Match each panel's intended population, metric +and time grain to the right source. Overall KPIs use ungrouped summary sources; +time trends use timechart outputs, never a per-entity summary. Include EVERY +requested page, chart and calculation exactly once, with the requested names, +membership and purpose. Never substitute a different calculation or drop work. +Bind literal output aliases using the schema channels. For line/area/bar/column +use x for time/category and y for the requested numeric aliases; never mix units +or bind categorical fields as metrics. Tables project their requested columns. +Exact bindings: splunk.line/area/bar/column {x:"output",y:["numeric_output"]}; +splunk.table {columns:["output_fields"]}; splunk.singlevalue {value:"numeric_output"}. +Use exact pool source IDs; choose the output with all required fields, not a +similarly named source. The compiler supplies native geometry and bindings. +For requested row navigation, links uses a TABLE panel id, destination page +index and verified entity field present in its output. The server filters ALL +destination charts before aggregation, keeps Overview independent and adds a +return button. Filtered clones count toward the eight-source expansion limit; +reuse the same sources for overview/detail where calculations match. Emit no +token syntax or separate native changes. Unknown/partial plans fail atomically. +On feedback return ONE complete corrected boardLayout against the original blank +canvas, retaining every requirement. Keep new titles short and each page purpose +one sentence under 100 characters unless the user supplied exact longer wording. +Use one short result sentence and no repeated compliance explanations. +No partial work has been delivered or saved. +''' + + +def recipe_goal(context): + """Keep complex arithmetic/native families on the existing full-plan path.""" + brief=context.get('dashboardBrief',{}) + prompt=context['request']+'\n'+'\n'.join(str(brief.get(k,''))for k in ('purpose','requirements'));types=requested_types(prompt) + for kinds in page_types(prompt).values():types.update(kinds) + if not types<=set(BASIC):return False + complex_goal=r'\b(?:outliers?|percentiles?|p\d{2,3}|forecast\w*|predict\w*|moving|rolling|cumulative|ratios?|rates?|deriv\w*|delta|sparklines?|joins?|lookups?|transactions?|distinct|dc|convert\w*|correlat\w*|split)\b|\btimechart\b[^.!?\n]{0,80}\bby\b' + return not re.search(complex_goal,prompt,re.I) + + +def source_schema(context): + sources = copy.deepcopy(schema_for(context)['properties']['sources']) + recipe=sources['items']['anyOf'][1] + for variant in recipe['properties']['recipe']['anyOf']: + metrics=variant['properties'].get('metrics') + if metrics:metrics['items']=metrics['items']['anyOf'][0] + sources['items']=recipe + return {'type':'object','properties':{'op':{'type':'string','enum':['boardSources']},'sources':sources}, + 'required':['op','sources'],'additionalProperties':False} + + +def source_actions(actions, context, server_pool=False): + if not isinstance(actions,list) or len(actions)!=1: + raise ProviderError('Return one complete boardSources plan for all requested calculations.',422,'board_sources') + action=actions[0];exact(action,('op','sources')) + if action['op']!='boardSources' or not isinstance(action['sources'],list) or not 1<=len(action['sources'])<=8: + raise ProviderError('Use one shared source pool with at most eight searches including room for detail clones.',422,'board_sources') + compiled=[];ids=set() + for source in action['sources']: + if not server_pool and (not isinstance(source,dict)or 'pipeline'in source): + raise ProviderError('Use verified stats/timechart/table recipes for this basic source plan, not raw pipelines.',422,'board_sources') + exact(source,('id','recipe') if isinstance(source,dict)and 'recipe'in source else ('id','pipeline')) + sid=identifier(source['id']) + if sid in ids:raise ProviderError('Give each shared source a unique ID.',422,'board_sources') + ids.add(sid) + if 'recipe'in source: + kind='splunk.line'if isinstance(source['recipe'],dict)and source['recipe'].get('kind')=='timechart'else'splunk.table' + pipeline=compile_recipe(source['recipe'],kind,context['dataProfile'],format_values=False)[0] + else:pipeline=source['pipeline'] + if not isinstance(pipeline,str)or not pipeline.strip().startswith('|'): + raise ProviderError('Use verified recipes or appended pipelines for the shared pool.',422,'board_sources') + compiled.append({'op':'search','id':'ds_plan_'+sid,'pipeline':pipeline}) + return compiled + + +def normalize_plan(actions, context): + """Coalesce independent aggregates before panel choices exist. + + This is a new pool, not an edit to accepted consumers. The next model sees + the combined outputs and chooses explicit bindings against actual receipts. + Complex pipelines and conflicting aliases remain separate. + """ + compiled=source_actions(actions,context);sources=actions[0]['sources'] + pipelines={item['id'][len('ds_plan_'):]:item['pipeline']for item in compiled} + merged=shared_stats(sources,pipelines,[],context['dataProfile'],unbound_pool=True) + result=[];seen=set() + for source in sources: + pipeline=merged[source['id']].strip() + if pipeline in seen:continue + seen.add(pipeline);result.append({'id':source['id'],'pipeline':pipeline}) + return [{'op':'boardSources','sources':result}] + + +def pool_context(sources, receipts): + fields={r['source']:r['fields']for r in receipts} + return [dict(copy.deepcopy(s),fields=fields['ds_plan_'+s['id']]) for s in sources] + + +def layout_schema(context, sources, receipts): + schema=copy.deepcopy(schema_for(context));schema['properties']['op']['enum']=['boardLayout'] + del schema['properties']['sources'];schema['required'].remove('sources') + # Keep the smaller model's schema about this task: ordinary charts plus + # every explicitly requested native family, rather than repeating unrelated + # advanced families for every source. No requested family is removed. + allowed=set(BASIC)|requested_types(context['request']) + for kinds in page_types(context['request']).values():allowed.update(kinds) + variants=[];fields={r['source']:r['fields']for r in receipts} + for source in sources: + names=fields['ds_plan_'+source['id']] + if not names:continue + recipe=source.get('recipe',{});pipeline=source.get('pipeline','') + grouped=bool(recipe.get('groupBy'))or any(re.match(r'(?i)stats\b.*\bBY\s+',c)for _,_,c in pipeline_commands(pipeline)) + scalar_stats=recipe.get('kind')=='stats'or bool(re.match(r'^\s*\|\s*stats\b',pipeline,re.I)) + for template in schema['properties']['panels']['items']['anyOf']: + kind=template['properties']['type']['enum'][0] + if kind not in allowed:continue + if kind=='splunk.singlevalue'and (grouped or not scalar_stats):continue + if kind=='splunk.sankey'and not {'source','target'}<=set(names):continue + item=copy.deepcopy(template);item['properties']['source']['enum']=[source['id']] + for channel,rule in item['properties']['bindings']['properties'].items(): + selected=[n for n in names if channel not in ('y','value','size')or n!='_time'] + if rule['type']=='array':rule['items']['enum']=selected or names + else:rule['enum']=(['']if rule.get('minLength')==0 else[])+(selected or names) + variants.append(item) + if not variants:raise ProviderError('The verified pool has no usable native panel bindings.',422,'board_sources') + required=requested_types(context['request']) + for kinds in page_types(context['request']).values():required.update(kinds) + missing=required-{v['properties']['type']['enum'][0]for v in variants} + if missing:raise ProviderError('The verified source pool lacks the output columns needed for '+', '.join(sorted(missing))+'. Correct the pool for every requested chart before composition.',422,'board_sources') + schema['properties']['panels']['items']['anyOf']=variants + return schema + + +def expand_layout(actions, document, context, sources, receipts=None): + if not isinstance(actions,list)or len(actions)!=1: + raise ProviderError('Return one complete boardLayout using the verified source pool.',422,'board_layout') + action=actions[0];exact(action,('op','title','description','pages','panels','links')) + if action['op']!='boardLayout':raise ProviderError('Use boardLayout with the existing verified source pool.',422,'board_layout') + if receipts is not None: + known={r['source'][len('ds_plan_'):]:set(r['fields'])for r in receipts} + by_id={s['id']:s for s in sources} + for panel in action['panels'] if isinstance(action['panels'],list)else[]: + if not isinstance(panel,dict)or not isinstance(panel.get('source'),str)or not isinstance(panel.get('bindings'),dict):continue + fields=set() + for value in panel['bindings'].values(): + if isinstance(value,str)and value:fields.add(value) + elif isinstance(value,list):fields.update(v for v in value if isinstance(v,str)and v) + available=known.get(panel['source'],set());missing=fields-available + if missing:raise ProviderError('Panel '+str(panel.get('id',''))[:100]+' selects '+panel['source'][:100]+' without '+', '.join(sorted(missing))[:300]+'. Choose the verified source containing those outputs; available here: '+', '.join(sorted(available))[:500]+'. A grouped summary is not a timechart.',422,'board_bindings') + if panel.get('type')=='splunk.singlevalue': + source=by_id.get(panel['source'],{});recipe=source.get('recipe',{});pipeline=source.get('pipeline','') + scalar_stats=recipe.get('kind')=='stats'or bool(re.match(r'^\s*\|\s*stats\b',pipeline,re.I)) + if not scalar_stats:raise ProviderError('Overall KPI cards need the verified ungrouped stats source, not a timechart bucket or raw row.',422,'board_bindings') + return expand([dict(action,op='boardPlan',sources=copy.deepcopy(sources))],document,context['dataProfile'],context['request']) diff --git a/splunk/constellation/bin/creation_recipes.py b/splunk/constellation/bin/creation_recipes.py index f24d119..cf79204 100644 --- a/splunk/constellation/bin/creation_recipes.py +++ b/splunk/constellation/bin/creation_recipes.py @@ -48,7 +48,7 @@ FIELD = r'[A-Za-z_][A-Za-z0-9_]*' -def compile_recipe(recipe, chart_type, profile): +def compile_recipe(recipe, chart_type, profile, format_values=True): if not isinstance(recipe, dict): raise ProviderError('Use one documented search recipe object.') required = {'stats': {'kind', 'metrics', 'groupBy'}, 'timechart': {'kind', 'metrics'}, 'table': {'kind', 'columns'}}.get(recipe.get('kind') if isinstance(recipe.get('kind'), str) else '') @@ -60,7 +60,7 @@ def compile_recipe(recipe, chart_type, profile): known = {f['name']: f for f in profile.get('fields', [])} def field(value): if not isinstance(value, str) or not re.fullmatch(FIELD, value) or value not in known: - raise ProviderError('Use exact verified literal input fields in the search recipe.') + raise ProviderError('Use exact verified literal input fields in the search recipe, not aggregate output aliases. Available inputs: '+', '.join(sorted(known))[:600]) return value kind, metrics, group, columns = (recipe[k] for k in RECIPE['required']) if kind not in ('stats', 'timechart', 'table') or not isinstance(metrics, list) or not isinstance(columns, list) or not isinstance(group, str): @@ -76,7 +76,7 @@ def field(value): if kind == 'timechart' and group: raise ProviderError('A timechart recipe uses groupBy:"" to keep its declared metric aliases. Row navigation already filters its device; only stats recipes may group by a field. Preserve this trend and its metrics.') if group: field(group) - aliases, expressions, formatting = [], [], [] + aliases, expressions, formatting, copies, canonical = [], [], [], [], {} for metric in metrics: sparkline = isinstance(metric, dict) and metric.get('function') == 'sparkline' required_metric = set(SPARKLINE_METRIC['required']) if sparkline else {'function', 'field', 'alias'} @@ -105,12 +105,15 @@ def field(value): raise ProviderError('Recipe metric ' + alias + ': ' + function + '(' + value + ') requires an inspected numeric input field. Preserve the metric; use a native timestamp aggregate for _time.') expression = function + '(' + value + ')' if sparkline: expression = 'sparkline(' + expression + ',' + metric['span'] + ')' - expressions.append(expression + ' AS ' + alias);aliases.append(alias) - if chart_type == 'splunk.table' and value and not sparkline: + if expression in canonical:copies.append(alias+'='+canonical[expression]) + else:expressions.append(expression+' AS '+alias);canonical[expression]=alias + aliases.append(alias) + if format_values and chart_type == 'splunk.table' and value and not sparkline: timestamp = value == '_time' and function in ('min', 'max', 'latest', 'earliest') and (known[value].get('numeric') is True or profile.get('scope', {}).get('index') and not profile.get('scope', {}).get('query')) if timestamp: formatting.append(alias + '=strftime(' + alias + ',"%Y-%m-%d %H:%M:%S")') elif function != 'count' and known[value].get('numeric') is True: formatting.append(alias + '=round(' + alias + ',2)') pipeline = '| ' + kind + (' bins=100' if kind == 'timechart' else '') + ' ' + ' '.join(expressions) + (' BY ' + group if group else '') + if copies:pipeline += ' | eval '+', '.join(copies) if formatting: pipeline += ' | eval ' + ', '.join(formatting) if chart_type == 'splunk.table': return pipeline, '', (['_time'] if kind == 'timechart' else [group] if group else []) + aliases if chart_type == 'splunk.singlevalue': diff --git a/splunk/constellation/bin/dashboard_plan.py b/splunk/constellation/bin/dashboard_plan.py new file mode 100644 index 0000000..1d727dc --- /dev/null +++ b/splunk/constellation/bin/dashboard_plan.py @@ -0,0 +1,290 @@ +"""Larger first drafts with shared searches and explicit page membership. + +The model chooses meaning, calculations and membership. This compiler owns +native bindings, geometry, source reuse and destination-local row navigation. +All existing native/search/intent checks run on the complete atomic proposal. +""" +import copy +import json +import re +from compact_creation import empty_canvas, exact, identifier +from creation_strategy import explicit_panel_count +from creation_recipes import RECIPE_PANEL, compile_recipe +from native_builders import CHANNELS, binding_schema, native_options, network_nodes, network_edges +from native_intent import requested_types +from provider_service import ProviderError + +MAX_PAGES, MAX_PANELS, MAX_SOURCES = 8, 24, 8 +WORDS = {'one':1,'two':2,'three':3,'four':4,'five':5,'six':6,'seven':7,'eight':8} +NUMBER = r'(?:one|two|three|four|five|six|seven|eight|[1-9][0-9]?)' + +def number(value): return WORDS.get(value.lower(), int(value) if value.isdigit() else 0) + +def counts(prompt): + pages = {number(v) for v in re.findall(r'\b('+NUMBER+r')[ -](?:named\s+|distinct\s+|separate\s+)?pages?\b', prompt, re.I)} + if len(pages) != 1: return None + pages = next(iter(pages));total = explicit_panel_count(prompt) + per = {number(v) for v in re.findall(r'\b('+NUMBER+r')\s+(?:charts?|panels?|tiles?|visualizations?)\s+(?:on\s+each|per)\s+page\b', prompt, re.I)} + if len(per) > 1: return None + per = next(iter(per)) if per else None + if per: + explicit = {number(v) for v in re.findall(r'\bexactly\s+('+NUMBER+r')\s+(?:total\s+)?(?:charts?|panels?|tiles?|visualizations?)\b',prompt,re.I)} + if explicit and explicit != {pages * per}: return None + total = pages * per + return (pages, total, per) if total and 1 <= pages <= MAX_PAGES and pages <= total <= MAX_PANELS else None + + +def page_names(prompt, count): + # Only an explicit quoted list is deterministic; prose names stay with the + # general model and existing intent checks rather than guessed extraction. + match = re.search(r'\bpages?\s+(?:named|called)\s+([^\n.!?]+)', prompt, re.I) + if not match: return [] + names = re.findall(r'["“]([^"”]+)["”]', match[1]) + return names if len(names) == count and len(set(names)) == count else [] + + +def page_types(prompt): + result = {} + for name, clause in re.findall(r'(?im)^\s*(?:On|In)\s+["“]([^"”]+)["”]\s*[:,]?\s+([^\n]+)', prompt): + kinds = requested_types('Create '+clause) + for term, kind in [('line','line'),('area','area'),('bar','bar'),('column','column'),('table','table'),('single[ -]value','singlevalue')]: + if re.search(r'\b'+term+(r'\b' if kind in ('table','singlevalue') else r'\s+(?:chart|trend)\b'), clause, re.I): kinds.add('splunk.'+kind) + if kinds: result.setdefault(name, set()).update(kinds) + return {name:sorted(kinds) for name,kinds in result.items()} + + +def eligible(context, document): + count = counts(context['request']);profile = context.get('dataProfile', {}) + if not count or not empty_canvas(document) or profile.get('scope', {}).get('language', 'spl') != 'spl' or profile.get('scope', {}).get('report'): return False + pages, panels, _ = count + if pages <= 4 and panels <= 8 and 'splunk.networkGraph' not in requested_types(context['request']): return False + if not requested_types(context['request']) <= set(CHANNELS): return False + brief = context.get('dashboardBrief', {}) + prompt = context['request'] + '\n' + '\n'.join(str(brief.get(k, '')) for k in ('purpose','requirements')) + # Admission only: explicit prohibitions are not requests for unsupported + # styling/assets. The unchanged original goal/brief still reaches the model + # and every validator; positive clauses after a semicolon remain visible. + clauses = re.split(r'(?<=[.!?;])\s+|\n', prompt) + prompt = '\n'.join(c for c in clauses if not re.match(r'\s*(?:no|avoid|never|without|do not|don.t)\b', c, re.I)) + if any('splunk.'+name not in CHANNELS for name in re.findall(r'\bsplunk\.([A-Za-z][A-Za-z0-9_.]*)', prompt)): return False + advanced = r'\b(?:dropdown|multiselect|cascad\w*|trellis|auto[- ]?refresh|conditional|visibility|markdown|images?|sketch|PDF|SPL2|uploads?|icons?|pixels?|width|height|colors?|colou?rs?|thresholds?|columnFormat|tokens?|scatter|gauges?|funnel|singlevalueicon|singlevalueradial|annotations?|rectangles?|ellipses?|richtext|legend|styling|style|stacked|stacking|precision|decimals?|theme|palette|formatting|sparklines?)\b|\$' + if re.search(r'\b(?:no|without)\s+(?:(?:return|back)\s+)?buttons?\b|\bfilter\s+only\s+(?:one|the)\b|\b(?:shared|global)\s+(?:entity\s+)?filter\b|\bbutton[^.!?]{0,40}\b(?:named|labelled|labeled|called)\b', prompt, re.I): return False + return not re.search(advanced, prompt, re.I) + + +SOURCE = {'anyOf': [ + {'type':'object','properties':{'id':{'type':'string'},'pipeline':{'type':'string'}},'required':['id','pipeline'],'additionalProperties':False}, + {'type':'object','properties':{'id':{'type':'string'},'recipe':copy.deepcopy(RECIPE_PANEL['properties']['recipe'])},'required':['id','recipe'],'additionalProperties':False}, +]} +INSTRUCTIONS = '''Create the COMPLETE current dashboard with one boardPlan action: +{op:"boardPlan",title,description,pages:[{label,purpose,columns:1 or 2}], +sources:[{id,pipeline} OR {id,recipe}],panels:[{id,page:0,type,title,source,bindings}], +links:[{from:"summary_table_id",to:1,field:"verified_entity"}]}. +Page membership is an integer index; honor every requested name, count, purpose, +chart, calculation and exclusion. Declare every panel exactly once. No empty pages. +Sources are a SHARED POOL, not one search per tile. Reuse one aggregate for several +KPI/table/chart consumers whenever their population and output are the same. +An overall KPI needs ungrouped stats. A per-entity summary is a DIFFERENT source +with groupBy; never bind an overall single value to a grouped output's last row. +At most eight expanded sources, including filtered detail clones and network node +sources. Plan fewer base searches when links or a network graph need that space. +Never omit requested work to meet a budget; correct the shared plan on feedback. +A source uses pipeline starting with | appended to the verified server-held base, +OR a recipe. Never repeat the base or supply alternate index/source selectors. +Recipes: stats {kind:"stats",metrics:[{function:"avg",field:"verified_numeric",alias:"mean"}],groupBy:"entity_or_empty"}; +timechart {kind:"timechart",metrics:[...]} (combined aliases, no groupBy); +table {kind:"table",columns:["_time","verified_entity","verified_measurement"]}. +Metrics: avg,min,max,sum,median,stdev,count,latest,earliest; count field:"" counts +all events, count with a field counts its observations. Only a source calculation outside recipes uses pipeline. Use explicit aliases and +SPL strings in double quotes; no SQL WHERE in stats. Preserve missing measurements. +The server applies confirmed measurement null masks before each new pipeline; +never overwrite, recast, re-extract or refill the constrained input. Independent +Wi-Fi/other measurements and source events must remain independent. +Bindings by chart type (actual OUTPUT names, not category values): +line/area/bar/column {x:"_time_or_category",y:["numeric_alias"]}; for an EXPLICIT +split timechart BY use x:"_time",y:[] so the compiler selects actual split columns, +including whatever categories exist. Never name unobserved severity columns. +table {columns:["visible_output_fields"]}, [] for all returned columns; +singlevalue {value:"one_numeric_alias"}; pie {label:"category",value:"weight"}; +sankey {value:"weight"}, with EXACT source,target output columns; +punchcard {x:"category",y:"category",size:"weight"}; +timeline {x:"_time_or_ISO",y:"lane",duration:"milliseconds_or_empty",category:"field_or_empty"}; +parallelcoordinates {} with source projection category FIRST, then only numeric axes; +linkgraph {fields:["first","next"]}; networkGraph {source:"from_field",target:"to_field"}. +Network endpoints use literal output aliases. The server creates a node chain from +BOTH endpoint sets, aligned labels/values and uniform node size. +Two auxiliary sources are needed per distinct network edge/binding pair: an +edge-membership chain and an aligned node-styling chain. These are observed +relationships, not invented causal dependencies or traffic topology. +links:[] unless requested. A row link uses a TABLE panel id, destination PAGE INDEX +and verified entity field in the table output. The compiler filters ALL destination +sources before aggregation, isolates them from Overview and adds a return button. +Do not author token syntax or entity filters in pipelines. If a source is shared +with Overview, the detail clone consumes another source slot. Keep descriptions +and purposes concise. The compiler supplies readable native geometry and bindings. +Context is metadata, not event rows: never claim observed trends or a completed +save. Existing native, version, search, scope, measurement, output, placement and +intent validators run before ATOMIC acceptance. Unknown fields and partial plans +are rejected, never truncated. Return short message,changes:[ONE boardPlan],suggestions:[]. +On feedback return ONE complete corrected plan against the ORIGINAL blank canvas, +retaining every requirement. Rejected staged work is not accepted user work. +''' + + +def schema_for(context): + pages, panels, _ = counts(context['request']) + variants = [] + for kind in CHANNELS: + environment = context.get('environment', {}) + advertised = environment.get('visualizations') + if isinstance(advertised, list) and kind not in advertised: continue + if kind == 'splunk.networkGraph' and environment.get('features', {}).get('networkGraph') is False: continue + properties = {'id':{'type':'string'},'page':{'type':'integer','enum':list(range(pages))}, + 'type':{'type':'string','enum':[kind]},'title':{'type':'string'},'source':{'type':'string'}, + 'bindings':binding_schema(kind)} + variants.append({'type':'object','properties':properties,'required':list(properties),'additionalProperties':False}) + source_schema = copy.deepcopy(SOURCE) + for variant in source_schema['anyOf'][1]['properties']['recipe']['anyOf']: + metrics=variant['properties'].get('metrics') + if metrics:metrics['items']['anyOf']=metrics['items']['anyOf'][:1] + known = sorted({f['name'] for f in context.get('dataProfile', {}).get('fields', [])}) + if known: + recipe = source_schema['anyOf'][1]['properties']['recipe'] + for variant in recipe.get('anyOf', [recipe]): + properties = variant.get('properties', {}) + if 'metrics' in properties: + for metric in properties['metrics']['items'].get('anyOf', [properties['metrics']['items']]): + metric['properties']['field']['enum'] = ['', *known] + if 'groupBy' in properties: properties['groupBy']['enum'] = ['', *known] + if 'columns' in properties: properties['columns']['items']['enum'] = known + props = {'op':{'type':'string','enum':['boardPlan']},'title':{'type':'string'},'description':{'type':'string'}, + 'pages':{'type':'array','minItems':pages,'maxItems':pages,'items':{'type':'object','properties':{ + 'label':{'type':'string'},'purpose':{'type':'string'},'columns':{'type':'integer','enum':[1,2]}}, + 'required':['label','purpose','columns'],'additionalProperties':False}}, + 'sources':{'type':'array','minItems':1,'maxItems':MAX_SOURCES,'items':source_schema}, + 'panels':{'type':'array','minItems':panels,'maxItems':panels,'items':{'anyOf':variants}}, + 'links':{'type':'array','maxItems':4,'items':{'type':'object','properties':{ + 'from':{'type':'string'},'to':{'type':'integer','enum':list(range(pages))},'field':{'type':'string'}}, + 'required':['from','to','field'],'additionalProperties':False}}} + return {'type':'object','properties':props,'required':list(props),'additionalProperties':False} + + +def expand(actions, document, profile, prompt): + def fail(message): raise ProviderError(message, 422, 'board_plan') + if not isinstance(actions, list) or len(actions) != 1 or not isinstance(actions[0], dict) or actions[0].get('op') != 'boardPlan': + fail('Return ONE complete boardPlan against the original blank canvas.') + if not empty_canvas(document) or not profile or profile.get('scope', {}).get('language', 'spl') != 'spl' or profile.get('scope', {}).get('report'): + fail('Board planning requires the original empty inspected SPL canvas.') + action = actions[0];exact(action, ('op','title','description','pages','sources','panels','links')) + expected = counts(prompt) + if not expected: fail('Use a bounded explicit page/chart count for board planning.') + pages, total, per = expected + if not isinstance(action['pages'], list) or len(action['pages']) != pages or not isinstance(action['panels'], list) or len(action['panels']) != total: + fail('Complete all '+str(pages)+' pages and '+str(total)+' panels; do not repeat the full chart list on each page.') + if not isinstance(action['sources'], list) or not 1 <= len(action['sources']) <= MAX_SOURCES or not isinstance(action['links'], list) or len(action['links']) > 4: + fail('Plan at most eight sources including dependencies and four row routes; reuse common outputs.') + names = page_names(prompt, pages) + for index, page in enumerate(action['pages']): + exact(page, ('label','purpose','columns')) + if (not isinstance(page['label'], str) or not 1 <= len(page['label']) <= 200 or not isinstance(page['purpose'], str) + or not 1 <= len(page['purpose']) <= 1200 or type(page['columns']) is not int or page['columns'] not in (1,2)): + fail('Give each page its requested readable name, purpose and one/two columns.') + if names and page['label'] != names[index]: fail('Preserve the requested page names and order: '+', '.join(names)) + if len({p['label'].casefold() for p in action['pages']}) != pages: fail('Give requested pages distinct names.') + sources = {};declared = set() + consumed = {p.get('source') for p in action['panels'] if isinstance(p,dict) and isinstance(p.get('source'),str)} + for source in action['sources']: + exact(source, ('id','recipe') if isinstance(source,dict) and 'recipe' in source else ('id','pipeline')) + sid = identifier(source['id']) + if sid in declared: fail('Use unique source IDs.') + declared.add(sid) + # Dead declarations are model staging on a blank canvas, not user work. + # Do not compile/dispatch an unused placeholder. Every requested panel + # and its actual consumed output still passes all final validators. + if sid not in consumed: continue + if 'recipe' in source: + chart_type = 'splunk.line' if isinstance(source['recipe'], dict) and source['recipe'].get('kind') == 'timechart' else 'splunk.table' + pipeline = compile_recipe(source['recipe'], chart_type, profile, format_values=False)[0] + else: pipeline = source['pipeline'] + if not isinstance(pipeline, str) or not pipeline.strip().startswith('|'): fail('Each source needs an appended pipeline or verified recipe.') + sources[sid] = pipeline + panels = {};membership = [[] for _ in range(pages)] + for panel in action['panels']: + exact(panel, ('id','page','type','title','source','bindings'));pid = identifier(panel['id']) + if pid in panels or type(panel['page']) is not int or not 0 <= panel['page'] < pages or panel['source'] not in sources or panel['type'] not in CHANNELS: + fail('Use distinct panels, declared sources, supported types and existing page indexes.') + if not isinstance(panel['title'], str) or not 1 <= len(panel['title']) <= 200: fail('Give each panel a readable metric/units title.') + panels[pid] = panel;membership[panel['page']].append(pid) + if any(not m or (per and len(m) != per) for m in membership): fail('Put every requested chart on its intended page; each page needs its requested panel count.') + required_types = page_types(prompt) + for index, page in enumerate(action['pages']): + missing = set(required_types.get(page['label'], [])) - {panels[pid]['type'] for pid in membership[index]} + if missing: fail('Page '+page['label']+' still needs its requested native families: '+', '.join(sorted(missing))+'. Preserve page membership; a chart elsewhere does not fulfill this page.') + from planning_sources import shared_stats + sources = shared_stats([s for s in action['sources'] if s['id'] in sources], sources, list(panels.values()), profile) + routes = {};origins = set();known = {f['name'] for f in profile.get('fields', [])} + for link in action['links']: + exact(link, ('from','to','field'));source = panels.get(link['from']) + if (not source or source['type'] != 'splunk.table' or link['from'] in origins or type(link['to']) is not int + or not 0 <= link['to'] < pages or link['to'] == source['page'] or link['field'] not in known + or not re.fullmatch(r'[A-Za-z_][A-Za-z0-9_]*', link['field'])): + fail('Connect a declared summary table to another page using its verified literal entity field.') + if link['to'] in routes: fail('Give each row destination one unambiguous source route in this initial plan.') + routes[link['to']] = link;origins.add(link['from']) + taken=set(document.get('expressions',{}));route_tokens={} + token_defaults=document.get('defaults',{}).get('tokens',{}) if routes else {} + if not isinstance(token_defaults,dict):fail('Preserve nonstandard native token defaults with general native authoring.') + for values in token_defaults.values(): + if isinstance(values,dict):taken.update(values) + for page in routes: + base='select_page_'+str(page);token=base;number=2 + while token in taken:token=base+'_'+str(number);number+=1 + route_tokens[page]=token;taken.add(token) + changes = [{'op':'dashboard','title':action['title'],'description':action['description']}] + pool = {};panel_sources = {};used_ids = set();node_pool = {} + for pid,panel in panels.items(): + route = routes.get(panel['page']);filter_key = (route['field'],route_tokens[panel['page']]) if route else None + key = (sources[panel['source']].strip(), filter_key) + if key not in pool: + sid = 'ds_plan_'+panel['source']+('_p'+str(panel['page']) if route else '') + if sid in used_ids: fail('Source IDs collide after page isolation; use shorter distinct IDs.') + used_ids.add(sid);pool[key] = sid + changes.append({'op':'search','id':sid,'pipeline':sources[panel['source']]}) + if route: changes.append({'op':'filter','sourceId':sid,'field':filter_key[0],'token':filter_key[1]}) + panel_sources[pid] = pool[key] + for pid,panel in panels.items(): + if panel['type'] == 'splunk.singlevalue': + from measurement_constraints import pipeline_commands + if any(re.match(r'(?i)stats\b.*\bBY\s+', command) for _,_,command in pipeline_commands(sources[panel['source']])): + fail('An overall single-value panel needs an ungrouped stats output, not the last row of a per-entity summary. Share one ungrouped aggregate among the KPI cards and keep grouped summaries separate.') + sid = panel_sources[pid];options = native_options(panel['type'], panel['bindings'], sources[panel['source']]);aliases = {'primary':sid} + if panel['type'] == 'splunk.networkGraph': + key = (sid,panel['bindings']['source'],panel['bindings']['target']) + if key not in node_pool: + node_id = 'nodes_'+pid;edge_id = 'edges_'+pid;node_source,node_options = network_nodes(sid,panel['bindings']);node_pool[key]=(node_id,edge_id,node_options) + changes.append({'op':'set','path':'/dataSources/'+node_id,'value':json.dumps(node_source)}) + changes.append({'op':'set','path':'/dataSources/'+edge_id,'value':json.dumps(network_edges(sid,panel['bindings']))}) + node_id,edge_id,node_options = node_pool[key];aliases.update(primary=edge_id,nodeSource=node_id);options.update(node_options) + visualization = {'type':panel['type'],'title':panel['title'],'options':options,'dataSources':aliases} + changes.append({'op':'set','path':'/visualizations/'+pid,'value':json.dumps(visualization)}) + if len(pool)+2*len(node_pool) > MAX_SOURCES: + fail('The expanded plan needs '+str(len(pool)+2*len(node_pool))+' affected sources; the limit is eight including filtered clones and network node dependencies. Reuse shared compatible aggregates; keep every requested page and chart.') + for index,page in enumerate(action['pages']): + items=[];row=column=0 + for pid in membership[index]: + panel=panels[pid];wide = page['columns']==1 or panel['type'] in ('splunk.table','splunk.networkGraph','splunk.sankey','splunk.parallelcoordinates','splunk.timeline') + if wide and column:row+=1;column=0 + items.append({'id':pid,'kind':'block','x':20+590*column,'y':20+380*row,'w':1160 if wide else 570,'h':360}) + column += page['columns'] if wide else 1 + if column >= page['columns']:row+=1;column=0 + bottom=20+(row+bool(column))*380 + changes.append({'op':'page','layoutId':'layout_board_'+str(index),'label':page['label'],'purpose':page['purpose'],'moveItems':False, + 'width':1200,'height':bottom+120 if index in routes else bottom+20,'items':items}) + if index in routes: + link=routes[index];token=route_tokens[index];origin=panels[link['from']]['page'] + changes.extend([{'op':'token','name':token,'value':'*'}, + {'op':'link','sourceId':link['from'],'pageId':'layout_board_'+str(index),'targetId':membership[index][0],'field':link['field'],'token':token}, + {'op':'button','id':'back_board_'+str(index),'label':('Back to '+action['pages'][origin]['label'])[:100], + 'pageId':'layout_board_'+str(index),'targetPageId':'layout_board_'+str(origin),'targetId':'','x':20,'y':bottom,'w':300,'h':80}]) + if len(changes)>64: fail('Keep the full expanded board within the existing 64-action bound; share sources instead of dropping requested work.') + return changes diff --git a/splunk/constellation/bin/data_service.py b/splunk/constellation/bin/data_service.py index ebb9045..f841897 100644 --- a/splunk/constellation/bin/data_service.py +++ b/splunk/constellation/bin/data_service.py @@ -226,9 +226,17 @@ def validate_searches(self, document, previous, profile): for identifier, item in document.get('inputs', {}).items(): if item != previous.get('inputs', {}).get(identifier): needed.update(item.get('dataSources', {}).values()) - pending = [(identifier, source) for identifier, source in document.get('dataSources', {}).items() - if source != previous.get('dataSources', {}).get(identifier) or identifier in needed] - if len(pending) > 8: raise ProviderError('Build at most eight new search sources in one turn.') + sources = document.get('dataSources', {}) + affected = {key for key, value in sources.items() if value != previous.get('dataSources', {}).get(key)} + # A changed parent also changes every native chain extending it, even + # when that child and its consuming chart have no literal JSON edits. + while True: + children = {key for key, value in sources.items() if value.get('type') == 'ds.chain' + and (value.get('options', {}).get('extend') or value.get('extend')) in affected} + if children <= affected: break + affected.update(children) + pending = [(identifier, source) for identifier, source in sources.items() if identifier in affected or identifier in needed] + if len(pending) > 8: raise ProviderError('Validate at most eight affected search sources in one turn, including reused sources and auxiliary dependencies. Share compatible outputs or use a smaller affected source set; preserve every requested chart.') problems = [] for identifier, source in pending: try: @@ -305,9 +313,11 @@ def validate_searches(self, document, previous, profile): if missing: problems.append('Native ' + root + ' ' + identifier[:100] + ', ' + path[:160] + ': missing actual source fields ' + ', '.join(sorted(missing))[:180] + '. Use verified output aliases and preserve existing calculations.') if root == 'visualizations': - changed = item != previous.get('visualizations', {}).get(identifier) or any(source in needed or document.get('dataSources', {}).get(source) != previous.get('dataSources', {}).get(source) for source in item.get('dataSources', {}).values()) + changed = item != previous.get('visualizations', {}).get(identifier) or any(source in needed or source in affected for source in item.get('dataSources', {}).values()) try: validate_shape(self.media.validation_item(item) if changed else item, outputs) except ProviderError as error: problems.append(str(error)) if problems: raise ProviderError('\n'.join(problems[:16])[:10000]) + from native_builders import verified_precision + self.native_corrections = verified_precision(document, previous, outputs) return receipts diff --git a/splunk/constellation/bin/native_builders.py b/splunk/constellation/bin/native_builders.py new file mode 100644 index 0000000..7496dbe --- /dev/null +++ b/splunk/constellation/bin/native_builders.py @@ -0,0 +1,138 @@ +"""Provider-neutral native bindings for bounded new-board plans. + +No search execution or inferred data relationships. Native shape/version/source +validators still inspect the expanded document before atomic acceptance. +""" +import json +import math +import re +from measurement_constraints import pipeline_commands +from provider_service import ProviderError + +BASIC = {'splunk.line', 'splunk.area', 'splunk.bar', 'splunk.column', 'splunk.table', 'splunk.singlevalue'} +CHANNELS = { + **{kind: {'x': 'field', 'y': 'fields'} for kind in sorted(BASIC - {'splunk.table', 'splunk.singlevalue'})}, + 'splunk.table': {'columns': 'fields'}, 'splunk.singlevalue': {'value': 'field'}, + 'splunk.sankey': {'value': 'field'}, 'splunk.pie': {'label': 'field', 'value': 'field'}, + 'splunk.punchcard': {'x': 'field', 'y': 'field', 'size': 'field'}, + 'splunk.timeline': {'x': 'field', 'y': 'field', 'duration': 'optional', 'category': 'optional'}, + 'splunk.parallelcoordinates': {}, 'splunk.linkgraph': {'fields': 'fields'}, + 'splunk.networkGraph': {'source': 'field', 'target': 'field'}, +} + + +def binding_schema(kind): + properties = {} + for name, form in CHANNELS[kind].items(): + field = {'type': 'string', 'minLength': 1, 'maxLength': 200} + properties[name] = ({'type': 'array', 'maxItems': 80 if kind == 'splunk.table' else 8, + 'items': field} if form == 'fields' else dict(field, minLength=0 if form == 'optional' else 1)) + return {'type': 'object', 'properties': properties, 'required': list(properties), 'additionalProperties': False} + + +def selector(fields, frame=False, alias='primary'): + return '> ' + alias + ' | ' + ('frameBySeriesNames' if frame else 'seriesByName') + '(' + ', '.join(json.dumps(f) for f in fields) + ')' + + +def native_options(kind, bindings, pipeline): + if kind not in CHANNELS or not isinstance(bindings, dict) or set(bindings) != set(CHANNELS[kind]): + raise ProviderError('Use the documented binding channels for each planned native chart.', 422, 'board_bindings') + for key, form in CHANNELS[kind].items(): + value = bindings[key]; values = value if form == 'fields' else [value] + if (form == 'fields' and (not isinstance(value, list) or len(value) > (80 if kind == 'splunk.table' else 8)) + or not isinstance(values, list) or any(not isinstance(v, str) or len(v) > 200 + or any(ord(c) < 32 for c in v) or (not v and form != 'optional') for v in values) + or len(set(values)) != len(values)): + raise ProviderError('Select distinct literal output fields for native bindings.', 422, 'board_bindings') + if kind == 'splunk.table': + return {'table': selector(bindings['columns'], True) if bindings['columns'] else '> primary'} + if kind == 'splunk.singlevalue': + options = {'majorValue': selector([bindings['value']]) + ' | lastPoint()'} + commands = [c for _, _, c in pipeline_commands(pipeline)] + # A grouped/scalar stats result has no chronological sparkline. Never + # change genuine timechart-backed single values or existing native work. + if any(re.match(r'(?i)stats\b', c) for c in commands) and not any(re.match(r'(?i)timechart\b', c) for c in commands): + options.update(sparklineDisplay='off', trendDisplay='off') + return options + if kind in BASIC: + if not bindings['y']: + commands = [c for _, _, c in pipeline_commands(pipeline)] + if bindings['x'] != '_time' or not any(re.match(r'(?i)timechart\b.*\bBY\s+', c) for c in commands): + raise ProviderError('An empty y list is only for an explicitly split timechart. Otherwise name every numeric output series.', 422, 'board_bindings') + y = '> primary | frameBySeriesIndexRange(1)' + else: y = selector(bindings['y'], True) + return {'x': selector([bindings['x']]), 'y': y} + if kind == 'splunk.sankey': return {'linkValues': selector([bindings['value']])} + if kind == 'splunk.linkgraph': + if len(bindings['fields']) < 2: raise ProviderError('Link graphs need at least two ordered output fields.', 422, 'board_bindings') + return {'fieldOrder': bindings['fields']} + if kind == 'splunk.parallelcoordinates': return {} + return {key: selector([field]) for key, field in bindings.items() if field} + + +def network_nodes(source_id, bindings): + """Node membership comes from both actual endpoint columns, not defaults. + + links counts endpoint occurrences in the aggregated topology, not event or + traffic volume. Uniform node size avoids implying a business measurement. + """ + fields = [bindings[key] for key in ('source', 'target')] + if any(not re.fullmatch(r'[A-Za-z_][A-Za-z0-9_]*', f) for f in fields): + raise ProviderError('Give the planned network endpoints literal output aliases before binding them.', 422, 'board_bindings') + query = '| eval constellation_node=mvappend(' + ','.join(fields) + ') | mvexpand constellation_node | where isnotnull(constellation_node) | stats count AS links BY constellation_node | rename constellation_node AS id | table id links' + source = {'type': 'ds.chain', 'options': {'extend': source_id, 'query': query}} + options = {'nodeIds': selector(['id'], alias='nodeSource'), 'nodeTexts': selector(['id'], alias='nodeSource'), + 'nodeValues': selector(['links'], alias='nodeSource'), 'nodeSize': 28, 'linkWidth': 2, + 'layout': 'grid', 'showDirection': 'oneWay'} + return source, options + + +def network_edges(source_id, bindings): + """Native membership is inferred from source, independently of nodeIds. + + Preserve each actual edge once and add only null-target membership rows. + This graph-only chain never changes the shared edge/weight population used + by tables, Sankey charts or the separate aligned node styling chain. + """ + start, end = (bindings[key] for key in ('source', 'target')) + if start == end or any(not re.fullmatch(r'[A-Za-z_][A-Za-z0-9_]*', f) for f in (start,end)): + raise ProviderError('Use distinct literal output aliases for the network endpoints.', 422, 'board_bindings') + if 'constellation_role' in (start,end): + raise ProviderError('Reserve constellation_role for native graph membership; choose another endpoint alias.', 422, 'board_bindings') + query = ('| eval constellation_role=mvappend("edge","node") | mvexpand constellation_role' + ' | eval '+start+'=if(constellation_role="edge",'+start+','+end+'), ' + +end+'=if(constellation_role="edge",'+end+',null()) | fields - constellation_role') + return {'type':'ds.chain','options':{'extend':source_id,'query':query}} + + +def verified_precision(document, previous, outputs): + """Presentation-only defaults from local verified values; no rows escape. + + Explicit/inherited precision and existing elements remain unchanged. Shared + source calculations retain full precision, including table/KPI consumers. + """ + from native_shapes import direct_fields, numeric, present + changes = [] + for key, item in document.get('visualizations', {}).items(): + if key in previous.get('visualizations', {}) or item.get('type') != 'splunk.singlevalue': continue + options = item.get('options', {}) + defaults = document.get('defaults', {}).get('visualizations', {}) + inherited = [defaults.get(kind, {}).get('options', {}) for kind in ('global', 'splunk.singlevalue')] + selected = direct_fields(options.get('majorValue'), item.get('dataSources', {}), outputs) + if selected is None or len(selected[1]) != 1: continue + sid, fields = selected + source = document.get('dataSources', {}).get(sid, {}) + query = source.get('options', {}).get('query', '') + commands = [c for _, _, c in pipeline_commands('| '+query.lstrip('| '))] if isinstance(query, str) else [] + if (any(re.match(r'(?i)stats\b', c) for c in commands) and not any(re.match(r'(?i)timechart\b', c) for c in commands) + and '_time' not in {f['name'] for f in outputs[sid]['fields']}): + for name in ('sparklineDisplay','trendDisplay'): + if name not in options and not any(name in v for v in inherited): + changes.append({'op':'set','path':'/visualizations/'+key.replace('~','~0').replace('/','~1')+'/options/'+name,'value':'"off"'}) + if 'numberPrecision' in options or any('numberPrecision' in v for v in inherited): continue + values = [abs(float(row[fields[0]])) for row in outputs[sid]['results'] if present(row.get(fields[0])) and numeric(row[fields[0]])] + fractions = [v for v in values if v and not v.is_integer()] + if not fractions: continue + precision = min(6, max(2, 1 - math.floor(math.log10(min(fractions))))) + changes.append({'op':'set','path':'/visualizations/'+key.replace('~','~0').replace('/','~1')+'/options/numberPrecision','value':str(precision)}) + return changes diff --git a/splunk/constellation/bin/native_intent.py b/splunk/constellation/bin/native_intent.py index 87a4646..d1de136 100644 --- a/splunk/constellation/bin/native_intent.py +++ b/splunk/constellation/bin/native_intent.py @@ -33,6 +33,15 @@ def requested_types(prompt): return found +def unavailable_requested_types(prompt, environment): + requested = requested_types(prompt) + advertised = environment.get('visualizations') + missing = requested - set(advertised) if isinstance(advertised, list) and all(isinstance(v, str) for v in advertised) else set() + if 'splunk.networkGraph' in requested and not environment.get('features', {}).get('networkGraph'): + missing.add('splunk.networkGraph') + return sorted(missing) + + def validate_native_intent(prompt, document, previous, focus): if document == previous: return charts = document.get('visualizations', {}) diff --git a/splunk/constellation/bin/native_shapes.py b/splunk/constellation/bin/native_shapes.py index 675262d..3cc29c7 100644 --- a/splunk/constellation/bin/native_shapes.py +++ b/splunk/constellation/bin/native_shapes.py @@ -20,7 +20,7 @@ 'splunk.pie': {'source': 'label selects one category series; value selects one numeric series. Preserve null measurements.', 'events': ['point.click']}, 'splunk.punchcard': {'source': 'x and y select category series; size selects one nonnegative numeric series.', 'events': ['point.click', 'legend.click']}, 'splunk.timeline': {'source': 'x selects standard _time (Splunk adapts its epoch seconds) or an ISO timestamp string, y selects a lane, duration selects nonnegative milliseconds. Do not bind raw custom epoch numbers directly: derive a separate ISO field with strftime(start_ms/1000,"%Y-%m-%dT%H:%M:%S.%3N%:z") when input is milliseconds. Preserve original timestamps. durationUnit requires its documented version.', 'events': ['event.click', 'lane.click', 'legend.click']}, - 'splunk.networkGraph': {'source': 'primary supplies source and target node IDs. Optional nodeSource supplies nodeIds and aligned node styling. Use explicit series selectors for custom names; links and node styling can use different source aliases.', 'events': ['node.click', 'node.mouseOver', 'node.mouseOut', 'node.drag']}, + 'splunk.networkGraph': {'source': 'Native node membership is inferred from the source series. Include target-only nodes as source rows with null target in a graph-only chain, preserving actual edges and weights. A read-only closure uses eval constellation_role=mvappend("edge","node") | mvexpand constellation_role | eval source=if(constellation_role="edge",source,target), target=if(constellation_role="edge",target,null()) | fields - constellation_role (adapt literal endpoint aliases). Do not use blocked appendpipe/subsearches or duplicate self-links. nodeIds is for styling; it must also include BOTH endpoint sets. A separate nodeSource chain can mvappend/mvexpand both fields then stats by id. Bind nodeIds/nodeTexts and node values explicitly to that aligned node frame. Use explicit series selectors for custom names.', 'events': ['node.click', 'node.mouseOver', 'node.mouseOut', 'node.drag']}, } @@ -84,7 +84,8 @@ def direct_fields(binding, aliases, outputs): def validate_shape(item, outputs): kind = item.get('type') - if kind not in CONTRACTS: return + axes = kind in ('splunk.line', 'splunk.area', 'splunk.bar', 'splunk.column', 'splunk.scatter') + if kind not in CONTRACTS and not axes: return aliases = item.get('dataSources', {}); source = aliases.get('primary') if source not in outputs: return if kind in ('splunk.map', 'splunk.choropleth.svg'): @@ -113,8 +114,20 @@ def channel(name, default=None, number=False, nonnegative=False, time=False): fail('x needs standard _time or an ISO timestamp series. Raw custom epoch numbers do not render reliably; derive a separate ISO field using the declared input unit, preserving original timestamps.') if number and any(not numeric(value) for value in values): fail(name + ' needs numeric output; do not replace unknown measurements with zero.') if nonnegative and any(numeric(value) and float(value) < 0 for value in values): fail(name + ' needs nonnegative values; resolve the intended measurement instead of clamping it silently.') - - if kind == 'splunk.sankey': + return selected + + if axes: + channel('x') + for name in ('y', 'y2'): + selected = direct_fields(options.get(name), aliases, outputs) + if selected is None: continue + sid, names = selected; actual = outputs[sid] + if not actual['fields'] and not actual['results']: continue + if not names or set(names) - {f['name'] for f in actual['fields']}: + fail(name + ' must select existing numeric series; split timecharts bind the actual returned series, not absent category names.') + if '_time' in names or any(present(row.get(field)) and not numeric(row.get(field)) for row in actual['results'] for field in names): + fail(name + ' needs numeric series; keep category/time fields out of the metric frame.') + elif kind == 'splunk.sankey': if fields and not {'source', 'target'} <= set(fields): fail('The search must return the exact source and target fields.') channel('linkValues', '> primary | seriesByName("value")' if 'value' in fields else '> primary | seriesByType("number")', True, True) for name in ('source', 'target'): @@ -140,7 +153,30 @@ def channel(name, default=None, number=False, nonnegative=False, time=False): channel('y', '> primary | seriesByPrioritizedTypes("string","number")') channel('duration', number=True, nonnegative=True) elif kind == 'splunk.networkGraph': - channel('source', '> primary | frameBySeriesTypes("string") | seriesByIndex(0)') - channel('target', '> primary | frameBySeriesTypes("string") | seriesByIndex(1)') + start = channel('source', '> primary | frameBySeriesTypes("string") | seriesByIndex(0)') + end = channel('target', '> primary | frameBySeriesTypes("string") | seriesByIndex(1)') + if start is not None and end is not None: + if len(outputs[start[0]]['results'])!=len(outputs[end[0]]['results']): + fail('source and target must align one endpoint per link row; do not bind a node frame as an edge endpoint frame.') + source_ids = {str(row[start[1][0]]) for row in outputs[start[0]]['results'] if present(row.get(start[1][0]))} + target_ids = {str(row[end[1][0]]) for row in outputs[end[0]]['results'] if present(row.get(end[1][0]))} + if target_ids - source_ids: + fail('Native graph membership comes from source, not nodeIds. Include target-only endpoints as source rows with null target in a graph-only chain, preserving real links and shared edge weights.') + node_binding = options.get('nodeIds', '> source') + nodes = start if isinstance(node_binding, str) and node_binding.strip() == '> source' else channel('nodeIds') + if nodes is not None: + sid, names = nodes + ids = {str(row[names[0]]) for row in outputs[sid]['results'] if present(row.get(names[0]))} + endpoints = set() + for selected in (start, end): + if selected is not None: + endpoint_sid, fields = selected + endpoints.update(str(row[fields[0]]) for row in outputs[endpoint_sid]['results'] if present(row.get(fields[0]))) + if endpoints - ids: + fail('nodeIds omits ' + str(len(endpoints - ids)) + ' observed source/target endpoints. Include both endpoint sets in an aligned node source; the default source-only node list can hide nodes and links.') + for name in ('nodeTexts', 'nodeValues', 'nodeColors', 'nodeTypes', 'nodeIcons', 'nodeIconColors', 'nodeSize', 'xPositions', 'yPositions'): + selected = direct_fields(options.get(name), aliases, outputs) + if selected is not None and len(outputs[selected[0]]['results']) != len(outputs[sid]['results']): + fail(name + ' must align one value with each nodeIds row; link rows and node rows are different populations.') for name in ('nodeValues', 'linkWidth', 'nodeSize', 'xPositions', 'yPositions'): if isinstance(options.get(name), str) and options[name].lstrip().startswith('>'): channel(name, number=True, nonnegative=name in ('nodeSize', 'linkWidth')) diff --git a/splunk/constellation/bin/planning_sources.py b/splunk/constellation/bin/planning_sources.py new file mode 100644 index 0000000..1f5ee34 --- /dev/null +++ b/splunk/constellation/bin/planning_sources.py @@ -0,0 +1,93 @@ +"""Share compatible typed aggregates without changing any requested binding. + +Only compatible stats or fixed-bin timecharts over the same verified base qualify. +Explicit projections prevent newly shared columns from changing an all-fields +consumer. Only a strict literal stats subset of raw SPL can join the pool; +different populations and other native expressions are never rewritten here. +Native source/measurement/output checks still run. +""" +import re +from creation_recipes import compile_recipe +from provider_service import ProviderError + + +def simple_stats(pipeline): + """Recognize only literal independent aggregates, without other commands. + + No expression evaluation, alias guessing, row filters or generic SPL rewrite. + The returned recipe must pass the normal verified-input compiler as well. + """ + match = re.fullmatch(r'\s*\|\s*stats\s+(.+?)(?:\s+BY\s+([A-Za-z_][A-Za-z0-9_]*))?\s*', pipeline, re.I) + if not match: return None + metrics = []; position = 0 + term = re.compile(r'\s*(?:(avg|min|max|sum|median|stdev|latest|earliest|count)\(\s*([A-Za-z_][A-Za-z0-9_]*|)\s*\)|(count))\s+AS\s+([A-Za-z_][A-Za-z0-9_]*)\s*', re.I) + while position < len(match[1]): + metric = term.match(match[1], position) + if not metric: return None + function = (metric[1] or metric[3]).lower();field = metric[2] or '' + if not field and function != 'count': return None + metrics.append({'function':function,'field':field,'alias':metric[4]});position = metric.end() + if not metrics or len({m['alias'] for m in metrics}) != len(metrics): return None + return {'kind':'stats','metrics':metrics,'groupBy':match[2] or ''} + + +def simple_timechart(pipeline): + match=re.fullmatch(r'\s*\|\s*timechart\s+(?:(bins=[1-9][0-9]{0,4}|span=[1-9][0-9]{0,4}[smhdw])\s+)?(.+?)\s*',pipeline,re.I) + if not match:return None + recipe=simple_stats('| stats '+match[2]) + if not recipe or recipe['groupBy']:return None + return dict(recipe,kind='timechart',header='| timechart '+(match[1]+' 'if match[1]else'')) + + +def shared_stats(sources, pipelines, panels, profile, unbound_pool=False): + result = dict(pipelines);buckets = [] + def projected(panel): + kind = panel['type'];binding = panel['bindings'] + if not isinstance(binding, dict): return False + if kind == 'splunk.singlevalue': return set(binding) == {'value'} + if kind == 'splunk.table': return set(binding) == {'columns'} and isinstance(binding['columns'], list) and bool(binding['columns']) + if kind in ('splunk.line','splunk.area','splunk.bar','splunk.column'): + return set(binding) == {'x','y'} and isinstance(binding['y'], list) and bool(binding['y']) + return False + for source in sources: + recipe = source.get('recipe') or simple_stats(pipelines[source['id']]) or simple_timechart(pipelines[source['id']]) + if not isinstance(recipe, dict) or recipe.get('kind') not in ('stats','timechart'): continue + kind=recipe['kind'];group=recipe.get('groupBy','') + header=recipe.get('header','| timechart bins=100 'if kind=='timechart'else'| stats ') + # A raw literal aggregate must satisfy the same input/alias rules as a + # recipe before it can join the sharing pool. Other SPL stays unchanged. + if 'recipe' not in source: + try: + for offset in range(0,len(recipe['metrics']),8): + compile_recipe({'kind':'stats','metrics':recipe['metrics'][offset:offset+8],'groupBy':group},'splunk.table',profile,format_values=False) + except ProviderError: continue + consumers = [p for p in panels if p['source'] == source['id']] + # Before composition, a fresh source pool has no consumers to preserve. + # Bound plans must retain the stricter explicit-projection condition. + if not unbound_pool and (not consumers or not all(projected(p) for p in consumers)): continue + metrics = {m['alias']:m for m in recipe['metrics']} + if group in metrics: continue + match = next((b for b in buckets if b['kind']==kind and b['header']==header and b['group'] == group and not any(alias in b['metrics'] and b['metrics'][alias] != metric for alias,metric in metrics.items())), None) + if match is None: + match = {'kind':kind,'header':header,'group':group,'sources':[],'metrics':{}};buckets.append(match) + match['sources'].append(source['id']);match['metrics'].update(metrics) + for bucket in buckets: + keys=[tuple(sorted((k,v)for k,v in m.items()if k!='alias'))for m in bucket['metrics'].values()] + if len(bucket['sources'])<2 and len(set(keys))==len(keys):continue + # Keep the original eight-metric recipe admission bound for each chunk. + # Compatible independently calculated stats share one output population; + # concatenation changes no aggregate, input, alias or null semantics. + metrics=[];canonical={};copies=[];pieces=[] + for metric in bucket['metrics'].values(): + key=tuple(sorted((k,v)for k,v in metric.items()if k!='alias')) + if key in canonical:copies.append(metric['alias']+'='+canonical[key]) + else:canonical[key]=metric['alias'];metrics.append(metric) + for offset in range(0,len(metrics),8): + pipeline,_,_ = compile_recipe({'kind':'stats','metrics':metrics[offset:offset+8],'groupBy':bucket['group']},'splunk.table',profile,format_values=False) + expression = pipeline[len('| stats '):] + if bucket['group']: expression = expression[:-len(' BY '+bucket['group'])] + pieces.append(expression) + combined = bucket['header']+' '.join(pieces)+(' BY '+bucket['group'] if bucket['group'] else '') + if copies:combined+=' | eval '+', '.join(copies) + for sid in bucket['sources']: result[sid] = combined + return result diff --git a/splunk/constellation/bin/table_aggregates.py b/splunk/constellation/bin/table_aggregates.py new file mode 100644 index 0000000..f3fc1be --- /dev/null +++ b/splunk/constellation/bin/table_aggregates.py @@ -0,0 +1,76 @@ +"""Exact named numeric aggregate additions on an inspected ordinary table. + +Ambiguous subjects, complex searches and mixed requests retain model authoring. +The returned native edits still pass the normal caller-scoped validation loop. +""" +import copy +import hashlib +import json +import re +from measurement_constraints import pipeline_commands, mask_command +from planning_sources import simple_stats +from search_scope import scoped_suffix + +FUNCTIONS={'minimum':'min','maximum':'max','average':'avg','mean':'avg','sum':'sum'} + + +def exact_table_aggregates(prompt, selected, document, profile, receipt, attachments): + if attachments or not profile or not receipt or receipt.get('status')=='failed' or profile.get('scope',{}).get('language','spl')!='spl':return None + if not re.search(r'\b(?:for|to) only this selected table\b|\bchange no other element\b',prompt,re.I):return None + if re.search(r'\b(?:rename|reorder|sort|format|round|colou?r|resize|move|remove|delete|retarget|navigate|link|limit)\b',prompt,re.I):return None + op=r'(?:minimum|maximum|average|mean|sum)';field=r'[A-Za-z_][A-Za-z0-9_]*' + match=re.search(r'\b(?:add|include)\s+('+op+r'(?:\s*(?:,|and)\s*'+op+r')*)\s+([A-Za-z_][A-Za-z0-9_ ]{0,80}?)\s+columns?\s+(?:named|called)\s+('+field+r'(?:\s*,\s*'+field+r')*(?:\s*,?\s+and\s+'+field+r')?)\s*(?=[.;\n]|$|\balongside\b|\bwhile\b|\bwithout\b)',prompt,re.I) + if not match:return None + prefix=prompt[:match.start()].strip(' ,.:;\n') + if prefix and not re.fullmatch(r'(?:for|to) only this selected table',prefix,re.I):return None + tail=prompt[match.end():].strip() + tail=re.sub(r'^alongside (?:its|the) existing (?:summary )?columns\s*','',tail,flags=re.I) + clauses=[part.strip()for part in re.split(r'[.;\n]',tail)if part.strip()] + if any(not re.match(r'(?:Keep|Preserve|Exclude)\b',part,re.I)for part in clauses):return None + if re.search(r'\b(?:add|include|create|convert|change|replace|also|instead|except)\b',tail,re.I):return None + functions=[FUNCTIONS[word.lower()]for word in re.findall(op,match[1],re.I)] + aliases=re.split(r'\s*,\s*(?:and\s+)?|\s+and\s+',match[3],flags=re.I) + if not 1<=len(aliases)<=4 or len(aliases)!=len(functions)or len(set(aliases))!=len(aliases):return None + table=document.get('visualizations',{}).get(selected,{}) + if table.get('type')!='splunk.table'or set(table.get('dataSources',{}))!={'primary'}:return None + sid=table['dataSources']['primary'];source=document.get('dataSources',{}).get(sid,{}) + if source.get('type')!='ds.search'or receipt.get('table')!=selected or receipt.get('source')!=sid:return None + query=source.get('options',{}).get('query','');suffix=scoped_suffix(query,profile) + if suffix is None or any(re.search(r'\b'+re.escape(alias)+r'\b',query)for alias in aliases):return None + if any(mask_command(rule)not in query for rule in profile.get('measurementConstraints',[])):return None + normalized='| '+query.strip().lstrip('| ').strip();commands=pipeline_commands(normalized) + stats=[(i,start,end,command)for i,(start,end,command)in enumerate(commands)if re.match(r'(?i)stats\b',command)] + if len(stats)!=1:return None + index,start,end,command=stats[0];parsed=simple_stats('| '+command) + if not parsed:return None + known={f['name']for f in profile.get('fields',[])if f.get('numeric')is True} + used={m['field']for m in parsed['metrics']if m['field']in known} + subject=match[2].strip().lower();words=set(re.findall(r'[a-z0-9]+',subject))-{'the','of','field','values','value','readings','reading','stored','recorded'} + candidates=[name for name in used if name.lower()==subject] + if not candidates:candidates=[name for name in used if words and words<=set(re.findall(r'[a-z0-9]+',name.lower()))] + if len(candidates)!=1:return None + input_field=candidates[0] + # Preserve post-aggregation calculations/order and extend only a literal + # terminal projection. Other frame-changing commands need general editing. + projections=[] + for j,(a,b,c)in enumerate(commands[index+1:],index+1): + if re.match(r'(?i)(?:eval|sort|head)\b',c):continue + if j==len(commands)-1 and re.fullmatch(r'(?i)(?:fields|table)\s+'+field+r'(?:\s+'+field+r')*',c):projections.append((a,b,c));continue + return None + extra=' '.join(fn+'('+input_field+') AS '+alias for fn,alias in zip(functions,aliases)) + group=re.search(r'(?i)\bBY\s+[A-Za-z_][A-Za-z0-9_]*\s*$',command) + replacement=command[:group.start()].rstrip()+' '+extra+' '+command[group.start():]if group else command+' '+extra + edits=[(start,end,normalized[start:end].replace(command,replacement,1))] + for a,b,c in projections:edits.append((a,b,normalized[a:b].replace(c,c+' '+' '.join(aliases),1))) + for a,b,text in sorted(edits,reverse=True):normalized=normalized[:a]+text+normalized[b:] + updated=copy.deepcopy(source);updated['options']['query']=normalized if query.lstrip().startswith('|')else normalized[2:] + shared=(any(key!=selected and sid in item.get('dataSources',{}).values()for key,item in document.get('visualizations',{}).items()) + or any(sid in item.get('dataSources',{}).values()for item in document.get('inputs',{}).values()) + or any(item.get('options',{}).get('extend',item.get('extend'))==sid for item in document.get('dataSources',{}).values())) + escape=lambda value:value.replace('~','~0').replace('/','~1');target=sid;changes=[] + if shared: + base='table_calc_'+hashlib.sha256((selected+sid+updated['options']['query']).encode()).hexdigest()[:20];target=base;n=2 + while target in document['dataSources']:target=base+'_'+str(n);n+=1 + changes.append({'op':'set','path':'/visualizations/'+escape(selected)+'/dataSources/primary','value':json.dumps(target)}) + changes.insert(0,{'op':'set','path':'/dataSources/'+escape(target),'value':json.dumps(updated)}) + return {'message':'Added '+', '.join(aliases)+' using the selected table’s existing '+input_field+' data.','changes':changes,'suggestions':[]} diff --git a/splunk/constellation/bin/table_projection.py b/splunk/constellation/bin/table_projection.py index debda27..463431e 100644 --- a/splunk/constellation/bin/table_projection.py +++ b/splunk/constellation/bin/table_projection.py @@ -8,7 +8,7 @@ def focused_calculation(prompt, selected, document, profile, receipt, attachment """One explicit new aggregate on an exclusive inspected SPL table source.""" if attachments or not profile or not receipt or receipt.get('status')=='failed' or profile.get('scope',{}).get('language','spl')!='spl':return None table,requested,_fields=requested_columns(prompt,selected,document,[]) - if len(requested)!=1 or not re.search(r'(?i)\bchange no other element\b|\bto only this selected\b.{0,50}\btable\b',prompt):return None + if len(requested)!=1 or not re.search(r'(?i)\bchange no other element\b|\b(?:to|for) only this selected\b.{0,50}\btable\b',prompt):return None if re.search(r'\b(?:move|resize|rename|retarget|remove|delete|create)\b',prompt,re.I):return None aggregates=re.findall(r'\b(avg|min|max|sum|count|latest|earliest)\(\s*([A-Za-z_][A-Za-z0-9_.]*)\s*\)\s+AS\s+([A-Za-z_][A-Za-z0-9_]*)\b',prompt,re.I) if len(aggregates)!=1 or aggregates[0][2]in {f['name']for f in receipt.get('fields',[])}:return None @@ -53,6 +53,8 @@ def requested_columns(prompt, selected, document, receipts): # A literal comma-separated list is explicit output intent too. Restrict it # to plain fields and a sentence boundary; prose/formatting stays unparsed. field = r'[A-Za-z_][A-Za-z0-9_]*' + named = re.findall(r'\bcolumns?\s+(?:named|called)\s+('+field+r'(?:\s*,\s*'+field+r')*(?:\s*,?\s+and\s+'+field+r')?)\s*(?=[.;\n]|$|\balongside\b|\bwhile\b|\bwithout\b|\bto the existing\b)',prompt,re.I) + for literal in named:requested.update(re.split(r'\s*,\s*(?:and\s+)?|\s+and\s+',literal,flags=re.I)) lists = re.findall(r'\b(?:display|show)\s+(?:columns\s+)?(' + field + r'(?:\s*,\s*' + field + r')+(?:\s*,?\s+and\s+' + field + r')?)\s*(?=[.;\n]|$)', prompt, re.I) for literal in lists: names = re.split(r'\s*,\s*(?:and\s+)?|\s+and\s+', literal, flags=re.I) @@ -79,7 +81,10 @@ def verified_requested_projection(prompt, selected, document, receipts): except (ValueError, TypeError): return [] if (not visible or any(not isinstance(field, str) for field in visible) or not set(visible) <= fields): return [] - missing = sorted(requested - set(visible)) + def order(field): + match=re.search(r'\b'+re.escape(field)+r'\b',prompt) + return (match.start()if match else len(prompt),field) + missing = sorted(requested - set(visible),key=order) if not missing: return [] value = '> primary | frameBySeriesNames(' + ', '.join(json.dumps(field) for field in visible + missing) + ')' return [{'op': 'set', 'path': '/visualizations/' + selected.replace('~', '~0').replace('/', '~1') + '/options/table', 'value': json.dumps(value)}] @@ -222,7 +227,7 @@ def validate_creation_columns(prompt, document, previous, profile, receipts): def validate_selected_calculation(prompt, selected, candidate, previous): """Explicit table-only calculations cannot edit a different element/source.""" _table, requested, _fields = requested_columns(prompt, selected, previous, []) - if not requested or not re.search(r'(?i)\bchange no other element\b|\bto only this selected\b.{0,50}\btable\b', prompt): return + if not requested or not re.search(r'(?i)\bchange no other element\b|\b(?:to|for) only this selected\b.{0,50}\btable\b', prompt): return if candidate == previous: return # A clarification can legitimately make no edits. visualizations = previous.get('visualizations', {}) if any(candidate.get('visualizations', {}).get(key) != value for key, value in visualizations.items() if key != selected) or set(candidate.get('visualizations', {})) != set(visualizations): @@ -240,7 +245,7 @@ def isolate_selected_calculation(prompt, selected, candidate, previous): """Clone a changed shared search only for an explicit table-only calculation.""" import hashlib _table, requested, _fields = requested_columns(prompt, selected, previous, []) - if not requested or not re.search(r'(?i)\bchange no other element\b|\bto only this selected\b.{0,50}\btable\b', prompt): return [] + if not requested or not re.search(r'(?i)\bchange no other element\b|\b(?:to|for) only this selected\b.{0,50}\btable\b', prompt): return [] before_table = previous.get('visualizations', {}).get(selected, {}) after_table = candidate.get('visualizations', {}).get(selected, {}) bindings = before_table.get('dataSources', {}) diff --git a/splunk/constellation/default/app.conf b/splunk/constellation/default/app.conf index 007cb18..0a7b9ba 100644 --- a/splunk/constellation/default/app.conf +++ b/splunk/constellation/default/app.conf @@ -1,6 +1,6 @@ [install] state = enabled -build = 61 +build = 62 [ui] is_visible = 1 @@ -9,11 +9,11 @@ label = Constellation [launcher] author = Leiter Consulting description = Conversational Dashboard Studio workspace with guarded visual references and bounded SPL/SPL2 previews. -version = 1.0.1 +version = 1.0.2 [id] name = constellation -version = 1.0.1 +version = 1.0.2 [package] id = constellation diff --git a/src/App.tsx b/src/App.tsx index 58a5158..3563753 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -284,7 +284,7 @@ export default function App({ initialColorScheme }: { initialColorScheme: 'light setHistory(previous => [...previous.slice(-19), previousRevision]); setFuture([]); setRevision(next); setSaved(null); updated = next; setSelected(value => validFocus(next.definition,value) ? value : ''); - setStatus(result.recovery&&result.recovery.modelCalls>1?'Dashboard updated after automatic recovery.':'Dashboard updated.'); + setStatus(result.repaired?'Dashboard updated after automatic recovery.':'Dashboard updated.'); } else setStatus(result.dataContext && fieldDefinitionKey(result.dataContext) !== fieldDefinitionKey(scopeOverride || dataContext) ? 'Field definitions updated.' : 'The agent replied. The document is unchanged.'); setActivity([...result.activity, ...(result.validationNotes || []).map(note => `Corrected during validation: ${note}`), ...(result.recovery ? [`${result.recovery.modelCalls} model requests · ${result.recovery.queryChecks} search checks${typeof result.recovery.seconds==='number'?` · ${Math.round(result.recovery.seconds)} seconds`:''}.`] : [])]); setProposals({ key: promptContextKey(updated.number, updated.definition, selected, activeTab, result.dataContext || scopeOverride || dataContext, {brief:result.brief || brief,messages:[...messages,{user:true,text}]}), items: result.suggestions }); setAttachments([]); addMessage(result.message); diff --git a/tests/fixtures/native_chart_shapes.json b/tests/fixtures/native_chart_shapes.json index acbfc9f..08261ac 100644 --- a/tests/fixtures/native_chart_shapes.json +++ b/tests/fixtures/native_chart_shapes.json @@ -255,6 +255,10 @@ [ "A", "C" + ], + [ + "C", + null ] ] }, diff --git a/tests/test_authoring_budget.py b/tests/test_authoring_budget.py index 797e28d..2decad4 100644 --- a/tests/test_authoring_budget.py +++ b/tests/test_authoring_budget.py @@ -12,6 +12,16 @@ from authoring_budget import AuthoringBudget class AuthoringBudgetTests(unittest.TestCase): + def test_focused_repair_keeps_one_exact_large_candidate_without_losing_original_receipt(self): + original={'title':'Original','visualizations':{'table':{'future':'fixture'*7000}}};candidate=copy.deepcopy(original);candidate['title']='Uncommitted' + context={'request':'Add two columns to this selected table','canvasState':'dashboard','focus':{'kind':'visualization','id':'table'},'history':[],'definition':original,'focusedSourceReceipt':{'originalQuery':'verified fixture'}} + budget=AuthoringBudget({'provider':'ollama'},context);request={'instructions':'Fixture','text':{},'max_output_tokens':8500,'input':[{'role':'user','content':[{'type':'input_text','text':json.dumps(context)}]}]} + envelope={'rejectedOutput':'old wire proposal','recoveryFeedback':{'candidateDefinition':candidate,'editsApplyTo':'candidate','placementHint':{'unneeded':'layout'},'validationError':'Fix one field'}} + budget.feedback(request,envelope);first=json.loads(request['input'][0]['content'][0]['text']);feedback=json.loads(request['input'][1]['content'][0]['text']) + self.assertEqual(first['definition'],candidate);self.assertEqual(first['focusedSourceReceipt'],context['focusedSourceReceipt']);self.assertNotIn('candidateDefinition',feedback['recoveryFeedback']);self.assertNotIn('placementHint',feedback['recoveryFeedback']);self.assertEqual(feedback['rejectedOutput'],'') + self.assertEqual(budget.context['definition'],original);self.assertEqual(envelope['recoveryFeedback']['candidateDefinition'],candidate) + envelope['recoveryFeedback']['editsApplyTo']='original';budget.feedback(request,envelope) + self.assertEqual(json.loads(request['input'][0]['content'][0]['text'])['definition'],original);self.assertNotIn('candidateDefinition',json.loads(request['input'][1]['content'][0]['text'])['recoveryFeedback']) def test_schema_ignoring_compact_reply_keeps_small_plan_repair_against_original(self): from agent_service import SCHEMA context={'request':'Build three pages with exactly six charts','canvasState':'blank','history':[],'dataProfile':PROFILE,'modelLimits':{'contextTokens':32768}} diff --git a/tests/test_creation_recipes.py b/tests/test_creation_recipes.py index 9a65d95..568488f 100644 --- a/tests/test_creation_recipes.py +++ b/tests/test_creation_recipes.py @@ -16,6 +16,11 @@ def recipe(kind='stats', metrics=None, group='device_name', columns=None): 'groupBy':group,'columns':columns or []} class RecipeTests(unittest.TestCase): + def test_repeated_aggregate_uses_one_native_specifier_and_keeps_every_alias(self): + metrics=[{'function':'count','field':'','alias':'readings'},{'function':'count','field':'','alias':'history_count'},{'function':'avg','field':'temperature_f','alias':'mean_f'},{'function':'avg','field':'temperature_f','alias':'temperature_mean'}] + original=copy.deepcopy(metrics);query,x,y=compile_recipe({'kind':'timechart','metrics':metrics},'splunk.line',PROFILE,format_values=False) + self.assertEqual(query,'| timechart bins=100 count AS readings avg(temperature_f) AS mean_f | eval history_count=readings, temperature_mean=mean_f') + self.assertEqual(y,['readings','history_count','mean_f','temperature_mean']);self.assertEqual(x,'_time');self.assertEqual(metrics,original) def test_kind_specific_plans_compile_without_irrelevant_fields_and_preserve_legacy(self): for modern, legacy, chart in ( ({'kind':'stats','metrics':recipe()['metrics'],'groupBy':'device_name'},recipe(),'splunk.table'), diff --git a/tests/test_dashboard_plan.py b/tests/test_dashboard_plan.py new file mode 100644 index 0000000..029d021 --- /dev/null +++ b/tests/test_dashboard_plan.py @@ -0,0 +1,274 @@ +"""Synthetic large-board proposals exercise real compilers and validation.""" +import copy +import json +import unittest +from test_drafts_and_data import blank +from test_reliability_journey import Provider, Runtime, reply +from test_native_shapes import frame, viz +from agent_service import AgentService, SCHEMA +from authoring_actions import compile_actions, validate_chart_placement +from authoring_budget import AuthoringBudget +from compatibility import feature_profile +from dashboard_plan import counts, eligible, expand, page_names, schema_for +from native_builders import native_options, verified_precision +from native_shapes import validate_shape +from studio_contract import apply_changes +from provider_service import ProviderError +from board_batches import source_schema, source_actions, layout_schema, pool_context, expand_layout, normalize_plan, recipe_goal + +PROFILE = {'baseQuery':'search index="fixture_index"','scope':{'index':'fixture_index','earliest':'-24h','language':'spl'}, + 'fields':[{'name':'host'},{'name':'temperature_f','numeric':True},{'name':'_time','numeric':False}]} +GOAL = 'Create exactly eight pages with exactly 24 charts. Give each page a purpose and use shared real-data summaries, temperature trends and host tables.' + + +def plan(): + sources = [{'id':'metrics','recipe':{'kind':'stats','metrics':[{'function':'avg','field':'temperature_f','alias':'mean_f'},{'function':'count','field':'','alias':'observations'}],'groupBy':''}}, + {'id':'trend','recipe':{'kind':'timechart','metrics':[{'function':'avg','field':'temperature_f','alias':'mean_f'}]}}, + {'id':'summary','recipe':{'kind':'stats','metrics':[{'function':'count','field':'','alias':'observations'}],'groupBy':'host'}}] + return {'op':'boardPlan','title':'Observed telemetry','description':'Shared observations across eight pages', + 'pages':[{'label':'Page '+str(p+1),'purpose':'Inspect observed telemetry '+str(p+1),'columns':2}for p in range(8)], + 'sources':sources,'panels':[{'id':'panel_'+str(p)+'_'+str(k),'page':p,'type':kind,'title':title,'source':source,'bindings':binding} + for p in range(8) for k,(kind,title,source,binding)in enumerate([ + ('splunk.singlevalue','Mean temperature (°F)','metrics',{'value':'mean_f'}), + ('splunk.line','Temperature over time (°F)','trend',{'x':'_time','y':['mean_f']}), + ('splunk.table','Host observations','summary',{'columns':['host','observations']})])], 'links':[]} + + +def compile_plan(action, goal=GOAL): + original=blank()['definition'];original['futureSetting']={'keep':True} + raw=expand([action],original,PROFILE,goal) + result=apply_changes(original,compile_actions(original,raw,PROFILE)) + return original,result,raw + + +class DashboardPlanTests(unittest.TestCase): + def test_batch_composition_uses_verified_outputs_and_keeps_pool_immutable(self): + context={'request':GOAL,'dataProfile':PROFILE};sources=plan()['sources'];before=copy.deepcopy(sources) + receipts=[{'source':'ds_plan_metrics','fields':['mean_f','observations']},{'source':'ds_plan_trend','fields':['_time','mean_f']},{'source':'ds_plan_summary','fields':['host','observations']}] + schema=layout_schema(context,sources,receipts);self.assertNotIn('sources',schema['properties']) + variants=schema['properties']['panels']['items']['anyOf'] + for v in variants: + if v['properties']['type']['enum']==['splunk.singlevalue']:self.assertEqual(v['properties']['source']['enum'],['metrics']) + if v['properties']['source']['enum']==['trend']and v['properties']['type']['enum']==['splunk.line']: + self.assertEqual(v['properties']['bindings']['properties']['y']['items']['enum'],['mean_f']) + pool=pool_context(sources,receipts);self.assertTrue(all('fields'in s and 'results'not in s for s in pool)) + layout=plan();layout.pop('sources');layout['op']='boardLayout' + self.assertEqual(expand_layout([layout],blank()['definition'],context,sources),expand([plan()],blank()['definition'],PROFILE,GOAL));self.assertEqual(sources,before) + layout['sources']=[] + with self.assertRaises(ProviderError):expand_layout([layout],blank()['definition'],context,sources) + def test_source_batch_rejects_invalid_scope_inputs_before_composition(self): + context={'request':GOAL,'dataProfile':PROFILE};action={'op':'boardSources','sources':plan()['sources']} + compiled=source_actions([action],context);self.assertEqual(len(compiled),3);self.assertTrue(all(c['id'].startswith('ds_plan_')for c in compiled)) + for invalid in (None,{'kind':'stats','metrics':[{'function':'avg','field':'unverified','alias':'mean'}],'groupBy':''}): + bad=copy.deepcopy(action);bad['sources'][0]['recipe']=invalid + with self.assertRaises(ProviderError):source_actions([bad],context) + def test_failed_batch_promotion_returns_to_source_planning(self): + from unittest.mock import patch + budget=AuthoringBudget({'provider':'ollama'},{'request':GOAL,'canvasState':'blank','dataProfile':PROFILE}) + calls=[] + def prepare(request,document): + calls.append(hasattr(budget,'verified_pool')) + if calls[-1]:raise ProviderError('Synthetic composition admission failure.',413) + with patch.object(budget,'prepare',side_effect=prepare),self.assertRaises(ProviderError): + budget.advance_sources({},blank()['definition'],[{'sources':plan()['sources']}],[]) + self.assertEqual(calls,[True,False]);self.assertFalse(hasattr(budget,'verified_pool'));self.assertEqual(budget.stages,0) + def test_pool_fragments_are_coalesced_before_actual_searches_and_bindings(self): + sources=[] + for n in range(5):sources.append({'id':'metric'+str(n),'recipe':{'kind':'stats','metrics':[{'function':'avg','field':'temperature_f','alias':'metric'+str(n)}],'groupBy':''}}) + sources.extend(plan()['sources'][1:]);sources.append({'id':'raw','recipe':{'kind':'table','columns':['host','temperature_f']}}) + self.assertEqual(len(sources),8);original=copy.deepcopy(sources);result=normalize_plan([{'op':'boardSources','sources':sources}],{'dataProfile':PROFILE})[0]['sources'] + self.assertEqual(len(result),4);self.assertEqual(sources,original) + self.assertIn(' AS metric0',result[0]['pipeline']) + for n in range(1,5):self.assertIn('metric'+str(n)+'=metric0',result[0]['pipeline']) + self.assertTrue(any('timechart'in s['pipeline']for s in result));self.assertTrue(any('BY host'in s['pipeline']for s in result));self.assertTrue(any('table host temperature_f'in s['pipeline']for s in result)) + def test_complex_requests_keep_native_authoring_and_batch_bindings_are_checked_early(self): + context={'request':GOAL,'dataProfile':PROFILE};self.assertTrue(recipe_goal(context)) + for goal in ('Add a native Sankey','Show p95 and outliers','Add table sparklines','Create a ratio','Use timechart count by host'): + self.assertFalse(recipe_goal(dict(context,request=GOAL+' '+goal))) + self.assertFalse(eligible(dict(context,request=GOAL+' Add table sparklines.'),blank()['definition'])) + self.assertNotIn('pipeline',json.dumps(source_schema(context))) + with self.assertRaisesRegex(ProviderError,'not raw pipelines'):source_actions([{'op':'boardSources','sources':[{'id':'raw','pipeline':'| stats count'}]}],context) + layout=plan();sources=layout.pop('sources');layout['op']='boardLayout';layout['panels'][1]['source']='summary' + receipts=[{'source':'ds_plan_metrics','fields':['mean_f','observations']},{'source':'ds_plan_trend','fields':['_time','mean_f']},{'source':'ds_plan_summary','fields':['host','observations']}] + with self.assertRaisesRegex(ProviderError,'without _time'):expand_layout([layout],blank()['definition'],context,sources,receipts) + def test_larger_shared_plan_keeps_all_membership_precision_and_unknown_native_work(self): + action=plan();before=copy.deepcopy(action);original,result,raw=compile_plan(action) + self.assertEqual(action,before);self.assertFalse(original['visualizations']) + self.assertEqual(result['futureSetting'],{'keep':True});self.assertEqual(len(result['visualizations']),24) + self.assertEqual(len(result['dataSources']),3);self.assertEqual(len(result['layout']['tabs']['items']),8) + self.assertTrue(all(len(p['structure'])==3 for p in result['layout']['layoutDefinitions'].values())) + self.assertNotIn('round(',result['dataSources']['ds_plan_metrics']['options']['query']) + self.assertEqual(result['visualizations']['panel_0_0']['options']['sparklineDisplay'],'off') + self.assertEqual(result['visualizations']['panel_0_0']['options']['trendDisplay'],'off') + validate_chart_placement(result,original) + def test_counts_admission_and_names_never_guess_or_truncate(self): + self.assertEqual(counts(GOAL),(8,24,None));self.assertEqual(counts('Build eight pages with 3 charts per page.'),(8,24,3)) + self.assertIsNone(counts('Build eight pages with exactly 20 charts and 3 charts per page.')) + self.assertIsNone(counts('Build nine pages with exactly 24 charts.')) + names='Build five pages named "Overview", "Inputs", "Details", "Signals", "Confidence" with exactly 10 charts.' + self.assertEqual(page_names(names,5),['Overview','Inputs','Details','Signals','Confidence']) + context={'request':GOAL,'dataProfile':PROFILE};self.assertTrue(eligible(context,blank()['definition'])) + self.assertTrue(eligible(dict(context,request=GOAL+' No invented health/SLA thresholds. No dropdowns or custom colors.'),blank()['definition'])) + self.assertFalse(eligible(dict(context,request=GOAL+' No dropdowns; add a gauge.'),blank()['definition'])) + for suffix in (' Add a dropdown.', ' Place an image.', ' Set custom colors.', ' Add a scatter chart.', ' Include splunk.singlevalueicon.'): + self.assertFalse(eligible(dict(context,request=GOAL+suffix),blank()['definition'])) + self.assertFalse(eligible(context,dict(blank()['definition'],visualizations={'existing':{'type':'splunk.table'}}))) + malformed=plan();malformed['panels'].pop() + with self.assertRaises(ProviderError):compile_plan(malformed) + named_goal=GOAL+'\nOn "Page 2", include a Sankey chart.' + with self.assertRaisesRegex(ProviderError,'Page 2 still needs'):compile_plan(plan(),named_goal) + def test_schema_and_compact_repair_are_provider_neutral_and_keep_limits(self): + for provider in ('openai','ollama','aitk'): + context={'request':GOAL,'canvasState':'blank','history':[],'dataProfile':PROFILE,'modelLimits':{'contextTokens':32768},'nativeAuthoring':{'unneeded':'extra'}} + budget=AuthoringBudget({'provider':provider},context);request={'instructions':'Fixture','text':{'format':{'schema':copy.deepcopy(SCHEMA)}},'input':[{'content':[{'type':'input_text','text':'Fixture'}]}]} + budget.prepare(request,blank()['definition']);self.assertTrue(budget.board_plan);self.assertEqual(budget.phase,'complete') + self.assertEqual(request['text']['format']['schema']['properties']['changes']['items'],source_schema(context)if provider in ('ollama','aitk')else schema_for(context)) + recipe=schema_for(context)['properties']['sources']['items']['anyOf'][1]['properties']['recipe'] + fields=recipe['anyOf'][0]['properties']['metrics']['items']['anyOf'][0]['properties']['field']['enum'] + self.assertEqual(set(fields),{''}|{f['name']for f in PROFILE['fields']}) + current=json.loads(request['input'][0]['content'][0]['text']);self.assertNotIn('nativeAuthoring',current) + self.assertNotIn('baseQuery',current['dataProfile']);self.assertEqual(current['creationRequirements']['panels'],24) + budget.feedback(request,{'recoveryFeedback':{'validationError':'Bad binding','candidateDefinition':{'sensitive':'do not repeat'},'dataProfile':PROFILE},'rejectedOutput':'old failed text','request':'repair'}) + feedback=json.loads(request['input'][-1]['content'][0]['text']);self.assertEqual(feedback['recoveryFeedback']['editsApplyTo'],'original') + self.assertNotIn('candidateDefinition',feedback['recoveryFeedback']);self.assertNotIn('baseQuery',feedback['recoveryFeedback']['dataProfile']) + self.assertNotIn('old failed text',json.dumps(request)) + def test_route_isolates_shared_destination_sources_and_keeps_overview_unfiltered(self): + action=plan();action['links']=[{'from':'panel_0_2','to':1,'field':'host'}] + _,result,_=compile_plan(action) + for pid in ('panel_0_0','panel_0_1','panel_0_2'): + self.assertNotIn('$select_page_1',result['dataSources'][result['visualizations'][pid]['dataSources']['primary']]['options']['query']) + for pid in ('panel_1_0','panel_1_1','panel_1_2'): + query=result['dataSources'][result['visualizations'][pid]['dataSources']['primary']]['options']['query'] + self.assertIn('search host=$select_page_1|s$',query) + self.assertEqual(len(result['dataSources']),6) + self.assertTrue(any(h['type']=='drilldown.switchToTab' and h['options']['tabId']=='layout_board_0' for h in result['inputs']['back_board_1']['eventHandlers'])) + def test_row_routes_do_not_overwrite_unknown_existing_token_work(self): + original=blank()['definition'];original['defaults']={'tokens':{'default':{'select_page_1':{'value':'keep','future':True}}}};original['expressions']={'select_page_1_2':{'future':True}} + action=plan();action['links']=[{'from':'panel_0_2','to':1,'field':'host'}] + changes=expand([action],original,PROFILE,GOAL);result=apply_changes(original,compile_actions(original,changes,PROFILE)) + self.assertEqual(result['defaults']['tokens']['default']['select_page_1'],original['defaults']['tokens']['default']['select_page_1']);self.assertEqual(result['expressions'],original['expressions']) + self.assertEqual(result['defaults']['tokens']['default']['select_page_1_3']['value'],'*') + def test_full_closure_includes_network_nodes_and_filtered_clones(self): + action=plan();action['panels'][0].update(type='splunk.networkGraph',source='edges',bindings={'source':'from_node','target':'to_node'}) + action['sources'].append({'id':'edges','pipeline':'| stats count BY host | eval from_node=host, to_node="observed" | table from_node to_node count'}) + _,result,_=compile_plan(action);graph=result['visualizations']['panel_0_0'];self.assertIn('nodeSource',graph['dataSources']) + nodes=result['dataSources'][graph['dataSources']['nodeSource']];self.assertEqual(nodes['type'],'ds.chain') + self.assertIn('mvappend(from_node,to_node)',nodes['options']['query']);self.assertIn('nodeSource',graph['options']['nodeIds']) + closure=result['dataSources'][graph['dataSources']['primary']];self.assertEqual(closure['type'],'ds.chain');self.assertIn('mvappend("edge","node")',closure['options']['query']);self.assertIn('to_node,null()',closure['options']['query']);self.assertEqual(closure['options']['extend'],nodes['options']['extend']) + action['links']=[{'from':'panel_0_2','to':i,'field':'host'}for i in (1,2,3)] + # Duplicate source routes also stay unambiguous; use distinct origin tables. + for i,link in enumerate(action['links']):link['from']='panel_'+str((0,4,6)[i])+'_2' + with self.assertRaisesRegex(ProviderError,'limit is eight'):compile_plan(action) + def test_overall_kpi_cannot_silently_display_last_grouped_row(self): + action=plan();action['sources'][0]['recipe']['groupBy']='host' + with self.assertRaisesRegex(ProviderError,'ungrouped'):compile_plan(action) + def test_unused_model_declarations_never_compile_or_change_the_board(self): + expected=compile_plan(plan())[1];action=plan();before=copy.deepcopy(action) + action['sources'].append({'id':'unused','recipe':{'kind':'stats','metrics':[{'function':'avg','field':'missing_input','alias':'unused'}],'groupBy':''}}) + self.assertEqual(compile_plan(action)[1],expected);self.assertEqual(action['sources'][:3],before['sources']) + def test_invalid_unknown_duplicate_or_wrong_membership_is_atomic(self): + cases=[] + bad=plan();bad['panels'][0]['extra']='unknown';cases.append(bad) + bad=plan();bad['panels'][0]['id']=bad['panels'][1]['id'];cases.append(bad) + bad=plan();bad['panels'][0]['page']=True;cases.append(bad) + bad=plan();bad['sources'][0]['recipe']=None;cases.append(bad) + bad=plan();bad['panels']=[dict(p,page=0)for p in bad['panels']];cases.append(bad) + for action in cases: + before=copy.deepcopy(action) + with self.subTest(action=action),self.assertRaises(ProviderError):compile_plan(action) + self.assertEqual(action,before) + def test_dynamic_split_series_are_actual_numeric_columns_not_guessed_categories(self): + options=native_options('splunk.area',{'x':'_time','y':[]},'| timechart bins=100 count BY host') + item=viz('area',options) + validate_shape(item,{'s':frame(['_time','fixture_a','fixture_b'],[[1000,3,7]])}) + for fields,values in [(['_time','fixture_a'],[1000,'text']),(['fixture_a','_time'],[3,1000])]: + with self.assertRaises(ProviderError):validate_shape(item,{'s':frame(fields,[values])}) + with self.assertRaises(ProviderError):native_options('splunk.line',{'x':'_time','y':[]},'| timechart count AS observed') + def test_network_endpoint_coverage_and_alignment_have_payload_free_feedback(self): + outputs={'links':frame(['from_node','to_node'],[['fixture_private_a','fixture_private_b']]),'nodes':frame(['id','size'],[['fixture_private_a',3]])} + item=viz('networkGraph',{'source':'> primary | seriesByName("from_node")','target':'> primary | seriesByName("to_node")'}, {'primary':'links','nodeSource':'nodes'}) + with self.assertRaisesRegex(ProviderError,'endpoint')as raised:validate_shape(item,outputs) + self.assertNotIn('fixture_private_b',str(raised.exception)) + item['options']['nodeIds']='> nodeSource | seriesByName("id")';outputs['nodes']=frame(['id','size'],[['fixture_private_a',2],['fixture_private_b',1]]) + with self.assertRaisesRegex(ProviderError,'membership'):validate_shape(item,outputs) + outputs['links']=frame(['from_node','to_node'],[['fixture_private_a','fixture_private_b'],['fixture_private_b',None]]) + validate_shape(item,outputs) + outputs['nodes']=frame(['id','size'],[['fixture_private_a',2],['fixture_private_b',1],['fixture_private_c',1]]) + bad=copy.deepcopy(item);bad['options']['target']='> nodeSource | seriesByName("id")' + with self.assertRaisesRegex(ProviderError,'align one endpoint'):validate_shape(bad,outputs) + item['options']['nodeValues']='> primary | seriesByIndex(0)' + with self.assertRaisesRegex(ProviderError,'align'):validate_shape(item,outputs) + def test_fractional_precision_does_not_modify_measurements_or_explicit_user_work(self): + original,result,_=compile_plan(plan());before=copy.deepcopy(result) + outputs={'ds_plan_metrics':frame(['mean_f'],[[.003125]])} + changes=verified_precision(result,original,outputs);self.assertEqual(len(changes),8) + self.assertTrue(all(c['value']=='4'for c in changes));self.assertEqual(result,before) + self.assertEqual(verified_precision(result,result,outputs),[]) + for item in result['visualizations'].values():item.setdefault('options',{})['numberPrecision']=0 + self.assertEqual(verified_precision(result,original,outputs),[]) + general=copy.deepcopy(before) + for item in general['visualizations'].values(): + item.get('options',{}).pop('sparklineDisplay',None);item.get('options',{}).pop('trendDisplay',None) + defaults=verified_precision(general,original,outputs) + self.assertEqual(sum(c['path'].endswith('/sparklineDisplay')for c in defaults),8) + self.assertEqual(sum(c['path'].endswith('/trendDisplay')for c in defaults),8) + def test_larger_plan_executes_real_orchestration_once_and_recovers_without_losing_requirements(self): + class Model(Provider): + def __init__(self,provider,replies):super().__init__(replies);self.kind=provider + def configured(self):return {'provider':self.kind,'model':'synthetic'} + def capabilities(self,saved):return {'contextTokens':32768,'images':False,'pdf':False} + class Searches(Runtime): + def preview(self,body): + if body.get('fieldDiscovery'):return dict(frame(['_time','host','temperature_f'],[[1000,'fixture_a',.003125]]),evidence={'state':'complete'}) + self.calls.append(body) + if 'timechart'in body['query']:return frame(['_time','mean_f'],[[1000,.003125]]) + if 'BY host'in body['query']:return frame(['host','observations'],[['fixture_a',1]]) + return frame(['mean_f','observations'],[[.003125,1]]) + for provider in ('openai','ollama','aitk'): + layout=plan();pool=layout.pop('sources');layout['op']='boardLayout' + replies=[reply([{'op':'boardSources','sources':pool}]),reply([layout])]if provider in ('ollama','aitk')else[reply([plan()])] + runtime=Searches();model=Model(provider,replies);original=blank()['definition'] + result=AgentService(model,runtime).assist({'prompt':GOAL,'revision':0,'definition':original,'dataContext':blank()['dataContext']}) + final=apply_changes(original,result['changes']);self.assertEqual(len(final['visualizations']),24);self.assertEqual(len(final['dataSources']),3) + self.assertEqual(result['recovery']['modelCalls'],2 if provider in ('ollama','aitk')else 1);self.assertEqual(result['recovery']['queryChecks'],3);self.assertFalse(result['repaired']) + self.assertEqual(final['visualizations']['panel_0_0']['options']['numberPrecision'],4) + self.assertFalse(original['visualizations']) + bad=copy.deepcopy(layout);bad['panels'].pop();runtime=Searches();model=Model('ollama',[reply([{'op':'boardSources','sources':pool}]),reply([bad]),reply([layout])]) + result=AgentService(model,runtime).assist({'prompt':GOAL,'revision':0,'definition':original,'dataContext':blank()['dataContext']}) + self.assertTrue(result['repaired']);self.assertEqual(result['recovery']['modelCalls'],3) + feedback=json.loads(model.requests[-1]['input'][-1]['content'][0]['text']);self.assertEqual(feedback['recoveryFeedback']['editsApplyTo'],'original') + runtime=Searches();model=Model('ollama',[reply([{'op':'boardSources','sources':pool}]),reply([bad]),reply([bad])]) + untouched=copy.deepcopy(original) + with self.assertRaises(ProviderError):AgentService(model,runtime).assist({'prompt':GOAL,'revision':0,'definition':original,'dataContext':blank()['dataContext']}) + self.assertEqual(original,untouched);self.assertEqual(len(runtime.calls),3);self.assertEqual(len(model.requests),3) + def test_unavailable_exact_family_is_negotiated_before_model_or_profile(self): + class Older(Runtime): + def environment(self):return {'version':'10.2.8','features':feature_profile('10.2.8',[]),'visualizations':['splunk.linkgraph']} + def preview(self,body):raise AssertionError('Unavailable-feature preflight dispatched data search') + model=Provider([]);result=AgentService(model,Older()).assist({'prompt':'Create one page with one network graph.','revision':0,'definition':blank()['definition'],'dataContext':blank()['dataContext'],'suggestionFormat':'cards'}) + self.assertEqual(result['changes'],[]);self.assertEqual(result['recovery']['modelCalls'],0);self.assertEqual(result['recovery']['queryChecks'],0) + self.assertIn('link graph',result['suggestions'][0]['prompt']);self.assertFalse(model.requests) + + def test_changed_parent_validates_unchanged_chain_consumers_and_retains_source_budget(self): + from data_service import DataService + from test_search_chart_actions import chart, page + actions=[{'op':'search','id':'events','pipeline':'| stats count AS old'}, + {'op':'set','path':'/dataSources/child','value':json.dumps({'type':'ds.chain','options':{'extend':'events','query':'| eval derived=old*2'}})}, + dict(chart('splunk.table','',['derived']),sourceId='child'),page()] + old=apply_changes(blank()['definition'],compile_actions(blank()['definition'],actions,PROFILE));new=copy.deepcopy(old) + new['dataSources']['events']['options']['query']=PROFILE['baseQuery']+' | stats count AS changed' + class Searches: + def __init__(self):self.calls=[] + def preview(self,body): + self.calls.append(body) + if 'eval derived'in body['query']:raise ProviderError('Synthetic missing old alias',422,'preview_failed') + return frame(['changed'],[[2]]) + runtime=Searches() + with self.assertRaisesRegex(ProviderError,'child'):DataService(runtime).validate_searches(new,old,PROFILE) + self.assertEqual(len(runtime.calls),2) + for i in range(8): + item={'type':'ds.chain','options':{'extend':'events','query':'| eval derived=old*2'}} + old['dataSources']['extra_'+str(i)]=copy.deepcopy(item);new['dataSources']['extra_'+str(i)]=item + runtime=Searches() + with self.assertRaisesRegex(ProviderError,'eight affected'):DataService(runtime).validate_searches(new,old,PROFILE) + self.assertFalse(runtime.calls) diff --git a/tests/test_native_shapes.py b/tests/test_native_shapes.py index cdc9463..064ae38 100644 --- a/tests/test_native_shapes.py +++ b/tests/test_native_shapes.py @@ -71,10 +71,11 @@ def test_timeline_custom_epoch_numbers_need_explicit_timestamp_conversion(self): def test_network_auxiliary_node_source_is_not_confused_with_link_source(self): item = viz('networkGraph', {'source': '> primary | seriesByName("from")', 'target': '> primary | seriesByName("to")', + 'nodeIds': '> nodeSource | seriesByName("id")', 'nodeValues': '> nodeSource | seriesByName("magnitude")'}, {'primary': 'links', 'nodeSource': 'nodes'}) - outputs = {'links': frame(['from', 'to'], [['A', 'B']]), 'nodes': frame(['id', 'magnitude'], [['A', 8]])} + outputs = {'links': frame(['from', 'to'], [['A', 'B'], ['B', None]]), 'nodes': frame(['id', 'magnitude'], [['A', 8], ['B', 4]])} validate_shape(item, outputs) - outputs['nodes'] = frame(['id', 'magnitude'], [['A', 'SECRET_SYNTHETIC_VALUE']]) + outputs['nodes'] = frame(['id', 'magnitude'], [['A', 'SECRET_SYNTHETIC_VALUE'], ['B', 4]]) with self.assertRaises(ProviderError) as raised: validate_shape(item, outputs) self.assertNotIn('SECRET_SYNTHETIC_VALUE', str(raised.exception)) diff --git a/tests/test_planning_sources.py b/tests/test_planning_sources.py new file mode 100644 index 0000000..e3f6192 --- /dev/null +++ b/tests/test_planning_sources.py @@ -0,0 +1,65 @@ +"""Aggregate sharing changes neither populations, expressions nor projections.""" +import copy +import unittest +from planning_sources import shared_stats +from creation_recipes import compile_recipe + +PROFILE={'scope':{'language':'spl'},'fields':[{'name':'host'},{'name':'temperature_f','numeric':True},{'name':'wifi_rssi','numeric':True}]} +def source(key,field,alias,group=''): + return {'id':key,'recipe':{'kind':'stats','groupBy':group,'metrics':[{'function':'avg','field':field,'alias':alias}]}} +def panel(key,kind='splunk.singlevalue',bindings=None): + return {'source':key,'type':kind,'bindings':bindings or {'value':key}} +def pipelines(specs):return {s['id']:compile_recipe(s['recipe'],'splunk.table',PROFILE,format_values=False)[0]for s in specs} + +class PlanningSourceTests(unittest.TestCase): + def test_timecharts_share_only_identical_buckets_without_changing_populations(self): + specs=[{'id':'a','recipe':{'kind':'timechart','metrics':[{'function':'avg','field':'temperature_f','alias':'temperature_mean'}]}},{'id':'b','recipe':{'kind':'timechart','metrics':[{'function':'avg','field':'wifi_rssi','alias':'wifi_mean'},{'function':'count','field':'','alias':'all_observations'}]}}] + before={s['id']:compile_recipe(s['recipe'],'splunk.line',PROFILE,format_values=False)[0]for s in specs};result=shared_stats(specs,before,[],PROFILE,unbound_pool=True) + self.assertEqual(result['a'],result['b']);self.assertTrue(result['a'].startswith('| timechart bins=100 '));self.assertIn('avg(wifi_rssi) AS wifi_mean',result['a']);self.assertIn('count AS all_observations',result['a']);self.assertNotIn('where',result['a']) + raw=[{'id':k,'pipeline':v}for k,v in before.items()] + self.assertEqual(shared_stats(raw,before,[],PROFILE,unbound_pool=True),result) + for query in ('| timechart span=1h avg(wifi_rssi) AS wifi_mean','| timechart bins=50 avg(wifi_rssi) AS wifi_mean','| timechart bins=100 avg(wifi_rssi) AS wifi_mean BY host','| timechart bins=100 avg(wifi_rssi) AS wifi_mean | fillnull value=0'): + raw[1]['pipeline']=query;original={'a':before['a'],'b':query};self.assertEqual(shared_stats(raw,original,[],PROFILE,unbound_pool=True),original) + consumers=[panel('a','splunk.line',{'x':'_time','y':['temperature_mean']}),panel('b','splunk.line',{'x':'_time','y':[]})] + self.assertEqual(shared_stats(specs,before,consumers,PROFILE),before) + def test_compatible_aggregates_share_exact_expressions_and_leave_inputs_unchanged(self): + specs=[source('temp','temperature_f','temp'),source('wifi','wifi_rssi','wifi')];old=copy.deepcopy(specs);original=pipelines(specs) + result=shared_stats(specs,original,[panel('temp'),panel('wifi')],PROFILE) + self.assertEqual(result['temp'],result['wifi']);self.assertIn('avg(temperature_f) AS temp',result['temp']);self.assertIn('avg(wifi_rssi) AS wifi',result['temp']) + self.assertNotIn('round',result['temp']);self.assertNotIn('where',result['temp']);self.assertEqual(specs,old);self.assertEqual(original,pipelines(specs)) + def test_conflicting_alias_group_and_unprojected_consumers_remain_separate(self): + variants=[ + ([source('a','temperature_f','same'),source('b','wifi_rssi','same')],[panel('a'),panel('b')]), + ([source('a','temperature_f','a'),source('b','wifi_rssi','b','host')],[panel('a'),panel('b')]), + ([source('a','temperature_f','a'),source('b','wifi_rssi','b')],[panel('a','splunk.table',{'columns':[]}),panel('b')]), + ([source('a','temperature_f','a'),source('b','wifi_rssi','b')],[panel('a','splunk.line',{'x':'host','y':[]}),panel('b')]), + ] + for specs,consumers in variants: + before=pipelines(specs);self.assertEqual(shared_stats(specs,before,consumers,PROFILE),before) + def test_shared_wide_aggregates_keep_every_validated_metric_and_input_bound(self): + specs=[];consumers=[] + for index in range(3): + s=source('s'+str(index),'temperature_f','m'+str(index));s['recipe']['metrics']=[{'function':'avg','field':'temperature_f','alias':'m'+str(index*5+i)}for i in range(5)];specs.append(s);consumers.append(panel(s['id'])) + result=shared_stats(specs,pipelines(specs),consumers,PROFILE) + self.assertEqual(len(set(result.values())),1) + self.assertIn(' AS m0',result['s0']) + for i in range(1,15):self.assertIn('m'+str(i)+'=m0',result['s0']) + self.assertEqual(result['s0'].count('avg(temperature_f)'),1) + def test_duplicate_timechart_specifiers_preserve_aliases_with_value_copies(self): + specs=[{'id':'a','recipe':{'kind':'timechart','metrics':[{'function':'count','field':'','alias':'all_readings'}]}},{'id':'b','recipe':{'kind':'timechart','metrics':[{'function':'count','field':'','alias':'history_observations'}]}}] + before={s['id']:compile_recipe(s['recipe'],'splunk.line',PROFILE,format_values=False)[0]for s in specs};result=shared_stats(specs,before,[],PROFILE,unbound_pool=True) + self.assertEqual(result['a'],result['b']);self.assertEqual(result['a'],'| timechart bins=100 count AS all_readings | eval history_observations=all_readings') + raw=[{'id':'a','pipeline':'| timechart bins=100 count AS a count AS b'}] + result=shared_stats(raw,{'a':raw[0]['pipeline']},[],PROFILE,unbound_pool=True) + self.assertEqual(result['a'],'| timechart bins=100 count AS a | eval b=a') + def test_raw_pipelines_are_never_rewritten_or_merged_speculatively(self): + specs=[source('a','temperature_f','a'),{'id':'b','pipeline':'| where temperature_f<0 | stats avg(wifi_rssi) AS b'}] + before={'a':compile_recipe(specs[0]['recipe'],'splunk.table',PROFILE,format_values=False)[0],'b':specs[1]['pipeline']} + self.assertEqual(shared_stats(specs,before,[panel('a'),panel('b')],PROFILE),before) + def test_exact_literal_stats_can_share_but_complex_expressions_cannot(self): + specs=[{'id':'a','pipeline':'| stats avg(temperature_f) AS a'}, {'id':'b','pipeline':'| stats count AS b'}] + before={s['id']:s['pipeline']for s in specs};result=shared_stats(specs,before,[panel('a'),panel('b')],PROFILE) + self.assertEqual(result['a'],result['b']);self.assertIn('avg(temperature_f) AS a',result['a']);self.assertIn('count AS b',result['a']) + for unsupported in ('| stats avg(temperature_f+1) AS b','| stats avg(temperature_f) AS b | eval b=round(b,2)','| stats avg(unknown) AS b','| stats sum() AS b','| stats avg(temperature_f) AS b BY host location'): + specs[1]['pipeline']=unsupported;before={s['id']:s['pipeline']for s in specs} + self.assertEqual(shared_stats(specs,before,[panel('a'),panel('b')],PROFILE),before) diff --git a/tests/test_table_aggregates.py b/tests/test_table_aggregates.py new file mode 100644 index 0000000..d64c532 --- /dev/null +++ b/tests/test_table_aggregates.py @@ -0,0 +1,85 @@ +"""Bounded exact aggregate intent still uses native, search and output validation.""" +import copy +import sys +import unittest +from pathlib import Path +sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'splunk/constellation/bin')) +from table_aggregates import exact_table_aggregates +from studio_contract import apply_changes +from test_drafts_and_data import blank + + +class ExactTableAggregateTests(unittest.TestCase): + def setUp(self): + self.prompt='For only this selected table, add minimum and maximum duration columns named minimum_duration and maximum_duration alongside its existing summary columns. Keep every original output field and calculation. Preserve all pages, geometry, inputs, tokens, drilldowns, other chart options and unrelated searches.' + self.profile={'baseQuery':'search index="fixture_index"','scope':{'index':'fixture_index','earliest':'-24h','language':'spl'},'fields':[{'name':'duration','numeric':True}]} + self.receipt={'status':'complete','table':'table','source':'source','fields':[{'name':'mean_duration'}]} + self.document=dict(blank()['definition'],visualizations={'table':{'type':'splunk.table','title':'Duration','dataSources':{'primary':'source'},'options':{'table':'> primary | frameBySeriesNames("host", "mean_duration")','future':{'keep':True}},'eventHandlers':[{'future':'keep'}]}},dataSources={'source':{'type':'ds.search','options':{'query':'search index="fixture_index" | stats avg(duration) AS mean_duration BY host','queryParameters':{'earliest':'-24h','latest':'now'}},'future':{'keep':True}}},layout={'type':'grid','structure':[{'item':'table'}]}) + + def proposal(self,**kwargs): + args=dict(prompt=self.prompt,selected='table',document=self.document,profile=self.profile,receipt=self.receipt,attachments=[]);args.update(kwargs) + return exact_table_aggregates(**args) + + def test_existing_stats_grouping_and_unknown_work_are_preserved(self): + before=copy.deepcopy(self.document);proposal=self.proposal();self.assertIsNotNone(proposal) + final=apply_changes(before,proposal['changes']) + self.assertEqual(final['dataSources']['source']['options']['query'],'search index="fixture_index" | stats avg(duration) AS mean_duration min(duration) AS minimum_duration max(duration) AS maximum_duration BY host') + expected=copy.deepcopy(before);expected['dataSources']['source']['options']['query']=final['dataSources']['source']['options']['query'] + self.assertEqual(final,expected);self.assertEqual(self.document,before) + + def test_shared_source_is_cloned_for_visualization_input_or_chain_consumers(self): + for consumer in ('visualization','input','chain'): + with self.subTest(consumer=consumer): + doc=copy.deepcopy(self.document) + if consumer=='visualization':doc['visualizations']['other']={'type':'splunk.bar','dataSources':{'primary':'source'}} + elif consumer=='input':doc['inputs']={'other':{'type':'input.dropdown','dataSources':{'primary':'source'}}} + else:doc['dataSources']['child']={'type':'ds.chain','options':{'extend':'source','query':'| head 3'}} + final=apply_changes(doc,self.proposal(document=doc)['changes']);target=final['visualizations']['table']['dataSources']['primary'] + self.assertNotEqual(target,'source');self.assertEqual(final['dataSources']['source'],doc['dataSources']['source']) + expected=copy.deepcopy(doc);expected['dataSources'][target]=final['dataSources'][target];expected['visualizations']['table']['dataSources']['primary']=target + self.assertEqual(final,expected) + + def test_masks_post_calculations_and_literal_projection_are_retained(self): + from measurement_constraints import mask_command + self.profile['measurementConstraints']=[{'field':'duration','maximum':150,'unit':'ms'}] + mask=mask_command(self.profile['measurementConstraints'][0]) + self.document['dataSources']['source']['options']['query']='search index="fixture_index" | '+mask+' | stats avg(duration) AS mean_duration BY host | eval mean_duration=round(mean_duration,2) | sort host | head 10 | table host mean_duration' + final=apply_changes(self.document,self.proposal()['changes']);query=final['dataSources']['source']['options']['query'] + self.assertIn('| '+mask+' | stats',query);self.assertIn('BY host | eval mean_duration=round(mean_duration,2) | sort host | head 10 | table host mean_duration minimum_duration maximum_duration',query) + + def test_ambiguous_unverified_mixed_or_complex_requests_fall_back(self): + for prompt in [self.prompt+' Add another chart.',self.prompt.replace('Keep every original output field and calculation.','Also filter hosts.'),self.prompt.replace('minimum_duration and maximum_duration','minimum_duration'),self.prompt.replace('duration columns','unknown columns'),'Sort this table and '+self.prompt,self.prompt.replace('For only this selected table, ','')]: + with self.subTest(prompt=prompt):self.assertIsNone(self.proposal(prompt=prompt)) + for change in ('attachment','receipt','language','numeric','complex','report','alias','scope'): + doc=copy.deepcopy(self.document);profile=copy.deepcopy(self.profile);receipt=copy.deepcopy(self.receipt);attachments=[] + if change=='attachment':attachments=[{'name':'fixture.pdf'}] + elif change=='receipt':receipt['source']='other' + elif change=='language':profile['scope']['language']='spl2' + elif change=='numeric':profile['fields'][0]['numeric']=False + elif change=='complex':doc['dataSources']['source']['options']['query']+=' | where mean_duration>0' + elif change=='report':doc['dataSources']['source']['type']='ds.savedSearch' + elif change=='alias':doc['dataSources']['source']['options']['query']+=' | eval minimum_duration=1' + else:profile['baseQuery']='search index="different"';profile['scope']['index']='different' + with self.subTest(change=change):self.assertIsNone(self.proposal(document=doc,profile=profile,receipt=receipt,attachments=attachments)) + doc=copy.deepcopy(self.document);doc['dataSources']['source']['options']['query']='search index="fixture_index" | stats avg(duration_ms) AS ms avg(duration_seconds) AS seconds' + profile=dict(self.profile,fields=[{'name':n,'numeric':True}for n in ('duration_ms','duration_seconds')]) + self.assertIsNone(self.proposal(document=doc,profile=profile)) + + def test_agent_uses_zero_model_calls_but_verifies_and_displays_outputs(self): + from test_reliability_journey import Provider,Runtime + from agent_service import AgentService + class Outputs(Runtime): + def preview(self,body): + if body.get('fieldDiscovery'):return super().preview(body) + self.calls.append(body);names=['host','mean_duration'] + if 'min(duration)'in body['query']:names+=['minimum_duration','maximum_duration'] + return {'state':'complete','fields':[{'name':n}for n in names],'results':[dict(zip(names,['fixture-host','20','10','30']))]} + for provider_name in ('openai','ollama','aitk'): + with self.subTest(provider=provider_name): + provider=Provider([]);provider.configured=lambda:{'provider':provider_name,'model':'synthetic-model'};runtime=Outputs() + result=AgentService(provider,runtime).assist({'prompt':self.prompt,'definition':self.document,'revision':0,'selected':'table','dataContext':self.profile['scope']}) + final=apply_changes(self.document,result['changes']) + self.assertEqual(result['recovery']['modelCalls'],0);self.assertFalse(provider.requests) + self.assertEqual(result['recovery']['queryChecks'],2) + self.assertIn('"minimum_duration", "maximum_duration"',final['visualizations']['table']['options']['table']) + self.assertEqual(final['visualizations']['table']['eventHandlers'],self.document['visualizations']['table']['eventHandlers']) diff --git a/tests/test_table_projection.py b/tests/test_table_projection.py index e3def7d..66bbf1b 100644 --- a/tests/test_table_projection.py +++ b/tests/test_table_projection.py @@ -10,6 +10,15 @@ class TableProjectionTests(unittest.TestCase): + def test_explicit_named_columns_are_verified_and_shown_in_requested_order(self): + document={'visualizations':{'table':{'type':'splunk.table','dataSources':{'primary':'source'},'options':{'table':'> primary | frameBySeriesNames("device", "count")','future':{'keep':True}},'eventHandlers':[{'future':'keep'}]}}} + document=dict(blank()['definition'],**document);document['dataSources']={'source':{'type':'ds.search','options':{'query':'| makeresults'}}};original=copy.deepcopy(document);prompt='For only this selected table, add minimum and maximum temperature columns named minimum_temperature_f and maximum_temperature_f alongside its existing columns.' + receipts=[{'source':'source','fields':['device','count','minimum_temperature_f','maximum_temperature_f']}] + changes=verified_requested_projection(prompt,'table',document,receipts);self.assertEqual(len(changes),1);candidate=apply_changes(document,changes) + self.assertEqual(candidate['visualizations']['table']['options']['table'],'> primary | frameBySeriesNames("device", "count", "minimum_temperature_f", "maximum_temperature_f")');self.assertEqual(document,original) + self.assertEqual(candidate['visualizations']['table']['eventHandlers'],original['visualizations']['table']['eventHandlers']);self.assertEqual(candidate['visualizations']['table']['options']['future'],{'keep':True});validate_requested_columns(prompt,'table',candidate,receipts) + with self.assertRaises(ProviderError):validate_requested_columns(prompt,'table',candidate,[{'source':'source','fields':['device','count']}]) + self.assertEqual(verified_requested_projection('Add columns named Minimum temperature and Maximum temperature.','table',document,receipts),[]) def setUp(self): self.doc = {'visualizations': {'table': {'type': 'splunk.table', 'dataSources': {'primary': 'source'}, 'options': {'table': '> primary | frameBySeriesNames("device", "count")'}}}} self.receipts = [{'source': 'source', 'fields': ['device', 'count', 'host_count']}]