@fluentcommerce/ai-skills 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +622 -0
  3. package/bin/cli.mjs +1973 -0
  4. package/content/cli/agents/fluent-cli/agent.json +149 -0
  5. package/content/cli/agents/fluent-cli.md +132 -0
  6. package/content/cli/skills/fluent-bootstrap/SKILL.md +181 -0
  7. package/content/cli/skills/fluent-cli-index/SKILL.md +63 -0
  8. package/content/cli/skills/fluent-cli-mcp-cicd/SKILL.md +77 -0
  9. package/content/cli/skills/fluent-cli-reference/SKILL.md +1031 -0
  10. package/content/cli/skills/fluent-cli-retailer/SKILL.md +85 -0
  11. package/content/cli/skills/fluent-cli-settings/SKILL.md +106 -0
  12. package/content/cli/skills/fluent-connect/SKILL.md +886 -0
  13. package/content/cli/skills/fluent-module-deploy/SKILL.md +349 -0
  14. package/content/cli/skills/fluent-profile/SKILL.md +180 -0
  15. package/content/cli/skills/fluent-workflow/SKILL.md +310 -0
  16. package/content/dev/agents/fluent-dev/agent.json +88 -0
  17. package/content/dev/agents/fluent-dev.md +525 -0
  18. package/content/dev/reference-modules/catalog.json +4754 -0
  19. package/content/dev/skills/fluent-build/SKILL.md +192 -0
  20. package/content/dev/skills/fluent-connection-analysis/SKILL.md +386 -0
  21. package/content/dev/skills/fluent-custom-code/SKILL.md +895 -0
  22. package/content/dev/skills/fluent-data-module-scaffold/SKILL.md +714 -0
  23. package/content/dev/skills/fluent-e2e-test/SKILL.md +394 -0
  24. package/content/dev/skills/fluent-event-api/SKILL.md +945 -0
  25. package/content/dev/skills/fluent-feature-explain/SKILL.md +603 -0
  26. package/content/dev/skills/fluent-feature-plan/PLAN_TEMPLATE.md +695 -0
  27. package/content/dev/skills/fluent-feature-plan/SKILL.md +227 -0
  28. package/content/dev/skills/fluent-job-batch/SKILL.md +138 -0
  29. package/content/dev/skills/fluent-mermaid-validate/SKILL.md +86 -0
  30. package/content/dev/skills/fluent-module-scaffold/SKILL.md +1928 -0
  31. package/content/dev/skills/fluent-module-validate/SKILL.md +775 -0
  32. package/content/dev/skills/fluent-pre-deploy-check/SKILL.md +1108 -0
  33. package/content/dev/skills/fluent-retailer-config/SKILL.md +1111 -0
  34. package/content/dev/skills/fluent-rule-scaffold/SKILL.md +385 -0
  35. package/content/dev/skills/fluent-scope-decompose/SKILL.md +1021 -0
  36. package/content/dev/skills/fluent-session-audit-export/SKILL.md +632 -0
  37. package/content/dev/skills/fluent-session-summary/SKILL.md +195 -0
  38. package/content/dev/skills/fluent-settings/SKILL.md +1058 -0
  39. package/content/dev/skills/fluent-source-onboard/SKILL.md +632 -0
  40. package/content/dev/skills/fluent-system-monitoring/SKILL.md +767 -0
  41. package/content/dev/skills/fluent-test-data/SKILL.md +513 -0
  42. package/content/dev/skills/fluent-trace/SKILL.md +1143 -0
  43. package/content/dev/skills/fluent-transition-api/SKILL.md +346 -0
  44. package/content/dev/skills/fluent-version-manage/SKILL.md +744 -0
  45. package/content/dev/skills/fluent-workflow-analyzer/SKILL.md +959 -0
  46. package/content/dev/skills/fluent-workflow-builder/SKILL.md +319 -0
  47. package/content/dev/skills/fluent-workflow-deploy/SKILL.md +267 -0
  48. package/content/mcp-extn/agents/fluent-mcp.md +69 -0
  49. package/content/mcp-extn/skills/fluent-mcp-tools/SKILL.md +461 -0
  50. package/content/mcp-official/agents/fluent-mcp-core.md +91 -0
  51. package/content/mcp-official/skills/fluent-mcp-core/SKILL.md +94 -0
  52. package/content/rfl/agents/fluent-rfl.md +56 -0
  53. package/content/rfl/skills/fluent-rfl-assess/SKILL.md +172 -0
  54. package/docs/CAPABILITY_MAP.md +77 -0
  55. package/docs/CLI_COVERAGE.md +47 -0
  56. package/docs/DEV_WORKFLOW.md +802 -0
  57. package/docs/FLOW_RUN.md +142 -0
  58. package/docs/USE_CASES.md +404 -0
  59. package/metadata.json +156 -0
  60. package/package.json +51 -0
@@ -0,0 +1,632 @@
1
+ ---
2
+ name: fluent-source-onboard
3
+ description: Onboard existing Java source code into a proper Fluent Commerce extension module. Analyzes non-standard code layouts (loose files, decompiled JARs, different build systems), restructures into Maven multi-module format with module.json, validates the result, and optionally attempts a build. Triggers on "onboard source", "refactor to module", "convert to module format", "restructure module", "import source code", "migrate to fluent module".
4
+ user-invocable: true
5
+ allowed-tools: Bash, Read, Write, Edit, Glob, Grep
6
+ argument-hint: <source-path> [--module-name <name>] [--account-prefix <PREFIX>] [--dry-run] [--skip-build]
7
+ ---
8
+
9
+ # Source Onboarder
10
+
11
+ Take existing Java source code — whether loose files, a non-standard project layout, a decompiled JAR, or a project using a different build system — and restructure it into a proper Fluent Commerce extension module that passes `/fluent-module-validate` and builds with `/fluent-build`.
12
+
13
+ ## When to Use
14
+
15
+ - "I have Java rule classes but they're not in a Fluent module structure"
16
+ - "Onboard this decompiled JAR into a buildable module"
17
+ - "Convert this Gradle project to Fluent Commerce module format"
18
+ - "I have source code from another team — make it a proper module"
19
+ - "Restructure this code into the standard Maven multi-module layout"
20
+ - "Import these rule classes into a deployable module"
21
+ - Code exists in `accounts/<PROFILE>/SOURCE/` but doesn't pass `/fluent-module-validate`
22
+ - Decompiled output exists in `accounts/<PROFILE>/SOURCE/.decompiled/` and needs to become a buildable module
23
+ - `/fluent-scope-decompose` generated a `SOURCE_ONBOARD` task
24
+
25
+ ## When NOT to Use
26
+
27
+ - Source code doesn't exist yet --> `/fluent-module-scaffold` (creates from scratch)
28
+ - Module already exists and passes validation, just need to add rules --> `/fluent-rule-scaffold`
29
+ - Only need to analyze/understand code, not restructure --> `/fluent-custom-code`
30
+ - Module structure is fine but needs version bumps --> `/fluent-version-manage`
31
+
32
+ ## Ownership Boundary
33
+
34
+ This skill owns:
35
+ - Analyzing existing source layout and classifying its state
36
+ - Generating a restructuring plan (target module structure)
37
+ - Moving, renaming, and refactoring files into Fluent module format
38
+ - Generating missing infrastructure files (POMs, module.json, build scripts, .gitignore)
39
+ - Fixing common structural issues (wrong base class, missing annotations, package mismatches)
40
+ - Running post-restructure validation via `/fluent-module-validate`
41
+
42
+ This skill does **not** own:
43
+ - Building the module after restructuring --> `/fluent-build`
44
+ - Adding new rules not present in source --> `/fluent-rule-scaffold`
45
+ - Deploying the restructured module --> `/fluent-module-deploy`
46
+ - Deep behavior analysis of existing rules --> `/fluent-custom-code`
47
+ - Decompiling JARs (but uses decompiled output) --> `/fluent-custom-code` or `/fluent-connect`
48
+
49
+ ### Cross-Skill Integration
50
+
51
+ **Upstream:**
52
+ - `/fluent-custom-code` — May have already analyzed the source (reuse `source-map.json`, `workflow-rule-map.json`)
53
+ - `/fluent-connect` — May have already decompiled JARs (reuse `.decompiled/` output)
54
+ - `/fluent-scope-decompose` — May have generated the `SOURCE_ONBOARD` task that triggered this skill
55
+
56
+ **Downstream:**
57
+ - `/fluent-module-validate` — Validate the restructured output
58
+ - `/fluent-build` — Attempt a Maven compile to verify buildability
59
+ - `/fluent-rule-scaffold` — Add new rules to the now-valid module
60
+ - `/fluent-module-deploy` — Deploy the restructured module
61
+
62
+ ## Inputs
63
+
64
+ | Parameter | Required | Default | Description |
65
+ |-----------|----------|---------|-------------|
66
+ | `source-path` | Yes | -- | Path to existing source code. Can be a directory with Java files, a decompiled JAR output, or a non-standard project root. Relative to workspace or absolute. |
67
+ | `--module-name` | No | Auto-detect | Target module name. If not specified, derived from directory name or existing `module.json`. |
68
+ | `--account-prefix` | No | Auto-detect | Account context prefix for rule registration (e.g., `HMDEV`). Same detection logic as `/fluent-module-scaffold`. |
69
+ | `--dry-run` | No | `false` | Analyze and plan only — do not move or modify any files. Produces the restructuring plan and exits. |
70
+ | `--skip-build` | No | `false` | Skip the post-restructure Maven build verification. |
71
+ | `--preserve-original` | No | `true` | Keep original files in a `.onboard-backup/` directory. Set `false` to delete originals after restructuring. |
72
+
73
+ ## Execution Protocol
74
+
75
+ ### Phase 1: Source Analysis
76
+
77
+ **Goal:** Understand what exists, classify its state, and identify all rule classes.
78
+
79
+ #### Step 1.1: Classify Source Layout
80
+
81
+ Scan the provided `source-path` and classify into one of these categories:
82
+
83
+ | Category | Detection | Example |
84
+ |----------|-----------|---------|
85
+ | `DECOMPILED_JAR` | Path contains `.decompiled/` or has `DECOMPILED.md` marker | `SOURCE/.decompiled/fc-module-ext/` |
86
+ | `STANDARD_MODULE` | Has `module.json` + `pom.xml` + `src/main/java/` | Standard but may have issues |
87
+ | `PARTIAL_MODULE` | Has some but not all of: `module.json`, `pom.xml`, Maven layout | Missing pieces |
88
+ | `MAVEN_NONSTANDARD` | Has `pom.xml` but not Fluent module layout (missing `plugins/` structure) | Generic Maven project |
89
+ | `GRADLE_PROJECT` | Has `build.gradle` or `build.gradle.kts` | Needs Maven conversion |
90
+ | `LOOSE_JAVA` | Has `.java` files but no build system files | Bare source files |
91
+ | `MIXED` | Multiple of the above in subdirectories | Complex layout |
92
+
93
+ ```
94
+ source-path/
95
+ ├── Glob("**/*.java") → collect all Java files
96
+ ├── Glob("**/module.json") → find Fluent module manifests
97
+ ├── Glob("**/pom.xml") → find Maven POMs
98
+ ├── Glob("**/build.gradle*") → find Gradle files
99
+ ├── Glob("**/DECOMPILED.md") → check for decompiled markers
100
+ └── Classify based on what's found
101
+ ```
102
+
103
+ #### Step 1.2: Discover Rule Classes
104
+
105
+ For each Java file found, determine if it's a Fluent rule class:
106
+
107
+ **Detection patterns** (check in order):
108
+ 1. Extends `BaseRule` or `Rule` (from Rubix SDK)
109
+ 2. Has `@RuleInfo` annotation
110
+ 3. Implements `run(ContextWrapper context)` or `run(Context context)` method
111
+ 4. Contains `context.getProp(...)` or `context.getEvent()` calls
112
+ 5. Is registered in a `module.json` (if one exists)
113
+
114
+ **For each detected rule, extract:**
115
+ - Class name (e.g., `ValidateReturnWindow`)
116
+ - Package name (e.g., `com.fluentcommerce.rule.order`)
117
+ - Base class (`BaseRule`, `Rule`, or other)
118
+ - Entity types accepted (from `@RuleInfo` or method signatures)
119
+ - Parameters read (from `context.getProp(...)` calls)
120
+ - Events produced (from `context.action().sendEvent(...)` calls)
121
+ - Has corresponding test class? (`<ClassName>Test.java`)
122
+
123
+ **For decompiled source**, also flag:
124
+ - Synthetic variable names (e.g., `var1`, `this$0`)
125
+ - Missing Javadoc/comments
126
+ - Confidence level: decompiled vs original
127
+
128
+ #### Step 1.3: Detect Existing module.json
129
+
130
+ If a `module.json` exists in the source path:
131
+ - Parse it for existing rule registrations
132
+ - Compare against discovered Java classes
133
+ - Flag mismatches:
134
+ - Rules in `module.json` but no Java class found (orphaned registration)
135
+ - Java rule classes not in `module.json` (unregistered rules)
136
+ - Version information
137
+ - Account prefix / symbolic name
138
+
139
+ #### Step 1.4: Check Against Deployed State
140
+
141
+ Query the live environment to understand what's deployed:
142
+
143
+ ```
144
+ plugin.list (compact: true)
145
+ ```
146
+
147
+ - Cross-reference discovered rule classes against deployed rules
148
+ - Identify rules that are deployed but have different versions or parameters
149
+ - Flag any namespace conflicts
150
+
151
+ ### Phase 2: Planning Gate
152
+
153
+ **MANDATORY: Present a restructuring plan before making ANY changes.** Use the template from `PLAN_TEMPLATE.md` in the `fluent-feature-plan` skill as the base structure. Every table row must carry a Source column (NEW/EXISTING/MODIFIED/REUSED/OOTB). Extend with the source-onboard-specific sections below.
154
+
155
+ Write the plan to: `accounts/<PROFILE>/plans/<YYYY-MM-DD>-source-onboard-<slug>.md`. Set `Status: PENDING`.
156
+
157
+ **Source-onboard specific sections** (in addition to the standard template):
158
+
159
+ #### 2.1 Source Assessment Summary
160
+
161
+ ```markdown
162
+ ## Source Assessment
163
+
164
+ | Property | Value |
165
+ |----------|-------|
166
+ | Source path | `accounts/HMDEV/SOURCE/.decompiled/fc-module-ext/` |
167
+ | Layout category | DECOMPILED_JAR |
168
+ | Java files found | 12 |
169
+ | Rule classes detected | 8 |
170
+ | Test classes found | 3 |
171
+ | Existing module.json | No |
172
+ | Existing pom.xml | No |
173
+ | Decompiled source | Yes (confidence: MEDIUM) |
174
+ ```
175
+
176
+ #### 2.2 Discovered Rules Table
177
+
178
+ ```markdown
179
+ ## Discovered Rules
180
+
181
+ | # | Class Name | Package | Base Class | Entity Types | Has Test | Deployed? | Status |
182
+ |---|-----------|---------|------------|-------------|----------|-----------|--------|
183
+ | 1 | ValidateOrder | com.fc.rule.order | BaseRule | ORDER | Yes | Yes (v2.1) | OK |
184
+ | 2 | CreateFulfilment | com.fc.rule.ful | Rule | ORDER | No | Yes (v2.1) | WARN: extends Rule, not BaseRule |
185
+ | 3 | NotifyWarehouse | com.fc.rule.webhook | BaseRule | FULFILMENT | No | No | NEW |
186
+ ```
187
+
188
+ #### 2.3 Target Module Structure
189
+
190
+ ```markdown
191
+ ## Target Structure
192
+
193
+ accounts/<PROFILE>/SOURCE/fluentcommerce-fc-module-<module-name>/
194
+ +-- plugins/
195
+ | +-- pom.xml # NEW: parent POM
196
+ | +-- types/
197
+ | | +-- <alias>/
198
+ | | +-- pom.xml # NEW: types POM
199
+ | | +-- src/main/java/ # MOVED: DTO/type classes
200
+ | +-- util/
201
+ | | +-- <alias>/
202
+ | | +-- pom.xml # NEW: util POM
203
+ | | +-- src/main/java/ # MOVED: utility classes
204
+ | +-- rules/
205
+ | +-- <alias>/
206
+ | +-- pom.xml # NEW: rules POM
207
+ | +-- src/main/java/ # MOVED: rule classes (repackaged)
208
+ | +-- src/test/java/ # MOVED or GENERATED: test classes
209
+ +-- resources/
210
+ | +-- module.json # NEW or MERGED: rule registrations
211
+ +-- scripts/
212
+ | +-- build.sh # NEW: build script
213
+ | +-- build.ps1 # NEW: PowerShell build script
214
+ +-- .gitignore # NEW
215
+ ```
216
+
217
+ #### 2.4 File Operations Plan
218
+
219
+ ```markdown
220
+ ## File Operations
221
+
222
+ | # | Operation | Source | Target | Notes |
223
+ |---|-----------|--------|--------|-------|
224
+ | 1 | MOVE | .decompiled/fc-ext/com/fc/rule/order/ValidateOrder.java | plugins/rules/<alias>/src/main/java/com/fluentcommerce/rule/order/ValidateOrder.java | Repackage from com.fc to com.fluentcommerce |
225
+ | 2 | MOVE | .decompiled/fc-ext/com/fc/rule/ful/CreateFulfilment.java | plugins/rules/<alias>/src/main/java/com/fluentcommerce/rule/fulfilment/CreateFulfilment.java | Repackage + fix base class |
226
+ | 3 | GENERATE | -- | plugins/rules/<alias>/src/test/java/.../CreateFulfilmentTest.java | Test skeleton (no existing test) |
227
+ | 4 | GENERATE | -- | resources/module.json | 8 rule registrations |
228
+ | 5 | GENERATE | -- | plugins/pom.xml | Parent POM with SDK dependencies |
229
+ ```
230
+
231
+ #### 2.5 Code Modifications Plan
232
+
233
+ ```markdown
234
+ ## Code Modifications
235
+
236
+ | # | File | Change | Reason |
237
+ |---|------|--------|--------|
238
+ | 1 | CreateFulfilment.java | `extends Rule` -> `extends BaseRule` | Standard base class |
239
+ | 2 | All rule classes | Package `com.fc.rule.*` -> `com.fluentcommerce.rule.*` | Standard package convention |
240
+ | 3 | All rule classes | Add missing `@RuleInfo` annotation | Required for module.json wiring |
241
+ | 4 | NotifyWarehouse.java | Add `@Override` to `run()` method | Compiler warning fix |
242
+ ```
243
+
244
+ #### 2.6 Risk Assessment
245
+
246
+ ```markdown
247
+ ## Risk Assessment
248
+
249
+ | Risk | Severity | Mitigation |
250
+ |------|----------|------------|
251
+ | Package rename breaks imports in downstream code | MEDIUM | Grep for old package refs after restructure |
252
+ | Decompiled source may have subtle bytecode artifacts | LOW | Build verification will catch compile errors |
253
+ | Module.json registration keys may not match deployed names | HIGH | Cross-reference with plugin.list before deploy |
254
+ | Test classes may not compile due to missing test dependencies | LOW | POMs include standard test deps |
255
+ ```
256
+
257
+ **Wait for user approval.** On `--dry-run`, output the plan and exit without making changes.
258
+
259
+ ### Phase 3: Execute Restructuring
260
+
261
+ After approval, execute the plan in this order:
262
+
263
+ #### Step 3.1: Create Target Directory Structure
264
+
265
+ Generate the full Maven multi-module directory tree using the same structure as `/fluent-module-scaffold`:
266
+
267
+ ```
268
+ fluentcommerce-fc-module-<module-name>/
269
+ plugins/
270
+ pom.xml (parent, packaging=pom)
271
+ types/<alias>/pom.xml + src/main/java/
272
+ util/<alias>/pom.xml + src/main/java/
273
+ rules/<alias>/pom.xml + src/main/java/ + src/test/java/
274
+ resources/module.json
275
+ scripts/build.sh + build.ps1
276
+ .gitignore
277
+ ```
278
+
279
+ Use the **exact same POM templates, SDK versions, and build scripts** as `/fluent-module-scaffold` generates. Do not reinvent — reuse the same patterns.
280
+
281
+ #### Step 3.2: Move and Repackage Rule Classes
282
+
283
+ For each discovered rule class:
284
+
285
+ 1. **Copy** (not move initially) to target location under `plugins/rules/<alias>/src/main/java/`
286
+ 2. **Repackage** if the original package doesn't follow `com.fluentcommerce.*` convention:
287
+ - Update `package` declaration in the Java file
288
+ - Update all internal `import` statements that reference sibling classes
289
+ - Track old-to-new package mapping for cross-reference
290
+ 3. **Classify** non-rule classes:
291
+ - Classes that are DTOs/POJOs/types --> `plugins/types/<alias>/src/main/java/`
292
+ - Classes that are utilities/helpers --> `plugins/util/<alias>/src/main/java/`
293
+ - Classes that are rule implementations --> `plugins/rules/<alias>/src/main/java/`
294
+
295
+ **Classification heuristics:**
296
+ - Extends `BaseRule`/`Rule` or has `@RuleInfo` --> rule
297
+ - Is an `enum`, has only getters/setters, or has `@Data`/`@Builder` --> type
298
+ - Is a helper/utility (static methods, service patterns, no rule inheritance) --> util
299
+ - Unclear --> ask user, default to rules
300
+
301
+ #### Step 3.3: Fix Common Structural Issues
302
+
303
+ Apply these fixes automatically (all tracked in the plan):
304
+
305
+ | Issue | Fix | Auto-apply? |
306
+ |-------|-----|-------------|
307
+ | `extends Rule` instead of `extends BaseRule` | Change to `extends BaseRule` | Yes |
308
+ | Missing `@RuleInfo` annotation | Add with class name as description | Yes (warn: description is generic) |
309
+ | Missing `@Override` on `run()` method | Add `@Override` | Yes |
310
+ | Wrong import for `BaseRule`/`Rule` | Fix to `com.fluentretail.rubix.rule.meta.BaseRule` | Yes |
311
+ | Synthetic variable names (decompiled) | Leave as-is, add `// decompiled` comment at top | Yes |
312
+ | Missing `@ParamString` annotations on rule parameters | Add based on `context.getProp()` calls detected in Phase 1 | Yes |
313
+ | Non-standard `run()` signature | Fix to `run(ContextWrapper context)` | Ask user |
314
+
315
+ #### Step 3.4: Move or Generate Test Classes
316
+
317
+ For each rule class:
318
+
319
+ 1. If a test class exists in the source: **copy** it to `plugins/rules/<alias>/src/test/java/` with matching package
320
+ 2. If no test class exists: **generate** a skeleton test using the same template as `/fluent-rule-scaffold`:
321
+ - Class name: `<RuleName>Test.java`
322
+ - Imports: JUnit 5, Mockito, Fluent test utilities
323
+ - One `@Test` method: `test<RuleName>_shouldRun()` with setup/execute/verify structure
324
+ - Comment: `// TODO: implement test logic`
325
+
326
+ #### Step 3.5: Generate or Merge module.json
327
+
328
+ If no `module.json` exists in the source:
329
+ - **Generate** a new one following the same format as `/fluent-module-scaffold`
330
+ - Register all discovered rule classes with:
331
+ - Key: `<ACCOUNT_PREFIX>.<context>.<ClassName>` (e.g., `HMDEV.order.ValidateOrder`)
332
+ - Context derived from entity type or package name
333
+ - Class path: `com.fluentcommerce.rule.<domain>.<ClassName>`
334
+
335
+ If a `module.json` already exists:
336
+ - **Merge**: keep existing entries, add missing rules, flag conflicts
337
+ - Fix any rule keys that don't match the account prefix
338
+ - Preserve metadata fields (`_schema`, `title`, `description`, `authors`, etc.)
339
+ - Add missing metadata fields with sensible defaults
340
+
341
+ #### Step 3.6: Generate Build Infrastructure
342
+
343
+ **Files to generate** (same templates as `/fluent-module-scaffold`):
344
+
345
+ - `plugins/pom.xml` — Parent POM (packaging=pom, modules: types, util, rules)
346
+ - `plugins/types/<alias>/pom.xml` — Types submodule
347
+ - `plugins/util/<alias>/pom.xml` — Util submodule
348
+ - `plugins/rules/<alias>/pom.xml` — Rules submodule (depends on types + util, includes test deps)
349
+ - `scripts/build.sh` — Bash build script
350
+ - `scripts/build.ps1` — PowerShell build script
351
+ - `.gitignore` — Standard ignores (target/, *.class, .idea/, etc.)
352
+
353
+ **SDK version detection:**
354
+ - If existing POMs reference Fluent SDK versions, preserve them
355
+ - Otherwise use the latest versions from `/fluent-module-scaffold` defaults
356
+ - Always include: `rubix-plugin-sdk`, `fluent-api-client`, JUnit 5, Mockito
357
+
358
+ #### Step 3.7: Backup Original Files
359
+
360
+ If `--preserve-original` is true (default):
361
+ - Create `<module-root>/.onboard-backup/` directory
362
+ - Copy all original source files there (preserving directory structure)
363
+ - Write `BACKUP.md` with timestamp, source path, and file count
364
+
365
+ ### Phase 4: Validation
366
+
367
+ After restructuring, run validation checks to verify the result.
368
+
369
+ #### Step 4.1: Structure Validation
370
+
371
+ Run the same checks as `/fluent-module-validate`:
372
+
373
+ | Check | Expected | Severity |
374
+ |-------|----------|----------|
375
+ | `resources/module.json` exists | Yes | FAIL |
376
+ | `module.json` has valid JSON | Yes | FAIL |
377
+ | `module.json` has `name` field | Yes | FAIL |
378
+ | `module.json.rules[]` is non-empty | Yes | FAIL |
379
+ | Each rule in `module.json` has matching Java class | Yes | FAIL |
380
+ | Each Java rule class is in `module.json` | Yes | WARN |
381
+ | `plugins/pom.xml` exists | Yes | FAIL |
382
+ | Parent POM has `<packaging>pom</packaging>` | Yes | WARN |
383
+ | Rules POM references parent | Yes | WARN |
384
+ | Each rule extends `BaseRule` or `Rule` | Yes | WARN |
385
+ | Each rule has `@RuleInfo` annotation | Yes | WARN |
386
+ | Each rule has a corresponding test class | Yes | WARN |
387
+ | No orphaned Java files outside the standard layout | Yes | WARN |
388
+ | No leftover files from original layout | Yes | INFO |
389
+
390
+ Report results as a table with PASS/WARN/FAIL per check.
391
+
392
+ #### Step 4.2: Compilation Check (unless --skip-build)
393
+
394
+ Attempt a Maven build to verify the restructured module compiles:
395
+
396
+ ```bash
397
+ cd accounts/<PROFILE>/SOURCE/fluentcommerce-fc-module-<module-name>/plugins
398
+ mvn clean compile -q 2>&1
399
+ ```
400
+
401
+ **If build succeeds:** Report success with artifact coordinates.
402
+
403
+ **If build fails:**
404
+ - Parse Maven error output
405
+ - Classify errors:
406
+ - Missing imports (suggest adding dependencies to POM)
407
+ - Unresolved symbols (suggest checking package renames)
408
+ - Type mismatches (suggest reviewing decompiled artifacts)
409
+ - Present errors to user with suggested fixes
410
+ - Do NOT automatically retry — the user should review
411
+
412
+ #### Step 4.3: Deployed Rule Reconciliation
413
+
414
+ Cross-reference the restructured module against deployed rules:
415
+
416
+ ```
417
+ plugin.list (name filter: <ACCOUNT_PREFIX>)
418
+ ```
419
+
420
+ | Check | Result |
421
+ |-------|--------|
422
+ | Rules in module.json that are already deployed | LIST (version comparison) |
423
+ | Deployed rules NOT in this module | LIST (belong to other modules?) |
424
+ | Rule key format matches deployed format | PASS/FAIL per rule |
425
+ | Account prefix is consistent | PASS/FAIL |
426
+
427
+ #### Step 4.4: Functional Checklist
428
+
429
+ Present a manual verification checklist to the user:
430
+
431
+ ```markdown
432
+ ## Post-Onboard Checklist
433
+
434
+ - [ ] Review repackaged rule classes — verify business logic is preserved
435
+ - [ ] Review generated test skeletons — add meaningful test assertions
436
+ - [ ] Verify module.json rule keys match expected deployment names
437
+ - [ ] If source was decompiled: review for synthetic artifacts, add meaningful variable names
438
+ - [ ] Run full test suite: `cd plugins && mvn test`
439
+ - [ ] Deploy to sandbox: `/fluent-module-deploy`
440
+ - [ ] Run E2E test: `/fluent-e2e-test` to verify runtime behavior
441
+ ```
442
+
443
+ ### Phase 5: Summary Report
444
+
445
+ Output a structured summary:
446
+
447
+ ```markdown
448
+ ## Source Onboard Summary
449
+
450
+ | Metric | Value |
451
+ |--------|-------|
452
+ | Source category | DECOMPILED_JAR |
453
+ | Rule classes onboarded | 8 |
454
+ | Test classes moved | 3 |
455
+ | Test skeletons generated | 5 |
456
+ | Type/DTO classes moved | 2 |
457
+ | Utility classes moved | 1 |
458
+ | module.json rules registered | 8 |
459
+ | Code modifications applied | 12 |
460
+ | Validation: PASS | 14 |
461
+ | Validation: WARN | 3 |
462
+ | Validation: FAIL | 0 |
463
+ | Build status | SUCCESS |
464
+ | Original files backed up | Yes (.onboard-backup/) |
465
+
466
+ ### Files Created
467
+ - `plugins/pom.xml` (parent)
468
+ - `plugins/types/<alias>/pom.xml`
469
+ - `plugins/util/<alias>/pom.xml`
470
+ - `plugins/rules/<alias>/pom.xml`
471
+ - `resources/module.json` (8 rules)
472
+ - `scripts/build.sh`
473
+ - `scripts/build.ps1`
474
+ - `.gitignore`
475
+ - 5 test skeleton files
476
+
477
+ ### Code Changes Applied
478
+ - 8 classes repackaged: com.fc.rule.* -> com.fluentcommerce.rule.*
479
+ - 1 class fixed: CreateFulfilment extends Rule -> extends BaseRule
480
+ - 2 classes: added missing @RuleInfo annotation
481
+ - 3 classes: added missing @Override on run()
482
+
483
+ ### Next Steps
484
+ 1. Review generated tests and add assertions
485
+ 2. Run `/fluent-module-validate` for detailed structural report
486
+ 3. Build: `/fluent-build`
487
+ 4. Deploy: `/fluent-module-deploy`
488
+ ```
489
+
490
+ ---
491
+
492
+ ## Input Scenarios — Detailed Handling
493
+
494
+ ### Scenario A: Decompiled JAR (`.decompiled/` directory)
495
+
496
+ ```
497
+ accounts/HMDEV/SOURCE/.decompiled/fc-module-ext/
498
+ com/fluentcommerce/rule/order/ValidateOrder.class → .java (decompiled)
499
+ com/fluentcommerce/rule/fulfilment/CreateFulfilment.class → .java
500
+ DECOMPILED.md
501
+ ```
502
+
503
+ **Handling:**
504
+ 1. Read `DECOMPILED.md` for source JAR name, date, decompiler used
505
+ 2. All classes are rule candidates — classify by detection patterns
506
+ 3. Package structure may already be correct (decompiled from original)
507
+ 4. Add `// Decompiled source — variable names may be synthetic` header to each file
508
+ 5. Mark confidence as MEDIUM in module.json comments
509
+ 6. Generate all infrastructure files (POMs, module.json, build scripts)
510
+ 7. **Do not modify decompiled business logic** — only structural fixes (base class, annotations)
511
+
512
+ ### Scenario B: Loose Java Files
513
+
514
+ ```
515
+ some-directory/
516
+ ValidateOrder.java
517
+ CreateFulfilment.java
518
+ OrderHelper.java
519
+ OrderType.java
520
+ ```
521
+
522
+ **Handling:**
523
+ 1. No existing package structure — derive from class content or ask user
524
+ 2. Default package: `com.fluentcommerce.rule.<entity-type-lowercase>`
525
+ 3. Add `package` declarations to files that don't have them
526
+ 4. Classify: rules vs types vs utils
527
+ 5. Generate complete module infrastructure from scratch
528
+
529
+ ### Scenario C: Non-Standard Maven Project
530
+
531
+ ```
532
+ my-rules/
533
+ pom.xml (exists but not Fluent multi-module layout)
534
+ src/main/java/com/mycompany/rules/
535
+ ValidateOrder.java
536
+ CreateFulfilment.java
537
+ src/test/java/com/mycompany/rules/
538
+ ValidateOrderTest.java
539
+ ```
540
+
541
+ **Handling:**
542
+ 1. Existing POM — parse for dependency versions, group ID
543
+ 2. Existing package `com.mycompany` — repackage to `com.fluentcommerce`
544
+ 3. Existing tests — move alongside repackaged classes
545
+ 4. Restructure to multi-module layout (flat `src/` -> `plugins/rules/<alias>/src/`)
546
+ 5. Generate missing types/util submodules (empty initially)
547
+ 6. Preserve dependency versions from original POM where possible
548
+
549
+ ### Scenario D: Gradle Project
550
+
551
+ ```
552
+ my-gradle-module/
553
+ build.gradle
554
+ src/main/java/...
555
+ src/test/java/...
556
+ ```
557
+
558
+ **Handling:**
559
+ 1. Parse `build.gradle` for dependencies and versions
560
+ 2. Convert dependency declarations to Maven POM format
561
+ 3. Same restructuring as Scenario C but with Gradle-to-Maven conversion
562
+ 4. Warn about any Gradle plugins that don't have Maven equivalents
563
+
564
+ ### Scenario E: Existing Module with Structural Issues
565
+
566
+ ```
567
+ fc-module-ext/
568
+ resources/module.json (exists, possibly outdated)
569
+ plugins/
570
+ pom.xml (exists but may be wrong)
571
+ rules/<alias>/
572
+ src/main/java/... (exists)
573
+ ```
574
+
575
+ **Handling:**
576
+ 1. This is a "repair" mode — module exists but has issues
577
+ 2. Run `/fluent-module-validate` to identify specific problems
578
+ 3. Generate a targeted fix plan (don't rebuild from scratch)
579
+ 4. Fix only what's broken:
580
+ - Missing submodules → generate them
581
+ - Orphaned rules → add to module.json
582
+ - Wrong base class → fix
583
+ - Missing tests → generate skeletons
584
+ 5. Preserve everything that's already correct
585
+
586
+ ---
587
+
588
+ ## Error Recovery
589
+
590
+ | Error | Handling |
591
+ |-------|---------|
592
+ | Java file doesn't compile after repackaging | List errors, suggest fixes, don't auto-retry |
593
+ | module.json rule key conflicts with existing deployed rule | Warn, ask user to choose: keep existing key or use new |
594
+ | Circular package dependencies after restructuring | Flag in validation, suggest manual reorganization |
595
+ | Decompiled source has unresolvable artifacts | Mark as `// MANUAL_REVIEW_NEEDED`, add to checklist |
596
+ | Maven build fails on SDK version mismatch | Suggest updating SDK versions, show what deployed modules use |
597
+ | Source path doesn't contain any Java files | Abort: "No Java files found in <path>. Verify the source path." |
598
+ | Source path contains only non-rule Java files | Abort: "No Fluent rule classes detected. Found N Java files but none extend BaseRule/Rule or have @RuleInfo." |
599
+ | `--module-name` conflicts with existing module | Warn and ask user: rename or merge? |
600
+
601
+ ---
602
+
603
+ ## Cross-References
604
+
605
+ - Module structure reference: `/fluent-module-scaffold`
606
+ - Source code analysis: `/fluent-custom-code`
607
+ - Structure validation: `/fluent-module-validate`
608
+ - Build execution: `/fluent-build`
609
+ - Rule addition: `/fluent-rule-scaffold`
610
+ - Deployment: `/fluent-module-deploy`
611
+ - Version management: `/fluent-version-manage`
612
+ - Pre-deploy checks: `/fluent-pre-deploy-check`
613
+ - JAR decompilation: `/fluent-custom-code` (Step 1A) or `/fluent-connect` (workspace setup)
614
+
615
+ ## Example Usage
616
+
617
+ ```bash
618
+ # Onboard decompiled JAR output into a module
619
+ /fluent-source-onboard accounts/HMDEV/SOURCE/.decompiled/fc-module-ext/
620
+
621
+ # Onboard loose Java files with explicit module name
622
+ /fluent-source-onboard ./my-rules/ --module-name hm-returns
623
+
624
+ # Dry run — analyze and plan only, don't modify anything
625
+ /fluent-source-onboard accounts/HMDEV/SOURCE/legacy-project/ --dry-run
626
+
627
+ # Onboard without attempting build (e.g., missing SDK locally)
628
+ /fluent-source-onboard accounts/HMDEV/SOURCE/old-module/ --skip-build
629
+
630
+ # Repair an existing module with structural issues
631
+ /fluent-source-onboard accounts/HMDEV/SOURCE/fluentcommerce-fc-module-ext/
632
+ ```