@etavioxy/wocingflow-mcp-server 0.0.5 → 0.0.6-fix.2

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 (21) hide show
  1. package/bin/wocingflow-mcp-server.js +259 -208
  2. package/package.json +19 -19
  3. package/vendor/mcp_server.exe +0 -0
  4. package/vendor/service-data/workflows/baseline-workflow/01-start-feature.sh +18 -18
  5. package/vendor/service-data/workflows/baseline-workflow/02-select-minimal-patch.sh +9 -9
  6. package/vendor/service-data/workflows/baseline-workflow/03-patch-sink.sh +26 -26
  7. package/vendor/service-data/workflows/baseline-workflow/04-patch-broadcast.sh +24 -24
  8. package/vendor/service-data/workflows/baseline-workflow/05-squash-feature.sh +18 -18
  9. package/vendor/service-data/workflows/baseline-workflow/06-feature-retract.sh +28 -28
  10. package/vendor/service-data/workflows/baseline-workflow/07-rebase-origin.sh +27 -27
  11. package/vendor/service-data/workflows/baseline-workflow/08-push-origin.sh +5 -5
  12. package/vendor/service-data/workflows/baseline-workflow/09-generate-patches.sh +11 -11
  13. package/vendor/service-data/workflows/baseline-workflow/profile.json +215 -215
  14. package/vendor/service-data/workflows/commit-merge-split-lab/01-show-recent-commits.sh +3 -3
  15. package/vendor/service-data/workflows/commit-merge-split-lab/02-merge-commits-in-range.sh +5 -5
  16. package/vendor/service-data/workflows/commit-merge-split-lab/03-split-commit-to-working-tree.sh +6 -6
  17. package/vendor/service-data/workflows/commit-merge-split-lab/04-recommit-selected-path.sh +6 -6
  18. package/vendor/service-data/workflows/commit-merge-split-lab/05-continue-rewrite.sh +3 -3
  19. package/vendor/service-data/workflows/patch-export-for-review/01-ensure-patch-out-dir.sh +4 -4
  20. package/vendor/service-data/workflows/patch-export-for-review/02-format-patch-by-folder.sh +6 -6
  21. package/vendor/service-data/workflows/patch-export-for-review/03-list-generated-patches.sh +7 -7
@@ -1,208 +1,259 @@
1
- #!/usr/bin/env node
2
- const fs = require("node:fs");
3
- const path = require("node:path");
4
- const net = require("node:net");
5
- const { spawn } = require("node:child_process");
6
- const packageMeta = require("../package.json");
7
-
8
- function sleep(ms) {
9
- return new Promise((resolve) => setTimeout(resolve, ms));
10
- }
11
-
12
- function isWindows() {
13
- return process.platform === "win32";
14
- }
15
-
16
- function fileExists(filePath) {
17
- try {
18
- return fs.existsSync(filePath);
19
- } catch {
20
- return false;
21
- }
22
- }
23
-
24
- function candidateRoots() {
25
- const cwd = process.cwd();
26
- return [cwd, path.resolve(cwd, ".."), path.resolve(cwd, "..", "..")];
27
- }
28
-
29
- function resolveServiceDataDir() {
30
- const bundledData = path.join(__dirname, "..", "vendor", "service-data");
31
- if (fileExists(bundledData)) {
32
- return bundledData;
33
- }
34
-
35
- if (process.env.WF_SERVICE_DATA_DIR && fileExists(process.env.WF_SERVICE_DATA_DIR)) {
36
- return process.env.WF_SERVICE_DATA_DIR;
37
- }
38
- for (const root of candidateRoots()) {
39
- const candidate = path.join(root, "service", "data");
40
- if (fileExists(candidate)) {
41
- return candidate;
42
- }
43
- }
44
- return "";
45
- }
46
-
47
- function resolveServerLaunch() {
48
- if (process.env.WF_MCP_SERVER_BIN && fileExists(process.env.WF_MCP_SERVER_BIN)) {
49
- return { command: process.env.WF_MCP_SERVER_BIN, args: [] };
50
- }
51
-
52
- const exeName = isWindows() ? "mcp_server.exe" : "mcp_server";
53
- const bundledPath = path.join(__dirname, "..", "vendor", exeName);
54
- if (fileExists(bundledPath)) {
55
- return { command: bundledPath, args: [] };
56
- }
57
-
58
- for (const root of candidateRoots()) {
59
- const debugPath = path.join(root, "service", "target", "debug", exeName);
60
- const releasePath = path.join(root, "service", "target", "release", exeName);
61
- if (fileExists(debugPath)) return { command: debugPath, args: [] };
62
- if (fileExists(releasePath)) return { command: releasePath, args: [] };
63
- }
64
-
65
- for (const root of candidateRoots()) {
66
- const manifestPath = path.join(root, "service", "Cargo.toml");
67
- if (fileExists(manifestPath)) {
68
- return {
69
- command: "cargo",
70
- args: ["run", "--manifest-path", manifestPath, "--bin", "mcp_server", "--"],
71
- };
72
- }
73
- }
74
-
75
- throw new Error(
76
- "Cannot locate wocingflow mcp_server. Build service/bin/mcp_server or set WF_MCP_SERVER_BIN."
77
- );
78
- }
79
-
80
- async function resolvePort() {
81
- if (process.env.WF_MCP_HTTP_PORT) {
82
- return String(process.env.WF_MCP_HTTP_PORT);
83
- }
84
- return String(
85
- await new Promise((resolve, reject) => {
86
- const server = net.createServer();
87
- server.listen(0, "127.0.0.1", () => {
88
- const address = server.address();
89
- if (!address || typeof address === "string") {
90
- server.close();
91
- reject(new Error("Failed to allocate free TCP port."));
92
- return;
93
- }
94
- const freePort = address.port;
95
- server.close(() => resolve(freePort));
96
- });
97
- server.on("error", reject);
98
- })
99
- );
100
- }
101
-
102
- async function waitHealth(endpoint, timeoutMs) {
103
- const started = Date.now();
104
- while (Date.now() - started < timeoutMs) {
105
- try {
106
- const response = await fetch(`${endpoint}/health`);
107
- if (response.ok) return;
108
- } catch {
109
- // keep waiting
110
- }
111
- await sleep(300);
112
- }
113
- throw new Error(`mcp_server health check timeout: ${endpoint}/health`);
114
- }
115
-
116
- function spawnBackend(command, args, env) {
117
- const child = spawn(command, args, {
118
- stdio: ["ignore", "pipe", "pipe"],
119
- env,
120
- shell: false,
121
- windowsHide: true,
122
- });
123
- child.stdout.on("data", (chunk) => {
124
- process.stderr.write(String(chunk));
125
- });
126
- child.stderr.on("data", (chunk) => {
127
- process.stderr.write(String(chunk));
128
- });
129
- return child;
130
- }
131
-
132
- function spawnBridge(env, endpoint) {
133
- let command;
134
- let args;
135
- if (isWindows()) {
136
- command = "cmd.exe";
137
- args = ["/d", "/s", "/c", `npx -y mcp-remote@latest ${endpoint}`];
138
- } else {
139
- command = "npx";
140
- args = ["-y", "mcp-remote@latest", endpoint];
141
- }
142
-
143
- const child = spawn(command, args, {
144
- stdio: ["pipe", "pipe", "pipe"],
145
- env,
146
- shell: false,
147
- windowsHide: true,
148
- });
149
-
150
- process.stdin.pipe(child.stdin);
151
- child.stdout.pipe(process.stdout);
152
- child.stderr.pipe(process.stderr);
153
- return child;
154
- }
155
-
156
- async function main() {
157
- const host = process.env.WF_MCP_HTTP_HOST || "127.0.0.1";
158
- const port = await resolvePort();
159
- const endpoint = `http://${host}:${port}`;
160
- const serviceDataDir = resolveServiceDataDir();
161
- const launch = resolveServerLaunch();
162
-
163
- const backendEnv = { ...process.env };
164
- if (serviceDataDir) {
165
- backendEnv.WF_SERVICE_DATA_DIR = serviceDataDir;
166
- }
167
- backendEnv.WF_MCP_NPM_PACKAGE = packageMeta.name || "@etavioxy/wocingflow-mcp-server";
168
- backendEnv.WF_MCP_NPM_VERSION = packageMeta.version || "";
169
-
170
- const backend = spawnBackend(
171
- launch.command,
172
- [...launch.args, "--host", host, "--port", String(port)],
173
- backendEnv
174
- );
175
-
176
- let shuttingDown = false;
177
- const shutdown = () => {
178
- if (shuttingDown) return;
179
- shuttingDown = true;
180
- if (!backend.killed) {
181
- backend.kill();
182
- }
183
- };
184
-
185
- process.on("SIGINT", shutdown);
186
- process.on("SIGTERM", shutdown);
187
- process.on("exit", shutdown);
188
-
189
- backend.on("exit", (code) => {
190
- if (!shuttingDown && code !== 0) {
191
- console.error(`[wocingflow-mcp] backend exited early with code ${code}`);
192
- process.exit(code || 1);
193
- }
194
- });
195
-
196
- await waitHealth(endpoint, 20000);
197
-
198
- const bridge = spawnBridge(process.env, endpoint);
199
- bridge.on("exit", (code) => {
200
- shutdown();
201
- process.exit(code || 0);
202
- });
203
- }
204
-
205
- main().catch((error) => {
206
- console.error(`[wocingflow-mcp] ${error.message}`);
207
- process.exit(1);
208
- });
1
+ #!/usr/bin/env node
2
+ const fs = require("node:fs");
3
+ const path = require("node:path");
4
+ const net = require("node:net");
5
+ const { spawn } = require("node:child_process");
6
+ const packageMeta = require("../package.json");
7
+
8
+ function sleep(ms) {
9
+ return new Promise((resolve) => setTimeout(resolve, ms));
10
+ }
11
+
12
+ function isWindows() {
13
+ return process.platform === "win32";
14
+ }
15
+
16
+ function fileExists(filePath) {
17
+ try {
18
+ return fs.existsSync(filePath);
19
+ } catch {
20
+ return false;
21
+ }
22
+ }
23
+
24
+ function candidateRoots() {
25
+ const cwd = process.cwd();
26
+ return [cwd, path.resolve(cwd, ".."), path.resolve(cwd, "..", "..")];
27
+ }
28
+
29
+ function resolveServiceDataDir() {
30
+ const bundledData = path.join(__dirname, "..", "vendor", "service-data");
31
+ if (fileExists(bundledData)) {
32
+ return bundledData;
33
+ }
34
+
35
+ if (process.env.WF_SERVICE_DATA_DIR && fileExists(process.env.WF_SERVICE_DATA_DIR)) {
36
+ return process.env.WF_SERVICE_DATA_DIR;
37
+ }
38
+ for (const root of candidateRoots()) {
39
+ const candidate = path.join(root, "service", "data");
40
+ if (fileExists(candidate)) {
41
+ return candidate;
42
+ }
43
+ }
44
+ return "";
45
+ }
46
+
47
+ function resolveServerLaunch() {
48
+ if (process.env.WF_MCP_SERVER_BIN && fileExists(process.env.WF_MCP_SERVER_BIN)) {
49
+ return { command: process.env.WF_MCP_SERVER_BIN, args: [] };
50
+ }
51
+
52
+ const exeName = isWindows() ? "mcp_server.exe" : "mcp_server";
53
+ const bundledPath = path.join(__dirname, "..", "vendor", exeName);
54
+ if (fileExists(bundledPath)) {
55
+ return { command: bundledPath, args: [] };
56
+ }
57
+
58
+ for (const root of candidateRoots()) {
59
+ const debugPath = path.join(root, "service", "target", "debug", exeName);
60
+ const releasePath = path.join(root, "service", "target", "release", exeName);
61
+ if (fileExists(debugPath)) return { command: debugPath, args: [] };
62
+ if (fileExists(releasePath)) return { command: releasePath, args: [] };
63
+ }
64
+
65
+ for (const root of candidateRoots()) {
66
+ const manifestPath = path.join(root, "service", "Cargo.toml");
67
+ if (fileExists(manifestPath)) {
68
+ return {
69
+ command: "cargo",
70
+ args: ["run", "--manifest-path", manifestPath, "--bin", "mcp_server", "--"],
71
+ };
72
+ }
73
+ }
74
+
75
+ throw new Error(
76
+ "Cannot locate wocingflow mcp_server. Build service/bin/mcp_server or set WF_MCP_SERVER_BIN."
77
+ );
78
+ }
79
+
80
+ async function resolvePort() {
81
+ if (process.env.WF_MCP_HTTP_PORT) {
82
+ return String(process.env.WF_MCP_HTTP_PORT);
83
+ }
84
+ return String(
85
+ await new Promise((resolve, reject) => {
86
+ const server = net.createServer();
87
+ server.listen(0, "127.0.0.1", () => {
88
+ const address = server.address();
89
+ if (!address || typeof address === "string") {
90
+ server.close();
91
+ reject(new Error("Failed to allocate free TCP port."));
92
+ return;
93
+ }
94
+ const freePort = address.port;
95
+ server.close(() => resolve(freePort));
96
+ });
97
+ server.on("error", reject);
98
+ })
99
+ );
100
+ }
101
+
102
+ async function waitHealth(endpoint, timeoutMs) {
103
+ const started = Date.now();
104
+ while (Date.now() - started < timeoutMs) {
105
+ try {
106
+ const response = await fetch(`${endpoint}/health`);
107
+ if (response.ok) return;
108
+ } catch {
109
+ // keep waiting
110
+ }
111
+ await sleep(300);
112
+ }
113
+ throw new Error(`mcp_server health check timeout: ${endpoint}/health`);
114
+ }
115
+
116
+ function spawnBackend(command, args, env) {
117
+ console.error(`[wocingflow-mcp] backend launch command=${command} args=${JSON.stringify(args)}`);
118
+ const child = spawn(command, args, {
119
+ stdio: ["ignore", "pipe", "pipe"],
120
+ env,
121
+ shell: false,
122
+ windowsHide: true,
123
+ });
124
+ child.on("error", (error) => {
125
+ console.error(`[wocingflow-mcp] backend spawn error: ${error.message}`);
126
+ });
127
+ child.stdout.on("data", (chunk) => {
128
+ process.stderr.write(String(chunk));
129
+ });
130
+ child.stderr.on("data", (chunk) => {
131
+ process.stderr.write(String(chunk));
132
+ });
133
+ return child;
134
+ }
135
+
136
+ function spawnBridge(env, endpoint) {
137
+ const protocolVersion = (process.env.WF_MCP_PROTOCOL_VERSION || "").trim();
138
+ const transportStrategy = process.env.WF_MCP_TRANSPORT_STRATEGY || "http-first";
139
+ const authTimeoutSeconds = process.env.WF_MCP_AUTH_TIMEOUT_SECONDS || "120";
140
+ const remoteArgs = [
141
+ "-y",
142
+ "mcp-remote@latest",
143
+ endpoint,
144
+ "--allow-http",
145
+ "--transport",
146
+ transportStrategy,
147
+ "--auth-timeout",
148
+ authTimeoutSeconds,
149
+ ];
150
+ if (protocolVersion) {
151
+ remoteArgs.push("--header", `MCP-Protocol-Version:${protocolVersion}`);
152
+ }
153
+ const command = isWindows() ? (process.env.ComSpec || "cmd.exe") : "npx";
154
+ const args = isWindows()
155
+ ? ["/d", "/s", "/c", `npx ${remoteArgs.join(" ")}`]
156
+ : remoteArgs;
157
+ console.error(`[wocingflow-mcp] bridge launch command=${command} args=${JSON.stringify(args)}`);
158
+
159
+ const child = spawn(command, args, {
160
+ stdio: ["pipe", "pipe", "pipe"],
161
+ env,
162
+ shell: false,
163
+ windowsHide: true,
164
+ });
165
+ child.on("error", (error) => {
166
+ console.error(`[wocingflow-mcp] bridge spawn error: ${error.message}`);
167
+ });
168
+
169
+ let bridgeReady = false;
170
+ const pendingInputChunks = [];
171
+ const forwardOrBuffer = (chunk) => {
172
+ if (bridgeReady) {
173
+ child.stdin.write(chunk);
174
+ return;
175
+ }
176
+ pendingInputChunks.push(Buffer.from(chunk));
177
+ };
178
+ const flushPending = () => {
179
+ if (!bridgeReady) return;
180
+ while (pendingInputChunks.length > 0) {
181
+ const next = pendingInputChunks.shift();
182
+ child.stdin.write(next);
183
+ }
184
+ };
185
+
186
+ process.stdin.on("data", forwardOrBuffer);
187
+ process.stdin.on("end", () => {
188
+ child.stdin.end();
189
+ });
190
+
191
+ child.stderr.on("data", (chunk) => {
192
+ const text = String(chunk);
193
+ process.stderr.write(text);
194
+ if (!bridgeReady && (text.includes("Local STDIO server running") || text.includes("Proxy established successfully"))) {
195
+ bridgeReady = true;
196
+ flushPending();
197
+ }
198
+ });
199
+
200
+ child.stdout.pipe(process.stdout);
201
+ return child;
202
+ }
203
+
204
+ async function main() {
205
+ const host = process.env.WF_MCP_HTTP_HOST || "127.0.0.1";
206
+ const port = await resolvePort();
207
+ const endpoint = `http://${host}:${port}`;
208
+ console.error(
209
+ `[wocingflow-mcp] launcher version=${packageMeta.version || "unknown"} package=${packageMeta.name || "unknown"}`
210
+ );
211
+ const serviceDataDir = resolveServiceDataDir();
212
+ const launch = resolveServerLaunch();
213
+
214
+ const backendEnv = { ...process.env };
215
+ if (serviceDataDir) {
216
+ backendEnv.WF_SERVICE_DATA_DIR = serviceDataDir;
217
+ }
218
+ backendEnv.WF_MCP_NPM_PACKAGE = packageMeta.name || "@etavioxy/wocingflow-mcp-server";
219
+ backendEnv.WF_MCP_NPM_VERSION = packageMeta.version || "";
220
+
221
+ const backend = spawnBackend(
222
+ launch.command,
223
+ [...launch.args, "--host", host, "--port", String(port)],
224
+ backendEnv
225
+ );
226
+
227
+ let shuttingDown = false;
228
+ const shutdown = () => {
229
+ if (shuttingDown) return;
230
+ shuttingDown = true;
231
+ if (!backend.killed) {
232
+ backend.kill();
233
+ }
234
+ };
235
+
236
+ process.on("SIGINT", shutdown);
237
+ process.on("SIGTERM", shutdown);
238
+ process.on("exit", shutdown);
239
+
240
+ backend.on("exit", (code) => {
241
+ if (!shuttingDown && code !== 0) {
242
+ console.error(`[wocingflow-mcp] backend exited early with code ${code}`);
243
+ process.exit(code || 1);
244
+ }
245
+ });
246
+
247
+ await waitHealth(endpoint, 20000);
248
+
249
+ const bridge = spawnBridge(process.env, endpoint);
250
+ bridge.on("exit", (code) => {
251
+ shutdown();
252
+ process.exit(code || 0);
253
+ });
254
+ }
255
+
256
+ main().catch((error) => {
257
+ console.error(`[wocingflow-mcp] ${error.message}`);
258
+ process.exit(1);
259
+ });
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
- {
2
- "name": "@etavioxy/wocingflow-mcp-server",
3
- "version": "0.0.5",
4
- "description": "MCP stdio launcher for WocingFlow service mcp_server",
5
- "type": "commonjs",
6
- "bin": {
7
- "wocingflow-mcp-server": "bin/wocingflow-mcp-server.js"
8
- },
9
- "engines": {
10
- "node": ">=18"
11
- },
12
- "scripts": {
13
- "prepack": "node scripts/prepack.js"
14
- },
15
- "files": [
16
- "bin",
17
- "vendor"
18
- ]
19
- }
1
+ {
2
+ "name": "@etavioxy/wocingflow-mcp-server",
3
+ "version": "0.0.6-fix.2",
4
+ "description": "MCP stdio launcher for WocingFlow service mcp_server",
5
+ "type": "commonjs",
6
+ "bin": {
7
+ "wocingflow-mcp-server": "bin/wocingflow-mcp-server.js"
8
+ },
9
+ "engines": {
10
+ "node": ">=18"
11
+ },
12
+ "scripts": {
13
+ "prepack": "node scripts/prepack.js"
14
+ },
15
+ "files": [
16
+ "bin",
17
+ "vendor"
18
+ ]
19
+ }
Binary file
@@ -1,18 +1,18 @@
1
- #!/bin/sh
2
- wf require WF_TARGET_FOLDER
3
- wf require WF_SHARED_REPO_PATH
4
- echo "[Status] Copying shared repo snapshot from: $WF_SHARED_REPO_PATH"
5
- wf test is-git-repo "$WF_SHARED_REPO_PATH"
6
- if wf test is-path-exists "$WF_TARGET_FOLDER"; then
7
- wf test is-dir "$WF_TARGET_FOLDER"
8
- wf test is-empty-dir "$WF_TARGET_FOLDER"
9
- else
10
- mkdir -p "$WF_TARGET_FOLDER"
11
- fi
12
- cp -a "$WF_SHARED_REPO_PATH/." "$WF_TARGET_FOLDER/"
13
- branch_name="feature/$(basename "$WF_TARGET_FOLDER")"
14
- if git -C "$WF_TARGET_FOLDER" rev-parse --verify --quiet "refs/heads/$branch_name" >/dev/null; then
15
- git -C "$WF_TARGET_FOLDER" checkout "$branch_name"
16
- else
17
- git -C "$WF_TARGET_FOLDER" checkout -b "$branch_name"
18
- fi
1
+ #!/bin/sh
2
+ wf require WF_TARGET_FOLDER
3
+ wf require WF_SHARED_REPO_PATH
4
+ echo "[Status] Copying shared repo snapshot from: $WF_SHARED_REPO_PATH"
5
+ wf test is-git-repo "$WF_SHARED_REPO_PATH"
6
+ if wf test is-path-exists "$WF_TARGET_FOLDER"; then
7
+ wf test is-dir "$WF_TARGET_FOLDER"
8
+ wf test is-empty-dir "$WF_TARGET_FOLDER"
9
+ else
10
+ mkdir -p "$WF_TARGET_FOLDER"
11
+ fi
12
+ cp -a "$WF_SHARED_REPO_PATH/." "$WF_TARGET_FOLDER/"
13
+ branch_name="feature/$(basename "$WF_TARGET_FOLDER")"
14
+ if git -C "$WF_TARGET_FOLDER" rev-parse --verify --quiet "refs/heads/$branch_name" >/dev/null; then
15
+ git -C "$WF_TARGET_FOLDER" checkout "$branch_name"
16
+ else
17
+ git -C "$WF_TARGET_FOLDER" checkout -b "$branch_name"
18
+ fi
@@ -1,9 +1,9 @@
1
- #!/bin/sh
2
- wf require WF_TARGET_FOLDER
3
- wf require WF_PATCH_COMMITS
4
- first="$(printf '%s\n' "$WF_PATCH_COMMITS" | awk '{print $1}')"
5
- wf test is-git-repo "$WF_TARGET_FOLDER"
6
- wf test is-git-commit "$WF_TARGET_FOLDER" "$first"
7
- echo "[Status] Open rebase todo from: $first^"
8
- echo "[Hint] Keep earliest hash as pick, change later selected hashes to squash."
9
- git -C "$WF_TARGET_FOLDER" rebase -i "$first^"
1
+ #!/bin/sh
2
+ wf require WF_TARGET_FOLDER
3
+ wf require WF_PATCH_COMMITS
4
+ first="$(printf '%s\n' "$WF_PATCH_COMMITS" | awk '{print $1}')"
5
+ wf test is-git-repo "$WF_TARGET_FOLDER"
6
+ wf test is-git-commit "$WF_TARGET_FOLDER" "$first"
7
+ echo "[Status] Open rebase todo from: $first^"
8
+ echo "[Hint] Keep earliest hash as pick, change later selected hashes to squash."
9
+ git -C "$WF_TARGET_FOLDER" rebase -i "$first^"
@@ -1,26 +1,26 @@
1
- #!/bin/sh
2
- wf require WF_TARGET_FOLDER
3
- wf require WF_SHARED_REPO_PATH
4
- wf require WF_COMMIT_HASH
5
- # Validate repositories and selected commit before rewriting history.
6
- wf test is-git-repo "$WF_TARGET_FOLDER"
7
- wf test is-git-repo "$WF_SHARED_REPO_PATH"
8
- wf test is-git-commit "$WF_TARGET_FOLDER" "$WF_COMMIT_HASH"
9
-
10
- # Use merge-base(target HEAD, shared HEAD) as the rebase base.
11
- shared_head="$(git -C "$WF_SHARED_REPO_PATH" rev-parse HEAD)"
12
- lcp="$(git -C "$WF_TARGET_FOLDER" merge-base HEAD "$shared_head")"
13
- if [ "$lcp" != "$shared_head" ]; then
14
- echo "[Error] LCP mismatch: lcp($lcp) != shared_head($shared_head)"
15
- exit 1
16
- fi
17
- selected_short="$(git -C "$WF_TARGET_FOLDER" rev-parse --short "$WF_COMMIT_HASH")"
18
-
19
- # Reorder rebase todo: move selected commit line to the top.
20
- editor_cmd="sh -c 'f=\"\$1\"; awk -v s=\"$selected_short\" '\''/^pick / { h=\$2; if (index(h, s)==1 || index(s, h)==1) { x=\$0; next } } { r = r \$0 ORS } END { if (!x) { print \"[Error] commit not in todo.\" > \"/dev/stderr\"; exit 3 } print x; printf \"%s\", r }'\'' \"\$f\" > \"\$f.tmp\" && mv \"\$f.tmp\" \"\$f\"' _"
21
- GIT_SEQUENCE_EDITOR="$editor_cmd" git -C "$WF_TARGET_FOLDER" rebase -i "$lcp"
22
-
23
- # Sync selected patch to shared branch.
24
- git -C "$WF_SHARED_REPO_PATH" fetch "$WF_TARGET_FOLDER" "$WF_COMMIT_HASH"
25
- git -C "$WF_SHARED_REPO_PATH" cherry-pick FETCH_HEAD
26
- echo "[Status] Patch sink completed."
1
+ #!/bin/sh
2
+ wf require WF_TARGET_FOLDER
3
+ wf require WF_SHARED_REPO_PATH
4
+ wf require WF_COMMIT_HASH
5
+ # Validate repositories and selected commit before rewriting history.
6
+ wf test is-git-repo "$WF_TARGET_FOLDER"
7
+ wf test is-git-repo "$WF_SHARED_REPO_PATH"
8
+ wf test is-git-commit "$WF_TARGET_FOLDER" "$WF_COMMIT_HASH"
9
+
10
+ # Use merge-base(target HEAD, shared HEAD) as the rebase base.
11
+ shared_head="$(git -C "$WF_SHARED_REPO_PATH" rev-parse HEAD)"
12
+ lcp="$(git -C "$WF_TARGET_FOLDER" merge-base HEAD "$shared_head")"
13
+ if [ "$lcp" != "$shared_head" ]; then
14
+ echo "[Error] LCP mismatch: lcp($lcp) != shared_head($shared_head)"
15
+ exit 1
16
+ fi
17
+ selected_short="$(git -C "$WF_TARGET_FOLDER" rev-parse --short "$WF_COMMIT_HASH")"
18
+
19
+ # Reorder rebase todo: move selected commit line to the top.
20
+ editor_cmd="sh -c 'f=\"\$1\"; awk -v s=\"$selected_short\" '\''/^pick / { h=\$2; if (index(h, s)==1 || index(s, h)==1) { x=\$0; next } } { r = r \$0 ORS } END { if (!x) { print \"[Error] commit not in todo.\" > \"/dev/stderr\"; exit 3 } print x; printf \"%s\", r }'\'' \"\$f\" > \"\$f.tmp\" && mv \"\$f.tmp\" \"\$f\"' _"
21
+ GIT_SEQUENCE_EDITOR="$editor_cmd" git -C "$WF_TARGET_FOLDER" rebase -i "$lcp"
22
+
23
+ # Sync selected patch to shared branch.
24
+ git -C "$WF_SHARED_REPO_PATH" fetch "$WF_TARGET_FOLDER" "$WF_COMMIT_HASH"
25
+ git -C "$WF_SHARED_REPO_PATH" cherry-pick FETCH_HEAD
26
+ echo "[Status] Patch sink completed."