effect-cursor-sdk 0.3.1 → 0.4.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.
@@ -0,0 +1,124 @@
1
+ # Changeset Agent
2
+
3
+ The changeset agent is a repository automation pattern built with `effect-cursor-sdk`: when a pull request against `main` is opened or updated, GitHub Actions starts a local Cursor SDK agent in the PR checkout and asks it to create a missing Changesets release note.
4
+
5
+ This is not part of the published library API. It is an executable example of using the package itself to automate a focused maintainer task.
6
+
7
+ ## What It Solves
8
+
9
+ This repository uses Changesets for versioning. Any user-facing source or documentation change should usually include a `.changeset/*.md` file so the release workflow can produce the correct package version and changelog entry.
10
+
11
+ The agent reduces reviewer overhead by handling the common case:
12
+
13
+ - A PR changes package behavior or public docs.
14
+ - The author forgot to add a changeset.
15
+ - CI asks Cursor to inspect the diff and add one concise release note.
16
+ - The workflow commits only `.changeset` changes back to the PR branch.
17
+
18
+ Manual changesets still win. If a PR already changes `.changeset/*.md`, the agent exits without adding another file.
19
+
20
+ ## Moving Parts
21
+
22
+ The feature has three pieces:
23
+
24
+ - `.github/workflows/changeset-agent.yml` runs on `pull_request` events targeting `main`.
25
+ - `scripts/create-changeset-agent.ts` contains the Effect program that starts and prompts Cursor.
26
+ - `bun run changeset:agent` is the package script used by CI and local maintainers.
27
+
28
+ The workflow provides repository context and write permissions. The script owns the agent lifecycle and release-note decision. The commit step stages only `.changeset`, so even if the agent reports extra commentary, only release-note files can be committed by the job.
29
+
30
+ ## Event Flow
31
+
32
+ 1. A same-repository PR is opened, reopened, synchronized, or marked ready for review against `main`.
33
+ 2. GitHub Actions checks out the PR head branch with full history.
34
+ 3. Bun installs dependencies with the lockfile.
35
+ 4. `bun run changeset:agent` runs `scripts/create-changeset-agent.ts`.
36
+ 5. The script compares `origin/main...HEAD` and exits early if the PR already includes a changeset.
37
+ 6. The script creates a scoped local Cursor agent using `CursorAgentService`.
38
+ 7. The agent receives a constrained prompt that allows exactly one `.changeset/*.md` file when release impact exists.
39
+ 8. The script logs the agent response and reports whether a new changeset appeared.
40
+ 9. The workflow commits and pushes only `.changeset` changes.
41
+
42
+ ## Why Same-Repository PRs Only
43
+
44
+ The workflow requires both `CURSOR_API_KEY` and `contents: write`. Those are powerful capabilities. The job therefore has this guard:
45
+
46
+ ```yaml
47
+ if: ${{ github.event.pull_request.head.repo.full_name == github.repository && !github.event.pull_request.draft }}
48
+ ```
49
+
50
+ That keeps secrets and write access away from forked pull requests. Forked PRs should continue to add changesets manually, or a maintainer can run the script from a trusted checkout.
51
+
52
+ ## Configuration
53
+
54
+ The workflow expects this repository secret:
55
+
56
+ - `CURSOR_API_KEY`: API key used by `@cursor/sdk`.
57
+
58
+ The script also reads optional environment variables:
59
+
60
+ - `CURSOR_MODEL`: Cursor model id. The workflow currently sets `composer-2.5`.
61
+ - `CHANGESET_BASE_REF`: diff base for release-impact detection. Defaults to `origin/main`.
62
+ - `GITHUB_WORKSPACE`: checkout directory in CI. Local runs default to `process.cwd()`.
63
+
64
+ The script loads Cursor credentials through `loadCursorConfig`, then creates a scoped agent with `CursorAgentService.scoped(config, overrides)`. This keeps the example aligned with the package's recommended configuration path.
65
+
66
+ ## Local Usage
67
+
68
+ From a branch with `main` fetched:
69
+
70
+ ```bash
71
+ export CURSOR_API_KEY=...
72
+ git fetch origin main
73
+ bun run changeset:agent
74
+ ```
75
+
76
+ To compare against a different base:
77
+
78
+ ```bash
79
+ CHANGESET_BASE_REF=origin/release bun run changeset:agent
80
+ ```
81
+
82
+ If the branch already contains a changeset, the command logs that fact and exits without invoking Cursor for another release note.
83
+
84
+ ## Prompt Contract
85
+
86
+ The prompt intentionally gives Cursor a narrow maintenance task. It tells the agent to:
87
+
88
+ - inspect the diff against the configured base;
89
+ - create one concise `.changeset/*.md` file only when the PR affects shipped behavior or public docs;
90
+ - choose `patch`, `minor`, or `major` using Changesets semver conventions;
91
+ - prefer `patch` unless there is a new public feature or breaking change;
92
+ - avoid editing source files, package metadata, lockfiles, or existing changesets;
93
+ - leave the workspace unchanged when no changeset is needed.
94
+
95
+ The prompt includes the changed-file list for orientation, but the agent is still expected to inspect the actual diff before deciding.
96
+
97
+ ## Idempotency
98
+
99
+ The script checks for changed `.changeset/*.md` files before starting Cursor. That prevents duplicate release notes on repeated `synchronize` events.
100
+
101
+ After Cursor finishes, the script lists `.changeset/*.md` files again and logs any newly created file. The workflow then checks `git status --porcelain .changeset` so untracked new files are detected; if the tree is clean under `.changeset`, it exits successfully without committing.
102
+
103
+ ## Failure Modes
104
+
105
+ Common failures are intentionally visible in CI:
106
+
107
+ - Missing or invalid `CURSOR_API_KEY` fails during agent creation.
108
+ - Cursor rate limits or network issues surface through the package's mapped Cursor errors.
109
+ - A missing `origin/main` ref causes the git diff command to fail; the workflow avoids this by using `fetch-depth: 0`.
110
+ - Forked PRs do not run the job because the workflow guard blocks them.
111
+
112
+ When the agent decides no changeset is required, the workflow succeeds and commits nothing.
113
+
114
+ ## Release Workflow Relationship
115
+
116
+ The changeset agent only creates release-note files on PR branches. It does not version, publish, or alter the release workflow.
117
+
118
+ Publishing still works through the existing Changesets process:
119
+
120
+ - PRs add `.changeset/*.md`.
121
+ - The release workflow creates or updates the version PR on `main`.
122
+ - Merging the version PR publishes with `bun run release`.
123
+
124
+ This separation keeps the agent focused on authoring missing release metadata, while Changesets remains the source of truth for version calculation and changelog generation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-cursor-sdk",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Effect-based wrapper around the Cursor SDK",
5
5
  "keywords": [
6
6
  "cursor",
@@ -40,6 +40,7 @@
40
40
  },
41
41
  "scripts": {
42
42
  "build": "tsdown",
43
+ "changeset:agent": "node --import tsx ./scripts/create-changeset-agent.ts",
43
44
  "changeset": "changeset",
44
45
  "prepare": "effect-language-service patch",
45
46
  "prepack": "bun run build",
@@ -63,13 +64,14 @@
63
64
  "verify:publish": "bun run typecheck && bun run sdk-audit && bun run lint && bun run test && bun run build && bun run lint:package"
64
65
  },
65
66
  "dependencies": {
66
- "@cursor/sdk": "^1.0.12",
67
+ "@cursor/sdk": "^1.0.13",
67
68
  "effect-cursor-sdk": "."
68
69
  },
69
70
  "devDependencies": {
70
71
  "@changesets/changelog-github": "^0.6.0",
71
72
  "@changesets/cli": "^2.31.0",
72
73
  "@effect/language-service": "^0.85.1",
74
+ "@effect/platform-node": "^4.0.0-beta.57",
73
75
  "@effect/vitest": "4.0.0-beta.57",
74
76
  "@types/bun": "latest",
75
77
  "@vitest/coverage-v8": "^4.1.5",
@@ -78,6 +80,7 @@
78
80
  "oxlint": "^1.61.0",
79
81
  "publint": "^0.3.12",
80
82
  "tsdown": "^0.21.10",
83
+ "tsx": "^4.21.0",
81
84
  "typescript": "^6.0.3",
82
85
  "vitest": "^4.1.5"
83
86
  },
@@ -1,22 +0,0 @@
1
- # Next major migration (planned)
2
-
3
- This mirrors [DEPRECATIONS.md](../DEPRECATIONS.md) at a high level. **No breaking release is scheduled in this document**; it only records the intended end state.
4
-
5
- ## Agent entry renames
6
-
7
- | Current (0.2.x) | Planned after removing deprecated overloads |
8
- | ----------------------------------------------- | ------------------------------------------- |
9
- | `createFromConfig(config, overrides?)` | `create(config, overrides?)` |
10
- | `resumeFromConfig(agentId, config, overrides?)` | `resume(agentId, config, overrides?)` |
11
- | `promptFromConfig(message, config, overrides?)` | `prompt(message, config, overrides?)` |
12
- | `scopedFromConfig(config, overrides?)` | `scoped(config, overrides?)` |
13
-
14
- Legacy methods that accept raw [`AgentOptions`](https://cursor.com/docs/sdk/typescript) (plain `apiKey` string) will be removed; [`loadCursorConfig`](../README.md#quick-start) and the config-first signatures above become the only entry points.
15
-
16
- ## Application code actions before upgrading (when the major ships)
17
-
18
- 1. Replace `agents.create({ apiKey: … })` with [`loadCursorConfig`](../README.md#quick-start) + `createFromConfig` (or the renamed `create`).
19
- 2. Remove uses of deprecated [`CursorSdkFactory`](../DEPRECATIONS.md#other-deprecations) `create` / `resume` / `prompt` from application layers (keep for tests if needed).
20
- 3. Run tests with [`mockLayer`](../README.md#mocks-and-tests); confirm `CursorSdkFactory` mocks still implement any new factory methods required by that major.
21
-
22
- Watch [CHANGELOG.md](../CHANGELOG.md) and [DEPRECATIONS.md](../DEPRECATIONS.md) for the actual major version and any codemods.