Skip to content

Commit fcd9f3a

Browse files
committed
refactor
1 parent f525189 commit fcd9f3a

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

registry/coder-labs/modules/cursor-cli/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module "cursor_cli" {
2727
# Optional
2828
install_cursor_cli = true
2929
cursor_cli_version = "latest"
30-
output_format = "json" # text | json | stream-json
3130
force = false
3231
model = "gpt-5"
3332
ai_prompt = data.coder_parameter.ai_prompt.value
@@ -56,7 +55,7 @@ module "cursor_cli" {
5655

5756
### MCP configuration
5857

59-
Minimal MCP server (writes `<folder>/.cursor/mcp.json`):
58+
Minimal MCP server (writes `~/.cursor/mcp.json`):
6059

6160
```tf
6261
module "cursor_cli" {
@@ -83,7 +82,7 @@ module "cursor_cli" {
8382
source = "registry.coder.com/coder-labs/cursor-cli/coder"
8483
version = "0.1.0"
8584
agent_id = coder_agent.example.id
86-
folder = "/workspace"
85+
folder = "/home/coder/project"
8786
8887
mcp_json = jsonencode({
8988
mcpServers = {
@@ -102,7 +101,7 @@ module "cursor_cli" {
102101

103102
### Rules
104103

105-
Provide a map of file name to content; files are written to `<folder>/.cursor/rules/<name>`.
104+
Provide a map of file name to content; files are written to `~/.cursor/rules/<name>`.
106105

107106
Single rules file:
108107

@@ -117,10 +116,10 @@ module "cursor_cli" {
117116
"global.yml" = <<-EOT
118117
version: 1
119118
rules:
120-
- name: project
119+
- name: frontend
121120
include: ['**/*']
122121
exclude: ['node_modules/**', '.git/**']
123-
description: Project-wide rules
122+
description: Frontend rules
124123
EOT
125124
}
126125
}
@@ -133,7 +132,7 @@ module "cursor_cli" {
133132
source = "registry.coder.com/coder-labs/cursor-cli/coder"
134133
version = "0.1.0"
135134
agent_id = coder_agent.example.id
136-
folder = "/workspace"
135+
folder = "/home/coder/project"
137136
138137
rules_files = {
139138
"python.yml" = <<-EOT
@@ -159,9 +158,8 @@ module "cursor_cli" {
159158
## Notes
160159

161160
- See Cursor CLI docs: `https://docs.cursor.com/en/cli/overview`
162-
- For MCP project config, see `https://docs.cursor.com/en/context/mcp#using-mcp-json`. This module writes your `mcp_json` into `<folder>/.cursor/mcp.json`.
163-
- For Rules, see `https://docs.cursor.com/en/context/rules#project-rules`. Provide `rules_files` (map of file name to content) to populate `<folder>/.cursor/rules/`.
164-
- The agent runs non-interactively with `-p` by default. Use `output_format` to choose `text | json | stream-json` (default `json`).
161+
- For MCP project config, see `https://docs.cursor.com/en/context/mcp#using-mcp-json`. This module writes your `mcp_json` into `~/.cursor/mcp.json`.
162+
- For Rules, see `https://docs.cursor.com/en/context/rules#project-rules`. Provide `rules_files` (map of file name to content) to populate `~/.cursor/rules/`.
165163

166164
## Troubleshooting
167165

registry/coder-labs/modules/cursor-cli/main.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ describe("cursor-cli", async () => {
8585
expect(startLog.stdout).toContain("status");
8686
});
8787

88-
test("writes project mcp.json when provided", async () => {
88+
test("writes workspace mcp.json when provided", async () => {
8989
const mcp = JSON.stringify({ mcpServers: { foo: { command: "foo", type: "stdio" } } });
90-
const { id, projectDir } = await setup({ mcp_json: mcp });
90+
const { id } = await setup({ mcp_json: mcp });
9191
await writeExecutable({
9292
containerId: id,
9393
filePath: "/usr/bin/cursor-agent",
@@ -99,7 +99,7 @@ describe("cursor-cli", async () => {
9999
const mcpContent = await execContainer(id, [
100100
"bash",
101101
"-c",
102-
`cat '${projectDir}/.cursor/mcp.json'`,
102+
`cat '/home/coder/.cursor/mcp.json'`,
103103
]);
104104
expect(mcpContent.exitCode).toBe(0);
105105
expect(mcpContent.stdout).toContain("mcpServers");

registry/coder-labs/modules/cursor-cli/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ resource "coder_script" "cursor_cli" {
152152
fi
153153
ARG_INSTALL='${var.install_cursor_cli}' \
154154
ARG_VERSION='${var.cursor_cli_version}' \
155-
PROJECT_MCP_JSON='${var.mcp_json != null ? base64encode(replace(var.mcp_json, "'", "'\\''")) : ""}' \
156-
PROJECT_RULES_JSON='${var.rules_files != null ? base64encode(jsonencode(var.rules_files)) : ""}' \
155+
WORKSPACE_MCP_JSON='${var.mcp_json != null ? base64encode(replace(var.mcp_json, "'", "'\\''")) : ""}' \
156+
WORKSPACE_RULES_JSON='${var.rules_files != null ? base64encode(jsonencode(var.rules_files)) : ""}' \
157157
MODULE_DIR_NAME='${local.module_dir_name}' \
158158
FOLDER='${var.folder}' \
159159
/tmp/install.sh | tee "$HOME/${local.module_dir_name}/install.log"

registry/coder-labs/modules/cursor-cli/scripts/install.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ FOLDER=${FOLDER:-$HOME}
1515

1616
mkdir -p "$HOME/$MODULE_DIR_NAME"
1717

18-
PROJECT_MCP_JSON=$(echo -n "$PROJECT_MCP_JSON" | base64 -d)
19-
PROJECT_RULES_JSON=$(echo -n "$PROJECT_RULES_JSON" | base64 -d)
18+
WORKSPACE_MCP_JSON=$(echo -n "$WORKSPACE_MCP_JSON" | base64 -d)
19+
WORKSPACE_RULES_JSON=$(echo -n "$WORKSPACE_RULES_JSON" | base64 -d)
2020

2121
{
2222
echo "--------------------------------"
@@ -62,19 +62,20 @@ if [ -n "${STATUS_SLUG:-}" ]; then
6262
export CODER_MCP_APP_STATUS_SLUG="$STATUS_SLUG"
6363
fi
6464

65-
# Write project-specific MCP if provided
66-
if [ -n "$PROJECT_MCP_JSON" ]; then
67-
TARGET_DIR="$FOLDER/.cursor"
65+
# Write MCP config to user's home if provided (~/.cursor/mcp.json)
66+
if [ -n "$WORKSPACE_MCP_JSON" ]; then
67+
TARGET_DIR="$HOME/.cursor"
68+
TARGET_FILE="$TARGET_DIR/mcp.json"
6869
mkdir -p "$TARGET_DIR"
69-
echo "$PROJECT_MCP_JSON" > "$TARGET_DIR/mcp.json"
70-
echo "Wrote project MCP to $TARGET_DIR/mcp.json" | tee -a "$HOME/$MODULE_DIR_NAME/install.log"
70+
echo "$WORKSPACE_MCP_JSON" > "$TARGET_FILE"
71+
echo "Wrote workspace MCP to $TARGET_FILE" | tee -a "$HOME/$MODULE_DIR_NAME/install.log"
7172
fi
7273

73-
# Write rules files if provided (map of name->content)
74-
if [ -n "$PROJECT_RULES_JSON" ]; then
75-
RULES_DIR="$FOLDER/.cursor/rules"
74+
# Write rules files to user's home (~/.cursor/rules)
75+
if [ -n "$WORKSPACE_RULES_JSON" ]; then
76+
RULES_DIR="$HOME/.cursor/rules"
7677
mkdir -p "$RULES_DIR"
77-
echo "$PROJECT_RULES_JSON" | jq -r 'to_entries[] | @base64' | while read -r entry; do
78+
echo "$WORKSPACE_RULES_JSON" | jq -r 'to_entries[] | @base64' | while read -r entry; do
7879
_jq() { echo "${entry}" | base64 -d | jq -r ${1}; }
7980
NAME=$(_jq '.key')
8081
CONTENT=$(_jq '.value')

0 commit comments

Comments
 (0)