ralph-cli-sandboxed 0.6.6 → 0.7.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.
- package/LICENSE +191 -0
- package/README.md +22 -2
- package/dist/commands/ask.d.ts +6 -0
- package/dist/commands/ask.js +140 -0
- package/dist/commands/branch.js +8 -4
- package/dist/commands/chat.js +11 -8
- package/dist/commands/docker.js +104 -17
- package/dist/commands/fix-config.js +0 -41
- package/dist/commands/help.js +10 -0
- package/dist/commands/run.js +17 -13
- package/dist/config/languages.json +2 -1
- package/dist/config/responder-presets.json +10 -0
- package/dist/config/skills.json +8 -0
- package/dist/index.js +2 -0
- package/dist/mcp-server.d.ts +2 -0
- package/dist/mcp-server.js +366 -0
- package/dist/providers/telegram.js +1 -1
- package/dist/responders/claude-code-responder.js +24 -1
- package/dist/responders/cli-responder.js +1 -0
- package/dist/responders/llm-responder.js +1 -1
- package/dist/templates/macos-scripts.js +18 -18
- package/dist/templates/prompts.d.ts +1 -0
- package/dist/tui/components/JsonSnippetEditor.js +7 -7
- package/dist/tui/components/KeyValueEditor.js +5 -1
- package/dist/tui/components/LLMProvidersEditor.js +7 -9
- package/dist/tui/components/Preview.js +1 -1
- package/dist/tui/components/SectionNav.js +18 -2
- package/dist/utils/chat-client.js +1 -0
- package/dist/utils/config.d.ts +2 -0
- package/dist/utils/config.js +3 -1
- package/dist/utils/config.test.d.ts +1 -0
- package/dist/utils/config.test.js +424 -0
- package/dist/utils/notification.js +1 -1
- package/dist/utils/prd-validator.d.ts +1 -0
- package/dist/utils/prd-validator.js +32 -10
- package/dist/utils/prd-validator.test.d.ts +1 -0
- package/dist/utils/prd-validator.test.js +1095 -0
- package/dist/utils/responder-logger.d.ts +6 -5
- package/dist/utils/responder-presets.d.ts +1 -0
- package/dist/utils/responder-presets.js +2 -0
- package/dist/utils/responder.js +1 -1
- package/dist/utils/stream-json.test.d.ts +1 -0
- package/dist/utils/stream-json.test.js +1007 -0
- package/docs/DOCKER.md +14 -0
- package/docs/MCP.md +192 -0
- package/docs/PRD-GENERATOR.md +15 -0
- package/package.json +22 -18
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2024 Lars Gregori
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -518,9 +518,10 @@ ralph docker run
|
|
|
518
518
|
|
|
519
519
|
Features:
|
|
520
520
|
- Based on [Claude Code devcontainer](https://github.com/anthropics/claude-code/tree/main/.devcontainer)
|
|
521
|
-
- Network sandboxing (firewall allows only GitHub, npm, Anthropic API)
|
|
521
|
+
- Network sandboxing (firewall allows only GitHub, npm, Anthropic API, plus language-specific domains — e.g., `deno.land`, `jsr.io`, `esm.sh` for Deno projects)
|
|
522
522
|
- Your `~/.claude` credentials mounted automatically (Pro/Max OAuth)
|
|
523
523
|
- Language-specific tooling pre-installed
|
|
524
|
+
- Language-specific Claude Code hooks (e.g., Deno projects auto-install a `PreToolUse` hook that blocks `npm`/`npx`/`yarn`/`pnpm` commands)
|
|
524
525
|
|
|
525
526
|
See [docs/DOCKER.md](docs/DOCKER.md) for detailed Docker configuration, customization, and troubleshooting.
|
|
526
527
|
|
|
@@ -554,6 +555,25 @@ Responders handle messages and can answer questions about your codebase:
|
|
|
554
555
|
|
|
555
556
|
See [docs/CHAT-CLIENTS.md](docs/CHAT-CLIENTS.md) for chat platform setup and [docs/CHAT-RESPONDERS.md](docs/CHAT-RESPONDERS.md) for responder configuration.
|
|
556
557
|
|
|
558
|
+
## MCP Server
|
|
559
|
+
|
|
560
|
+
Ralph provides an [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) server that exposes PRD management as tools for AI assistants. This lets MCP-compatible clients like Claude Code list, add, toggle, and check the status of PRD entries directly through tool calls.
|
|
561
|
+
|
|
562
|
+
Add to your `.mcp.json`:
|
|
563
|
+
|
|
564
|
+
```json
|
|
565
|
+
{
|
|
566
|
+
"mcpServers": {
|
|
567
|
+
"ralph": {
|
|
568
|
+
"command": "ralph-mcp",
|
|
569
|
+
"args": []
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
See [docs/MCP.md](docs/MCP.md) for available tools, parameters, return values, and example conversations.
|
|
576
|
+
|
|
557
577
|
## How It Works
|
|
558
578
|
|
|
559
579
|
1. **Read PRD**: Claude reads your requirements from `prd.json`
|
|
@@ -594,4 +614,4 @@ See [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) for detailed development setup, p
|
|
|
594
614
|
|
|
595
615
|
## License
|
|
596
616
|
|
|
597
|
-
|
|
617
|
+
Apache-2.0 — see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { loadConfig } from "../utils/config.js";
|
|
2
|
+
import { loadResponderPresets, presetToResponderConfig } from "../utils/responder-presets.js";
|
|
3
|
+
import { executeLLMResponder } from "../responders/llm-responder.js";
|
|
4
|
+
import { executeClaudeCodeResponder } from "../responders/claude-code-responder.js";
|
|
5
|
+
import { executeCLIResponder } from "../responders/cli-responder.js";
|
|
6
|
+
/**
|
|
7
|
+
* Large maxLength override for CLI usage — users want the full response.
|
|
8
|
+
*/
|
|
9
|
+
const CLI_MAX_LENGTH = 100_000;
|
|
10
|
+
/**
|
|
11
|
+
* ralph ask <preset> <message...>
|
|
12
|
+
*
|
|
13
|
+
* Run a responder preset from the CLI and print the result to stdout.
|
|
14
|
+
*/
|
|
15
|
+
export async function ask(args) {
|
|
16
|
+
// Handle flags before positional args
|
|
17
|
+
if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
|
|
18
|
+
showHelp();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (args[0] === "--list" || args[0] === "-l") {
|
|
22
|
+
listPresets();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const name = args[0];
|
|
26
|
+
const message = args.slice(1).join(" ");
|
|
27
|
+
if (!message) {
|
|
28
|
+
console.error(`Error: No message provided.`);
|
|
29
|
+
console.error(`Usage: ralph ask <preset> <message...>`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
// Resolve responder config: config responders first, then built-in presets
|
|
33
|
+
const { responderConfig } = resolveResponder(name);
|
|
34
|
+
if (!responderConfig) {
|
|
35
|
+
console.error(`Error: Unknown responder "${name}".`);
|
|
36
|
+
console.error(`Run 'ralph ask --list' to see available presets.`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
// Override maxLength for CLI (no truncation)
|
|
40
|
+
const config = { ...responderConfig, maxLength: CLI_MAX_LENGTH };
|
|
41
|
+
// Execute based on type
|
|
42
|
+
const result = await executeResponder(config, message);
|
|
43
|
+
if (!result.success) {
|
|
44
|
+
console.error(`Error: ${result.error}`);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
console.log(result.response);
|
|
48
|
+
}
|
|
49
|
+
function resolveResponder(name) {
|
|
50
|
+
// 1. Check config responders first (user overrides)
|
|
51
|
+
try {
|
|
52
|
+
const ralphConfig = loadConfig();
|
|
53
|
+
const responders = ralphConfig.chat?.responders;
|
|
54
|
+
if (responders && responders[name]) {
|
|
55
|
+
return { responderConfig: responders[name], source: "config" };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Config not loaded — fall through to presets
|
|
60
|
+
}
|
|
61
|
+
// 2. Check built-in presets
|
|
62
|
+
const presetsConfig = loadResponderPresets();
|
|
63
|
+
const preset = presetsConfig.presets[name];
|
|
64
|
+
if (preset) {
|
|
65
|
+
return { responderConfig: presetToResponderConfig(preset), source: "preset" };
|
|
66
|
+
}
|
|
67
|
+
return { responderConfig: null, source: "preset" };
|
|
68
|
+
}
|
|
69
|
+
async function executeResponder(config, message) {
|
|
70
|
+
switch (config.type) {
|
|
71
|
+
case "llm":
|
|
72
|
+
return executeLLMResponder(message, config, undefined, {
|
|
73
|
+
responderName: "ask",
|
|
74
|
+
});
|
|
75
|
+
case "claude-code":
|
|
76
|
+
return executeClaudeCodeResponder(message, config, {
|
|
77
|
+
maxLength: config.maxLength,
|
|
78
|
+
});
|
|
79
|
+
case "cli":
|
|
80
|
+
return executeCLIResponder(message, config, {
|
|
81
|
+
maxLength: config.maxLength,
|
|
82
|
+
});
|
|
83
|
+
default:
|
|
84
|
+
return {
|
|
85
|
+
success: false,
|
|
86
|
+
response: "",
|
|
87
|
+
error: `Unsupported responder type: ${config.type}`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function listPresets() {
|
|
92
|
+
const presetsConfig = loadResponderPresets();
|
|
93
|
+
console.log("Built-in presets:");
|
|
94
|
+
for (const [id, preset] of Object.entries(presetsConfig.presets)) {
|
|
95
|
+
console.log(` ${id.padEnd(12)} ${preset.type.padEnd(14)} ${preset.description}`);
|
|
96
|
+
}
|
|
97
|
+
// Show config responders if available
|
|
98
|
+
try {
|
|
99
|
+
const ralphConfig = loadConfig();
|
|
100
|
+
const responders = ralphConfig.chat?.responders;
|
|
101
|
+
if (responders && Object.keys(responders).length > 0) {
|
|
102
|
+
console.log("\nConfigured responders:");
|
|
103
|
+
for (const [name, cfg] of Object.entries(responders)) {
|
|
104
|
+
console.log(` ${name.padEnd(12)} ${cfg.type.padEnd(14)} (from config.json)`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// No config — skip
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function showHelp() {
|
|
113
|
+
console.log(`
|
|
114
|
+
ralph ask - Run a responder preset from the CLI
|
|
115
|
+
|
|
116
|
+
USAGE:
|
|
117
|
+
ralph ask <preset> <message...>
|
|
118
|
+
ralph ask --list
|
|
119
|
+
ralph ask --help
|
|
120
|
+
|
|
121
|
+
OPTIONS:
|
|
122
|
+
-l, --list List available presets and configured responders
|
|
123
|
+
-h, --help Show this help message
|
|
124
|
+
|
|
125
|
+
DESCRIPTION:
|
|
126
|
+
Runs a responder preset (or custom responder from config) and prints
|
|
127
|
+
the result to stdout. This lets you use responder presets without
|
|
128
|
+
needing a chat provider set up.
|
|
129
|
+
|
|
130
|
+
Lookup priority: config responders first, then built-in presets.
|
|
131
|
+
|
|
132
|
+
EXAMPLES:
|
|
133
|
+
ralph ask qa "What does the config loader do?"
|
|
134
|
+
ralph ask reviewer diff
|
|
135
|
+
ralph ask architect "Should we split this into microservices?"
|
|
136
|
+
ralph ask explain src/utils/config.ts
|
|
137
|
+
ralph ask code "Add a --verbose flag to the run command"
|
|
138
|
+
ralph ask --list
|
|
139
|
+
`.trimEnd());
|
|
140
|
+
}
|
package/dist/commands/branch.js
CHANGED
|
@@ -163,7 +163,13 @@ async function branchMerge(args) {
|
|
|
163
163
|
const status = execSync("git status --porcelain", { encoding: "utf-8" });
|
|
164
164
|
conflictingFiles = status
|
|
165
165
|
.split("\n")
|
|
166
|
-
.filter((line) => line.startsWith("UU") ||
|
|
166
|
+
.filter((line) => line.startsWith("UU") ||
|
|
167
|
+
line.startsWith("AA") ||
|
|
168
|
+
line.startsWith("DD") ||
|
|
169
|
+
line.startsWith("AU") ||
|
|
170
|
+
line.startsWith("UA") ||
|
|
171
|
+
line.startsWith("DU") ||
|
|
172
|
+
line.startsWith("UD"))
|
|
167
173
|
.map((line) => line.substring(3).trim());
|
|
168
174
|
}
|
|
169
175
|
catch {
|
|
@@ -358,9 +364,7 @@ async function branchDelete(args) {
|
|
|
358
364
|
const hasWorktree = existsSync(worktreePath);
|
|
359
365
|
// Load PRD to check for tagged items
|
|
360
366
|
const result = loadPrdEntries();
|
|
361
|
-
const taggedCount = result
|
|
362
|
-
? result.entries.filter((e) => e.branch === branchName).length
|
|
363
|
-
: 0;
|
|
367
|
+
const taggedCount = result ? result.entries.filter((e) => e.branch === branchName).length : 0;
|
|
364
368
|
console.log(`Branch: ${branchName}`);
|
|
365
369
|
if (hasWorktree) {
|
|
366
370
|
console.log(`Worktree: ${worktreePath}`);
|
package/dist/commands/chat.js
CHANGED
|
@@ -7,7 +7,7 @@ import { join, basename, extname } from "path";
|
|
|
7
7
|
import { execSync, spawn } from "child_process";
|
|
8
8
|
import YAML from "yaml";
|
|
9
9
|
import { robustYamlParse } from "../utils/prd-validator.js";
|
|
10
|
-
import { loadConfig, getRalphDir, isRunningInContainer, getPrdFiles, loadBranchState, getProjectName as getConfigProjectName } from "../utils/config.js";
|
|
10
|
+
import { loadConfig, getRalphDir, isRunningInContainer, getPrdFiles, loadBranchState, getProjectName as getConfigProjectName, } from "../utils/config.js";
|
|
11
11
|
import { createTelegramClient } from "../providers/telegram.js";
|
|
12
12
|
import { createSlackClient } from "../providers/slack.js";
|
|
13
13
|
import { createDiscordClient } from "../providers/discord.js";
|
|
@@ -259,9 +259,7 @@ async function handleBranchList(chatId, client, state) {
|
|
|
259
259
|
async function handleBranchPr(args, chatId, client, state) {
|
|
260
260
|
const branchName = args[0];
|
|
261
261
|
if (!branchName) {
|
|
262
|
-
const usage = client.provider === "slack"
|
|
263
|
-
? "/ralph branch pr <branch-name>"
|
|
264
|
-
: "/branch pr <branch-name>";
|
|
262
|
+
const usage = client.provider === "slack" ? "/ralph branch pr <branch-name>" : "/branch pr <branch-name>";
|
|
265
263
|
await client.sendMessage(chatId, `${state.projectName}: Usage: ${usage}`);
|
|
266
264
|
return;
|
|
267
265
|
}
|
|
@@ -288,7 +286,9 @@ async function handleBranchPr(args, chatId, client, state) {
|
|
|
288
286
|
// Verify a git remote exists
|
|
289
287
|
let remote;
|
|
290
288
|
try {
|
|
291
|
-
remote = execSync("git remote", { encoding: "utf-8", cwd: process.cwd() })
|
|
289
|
+
remote = execSync("git remote", { encoding: "utf-8", cwd: process.cwd() })
|
|
290
|
+
.trim()
|
|
291
|
+
.split("\n")[0];
|
|
292
292
|
if (!remote)
|
|
293
293
|
throw new Error("no remote");
|
|
294
294
|
}
|
|
@@ -391,8 +391,12 @@ async function handleBranchMerge(args, chatId, client, state) {
|
|
|
391
391
|
const status = execSync("git status --porcelain", { encoding: "utf-8", cwd });
|
|
392
392
|
conflictingFiles = status
|
|
393
393
|
.split("\n")
|
|
394
|
-
.filter((line) => line.startsWith("UU") ||
|
|
395
|
-
line.startsWith("
|
|
394
|
+
.filter((line) => line.startsWith("UU") ||
|
|
395
|
+
line.startsWith("AA") ||
|
|
396
|
+
line.startsWith("DD") ||
|
|
397
|
+
line.startsWith("AU") ||
|
|
398
|
+
line.startsWith("UA") ||
|
|
399
|
+
line.startsWith("DU") ||
|
|
396
400
|
line.startsWith("UD"))
|
|
397
401
|
.map((line) => line.substring(3).trim());
|
|
398
402
|
}
|
|
@@ -742,7 +746,6 @@ async function handleCommand(command, client, config, state, debug) {
|
|
|
742
746
|
await client.sendMessage(chatId, `${state.projectName}: Usage: ${usage}`);
|
|
743
747
|
return;
|
|
744
748
|
}
|
|
745
|
-
const prompt = args.join(" ");
|
|
746
749
|
await client.sendMessage(chatId, `⏳ ${state.projectName}: Running Claude Code...\n(this may take a few minutes)`);
|
|
747
750
|
// Send claude command to sandbox with longer timeout (5 minutes)
|
|
748
751
|
const response = await sendToSandbox("claude", args, debug, 300000);
|
package/dist/commands/docker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, writeFileSync, readFileSync, mkdirSync, chmodSync, openSync } from "fs";
|
|
2
|
-
import { join, basename } from "path";
|
|
2
|
+
import { join, basename, normalize } from "path";
|
|
3
3
|
import { spawn } from "child_process";
|
|
4
4
|
import { createHash } from "crypto";
|
|
5
5
|
import { loadConfig, getRalphDir, } from "../utils/config.js";
|
|
@@ -373,6 +373,21 @@ function generateDockerCompose(imageName, dockerConfig) {
|
|
|
373
373
|
baseVolumes.push(" # Mount host worktrees directory for git worktree storage");
|
|
374
374
|
baseVolumes.push(` - ${dockerConfig.worktreesPath}:/worktrees`);
|
|
375
375
|
}
|
|
376
|
+
// Mount env file if configured (read-only)
|
|
377
|
+
// Validate envFile to prevent path traversal outside the project root
|
|
378
|
+
let sanitizedEnvFile;
|
|
379
|
+
if (dockerConfig?.envFile) {
|
|
380
|
+
const normalized = normalize(dockerConfig.envFile);
|
|
381
|
+
if (normalized.startsWith("/") ||
|
|
382
|
+
normalized.startsWith("..") ||
|
|
383
|
+
normalized.includes("/../") ||
|
|
384
|
+
normalized.includes("\\")) {
|
|
385
|
+
throw new Error(`Invalid envFile path "${dockerConfig.envFile}": must be a relative path within the project root (no "..", absolute paths, or backslashes).`);
|
|
386
|
+
}
|
|
387
|
+
sanitizedEnvFile = normalized;
|
|
388
|
+
baseVolumes.push(" # Mount env file into container");
|
|
389
|
+
baseVolumes.push(` - ../../${sanitizedEnvFile}:/workspace/${sanitizedEnvFile}:ro`);
|
|
390
|
+
}
|
|
376
391
|
if (dockerConfig?.volumes && dockerConfig.volumes.length > 0) {
|
|
377
392
|
const customVolumeLines = dockerConfig.volumes.map((vol) => ` - ${vol}`);
|
|
378
393
|
baseVolumes.push(...customVolumeLines);
|
|
@@ -444,7 +459,7 @@ services:
|
|
|
444
459
|
dockerfile: Dockerfile
|
|
445
460
|
${portsSection} volumes:
|
|
446
461
|
${volumesSection}
|
|
447
|
-
${environmentSection} working_dir: /workspace
|
|
462
|
+
${environmentSection}${sanitizedEnvFile ? ` env_file:\n - ../../${sanitizedEnvFile}\n` : ""} working_dir: /workspace
|
|
448
463
|
stdin_open: true
|
|
449
464
|
tty: true
|
|
450
465
|
cap_add:
|
|
@@ -530,7 +545,7 @@ claude \\
|
|
|
530
545
|
--output-format stream-json \\
|
|
531
546
|
--verbose \\
|
|
532
547
|
--print \\
|
|
533
|
-
"
|
|
548
|
+
"$@" 2>&1 \\
|
|
534
549
|
| grep --line-buffered '^{' \\
|
|
535
550
|
| eval $TEE_CMD \\
|
|
536
551
|
| jq --unbuffered -rj "$JQ_FILTER"
|
|
@@ -642,22 +657,70 @@ else
|
|
|
642
657
|
fi
|
|
643
658
|
`;
|
|
644
659
|
}
|
|
660
|
+
// Generate block-npm-commands.sh hook script for Deno projects
|
|
661
|
+
function generateBlockNpmCommandsHook() {
|
|
662
|
+
return `#!/bin/bash
|
|
663
|
+
# Claude Code PreToolUse hook: blocks npm/npx/yarn/pnpm commands in Deno projects
|
|
664
|
+
# Generated by ralph-cli
|
|
665
|
+
#
|
|
666
|
+
# This project uses Deno. npm/npx/yarn/pnpm should not be used for
|
|
667
|
+
# package management or script execution. Use deno commands instead.
|
|
668
|
+
|
|
669
|
+
set -e
|
|
670
|
+
|
|
671
|
+
# Read the command from hook JSON input on stdin
|
|
672
|
+
INPUT=$(cat)
|
|
673
|
+
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
|
|
674
|
+
|
|
675
|
+
if [ -z "$COMMAND" ]; then
|
|
676
|
+
exit 0
|
|
677
|
+
fi
|
|
678
|
+
|
|
679
|
+
# Match package-manager invocations at shell-command boundaries.
|
|
680
|
+
# Examples matched: npm test, cd app && pnpm install
|
|
681
|
+
# Examples ignored: grep "npm test" README.md
|
|
682
|
+
if echo "$COMMAND" | grep -qE '(^|[;&|][&|]?[[:space:]]*)(npm|npx|yarn|pnpm)([[:space:]]|$)'; then
|
|
683
|
+
jq -n --arg reason "Blocked: This is a Deno project. Use 'deno' commands instead of npm/npx/yarn/pnpm. Examples: 'deno task' instead of 'npm run', 'deno test' instead of 'npm test', 'deno add' or import maps instead of 'npm install'." '{
|
|
684
|
+
hookSpecificOutput: {
|
|
685
|
+
hookEventName: "PreToolUse",
|
|
686
|
+
permissionDecision: "deny",
|
|
687
|
+
permissionDecisionReason: $reason
|
|
688
|
+
}
|
|
689
|
+
}'
|
|
690
|
+
else
|
|
691
|
+
exit 0
|
|
692
|
+
fi
|
|
693
|
+
`;
|
|
694
|
+
}
|
|
645
695
|
// Generate .claude/settings.json with hooks configuration
|
|
646
|
-
function generateClaudeSettings() {
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
|
|
696
|
+
function generateClaudeSettings(language) {
|
|
697
|
+
const hooks = [
|
|
698
|
+
{
|
|
699
|
+
matcher: "Bash",
|
|
700
|
+
hooks: [
|
|
650
701
|
{
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
{
|
|
654
|
-
type: "command",
|
|
655
|
-
command: "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-commands.sh",
|
|
656
|
-
},
|
|
657
|
-
],
|
|
702
|
+
type: "command",
|
|
703
|
+
command: '"$CLAUDE_PROJECT_DIR"/.claude/hooks/block-dangerous-commands.sh',
|
|
658
704
|
},
|
|
659
705
|
],
|
|
660
706
|
},
|
|
707
|
+
];
|
|
708
|
+
// Add Deno-specific hook to block npm commands
|
|
709
|
+
if (language === "deno") {
|
|
710
|
+
hooks.push({
|
|
711
|
+
matcher: "Bash",
|
|
712
|
+
hooks: [
|
|
713
|
+
{
|
|
714
|
+
type: "command",
|
|
715
|
+
command: '"$CLAUDE_PROJECT_DIR"/.claude/hooks/block-npm-commands.sh',
|
|
716
|
+
},
|
|
717
|
+
],
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
const settings = {
|
|
721
|
+
hooks: {
|
|
722
|
+
PreToolUse: hooks,
|
|
723
|
+
},
|
|
661
724
|
};
|
|
662
725
|
return JSON.stringify(settings, null, 2) + "\n";
|
|
663
726
|
}
|
|
@@ -668,13 +731,17 @@ async function generateFiles(ralphDir, language, imageName, force = false, javaV
|
|
|
668
731
|
mkdirSync(dockerDir, { recursive: true });
|
|
669
732
|
console.log(`Created ${DOCKER_DIR}/`);
|
|
670
733
|
}
|
|
734
|
+
// Merge custom firewall domains with language-specific domains
|
|
671
735
|
const customDomains = dockerConfig?.firewall?.allowedDomains || [];
|
|
736
|
+
const languagesJson = getLanguagesJson();
|
|
737
|
+
const langFirewallDomains = languagesJson.languages[language]?.docker?.firewallDomains || [];
|
|
738
|
+
const allFirewallDomains = [...new Set([...customDomains, ...langFirewallDomains])];
|
|
672
739
|
const files = [
|
|
673
740
|
{
|
|
674
741
|
name: "Dockerfile",
|
|
675
742
|
content: generateDockerfile(language, javaVersion, cliProvider, dockerConfig, cliModel),
|
|
676
743
|
},
|
|
677
|
-
{ name: "init-firewall.sh", content: generateFirewallScript(
|
|
744
|
+
{ name: "init-firewall.sh", content: generateFirewallScript(allFirewallDomains) },
|
|
678
745
|
{ name: "docker-compose.yml", content: generateDockerCompose(imageName, dockerConfig) },
|
|
679
746
|
{ name: ".dockerignore", content: DOCKERIGNORE },
|
|
680
747
|
];
|
|
@@ -779,12 +846,32 @@ async function generateFiles(ralphDir, language, imageName, force = false, javaV
|
|
|
779
846
|
chmodSync(hookScriptPath, 0o755);
|
|
780
847
|
console.log("Created .claude/hooks/block-dangerous-commands.sh");
|
|
781
848
|
}
|
|
849
|
+
// Generate Deno-specific hook to block npm commands
|
|
850
|
+
if (language === "deno") {
|
|
851
|
+
const npmHookPath = join(hooksDir, "block-npm-commands.sh");
|
|
852
|
+
if (existsSync(npmHookPath) && !force) {
|
|
853
|
+
const overwrite = await promptConfirm(".claude/hooks/block-npm-commands.sh already exists. Overwrite?");
|
|
854
|
+
if (overwrite) {
|
|
855
|
+
writeFileSync(npmHookPath, generateBlockNpmCommandsHook());
|
|
856
|
+
chmodSync(npmHookPath, 0o755);
|
|
857
|
+
console.log("Created .claude/hooks/block-npm-commands.sh");
|
|
858
|
+
}
|
|
859
|
+
else {
|
|
860
|
+
console.log("Skipped .claude/hooks/block-npm-commands.sh");
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
writeFileSync(npmHookPath, generateBlockNpmCommandsHook());
|
|
865
|
+
chmodSync(npmHookPath, 0o755);
|
|
866
|
+
console.log("Created .claude/hooks/block-npm-commands.sh");
|
|
867
|
+
}
|
|
868
|
+
}
|
|
782
869
|
// Generate .claude/settings.json with hooks configuration
|
|
783
870
|
const settingsPath = join(projectRoot, ".claude", "settings.json");
|
|
784
871
|
if (existsSync(settingsPath) && !force) {
|
|
785
872
|
const overwrite = await promptConfirm(".claude/settings.json already exists. Overwrite?");
|
|
786
873
|
if (overwrite) {
|
|
787
|
-
writeFileSync(settingsPath, generateClaudeSettings());
|
|
874
|
+
writeFileSync(settingsPath, generateClaudeSettings(language));
|
|
788
875
|
console.log("Created .claude/settings.json");
|
|
789
876
|
}
|
|
790
877
|
else {
|
|
@@ -792,7 +879,7 @@ async function generateFiles(ralphDir, language, imageName, force = false, javaV
|
|
|
792
879
|
}
|
|
793
880
|
}
|
|
794
881
|
else {
|
|
795
|
-
writeFileSync(settingsPath, generateClaudeSettings());
|
|
882
|
+
writeFileSync(settingsPath, generateClaudeSettings(language));
|
|
796
883
|
console.log("Created .claude/settings.json");
|
|
797
884
|
}
|
|
798
885
|
// Save config hash for change detection
|