@cursorpool-dev/cli 0.5.6

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 (105) hide show
  1. package/bin/cursor-pool.mjs +9 -0
  2. package/bin/cursor-pool.ts +169 -0
  3. package/node_modules/@cursor-pool/extension/dist/extension.js +2910 -0
  4. package/node_modules/@cursor-pool/extension/package.json +64 -0
  5. package/node_modules/@cursor-pool/extension/resources/cursor-pool.svg +6 -0
  6. package/node_modules/@cursor-pool/extension/src/api.ts +545 -0
  7. package/node_modules/@cursor-pool/extension/src/extension.ts +104 -0
  8. package/node_modules/@cursor-pool/extension/src/index.ts +1 -0
  9. package/node_modules/@cursor-pool/extension/src/panel.ts +569 -0
  10. package/node_modules/@cursor-pool/extension/src/runtime.ts +22 -0
  11. package/node_modules/@cursor-pool/extension/test/panel.test.ts +1785 -0
  12. package/node_modules/@cursor-pool/patcher/package.json +17 -0
  13. package/node_modules/@cursor-pool/patcher/src/alwaysLocalMarker.ts +86 -0
  14. package/node_modules/@cursor-pool/patcher/src/hash.ts +7 -0
  15. package/node_modules/@cursor-pool/patcher/src/index.ts +55 -0
  16. package/node_modules/@cursor-pool/patcher/src/marker.ts +159 -0
  17. package/node_modules/@cursor-pool/patcher/src/patchCursorAgentExec.ts +154 -0
  18. package/node_modules/@cursor-pool/patcher/src/patchCursorAlwaysLocal.ts +142 -0
  19. package/node_modules/@cursor-pool/patcher/src/patchCursorWorkbenchAuthGate.ts +140 -0
  20. package/node_modules/@cursor-pool/patcher/src/restoreCursorAgentExec.ts +52 -0
  21. package/node_modules/@cursor-pool/patcher/src/restoreCursorAlwaysLocal.ts +52 -0
  22. package/node_modules/@cursor-pool/patcher/src/restoreCursorWorkbenchAuthGate.ts +70 -0
  23. package/node_modules/@cursor-pool/patcher/src/workbenchAuthGateMarker.ts +243 -0
  24. package/node_modules/@cursor-pool/patcher/test/patchCursorAgentExec.test.ts +630 -0
  25. package/node_modules/@cursor-pool/patcher/test/patchCursorAlwaysLocal.test.ts +144 -0
  26. package/node_modules/@cursor-pool/patcher/test/patchCursorWorkbench.test.ts +770 -0
  27. package/node_modules/@cursor-pool/patcher/test/restoreCursorAgentExec.test.ts +139 -0
  28. package/node_modules/@cursor-pool/service/package.json +17 -0
  29. package/node_modules/@cursor-pool/service/src/canary.ts +61 -0
  30. package/node_modules/@cursor-pool/service/src/diagnostics.ts +385 -0
  31. package/node_modules/@cursor-pool/service/src/entry.ts +161 -0
  32. package/node_modules/@cursor-pool/service/src/health.ts +10 -0
  33. package/node_modules/@cursor-pool/service/src/index.ts +29 -0
  34. package/node_modules/@cursor-pool/service/src/metadata.ts +22 -0
  35. package/node_modules/@cursor-pool/service/src/platformSession.ts +1178 -0
  36. package/node_modules/@cursor-pool/service/src/requestCheck.ts +81 -0
  37. package/node_modules/@cursor-pool/service/src/requestGate.ts +100 -0
  38. package/node_modules/@cursor-pool/service/src/requestGateway.ts +441 -0
  39. package/node_modules/@cursor-pool/service/src/runtime.ts +48 -0
  40. package/node_modules/@cursor-pool/service/src/server.ts +939 -0
  41. package/node_modules/@cursor-pool/service/src/takeover.ts +111 -0
  42. package/node_modules/@cursor-pool/service/test/canary.test.ts +140 -0
  43. package/node_modules/@cursor-pool/service/test/diagnostics.test.ts +506 -0
  44. package/node_modules/@cursor-pool/service/test/metadata.test.ts +63 -0
  45. package/node_modules/@cursor-pool/service/test/platformSession.test.ts +2428 -0
  46. package/node_modules/@cursor-pool/service/test/requestCheck.test.ts +152 -0
  47. package/node_modules/@cursor-pool/service/test/requestGate.test.ts +207 -0
  48. package/node_modules/@cursor-pool/service/test/requestGateway.test.ts +466 -0
  49. package/node_modules/@cursor-pool/service/test/runtime.test.ts +47 -0
  50. package/node_modules/@cursor-pool/service/test/server.test.ts +2570 -0
  51. package/node_modules/@cursor-pool/shared/package.json +17 -0
  52. package/node_modules/@cursor-pool/shared/src/clientConfig.ts +49 -0
  53. package/node_modules/@cursor-pool/shared/src/index.ts +14 -0
  54. package/node_modules/@cursor-pool/shared/src/manifest.ts +36 -0
  55. package/node_modules/@cursor-pool/shared/src/metadata.ts +19 -0
  56. package/node_modules/@cursor-pool/shared/src/paths.ts +5 -0
  57. package/node_modules/@cursor-pool/shared/src/runtime.ts +3 -0
  58. package/node_modules/@cursor-pool/shared/test/index.test.ts +56 -0
  59. package/node_modules/@cursor-pool/shared/test/manifest.test.ts +65 -0
  60. package/node_modules/@cursor-pool/shared/test/metadata.test.ts +25 -0
  61. package/node_modules/@cursor-pool/shared/test/runtime.test.ts +8 -0
  62. package/package.json +28 -0
  63. package/src/adHocResign.ts +65 -0
  64. package/src/autostart.ts +240 -0
  65. package/src/compat.ts +282 -0
  66. package/src/confirm.ts +76 -0
  67. package/src/cursor.ts +94 -0
  68. package/src/diagnostics.ts +558 -0
  69. package/src/environment.ts +18 -0
  70. package/src/extensionBundle.ts +111 -0
  71. package/src/extensionLink.ts +168 -0
  72. package/src/index.ts +23 -0
  73. package/src/install.ts +614 -0
  74. package/src/installRecord.ts +105 -0
  75. package/src/launch.ts +182 -0
  76. package/src/patchSet.ts +182 -0
  77. package/src/platform.ts +132 -0
  78. package/src/repair.ts +383 -0
  79. package/src/restore.ts +153 -0
  80. package/src/serviceCommands.ts +79 -0
  81. package/src/serviceProcess.ts +188 -0
  82. package/src/status.ts +241 -0
  83. package/src/target.ts +37 -0
  84. package/src/trial.ts +133 -0
  85. package/src/uninstall.ts +213 -0
  86. package/test/autostart.test.ts +151 -0
  87. package/test/compat.test.ts +192 -0
  88. package/test/confirm.test.ts +114 -0
  89. package/test/cursor-pool-bin.test.ts +658 -0
  90. package/test/cursor.test.ts +20 -0
  91. package/test/diagnostics.test.ts +709 -0
  92. package/test/e2e-install.test.ts +773 -0
  93. package/test/extensionBundle.test.ts +161 -0
  94. package/test/extensionLink.test.ts +209 -0
  95. package/test/install.test.ts +862 -0
  96. package/test/installRecord.test.ts +107 -0
  97. package/test/launch.test.ts +138 -0
  98. package/test/platform.test.ts +226 -0
  99. package/test/repair.test.ts +575 -0
  100. package/test/restore.test.ts +211 -0
  101. package/test/serviceCommands.test.ts +135 -0
  102. package/test/serviceProcess.test.ts +280 -0
  103. package/test/status.test.ts +615 -0
  104. package/test/target.test.ts +49 -0
  105. package/test/trial.test.ts +146 -0
@@ -0,0 +1,111 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import type { SafeGatewayForwardState } from './requestGateway';
3
+ import type { SafeRouteState } from './platformSession';
4
+ import type { RequestGateDecision } from './requestGate';
5
+
6
+ export type AgentTakeoverInput = {
7
+ requestId?: unknown;
8
+ source?: unknown;
9
+ model?: unknown;
10
+ stream?: unknown;
11
+ messagesShape?: unknown;
12
+ };
13
+
14
+ export type AgentTakeoverRejectReason =
15
+ | 'logged-out'
16
+ | 'mode-inactive'
17
+ | 'mode-released'
18
+ | 'device-inactive'
19
+ | 'invalid-session'
20
+ | 'route-missing'
21
+ | 'route-expired';
22
+
23
+ export type AgentTakeoverResponse =
24
+ | {
25
+ state: 'answered';
26
+ requestId: string;
27
+ source: 'cursor-always-local' | 'cursor-agent-exec' | 'unknown';
28
+ model: string;
29
+ content: string;
30
+ }
31
+ | {
32
+ state: 'rejected';
33
+ requestId: string;
34
+ reason: AgentTakeoverRejectReason;
35
+ };
36
+
37
+ const SAFE_TOKEN_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
38
+ const SAFE_MODEL_PATTERN = /^[A-Za-z0-9._:-]{1,96}$/;
39
+ const SECRET_PATTERN =
40
+ /(api[_-]?key|authorization|bearer|cookie|cursor[_-]?auth|provider[_-]?secret|secret|token|prompt|messages|sk-[A-Za-z0-9])/i;
41
+
42
+ function safeToken(value: unknown, fallback: string) {
43
+ return typeof value === 'string' &&
44
+ SAFE_TOKEN_PATTERN.test(value) &&
45
+ !SECRET_PATTERN.test(value)
46
+ ? value
47
+ : fallback;
48
+ }
49
+
50
+ function safeSource(value: unknown): Extract<AgentTakeoverResponse, { state: 'answered' }>['source'] {
51
+ return value === 'cursor-always-local' || value === 'cursor-agent-exec'
52
+ ? value
53
+ : 'unknown';
54
+ }
55
+
56
+ function safeModel(value: unknown) {
57
+ return typeof value === 'string' &&
58
+ SAFE_MODEL_PATTERN.test(value) &&
59
+ !SECRET_PATTERN.test(value)
60
+ ? value
61
+ : 'unknown';
62
+ }
63
+
64
+ export function buildAgentTakeoverResponse(
65
+ input: AgentTakeoverInput,
66
+ gate: RequestGateDecision,
67
+ route: SafeRouteState,
68
+ forward?: SafeGatewayForwardState,
69
+ ): AgentTakeoverResponse {
70
+ const requestId = safeToken(input.requestId, randomUUID());
71
+
72
+ if (gate.state === 'blocked') {
73
+ return {
74
+ state: 'rejected',
75
+ requestId,
76
+ reason: gate.reason,
77
+ };
78
+ }
79
+
80
+ if (route.state === 'missing') {
81
+ return { state: 'rejected', requestId, reason: 'route-missing' };
82
+ }
83
+
84
+ if (route.state === 'expired') {
85
+ return { state: 'rejected', requestId, reason: 'route-expired' };
86
+ }
87
+
88
+ const content = forward?.state === 'forwarded' ? forward.content : undefined;
89
+
90
+ return {
91
+ state: 'answered',
92
+ requestId,
93
+ source: safeSource(input.source),
94
+ model: safeModel(input.model),
95
+ content: content ?? 'Cursor Pool provider 暂时没有返回可显示内容',
96
+ };
97
+ }
98
+
99
+ export function createAgentTakeoverStore() {
100
+ let latestTakeover: AgentTakeoverResponse | null = null;
101
+
102
+ return {
103
+ record(takeover: AgentTakeoverResponse): AgentTakeoverResponse {
104
+ latestTakeover = takeover;
105
+ return takeover;
106
+ },
107
+ latest(): AgentTakeoverResponse | null {
108
+ return latestTakeover;
109
+ },
110
+ };
111
+ }
@@ -0,0 +1,140 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+ import { createCanaryStore, sanitizeAgentCanary } from '../src/canary';
4
+
5
+ const allowedGate = {
6
+ state: 'allowed' as const,
7
+ productId: 'prod_basic',
8
+ modeStartedAt: '2026-05-31T00:05:00.000Z',
9
+ };
10
+ const blockedGate = {
11
+ state: 'blocked' as const,
12
+ reason: 'logged-out' as const,
13
+ };
14
+
15
+ test('sanitizeAgentCanary drops sensitive and unknown fields while adding service fields', () => {
16
+ const canary = sanitizeAgentCanary(
17
+ {
18
+ requestId: 'req-1',
19
+ requestType: 'agent',
20
+ source: 'cursor-agent-exec',
21
+ model: 'claude-secret',
22
+ prompt: 'do not store',
23
+ messages: [{ role: 'user', content: 'do not store' }],
24
+ apiKey: 'secret',
25
+ authorization: 'Bearer secret',
26
+ cookie: 'secret',
27
+ body: { hidden: true },
28
+ unknown: 'discard-me',
29
+ gate: { state: 'allowed', productId: 'prod_from_input', modeStartedAt: 'discard-me' },
30
+ },
31
+ {
32
+ runtimeId: 'runtime-1',
33
+ gate: allowedGate,
34
+ now: () => '2026-05-30T00:00:00.000Z',
35
+ requestId: () => 'generated-1',
36
+ },
37
+ );
38
+
39
+ assert.deepEqual(canary, {
40
+ requestId: 'req-1',
41
+ requestType: 'agent',
42
+ source: 'cursor-agent-exec',
43
+ model: 'claude-secret',
44
+ receivedAt: '2026-05-30T00:00:00.000Z',
45
+ runtimeId: 'runtime-1',
46
+ gate: allowedGate,
47
+ });
48
+ assert.equal(Object.hasOwn(canary, 'prompt'), false);
49
+ assert.equal(Object.hasOwn(canary, 'messages'), false);
50
+ assert.equal(Object.hasOwn(canary, 'apiKey'), false);
51
+ assert.equal(Object.hasOwn(canary, 'authorization'), false);
52
+ assert.equal(Object.hasOwn(canary, 'cookie'), false);
53
+ assert.equal(Object.hasOwn(canary, 'body'), false);
54
+ assert.equal(Object.hasOwn(canary, 'unknown'), false);
55
+ assert.notDeepEqual(canary.gate, { state: 'allowed', productId: 'prod_from_input', modeStartedAt: 'discard-me' });
56
+ });
57
+
58
+ test('sanitizeAgentCanary defaults fields and generates requestId for invalid input', () => {
59
+ const canary = sanitizeAgentCanary(
60
+ {
61
+ requestId: 'x'.repeat(129),
62
+ requestType: 123,
63
+ source: '',
64
+ model: null,
65
+ },
66
+ {
67
+ runtimeId: 'runtime-2',
68
+ gate: blockedGate,
69
+ now: () => '2026-05-30T00:00:01.000Z',
70
+ requestId: () => 'generated-2',
71
+ },
72
+ );
73
+
74
+ assert.deepEqual(canary, {
75
+ requestId: 'generated-2',
76
+ requestType: 'agent',
77
+ source: 'cursor-agent-exec',
78
+ model: 'unknown',
79
+ receivedAt: '2026-05-30T00:00:01.000Z',
80
+ runtimeId: 'runtime-2',
81
+ gate: blockedGate,
82
+ });
83
+ });
84
+
85
+ test('sanitizeAgentCanary uses default clock and requestId providers when omitted', () => {
86
+ const canary = sanitizeAgentCanary({}, { runtimeId: 'runtime-3', gate: blockedGate });
87
+
88
+ assert.equal(typeof canary.requestId, 'string');
89
+ assert.notEqual(canary.requestId, '');
90
+ assert.equal(Number.isNaN(Date.parse(canary.receivedAt)), false);
91
+ assert.equal(canary.runtimeId, 'runtime-3');
92
+ assert.equal(canary.requestType, 'agent');
93
+ assert.equal(canary.source, 'cursor-agent-exec');
94
+ assert.equal(canary.model, 'unknown');
95
+ assert.equal(canary.gate, blockedGate);
96
+ });
97
+
98
+ test('canary store keeps only the latest event in memory', () => {
99
+ const store = createCanaryStore();
100
+ assert.equal(store.latest(), null);
101
+
102
+ store.record({
103
+ requestId: 'req-1',
104
+ requestType: 'agent',
105
+ source: 'cursor-agent-exec',
106
+ model: 'unknown',
107
+ receivedAt: '2026-05-30T00:00:00.000Z',
108
+ runtimeId: 'runtime-1',
109
+ gate: blockedGate,
110
+ });
111
+ store.record({
112
+ requestId: 'req-2',
113
+ requestType: 'agent',
114
+ source: 'cursor-agent-exec',
115
+ model: 'unknown',
116
+ receivedAt: '2026-05-30T00:00:01.000Z',
117
+ runtimeId: 'runtime-1',
118
+ gate: allowedGate,
119
+ });
120
+
121
+ assert.equal(store.latest()?.requestId, 'req-2');
122
+ });
123
+
124
+ test('canary store record returns the saved canary', () => {
125
+ const store = createCanaryStore();
126
+ const canary = {
127
+ requestId: 'req-3',
128
+ requestType: 'agent' as const,
129
+ source: 'cursor-agent-exec' as const,
130
+ model: 'unknown',
131
+ receivedAt: '2026-05-30T00:00:02.000Z',
132
+ runtimeId: 'runtime-1',
133
+ gate: allowedGate,
134
+ };
135
+
136
+ const saved = store.record(canary);
137
+
138
+ assert.equal(saved, canary);
139
+ assert.equal(store.latest(), canary);
140
+ });