Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
12 KiB
PRD — Workflow Regex Transform + AI-Assisted Authoring
- Slug:
2026-05-09-workflow-regex-transform-ai-authoring - Date:
2026-05-09 - Status: Draft
Summary
Add first-class regex transform actions to the workflow system so authors can match, extract, and replace text using deterministic JavaScript regular expressions. The feature should mirror the JSON transform pattern: pure Transform actions in the workflow runtime, normal action.call input mappings, normal saveAs outputs, useful Run Studio errors, designer-friendly inputs/outputs, and Quick Ask guidance for regex syntax and safe usage. AI should help authors write patterns, but saved workflow execution must remain deterministic and independent of AI.
Problem
Workflow authors frequently need to parse semi-structured text: email subjects, alert bodies, ticket descriptions, webhook text fields, hostnames, asset tags, invoice references, phone numbers, and vendor incident IDs. Today they can combine basic text transforms or expressions, but there is no workflow-native regex action with clear inputs, captures, replacement semantics, output schemas, and actionable runtime errors. This makes common automation patterns harder than necessary and encourages brittle ad hoc expressions.
Goals
- Add pure, side-effect-free regex Transform actions for matching, extracting captures, and replacing text.
- Use JavaScript
RegExpsyntax and flags so runtime behavior is predictable in TypeScript/Node. - Return structured match/capture outputs that can be saved and referenced by downstream workflow steps.
- Provide guardrails for invalid patterns, unsupported flags, oversized inputs, excessive matches, and pathological regex risk where feasible.
- Improve designer behavior so regex pattern, flags, replacement, and saveAs outputs are clear to workflow authors.
- Preserve existing workflow runtime and designer behavior for all current actions.
- Add Quick Ask guidance that explains JavaScript regex syntax, capture groups, named groups, flags, replacement strings, and deterministic workflow-safe usage.
Non-goals
- No new workflow node type; use the existing
action.callTransform action model. - No external text loading from URLs/files/blobs.
- No AI-dependent runtime behavior.
- No full visual regex builder in this phase.
- No guarantee that every possible catastrophic JavaScript regex can be safely interrupted once execution starts; guardrails should prevent common risky inputs/patterns before execution.
- No PCRE-only syntax support beyond what JavaScript
RegExpsupports.
Users and Primary Flows
MSP workflow author: extract an incident ID from text
- Adds a Transform action.
- Selects
Regex Extract. - Maps
textfrom a workflow payload field such aspayload.email.subject. - Enters a pattern such as
INC-(\d{6}). - Saves output as
payload.parsedIncident. - Uses
payload.parsedIncident.first.groups[0]or named captures in a later ticket/client lookup action.
MSP workflow author: detect whether text matches a policy
- Adds
Regex Match. - Maps
textfrom a ticket title or alert body. - Enters a pattern and flags.
- Saves output as
vars.regexResult. - Uses
vars.regexResult.matchedin acontrol.ifbranch.
MSP workflow author: normalize text
- Adds
Regex Replace. - Maps source text from a payload or previous action output.
- Enters a pattern like
\s+, replacement, and replace-all behavior. - Saves the normalized text for downstream actions.
AI-assisted workflow author
- Opens existing Quick Ask or contextual workflow AI affordance if present.
- Asks: “Write a workflow regex to extract the device hostname and serial number from this alert.”
- Alga explains which regex Transform action to use, provides a JavaScript regex pattern, explains groups/flags, and tells the user where to paste it.
- User stores deterministic action config in the workflow designer.
UX / UI Notes
- Regex actions appear under the existing Transform palette group.
- Inputs should render with helpful labels/descriptions:
text: source text to inspect or modifypattern: JavaScript regular expression body, without surrounding/.../flags: JavaScript regex flags, constrained to supported valuesreplacement: replacement string for replace actionmaxMatches: match cap for extractrequireMatch: optional failure behavior for extract/match
- If the editor has specialized action input support, regex pattern fields should use multiline/text input with helper text rather than a tiny one-line generic field.
- Save output paths should continue to validate scoped paths such as
payload.*,vars.*, andmeta.*. - Downstream reference trees should expose stable output fields such as
matched,first,matches,text, andreplacementCount. Named capture inference is desirable but can be implemented as a second step if generic outputs are shipped first. - Run Studio should surface action-level regex errors first, especially invalid pattern/flag errors and require-match failures.
Requirements
Functional Requirements
- Register
transform.regex_matchas a pure Transform action. transform.regex_matchaccepts at leasttext,pattern, optionalflags, and optionalrequireMatch.transform.regex_matchreturns at least{ matched, match, index, groups, namedGroups }, where missing match fields arenullor empty in a consistent documented shape.- Register
transform.regex_extractas a pure Transform action. transform.regex_extractaccepts at leasttext,pattern, optionalflags, optionalmaxMatches, and optionalrequireMatch.transform.regex_extractreturns at least{ matched, count, first, matches }, where each match contains{ text, index, groups, namedGroups }.transform.regex_extractsupports numbered capture groups.transform.regex_extractsupports JavaScript named capture groups where the runtime supports them.- Register
transform.regex_replaceas a pure Transform action. transform.regex_replaceaccepts at leasttext,pattern, optionalflags,replacement, and optionalreplaceAll.transform.regex_replacereturns at least{ text, replacementCount }.transform.regex_replacesupports JavaScript replacement tokens such as$1,$2,$<name>, and$$, or explicitly documents any limits.- Regex actions validate pattern syntax before execution and fail with actionable messages for invalid patterns.
- Regex actions validate flags and reject unsupported or duplicate flags with actionable messages.
- Regex actions enforce guardrails for max source text length, max pattern length, and max match count.
- Regex actions avoid infinite loops for zero-width global matches.
- No-match behavior is deterministic: by default no match is a successful result with
matched: false/ empty matches;requireMatchturns no match into an action failure. - All regex transform actions are
sideEffectful: falseand use engine-provided idempotency. - Action schemas are explicit enough for the catalog/designer to expose input and output field names.
- Outputs save through existing
action.call.saveAs; no new assignment behavior is required. - The workflow designer exposes regex transform outputs in downstream workflow references.
- Run Studio displays useful regex action failure messages before generic wrapper errors.
- Quick Ask guidance covers action names, JavaScript regex pattern syntax, flags, numbered captures, named captures, replacement strings,
saveAsexamples, guardrails, and deterministic runtime behavior. - Regex actions are available regardless of AI entitlement; AI assistance remains gated by existing AI Assistant/Quick Ask access.
Non-functional Requirements
- Runtime behavior must be deterministic and tenant-agnostic.
- Actions must not access the database, network, filesystem, or secrets directly.
- Regex execution must fail fast on invalid inputs and protect workflow workers from obvious expensive patterns/inputs.
- Error messages should distinguish invalid pattern, invalid flags, guardrail limit, no match with
requireMatch, and replacement errors. - Existing workflows and transform actions must remain backward-compatible.
Data / API / Integrations
- No database migration is required.
- Main runtime registration should live in
shared/workflow/runtime/actions/registerTransformActions.ts, following existing transform action patterns. - If EE has a separate workflow runtime action registration or exposure layer, mirror the JSON feature integration in
ee/packages/workflows/src/actions/workflow-runtime-v2-actions.tsas needed. - Designer work should follow the JSON transform/editor changes in:
ee/server/src/components/workflow-designer/WorkflowDesigner.tsxee/server/src/components/workflow-designer/actionInputEditorState.tsee/server/src/components/workflow-designer/workflowDataContext.tsee/server/src/components/workflow-designer/WorkflowStepSaveOutputSection.tsxee/server/src/components/workflow-designer/workflowSaveAsPath.tsee/server/src/components/workflow-designer/mapping/InputMappingEditor.tsx
- Run Studio error display should follow the JSON feature pattern in
workflowRunDisplayError.tsandWorkflowRunDetailsPanel.tsx. - AI guidance should follow the JSON guidance pattern, likely with a new regex-specific guidance module or an expanded workflow transform guidance module.
Security / Permissions
- Regex Transform actions are not AI-gated.
- Quick Ask/AI guidance remains gated by existing AI Assistant feature/add-on checks.
- Regex outputs may persist sensitive content into workflow state through
saveAs; guidance should warn users not to save secret-derived or sensitive captures unless intentional. - Regex patterns should be treated as workflow configuration, not executable code, but JavaScript regex can still be expensive; guardrails are required.
Observability
No new production observability is required for MVP. Existing workflow action failure logs and Run Studio details should be sufficient. Tests should assert the action-level error messages that users see.
Rollout / Migration
- No migration required.
- Existing workflows are unaffected.
- New actions appear in the Transform catalog after registration.
- AI guidance improvements apply automatically to entitled Quick Ask users.
Open Questions
- Do we include named capture output schema inference in the first implementation, or only generic
namedGroupsrecords? - Should we add a safe-regex/static-analysis dependency, or rely on source length, pattern length, flags, and match-count limits?
- Should
regex_matchandregex_extractbe separate actions, or should one action cover both? Current recommendation is separate for clearer authoring. - Should
regex_replacesupport both JavaScript replacement-token mode and literal replacement mode?
Acceptance Criteria (Definition of Done)
- Workflow authors can match text with regex and branch on a saved boolean result.
- Workflow authors can extract numbered and named captures and reference them downstream.
- Workflow authors can replace text with regex and save normalized output.
- Invalid patterns/flags and require-match misses fail with clear action-level messages in Run Studio.
- Regex actions appear under Transform with explicit input/output schemas and saveAs support.
- Quick Ask can explain how to author regex workflow transforms without implying AI runs inside workflow execution.
- Unit/integration tests cover happy paths, failures, guardrails, catalog registration, saveAs/downstream references, Run Studio error display, and Quick Ask guidance.