Skip to content

add rule criteria - #472

Merged
iceljc merged 4 commits into
SciSharp:mainfrom
iceljc:features/add-rule-criteria
Aug 5, 2026
Merged

add rule criteria#472
iceljc merged 4 commits into
SciSharp:mainfrom
iceljc:features/add-rule-criteria

Conversation

@iceljc

@iceljc iceljc commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@iceljc
iceljc marked this pull request as draft July 17, 2026 22:20
@iceljc
iceljc marked this pull request as ready for review August 5, 2026 14:47
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add rule criteria editor and code-script generation action

✨ Enhancement 🕐 20-40 Minutes

Grey Divider

AI Description

• Add a per-rule "Criteria" text area to capture trigger conditions.
• Allow generating an agent code script from criteria with confirmation.
• Add supporting styles for the criteria row, textarea, and compile icon.
Diagram

graph TD
U["Admin user"] --> I["AgentRuleItem"] --> R["AgentRule page"] --> M["ConfirmModal"] --> R --> S["agent-service"] --> API[("CodeScript generate API")]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Defer generation to save/apply step
  • ➕ Avoids generating scripts from partially edited criteria
  • ➕ Keeps backend calls aligned with explicit rule persistence workflow
  • ➖ Slower iteration for admins; extra clicks to generate scripts
  • ➖ More coupling between rule save and code generation
2. Backend-managed overwrite prompt (no UI confirm)
  • ➕ Simplifies UI flow and state management
  • ➕ Backend can return explicit "would overwrite" result and require a force flag
  • ➖ Requires backend behavior/contract changes
  • ➖ UI becomes less explicit unless additional error/force handling is added

Recommendation: Current approach (inline criteria editor + explicit confirm modal + direct generation call) is appropriate for an admin-facing workflow and minimizes backend changes. One thing to verify during review: the UI comment says "admins only" but the gating shown here is based on trigger_name + criteria presence; ensure authorization is enforced (either by role checks in UI or, preferably, by the backend endpoint).

Files changed (3) +216 / -13

Enhancement (3) +216 / -13
_agent.scssAdd styles for criteria row, textarea, and compile icon +62/-10

Add styles for criteria row, textarea, and compile icon

• Removes the lift-on-hover transform behavior for .ad-section and switches to a box-shadow transition. Adds styling for a secondary rule row, a clickable compile icon, and a themed textarea (including dark mode and a responsive tweak).

src/lib/styles/pages/_agent.scss

agent-rule-item.svelteRender criteria textarea and compile trigger per rule +69/-2

Render criteria textarea and compile trigger per rule

• Introduces a new, collapsible secondary row containing a criteria textarea with a character limit. Adds a compile icon (shown only when a trigger is selected and criteria is non-empty) and emits new onchange(field=criteria) and oncompile events to the parent.

src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte

agent-rule.sveltePersist criteria to rule config and generate code script with confirmation +85/-1

Persist criteria to rule config and generate code script with confirmation

• Extends rule change handling to store criteria under rule.config.criteria. Adds a ConfirmModal-driven flow that calls generateAgentCodeScript to create/overwrite a "{trigger}_criteria.py" source script using the criteria as the user_request payload, with success/error feedback timing.

src/routes/page/agent/[agentId]/agent-components/rules/agent-rule.svelte

@iceljc
iceljc merged commit aa1e84d into SciSharp:main Aug 5, 2026
1 of 2 checks passed
@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Compile icon not keyboardable 🐞 Bug ≡ Correctness
Description
In agent-rule-item.svelte the new compile icon is focusable (tabindex=0) but its onkeydown handler
is a no-op, so keyboard users cannot trigger compilation via Enter/Space even though the UI presents
it as a link.
Code

src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[R195-198]

+                    title="Generate code script"
+                    onkeydown={() => {}}
+                    onclick={() => compile()}
+                ></i>
Evidence
The compile control is focusable and claims interactive semantics, but the only working activation
handler is onclick; onkeydown is explicitly a no-op.

src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[186-199]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The new compile affordance is rendered as an `<i>` with `role="link"` + `tabindex="0"`, but `onkeydown={() => {}}` means there is no keyboard activation path.

### Issue Context
This was introduced with the new Criteria/compile UI. The click handler calls `compile()`, but keyboard events never do.

### Fix Focus Areas
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[186-199]

Suggested implementation options:
- Prefer a semantic `<button type="button">` wrapping the icon (native keyboard behavior), or
- Implement `onkeydown` to call `compile()` when `e.key === 'Enter'` (and optionally `' '`), with `e.preventDefault()` for Space.
- Add `aria-label="Generate code script"` (tooltip `title` is not a reliable accessible name).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Compile allowed when disabled 🐞 Bug ≡ Correctness
Description
canCompile ignores rule.disabled, so a disabled rule can still show and execute the compile action
even though the Criteria textarea is disabled, allowing code generation/overwrite for a rule the UI
marks as disabled.
Code

src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[R36-39]

+    // Code script can only be generated by admins, once a trigger is picked and criteria text exists.
+    let canCompile = $derived(
+        !!rule.trigger_name && !!rule.config?.criteria?.trim()
+    );
Evidence
The UI disables the Criteria textarea based on rule.disabled, but the compile icon is rendered based
on canCompile which does not consider rule.disabled, so compile remains clickable for disabled
rules.

src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[36-40]
src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[186-213]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The Criteria textarea is disabled when `rule.disabled` is true, but the compile icon’s visibility/enabled state is driven only by `canCompile` which does not include `rule.disabled`. This allows generating code scripts for disabled rules.

### Issue Context
- `canCompile` currently checks `trigger_name` and `criteria.trim()` only.
- The compile icon is rendered when `canCompile` is true.
- The Criteria textarea is disabled via `disabled={rule.disabled}`.

### Fix Focus Areas
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[36-40]
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[186-213]

Suggested fix:
- Update `canCompile` to include `!rule.disabled`.
- Additionally (defense-in-depth), in the parent compile handler (agent-rule.svelte) refuse to open the confirm modal / call the API when `rule.disabled` is true.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. No in-flight compile guard 🐞 Bug ☼ Reliability
Description
generateCodeScript() sets isLoading but never checks it, so users can trigger multiple confirmed
generateAgentCodeScript requests concurrently, causing duplicate work and racing success/error
banners/timeouts.
Code

src/routes/page/agent/[agentId]/agent-components/rules/agent-rule.svelte[R257-260]

+    function generateCodeScript(rule) {
+        isLoading = true;
+        generateAgentCodeScript(agent.id, {
+            options: {
Evidence
generateCodeScript tracks loading state but does not use it to block repeated invocations; the
compile icon always triggers compile() on click, enabling multiple confirmed runs while a prior
request is still in flight.

src/routes/page/agent/[agentId]/agent-components/rules/agent-rule.svelte[257-290]
src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[186-199]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The code-generation flow does not enforce mutual exclusion:
- `generateCodeScript()` sets `isLoading = true`, but does not early-return if already loading.
- The UI path to invoke compile does not consult `isLoading`.
This allows concurrent requests and out-of-order UI state updates.

### Issue Context
`generateAgentCodeScript(...).then(...).catch(...)` toggles `isLoading/isComplete/isError` and schedules timeouts. With concurrent invocations, later responses can overwrite earlier UI status, and multiple writes may race on the backend.

### Fix Focus Areas
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule.svelte[257-290]
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[186-199]

Suggested fix:
- Add a guard at the top of `generateCodeScript`: `if (isLoading) return;`
- Disable/hide the compile icon (or the confirm button) while `isLoading` is true.
- Optionally store/clear timeout IDs to avoid overlapping timers from successive runs.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

Comment on lines +195 to +198
title="Generate code script"
onkeydown={() => {}}
onclick={() => compile()}
></i>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

1. Compile icon not keyboardable 🐞 Bug ≡ Correctness

In agent-rule-item.svelte the new compile icon is focusable (tabindex=0) but its onkeydown handler
is a no-op, so keyboard users cannot trigger compilation via Enter/Space even though the UI presents
it as a link.
Agent Prompt
### Issue description
The new compile affordance is rendered as an `<i>` with `role="link"` + `tabindex="0"`, but `onkeydown={() => {}}` means there is no keyboard activation path.

### Issue Context
This was introduced with the new Criteria/compile UI. The click handler calls `compile()`, but keyboard events never do.

### Fix Focus Areas
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[186-199]

Suggested implementation options:
- Prefer a semantic `<button type="button">` wrapping the icon (native keyboard behavior), or
- Implement `onkeydown` to call `compile()` when `e.key === 'Enter'` (and optionally `' '`), with `e.preventDefault()` for Space.
- Add `aria-label="Generate code script"` (tooltip `title` is not a reliable accessible name).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +36 to +39
// Code script can only be generated by admins, once a trigger is picked and criteria text exists.
let canCompile = $derived(
!!rule.trigger_name && !!rule.config?.criteria?.trim()
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. Compile allowed when disabled 🐞 Bug ≡ Correctness

canCompile ignores rule.disabled, so a disabled rule can still show and execute the compile action
even though the Criteria textarea is disabled, allowing code generation/overwrite for a rule the UI
marks as disabled.
Agent Prompt
### Issue description
The Criteria textarea is disabled when `rule.disabled` is true, but the compile icon’s visibility/enabled state is driven only by `canCompile` which does not include `rule.disabled`. This allows generating code scripts for disabled rules.

### Issue Context
- `canCompile` currently checks `trigger_name` and `criteria.trim()` only.
- The compile icon is rendered when `canCompile` is true.
- The Criteria textarea is disabled via `disabled={rule.disabled}`.

### Fix Focus Areas
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[36-40]
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[186-213]

Suggested fix:
- Update `canCompile` to include `!rule.disabled`.
- Additionally (defense-in-depth), in the parent compile handler (agent-rule.svelte) refuse to open the confirm modal / call the API when `rule.disabled` is true.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +257 to +260
function generateCodeScript(rule) {
isLoading = true;
generateAgentCodeScript(agent.id, {
options: {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

3. No in-flight compile guard 🐞 Bug ☼ Reliability

generateCodeScript() sets isLoading but never checks it, so users can trigger multiple confirmed
generateAgentCodeScript requests concurrently, causing duplicate work and racing success/error
banners/timeouts.
Agent Prompt
### Issue description
The code-generation flow does not enforce mutual exclusion:
- `generateCodeScript()` sets `isLoading = true`, but does not early-return if already loading.
- The UI path to invoke compile does not consult `isLoading`.
This allows concurrent requests and out-of-order UI state updates.

### Issue Context
`generateAgentCodeScript(...).then(...).catch(...)` toggles `isLoading/isComplete/isError` and schedules timeouts. With concurrent invocations, later responses can overwrite earlier UI status, and multiple writes may race on the backend.

### Fix Focus Areas
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule.svelte[257-290]
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[186-199]

Suggested fix:
- Add a guard at the top of `generateCodeScript`: `if (isLoading) return;`
- Disable/hide the compile icon (or the confirm button) while `isLoading` is true.
- Optionally store/clear timeout IDs to avoid overlapping timers from successive runs.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant