vibe-coding-master 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 (52) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +226 -0
  3. package/dist/backend/adapters/claude-adapter.js +38 -0
  4. package/dist/backend/adapters/command-runner.js +33 -0
  5. package/dist/backend/adapters/filesystem.js +60 -0
  6. package/dist/backend/adapters/git-adapter.js +33 -0
  7. package/dist/backend/api/artifact-routes.js +109 -0
  8. package/dist/backend/api/message-routes.js +90 -0
  9. package/dist/backend/api/project-routes.js +17 -0
  10. package/dist/backend/api/session-routes.js +64 -0
  11. package/dist/backend/api/task-routes.js +30 -0
  12. package/dist/backend/errors.js +29 -0
  13. package/dist/backend/runtime/node-pty-runtime.js +162 -0
  14. package/dist/backend/runtime/session-registry.js +36 -0
  15. package/dist/backend/runtime/terminal-runtime.js +1 -0
  16. package/dist/backend/server.js +159 -0
  17. package/dist/backend/services/artifact-service.js +170 -0
  18. package/dist/backend/services/command-dispatcher.js +37 -0
  19. package/dist/backend/services/message-service.js +217 -0
  20. package/dist/backend/services/project-service.js +71 -0
  21. package/dist/backend/services/session-service.js +221 -0
  22. package/dist/backend/services/status-service.js +21 -0
  23. package/dist/backend/services/task-service.js +88 -0
  24. package/dist/backend/templates/handoff.js +76 -0
  25. package/dist/backend/templates/message-envelope.js +27 -0
  26. package/dist/backend/templates/role-command.js +21 -0
  27. package/dist/backend/templates/role-messaging-context.js +44 -0
  28. package/dist/backend/ws/terminal-ws.js +60 -0
  29. package/dist/cli/vcmctl.js +141 -0
  30. package/dist/main.js +63 -0
  31. package/dist/shared/constants.js +45 -0
  32. package/dist/shared/types/api.js +1 -0
  33. package/dist/shared/types/artifact.js +1 -0
  34. package/dist/shared/types/message.js +1 -0
  35. package/dist/shared/types/project.js +1 -0
  36. package/dist/shared/types/role.js +1 -0
  37. package/dist/shared/types/session.js +1 -0
  38. package/dist/shared/types/task.js +1 -0
  39. package/dist/shared/types/terminal.js +1 -0
  40. package/dist/shared/validation/artifact-check.js +64 -0
  41. package/dist/shared/validation/slug-check.js +22 -0
  42. package/dist-frontend/assets/index-Bah6k-Ix.css +32 -0
  43. package/dist-frontend/assets/index-EMaQuIB6.js +58 -0
  44. package/dist-frontend/index.html +13 -0
  45. package/docs/cc-best-practices.md +2142 -0
  46. package/docs/product-design.md +1597 -0
  47. package/docs/v1-architecture-design.md +1431 -0
  48. package/docs/v1-implementation-plan.md +1949 -0
  49. package/docs/v1-message-bus-orchestration-design.md +534 -0
  50. package/package.json +60 -0
  51. package/scripts/clean-build.mjs +12 -0
  52. package/scripts/fix-node-pty-spawn-helper.mjs +31 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # VibeCodingMaster
2
+
3
+ VibeCodingMaster is a local GUI workspace for managing multiple Claude Code role sessions around one engineering task.
4
+
5
+ It is designed for long-running coding work where one Claude Code conversation is not enough. VCM gives the user a task workspace with four role sessions:
6
+
7
+ - `project-manager`
8
+ - `architect`
9
+ - `coder`
10
+ - `reviewer`
11
+
12
+ Each role runs as a real Claude Code process inside an embedded terminal. The GUI lets the user start, stop, resume, switch, inspect, and manually intervene in those sessions without juggling several terminal windows.
13
+
14
+ ## What It Does
15
+
16
+ ```text
17
+ Open local GUI
18
+ -> connect a Git repository
19
+ -> create a task
20
+ -> start Claude Code role sessions
21
+ -> talk to Claude Code through embedded terminals
22
+ -> let project-manager coordinate architect / coder / reviewer
23
+ -> approve or automate role-to-role messages
24
+ -> resume interrupted role sessions later
25
+ ```
26
+
27
+ Current V1 capabilities:
28
+
29
+ - GUI-first task workspace.
30
+ - Embedded Claude Code terminals powered by `node-pty`.
31
+ - One Claude Code session per role.
32
+ - Role session recovery with persisted Claude session ids and `claude --resume`.
33
+ - Permission mode selection before start/restart:
34
+ - default
35
+ - `bypassPermissions`
36
+ - `--dangerously-skip-permissions`
37
+ - PM-mediated role messaging through `vcmctl`.
38
+ - Manual and automatic orchestration modes.
39
+ - Durable task state, session state, raw logs, handoff artifacts, and message history.
40
+
41
+ ## Requirements
42
+
43
+ - Node.js 20+.
44
+ - npm.
45
+ - Git.
46
+ - Claude Code installed and available as `claude` in the runtime environment.
47
+ - For Linux containers, native build/runtime basics for `node-pty`, usually:
48
+
49
+ ```bash
50
+ python3 make g++ git bash
51
+ ```
52
+
53
+ ## Install
54
+
55
+ ```bash
56
+ npm install
57
+ ```
58
+
59
+ ## Run Locally
60
+
61
+ Development mode:
62
+
63
+ ```bash
64
+ npm run dev
65
+ ```
66
+
67
+ Open the Vite GUI:
68
+
69
+ ```text
70
+ http://127.0.0.1:5173/
71
+ ```
72
+
73
+ The backend runs at:
74
+
75
+ ```text
76
+ http://127.0.0.1:4173/
77
+ ```
78
+
79
+ If `5173` is already in use, Vite may choose another frontend port and print it in the terminal.
80
+
81
+ Production-style local run:
82
+
83
+ ```bash
84
+ npm run build
85
+ npm start
86
+ ```
87
+
88
+ Then open:
89
+
90
+ ```text
91
+ http://127.0.0.1:4173/
92
+ ```
93
+
94
+ ## Run In VS Code Dev Containers
95
+
96
+ VCM works well inside a VS Code `devContainer` as long as VCM, Claude Code, and the target repository are all inside the same container filesystem.
97
+
98
+ Add port forwarding to `.devcontainer/devcontainer.json`:
99
+
100
+ ```json
101
+ {
102
+ "forwardPorts": [4173, 5173],
103
+ "portsAttributes": {
104
+ "4173": {
105
+ "label": "VCM backend / production UI"
106
+ },
107
+ "5173": {
108
+ "label": "VCM dev UI"
109
+ }
110
+ }
111
+ }
112
+ ```
113
+
114
+ Use:
115
+
116
+ ```bash
117
+ npm install
118
+ npm run dev
119
+ ```
120
+
121
+ Open the forwarded `5173` port for development mode. If you run `npm run build && npm start`, only `4173` is required.
122
+
123
+ Important container notes:
124
+
125
+ - Install Claude Code inside the container, or make the `claude` command available in the container PATH.
126
+ - Make sure Claude Code authentication works inside the container.
127
+ - Make sure the container has network access to Claude services.
128
+ - Keep the user project, `.vcm`, and `.ai/handoffs` on the same mounted workspace so paths are consistent.
129
+ - Treat the container as the sandbox boundary, especially when using relaxed Claude Code permission modes.
130
+
131
+ ## Basic Usage
132
+
133
+ 1. Start VCM.
134
+ 2. Open the GUI.
135
+ 3. Connect a Git repository.
136
+ 4. Create a task.
137
+ 5. Select a role tab.
138
+ 6. Choose the Claude Code permission mode for that role.
139
+ 7. Click `Start`.
140
+ 8. Talk to `project-manager` first.
141
+ 9. Let PM delegate to `architect`, `coder`, or `reviewer`.
142
+ 10. Inspect and approve role messages in the `Messages` panel.
143
+
144
+ The recommended flow is to mostly talk to `project-manager`. The PM role should coordinate the other roles through VCM messaging instead of asking the user to copy prompts between terminals.
145
+
146
+ ## Message Bus
147
+
148
+ The message bus is API-driven. VCM does not watch files to trigger role messages.
149
+
150
+ Role communication works like this:
151
+
152
+ ```text
153
+ Claude Code role
154
+ -> runs vcmctl send / vcmctl reply
155
+ -> vcmctl calls VCM backend API
156
+ -> backend validates policy and persists the message
157
+ -> backend writes to the target embedded terminal when allowed
158
+ ```
159
+
160
+ Examples that roles can run inside their terminal:
161
+
162
+ ```bash
163
+ vcmctl send --to coder --type task --body-file /tmp/message.md
164
+ vcmctl reply --type blocked --body "Need clarification."
165
+ vcmctl result --body-file /tmp/result.md --artifact .ai/handoffs/task/implementation-log.md
166
+ vcmctl inbox
167
+ ```
168
+
169
+ Files are still used for durability and auditability:
170
+
171
+ ```text
172
+ .vcm/messages/<task>.jsonl
173
+ .vcm/orchestration/<task>.json
174
+ .ai/handoffs/<task>/messages/<message-id>.md
175
+ .ai/handoffs/<task>/role-commands/
176
+ .ai/handoffs/<task>/logs/
177
+ ```
178
+
179
+ ## Orchestration Modes
180
+
181
+ VCM has a task-level `Auto orchestration` switch.
182
+
183
+ When it is off, VCM is in manual mode:
184
+
185
+ - Roles may send messages through `vcmctl`.
186
+ - Messages appear in the GUI.
187
+ - The user can inspect them.
188
+ - Clicking `Stage` writes the message prompt into the target embedded terminal input line.
189
+ - VCM does not press Enter for the user.
190
+
191
+ When it is on, VCM is in auto mode:
192
+
193
+ - Backend policy still applies.
194
+ - PM can send work to `architect`, `coder`, or `reviewer`.
195
+ - Non-PM roles can reply only to `project-manager`.
196
+ - If the target role session is running and orchestration is not paused, VCM can deliver the message directly to the target terminal.
197
+
198
+ High-risk work should still stop for human review.
199
+
200
+ ## Resume Behavior
201
+
202
+ Each role session stores a Claude session id under `.vcm/sessions`. If VCM exits or a task is interrupted, reopen the task and use `Resume` for the role. VCM starts Claude Code with `claude --resume <session-id>` where supported by Claude Code.
203
+
204
+ ## Validation
205
+
206
+ ```bash
207
+ npm run typecheck
208
+ npm test
209
+ npm run build
210
+ ```
211
+
212
+ ## Current Boundaries
213
+
214
+ - VCM does not use tmux.
215
+ - VCM does not auto-confirm Claude Code permission prompts.
216
+ - VCM does not deeply parse Claude Code output.
217
+ - VCM does not isolate roles with separate worktrees in V1.
218
+ - File writes still happen in the connected repository environment.
219
+ - The safest sandbox today is a container or VM boundary controlled by the user.
220
+
221
+ See also:
222
+
223
+ - `docs/product-design.md`
224
+ - `docs/v1-architecture-design.md`
225
+ - `docs/v1-implementation-plan.md`
226
+ - `docs/v1-message-bus-orchestration-design.md`
@@ -0,0 +1,38 @@
1
+ import { VcmError } from "../errors.js";
2
+ export function createClaudeAdapter(runner) {
3
+ return {
4
+ async isAvailable(command = "claude") {
5
+ const result = await runner.run(command, ["--version"]);
6
+ return result.exitCode === 0;
7
+ },
8
+ async getVersion(command = "claude") {
9
+ const result = await runner.run(command, ["--version"]);
10
+ if (result.exitCode !== 0) {
11
+ throw new VcmError({
12
+ code: "CLAUDE_UNAVAILABLE",
13
+ message: `Claude Code command is not available: ${command}`,
14
+ statusCode: 400,
15
+ hint: "Install Claude Code or configure a valid claude command path."
16
+ });
17
+ }
18
+ return result.stdout.trim();
19
+ },
20
+ buildRoleStartCommand(role, command = "claude", permissionMode = "default", claudeSessionId, resume = false) {
21
+ const args = ["--agent", role];
22
+ if (claudeSessionId) {
23
+ args.push(resume ? "--resume" : "--session-id", claudeSessionId);
24
+ }
25
+ if (permissionMode === "bypassPermissions") {
26
+ args.push("--permission-mode", "bypassPermissions");
27
+ }
28
+ else if (permissionMode === "dangerously-skip-permissions") {
29
+ args.push("--dangerously-skip-permissions");
30
+ }
31
+ return {
32
+ command,
33
+ args,
34
+ display: `${command} ${args.join(" ")}`
35
+ };
36
+ }
37
+ };
38
+ }
@@ -0,0 +1,33 @@
1
+ import { execa } from "execa";
2
+ export function createCommandRunner() {
3
+ return {
4
+ async run(command, args = [], options = {}) {
5
+ try {
6
+ const result = await execa(command, args, {
7
+ cwd: options.cwd,
8
+ env: options.env,
9
+ reject: false
10
+ });
11
+ return {
12
+ stdout: result.stdout,
13
+ stderr: result.stderr,
14
+ exitCode: result.exitCode ?? 0
15
+ };
16
+ }
17
+ catch (error) {
18
+ if (error instanceof Error) {
19
+ return {
20
+ stdout: "",
21
+ stderr: error.message,
22
+ exitCode: 1
23
+ };
24
+ }
25
+ return {
26
+ stdout: "",
27
+ stderr: "Unknown command error",
28
+ exitCode: 1
29
+ };
30
+ }
31
+ }
32
+ };
33
+ }
@@ -0,0 +1,60 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ export function createNodeFileSystemAdapter() {
4
+ return {
5
+ async pathExists(targetPath) {
6
+ try {
7
+ await fs.access(targetPath);
8
+ return true;
9
+ }
10
+ catch {
11
+ return false;
12
+ }
13
+ },
14
+ async ensureDir(targetPath) {
15
+ await fs.mkdir(targetPath, { recursive: true });
16
+ },
17
+ async readDir(targetPath) {
18
+ return fs.readdir(targetPath);
19
+ },
20
+ async readText(targetPath) {
21
+ return fs.readFile(targetPath, "utf8");
22
+ },
23
+ async writeText(targetPath, content) {
24
+ await fs.mkdir(path.dirname(targetPath), { recursive: true });
25
+ await fs.writeFile(targetPath, content, "utf8");
26
+ },
27
+ async appendText(targetPath, content) {
28
+ await fs.mkdir(path.dirname(targetPath), { recursive: true });
29
+ await fs.appendFile(targetPath, content, "utf8");
30
+ },
31
+ async readJson(targetPath) {
32
+ return JSON.parse(await fs.readFile(targetPath, "utf8"));
33
+ },
34
+ async writeJson(targetPath, value) {
35
+ await this.writeText(targetPath, `${JSON.stringify(value, null, 2)}\n`);
36
+ },
37
+ async writeJsonAtomic(targetPath, value) {
38
+ await fs.mkdir(path.dirname(targetPath), { recursive: true });
39
+ const tempPath = `${targetPath}.${process.pid}.tmp`;
40
+ await fs.writeFile(tempPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
41
+ await fs.rename(tempPath, targetPath);
42
+ },
43
+ async ensureFile(targetPath, content, options = {}) {
44
+ if (!options.overwrite && await this.pathExists(targetPath)) {
45
+ return false;
46
+ }
47
+ await this.writeText(targetPath, content);
48
+ return true;
49
+ }
50
+ };
51
+ }
52
+ export function resolveRepoPath(repoRoot, repoRelativePath) {
53
+ if (path.isAbsolute(repoRelativePath)) {
54
+ return repoRelativePath;
55
+ }
56
+ return path.resolve(repoRoot, repoRelativePath);
57
+ }
58
+ export function toRepoRelativePath(repoRoot, absolutePath) {
59
+ return path.relative(repoRoot, absolutePath).split(path.sep).join(path.posix.sep);
60
+ }
@@ -0,0 +1,33 @@
1
+ import { VcmError } from "../errors.js";
2
+ export function createGitAdapter(runner) {
3
+ return {
4
+ async isRepo(repoRoot) {
5
+ const result = await runner.run("git", ["rev-parse", "--is-inside-work-tree"], { cwd: repoRoot });
6
+ return result.exitCode === 0 && result.stdout.trim() === "true";
7
+ },
8
+ async getCurrentBranch(repoRoot) {
9
+ const result = await runner.run("git", ["branch", "--show-current"], { cwd: repoRoot });
10
+ if (result.exitCode !== 0) {
11
+ throw new VcmError({
12
+ code: "GIT_ERROR",
13
+ message: "Unable to read current Git branch.",
14
+ statusCode: 400,
15
+ hint: result.stderr
16
+ });
17
+ }
18
+ return result.stdout.trim() || "detached";
19
+ },
20
+ async isDirty(repoRoot) {
21
+ const result = await runner.run("git", ["status", "--porcelain"], { cwd: repoRoot });
22
+ if (result.exitCode !== 0) {
23
+ throw new VcmError({
24
+ code: "GIT_ERROR",
25
+ message: "Unable to read Git status.",
26
+ statusCode: 400,
27
+ hint: result.stderr
28
+ });
29
+ }
30
+ return result.stdout.trim().length > 0;
31
+ }
32
+ };
33
+ }