effect-cursor-sdk 0.1.1 → 0.2.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/dist/index.js CHANGED
@@ -109,6 +109,184 @@ function mapCursorError(cause, context) {
109
109
  }));
110
110
  }
111
111
  //#endregion
112
+ //#region src/cursor-config.ts
113
+ /**
114
+ * Branded secret material for the Cursor API key.
115
+ *
116
+ * Values are held inside {@link Redacted} on {@link CursorConfig}; this schema
117
+ * only brands the decoded plaintext type so it cannot be confused with other
118
+ * strings at the type level.
119
+ */
120
+ const CursorApiKey = Schema.Redacted(Schema.String).pipe(Schema.brand("CursorApiKey"));
121
+ /**
122
+ * Branded model identifier from wrapper config.
123
+ *
124
+ * Populated from the `CURSOR_MODEL` environment variable when using
125
+ * {@link loadCursorConfig}.
126
+ */
127
+ const CursorModelId = Schema.String.pipe(Schema.brand("CursorModelId"));
128
+ /**
129
+ * Branded local working directory for agent runs.
130
+ *
131
+ * Populated from `CURSOR_LOCAL_CWD` when using {@link loadCursorConfig}.
132
+ */
133
+ const CursorLocalCwd = Schema.String.pipe(Schema.brand("CursorLocalCwd"));
134
+ /**
135
+ * Minimal configuration owned by this wrapper.
136
+ *
137
+ * The SDK's `AgentOptions` type remains the source of truth for complete
138
+ * runtime options. This schema models environment-derived defaults only.
139
+ * Use {@link agentOptionsFromConfig} to merge those defaults into SDK-owned
140
+ * {@link AgentOptions} at the SDK boundary.
141
+ *
142
+ * @remarks
143
+ * **Preferred path:** Load defaults with {@link loadCursorConfig}, then call
144
+ * `CursorAgentService` methods such as `createFromConfig` (and related helpers)
145
+ * or merge manually with {@link agentOptionsFromConfig}. Passing plain
146
+ * {@link AgentOptions} directly to deprecated `create` / `resume` / `prompt` /
147
+ * `scoped` overloads may be removed in a future major version.
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * const config = new CursorConfig({
152
+ * apiKey: Redacted.make(CursorApiKey.make(process.env.CURSOR_API_KEY!)),
153
+ * modelId: CursorModelId.make("composer-2"),
154
+ * cwd: CursorLocalCwd.make(process.cwd())
155
+ * })
156
+ * ```
157
+ *
158
+ * @see {@link cursorConfig}
159
+ * @see {@link loadCursorConfig}
160
+ *
161
+ * @category config
162
+ */
163
+ var CursorConfig = class extends Schema.Class("CursorConfig")({
164
+ apiKey: Schema.optional(CursorApiKey),
165
+ modelId: Schema.optional(CursorModelId),
166
+ cwd: Schema.optional(CursorLocalCwd)
167
+ }) {};
168
+ /**
169
+ * Effect Config descriptors for common Cursor environment variables.
170
+ *
171
+ * Reads `CURSOR_API_KEY`, `CURSOR_MODEL`, and `CURSOR_LOCAL_CWD` from the active
172
+ * Effect {@link ConfigProvider.ConfigProvider}. All fields are optional so
173
+ * callers can merge with explicit overrides via {@link agentOptionsFromConfig}.
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * const config = yield* loadCursorConfig
178
+ * const options = agentOptionsFromConfig(config)
179
+ * ```
180
+ *
181
+ * @see {@link Config}
182
+ * @see {@link loadCursorConfig}
183
+ *
184
+ * @category config
185
+ */
186
+ const cursorConfig = Config.all({
187
+ apiKey: Config.redacted("CURSOR_API_KEY").pipe(Config.option),
188
+ modelId: Config.string("CURSOR_MODEL").pipe(Config.option),
189
+ cwd: Config.string("CURSOR_LOCAL_CWD").pipe(Config.option)
190
+ });
191
+ /**
192
+ * Build SDK `AgentOptions` from wrapper config and optional overrides.
193
+ *
194
+ * This is the adapter from typed, redacted {@link CursorConfig} to the SDK's
195
+ * plain-string `apiKey` boundary. Prefer `CursorAgentService.createFromConfig`
196
+ * (and related methods) over building {@link AgentOptions} by hand.
197
+ *
198
+ * @param config - Wrapper-owned environment defaults.
199
+ * @param overrides - Complete or partial SDK-owned options to merge over the defaults.
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * const options = agentOptionsFromConfig(config, {
204
+ * cloud: {
205
+ * repos: [{ url: "https://github.com/acme/app" }],
206
+ * autoCreatePR: true
207
+ * }
208
+ * })
209
+ * ```
210
+ *
211
+ * @see {@link CursorConfig}
212
+ * @see {@link AgentOptions}
213
+ *
214
+ * @remarks
215
+ * Explicit override values always win over environment-derived defaults.
216
+ * For application code, prefer service methods that take {@link CursorConfig}
217
+ * instead of calling this helper and then the deprecated `create` overload.
218
+ *
219
+ * @category config
220
+ */
221
+ const agentOptionsFromConfig = (config, overrides = {}) => {
222
+ const model = overrides.model ?? (config.modelId ? { id: config.modelId } : void 0);
223
+ const hasNonEmptyLocalOverride = overrides.local !== void 0 && Object.keys(overrides.local).length > 0;
224
+ const local = config.cwd || hasNonEmptyLocalOverride ? {
225
+ cwd: config.cwd,
226
+ ...overrides.local
227
+ } : void 0;
228
+ return {
229
+ ...overrides,
230
+ apiKey: overrides.apiKey ?? (config.apiKey ? Redacted.value(config.apiKey) : void 0),
231
+ model,
232
+ local
233
+ };
234
+ };
235
+ /**
236
+ * Load environment-derived defaults as a schema-backed value.
237
+ * It uses ConfigProvider to load the environment variables
238
+ * with their default names (`CURSOR_API_KEY`, `CURSOR_MODEL`, `CURSOR_LOCAL_CWD`)
239
+ * from {@link cursorConfig}.
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * const config = yield* loadCursorConfig
244
+ * const options = agentOptionsFromConfig(config, { local: { cwd: process.cwd() } })
245
+ * // Or use CursorAgentService.createFromConfig(config, { local: { cwd: process.cwd() } })
246
+ * ```
247
+ *
248
+ * To change the way that the environment variables are loaded,
249
+ * you can do it with Effect by providing a custom ConfigProvider.
250
+ *
251
+ * ```ts
252
+ * // For example: load via custom environment object
253
+ * const config = yield* loadCursorConfig.pipe(
254
+ * Effect.provideService(
255
+ * ConfigProvider.ConfigProvider,
256
+ * ConfigProvider.fromEnv({
257
+ * env: {
258
+ * CURSOR_API_KEY: "crsr_******",
259
+ * CURSOR_MODEL: "composer-2",
260
+ * CURSOR_LOCAL_CWD: "/workspace",
261
+ * },
262
+ * }),
263
+ * ),
264
+ * )
265
+ * ```
266
+ *
267
+ * @see {@link cursorConfig}
268
+ * @see {@link agentOptionsFromConfig}
269
+ *
270
+ * @remarks
271
+ * This effect is the preferred entry for redacted environment defaults.
272
+ * Pair it with {@link agentOptionsFromConfig} or `CursorAgentService` helpers
273
+ * such as `createFromConfig`.
274
+ *
275
+ * @category config
276
+ */
277
+ const loadCursorConfig = Effect.gen(function* () {
278
+ const provider = yield* ConfigProvider.ConfigProvider;
279
+ const raw = yield* cursorConfig.parse(provider);
280
+ const apiKey = Option.getOrUndefined(raw.apiKey);
281
+ const modelId = Option.getOrUndefined(raw.modelId);
282
+ const cwd = Option.getOrUndefined(raw.cwd);
283
+ return new CursorConfig({
284
+ apiKey: apiKey ? CursorApiKey.make(apiKey) : void 0,
285
+ modelId: modelId !== void 0 ? CursorModelId.make(modelId) : void 0,
286
+ cwd: cwd !== void 0 ? CursorLocalCwd.make(cwd) : void 0
287
+ });
288
+ });
289
+ //#endregion
112
290
  //#region src/cursor-sdk-factory.ts
113
291
  /**
114
292
  * Context service that provides the live `@cursor/sdk` static API boundary.
@@ -118,9 +296,13 @@ function mapCursorError(cause, context) {
118
296
  *
119
297
  * @example
120
298
  * ```ts
299
+ * import { CursorSdkFactory, agentOptionsFromConfig, loadCursorConfig } from "effect-cursor-sdk"
300
+ * import { Effect } from "effect"
301
+ *
121
302
  * const program = Effect.gen(function*() {
122
303
  * const sdk = yield* CursorSdkFactory
123
- * return sdk.create({ model: { id: "composer-2" }, local: { cwd: process.cwd() } })
304
+ * const config = yield* loadCursorConfig
305
+ * return sdk.create(agentOptionsFromConfig(config, { model: { id: "composer-2" } }))
124
306
  * })
125
307
  * ```
126
308
  *
@@ -363,12 +545,16 @@ const instrument = (operation, effect) => {
363
545
  *
364
546
  * @example
365
547
  * ```ts
366
- * import { CursorAgentService, liveLayer } from "effect-cursor-sdk"
548
+ * import { CursorAgentService, liveLayer, loadCursorConfig } from "effect-cursor-sdk"
367
549
  * import { Effect } from "effect"
368
550
  *
369
551
  * const program = Effect.gen(function*() {
370
552
  * const agents = yield* CursorAgentService
371
- * const agent = yield* agents.create({ model: { id: "composer-2" }, local: { cwd: process.cwd() } })
553
+ * const config = yield* loadCursorConfig
554
+ * const agent = yield* agents.createFromConfig(config, {
555
+ * model: { id: "composer-2" },
556
+ * local: { cwd: process.cwd() },
557
+ * })
372
558
  * return yield* agents.send(agent, "Summarize this repository")
373
559
  * }).pipe(Effect.provide(liveLayer))
374
560
  * ```
@@ -377,9 +563,11 @@ const instrument = (operation, effect) => {
377
563
  * @see {@link CursorSdkFactory} for replacing SDK construction in tests.
378
564
  *
379
565
  * @remarks
380
- * Inherits the **API boundary notice** on {@link CursorAgentServiceShape} about
381
- * a possible future switch from raw {@link AgentOptions} to
382
- * {@link loadCursorConfig} / {@link agentOptionsFromConfig}.
566
+ * Prefer {@link CursorAgentServiceShape.createFromConfig} and related methods
567
+ * with {@link loadCursorConfig}; raw {@link AgentOptions} on
568
+ * {@link CursorAgentServiceShape.create} and siblings are deprecated.
569
+ * See `DEPRECATIONS.md` at the package root for migration and planned next-major renames
570
+ * (`createFromConfig` → `create`, etc.).
383
571
  *
384
572
  * @category services
385
573
  */
@@ -454,15 +642,31 @@ var CursorAgentService = class CursorAgentService extends Context.Service()("eff
454
642
  return Effect.ignore(dispose(agent));
455
643
  });
456
644
  };
645
+ const createFromConfig = (config, overrides = {}) => {
646
+ return create(agentOptionsFromConfig(config, overrides));
647
+ };
648
+ const resumeFromConfig = (agentId, config, overrides = {}) => {
649
+ return resume(agentId, agentOptionsFromConfig(config, overrides));
650
+ };
651
+ const promptFromConfig = (message, config, overrides = {}) => {
652
+ return prompt(message, agentOptionsFromConfig(config, overrides));
653
+ };
654
+ const scopedFromConfig = (config, overrides = {}) => {
655
+ return scoped(agentOptionsFromConfig(config, overrides));
656
+ };
457
657
  return {
458
658
  create,
659
+ createFromConfig,
459
660
  resume,
661
+ resumeFromConfig,
460
662
  prompt,
663
+ promptFromConfig,
461
664
  send,
462
665
  reload,
463
666
  close,
464
667
  dispose,
465
- scoped
668
+ scoped,
669
+ scopedFromConfig
466
670
  };
467
671
  }));
468
672
  };
@@ -509,157 +713,6 @@ var CursorArtifactService = class CursorArtifactService extends Context.Service(
509
713
  }));
510
714
  };
511
715
  //#endregion
512
- //#region src/cursor-config.ts
513
- /**
514
- * Branded secret material for the Cursor API key.
515
- *
516
- * Values are held inside {@link Redacted} on {@link CursorConfig}; this schema
517
- * only brands the decoded plaintext type so it cannot be confused with other
518
- * strings at the type level.
519
- */
520
- const CursorApiKey = Schema.Redacted(Schema.String).pipe(Schema.brand("CursorApiKey"));
521
- /**
522
- * Branded model identifier from wrapper config.
523
- *
524
- * Populated from the `CURSOR_MODEL` environment variable when using
525
- * {@link loadCursorConfig}.
526
- */
527
- const CursorModelId = Schema.String.pipe(Schema.brand("CursorModelId"));
528
- /**
529
- * Branded local working directory for agent runs.
530
- *
531
- * Populated from `CURSOR_LOCAL_CWD` when using {@link loadCursorConfig}.
532
- */
533
- const CursorLocalCwd = Schema.String.pipe(Schema.brand("CursorLocalCwd"));
534
- /**
535
- * Minimal configuration owned by this wrapper.
536
- *
537
- * The SDK's `AgentOptions` type remains the source of truth for complete
538
- * runtime options. This schema only models environment-derived defaults.
539
- * Use {@link agentOptionsFromConfig} to merge those defaults into SDK-owned
540
- * {@link AgentOptions}.
541
- *
542
- * @remarks
543
- * **Forward path:** A future major version of this package may require all
544
- * agent-related options to be supplied through this module (for example
545
- * {@link loadCursorConfig} plus {@link agentOptionsFromConfig}) instead of raw
546
- * {@link AgentOptions} on {@link CursorAgentService}.
547
- * Prefer this path for new code.
548
- *
549
- * @example
550
- * ```ts
551
- * const config = new CursorConfig({
552
- * apiKey: Redacted.make(CursorApiKey.make(process.env.CURSOR_API_KEY!)),
553
- * modelId: CursorModelId.make("composer-2"),
554
- * cwd: CursorLocalCwd.make(process.cwd())
555
- * })
556
- * ```
557
- *
558
- * @see {@link cursorConfig}
559
- * @see {@link loadCursorConfig}
560
- *
561
- * @category config
562
- */
563
- var CursorConfig = class extends Schema.Class("CursorConfig")({
564
- apiKey: Schema.optional(CursorApiKey),
565
- modelId: Schema.optional(CursorModelId),
566
- cwd: Schema.optional(CursorLocalCwd)
567
- }) {};
568
- /**
569
- * Effect Config descriptors for common Cursor environment variables.
570
- *
571
- * Reads `CURSOR_API_KEY`, `CURSOR_MODEL`, and `CURSOR_LOCAL_CWD` from the active
572
- * Effect {@link ConfigProvider.ConfigProvider}. All fields are optional so
573
- * callers can still pass complete SDK options explicitly.
574
- *
575
- * @example
576
- * ```ts
577
- * const config = yield* loadCursorConfig
578
- * const options = agentOptionsFromConfig(config)
579
- * ```
580
- *
581
- * @see {@link Config}
582
- * @see {@link loadCursorConfig}
583
- *
584
- * @category config
585
- */
586
- const cursorConfig = Config.all({
587
- apiKey: Config.redacted("CURSOR_API_KEY").pipe(Config.option),
588
- modelId: Config.string("CURSOR_MODEL").pipe(Config.option),
589
- cwd: Config.string("CURSOR_LOCAL_CWD").pipe(Config.option)
590
- });
591
- /**
592
- * Build SDK `AgentOptions` from wrapper config and optional overrides.
593
- *
594
- * Explicit override values always win over environment-derived defaults.
595
- *
596
- * @param config - Wrapper-owned environment defaults.
597
- * @param overrides - Complete or partial SDK-owned options to merge over the defaults.
598
- *
599
- * @example
600
- * ```ts
601
- * const options = agentOptionsFromConfig(config, {
602
- * cloud: {
603
- * repos: [{ url: "https://github.com/acme/app" }],
604
- * autoCreatePR: true
605
- * }
606
- * })
607
- * ```
608
- *
609
- * @see {@link CursorConfig}
610
- * @see {@link AgentOptions}
611
- *
612
- * @remarks
613
- * Same **forward path** notice as {@link CursorConfig}: this merge is the
614
- * intended boundary for redacted keys and env defaults ahead of a possible
615
- * requirement to use it for all agent entry points.
616
- *
617
- * @category config
618
- */
619
- const agentOptionsFromConfig = (config, overrides = {}) => {
620
- const model = overrides.model ?? (config.modelId ? { id: config.modelId } : void 0);
621
- return {
622
- ...overrides,
623
- apiKey: overrides.apiKey ?? (config.apiKey ? Redacted.value(config.apiKey) : void 0),
624
- model,
625
- local: overrides.local ?? config.cwd ? {
626
- cwd: config.cwd,
627
- ...overrides.local
628
- } : void 0
629
- };
630
- };
631
- /**
632
- * Load environment-derived defaults as a schema-backed value.
633
- *
634
- * @example
635
- * ```ts
636
- * const config = yield* loadCursorConfig
637
- * const options = agentOptionsFromConfig(config, { local: { cwd: process.cwd() } })
638
- * ```
639
- *
640
- * @see {@link cursorConfig}
641
- * @see {@link agentOptionsFromConfig}
642
- *
643
- * @remarks
644
- * Same **forward path** notice as {@link CursorConfig}: this effect is the
645
- * intended entry for redacted env defaults ahead of a possible requirement to
646
- * use it (with {@link agentOptionsFromConfig}) for all agent entry points.
647
- *
648
- * @category config
649
- */
650
- const loadCursorConfig = Effect.gen(function* () {
651
- const provider = yield* ConfigProvider.ConfigProvider;
652
- const raw = yield* cursorConfig.parse(provider);
653
- const apiKey = Option.getOrUndefined(raw.apiKey);
654
- const modelId = Option.getOrUndefined(raw.modelId);
655
- const cwd = Option.getOrUndefined(raw.cwd);
656
- return new CursorConfig({
657
- apiKey: apiKey ? CursorApiKey.make(apiKey) : void 0,
658
- modelId: modelId !== void 0 ? CursorModelId.make(modelId) : void 0,
659
- cwd: cwd !== void 0 ? CursorLocalCwd.make(cwd) : void 0
660
- });
661
- });
662
- //#endregion
663
716
  //#region src/cursor-inspection.ts
664
717
  /**
665
718
  * Effect-native wrappers for SDK inspection, lifecycle, and account catalog APIs.