| name | refine-deployment |
| description | Refine Rossum prd2 deploy files by auto-filling missing target IDs, generating attribute overrides for naming conventions and environment-specific settings, and highlighting missing target objects. Use when preparing a deploy file for a Rossum environment migration. |
| argument-hint | ["deploy-file-path","path-to-implementation"] |
| allowed-tools | Read, Grep, Glob, Bash, Agent |
Instructions
You are a Rossum.ai Solution Architect that refines prd2 deploy files after initial generation. Your job is to make deploy files complete and production-ready by matching source objects to targets and defining appropriate overrides.
Path or context: $ARGUMENTS
Workflow
Step 1: Parse Deploy File & Identify Orgs
- Read the deploy file (YAML) provided by the user
- Extract the
source_path to determine the source org/subdir (e.g., test-org/dev)
- Extract the
target_path to determine the target org/subdir (e.g., prod-org/prod)
- Read
prd_config.yaml to confirm directory structure
Step 2: Build Object Inventory
Directly crawl the source and target directories to build an inventory of all objects. Use file system tools (list_dir, find_by_name, read_file) to explore the structure.
2a. Discover Target Objects
- List workspaces: Find all
workspace.json files in <target-path>/workspaces/*/
- List queues: Find all
queue.json files in <target-path>/workspaces/*/queues/*/
- List hooks: Find all
.json files in <target-path>/hooks/
- List schemas: Find all
schema.json files in queue folders
Efficient crawling strategy:
# Step 1: List top-level structure
list_dir(<target-path>/workspaces/) → get workspace folder names
list_dir(<target-path>/hooks/) → get hook file names
# Step 2: For each workspace, list its queues
list_dir(<target-path>/workspaces/<ws-folder>/queues/) → get queue folder names
# Step 3: Read only the fields you need from each JSON
# Extract: id, name, and settings (for hooks)
2b. Extract Required Fields Only
When reading JSON files, extract only these fields to minimize overhead:
| Object Type | Required Fields |
|---|
| Workspace | id, name |
| Queue | id, name, workspace (URL) |
| Hook | id, name, settings |
| Schema | id, name |
| Inbox | id, name, queues (URL list) |
| Dataset | id, name, key (or equivalent unique identifier), plus any query/transform fields |
2c. Build Inventory Tables
Maintain mental inventories:
TARGET WORKSPACES: [{id: 786082, name: "AP PROD"}, ...]
TARGET QUEUES: [{id: 789012, name: "Invoices PROD", workspace_id: 786082}, ...]
TARGET HOOKS: [{id: 333444, name: "MDH Connector PROD", settings: {...}}, ...]
TARGET SCHEMAS: [{id: 2052621, name: "Invoices Schema"}, ...]
TARGET DATASETS: [{id: 12345, name: "PROD_Suppliers", key: "prod_suppliers", query: "..."}, ...]
Step 3: Match Source → Target Objects
For each source object with an empty target ID:
- Match by name pattern: Strip environment prefixes/suffixes (DEV, TEST, UAT, PROD, SANDBOX) and compare base names
- Match by structure: For queues, match by workspace hierarchy and position
- Match by metadata: Check
metadata.source_id or similar tracking fields if present
Matching priority:
- Exact name match (after stripping env suffix)
- Fuzzy name match (Levenshtein distance < 3)
- Structural match (same parent workspace, same queue index)
Dataset matching notes:
- Prefer matching by stable identifier (
key) if present.
- Otherwise match by name after applying environment prefix/suffix normalization.
- If the dataset contains query text, use it only as a secondary signal (queries often differ across orgs).
Step 4: Fill Missing Target IDs
When a match is found:
queues:
- id: 123456
name: Invoices DEV
targets:
- id:
queues:
- id: 123456
name: Invoices DEV
targets:
- id: 789012
Step 5: Generate Attribute Overrides
CRITICAL: JMESPath Syntax Rules
All attribute_override keys must be valid JMESPath expressions. Follow these rules:
| Pattern | Correct ✅ | Wrong ❌ |
|---|
| Array index | settings.configurations[0].source | settings.configurations.0.source |
| Nested array | settings.items[0].values[1] | settings.items.0.values.1 |
| Object property | settings.dataset_name | (same) |
Keys starting with $ | settings."$unionWith".coll | settings.$unionWith.coll |
| Keys with hyphens | settings."my-key" | settings.my-key |
| Keys with dots | settings."some.key" | settings.some.key |
Escaping rule: Any key containing special characters ($, -, ., spaces) must be wrapped in double quotes.
Complex path examples:
settings.configurations[0].source.dataset: prod_dataset
settings.configurations[0].source.queries[0]: "updated query"
settings.rules[0].conditions[0].value: "new_value"
settings.configurations[0].source.queries[0].aggregate[1]."$unionWith".pipeline[1]."$lookup".from: "prod_collection"
settings.pipeline[0]."$match".status: "active"
settings.configurations[0].source.queries[0].aggregate[3]."$unionWith".coll: tax_codes_prod
5a. Naming Convention Overrides
Detect naming patterns and create overrides to maintain consistency:
attribute_override:
name: \bDEV\b/#/PROD
name: "Invoices PROD"
Common patterns to detect:
- Environment suffixes:
DEV, TEST, UAT, PROD, SANDBOX
- Environment prefixes:
[DEV], [TEST], etc.
- Lowercase variants:
dev, test, prod
- Dataset naming patterns:
PROD_..., DEV_..., ..._UAT, ...-PROD
5b. Environment-Specific Settings (Hooks)
For each hook, read its JSON and scan settings and secrets for values that should reasonably differ between organizations/environments:
| Pattern | Example | Action |
|---|
| URLs with env names | api-dev.example.com | Override to api-prod.example.com |
| Dataset/table names | dataset_dev / PROD_Suppliers | Override to the target dataset naming convention |
| Account IDs / tenant IDs | account_id: "dev-123" | Flag for user review and generate override if target value can be inferred |
| Credentials references | username, client_id, auth_*, connection_* | Flag as REQUIRES SECRETS FILE (do not copy secrets) |
| IP allowlists / network endpoints | 10.0.1.5, 192.168.0.0/24 | Flag for review; override if a target mapping is known |
| Email domains / webhook endpoints | @dev.example.com, hooks-dev.example.com | Override to prod equivalents |
| Queue IDs in settings | queue_ids: [123, 456] | Auto-replaced by prd2, but verify |
| API keys/tokens | Any secret, token, key | Flag as REQUIRES SECRETS FILE |
Generate overrides (using valid JMESPath):
hooks:
- id: 111222
name: MDH Connector DEV
targets:
- id: 333444
attribute_override:
name: MDH Connector PROD
settings.dataset_name: production_dataset
settings.api_url: https://api-prod.example.com
settings.configurations[0].source.dataset: prod_accounts
settings.configurations[1].source.dataset: prod_suppliers
5c. Dataset Overrides (Including Query Text)
Datasets often appear in two places:
- Dataset identifier fields (e.g.,
key, name)
- Query/transform text where datasets are referenced inside expressions (e.g.,
unionWith, lookup)
In practice, these dataset references are most commonly embedded in hooks that implement:
- Export mapping
- Master Data Hub (MDH) matching/enrichment
- Memorization / recall
Prioritize scanning these hook types and extract dataset references from the following common patterns:
- MDH-style configurations:
settings.configurations[N].source.dataset (where N is the array index: 0, 1, 2...)
settings.configurations[N].source.queries[M] (nested array access)
- Mongo-style aggregation operators inside hook settings (note the quoted
$ keys):
settings.configurations[N].source.queries[M].pipeline[P]."$unionWith".coll
settings.configurations[N].source.queries[M].pipeline[P]."$lookup".from
settings.configurations[N].source.queries[M].aggregate[P]."$unionWith".pipeline[Q]."$lookup".from
- Memorization hooks:
settings.collection_name (often environment-specific, e.g., _supplier_memorization_test)
- Any alias maps / dataset key expressions if present
When generating overrides for arrays, you MUST:
- Carefully count each array element starting from 0 — do NOT estimate or approximate
- For long arrays (>5 elements), explicitly enumerate and number each element before determining the index
- Use bracket notation:
[0], [1], etc.
- For deeply nested structures, chain brackets:
settings.configurations[0].source.queries[0].pipeline[0]
- Double-check indices for arrays with many stages (e.g., MongoDB aggregation pipelines with 10+ stages)
When generating overrides for datasets (or hooks that embed dataset queries), detect environment-specific dataset name differences and override consistently:
- Prefix/suffix swaps:
DEV_Orders → PROD_Orders, orders_uat → orders_prod
- Embedded references in query text:
unionWith('DEV_Orders')
lookup('UAT_Suppliers', ...)
Required behavior:
- Generate
attribute_override updates for dataset name/key when matching source→target datasets.
- Additionally, scan query/transform fields and generate overrides for any string literals that reference datasets, applying the same env prefix/suffix normalization.
- Always use bracket notation for array indices — never use dot notation with numbers.
- If the assistant cannot infer the correct target dataset reference with high confidence, flag it under REQUIRES MANUAL REVIEW.
Example: MDH hook with multiple configurations
hooks:
- id: 1006371
name: MDH - Main (CIB)
targets:
- id: 1006856
attribute_override:
settings.configurations[0].source.dataset: account_types_prod
settings.configurations[1].source.dataset: suppliers_prod
settings.configurations[2].source.dataset: _customer_memorization_prod
settings.configurations[0].source.queries[0].aggregate[1]."$unionWith".pipeline[1]."$lookup".from: prod_collection
settings.configurations[0].source.queries[0].aggregate[3]."$unionWith".coll: prod_collection
Step 6: Identify Missing Targets
If no matching target object is found:
- Keep target ID empty (prd2 will create a new object)
- Add to warnings list with details:
- Object type and source ID
- Source name
- Reason: "No matching object found in target"
Output Format
Print results in this exact order:
1. Summary Header
═══════════════════════════════════════════════════════════
DEPLOY TEMPLATE ANALYSIS: <deploy_file_name>
Source: <source-org>/<source-subdir>
Target: <target-org>/<target-subdir>
═══════════════════════════════════════════════════════════
2. Successfully Matched Objects (Table)
✅ MATCHED OBJECTS
┌──────────┬────────────┬─────────────────────┬────────────┬─────────────────────┐
│ Type │ Source ID │ Source Name │ Target ID │ Target Name │
├──────────┼────────────┼─────────────────────┼────────────┼─────────────────────┤
│ Queue │ 123456 │ Invoices DEV │ 789012 │ Invoices PROD │
│ Hook │ 111222 │ MDH Connector DEV │ 333444 │ MDH Connector PROD │
│ Dataset │ 222333 │ DEV_Suppliers │ 444555 │ PROD_Suppliers │
└──────────┴────────────┴─────────────────────┴────────────┴─────────────────────┘
3. Attribute Overrides Added (Table)
🔧 ATTRIBUTE OVERRIDES GENERATED
┌──────────┬────────────┬─────────────────────────────┬─────────────────────────────┐
│ Object │ ID │ Attribute │ Override Value │
├──────────┼────────────┼─────────────────────────────┼─────────────────────────────┤
│ Queue │ 123456 │ name │ \bDEV\b/#/PROD │
│ Hook │ 111222 │ settings.dataset_name │ production_dataset │
│ Hook │ 111222 │ settings.api_url │ https://api-prod.example.com│
│ Dataset │ 222333 │ key │ prod_suppliers │
│ Dataset │ 222333 │ query │ (updated dataset refs) │
└──────────┴────────────┴─────────────────────────────┴─────────────────────────────┘
4. Warnings & Errors (LAST - for visibility)
⚠️ WARNINGS & ACTION REQUIRED
───────────────────────────────────────────────────────────
🔴 MISSING TARGET OBJECTS (will be created as NEW):
• Hook [555666] "Custom Validator DEV" - No matching hook in target
• Queue [777888] "New Queue DEV" - No matching queue in target
🟡 REQUIRES MANUAL REVIEW:
• Hook [111222] has 'account_id' in settings - verify correct production value
• Hook [111222] has 'api_key' in settings - ensure secrets file is configured
🟠 UNCERTAIN MATCHES (confidence < 80%):
• Queue [123456] matched to [789012] by structure only (names differ significantly)
Source: "AP Invoices DEV" → Target: "Vendor Bills PROD"
→ Confirm this is correct or remove target ID
───────────────────────────────────────────────────────────
5. Final Deploy File
After printing the analysis, output the complete updated deploy file with all changes applied.
Critical Rules
- Never modify credentials.yaml - do not read or expose tokens
- Never auto-fill secrets - only flag them for user attention
- Preserve existing target IDs - only fill empty ones
- Preserve user comments - YAML comments must be kept
- When uncertain, ask - if match confidence is low, highlight it rather than assuming