pi-cursor-sdk 0.1.20 → 0.1.22

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.
Files changed (89) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +49 -9
  3. package/docs/cursor-dogfood-checklist.md +57 -0
  4. package/docs/cursor-live-smoke-checklist.md +115 -9
  5. package/docs/cursor-model-ux-spec.md +58 -18
  6. package/docs/cursor-native-tool-replay.md +15 -7
  7. package/docs/cursor-native-tool-visual-audit.md +104 -59
  8. package/docs/cursor-testing-lessons.md +8 -3
  9. package/docs/cursor-tool-surfaces.md +69 -0
  10. package/package.json +34 -10
  11. package/scripts/debug-provider-events.d.mts +59 -0
  12. package/scripts/debug-provider-events.mjs +70 -175
  13. package/scripts/debug-sdk-events.d.mts +90 -0
  14. package/scripts/debug-sdk-events.mjs +36 -98
  15. package/scripts/fixtures/plan-strip-shim/index.ts +12 -0
  16. package/scripts/isolated-cursor-smoke.sh +264 -102
  17. package/scripts/lib/cursor-child-process.d.mts +10 -0
  18. package/scripts/lib/cursor-child-process.mjs +50 -0
  19. package/scripts/lib/cursor-cli-args.d.mts +63 -0
  20. package/scripts/lib/cursor-cli-args.mjs +129 -0
  21. package/scripts/lib/cursor-script-fail.d.mts +1 -0
  22. package/scripts/lib/cursor-script-fail.mjs +13 -0
  23. package/scripts/lib/cursor-sdk-output-filter.d.mts +5 -0
  24. package/scripts/lib/cursor-smoke-env.d.mts +38 -0
  25. package/scripts/lib/cursor-smoke-env.mjs +81 -0
  26. package/scripts/lib/cursor-smoke-shell.sh +174 -0
  27. package/scripts/lib/cursor-visual-render.d.mts +15 -0
  28. package/scripts/lib/cursor-visual-render.mjs +131 -0
  29. package/scripts/probe-mcp-coldstart.mjs +20 -38
  30. package/scripts/refresh-cursor-model-snapshots.mjs +29 -65
  31. package/scripts/steering-rpc-smoke.mjs +170 -65
  32. package/scripts/tmux-live-smoke.sh +152 -98
  33. package/scripts/visual-tui-smoke.mjs +659 -0
  34. package/shared/cursor-sdk-event-debug-env.d.mts +12 -0
  35. package/shared/cursor-sdk-event-debug-env.mjs +13 -0
  36. package/shared/cursor-sensitive-text.d.mts +1 -0
  37. package/{scripts/lib/cursor-probe-utils.mjs → shared/cursor-sensitive-text.mjs} +1 -13
  38. package/shared/cursor-setting-sources.d.mts +5 -0
  39. package/shared/cursor-setting-sources.mjs +22 -0
  40. package/src/context.ts +21 -12
  41. package/src/cursor-bridge-contract.ts +1 -3
  42. package/src/cursor-incomplete-tool-visibility.ts +22 -5
  43. package/src/cursor-native-tool-display-registration.ts +63 -27
  44. package/src/cursor-native-tool-display-replay.ts +246 -144
  45. package/src/cursor-native-tool-display-state.ts +2 -0
  46. package/src/cursor-native-tool-display-tools.ts +149 -41
  47. package/src/cursor-provider-live-run-drain.ts +1 -52
  48. package/src/cursor-provider-run-finalizer.ts +237 -0
  49. package/src/cursor-provider-run-outcome.ts +149 -0
  50. package/src/cursor-provider-turn-api-key.ts +8 -0
  51. package/src/cursor-provider-turn-coordinator.ts +98 -446
  52. package/src/cursor-provider-turn-display-router.ts +216 -0
  53. package/src/cursor-provider-turn-emit.ts +59 -0
  54. package/src/cursor-provider-turn-finalize.ts +119 -0
  55. package/src/cursor-provider-turn-lifecycle-emitter.ts +97 -0
  56. package/src/cursor-provider-turn-message-offset.ts +15 -0
  57. package/src/cursor-provider-turn-prepare.ts +216 -0
  58. package/src/cursor-provider-turn-runner.ts +140 -0
  59. package/src/cursor-provider-turn-sdk-normalizer.ts +88 -0
  60. package/src/cursor-provider-turn-send.ts +103 -0
  61. package/src/cursor-provider-turn-shell-output.ts +107 -0
  62. package/src/cursor-provider-turn-tool-ledger.ts +126 -0
  63. package/src/cursor-provider-turn-types.ts +87 -0
  64. package/src/cursor-provider.ts +16 -504
  65. package/src/cursor-replay-activity-builders.ts +276 -0
  66. package/src/cursor-replay-source-names.ts +33 -0
  67. package/src/cursor-replay-summary-args.ts +191 -0
  68. package/src/cursor-replay-tool-details.ts +464 -0
  69. package/src/cursor-run-final-text.ts +56 -0
  70. package/src/cursor-sdk-abort-error-guard.ts +4 -0
  71. package/src/cursor-sdk-event-debug-constants.ts +14 -5
  72. package/src/cursor-sdk-event-debug.ts +2 -1
  73. package/src/cursor-sensitive-text.ts +3 -36
  74. package/src/cursor-session-agent.ts +3 -1
  75. package/src/cursor-session-compaction-prep.ts +19 -0
  76. package/src/cursor-setting-sources.ts +7 -10
  77. package/src/cursor-state.ts +232 -28
  78. package/src/cursor-tool-lifecycle.ts +9 -8
  79. package/src/cursor-tool-manifest.ts +41 -0
  80. package/src/cursor-tool-names.ts +18 -106
  81. package/src/cursor-tool-presentation-registry.ts +556 -0
  82. package/src/cursor-tool-transcript.ts +1 -1
  83. package/src/cursor-tool-visibility.ts +3 -27
  84. package/src/cursor-transcript-tool-formatters.ts +0 -59
  85. package/src/cursor-transcript-tool-specs.ts +158 -233
  86. package/src/cursor-transcript-utils.ts +0 -44
  87. package/src/cursor-web-tool-activity.ts +10 -60
  88. package/src/cursor-web-tool-args.ts +39 -0
  89. package/src/index.ts +8 -10
@@ -0,0 +1,149 @@
1
+ import type { RunResult } from "@cursor/sdk";
2
+ import { selectCursorFinalText } from "./cursor-run-final-text.js";
3
+ import {
4
+ formatCursorSdkAbortMessage,
5
+ formatCursorSdkRunFailureDetail,
6
+ resolveCursorSdkAbortCause,
7
+ sanitizeCursorProviderError,
8
+ } from "./cursor-provider-errors.js";
9
+ import { hasUsableText } from "./cursor-record-utils.js";
10
+ import {
11
+ buildIncompleteCursorToolRunOutcome,
12
+ type IncompleteCursorToolRunOutcome,
13
+ type IncompleteCursorToolRunOutcomeInput,
14
+ } from "./cursor-incomplete-tool-visibility.js";
15
+
16
+ /** Unified SDK wait() facts consumed by live and direct emission strategies. */
17
+ export type CursorRunOutcome =
18
+ | {
19
+ kind: "finished";
20
+ waitResult: RunResult;
21
+ finalText: string;
22
+ incompleteTools: IncompleteCursorToolRunOutcome;
23
+ assistantTextProduced: boolean;
24
+ }
25
+ | {
26
+ kind: "cancelled";
27
+ waitResult: RunResult;
28
+ incompleteTools: IncompleteCursorToolRunOutcome;
29
+ abortMessage: string;
30
+ }
31
+ | {
32
+ kind: "error";
33
+ waitResult: RunResult;
34
+ incompleteTools: IncompleteCursorToolRunOutcome;
35
+ errorMessage: string;
36
+ };
37
+
38
+ export interface ResolveCursorRunOutcomeParams {
39
+ waitResult: RunResult;
40
+ signalAborted?: boolean;
41
+ textDeltas: readonly string[];
42
+ emittedText: string;
43
+ planTextCandidate?: string;
44
+ selectFinalTextOptions?: { allowPartialPrefix?: boolean };
45
+ runResultFallback?: string;
46
+ resolvedApiKey?: string;
47
+ optionsApiKey?: string;
48
+ }
49
+
50
+ function hasCursorAssistantText(
51
+ resultText: unknown,
52
+ textDeltas: readonly string[],
53
+ fallbackText?: string,
54
+ ): boolean {
55
+ return (
56
+ hasUsableText(typeof resultText === "string" ? resultText : undefined) ||
57
+ hasUsableText(textDeltas.join("")) ||
58
+ hasUsableText(fallbackText)
59
+ );
60
+ }
61
+
62
+ export function isCursorRunFinishedSuccessfully(outcome: CursorRunOutcome): boolean {
63
+ return outcome.kind === "finished";
64
+ }
65
+
66
+ function buildCursorRunAbortMessage(signalAborted: boolean | undefined, sdkStatusCancelled: boolean): string {
67
+ return formatCursorSdkAbortMessage(
68
+ resolveCursorSdkAbortCause({
69
+ signalAborted,
70
+ sdkStatusCancelled,
71
+ }),
72
+ );
73
+ }
74
+
75
+ export function resolveCursorRunOutcome(params: ResolveCursorRunOutcomeParams): CursorRunOutcome {
76
+ const { waitResult, signalAborted } = params;
77
+ const sdkCancelled = waitResult.status === "cancelled";
78
+ const callerAborted = signalAborted === true;
79
+
80
+ if (callerAborted || sdkCancelled) {
81
+ const incompleteTools = buildIncompleteCursorToolRunOutcome({
82
+ status: "cancelled",
83
+ signalAborted: callerAborted,
84
+ assistantTextProduced: false,
85
+ });
86
+ return {
87
+ kind: "cancelled",
88
+ waitResult,
89
+ incompleteTools,
90
+ abortMessage: buildCursorRunAbortMessage(callerAborted, sdkCancelled),
91
+ };
92
+ }
93
+
94
+ if (waitResult.status === "error") {
95
+ const failureDetail = formatCursorSdkRunFailureDetail(waitResult, params.runResultFallback);
96
+ return {
97
+ kind: "error",
98
+ waitResult,
99
+ incompleteTools: buildIncompleteCursorToolRunOutcome({
100
+ status: "error",
101
+ assistantTextProduced: false,
102
+ }),
103
+ errorMessage: sanitizeCursorProviderError(failureDetail, params.resolvedApiKey ?? params.optionsApiKey),
104
+ };
105
+ }
106
+
107
+ const assistantTextProduced = hasCursorAssistantText(
108
+ waitResult.result,
109
+ params.textDeltas,
110
+ params.planTextCandidate,
111
+ );
112
+ const incompleteTools = buildIncompleteCursorToolRunOutcome({
113
+ status: waitResult.status,
114
+ assistantTextProduced,
115
+ });
116
+ const finalText = selectCursorFinalText(
117
+ waitResult.result,
118
+ params.textDeltas,
119
+ params.emittedText,
120
+ params.planTextCandidate,
121
+ params.selectFinalTextOptions,
122
+ );
123
+
124
+ return {
125
+ kind: "finished",
126
+ waitResult,
127
+ finalText,
128
+ incompleteTools,
129
+ assistantTextProduced,
130
+ };
131
+ }
132
+
133
+ export type CursorRunEmission = "finished" | "cancelled" | "failed";
134
+
135
+ export function classifyCursorRunEmission(outcome: CursorRunOutcome): CursorRunEmission {
136
+ switch (outcome.kind) {
137
+ case "finished":
138
+ return "finished";
139
+ case "cancelled":
140
+ return "cancelled";
141
+ case "error":
142
+ return "failed";
143
+ }
144
+ }
145
+
146
+ export function getCursorRunAbortMessage(outcome: CursorRunOutcome): string {
147
+ if (outcome.kind === "cancelled") return outcome.abortMessage;
148
+ return buildCursorRunAbortMessage(false, outcome.waitResult.status === "cancelled");
149
+ }
@@ -0,0 +1,8 @@
1
+ const CURSOR_API_KEY_ENV_VAR = "CURSOR_API_KEY";
2
+
3
+ export function resolveCursorApiKey(apiKey?: string): string | undefined {
4
+ const trimmed = apiKey?.trim();
5
+ if (!trimmed) return undefined;
6
+ if (trimmed === CURSOR_API_KEY_ENV_VAR) return process.env.CURSOR_API_KEY?.trim();
7
+ return trimmed;
8
+ }