@etavioxy/wocingflow-mcp-server 0.0.2 → 0.0.3

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 (23) hide show
  1. package/bin/wocingflow-mcp-server.js +205 -200
  2. package/package.json +1 -1
  3. package/vendor/mcp_server.exe +0 -0
  4. package/vendor/service-data/workflows/baseline-workflow/01-start-feature.sh +18 -0
  5. package/vendor/service-data/workflows/baseline-workflow/02-select-minimal-patch.sh +9 -0
  6. package/vendor/service-data/workflows/baseline-workflow/03-patch-sink.sh +26 -0
  7. package/vendor/service-data/workflows/baseline-workflow/04-patch-broadcast.sh +24 -0
  8. package/vendor/service-data/workflows/baseline-workflow/05-squash-feature.sh +18 -0
  9. package/vendor/service-data/workflows/baseline-workflow/06-feature-retract.sh +28 -0
  10. package/vendor/service-data/workflows/baseline-workflow/07-rebase-origin.sh +27 -0
  11. package/vendor/service-data/workflows/baseline-workflow/08-push-origin.sh +5 -0
  12. package/vendor/service-data/workflows/baseline-workflow/09-generate-patches.sh +11 -0
  13. package/vendor/service-data/workflows/baseline-workflow/profile.json +215 -0
  14. package/vendor/service-data/workflows/commit-merge-split-lab/01-show-recent-commits.sh +3 -0
  15. package/vendor/service-data/workflows/commit-merge-split-lab/02-merge-commits-in-range.sh +5 -0
  16. package/vendor/service-data/workflows/commit-merge-split-lab/03-split-commit-to-working-tree.sh +6 -0
  17. package/vendor/service-data/workflows/commit-merge-split-lab/04-recommit-selected-path.sh +6 -0
  18. package/vendor/service-data/workflows/commit-merge-split-lab/05-continue-rewrite.sh +3 -0
  19. package/vendor/service-data/workflows/commit-merge-split-lab/profile.json +79 -0
  20. package/vendor/service-data/workflows/patch-export-for-review/01-ensure-patch-out-dir.sh +4 -0
  21. package/vendor/service-data/workflows/patch-export-for-review/02-format-patch-by-folder.sh +6 -0
  22. package/vendor/service-data/workflows/patch-export-for-review/03-list-generated-patches.sh +7 -0
  23. package/vendor/service-data/workflows/patch-export-for-review/profile.json +61 -0
@@ -1,200 +1,205 @@
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
-
7
- function sleep(ms) {
8
- return new Promise((resolve) => setTimeout(resolve, ms));
9
- }
10
-
11
- function isWindows() {
12
- return process.platform === "win32";
13
- }
14
-
15
- function fileExists(filePath) {
16
- try {
17
- return fs.existsSync(filePath);
18
- } catch {
19
- return false;
20
- }
21
- }
22
-
23
- function candidateRoots() {
24
- const cwd = process.cwd();
25
- return [cwd, path.resolve(cwd, ".."), path.resolve(cwd, "..", "..")];
26
- }
27
-
28
- function resolveServiceDataDir() {
29
- if (process.env.WF_SERVICE_DATA_DIR && fileExists(process.env.WF_SERVICE_DATA_DIR)) {
30
- return process.env.WF_SERVICE_DATA_DIR;
31
- }
32
- for (const root of candidateRoots()) {
33
- const candidate = path.join(root, "service", "data");
34
- if (fileExists(candidate)) {
35
- return candidate;
36
- }
37
- }
38
- return "";
39
- }
40
-
41
- function resolveServerLaunch() {
42
- if (process.env.WF_MCP_SERVER_BIN && fileExists(process.env.WF_MCP_SERVER_BIN)) {
43
- return { command: process.env.WF_MCP_SERVER_BIN, args: [] };
44
- }
45
-
46
- const exeName = isWindows() ? "mcp_server.exe" : "mcp_server";
47
- const bundledPath = path.join(__dirname, "..", "vendor", exeName);
48
- if (fileExists(bundledPath)) {
49
- return { command: bundledPath, args: [] };
50
- }
51
-
52
- for (const root of candidateRoots()) {
53
- const debugPath = path.join(root, "service", "target", "debug", exeName);
54
- const releasePath = path.join(root, "service", "target", "release", exeName);
55
- if (fileExists(debugPath)) return { command: debugPath, args: [] };
56
- if (fileExists(releasePath)) return { command: releasePath, args: [] };
57
- }
58
-
59
- for (const root of candidateRoots()) {
60
- const manifestPath = path.join(root, "service", "Cargo.toml");
61
- if (fileExists(manifestPath)) {
62
- return {
63
- command: "cargo",
64
- args: ["run", "--manifest-path", manifestPath, "--bin", "mcp_server", "--"],
65
- };
66
- }
67
- }
68
-
69
- throw new Error(
70
- "Cannot locate wocingflow mcp_server. Build service/bin/mcp_server or set WF_MCP_SERVER_BIN."
71
- );
72
- }
73
-
74
- async function resolvePort() {
75
- if (process.env.WF_MCP_HTTP_PORT) {
76
- return String(process.env.WF_MCP_HTTP_PORT);
77
- }
78
- return String(
79
- await new Promise((resolve, reject) => {
80
- const server = net.createServer();
81
- server.listen(0, "127.0.0.1", () => {
82
- const address = server.address();
83
- if (!address || typeof address === "string") {
84
- server.close();
85
- reject(new Error("Failed to allocate free TCP port."));
86
- return;
87
- }
88
- const freePort = address.port;
89
- server.close(() => resolve(freePort));
90
- });
91
- server.on("error", reject);
92
- })
93
- );
94
- }
95
-
96
- async function waitHealth(endpoint, timeoutMs) {
97
- const started = Date.now();
98
- while (Date.now() - started < timeoutMs) {
99
- try {
100
- const response = await fetch(`${endpoint}/health`);
101
- if (response.ok) return;
102
- } catch {
103
- // keep waiting
104
- }
105
- await sleep(300);
106
- }
107
- throw new Error(`mcp_server health check timeout: ${endpoint}/health`);
108
- }
109
-
110
- function spawnBackend(command, args, env) {
111
- const child = spawn(command, args, {
112
- stdio: ["ignore", "pipe", "pipe"],
113
- env,
114
- shell: false,
115
- windowsHide: true,
116
- });
117
- child.stdout.on("data", (chunk) => {
118
- process.stderr.write(String(chunk));
119
- });
120
- child.stderr.on("data", (chunk) => {
121
- process.stderr.write(String(chunk));
122
- });
123
- return child;
124
- }
125
-
126
- function spawnBridge(env, endpoint) {
127
- let command;
128
- let args;
129
- if (isWindows()) {
130
- command = "cmd.exe";
131
- args = ["/d", "/s", "/c", `npx -y mcp-remote@latest ${endpoint}`];
132
- } else {
133
- command = "npx";
134
- args = ["-y", "mcp-remote@latest", endpoint];
135
- }
136
-
137
- const child = spawn(command, args, {
138
- stdio: ["pipe", "pipe", "pipe"],
139
- env,
140
- shell: false,
141
- windowsHide: true,
142
- });
143
-
144
- process.stdin.pipe(child.stdin);
145
- child.stdout.pipe(process.stdout);
146
- child.stderr.pipe(process.stderr);
147
- return child;
148
- }
149
-
150
- async function main() {
151
- const host = process.env.WF_MCP_HTTP_HOST || "127.0.0.1";
152
- const port = await resolvePort();
153
- const endpoint = `http://${host}:${port}`;
154
- const serviceDataDir = resolveServiceDataDir();
155
- const launch = resolveServerLaunch();
156
-
157
- const backendEnv = { ...process.env };
158
- if (serviceDataDir) {
159
- backendEnv.WF_SERVICE_DATA_DIR = serviceDataDir;
160
- }
161
-
162
- const backend = spawnBackend(
163
- launch.command,
164
- [...launch.args, "--host", host, "--port", String(port)],
165
- backendEnv
166
- );
167
-
168
- let shuttingDown = false;
169
- const shutdown = () => {
170
- if (shuttingDown) return;
171
- shuttingDown = true;
172
- if (!backend.killed) {
173
- backend.kill();
174
- }
175
- };
176
-
177
- process.on("SIGINT", shutdown);
178
- process.on("SIGTERM", shutdown);
179
- process.on("exit", shutdown);
180
-
181
- backend.on("exit", (code) => {
182
- if (!shuttingDown && code !== 0) {
183
- console.error(`[wocingflow-mcp] backend exited early with code ${code}`);
184
- process.exit(code || 1);
185
- }
186
- });
187
-
188
- await waitHealth(endpoint, 20000);
189
-
190
- const bridge = spawnBridge(process.env, endpoint);
191
- bridge.on("exit", (code) => {
192
- shutdown();
193
- process.exit(code || 0);
194
- });
195
- }
196
-
197
- main().catch((error) => {
198
- console.error(`[wocingflow-mcp] ${error.message}`);
199
- process.exit(1);
200
- });
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
+
7
+ function sleep(ms) {
8
+ return new Promise((resolve) => setTimeout(resolve, ms));
9
+ }
10
+
11
+ function isWindows() {
12
+ return process.platform === "win32";
13
+ }
14
+
15
+ function fileExists(filePath) {
16
+ try {
17
+ return fs.existsSync(filePath);
18
+ } catch {
19
+ return false;
20
+ }
21
+ }
22
+
23
+ function candidateRoots() {
24
+ const cwd = process.cwd();
25
+ return [cwd, path.resolve(cwd, ".."), path.resolve(cwd, "..", "..")];
26
+ }
27
+
28
+ function resolveServiceDataDir() {
29
+ const bundledData = path.join(__dirname, "..", "vendor", "service-data");
30
+ if (fileExists(bundledData)) {
31
+ return bundledData;
32
+ }
33
+
34
+ if (process.env.WF_SERVICE_DATA_DIR && fileExists(process.env.WF_SERVICE_DATA_DIR)) {
35
+ return process.env.WF_SERVICE_DATA_DIR;
36
+ }
37
+ for (const root of candidateRoots()) {
38
+ const candidate = path.join(root, "service", "data");
39
+ if (fileExists(candidate)) {
40
+ return candidate;
41
+ }
42
+ }
43
+ return "";
44
+ }
45
+
46
+ function resolveServerLaunch() {
47
+ if (process.env.WF_MCP_SERVER_BIN && fileExists(process.env.WF_MCP_SERVER_BIN)) {
48
+ return { command: process.env.WF_MCP_SERVER_BIN, args: [] };
49
+ }
50
+
51
+ const exeName = isWindows() ? "mcp_server.exe" : "mcp_server";
52
+ const bundledPath = path.join(__dirname, "..", "vendor", exeName);
53
+ if (fileExists(bundledPath)) {
54
+ return { command: bundledPath, args: [] };
55
+ }
56
+
57
+ for (const root of candidateRoots()) {
58
+ const debugPath = path.join(root, "service", "target", "debug", exeName);
59
+ const releasePath = path.join(root, "service", "target", "release", exeName);
60
+ if (fileExists(debugPath)) return { command: debugPath, args: [] };
61
+ if (fileExists(releasePath)) return { command: releasePath, args: [] };
62
+ }
63
+
64
+ for (const root of candidateRoots()) {
65
+ const manifestPath = path.join(root, "service", "Cargo.toml");
66
+ if (fileExists(manifestPath)) {
67
+ return {
68
+ command: "cargo",
69
+ args: ["run", "--manifest-path", manifestPath, "--bin", "mcp_server", "--"],
70
+ };
71
+ }
72
+ }
73
+
74
+ throw new Error(
75
+ "Cannot locate wocingflow mcp_server. Build service/bin/mcp_server or set WF_MCP_SERVER_BIN."
76
+ );
77
+ }
78
+
79
+ async function resolvePort() {
80
+ if (process.env.WF_MCP_HTTP_PORT) {
81
+ return String(process.env.WF_MCP_HTTP_PORT);
82
+ }
83
+ return String(
84
+ await new Promise((resolve, reject) => {
85
+ const server = net.createServer();
86
+ server.listen(0, "127.0.0.1", () => {
87
+ const address = server.address();
88
+ if (!address || typeof address === "string") {
89
+ server.close();
90
+ reject(new Error("Failed to allocate free TCP port."));
91
+ return;
92
+ }
93
+ const freePort = address.port;
94
+ server.close(() => resolve(freePort));
95
+ });
96
+ server.on("error", reject);
97
+ })
98
+ );
99
+ }
100
+
101
+ async function waitHealth(endpoint, timeoutMs) {
102
+ const started = Date.now();
103
+ while (Date.now() - started < timeoutMs) {
104
+ try {
105
+ const response = await fetch(`${endpoint}/health`);
106
+ if (response.ok) return;
107
+ } catch {
108
+ // keep waiting
109
+ }
110
+ await sleep(300);
111
+ }
112
+ throw new Error(`mcp_server health check timeout: ${endpoint}/health`);
113
+ }
114
+
115
+ function spawnBackend(command, args, env) {
116
+ const child = spawn(command, args, {
117
+ stdio: ["ignore", "pipe", "pipe"],
118
+ env,
119
+ shell: false,
120
+ windowsHide: true,
121
+ });
122
+ child.stdout.on("data", (chunk) => {
123
+ process.stderr.write(String(chunk));
124
+ });
125
+ child.stderr.on("data", (chunk) => {
126
+ process.stderr.write(String(chunk));
127
+ });
128
+ return child;
129
+ }
130
+
131
+ function spawnBridge(env, endpoint) {
132
+ let command;
133
+ let args;
134
+ if (isWindows()) {
135
+ command = "cmd.exe";
136
+ args = ["/d", "/s", "/c", `npx -y mcp-remote@latest ${endpoint}`];
137
+ } else {
138
+ command = "npx";
139
+ args = ["-y", "mcp-remote@latest", endpoint];
140
+ }
141
+
142
+ const child = spawn(command, args, {
143
+ stdio: ["pipe", "pipe", "pipe"],
144
+ env,
145
+ shell: false,
146
+ windowsHide: true,
147
+ });
148
+
149
+ process.stdin.pipe(child.stdin);
150
+ child.stdout.pipe(process.stdout);
151
+ child.stderr.pipe(process.stderr);
152
+ return child;
153
+ }
154
+
155
+ async function main() {
156
+ const host = process.env.WF_MCP_HTTP_HOST || "127.0.0.1";
157
+ const port = await resolvePort();
158
+ const endpoint = `http://${host}:${port}`;
159
+ const serviceDataDir = resolveServiceDataDir();
160
+ const launch = resolveServerLaunch();
161
+
162
+ const backendEnv = { ...process.env };
163
+ if (serviceDataDir) {
164
+ backendEnv.WF_SERVICE_DATA_DIR = serviceDataDir;
165
+ }
166
+
167
+ const backend = spawnBackend(
168
+ launch.command,
169
+ [...launch.args, "--host", host, "--port", String(port)],
170
+ backendEnv
171
+ );
172
+
173
+ let shuttingDown = false;
174
+ const shutdown = () => {
175
+ if (shuttingDown) return;
176
+ shuttingDown = true;
177
+ if (!backend.killed) {
178
+ backend.kill();
179
+ }
180
+ };
181
+
182
+ process.on("SIGINT", shutdown);
183
+ process.on("SIGTERM", shutdown);
184
+ process.on("exit", shutdown);
185
+
186
+ backend.on("exit", (code) => {
187
+ if (!shuttingDown && code !== 0) {
188
+ console.error(`[wocingflow-mcp] backend exited early with code ${code}`);
189
+ process.exit(code || 1);
190
+ }
191
+ });
192
+
193
+ await waitHealth(endpoint, 20000);
194
+
195
+ const bridge = spawnBridge(process.env, endpoint);
196
+ bridge.on("exit", (code) => {
197
+ shutdown();
198
+ process.exit(code || 0);
199
+ });
200
+ }
201
+
202
+ main().catch((error) => {
203
+ console.error(`[wocingflow-mcp] ${error.message}`);
204
+ process.exit(1);
205
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etavioxy/wocingflow-mcp-server",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "MCP stdio launcher for WocingFlow service mcp_server",
5
5
  "type": "commonjs",
6
6
  "bin": {
Binary file
@@ -0,0 +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
@@ -0,0 +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^"
@@ -0,0 +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."
@@ -0,0 +1,24 @@
1
+ #!/bin/sh
2
+ # Rebase target repos onto latest shared head.
3
+ wf require WF_SHARED_REPO_PATH
4
+ wf require WF_TARGET_REPOS
5
+ wf test is-git-repo "$WF_SHARED_REPO_PATH"
6
+ shared_head="$(git -C "$WF_SHARED_REPO_PATH" rev-parse HEAD)"
7
+
8
+ # Validate all target repos first (fail fast before any mutation).
9
+ for repo_path in $WF_TARGET_REPOS; do
10
+ [ "$repo_path" = "$WF_SHARED_REPO_PATH" ] && continue
11
+ wf test is-git-repo "$repo_path"
12
+ done
13
+
14
+ # Rebase each validated target repo onto shared latest base.
15
+ for repo_path in $WF_TARGET_REPOS; do
16
+ [ "$repo_path" = "$WF_SHARED_REPO_PATH" ] && continue
17
+ git -C "$repo_path" fetch "$WF_SHARED_REPO_PATH" "$shared_head"
18
+ fetched_shared_head="$(git -C "$repo_path" rev-parse FETCH_HEAD)"
19
+ lcp="$(git -C "$repo_path" merge-base HEAD "$fetched_shared_head")"
20
+ [ "$lcp" = "$fetched_shared_head" ] && continue
21
+ git -C "$repo_path" rebase --onto "$fetched_shared_head" "$lcp"
22
+ done
23
+
24
+ echo "[Status] Broadcast completed."
@@ -0,0 +1,18 @@
1
+ #!/bin/sh
2
+ wf require WF_TARGET_FOLDER
3
+ wf require WF_SHARED_REPO_PATH
4
+ echo "[Status] Squashing commits from source branch into shared as one commit..."
5
+ wf test is-git-repo "$WF_TARGET_FOLDER"
6
+ wf test is-git-repo "$WF_SHARED_REPO_PATH"
7
+ shared_head="$(git -C "$WF_SHARED_REPO_PATH" rev-parse HEAD)"
8
+ source_head="$(git -C "$WF_TARGET_FOLDER" rev-parse HEAD)"
9
+ git -C "$WF_SHARED_REPO_PATH" fetch "$WF_TARGET_FOLDER" "$source_head"
10
+ fetched_source_head="$(git -C "$WF_SHARED_REPO_PATH" rev-parse FETCH_HEAD)"
11
+ commit_count="$(git -C "$WF_SHARED_REPO_PATH" rev-list --count "${shared_head}..${fetched_source_head}")"
12
+ if [ "$commit_count" -lt 1 ]; then
13
+ echo "[Error] No commits after shared base to squash."
14
+ exit 1
15
+ fi
16
+ git -C "$WF_SHARED_REPO_PATH" cherry-pick --no-commit "${shared_head}..${fetched_source_head}"
17
+ git -C "$WF_SHARED_REPO_PATH" commit -m "squash: from $(basename "$WF_TARGET_FOLDER") after shared base"
18
+ echo "[Status] Shared squash commit created."
@@ -0,0 +1,28 @@
1
+ #!/bin/sh
2
+ wf require WF_COMMIT_HASH
3
+ wf require WF_SHARED_REPO_PATH
4
+ echo "[Status] Dropping latest shared squash commit: $WF_COMMIT_HASH..."
5
+
6
+ # Ensure shared repo and target commit are valid before any history operation.
7
+ wf test is-git-repo "$WF_SHARED_REPO_PATH"
8
+ wf test is-git-commit "$WF_SHARED_REPO_PATH" "$WF_COMMIT_HASH"
9
+
10
+ # Step6 must revert the current shared HEAD produced by Step5.
11
+ head_commit="$(git -C "$WF_SHARED_REPO_PATH" rev-parse HEAD)"
12
+ if [ "$head_commit" != "$WF_COMMIT_HASH" ]; then
13
+ echo "[Error] WF_COMMIT_HASH must be current shared HEAD for retract."
14
+ exit 1
15
+ fi
16
+
17
+ # Guard against dropping arbitrary commits: only allow Step5 squash commit pattern.
18
+ commit_subject="$(git -C "$WF_SHARED_REPO_PATH" log -1 --format=%s "$WF_COMMIT_HASH")"
19
+ case "$commit_subject" in
20
+ squash:*)
21
+ ;;
22
+ *)
23
+ echo "[Error] commit is not a squash commit from Step5."
24
+ exit 1
25
+ ;;
26
+ esac
27
+ git -C "$WF_SHARED_REPO_PATH" reset --hard "$WF_COMMIT_HASH^"
28
+ echo "[Status] Shared squash commit dropped."
@@ -0,0 +1,27 @@
1
+ #!/bin/sh
2
+ wf require WF_SHARED_REPO_PATH
3
+ wf require WF_TARGET_REPOS
4
+ echo "[Status] Rebasing shared onto origin/main, then rebasing non-shared repos onto shared..."
5
+
6
+ # Validate all repos first (fail fast before any mutation).
7
+ wf test is-git-repo "$WF_SHARED_REPO_PATH"
8
+ for repo_path in $WF_TARGET_REPOS; do
9
+ [ "$repo_path" = "$WF_SHARED_REPO_PATH" ] && continue
10
+ wf test is-git-repo "$repo_path"
11
+ done
12
+
13
+ # Rebase shared repo to origin/main first.
14
+ git -C "$WF_SHARED_REPO_PATH" fetch origin
15
+ git -C "$WF_SHARED_REPO_PATH" rebase origin/main
16
+ shared_head="$(git -C "$WF_SHARED_REPO_PATH" rev-parse HEAD)"
17
+
18
+ # Rebase each target repo to the new shared base.
19
+ for repo_path in $WF_TARGET_REPOS; do
20
+ [ "$repo_path" = "$WF_SHARED_REPO_PATH" ] && continue
21
+ git -C "$repo_path" fetch "$WF_SHARED_REPO_PATH" "$shared_head"
22
+ fetched_shared_head="$(git -C "$repo_path" rev-parse FETCH_HEAD)"
23
+ lcp="$(git -C "$repo_path" merge-base HEAD "$fetched_shared_head")"
24
+ [ "$lcp" = "$fetched_shared_head" ] && continue
25
+ git -C "$repo_path" rebase --onto "$fetched_shared_head" "$lcp"
26
+ done
27
+ echo "[Status] Shared and non-shared repos are rebased to latest base."
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ wf test is-git-repo "."
3
+ echo "[Status] Pushing shared branch to origin..."
4
+ git push origin HEAD --force-with-lease
5
+ echo "[Status] Push completed."
@@ -0,0 +1,11 @@
1
+ #!/bin/sh
2
+ wf require WF_TARGET_FOLDER
3
+ wf require WF_TARGET_REPO_PATH
4
+ wf require WF_SHARED_REPO_PATH
5
+ wf test is-git-repo "$WF_TARGET_REPO_PATH"
6
+ wf test is-git-repo "$WF_SHARED_REPO_PATH"
7
+ wf test is-path-exists "$WF_TARGET_FOLDER"
8
+ echo "[Status] Generating exported patch files for $WF_TARGET_FOLDER..."
9
+ mkdir -p "$WF_TARGET_REPO_PATH/patches_out"
10
+ git -C "$WF_TARGET_REPO_PATH" format-patch -o "$WF_TARGET_REPO_PATH/patches_out/" -1 HEAD -- $WF_TARGET_FOLDER
11
+ echo "[Status] Patch sequence generated."
@@ -0,0 +1,215 @@
1
+ {
2
+ "id": "baseline-workflow",
3
+ "name": "Baseline Workflow",
4
+ "nameI18n": {
5
+ "en-US": "Baseline Workflow",
6
+ "zh-CN": "基础工作流"
7
+ },
8
+ "description": "Default profile for daily Git operations with local shared-repo state and patch/feature handling.",
9
+ "descriptionI18n": {
10
+ "en-US": "Default profile for daily Git operations with local shared-repo state and patch/feature handling.",
11
+ "zh-CN": "用于日常 Git 操作的基础配置,包含共享仓库本地状态以及补丁/特性整理流程。"
12
+ },
13
+ "storageFields": [
14
+ {
15
+ "key": "repoPaths",
16
+ "type": "stringList",
17
+ "required": true,
18
+ "linkSource": "profileState",
19
+ "description": "Locally persisted repository folder paths used by this profile.",
20
+ "descriptionI18n": {
21
+ "en-US": "Locally persisted repository folder paths used by this profile.",
22
+ "zh-CN": "该 profile 在本地保存的仓库目录路径列表。"
23
+ }
24
+ },
25
+ {
26
+ "key": "lastTargetFolder",
27
+ "type": "path",
28
+ "required": false,
29
+ "description": "Last target folder used when running steps.",
30
+ "descriptionI18n": {
31
+ "en-US": "Last target folder used when running steps.",
32
+ "zh-CN": "上次执行步骤时使用的目标文件夹。"
33
+ }
34
+ },
35
+ {
36
+ "key": "sharedRepoPath",
37
+ "type": "path",
38
+ "required": true,
39
+ "description": "Shared source repository used as Step1 baseline.",
40
+ "descriptionI18n": {
41
+ "en-US": "Shared source repository used as Step1 baseline.",
42
+ "zh-CN": "Step1 使用的共享源仓库路径。"
43
+ }
44
+ }
45
+ ],
46
+ "steps": [
47
+ {
48
+ "id": "start-feature",
49
+ "name": "Start Feature",
50
+ "nameI18n": {
51
+ "en-US": "Start Feature",
52
+ "zh-CN": "创建特性分支"
53
+ },
54
+ "description": "Create feature branch and copy full snapshot from shared source repo.",
55
+ "descriptionI18n": {
56
+ "en-US": "Create feature branch and copy full snapshot from shared source repo.",
57
+ "zh-CN": "创建特性分支,并从共享源仓库全量复制快照。"
58
+ },
59
+ "paramBindings": [
60
+ {
61
+ "paramKey": "TARGET_FOLDER",
62
+ "storageKey": "lastTargetFolder",
63
+ "uiControl": "select",
64
+ "optionsFromStorageKey": "repoPaths",
65
+ "placeholderI18n": {
66
+ "en-US": "Select a target folder",
67
+ "zh-CN": "请选择目标目录"
68
+ }
69
+ },
70
+ {
71
+ "paramKey": "SHARED_REPO_PATH",
72
+ "storageKey": "sharedRepoPath",
73
+ "valueSource": "storageDirect"
74
+ }
75
+ ],
76
+ "script": "01-start-feature.sh"
77
+ },
78
+ {
79
+ "id": "select-minimal-patch",
80
+ "name": "Select Minimal Patch",
81
+ "nameI18n": {
82
+ "en-US": "Select Minimal Patch",
83
+ "zh-CN": "选定最小修复"
84
+ },
85
+ "descriptionI18n": {
86
+ "en-US": "Select commit hashes and squash them into the earliest one via rebase.",
87
+ "zh-CN": "输入 commit hash 列表,并在 rebase 中将它们压缩到最早提交。"
88
+ },
89
+ "paramBindings": [
90
+ {
91
+ "paramKey": "TARGET_FOLDER",
92
+ "storageKey": "lastTargetFolder",
93
+ "uiControl": "select",
94
+ "optionsFromStorageKey": "repoPaths",
95
+ "placeholderI18n": {
96
+ "en-US": "Select a target folder",
97
+ "zh-CN": "请选择目标目录"
98
+ }
99
+ }
100
+ ],
101
+ "script": "02-select-minimal-patch.sh"
102
+ },
103
+ {
104
+ "id": "patch-sink",
105
+ "name": "Patch Sink",
106
+ "nameI18n": {
107
+ "en-US": "Patch Sink",
108
+ "zh-CN": "补丁下沉"
109
+ },
110
+ "script": "03-patch-sink.sh"
111
+ },
112
+ {
113
+ "id": "patch-broadcast",
114
+ "name": "Patch Broadcast",
115
+ "nameI18n": {
116
+ "en-US": "Patch Broadcast",
117
+ "zh-CN": "补丁分发"
118
+ },
119
+ "paramBindings": [
120
+ {
121
+ "paramKey": "SHARED_REPO_PATH",
122
+ "storageKey": "sharedRepoPath",
123
+ "valueSource": "storageDirect"
124
+ },
125
+ {
126
+ "paramKey": "TARGET_REPOS",
127
+ "storageKey": "repoPaths",
128
+ "valueSource": "storageDirect"
129
+ }
130
+ ],
131
+ "script": "04-patch-broadcast.sh"
132
+ },
133
+ {
134
+ "id": "squash-feature",
135
+ "name": "Squash Feature",
136
+ "nameI18n": {
137
+ "en-US": "Squash Feature",
138
+ "zh-CN": "特性收敛"
139
+ },
140
+ "paramBindings": [
141
+ {
142
+ "paramKey": "TARGET_FOLDER",
143
+ "storageKey": "lastTargetFolder",
144
+ "uiControl": "select",
145
+ "optionsFromStorageKey": "repoPaths",
146
+ "placeholderI18n": {
147
+ "en-US": "Select a target folder",
148
+ "zh-CN": "请选择目标目录"
149
+ }
150
+ }
151
+ ],
152
+ "script": "05-squash-feature.sh"
153
+ },
154
+ {
155
+ "id": "feature-retract",
156
+ "name": "Feature Retract",
157
+ "nameI18n": {
158
+ "en-US": "Feature Retract",
159
+ "zh-CN": "特性撤回"
160
+ },
161
+ "script": "06-feature-retract.sh"
162
+ },
163
+ {
164
+ "id": "rebase-origin",
165
+ "name": "Rebase Origin",
166
+ "nameI18n": {
167
+ "en-US": "Rebase Origin",
168
+ "zh-CN": "同步远端基线"
169
+ },
170
+ "paramBindings": [
171
+ {
172
+ "paramKey": "SHARED_REPO_PATH",
173
+ "storageKey": "sharedRepoPath",
174
+ "valueSource": "storageDirect"
175
+ },
176
+ {
177
+ "paramKey": "TARGET_REPOS",
178
+ "storageKey": "repoPaths",
179
+ "valueSource": "storageDirect"
180
+ }
181
+ ],
182
+ "script": "07-rebase-origin.sh"
183
+ },
184
+ {
185
+ "id": "push-origin",
186
+ "name": "Push Origin",
187
+ "nameI18n": {
188
+ "en-US": "Push Origin",
189
+ "zh-CN": "推送提交"
190
+ },
191
+ "script": "08-push-origin.sh"
192
+ },
193
+ {
194
+ "id": "generate-patches",
195
+ "name": "Generate Patches",
196
+ "nameI18n": {
197
+ "en-US": "Generate Patches",
198
+ "zh-CN": "生成补丁"
199
+ },
200
+ "paramBindings": [
201
+ {
202
+ "paramKey": "TARGET_FOLDER",
203
+ "storageKey": "lastTargetFolder",
204
+ "uiControl": "select",
205
+ "optionsFromStorageKey": "repoPaths",
206
+ "placeholderI18n": {
207
+ "en-US": "Select a target folder",
208
+ "zh-CN": "请选择目标目录"
209
+ }
210
+ }
211
+ ],
212
+ "script": "09-generate-patches.sh"
213
+ }
214
+ ]
215
+ }
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+ echo "[Status] Recent commit history (latest 20):"
3
+ git log --oneline -n 20
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ wf require WF_BASE_REF
3
+ echo "[Status] Starting interactive rebase from base: $WF_BASE_REF"
4
+ echo "[Hint] Change 'pick' to 'squash'/'fixup' to merge commits as needed."
5
+ git rebase -i "$WF_BASE_REF"
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+ wf require WF_SPLIT_COMMIT_HASH
3
+ echo "[Status] Splitting commit: $WF_SPLIT_COMMIT_HASH"
4
+ echo "[Hint] This resets target commit changes into working tree for manual split."
5
+ git reset --mixed "$WF_SPLIT_COMMIT_HASH^"
6
+ git status --short
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+ wf require WF_TARGET_FOLDER
3
+ wf require WF_COMMIT_MSG
4
+ echo "[Status] Recommitting selected path: $WF_TARGET_FOLDER"
5
+ git add "$WF_TARGET_FOLDER"
6
+ git commit -m "$WF_COMMIT_MSG"
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+ echo "[Status] Continue history rewrite flow..."
3
+ git rebase --continue
@@ -0,0 +1,79 @@
1
+ {
2
+ "id": "commit-merge-split-lab",
3
+ "name": "Commit Merge and Split Lab",
4
+ "nameI18n": {
5
+ "en-US": "Commit Merge and Split Lab",
6
+ "zh-CN": "提交合并与分割实验室"
7
+ },
8
+ "descriptionI18n": {
9
+ "en-US": "Interactive profile for combining or splitting commits safely.",
10
+ "zh-CN": "用于交互式合并或分割提交的实验配置。"
11
+ },
12
+ "storageFields": [
13
+ {
14
+ "key": "lastRewriteBaseRef",
15
+ "type": "string",
16
+ "required": false,
17
+ "descriptionI18n": {
18
+ "en-US": "Last base ref used for interactive rebase.",
19
+ "zh-CN": "最近一次交互式 rebase 使用的基准引用。"
20
+ }
21
+ },
22
+ {
23
+ "key": "lastSplitCommitHash",
24
+ "type": "string",
25
+ "required": false,
26
+ "descriptionI18n": {
27
+ "en-US": "Last commit hash selected for split operation.",
28
+ "zh-CN": "最近一次用于分割的提交哈希。"
29
+ }
30
+ }
31
+ ],
32
+ "steps": [
33
+ {
34
+ "id": "show-recent-commits",
35
+ "name": "Show Recent Commits",
36
+ "nameI18n": {
37
+ "en-US": "Show Recent Commits",
38
+ "zh-CN": "查看最近提交"
39
+ },
40
+ "script": "01-show-recent-commits.sh"
41
+ },
42
+ {
43
+ "id": "merge-commits-in-range",
44
+ "name": "Merge Commits In Range",
45
+ "nameI18n": {
46
+ "en-US": "Merge Commits In Range",
47
+ "zh-CN": "范围内合并提交"
48
+ },
49
+ "script": "02-merge-commits-in-range.sh"
50
+ },
51
+ {
52
+ "id": "split-commit-to-working-tree",
53
+ "name": "Split Commit To Working Tree",
54
+ "nameI18n": {
55
+ "en-US": "Split Commit To Working Tree",
56
+ "zh-CN": "将提交拆回工作区"
57
+ },
58
+ "script": "03-split-commit-to-working-tree.sh"
59
+ },
60
+ {
61
+ "id": "recommit-selected-path",
62
+ "name": "Recommit Selected Path",
63
+ "nameI18n": {
64
+ "en-US": "Recommit Selected Path",
65
+ "zh-CN": "按路径重新提交"
66
+ },
67
+ "script": "04-recommit-selected-path.sh"
68
+ },
69
+ {
70
+ "id": "continue-rewrite",
71
+ "name": "Continue Rewrite",
72
+ "nameI18n": {
73
+ "en-US": "Continue Rewrite",
74
+ "zh-CN": "继续历史重写"
75
+ },
76
+ "script": "05-continue-rewrite.sh"
77
+ }
78
+ ]
79
+ }
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ echo "[Status] Ensuring patch output directory exists..."
3
+ mkdir -p patches_out
4
+ echo "[Status] Output directory ready: patches_out"
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+ wf require WF_TARGET_FOLDER
3
+ wf require WF_BASE_REF
4
+ echo "[Status] Exporting patch set from $WF_BASE_REF for folder $WF_TARGET_FOLDER..."
5
+ git format-patch "$WF_BASE_REF" -- "$WF_TARGET_FOLDER" -o patches_out/
6
+ echo "[Status] Patch files exported to patches_out"
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ echo "[Status] Listing generated patches..."
3
+ if [ -d patches_out ]; then
4
+ ls -1 patches_out
5
+ else
6
+ echo "[Warn] patches_out does not exist."
7
+ fi
@@ -0,0 +1,61 @@
1
+ {
2
+ "id": "patch-export-for-review",
3
+ "name": "Patch Export For Review",
4
+ "nameI18n": {
5
+ "en-US": "Patch Export For Review",
6
+ "zh-CN": "补丁导出评审"
7
+ },
8
+ "descriptionI18n": {
9
+ "en-US": "Export folder-scoped patch series for review or archival.",
10
+ "zh-CN": "按目录导出补丁序列,用于评审或归档。"
11
+ },
12
+ "storageFields": [
13
+ {
14
+ "key": "lastPatchBaseRef",
15
+ "type": "string",
16
+ "required": false,
17
+ "descriptionI18n": {
18
+ "en-US": "Most recently used base ref for format-patch.",
19
+ "zh-CN": "最近一次生成 patch 使用的基准引用。"
20
+ }
21
+ },
22
+ {
23
+ "key": "lastPatchTargetFolder",
24
+ "type": "path",
25
+ "required": false,
26
+ "descriptionI18n": {
27
+ "en-US": "Most recently exported target folder.",
28
+ "zh-CN": "最近一次导出补丁的目标目录。"
29
+ }
30
+ }
31
+ ],
32
+ "steps": [
33
+ {
34
+ "id": "ensure-patch-out-dir",
35
+ "name": "Ensure Patch Output Directory",
36
+ "nameI18n": {
37
+ "en-US": "Ensure Patch Output Directory",
38
+ "zh-CN": "准备补丁输出目录"
39
+ },
40
+ "script": "01-ensure-patch-out-dir.sh"
41
+ },
42
+ {
43
+ "id": "format-patch-by-folder",
44
+ "name": "Format Patch By Folder",
45
+ "nameI18n": {
46
+ "en-US": "Format Patch By Folder",
47
+ "zh-CN": "按目录导出补丁"
48
+ },
49
+ "script": "02-format-patch-by-folder.sh"
50
+ },
51
+ {
52
+ "id": "list-generated-patches",
53
+ "name": "List Generated Patches",
54
+ "nameI18n": {
55
+ "en-US": "List Generated Patches",
56
+ "zh-CN": "列出已生成补丁"
57
+ },
58
+ "script": "03-list-generated-patches.sh"
59
+ }
60
+ ]
61
+ }