@njuptlzf/mcp-adapter 2.29.0-0.0.1

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 (131) hide show
  1. package/CHANGELOG.md +1205 -0
  2. package/LICENSE +21 -0
  3. package/MAPPING.md +73 -0
  4. package/README.md +564 -0
  5. package/abort.ts +34 -0
  6. package/adapters/pi-renderer.ts +7 -0
  7. package/adapters/protocol-elicitation-forwarder.ts +164 -0
  8. package/adapters/protocol-sampling-forwarder.ts +108 -0
  9. package/adapters/universal-host.ts +213 -0
  10. package/agent-dir.ts +68 -0
  11. package/agent-plugin-loader.ts +377 -0
  12. package/app-bridge.bundle.js +67 -0
  13. package/banner.png +0 -0
  14. package/bin/mcp-server.ts +282 -0
  15. package/cli.js +392 -0
  16. package/commands.ts +735 -0
  17. package/config.ts +1284 -0
  18. package/consent-manager.ts +64 -0
  19. package/direct-tools.ts +619 -0
  20. package/dist/agent-dir.d.ts +10 -0
  21. package/dist/agent-dir.js +63 -0
  22. package/dist/agent-dir.js.map +1 -0
  23. package/dist/agent-plugin-loader.d.ts +8 -0
  24. package/dist/agent-plugin-loader.js +356 -0
  25. package/dist/agent-plugin-loader.js.map +1 -0
  26. package/dist/config.d.ts +123 -0
  27. package/dist/config.js +1087 -0
  28. package/dist/config.js.map +1 -0
  29. package/dist/metadata-cache.d.ts +19 -0
  30. package/dist/metadata-cache.js +319 -0
  31. package/dist/metadata-cache.js.map +1 -0
  32. package/dist/package-mcp-loader.d.ts +2 -0
  33. package/dist/package-mcp-loader.js +156 -0
  34. package/dist/package-mcp-loader.js.map +1 -0
  35. package/dist/resource-tools.d.ts +1 -0
  36. package/dist/resource-tools.js +15 -0
  37. package/dist/resource-tools.js.map +1 -0
  38. package/dist/types.d.ts +564 -0
  39. package/dist/types.js +287 -0
  40. package/dist/types.js.map +1 -0
  41. package/dist/ui-app-bridge-helpers.d.ts +6 -0
  42. package/dist/ui-app-bridge-helpers.js +37 -0
  43. package/dist/ui-app-bridge-helpers.js.map +1 -0
  44. package/dist/ui-stream-types.d.ts +104 -0
  45. package/dist/ui-stream-types.js +59 -0
  46. package/dist/ui-stream-types.js.map +1 -0
  47. package/dist/ui-tool-visibility.d.ts +4 -0
  48. package/dist/ui-tool-visibility.js +27 -0
  49. package/dist/ui-tool-visibility.js.map +1 -0
  50. package/dist/utils.d.ts +32 -0
  51. package/dist/utils.js +338 -0
  52. package/dist/utils.js.map +1 -0
  53. package/elicitation-handler.ts +348 -0
  54. package/error-signal.ts +21 -0
  55. package/errors.ts +223 -0
  56. package/failure-backoff.ts +23 -0
  57. package/glimpse-ui.ts +80 -0
  58. package/host-html-template.ts +461 -0
  59. package/index.ts +1291 -0
  60. package/init.ts +692 -0
  61. package/interfaces/agent-paths.ts +67 -0
  62. package/interfaces/host-types.ts +102 -0
  63. package/interfaces/sampling.ts +57 -0
  64. package/json-schema-validator.ts +69 -0
  65. package/lifecycle.ts +446 -0
  66. package/logger.ts +169 -0
  67. package/mcp-auth-flow.ts +1026 -0
  68. package/mcp-auth.ts +1000 -0
  69. package/mcp-bearer-store.ts +387 -0
  70. package/mcp-callback-server.ts +534 -0
  71. package/mcp-code.ts +360 -0
  72. package/mcp-keyring-helper.cjs +89 -0
  73. package/mcp-oauth-provider.ts +666 -0
  74. package/mcp-output-guard.ts +496 -0
  75. package/mcp-panel.ts +1044 -0
  76. package/mcp-probe.ts +201 -0
  77. package/mcp-references.ts +368 -0
  78. package/mcp-script-worker.mjs +130 -0
  79. package/mcp-server.mjs +2133 -0
  80. package/mcp-setup-panel.ts +667 -0
  81. package/mcp-status.ts +98 -0
  82. package/mcp-trace.ts +306 -0
  83. package/metadata-cache.ts +382 -0
  84. package/namespace-tools.ts +276 -0
  85. package/npx-resolver.ts +543 -0
  86. package/oauth-handler.ts +30 -0
  87. package/oauth.ts +48 -0
  88. package/onboarding-state.ts +76 -0
  89. package/package-mcp-loader.ts +168 -0
  90. package/package.json +225 -0
  91. package/panel-keys.ts +53 -0
  92. package/prompts.ts +353 -0
  93. package/proxy-modes.ts +1418 -0
  94. package/request-headers-command.ts +330 -0
  95. package/resource-tools.ts +17 -0
  96. package/runtime-owner.ts +91 -0
  97. package/sampling-handler.ts +284 -0
  98. package/search-ranking.ts +278 -0
  99. package/server-manager.ts +1318 -0
  100. package/session-recovery.ts +158 -0
  101. package/skills/README.md +64 -0
  102. package/skills/mcp-adapter/SKILL.md +332 -0
  103. package/skills/mcp-adapter/references/deploy-examples.md +259 -0
  104. package/skills/mcp-adapter/references/deploy.md +89 -0
  105. package/skills/mcp-adapter/references/generate.md +144 -0
  106. package/skills/mcp-adapter/references/resolver.md +105 -0
  107. package/skills/mcp-adapter/references/verify.md +157 -0
  108. package/skills/mcp-scripting/SKILL.md +38 -0
  109. package/skills/resolve-conflicts/SKILL.md +482 -0
  110. package/skills/resolve-conflicts/references/patterns.md +432 -0
  111. package/skills/resolve-conflicts/references/sample-plan.md +96 -0
  112. package/skills/resolve-conflicts/scripts/handle-deleted-modified.sh +183 -0
  113. package/skills/resolve-conflicts/scripts/validate-conflicts.sh +120 -0
  114. package/skills/upstream-merge/SKILL.md +486 -0
  115. package/skills/upstream-merge/references/pi-coupling-markers.md +129 -0
  116. package/skills/upstream-merge/references/special-cases.md +39 -0
  117. package/state.ts +60 -0
  118. package/tool-approval.ts +195 -0
  119. package/tool-metadata.ts +296 -0
  120. package/tool-registrar.ts +253 -0
  121. package/tool-result-renderer.ts +477 -0
  122. package/ts-shape.ts +149 -0
  123. package/types.ts +991 -0
  124. package/ui-app-bridge-helpers.ts +40 -0
  125. package/ui-resource-handler.ts +250 -0
  126. package/ui-server.ts +852 -0
  127. package/ui-session.ts +571 -0
  128. package/ui-stream-types.ts +89 -0
  129. package/ui-tool-visibility.ts +25 -0
  130. package/unix-socket-transport.ts +85 -0
  131. package/utils.ts +382 -0
@@ -0,0 +1,157 @@
1
+ # Phase 3 Reference: Verify Deployment
2
+
3
+ > **Called from**: `skills/mcp-adapter/SKILL.md` Phase 3
4
+ > **Path resolution**: See [resolver.md](resolver.md) — agent discovery + Host × Target matrix
5
+
6
+ Runs the full mcp-adapter integration test matrix to confirm deployment works.
7
+
8
+ ## Quick Verification
9
+
10
+ ```bash
11
+ npm run verify:deploy -- --agent universal-mcp
12
+ ```
13
+
14
+ Checks: adapter creation → context → config loading → tool registration → session lifecycle.
15
+ Pass: `✅ Universal MCP verification passed`.
16
+
17
+ ## Full Test Matrix
18
+
19
+ ### Pre-flight
20
+
21
+ ```bash
22
+ mkdir -p tests/reports
23
+ npm run test:prebuild # build visualizer dist/
24
+ ```
25
+
26
+ ### Phase 1: MockAgent Compatibility (Section 4)
27
+
28
+ ```bash
29
+ npx vitest run tests/compatibility/ --reporter=verbose
30
+ ```
31
+
32
+ **Pass**: 44/44 (40 server + 4 contract).
33
+
34
+ ### Phase 2: Token Benchmark (Section 5)
35
+
36
+ ```bash
37
+ npx tsx tests/token-benchmark/run-baseline.ts
38
+ npx tsx tests/token-benchmark/run-adapter.ts
39
+ npx tsx tests/token-benchmark/report.ts
40
+ ```
41
+
42
+ **Pass**: Proxy tool ≤ 300 tokens; 10-server savings ≥ 95%.
43
+
44
+ ### Phase 3: Conversation Cost Simulation (Section 5B)
45
+
46
+ ```bash
47
+ npx tsx tests/token-benchmark/run-conversation-sim.ts
48
+ ```
49
+
50
+ Skip if file missing (conditional guard).
51
+
52
+ ### Phase 4: Per-Path Verification (Section 6)
53
+
54
+ #### Step 0 — Capability Gate
55
+
56
+ Uses the Host × Target matrix from [resolver.md](resolver.md#host--target-matrix):
57
+
58
+ | `mcp` in host tools? | `^<server>_` prefix? | `^mcp_` SDK bridge? | Host mode |
59
+ |----------------------|---------------------|---------------------|-----------|
60
+ | yes | any | any | Full mcp proxy |
61
+ | no | yes | any | directTools |
62
+ | no | no | no | SDK_DIRECT (spawn required) |
63
+
64
+ #### Step 1 — Path verification
65
+
66
+ Read [resolver.md](resolver.md) and execute:
67
+ - Path A: `adapter.getAllTools()` includes `mcp`
68
+ - Path B: individual tools with server prefix
69
+ - Path C: SDK_DIRECT fallback
70
+
71
+ #### Step 2 — Proxy mode unit tests
72
+
73
+ ```bash
74
+ npx vitest run __tests__/proxy-modes-discovery.test.ts __tests__/proxy-modes-auto-auth.test.ts __tests__/proxy-modes-ui-messages.test.ts --reporter=verbose
75
+ ```
76
+
77
+ #### Step 3 — directTools unit + integration
78
+
79
+ ```bash
80
+ npx vitest run __tests__/direct-tools.test.ts __tests__/direct-tools-auto-auth.test.ts
81
+ npx vitest run tests/smoke/e2e-direct-tools.test.ts
82
+ ```
83
+
84
+ #### Step 4 — E2E tests
85
+
86
+ ```bash
87
+ npx vitest run tests/smoke/e2e-all-servers.test.ts --reporter=verbose
88
+ ```
89
+
90
+ **Pass**: 25/25.
91
+
92
+ #### Step 5 — Protocol Forwarder Tests
93
+
94
+ ```bash
95
+ # ProtocolSamplingForwarder unit tests (sampling forwarding via server.createMessage)
96
+ npx vitest run __tests__/protocol-sampling-forwarder.test.ts --reporter=verbose
97
+
98
+ # ProtocolElicitationForwarder unit tests (elicitation forwarding via server.elicitInput)
99
+ npx vitest run __tests__/protocol-elicitation-forwarder.test.ts --reporter=verbose
100
+
101
+ # Universal MCP server E2E tests (subprocess + real MCP Client)
102
+ npx vitest run __tests__/mcp-server-e2e.test.ts --reporter=verbose
103
+ ```
104
+
105
+ #### Step 6 — Adapter Integration Tests (Host × Target × Mode)
106
+
107
+ The three dimensions are independent:
108
+
109
+ | Dimension | Values | Default |
110
+ |-----------|--------|---------|
111
+ | Host | Current agent, Universal MCP, … | Current agent |
112
+ | Target | universal-mcp | universal-mcp |
113
+ | Mode | in-process / spawn / mock | in-process |
114
+
115
+ **Step 6a — Discover adapters**:
116
+
117
+ ```bash
118
+ echo "=== Discovered adapters ==="
119
+ grep -B1 -A5 "id:" interfaces/agent-api.ts | grep -E "(id:|displayName:|capabilities:)" | head -40
120
+ ```
121
+
122
+ **Step 6b — User selection**: AskUserQuestion for Host/Target/Mode (3D matrix).
123
+
124
+ **Step 6c — Run contract tests**:
125
+
126
+ ```bash
127
+ npx vitest run __tests__/adapter-contract.test.ts --reporter=verbose
128
+ ```
129
+
130
+ **Step 6d — Deployment wiring verification**:
131
+
132
+ ```bash
133
+ npm run verify:deploy # all harnessed adapters
134
+ npm run verify:deploy -- --agent universal-mcp # universal MCP server
135
+ ```
136
+
137
+ ### Report
138
+
139
+ `tests/reports/mcp-adapter-test-report.md` — auto-generated by matrix reporter.
140
+ Never edit by hand.
141
+
142
+ ## One-Screen Summary
143
+
144
+ ```
145
+ === mcp-adapter Test Results ===
146
+ Section 4 (MockAgent): ✅ 44/44
147
+ Section 5 (Token Bench): ✅ 94% savings
148
+ Section 5B (Conversation): ✅/⚠️/SKIP
149
+ Proxy Unit Tests: ✅ N/N
150
+ DirectTools Unit+Integration: ✅ 24/24
151
+ Section 6 (E2E): ✅ 25/25
152
+ Protocol Forwarders: ✅ N/N
153
+ Adapter Integration (Step 6): ✅ N/N
154
+ Capability Gate: Host=<current> × Target=<selected>
155
+
156
+ Verdict: 🟢 ALL PASS
157
+ ```
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: mcp-scripting
3
+ description: Write mcpScript JavaScript for discovering, inspecting, and calling MCP tools.
4
+ ---
5
+
6
+ # MCP scripting
7
+
8
+ For multi-call MCP work, write ordinary JavaScript with loops, filtering, chaining, fan-out, or other logic between calls. Run that source with `mcpScript`; it is the primary MCP orchestration surface. For a single MCP search, describe, status check, auth action, or tool call, use `mcp` instead.
9
+
10
+ Write the source naturally, then pass it as `mcpScript`'s `code` argument:
11
+
12
+ ```js
13
+ const { items } = await tools.search({ query: "search issues", server: "github" });
14
+ const candidate = items[0];
15
+ if (!candidate) return { error: "No matching tool" };
16
+
17
+ const details = await tools.describe({ path: candidate.path });
18
+ if (details.error) return details;
19
+
20
+ const result = await tools.call(details.path, { query: "is:open label:bug" });
21
+ if (!result.ok) return result;
22
+ emit({ tool: details.path, completed: true });
23
+ return result.data;
24
+ ```
25
+
26
+ ## Workflow
27
+
28
+ 1. Find candidate tools with `await tools.search({ query, server?, limit?, offset? })`.
29
+ 2. Inspect the exact returned path with `await tools.describe({ path })`.
30
+ 3. Call it with `tools.call(path, args)`.
31
+
32
+ Calls resolve to `{ ok: true, data }` or `{ ok: false, error }`; handle failed calls instead of expecting them to stop the script. `emit(value)` adds user-visible output before the final `return` value. `console` output is captured too.
33
+
34
+ `tools` is a non-enumerable proxy: `Object.keys(tools)` throws. Always use `tools.search` for discovery. When a known flat path is a valid identifier, direct calls such as `tools.github_search_issues(args)` are supported; use bracket syntax for hyphenated names: `tools["server_tool-name"](args)`. `search`, `call`, `describe`, and promise/serialization names (`then`, `catch`, `finally`, `toJSON`, `toString`, `valueOf`) are reserved on the proxy; if a flat path collides with one, call it via `tools.call("exact-path", args)`.
35
+
36
+ `tools.search` and `tools.describe` are asynchronous and must be awaited. The default script timeout is 30 seconds; the worker is terminated at the deadline, including for infinite loops. Every invocation still uses normal lazy connection, authentication, output guarding, and approval gates. Result details contain a concise `calls` trace with every search, describe, and call operation; each entry includes its query or path, outcome, and duration.
37
+
38
+ Use plain JavaScript loops and Promise utilities for composition. Fluent helpers such as `tools.find(...).one()`, `tools.parallel(...)`, and `tools.retry(...)` are not provided.
@@ -0,0 +1,482 @@
1
+ ---
2
+ name: resolve-conflicts
3
+ description: Use this skill immediately when the user mentions merge conflicts that need to be resolved. Do not attempt to resolve conflicts directly - invoke this skill first. This skill specializes in providing a structured framework for merging imports, tests, lock files (regeneration), configuration files, and handling deleted-but-modified files with backup and analysis.
4
+ ---
5
+
6
+ # Git Conflict Resolution
7
+
8
+ Resolve Git merge conflicts by intelligently combining changes from both branches while preserving the intent of both changes. This skill follows a plan-first approach: assess conflicts, create a detailed resolution plan, get approval, then execute.
9
+
10
+ ## Core Principles
11
+
12
+ 1. **Plan Before Executing**: Always create a structured resolution plan and get user approval before making changes
13
+ 2. **Prefer Both Changes**: Default to keeping both changes unless they directly contradict
14
+ 3. **Merge, Don't Choose**: Especially for imports, tests, and configuration
15
+ 4. **Regenerate Generated Files**: Never manually merge generated files - always regenerate them from their sources
16
+ 5. **Backup Before Resolving**: For deleted-modified files, create backups first
17
+ 6. **Validate with Tests**: Always run tests after resolution
18
+ 7. **Explain All Resolutions**: For each conflict resolved, provide a one-line explanation of the resolution strategy
19
+ 8. **Ask When Unclear**: When the correct resolution isn't clear from the diff, present options to the user and ask for their choice
20
+
21
+ ## Workflow
22
+
23
+ ### Step 1: Assess the Conflict Situation
24
+
25
+ Run initial checks to understand the conflict scope:
26
+
27
+ ```bash
28
+ git status
29
+ ```
30
+
31
+ Identify and categorize all conflicted files:
32
+
33
+ - Regular file conflicts (both modified)
34
+ - Deleted-modified conflicts (one deleted, one modified)
35
+ - Generated file conflicts (lock files, build artifacts, generated code)
36
+ - Test file conflicts
37
+ - Import/configuration conflicts
38
+ - Binary file conflicts
39
+
40
+ For each conflicted file, gather information:
41
+
42
+ - File type and purpose
43
+ - Nature of the conflict (content, deletion, type change)
44
+ - Scope of changes (lines changed, sections affected)
45
+ - Whether the file is generated or hand-written
46
+
47
+ ### Step 2: Create Merge Resolution Plan
48
+
49
+ Based on the assessment, create a structured plan before resolving any conflicts. Present the plan in the following markdown format:
50
+
51
+ ```markdown
52
+ ## Merge Resolution Plan
53
+
54
+ ### Conflict Summary
55
+
56
+ - **Total conflicted files**: [N]
57
+ - **Deleted-modified conflicts**: [N]
58
+ - **Generated files**: [N]
59
+ - **Regular conflicts**: [N]
60
+
61
+ ### Resolution Strategy by File
62
+
63
+ #### 1. [File Path]
64
+
65
+ **Conflict Type**: [deleted-modified / generated / imports / tests / code logic / config / struct / binary]
66
+ **Strategy**: [Brief description of resolution approach]
67
+ **Rationale**: [Why this strategy is appropriate]
68
+ **Risk**: [Low/Medium/High] - [Brief risk description]
69
+ **Action Items**:
70
+
71
+ - [ ] [Specific action 1]
72
+ - [ ] [Specific action 2]
73
+
74
+ #### 2. [File Path]
75
+
76
+ ...
77
+
78
+ ### Execution Order
79
+
80
+ 1. **Phase 1: Deleted-Modified Files** - Handle deletions and backups first
81
+ 2. **Phase 2: Generated Files** - Regenerate from source
82
+ 3. **Phase 3: Low-Risk Merges** - Imports, tests, documentation
83
+ 4. **Phase 4: High-Risk Merges** - Code logic, configuration, structs
84
+ 5. **Phase 5: Validation** - Compile, test, verify
85
+
86
+ ### Questions/Decisions Needed
87
+
88
+ - [ ] **[File/Decision]**: [Question for user] (Options: 1, 2, 3)
89
+
90
+ ### Validation Steps
91
+
92
+ - [ ] Run conflict validation script
93
+ - [ ] Compile project
94
+ - [ ] Run test suite
95
+ - [ ] Manual verification of high-risk changes
96
+ ```
97
+
98
+ **Present this plan to the user** and wait for their approval before proceeding with resolution. If there are any unclear conflicts where you need user input, list them in the "Questions/Decisions Needed" section.
99
+
100
+ **For a complete example plan**, see `references/sample-plan.md`.
101
+
102
+ ### Step 3: Handle Deleted-Modified Files
103
+
104
+ **Execute this phase only after the plan is approved.**
105
+
106
+ If there are deleted-but-modified files (status: DU, UD, DD, UA, AU):
107
+
108
+ ```bash
109
+ .forge/skills/resolve-conflicts/scripts/handle-deleted-modified.sh
110
+ ```
111
+
112
+ This script will:
113
+
114
+ - Create timestamped backups of modified content
115
+ - Analyze potential relocation targets
116
+ - Generate analysis reports for each file
117
+ - Automatically resolve the deletion status
118
+
119
+ Review the backup directory and analysis files to understand where changes should be applied.
120
+
121
+ ### Step 4: Execute Resolution Plan
122
+
123
+ **Follow the execution order defined in your plan.** For each conflicted file, apply the appropriate resolution pattern according to your plan. **For every conflict you resolve, provide a one-line explanation** of how you're resolving it.
124
+
125
+ As you complete each action item in your plan, mark it as done and report progress to the user.
126
+
127
+ #### When Resolution is Unclear
128
+
129
+ When you cannot determine the correct resolution from the diff alone (these should already be listed in your plan's "Questions/Decisions Needed" section):
130
+
131
+ 1. **Present the conflict** to the user with the conflicting code from both sides
132
+ 2. **Provide numbered options** for resolution (Option 1, Option 2, etc.)
133
+ 3. **Explain each option** clearly with what it would do
134
+ 4. **Ask the user to choose** an option number or provide additional information
135
+ 5. **Remember their choice** and apply similar reasoning to subsequent related conflicts
136
+
137
+ **Example interaction:**
138
+
139
+ ```
140
+ I found a conflict in src/main.rs where both branches modify the `calculate_price` function:
141
+
142
+ <<<<<<< HEAD (Current Branch)
143
+ fn calculate_price(item: &Item) -> f64 {
144
+ item.base_price * (1.0 + item.tax_rate)
145
+ }
146
+ =======
147
+ fn calculate_price(item: &Item) -> f64 {
148
+ item.base_price + item.tax_amount
149
+ }
150
+ >>>>>>> feature-branch (Incoming Branch)
151
+
152
+ I'm not sure which calculation is correct. Please select an option:
153
+
154
+ **Option 1**: Keep current branch (multiplies base_price by tax_rate)
155
+ **Option 2**: Keep incoming branch (adds tax_amount to base_price)
156
+ **Option 3**: Keep both approaches with a new parameter
157
+ **Option 4**: Provide more context to help me decide
158
+
159
+ Please respond with "Option 1", "Option 2", "Option 3", or "Option 4", or provide additional information.
160
+ ```
161
+
162
+ Once the user responds, apply their decision and similar logic to related conflicts.
163
+
164
+ #### Resolution Patterns
165
+
166
+ For each conflicted file, apply the appropriate resolution pattern:
167
+
168
+ #### Imports/Dependencies
169
+
170
+ **Goal**: Merge all unique imports from both branches.
171
+
172
+ **One-line explanation**: "Merging imports by combining unique imports from both branches, removing duplicates, and grouping by module."
173
+
174
+ Read `references/patterns.md` section "Import Conflicts" for detailed examples.
175
+
176
+ **Quick approach:**
177
+
178
+ 1. Extract all imports from both sides
179
+ 2. Remove duplicates
180
+ 3. Group by module/package
181
+ 4. Follow language-specific style (alphabetize, group std/external/internal)
182
+
183
+ #### Tests
184
+
185
+ **Goal**: Include all test cases and test data from both branches.
186
+
187
+ **One-line explanation**: "Merging tests by including all test cases from both branches, combining fixtures, and renaming if necessary to avoid conflicts."
188
+
189
+ Read `references/patterns.md` section "Test Conflicts" for detailed examples.
190
+
191
+ **Quick approach:**
192
+
193
+ 1. Keep all test functions unless they test the exact same thing
194
+ 2. Merge test fixtures and setup functions
195
+ 3. Combine assertions from both sides
196
+ 4. If test names conflict but test different behaviors, rename to clarify
197
+
198
+ #### Generated Files
199
+
200
+ **Goal**: Regenerate any generated files to include changes from both branches.
201
+
202
+ **One-line explanation**: "Resolving generated file by regenerating it from source files to incorporate changes from both branches."
203
+
204
+ **Recognition**: A file is generated if it:
205
+
206
+ - Is produced by a build tool, compiler, or code generator
207
+ - Has a source file or configuration that defines it
208
+ - Contains headers/comments indicating it's auto-generated
209
+ - Is listed in `.gitattributes` as generated
210
+ - Common examples: lock files, protobuf outputs, GraphQL schema files, compiled assets, auto-generated docs
211
+
212
+ **Approach:**
213
+
214
+ 1. **Identify the generation source**: Determine what command or tool generates the file
215
+ 2. **Choose either version** temporarily (doesn't matter which):
216
+
217
+ ```bash
218
+ git checkout --ours <generated-file> # or --theirs
219
+ ```
220
+
221
+ 3. **Regenerate from source**: Run the appropriate generation command:
222
+
223
+ ```bash
224
+ # Package manager lock files
225
+ cargo update # for Cargo.lock
226
+ npm install # for package-lock.json
227
+ yarn install # for yarn.lock
228
+ bundle install # for Gemfile.lock
229
+ poetry lock --no-update # for poetry.lock
230
+
231
+ # Code generation
232
+ protoc ... # for protobuf files
233
+ graphql-codegen # for GraphQL generated code
234
+ make generate # for Makefile-based generation
235
+ npm run generate # for npm script-based generation
236
+
237
+ # Build artifacts
238
+ npm run build # for compiled/bundled assets
239
+ cargo build # for Rust build artifacts
240
+ ```
241
+
242
+ 4. **Stage the regenerated file**:
243
+ ```bash
244
+ git add <generated-file>
245
+ ```
246
+
247
+ **When unsure if a file is generated**: Check for auto-generation markers in the file header, or ask the user if you should regenerate or manually merge the file.
248
+
249
+ #### Configuration Files
250
+
251
+ **Goal**: Merge configuration values from both branches.
252
+
253
+ **One-line explanation**: "Merging configuration by including all keys from both branches and choosing appropriate values for conflicts."
254
+
255
+ Read `references/patterns.md` section "Configuration File Conflicts" for detailed examples.
256
+
257
+ **Quick approach:**
258
+
259
+ 1. Include all keys from both sides
260
+ 2. For conflicting values, choose based on:
261
+ - Newer/more recent value
262
+ - Safer/more conservative value
263
+ - Production requirements
264
+ 3. Document choice in commit message
265
+
266
+ **When unclear**: Ask the user which configuration value to prefer (current vs incoming)
267
+
268
+ #### Code Logic
269
+
270
+ **Goal**: Understand intent of both changes and combine if possible.
271
+
272
+ **One-line explanation**: "Resolving code logic by analyzing intent: merging if changes are orthogonal, or choosing one approach if they conflict."
273
+
274
+ Read `references/patterns.md` section "Code Logic Conflicts" for detailed examples.
275
+
276
+ **Quick approach:**
277
+
278
+ 1. Analyze what each branch is trying to achieve
279
+ 2. If changes are orthogonal (different concerns), merge both
280
+ 3. If changes conflict (same concern, different approach):
281
+ - Review commit messages/PRs for context
282
+ - Choose the approach that matches requirements
283
+ - Test both approaches if unclear
284
+ - Document the decision
285
+
286
+ **When unclear**: Present both approaches as options to the user with context about what each does
287
+
288
+ #### Struct/Type Definitions
289
+
290
+ **Goal**: Include all fields from both branches.
291
+
292
+ **One-line explanation**: "Merging struct by including all fields from both branches and choosing appropriate types for any conflicting field definitions."
293
+
294
+ **Quick approach:**
295
+
296
+ 1. Merge all fields
297
+ 2. If field types conflict, analyze which is more appropriate
298
+ 3. Fix all compilation errors from updated struct
299
+ 4. Update tests to use new fields
300
+
301
+ **When unclear**: Ask the user which type definition is correct if field types conflict
302
+
303
+ ### Step 5: Validate Resolution
304
+
305
+ After completing all resolution phases in your plan, validate that all conflicts are resolved:
306
+
307
+ ```bash
308
+ .forge/skills/resolve-conflicts/scripts/validate-conflicts.sh
309
+ ```
310
+
311
+ This script checks for:
312
+
313
+ - Remaining conflict markers (<<<<<<<, =======, >>>>>>>)
314
+ - Unmerged paths in git status
315
+ - Deleted-modified conflicts
316
+ - Merge state files
317
+
318
+ ### Step 6: Compile and Test
319
+
320
+ Build and test to ensure the resolution is correct (as defined in your plan's validation steps):
321
+
322
+ ```bash
323
+ # For Rust projects
324
+ cargo test
325
+
326
+ # For other projects, use appropriate test command
327
+ # npm test
328
+ # pytest
329
+ # etc.
330
+ ```
331
+
332
+ If tests fail:
333
+
334
+ 1. Review the failure - is it from merged code or conflict resolution?
335
+ 2. Check if both branches' tests pass individually
336
+ 3. Fix integration issues between the merged changes
337
+ 4. Re-run tests until all pass
338
+
339
+ ### Step 7: Finalize
340
+
341
+ Once all conflicts are resolved and tests pass, review your completed plan and commit:
342
+
343
+ ```bash
344
+ # Review the changes
345
+ git diff --cached
346
+
347
+ # Commit with descriptive message that references the plan
348
+ git commit -m "Resolve merge conflicts: [describe key decisions]
349
+
350
+ Executed merge resolution plan:
351
+ - [Phase 1 summary]
352
+ - [Phase 2 summary]
353
+ - [Phase 3+ summaries]
354
+
355
+ Key decisions:
356
+ - Merged imports from both branches
357
+ - Combined test cases
358
+ - Regenerated lock files
359
+ - [other significant decisions from plan]
360
+
361
+ Co-Authored-By: ForgeCode <noreply@forgecode.dev>"
362
+ ```
363
+
364
+ ## Decision Tracking
365
+
366
+ When you ask the user to choose between options, track their decision and apply similar reasoning to subsequent conflicts:
367
+
368
+ **Example scenario:**
369
+
370
+ 1. First conflict: User chooses Option 1 (prefer current branch's validation logic)
371
+ 2. Second similar conflict: Apply the same reasoning (prefer current branch's validation approach)
372
+ 3. Mention: "Resolving by keeping current branch's approach (consistent with your earlier choice)"
373
+
374
+ **Key principles:**
375
+
376
+ - Remember user preferences within the same conflict resolution session
377
+ - Apply consistent patterns when conflicts are similar
378
+ - Mention the consistency: "Following the same pattern as before..."
379
+ - Ask again if a new conflict is sufficiently different from previous ones
380
+
381
+ ## Common Patterns Reference
382
+
383
+ For detailed resolution patterns, read:
384
+
385
+ - `references/patterns.md` - Comprehensive examples for all conflict types
386
+
387
+ **Quick pattern lookup:**
388
+
389
+ - **Imports**: Combine all unique imports, group by module
390
+ - **Tests**: Keep all tests unless identical, merge fixtures
391
+ - **Generated files**: Choose either version, regenerate from source
392
+ - **Config**: Merge all keys, choose newer/safer values for conflicts
393
+ - **Code**: Analyze intent, merge if orthogonal, choose one if conflicting
394
+ - **Structs**: Include all fields from both branches
395
+ - **Docs**: Combine all documentation sections
396
+
397
+ ## Special Scenarios
398
+
399
+ ### Binary Files in Conflict
400
+
401
+ Binary files cannot be merged. Choose one version:
402
+
403
+ ```bash
404
+ git checkout --ours path/to/binary # keep our version
405
+ # or
406
+ git checkout --theirs path/to/binary # keep their version
407
+ ```
408
+
409
+ ### Mass Rename/Refactoring Conflicts
410
+
411
+ If one branch renamed/refactored many files while another modified them:
412
+
413
+ 1. Accept the rename/refactoring (structural change)
414
+ 2. Apply the modifications to the new structure
415
+ 3. Use backups from `handle-deleted-modified.sh` to guide the application
416
+
417
+ ### Submodule Conflicts
418
+
419
+ ```bash
420
+ # Check submodule status
421
+ git submodule status
422
+
423
+ # Update to the correct commit
424
+ cd path/to/submodule
425
+ git checkout <desired-commit>
426
+ cd ../..
427
+ git add path/to/submodule
428
+ ```
429
+
430
+ ## Troubleshooting
431
+
432
+ ### "Both Added" Conflicts (AA)
433
+
434
+ Both branches added a new file with the same name but different content:
435
+
436
+ 1. Review both versions
437
+ 2. If they serve the same purpose, merge their content
438
+ 3. If they serve different purposes, rename one
439
+
440
+ ### Whitespace-Only Conflicts
441
+
442
+ If conflicts are only whitespace differences:
443
+
444
+ ```bash
445
+ git merge -Xignore-space-change <branch>
446
+ ```
447
+
448
+ ### Persistent Conflict Markers
449
+
450
+ If validation shows conflict markers but you think you resolved them:
451
+
452
+ 1. Search for the exact marker strings: `git grep -n "<<<<<<< HEAD"`
453
+ 2. Some markers might be in strings or comments - resolve those too
454
+ 3. Check for hidden characters or encoding issues
455
+
456
+ ### Tests Fail After Resolution
457
+
458
+ 1. Test each branch individually to confirm they pass
459
+ 2. The failure is likely from interaction between the merged changes
460
+ 3. Debug the interaction issue, not the individual changes
461
+ 4. Update code to make both changes work together
462
+
463
+ ## Quick Reference Card
464
+
465
+ | Conflict Type | Strategy | One-line Explanation Template |
466
+ | ---------------- | --------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
467
+ | Imports | Merge all, deduplicate, group by module | "Merging imports by combining unique imports from both branches and grouping by module" |
468
+ | Tests | Keep all, merge fixtures | "Including all test cases from both branches and combining test fixtures" |
469
+ | Generated files | Regenerate from source | "Regenerating [file] from source to include changes from both branches" |
470
+ | Config | Merge keys, choose newer values | "Merging all config keys and choosing [current/incoming] value for [key]" |
471
+ | Code logic | Analyze intent, merge if orthogonal | "Merging both changes as they address different concerns" OR "Choosing [current/incoming] approach for [reason]" |
472
+ | Structs | Include all fields | "Including all fields from both branches in struct definition" |
473
+ | Docs | Combine all sections | "Combining documentation from both branches" |
474
+ | Deleted-modified | Backup, analyze, apply to new location | "Applying modifications to new location after file was moved/renamed" |
475
+ | Binary files | Choose one version | "Keeping [current/incoming] version of binary file" |
476
+
477
+ **Remember:**
478
+
479
+ - Always provide a one-line explanation for each conflict resolution
480
+ - When unclear, present numbered options to the user
481
+ - Track user decisions and apply consistently to similar conflicts
482
+ - The goal is to preserve the intent and functionality of both branches while creating a cohesive merged result