golutra-mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.example ADDED
@@ -0,0 +1,14 @@
1
+ # Optional. If unset, mcp-golutra first tries the macOS app-bundled CLI path
2
+ # and then falls back to resolving `golutra-cli` from PATH.
3
+ GOLUTRA_CLI_PATH=golutra-cli
4
+ GOLUTRA_PROFILE=stable
5
+ GOLUTRA_WORKSPACE_PATH=/absolute/path/to/workspace
6
+ GOLUTRA_COMMAND_TIMEOUT_MS=30000
7
+
8
+ # Optional end-to-end smoke test inputs for `npm run test:e2e`.
9
+ GOLUTRA_E2E_CLI_PATH=/absolute/path/to/golutra-cli
10
+ GOLUTRA_E2E_WORKSPACE_PATH=/absolute/path/to/workspace
11
+ GOLUTRA_E2E_PROFILE=stable
12
+ # Optional. When set, the smoke test also verifies the app-backed
13
+ # `chat.conversations.list` probe through `golutra-diagnose`.
14
+ GOLUTRA_E2E_USER_ID=
package/CHANGELOG.md ADDED
@@ -0,0 +1,32 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format follows Keep a Changelog, and this project uses Semantic Versioning.
6
+
7
+ ## [0.1.0] - 2026-03-17
8
+
9
+ ### Added
10
+
11
+ - Initial TypeScript `stdio` MCP server implementation
12
+ - Golutra chat, roadmap, and skill tools
13
+ - `golutra-set-context` and `golutra-get-context` for default runtime settings
14
+ - `golutra-reset-context` and `golutra-diagnose` for runtime troubleshooting
15
+ - ESLint, TypeScript, and Vitest based quality gates
16
+ - CI workflow, contribution guide, security policy, and code of conduct
17
+ - Dedicated `startup_processmd.md` for setup/start/build/validation flow
18
+
19
+ ### Changed
20
+
21
+ - Fixed `golutra-list-skills` so it now inherits the stored `workspacePath` from `golutra-set-context`, keeping skill discovery behavior consistent with the other workspace-aware tools
22
+ - Added `npm run test:e2e`, a real stdio MCP smoke test for the `golutra-mcp -> golutra-cli` path, with optional app-backed verification through `golutra-diagnose`
23
+ - Added `.github/workflows/e2e-self-hosted.yml` so maintainers can run the same smoke test on a macOS self-hosted runner before release
24
+ - Re-generated `package-lock.json` against the official npm registry and added public package metadata for repository, homepage, bugs, and author fields
25
+ - Split README startup guidance into a safer “try from source first, then install globally” flow for public users
26
+ - Replaced the project license from MIT to Apache-2.0 for clearer patent and redistribution terms
27
+ - Started tracking the built `dist/` output so GitHub source archives also include runnable server files instead of documentation only
28
+ - Switched the user-facing default profile examples from `dev` to `stable` so published usage aligns with the release app instead of development builds
29
+ - Reworked `README.md` into a project-introduction document focused on purpose, architecture, tool surface, and design boundaries
30
+ - Moved startup, environment, and local development instructions out of `README.md` into `startup_processmd.md`
31
+ - Replaced `README.md` again with a bilingual project-homepage version that explains what the project is, what it is today, and the future direction in English and Chinese
32
+ - Moved the remaining reference and operational material from `README.md` into `startup_processmd.md`
package/LICENSE ADDED
@@ -0,0 +1,184 @@
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, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and
27
+ configuration files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object
31
+ code, generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form,
34
+ made available under the License, as indicated by a copyright notice that is
35
+ included in or attached to the work (an example is provided in the Appendix
36
+ below).
37
+
38
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
39
+ is based on (or derived from) the Work and for which the editorial revisions,
40
+ annotations, elaborations, or other modifications represent, as a whole, an
41
+ original work of authorship. For the purposes of this License, Derivative Works
42
+ shall not include works that remain separable from, or merely link (or bind by
43
+ name) to the interfaces of, the Work and Derivative Works thereof.
44
+
45
+ "Contribution" shall mean any work of authorship, including the original
46
+ version of the Work and any modifications or additions to that Work or
47
+ Derivative Works thereof, that is intentionally submitted to Licensor for
48
+ inclusion in the Work by the copyright owner or by an individual or Legal
49
+ Entity authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal, or
51
+ written communication sent to the Licensor or its representatives, including
52
+ but not limited to communication on electronic mailing lists, source code
53
+ control systems, and issue tracking systems that are managed by, or on behalf
54
+ of, the Licensor for the purpose of discussing and improving the Work, but
55
+ excluding communication that is conspicuously marked or otherwise designated in
56
+ writing by the copyright owner as "Not a Contribution."
57
+
58
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
59
+ of whom a Contribution has been received by Licensor and subsequently
60
+ incorporated within the Work.
61
+
62
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
63
+ License, each Contributor hereby grants to You a perpetual, worldwide,
64
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
65
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
66
+ sublicense, and distribute the Work and such Derivative Works in Source or
67
+ Object form.
68
+
69
+ 3. Grant of Patent License. Subject to the terms and conditions of this
70
+ License, each Contributor hereby grants to You a perpetual, worldwide,
71
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
72
+ section) patent license to make, have made, use, offer to sell, sell, import,
73
+ and otherwise transfer the Work, where such license applies only to those
74
+ patent claims licensable by such Contributor that are necessarily infringed by
75
+ their Contribution(s) alone or by combination of their Contribution(s) with the
76
+ Work to which such Contribution(s) was submitted. If You institute patent
77
+ litigation against any entity (including a cross-claim or counterclaim in a
78
+ lawsuit) alleging that the Work or a Contribution incorporated within the Work
79
+ constitutes direct or contributory patent infringement, then any patent
80
+ licenses granted to You under this License for that Work shall terminate as of
81
+ the date such litigation is filed.
82
+
83
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
84
+ Derivative Works thereof in any medium, with or without modifications, and in
85
+ Source or Object form, provided that You meet the following conditions:
86
+
87
+ (a) You must give any other recipients of the Work or Derivative Works a copy
88
+ of this License; and
89
+
90
+ (b) You must cause any modified files to carry prominent notices stating that
91
+ You changed the files; and
92
+
93
+ (c) You must retain, in the Source form of any Derivative Works that You
94
+ distribute, all copyright, patent, trademark, and attribution notices from the
95
+ Source form of the Work, excluding those notices that do not pertain to any
96
+ part of the Derivative Works; and
97
+
98
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
99
+ any Derivative Works that You distribute must include a readable copy of the
100
+ attribution notices contained within such NOTICE file, excluding those notices
101
+ that do not pertain to any part of the Derivative Works, in at least one of the
102
+ following places: within a NOTICE text file distributed as part of the
103
+ Derivative Works; within the Source form or documentation, if provided along
104
+ with the Derivative Works; or, within a display generated by the Derivative
105
+ Works, if and wherever such third-party notices normally appear. The contents
106
+ of the NOTICE file are for informational purposes only and do not modify the
107
+ License. You may add Your own attribution notices within Derivative Works that
108
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+ provided that such additional attribution notices cannot be construed as
110
+ modifying the License.
111
+
112
+ You may add Your own copyright statement to Your modifications and may provide
113
+ additional or different license terms and conditions for use, reproduction, or
114
+ distribution of Your modifications, or for any such Derivative Works as a
115
+ whole, provided Your use, reproduction, and distribution of the Work otherwise
116
+ complies with the conditions stated in this License.
117
+
118
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
119
+ Contribution intentionally submitted for inclusion in the Work by You to the
120
+ Licensor shall be under the terms and conditions of this License, without any
121
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
122
+ supersede or modify the terms of any separate license agreement you may have
123
+ executed with Licensor regarding such Contributions.
124
+
125
+ 6. Trademarks. This License does not grant permission to use the trade names,
126
+ trademarks, service marks, or product names of the Licensor, except as required
127
+ for reasonable and customary use in describing the origin of the Work and
128
+ reproducing the content of the NOTICE file.
129
+
130
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
131
+ writing, Licensor provides the Work (and each Contributor provides its
132
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
133
+ KIND, either express or implied, including, without limitation, any warranties
134
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
135
+ PARTICULAR PURPOSE. You are solely responsible for determining the
136
+ appropriateness of using or redistributing the Work and assume any risks
137
+ associated with Your exercise of permissions under this License.
138
+
139
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
140
+ tort (including negligence), contract, or otherwise, unless required by
141
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
142
+ writing, shall any Contributor be liable to You for damages, including any
143
+ direct, indirect, special, incidental, or consequential damages of any
144
+ character arising as a result of this License or out of the use or inability to
145
+ use the Work (including but not limited to damages for loss of goodwill, work
146
+ stoppage, computer failure or malfunction, or any and all other commercial
147
+ damages or losses), even if such Contributor has been advised of the
148
+ possibility of such damages.
149
+
150
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
151
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
152
+ acceptance of support, warranty, indemnity, or other liability obligations
153
+ and/or rights consistent with this License. However, in accepting such
154
+ obligations, You may act only on Your own behalf and on Your sole
155
+ responsibility, not on behalf of any other Contributor, and only if You agree
156
+ to indemnify, defend, and hold each Contributor harmless for any liability
157
+ incurred by, or claims asserted against, such Contributor by reason of your
158
+ accepting any such warranty or additional liability.
159
+
160
+ END OF TERMS AND CONDITIONS
161
+
162
+ APPENDIX: How to apply the Apache License to your work.
163
+
164
+ To apply the Apache License to your work, attach the following boilerplate
165
+ notice, with the fields enclosed by brackets "[]" replaced with your own
166
+ identifying information. (Don't include the brackets!) The text should be
167
+ enclosed in the appropriate comment syntax for the file format. We also
168
+ recommend that a file or class name and description of purpose be included on
169
+ the same "printed page" as the copyright notice for easier identification
170
+ within third-party archives.
171
+
172
+ Copyright 2026 Golutra Contributors
173
+
174
+ Licensed under the Apache License, Version 2.0 (the "License");
175
+ you may not use this file except in compliance with the License.
176
+ You may obtain a copy of the License at
177
+
178
+ http://www.apache.org/licenses/LICENSE-2.0
179
+
180
+ Unless required by applicable law or agreed to in writing, software
181
+ distributed under the License is distributed on an "AS IS" BASIS,
182
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183
+ See the License for the specific language governing permissions and
184
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # golutra-mcp
2
+
3
+ `golutra-mcp` is an MCP bridge project for Golutra.
4
+
5
+ `golutra-mcp` 是一个面向 Golutra 的 MCP 桥接项目。
6
+
7
+ ## English
8
+
9
+ ### What This Project Is
10
+
11
+ `golutra-mcp` is a Model Context Protocol server that exposes Golutra collaboration capabilities to MCP-compatible hosts through `golutra-cli`.
12
+
13
+ It is not a replacement for Golutra itself, and it does not re-implement Golutra's local IPC protocol. Instead, it acts as a thin integration layer that lets external MCP clients reuse Golutra's existing chat, roadmap, and skill flows through a smaller and more stable boundary.
14
+
15
+ ### What It Is Today
16
+
17
+ The current project is a usable engineering preview, not yet a fully mature public integration product.
18
+
19
+ Today it already provides:
20
+
21
+ - a local `stdio` MCP server
22
+ - a command bridge based on `golutra-cli`
23
+ - tool coverage for chat, roadmap, context, diagnostics, and skill discovery
24
+ - skill validation and direct project `SKILL.md` reading for local Golutra skill workflows
25
+ - an open-source project skeleton with contribution, security, CI, and release-facing metadata
26
+
27
+ At the current stage, the project should be understood as a focused integration layer that can already be downloaded and evaluated, but still needs broader real-world validation before it should be treated as a fully mature public MCP distribution.
28
+
29
+ ### Why It Exists
30
+
31
+ The goal is to let MCP hosts talk to Golutra without forcing them to understand Golutra internals.
32
+
33
+ That means this repository is mainly responsible for:
34
+
35
+ - protocol translation
36
+ - runtime context management
37
+ - safe command wrapping
38
+ - diagnostics and integration ergonomics
39
+
40
+ ### Future Direction
41
+
42
+ The next stages should move the project from "basic bridge" to "usable integration product."
43
+
44
+ Likely future work includes:
45
+
46
+ - richer typed result models instead of mostly pass-through payloads
47
+ - stronger health checks and diagnostics for CLI, profile, workspace, and app status
48
+ - clearer MCP resource/prompt support in addition to tool calls
49
+ - better packaging and publish flow once dependency install and build are stable in target environments
50
+ - tighter documentation around real Golutra collaboration workflows
51
+ - stronger release hardening across installation paths, packaging validation, and end-to-end compatibility checks
52
+
53
+ ### Getting Started
54
+
55
+ Try from source first:
56
+
57
+ ```bash
58
+ npm install
59
+ export GOLUTRA_CLI_PATH=/absolute/path/to/golutra-cli
60
+ export GOLUTRA_PROFILE=stable
61
+ export GOLUTRA_WORKSPACE_PATH=/absolute/path/to/workspace
62
+ npm run dev
63
+ ```
64
+
65
+ Use the npm package after you are ready to consume it as a normal MCP server distribution:
66
+
67
+ ```bash
68
+ npm install -g golutra-mcp
69
+ export GOLUTRA_CLI_PATH=/absolute/path/to/golutra-cli
70
+ export GOLUTRA_PROFILE=stable
71
+ export GOLUTRA_WORKSPACE_PATH=/absolute/path/to/workspace
72
+ golutra-mcp
73
+ ```
74
+
75
+ Detailed startup, validation, and client wiring instructions live in `startup_processmd.md`.
76
+
77
+ ## 中文
78
+
79
+ ### 这是什么项目
80
+
81
+ `golutra-mcp` 是一个把 Golutra 能力暴露给 MCP 客户端的桥接层,底层通过 `golutra-cli` 与 Golutra 桌面端联通。
82
+
83
+ 它不是 Golutra 本体,也不是对 Golutra 本地 IPC 协议的重写。这个仓库的职责,是把外部 MCP Host 和 Golutra 之间的集成边界收敛成一层更小、更稳定、更容易复用的适配层。
84
+
85
+ ### 当前阶段是什么
86
+
87
+ 当前这个项目已经进入“可下载试用的工程化预发布”阶段,但还不能算“完全成熟、长期稳定的公共 MCP 成品”。
88
+
89
+ 现阶段已经具备:
90
+
91
+ - 基于 `stdio` 的 MCP Server 形态
92
+ - 基于 `golutra-cli` 的命令桥接
93
+ - chat、roadmap、context、diagnostics、skills 这些基础工具面
94
+ - 技能校验与项目 `SKILL.md` 直接读取能力,能覆盖本地技能开发链路
95
+ - 基本完整的开源项目骨架,包括贡献规范、安全策略、CI 和发布元数据
96
+
97
+ 但它现在还不是一个“已经经过广泛真实场景验证的完整 Golutra 远程集成产品”,更准确的定位是:一个已经能下载试用、也具备基本发布骨架的 MCP 集成底座。
98
+
99
+ ### 这个项目解决什么问题
100
+
101
+ 这个项目的目标,是让支持 MCP 的宿主可以接入 Golutra,而不需要理解 Golutra 内部的本地 IPC 细节。
102
+
103
+ 因此,这个仓库重点负责的是:
104
+
105
+ - 协议转换
106
+ - 运行时上下文管理
107
+ - 对现有 CLI 能力的稳定封装
108
+ - 联通诊断与集成体验
109
+
110
+ ### 后续规划
111
+
112
+ 后续项目应该从“能桥接”继续推进到“更好用、可发布、可维护”。
113
+
114
+ 比较明确的方向包括:
115
+
116
+ - 把当前偏透传的结果结构进一步做强类型化
117
+ - 增强 CLI / profile / workspace / app 状态诊断
118
+ - 在 tool 之外补充更完整的 MCP resources / prompts 能力
119
+ - 把打包、安装、发布链路收敛到更稳定的状态
120
+ - 补齐围绕真实 Golutra 协作场景的文档和示例
121
+ - 继续补强跨平台安装路径、自诊断、端到端兼容性验证
122
+
123
+ ### 开始使用
124
+
125
+ 建议先从源码试用:
126
+
127
+ ```bash
128
+ npm install
129
+ export GOLUTRA_CLI_PATH=/absolute/path/to/golutra-cli
130
+ export GOLUTRA_PROFILE=stable
131
+ export GOLUTRA_WORKSPACE_PATH=/absolute/path/to/workspace
132
+ npm run dev
133
+ ```
134
+
135
+ 确认链路符合预期后,再按普通 MCP 包的方式安装:
136
+
137
+ ```bash
138
+ npm install -g golutra-mcp
139
+ export GOLUTRA_CLI_PATH=/absolute/path/to/golutra-cli
140
+ export GOLUTRA_PROFILE=stable
141
+ export GOLUTRA_WORKSPACE_PATH=/absolute/path/to/workspace
142
+ golutra-mcp
143
+ ```
144
+
145
+ 更完整的启动、验证与客户端接入说明见 `startup_processmd.md`。
146
+
147
+ ## Documentation
148
+
149
+ - Startup, installation, validation, and MCP client wiring:
150
+ [startup_processmd.md](./startup_processmd.md)
151
+ - Contribution guide:
152
+ [CONTRIBUTING.md](./CONTRIBUTING.md)
153
+ - Security policy:
154
+ [SECURITY.md](./SECURITY.md)
155
+ - Change history:
156
+ [CHANGELOG.md](./CHANGELOG.md)
157
+ - License:
158
+ [LICENSE](./LICENSE)
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { NodeCliJsonRunner } from "./lib/cli-runner.js";
5
+ import { ContextStore, createInitialContext } from "./lib/context.js";
6
+ import { GolutraCliGateway } from "./lib/golutra-client.js";
7
+ import { registerTools } from "./lib/toolkit.js";
8
+ const SERVER_NAME = "golutra-mcp";
9
+ const SERVER_VERSION = "0.1.0";
10
+ async function main() {
11
+ const server = new McpServer({
12
+ name: SERVER_NAME,
13
+ version: SERVER_VERSION
14
+ });
15
+ const contextStore = new ContextStore(createInitialContext(process.env));
16
+ const gateway = new GolutraCliGateway(new NodeCliJsonRunner());
17
+ // 设计原因:MCP 侧只暴露稳定工具面,不直接泄漏 golutra-cli/IPC 的内部细节。
18
+ registerTools(server, contextStore, gateway);
19
+ const transport = new StdioServerTransport();
20
+ await server.connect(transport);
21
+ const shutdown = async () => {
22
+ await server.close();
23
+ process.exit(0);
24
+ };
25
+ process.on("SIGINT", () => {
26
+ void shutdown();
27
+ });
28
+ process.on("SIGTERM", () => {
29
+ void shutdown();
30
+ });
31
+ }
32
+ main().catch((error) => {
33
+ const message = error instanceof Error ? error.stack ?? error.message : String(error);
34
+ process.stderr.write(`${SERVER_NAME} failed to start\n${message}\n`);
35
+ process.exit(1);
36
+ });
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,cAAc;KACxB,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,oBAAoB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,IAAI,iBAAiB,CAAC,IAAI,iBAAiB,EAAE,CAAC,CAAC;IAE/D,kDAAkD;IAClD,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IAE7C,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhC,MAAM,QAAQ,GAAG,KAAK,IAAmB,EAAE;QACzC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACxB,KAAK,QAAQ,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;QACzB,KAAK,QAAQ,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACtF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,WAAW,qBAAqB,OAAO,IAAI,CAAC,CAAC;IACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { CliCommandRequest } from "./types.js";
2
+ export interface CliJsonRunner {
3
+ executeJson<T>(request: CliCommandRequest): Promise<T>;
4
+ }
5
+ export declare class NodeCliJsonRunner implements CliJsonRunner {
6
+ executeJson<T>(request: CliCommandRequest): Promise<T>;
7
+ }
@@ -0,0 +1,107 @@
1
+ import { spawn } from "node:child_process";
2
+ import { CliExecutionError } from "./errors.js";
3
+ function formatCommand(request) {
4
+ return [request.cliPath, ...request.args].join(" ");
5
+ }
6
+ function extractErrorMessage(parsed) {
7
+ if (!parsed || typeof parsed !== "object") {
8
+ return undefined;
9
+ }
10
+ if ("error" in parsed && typeof parsed.error === "string") {
11
+ return parsed.error;
12
+ }
13
+ if ("result" in parsed &&
14
+ parsed.result &&
15
+ typeof parsed.result === "object" &&
16
+ "message" in parsed.result &&
17
+ typeof parsed.result.message === "string") {
18
+ return parsed.result.message;
19
+ }
20
+ return undefined;
21
+ }
22
+ export class NodeCliJsonRunner {
23
+ async executeJson(request) {
24
+ const stdoutChunks = [];
25
+ const stderrChunks = [];
26
+ const child = spawn(request.cliPath, request.args, {
27
+ env: process.env,
28
+ stdio: ["ignore", "pipe", "pipe"]
29
+ });
30
+ child.stdout.setEncoding("utf8");
31
+ child.stderr.setEncoding("utf8");
32
+ child.stdout.on("data", (chunk) => stdoutChunks.push(chunk));
33
+ child.stderr.on("data", (chunk) => stderrChunks.push(chunk));
34
+ const completed = await new Promise((resolve, reject) => {
35
+ const timer = setTimeout(() => {
36
+ child.kill("SIGTERM");
37
+ reject(new CliExecutionError({
38
+ message: `golutra-cli timed out after ${request.timeoutMs}ms`,
39
+ cliPath: request.cliPath,
40
+ args: request.args,
41
+ exitCode: null,
42
+ stdout: stdoutChunks.join(""),
43
+ stderr: stderrChunks.join("")
44
+ }));
45
+ }, request.timeoutMs);
46
+ child.once("error", (error) => {
47
+ clearTimeout(timer);
48
+ reject(new CliExecutionError({
49
+ message: `failed to start golutra-cli: ${error.message}`,
50
+ cliPath: request.cliPath,
51
+ args: request.args,
52
+ exitCode: null,
53
+ stdout: stdoutChunks.join(""),
54
+ stderr: stderrChunks.join("")
55
+ }));
56
+ });
57
+ child.once("close", (exitCode) => {
58
+ clearTimeout(timer);
59
+ resolve({
60
+ exitCode,
61
+ stdout: stdoutChunks.join(""),
62
+ stderr: stderrChunks.join("")
63
+ });
64
+ });
65
+ });
66
+ const trimmedStdout = completed.stdout.trim();
67
+ if (!trimmedStdout) {
68
+ throw new CliExecutionError({
69
+ message: completed.stderr.trim() ||
70
+ `golutra-cli returned no JSON output: ${formatCommand(request)}`,
71
+ cliPath: request.cliPath,
72
+ args: request.args,
73
+ exitCode: completed.exitCode,
74
+ stdout: completed.stdout,
75
+ stderr: completed.stderr
76
+ });
77
+ }
78
+ let parsed;
79
+ try {
80
+ parsed = JSON.parse(trimmedStdout);
81
+ }
82
+ catch (error) {
83
+ throw new CliExecutionError({
84
+ message: `golutra-cli returned invalid JSON: ${error instanceof Error ? error.message : String(error)}`,
85
+ cliPath: request.cliPath,
86
+ args: request.args,
87
+ exitCode: completed.exitCode,
88
+ stdout: completed.stdout,
89
+ stderr: completed.stderr
90
+ });
91
+ }
92
+ if (completed.exitCode !== 0) {
93
+ throw new CliExecutionError({
94
+ message: extractErrorMessage(parsed) ??
95
+ completed.stderr.trim() ??
96
+ `golutra-cli exited with code ${completed.exitCode}`,
97
+ cliPath: request.cliPath,
98
+ args: request.args,
99
+ exitCode: completed.exitCode,
100
+ stdout: completed.stdout,
101
+ stderr: completed.stderr
102
+ });
103
+ }
104
+ return parsed;
105
+ }
106
+ }
107
+ //# sourceMappingURL=cli-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-runner.js","sourceRoot":"","sources":["../../src/lib/cli-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAOhD,SAAS,aAAa,CAAC,OAA0B;IAC/C,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAe;IAC1C,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,OAAO,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC1D,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;IACD,IACE,QAAQ,IAAI,MAAM;QAClB,MAAM,CAAC,MAAM;QACb,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;QACjC,SAAS,IAAI,MAAM,CAAC,MAAM;QAC1B,OAAO,MAAM,CAAC,MAAM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shot } from "./types.js";
2
+ export declare function resolveDefaultCliPath(env: NodeJS.ProcessEnv, options?: {
3
+ platform?: NodeJS.Platform;
4
+ homeDirectory?: string;
5
+ pathExists?: (candidatePath: string) => boolean;
6
+ }): string;
7
+ export declare function createInitialContext(env: NodeJS.ProcessEnv): RuntimeContextSnapshot;
8
+ export declare class ContextStore {
9
+ private readonly initialContext;
10
+ private context;
11
+ constructor(initialContext: RuntimeContextSnapshot);
12
+ getSnapshot(): RuntimeContextSnapshot;
13
+ reset(): RuntimeContextSnapshot;
14
+ update(nextValues: CommandContextInput): RuntimeContextSnapshot;
15
+ resolveCommandContext(nextValues?: CommandContextInput): RuntimeContextSnapshot;
16
+ requireWorkspacePath(nextValues?: CommandContextInput): string;
17
+ }