@code-yeongyu/senpi 2026.8.17 → 2026.8.18-2

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 (67) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/core/cursor-exec-bridge-session.d.ts.map +1 -1
  3. package/dist/core/cursor-exec-bridge-session.js +1 -3
  4. package/dist/core/cursor-exec-bridge-session.js.map +1 -1
  5. package/dist/core/cursor-exec-bridge.d.ts +2 -2
  6. package/dist/core/cursor-exec-bridge.d.ts.map +1 -1
  7. package/dist/core/cursor-exec-bridge.js +29 -20
  8. package/dist/core/cursor-exec-bridge.js.map +1 -1
  9. package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.d.ts +4 -1
  10. package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.d.ts.map +1 -1
  11. package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.js +27 -7
  12. package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.js.map +1 -1
  13. package/dist/core/extensions/builtin/cursor-cli-oauth/index.d.ts +1 -0
  14. package/dist/core/extensions/builtin/cursor-cli-oauth/index.d.ts.map +1 -1
  15. package/dist/core/extensions/builtin/cursor-cli-oauth/index.js +21 -2
  16. package/dist/core/extensions/builtin/cursor-cli-oauth/index.js.map +1 -1
  17. package/dist/core/extensions/builtin/cursor-cli-oauth/native-bootstrap.d.ts +14 -0
  18. package/dist/core/extensions/builtin/cursor-cli-oauth/native-bootstrap.d.ts.map +1 -0
  19. package/dist/core/extensions/builtin/cursor-cli-oauth/native-bootstrap.js +58 -0
  20. package/dist/core/extensions/builtin/cursor-cli-oauth/native-bootstrap.js.map +1 -0
  21. package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.d.ts +4 -0
  22. package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.d.ts.map +1 -1
  23. package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.js +33 -2
  24. package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.js.map +1 -1
  25. package/dist/core/extensions/builtin/cursor-cli-oauth/settings.d.ts +2 -0
  26. package/dist/core/extensions/builtin/cursor-cli-oauth/settings.d.ts.map +1 -1
  27. package/dist/core/extensions/builtin/cursor-cli-oauth/settings.js +20 -10
  28. package/dist/core/extensions/builtin/cursor-cli-oauth/settings.js.map +1 -1
  29. package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
  30. package/dist/core/extensions/builtin/goal/index.js +14 -3
  31. package/dist/core/extensions/builtin/goal/index.js.map +1 -1
  32. package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts +9 -0
  33. package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts.map +1 -1
  34. package/dist/core/extensions/builtin/goal/monitor-continuation.js +16 -0
  35. package/dist/core/extensions/builtin/goal/monitor-continuation.js.map +1 -1
  36. package/dist/core/extensions/builtin/goal/reload-reengagement.d.ts +30 -0
  37. package/dist/core/extensions/builtin/goal/reload-reengagement.d.ts.map +1 -0
  38. package/dist/core/extensions/builtin/goal/reload-reengagement.js +36 -0
  39. package/dist/core/extensions/builtin/goal/reload-reengagement.js.map +1 -0
  40. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  41. package/dist/modes/interactive/interactive-mode.js +12 -5
  42. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  43. package/docs/providers.md +9 -6
  44. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +24 -0
  45. package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
  46. package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts +3 -2
  47. package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts.map +1 -1
  48. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js +6 -2
  49. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js.map +1 -1
  50. package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  51. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  52. package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  53. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
  54. package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  55. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
  56. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  57. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  58. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  59. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -1
  60. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/recovery-message-snapshot.d.ts.map +1 -1
  61. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/recovery-message-snapshot.js +2 -1
  62. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/recovery-message-snapshot.js.map +1 -1
  63. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  64. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  65. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  66. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  67. package/package.json +7 -7
package/CHANGELOG.md CHANGED
@@ -16,6 +16,57 @@
16
16
 
17
17
  ### Removed
18
18
 
19
+ ## [2026.8.18-2] - 2026-08-18
20
+
21
+ ### Added
22
+
23
+ ### Fixed
24
+
25
+ - Goals no longer stall after a settings hot-reload: a reload `session_start` now re-engages an active goal (re-arming the monitor backstop while wake sources are live, or queueing a continuation through the existing sessionStart admission) instead of parking it until the next user message; stopped goals still never auto-start on reload ([#936](https://github.com/code-yeongyu/senpi/pull/936)).
26
+ - Cursor CLI OAuth is now available by default when its real prerequisites exist: with `cursor-agent` installed and no managed CLI account, a native `cursor` OAuth credential is copied automatically into one canonical `native` slot without modifying the primary credential; explicit `enabled: false` remains a hard opt-out, repeated/concurrent startup is idempotent, and `/login cursor` refreshes the CLI fallback in the same session ([#931](https://github.com/code-yeongyu/senpi/pull/931)).
27
+
28
+ - Cursor exec-bridge lifecycle events now require their originating run signal and await listener delivery, preventing delayed completions from entering a replacement run or becoming detached unhandled rejections ([#935](https://github.com/code-yeongyu/senpi/pull/935)).
29
+ - Model recovery now preserves Cursor's in-memory resolved-tool marker on native tool-call blocks, so Claude/Kimi-id
30
+ Cursor turns do not execute server-resolved bash/write/delete calls a second time
31
+ ([#939](https://github.com/code-yeongyu/senpi/pull/939)).
32
+ - GPT-5.6 Sol and Sol Fast now default to a 400,000-token context window in both the direct OpenAI and
33
+ ChatGPT OAuth (`openai-codex`) catalogs ([#933](https://github.com/code-yeongyu/senpi/pull/933)).
34
+ - Refreshed Vercel AI Gateway pricing for `alibaba/qwen3.8-27b` from zero-value placeholder metadata to the
35
+ current upstream input, output, and cache-read rates ([#933](https://github.com/code-yeongyu/senpi/pull/933)).
36
+
37
+ ### New Features
38
+
39
+ ### Breaking Changes
40
+
41
+ ### Added
42
+
43
+ ### Changed
44
+
45
+ ### Removed
46
+
47
+ ## [2026.8.18] - 2026-08-18
48
+
49
+ ### Added
50
+
51
+ ### Fixed
52
+
53
+ - Extension widgets no longer change stacking order when their content updates: `setWidget` now replaces the
54
+ component in place, so two live widgets with independent refresh timers (for example omo-senpi's `omo-task` and
55
+ `omo-dag` status widgets) stay in a fixed vertical order instead of bouncing on every refresh
56
+ ([#929](https://github.com/code-yeongyu/senpi/pull/929)).
57
+
58
+ - Cursor model catalogs now become available immediately after authentication: dynamic providers perform their scoped network refresh after login, while explicit Cursor CLI fallback login/import enables the lane, `/cursor-account import native` safely copies the primary OAuth credential into managed accounts, and imported accounts refresh model availability in the current session ([#928](https://github.com/code-yeongyu/senpi/pull/928)).
59
+
60
+ ### New Features
61
+
62
+ ### Breaking Changes
63
+
64
+ ### Added
65
+
66
+ ### Changed
67
+
68
+ ### Removed
69
+
19
70
  ## [2026.8.17] - 2026-08-17
20
71
 
21
72
  ### Added
@@ -1 +1 @@
1
- {"version":3,"file":"cursor-exec-bridge-session.d.ts","sourceRoot":"","sources":["../../src/core/cursor-exec-bridge-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAc,SAAS,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAGvH,KAAK,iBAAiB,GAAG,IAAI,CAAC,KAAK,EAAE,mBAAmB,GAAG,QAAQ,CAAC,CAAC;AAErE,MAAM,WAAW,uBAAuB;IACvC,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;IACvD,iBAAiB,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC;CACrG;AAED,wBAAgB,6BAA6B,CAC5C,UAAU,EAAE;IAAE,OAAO,CAAC,EAAE,uBAAuB,CAAA;CAAE,EACjD,QAAQ,EAAE,MAAM,iBAAiB,sDAmBjC"}
1
+ {"version":3,"file":"cursor-exec-bridge-session.d.ts","sourceRoot":"","sources":["../../src/core/cursor-exec-bridge-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAc,SAAS,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAGvH,KAAK,iBAAiB,GAAG,IAAI,CAAC,KAAK,EAAE,mBAAmB,GAAG,QAAQ,CAAC,CAAC;AAErE,MAAM,WAAW,uBAAuB;IACvC,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;IACvD,iBAAiB,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC;CACrG;AAED,wBAAgB,6BAA6B,CAC5C,UAAU,EAAE;IAAE,OAAO,CAAC,EAAE,uBAAuB,CAAA;CAAE,EACjD,QAAQ,EAAE,MAAM,iBAAiB,sDAkBjC"}
@@ -8,9 +8,7 @@ export function createSessionCursorExecBridge(sessionRef, getAgent) {
8
8
  name: event.toolName,
9
9
  arguments: event.input,
10
10
  }, event.input),
11
- emitEvent: (event) => {
12
- void getAgent().emitExternalEvent(event);
13
- },
11
+ emitEvent: async (event, runSignal) => await getAgent().emitExternalEvent(event, runSignal),
14
12
  getAbortSignal: () => getAgent().signal,
15
13
  });
16
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cursor-exec-bridge-session.js","sourceRoot":"","sources":["../../src/core/cursor-exec-bridge-session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AASjE,MAAM,UAAU,6BAA6B,CAC5C,UAAiD,EACjD,QAAiC;IAEjC,OAAO,sBAAsB,CAAC;QAC7B,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAiB,CAAC,IAAI,CAAC;QAC9D,iBAAiB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAClC,UAAU,CAAC,OAAO,EAAE,iBAAiB,CACpC;YACC,IAAI,EAAE,UAAU;YAChB,EAAE,EAAE,KAAK,CAAC,UAAU;YACpB,IAAI,EAAE,KAAK,CAAC,QAAQ;YACpB,SAAS,EAAE,KAAK,CAAC,KAAK;SACtB,EACD,KAAK,CAAC,KAAK,CACX;QACF,SAAS,EAAE,CAAC,KAAiB,EAAE,EAAE;YAChC,KAAK,QAAQ,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;QACD,cAAc,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM;KACvC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Agent, AgentEvent, AgentTool, AgentToolCall, BeforeToolCallResult } from \"@earendil-works/pi-agent-core\";\nimport { createCursorExecBridge } from \"./cursor-exec-bridge.ts\";\n\ntype CursorBridgeAgent = Pick<Agent, \"emitExternalEvent\" | \"signal\">;\n\nexport interface CursorExecBridgeSession {\n\tgetRegisteredTool(name: string): AgentTool | undefined;\n\tpreflightToolCall(toolCall: AgentToolCall, args: unknown): Promise<BeforeToolCallResult | undefined>;\n}\n\nexport function createSessionCursorExecBridge(\n\tsessionRef: { current?: CursorExecBridgeSession },\n\tgetAgent: () => CursorBridgeAgent,\n) {\n\treturn createCursorExecBridge({\n\t\tgetTool: (name) => sessionRef.current?.getRegisteredTool(name),\n\t\tpreflightToolCall: async (event) =>\n\t\t\tsessionRef.current?.preflightToolCall(\n\t\t\t\t{\n\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\tid: event.toolCallId,\n\t\t\t\t\tname: event.toolName,\n\t\t\t\t\targuments: event.input,\n\t\t\t\t},\n\t\t\t\tevent.input,\n\t\t\t),\n\t\temitEvent: (event: AgentEvent) => {\n\t\t\tvoid getAgent().emitExternalEvent(event);\n\t\t},\n\t\tgetAbortSignal: () => getAgent().signal,\n\t});\n}\n"]}
1
+ {"version":3,"file":"cursor-exec-bridge-session.js","sourceRoot":"","sources":["../../src/core/cursor-exec-bridge-session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AASjE,MAAM,UAAU,6BAA6B,CAC5C,UAAiD,EACjD,QAAiC;IAEjC,OAAO,sBAAsB,CAAC;QAC7B,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAiB,CAAC,IAAI,CAAC;QAC9D,iBAAiB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAClC,UAAU,CAAC,OAAO,EAAE,iBAAiB,CACpC;YACC,IAAI,EAAE,UAAU;YAChB,EAAE,EAAE,KAAK,CAAC,UAAU;YACpB,IAAI,EAAE,KAAK,CAAC,QAAQ;YACpB,SAAS,EAAE,KAAK,CAAC,KAAK;SACtB,EACD,KAAK,CAAC,KAAK,CACX;QACF,SAAS,EAAE,KAAK,EAAE,KAAiB,EAAE,SAAsB,EAAE,EAAE,CAC9D,MAAM,QAAQ,EAAE,CAAC,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC;QACrD,cAAc,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM;KACvC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Agent, AgentEvent, AgentTool, AgentToolCall, BeforeToolCallResult } from \"@earendil-works/pi-agent-core\";\nimport { createCursorExecBridge } from \"./cursor-exec-bridge.ts\";\n\ntype CursorBridgeAgent = Pick<Agent, \"emitExternalEvent\" | \"signal\">;\n\nexport interface CursorExecBridgeSession {\n\tgetRegisteredTool(name: string): AgentTool | undefined;\n\tpreflightToolCall(toolCall: AgentToolCall, args: unknown): Promise<BeforeToolCallResult | undefined>;\n}\n\nexport function createSessionCursorExecBridge(\n\tsessionRef: { current?: CursorExecBridgeSession },\n\tgetAgent: () => CursorBridgeAgent,\n) {\n\treturn createCursorExecBridge({\n\t\tgetTool: (name) => sessionRef.current?.getRegisteredTool(name),\n\t\tpreflightToolCall: async (event) =>\n\t\t\tsessionRef.current?.preflightToolCall(\n\t\t\t\t{\n\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\tid: event.toolCallId,\n\t\t\t\t\tname: event.toolName,\n\t\t\t\t\targuments: event.input,\n\t\t\t\t},\n\t\t\t\tevent.input,\n\t\t\t),\n\t\temitEvent: async (event: AgentEvent, runSignal: AbortSignal) =>\n\t\t\tawait getAgent().emitExternalEvent(event, runSignal),\n\t\tgetAbortSignal: () => getAgent().signal,\n\t});\n}\n"]}
@@ -30,11 +30,11 @@ export interface CursorExecBridgeOptions {
30
30
  * the agent loop's executor, so without these the live tool card for a
31
31
  * synthesized call never resolves.
32
32
  */
33
- emitEvent?: (event: AgentEvent) => void;
33
+ emitEvent: (event: AgentEvent, runSignal: AbortSignal) => Promise<void>;
34
34
  /** Run the session's vetoable extension preflight before tool execution. */
35
35
  preflightToolCall?: (event: ToolCallEvent) => Promise<ToolCallEventResult | undefined>;
36
36
  /** Abort signal for in-flight bridge executions (the active run's signal). */
37
- getAbortSignal?: () => AbortSignal | undefined;
37
+ getAbortSignal: () => AbortSignal | undefined;
38
38
  }
39
39
  /**
40
40
  * Build the exec handlers passed to the `cursor-agent` API through the agent
@@ -1 +1 @@
1
- {"version":3,"file":"cursor-exec-bridge.d.ts","sourceRoot":"","sources":["../../src/core/cursor-exec-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAiB,MAAM,+BAA+B,CAAC;AAC1F,OAAO,EACN,KAAK,kBAAkB,EASvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEhF,MAAM,WAAW,uBAAuB;IACvC;;;;;OAKG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,GAAG,SAAS,CAAC;IACjD;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IACxC,4EAA4E;IAC5E,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAAC;IACvF,8EAA8E;IAC9E,cAAc,CAAC,EAAE,MAAM,WAAW,GAAG,SAAS,CAAC;CAC/C;AA4GD;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,kBAAkB,CA0F3F"}
1
+ {"version":3,"file":"cursor-exec-bridge.d.ts","sourceRoot":"","sources":["../../src/core/cursor-exec-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAiB,MAAM,+BAA+B,CAAC;AAC1F,OAAO,EACN,KAAK,kBAAkB,EASvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEhF,MAAM,WAAW,uBAAuB;IACvC;;;;;OAKG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,GAAG,SAAS,CAAC;IACjD;;;;OAIG;IACH,SAAS,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,4EAA4E;IAC5E,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAAC;IACvF,8EAA8E;IAC9E,cAAc,EAAE,MAAM,WAAW,GAAG,SAAS,CAAC;CAC9C;AAqHD;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,kBAAkB,CA0F3F"}
@@ -39,6 +39,10 @@ function emptyResult(toolCallId, toolName) {
39
39
  };
40
40
  }
41
41
  async function executeTool(options, toolName, toolCallId, args) {
42
+ const runSignal = options.getAbortSignal();
43
+ if (!runSignal) {
44
+ return errorResult(toolCallId, toolName, "Tool execution has no active run");
45
+ }
42
46
  const tool = options.getTool(toolName);
43
47
  if (!tool) {
44
48
  return errorResult(toolCallId, toolName, `Tool "${toolName}" is not available in this session`);
@@ -63,7 +67,9 @@ async function executeTool(options, toolName, toolCallId, args) {
63
67
  catch (error) {
64
68
  return errorResult(toolCallId, toolName, error instanceof Error ? error.message : String(error));
65
69
  }
66
- options.emitEvent?.({ type: "tool_execution_start", toolCallId, toolName, args: cleanArgs });
70
+ await options.emitEvent({ type: "tool_execution_start", toolCallId, toolName, args: cleanArgs }, runSignal);
71
+ let toolResult;
72
+ let endEvent;
67
73
  try {
68
74
  if (!isRecord(params)) {
69
75
  throw new Error(`Tool "${toolName}" prepared non-object arguments`);
@@ -76,40 +82,43 @@ async function executeTool(options, toolName, toolCallId, args) {
76
82
  });
77
83
  if (preflight?.block) {
78
84
  const message = preflight.reason || "Tool execution was blocked";
79
- options.emitEvent?.({
85
+ toolResult = errorResult(toolCallId, toolName, message);
86
+ endEvent = {
80
87
  type: "tool_execution_end",
81
88
  toolCallId,
82
89
  toolName,
83
90
  result: { content: [{ type: "text", text: message }], details: undefined },
84
91
  isError: true,
85
- });
86
- return errorResult(toolCallId, toolName, message);
92
+ };
93
+ }
94
+ else {
95
+ const result = await tool.execute(toolCallId, params, runSignal, undefined);
96
+ toolResult = {
97
+ role: "toolResult",
98
+ toolCallId,
99
+ toolName,
100
+ content: result.content ?? [],
101
+ details: result.details,
102
+ usage: result.usage,
103
+ isError: false,
104
+ timestamp: Date.now(),
105
+ };
106
+ endEvent = { type: "tool_execution_end", toolCallId, toolName, result, isError: false };
87
107
  }
88
- const result = await tool.execute(toolCallId, params, options.getAbortSignal?.(), undefined);
89
- const toolResult = {
90
- role: "toolResult",
91
- toolCallId,
92
- toolName,
93
- content: result.content ?? [],
94
- details: result.details,
95
- usage: result.usage,
96
- isError: false,
97
- timestamp: Date.now(),
98
- };
99
- options.emitEvent?.({ type: "tool_execution_end", toolCallId, toolName, result, isError: false });
100
- return toolResult;
101
108
  }
102
109
  catch (error) {
103
110
  const message = error instanceof Error ? error.message : String(error);
104
- options.emitEvent?.({
111
+ toolResult = errorResult(toolCallId, toolName, message);
112
+ endEvent = {
105
113
  type: "tool_execution_end",
106
114
  toolCallId,
107
115
  toolName,
108
116
  result: { content: [{ type: "text", text: message }], details: undefined },
109
117
  isError: true,
110
- });
111
- return errorResult(toolCallId, toolName, message);
118
+ };
112
119
  }
120
+ await options.emitEvent(endEvent, runSignal);
121
+ return toolResult;
113
122
  }
114
123
  /**
115
124
  * Build the exec handlers passed to the `cursor-agent` API through the agent
@@ -1 +1 @@
1
- {"version":3,"file":"cursor-exec-bridge.js","sourceRoot":"","sources":["../../src/core/cursor-exec-b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CAAC,SAAS;YAC5D,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YACtD,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO;YAC1B,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;SACrC,CAAC;QAEH,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACtB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE;YAC7C,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO;YAC1B,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,SAAS;YACjC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;SACrC,CAAC;QAEH,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACpB,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE;YAC3C,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACpC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;SACrC,CAAC;KACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * Cursor exec-channel → local tool bridge.\n *\n * Cursor's agent protocol executes tools server-drivenly: mid-stream, the\n * server sends exec frames and blocks until the client answers in band. The\n * `cursor-agent` API dispatches those frames onto this bridge, which maps\n * each frame's args onto the session's real tools (`read`, `bash`, `edit`,\n * `write`, `grep`, `find`, `ls`, plus MCP/extension tools by name) and runs\n * them through the same wrapped `AgentTool.execute` path model-issued calls\n * use — so approvals, sandboxing, truncation, and rendering behavior stay\n * identical.\n *\n * The arg translations here MUST mirror the display blocks the API\n * synthesizes (`synthesizeCursorExecToolCall` call sites): the transcript\n * shows one operation, so a different one must not run.\n */\n\nimport type { AgentEvent, AgentTool, AgentToolCall } from \"@earendil-works/pi-agent-core\";\nimport {\n\ttype CursorExecHandlers,\n\tcomposeCursorShellCommand,\n\tcursorPiLimit,\n\tcursorPiLsPath,\n\tcursorPiReadArgs,\n\tcursorPiTimeout,\n\tomitUndefinedCursorArgs,\n\ttype ToolResultMessage,\n\tvalidateToolArguments,\n} from \"@earendil-works/pi-ai\";\nimport type { ToolCallEvent, ToolCallEventResult } from \"./extensions/types.ts\";\n\nexport interface CursorExecBridgeOptions {\n\t/**\n\t * Resolve an executable tool by name. Backed by the session's full tool\n\t * registry (builtin + extension tools), not only the active set: Cursor\n\t * drives its native tools (read/bash/grep/ls/write) over the exec channel\n\t * regardless of which tools the request advertised.\n\t */\n\tgetTool: (name: string) => AgentTool | undefined;\n\t/**\n\t * Surface tool lifecycle events to the host UI. Bridge-run tools bypass\n\t * the agent loop's executor, so without these the live tool card for a\n\t * synthesized call never resolves.\n\t */\n\temitEvent?: (event: AgentEvent) => void;\n\t/** Run the session's vetoable extension preflight before tool execution. */\n\tpreflightToolCall?: (event: ToolCallEvent) => Promise<ToolCallEventResult | undefined>;\n\t/** Abort signal for in-flight bridge executions (the active run's signal). */\n\tgetAbortSignal?: () => AbortSignal | undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction errorResult(toolCallId: string, toolName: string, text: string): ToolResultMessage {\n\treturn {\n\t\trole: \"toolResult\",\n\t\ttoolCallId,\n\t\ttoolName,\n\t\tcontent: [{ type: \"text\", text }],\n\t\tisError: true,\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction emptyResult(toolCallId: string, toolName: string): ToolResultMessage {\n\treturn {\n\t\trole: \"toolResult\",\n\t\ttoolCallId,\n\t\ttoolName,\n\t\tcontent: [{ type: \"text\", text: \"\" }],\n\t\tisError: false,\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nasync function executeTool(\n\toptions: CursorExecBridgeOptions,\n\ttoolName: string,\n\ttoolCallId: string,\n\targs: Record<string, unknown>,\n): Promise<ToolResultMessage> {\n\tconst tool = options.getTool(toolName);\n\tif (!tool) {\n\t\treturn errorResult(toolCallId, toolName, `Tool \"${toolName}\" is not available in this session`);\n\t}\n\n\t// Exec-frame translators write forms like `path: args.path || undefined`;\n\t// a present `undefined` fails schema validation on optional fields even\n\t// though omitting the key is valid.\n\tconst cleanArgs = omitUndefinedCursorArgs(args);\n\tconst toolCall: AgentToolCall = {\n\t\ttype: \"toolCall\",\n\t\tid: toolCallId,\n\t\tname: toolName,\n\t\targuments: cleanArgs,\n\t};\n\n\tlet params: unknown;\n\ttry {\n\t\tparams = validateToolArguments(tool, toolCall);\n\t\tif (tool.prepareArguments) {\n\t\t\tparams = tool.prepareArguments(params);\n\t\t}\n\t} catch (error) {\n\t\treturn errorResult(toolCallId, toolName, error instanceof Error ? error.message : String(error));\n\t}\n\n\toptions.emitEvent?.({ type: \"tool_execution_start\", toolCallId, toolName, args: cleanArgs });\n\ttry {\n\t\tif (!isRecord(params)) {\n\t\t\tthrow new Error(`Tool \"${toolName}\" prepared non-object arguments`);\n\t\t}\n\t\tconst preflight = await options.preflightToolCall?.({\n\t\t\ttype: \"tool_call\",\n\t\t\ttoolCallId,\n\t\t\ttoolName,\n\t\t\tinput: params,\n\t\t});\n\t\tif (preflight?.block) {\n\t\t\tconst message = preflight.reason || \"Tool execution was blocked\";\n\t\t\toptions.emitEvent?.({\n\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\ttoolCallId,\n\t\t\t\ttoolName,\n\t\t\t\tresult: { content: [{ type: \"text\", text: message }], details: undefined },\n\t\t\t\tisError: true,\n\t\t\t});\n\t\t\treturn errorResult(toolCallId, toolName, message);\n\t\t}\n\t\tconst result = await tool.execute(toolCallId, params, options.getAbortSignal?.(), undefined);\n\t\tconst toolResult: ToolResultMessage = {\n\t\t\trole: \"toolResult\",\n\t\t\ttoolCallId,\n\t\t\ttoolName,\n\t\t\tcontent: result.content ?? [],\n\t\t\tdetails: result.details,\n\t\t\tusage: result.usage,\n\t\t\tisError: false,\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\t\toptions.emitEvent?.({ type: \"tool_execution_end\", toolCallId, toolName, result, isError: false });\n\t\treturn toolResult;\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\toptions.emitEvent?.({\n\t\t\ttype: \"tool_execution_end\",\n\t\t\ttoolCallId,\n\t\t\ttoolName,\n\t\t\tresult: { content: [{ type: \"text\", text: message }], details: undefined },\n\t\t\tisError: true,\n\t\t});\n\t\treturn errorResult(toolCallId, toolName, message);\n\t}\n}\n\n/**\n * Build the exec handlers passed to the `cursor-agent` API through the agent\n * loop config. Handlers return bare `ToolResultMessage`s; the API derives the\n * wire protobuf answer from them and pairs the transcript result.\n *\n * Deliberately absent handlers (the API answers with a typed refusal):\n * - `delete`: senpi has no delete tool and the bridge must not mutate the\n * filesystem outside the tool/approval path.\n * - `diagnostics`: no LSP tool in this fork.\n * - `mcpApprovalPreflight`: approval decisions cannot be resolved without an\n * interactive prompt, so smart-mode probes are conservatively refused.\n */\nexport function createCursorExecBridge(options: CursorExecBridgeOptions): CursorExecHandlers {\n\treturn {\n\t\tread: async (args) =>\n\t\t\texecuteTool(options, \"read\", args.toolCallId, {\n\t\t\t\tpath: args.path,\n\t\t\t\toffset: args.offset,\n\t\t\t\tlimit: args.limit,\n\t\t\t}),\n\n\t\tls: async (args) => executeTool(options, \"ls\", args.toolCallId, { path: cursorPiLsPath(args.path) }),\n\n\t\tgrep: async (args) =>\n\t\t\texecuteTool(options, \"grep\", args.toolCallId, {\n\t\t\t\tpattern: args.pattern,\n\t\t\t\tpath: args.path || undefined,\n\t\t\t\tglob: args.glob || undefined,\n\t\t\t\tignoreCase: args.caseInsensitive === true ? true : undefined,\n\t\t\t}),\n\n\t\twrite: async (args) =>\n\t\t\texecuteTool(options, \"write\", args.toolCallId, {\n\t\t\t\tpath: args.path,\n\t\t\t\tcontent: args.fileText ?? new TextDecoder().decode(args.fileBytes ?? new Uint8Array()),\n\t\t\t}),\n\n\t\tshell: async (args) =>\n\t\t\texecuteTool(options, \"bash\", args.toolCallId, {\n\t\t\t\tcommand: composeCursorShellCommand(args.command, args.workingDirectory || undefined),\n\t\t\t\ttimeout: args.timeout && args.timeout > 0 ? args.timeout : undefined,\n\t\t\t}),\n\n\t\tmcp: async (call) => {\n\t\t\tconst toolName = call.toolName || call.name;\n\t\t\tconst tool = options.getTool(toolName);\n\t\t\tif (!tool) {\n\t\t\t\treturn errorResult(call.toolCallId, toolName, `Tool \"${toolName}\" is not registered in this session`);\n\t\t\t}\n\t\t\treturn executeTool(options, toolName, call.toolCallId, call.args);\n\t\t},\n\n\t\tpiRead: async (call) => {\n\t\t\tconst readArgs = cursorPiReadArgs(call.args.path, call.args.offset, call.args.limit);\n\t\t\t// A present `limit: 0` reads zero lines; answer with empty output\n\t\t\t// without running the tool rather than degrading into a full read.\n\t\t\tif (readArgs === null) return emptyResult(call.toolCallId, \"read\");\n\t\t\treturn executeTool(options, \"read\", call.toolCallId, readArgs);\n\t\t},\n\n\t\tpiBash: async (call) =>\n\t\t\texecuteTool(options, \"bash\", call.toolCallId, {\n\t\t\t\tcommand: call.args.command,\n\t\t\t\ttimeout: cursorPiTimeout(call.args.timeout),\n\t\t\t}),\n\n\t\tpiEdit: async (call) =>\n\t\t\texecuteTool(options, \"edit\", call.toolCallId, {\n\t\t\t\tpath: call.args.path,\n\t\t\t\tedits: call.args.edits.map((edit) => ({ oldText: edit.oldText, newText: edit.newText })),\n\t\t\t}),\n\n\t\tpiWrite: async (call) =>\n\t\t\texecuteTool(options, \"write\", call.toolCallId, {\n\t\t\t\tpath: call.args.path,\n\t\t\t\tcontent: call.args.content,\n\t\t\t}),\n\n\t\tpiGrep: async (call) =>\n\t\t\texecuteTool(options, \"grep\", call.toolCallId, {\n\t\t\t\tpattern: call.args.pattern,\n\t\t\t\tpath: call.args.path || undefined,\n\t\t\t\tglob: call.args.glob || undefined,\n\t\t\t\tignoreCase: call.args.ignoreCase === true ? true : undefined,\n\t\t\t\tliteral: call.args.literal === true ? true : undefined,\n\t\t\t\tcontext: call.args.context,\n\t\t\t\tlimit: cursorPiLimit(call.args.limit),\n\t\t\t}),\n\n\t\tpiFind: async (call) =>\n\t\t\texecuteTool(options, \"find\", call.toolCallId, {\n\t\t\t\tpattern: call.args.pattern,\n\t\t\t\tpath: call.args.path || undefined,\n\t\t\t\tlimit: cursorPiLimit(call.args.limit),\n\t\t\t}),\n\n\t\tpiLs: async (call) =>\n\t\t\texecuteTool(options, \"ls\", call.toolCallId, {\n\t\t\t\tpath: cursorPiLsPath(call.args.path),\n\t\t\t\tlimit: cursorPiLimit(call.args.limit),\n\t\t\t}),\n\t};\n}\n"]}
1
+ {"version":3,"file":"cursor-exec-bridge.js","sourceRoot":"","sources":["../../src/core/cursor-exec-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAEN,yBAAyB,EACzB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EAEvB,qBAAqB,GACrB,MAAM,uBAAuB,CAAC;AAuB/B,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,WAAW,CAAC,UAAkB,EAAE,QAAgB,EAAE,IAAY;IACtE,OAAO;QACN,IAAI,EAAE,YAAY;QAClB,UAAU;QACV,QAAQ;QACR,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACjC,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACrB,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,UAAkB,EAAE,QAAgB;IACxD,OAAO;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EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,SAAS;YACjC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;SACrC,CAAC;QAEH,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACpB,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE;YAC3C,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACpC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;SACrC,CAAC;KACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * Cursor exec-channel → local tool bridge.\n *\n * Cursor's agent protocol executes tools server-drivenly: mid-stream, the\n * server sends exec frames and blocks until the client answers in band. The\n * `cursor-agent` API dispatches those frames onto this bridge, which maps\n * each frame's args onto the session's real tools (`read`, `bash`, `edit`,\n * `write`, `grep`, `find`, `ls`, plus MCP/extension tools by name) and runs\n * them through the same wrapped `AgentTool.execute` path model-issued calls\n * use — so approvals, sandboxing, truncation, and rendering behavior stay\n * identical.\n *\n * The arg translations here MUST mirror the display blocks the API\n * synthesizes (`synthesizeCursorExecToolCall` call sites): the transcript\n * shows one operation, so a different one must not run.\n */\n\nimport type { AgentEvent, AgentTool, AgentToolCall } from \"@earendil-works/pi-agent-core\";\nimport {\n\ttype CursorExecHandlers,\n\tcomposeCursorShellCommand,\n\tcursorPiLimit,\n\tcursorPiLsPath,\n\tcursorPiReadArgs,\n\tcursorPiTimeout,\n\tomitUndefinedCursorArgs,\n\ttype ToolResultMessage,\n\tvalidateToolArguments,\n} from \"@earendil-works/pi-ai\";\nimport type { ToolCallEvent, ToolCallEventResult } from \"./extensions/types.ts\";\n\nexport interface CursorExecBridgeOptions {\n\t/**\n\t * Resolve an executable tool by name. Backed by the session's full tool\n\t * registry (builtin + extension tools), not only the active set: Cursor\n\t * drives its native tools (read/bash/grep/ls/write) over the exec channel\n\t * regardless of which tools the request advertised.\n\t */\n\tgetTool: (name: string) => AgentTool | undefined;\n\t/**\n\t * Surface tool lifecycle events to the host UI. Bridge-run tools bypass\n\t * the agent loop's executor, so without these the live tool card for a\n\t * synthesized call never resolves.\n\t */\n\temitEvent: (event: AgentEvent, runSignal: AbortSignal) => Promise<void>;\n\t/** Run the session's vetoable extension preflight before tool execution. */\n\tpreflightToolCall?: (event: ToolCallEvent) => Promise<ToolCallEventResult | undefined>;\n\t/** Abort signal for in-flight bridge executions (the active run's signal). */\n\tgetAbortSignal: () => AbortSignal | undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction errorResult(toolCallId: string, toolName: string, text: string): ToolResultMessage {\n\treturn {\n\t\trole: \"toolResult\",\n\t\ttoolCallId,\n\t\ttoolName,\n\t\tcontent: [{ type: \"text\", text }],\n\t\tisError: true,\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction emptyResult(toolCallId: string, toolName: string): ToolResultMessage {\n\treturn {\n\t\trole: \"toolResult\",\n\t\ttoolCallId,\n\t\ttoolName,\n\t\tcontent: [{ type: \"text\", text: \"\" }],\n\t\tisError: false,\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nasync function executeTool(\n\toptions: CursorExecBridgeOptions,\n\ttoolName: string,\n\ttoolCallId: string,\n\targs: Record<string, unknown>,\n): Promise<ToolResultMessage> {\n\tconst runSignal = options.getAbortSignal();\n\tif (!runSignal) {\n\t\treturn errorResult(toolCallId, toolName, \"Tool execution has no active run\");\n\t}\n\n\tconst tool = options.getTool(toolName);\n\tif (!tool) {\n\t\treturn errorResult(toolCallId, toolName, `Tool \"${toolName}\" is not available in this session`);\n\t}\n\n\t// Exec-frame translators write forms like `path: args.path || undefined`;\n\t// a present `undefined` fails schema validation on optional fields even\n\t// though omitting the key is valid.\n\tconst cleanArgs = omitUndefinedCursorArgs(args);\n\tconst toolCall: AgentToolCall = {\n\t\ttype: \"toolCall\",\n\t\tid: toolCallId,\n\t\tname: toolName,\n\t\targuments: cleanArgs,\n\t};\n\n\tlet params: unknown;\n\ttry {\n\t\tparams = validateToolArguments(tool, toolCall);\n\t\tif (tool.prepareArguments) {\n\t\t\tparams = tool.prepareArguments(params);\n\t\t}\n\t} catch (error) {\n\t\treturn errorResult(toolCallId, toolName, error instanceof Error ? error.message : String(error));\n\t}\n\n\tawait options.emitEvent({ type: \"tool_execution_start\", toolCallId, toolName, args: cleanArgs }, runSignal);\n\tlet toolResult: ToolResultMessage;\n\tlet endEvent: AgentEvent;\n\ttry {\n\t\tif (!isRecord(params)) {\n\t\t\tthrow new Error(`Tool \"${toolName}\" prepared non-object arguments`);\n\t\t}\n\t\tconst preflight = await options.preflightToolCall?.({\n\t\t\ttype: \"tool_call\",\n\t\t\ttoolCallId,\n\t\t\ttoolName,\n\t\t\tinput: params,\n\t\t});\n\t\tif (preflight?.block) {\n\t\t\tconst message = preflight.reason || \"Tool execution was blocked\";\n\t\t\ttoolResult = errorResult(toolCallId, toolName, message);\n\t\t\tendEvent = {\n\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\ttoolCallId,\n\t\t\t\ttoolName,\n\t\t\t\tresult: { content: [{ type: \"text\", text: message }], details: undefined },\n\t\t\t\tisError: true,\n\t\t\t};\n\t\t} else {\n\t\t\tconst result = await tool.execute(toolCallId, params, runSignal, undefined);\n\t\t\ttoolResult = {\n\t\t\t\trole: \"toolResult\",\n\t\t\t\ttoolCallId,\n\t\t\t\ttoolName,\n\t\t\t\tcontent: result.content ?? [],\n\t\t\t\tdetails: result.details,\n\t\t\t\tusage: result.usage,\n\t\t\t\tisError: false,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t};\n\t\t\tendEvent = { type: \"tool_execution_end\", toolCallId, toolName, result, isError: false };\n\t\t}\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\ttoolResult = errorResult(toolCallId, toolName, message);\n\t\tendEvent = {\n\t\t\ttype: \"tool_execution_end\",\n\t\t\ttoolCallId,\n\t\t\ttoolName,\n\t\t\tresult: { content: [{ type: \"text\", text: message }], details: undefined },\n\t\t\tisError: true,\n\t\t};\n\t}\n\tawait options.emitEvent(endEvent, runSignal);\n\treturn toolResult;\n}\n\n/**\n * Build the exec handlers passed to the `cursor-agent` API through the agent\n * loop config. Handlers return bare `ToolResultMessage`s; the API derives the\n * wire protobuf answer from them and pairs the transcript result.\n *\n * Deliberately absent handlers (the API answers with a typed refusal):\n * - `delete`: senpi has no delete tool and the bridge must not mutate the\n * filesystem outside the tool/approval path.\n * - `diagnostics`: no LSP tool in this fork.\n * - `mcpApprovalPreflight`: approval decisions cannot be resolved without an\n * interactive prompt, so smart-mode probes are conservatively refused.\n */\nexport function createCursorExecBridge(options: CursorExecBridgeOptions): CursorExecHandlers {\n\treturn {\n\t\tread: async (args) =>\n\t\t\texecuteTool(options, \"read\", args.toolCallId, {\n\t\t\t\tpath: args.path,\n\t\t\t\toffset: args.offset,\n\t\t\t\tlimit: args.limit,\n\t\t\t}),\n\n\t\tls: async (args) => executeTool(options, \"ls\", args.toolCallId, { path: cursorPiLsPath(args.path) }),\n\n\t\tgrep: async (args) =>\n\t\t\texecuteTool(options, \"grep\", args.toolCallId, {\n\t\t\t\tpattern: args.pattern,\n\t\t\t\tpath: args.path || undefined,\n\t\t\t\tglob: args.glob || undefined,\n\t\t\t\tignoreCase: args.caseInsensitive === true ? true : undefined,\n\t\t\t}),\n\n\t\twrite: async (args) =>\n\t\t\texecuteTool(options, \"write\", args.toolCallId, {\n\t\t\t\tpath: args.path,\n\t\t\t\tcontent: args.fileText ?? new TextDecoder().decode(args.fileBytes ?? new Uint8Array()),\n\t\t\t}),\n\n\t\tshell: async (args) =>\n\t\t\texecuteTool(options, \"bash\", args.toolCallId, {\n\t\t\t\tcommand: composeCursorShellCommand(args.command, args.workingDirectory || undefined),\n\t\t\t\ttimeout: args.timeout && args.timeout > 0 ? args.timeout : undefined,\n\t\t\t}),\n\n\t\tmcp: async (call) => {\n\t\t\tconst toolName = call.toolName || call.name;\n\t\t\tconst tool = options.getTool(toolName);\n\t\t\tif (!tool) {\n\t\t\t\treturn errorResult(call.toolCallId, toolName, `Tool \"${toolName}\" is not registered in this session`);\n\t\t\t}\n\t\t\treturn executeTool(options, toolName, call.toolCallId, call.args);\n\t\t},\n\n\t\tpiRead: async (call) => {\n\t\t\tconst readArgs = cursorPiReadArgs(call.args.path, call.args.offset, call.args.limit);\n\t\t\t// A present `limit: 0` reads zero lines; answer with empty output\n\t\t\t// without running the tool rather than degrading into a full read.\n\t\t\tif (readArgs === null) return emptyResult(call.toolCallId, \"read\");\n\t\t\treturn executeTool(options, \"read\", call.toolCallId, readArgs);\n\t\t},\n\n\t\tpiBash: async (call) =>\n\t\t\texecuteTool(options, \"bash\", call.toolCallId, {\n\t\t\t\tcommand: call.args.command,\n\t\t\t\ttimeout: cursorPiTimeout(call.args.timeout),\n\t\t\t}),\n\n\t\tpiEdit: async (call) =>\n\t\t\texecuteTool(options, \"edit\", call.toolCallId, {\n\t\t\t\tpath: call.args.path,\n\t\t\t\tedits: call.args.edits.map((edit) => ({ oldText: edit.oldText, newText: edit.newText })),\n\t\t\t}),\n\n\t\tpiWrite: async (call) =>\n\t\t\texecuteTool(options, \"write\", call.toolCallId, {\n\t\t\t\tpath: call.args.path,\n\t\t\t\tcontent: call.args.content,\n\t\t\t}),\n\n\t\tpiGrep: async (call) =>\n\t\t\texecuteTool(options, \"grep\", call.toolCallId, {\n\t\t\t\tpattern: call.args.pattern,\n\t\t\t\tpath: call.args.path || undefined,\n\t\t\t\tglob: call.args.glob || undefined,\n\t\t\t\tignoreCase: call.args.ignoreCase === true ? true : undefined,\n\t\t\t\tliteral: call.args.literal === true ? true : undefined,\n\t\t\t\tcontext: call.args.context,\n\t\t\t\tlimit: cursorPiLimit(call.args.limit),\n\t\t\t}),\n\n\t\tpiFind: async (call) =>\n\t\t\texecuteTool(options, \"find\", call.toolCallId, {\n\t\t\t\tpattern: call.args.pattern,\n\t\t\t\tpath: call.args.path || undefined,\n\t\t\t\tlimit: cursorPiLimit(call.args.limit),\n\t\t\t}),\n\n\t\tpiLs: async (call) =>\n\t\t\texecuteTool(options, \"ls\", call.toolCallId, {\n\t\t\t\tpath: cursorPiLsPath(call.args.path),\n\t\t\t\tlimit: cursorPiLimit(call.args.limit),\n\t\t\t}),\n\t};\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { Credential } from "@earendil-works/pi-ai";
2
2
  import type { ExtensionAPI } from "../../types.ts";
3
3
  import { type CursorCliGenerationGuard } from "./diagnostics.ts";
4
- import { importLocalCursorCredential, type LocalCursorImportDeps } from "./oauth-login.ts";
4
+ import { importLocalCursorCredential, importNativeCursorCredential, type LocalCursorImportDeps } from "./oauth-login.ts";
5
5
  import { type CursorCliSessionRouter } from "./session-router.ts";
6
6
  import { type CursorCliOauthProviderSettings } from "./settings.ts";
7
7
  /** Injectable seams; every default resolves real on-disk state at invocation time. */
@@ -12,9 +12,12 @@ export type CursorCliAccountCommandDeps = {
12
12
  readonly probeVersion?: (executable: string) => Promise<string>;
13
13
  readonly readNativeCredential?: () => Credential | undefined | Promise<Credential | undefined>;
14
14
  readonly importCredential?: typeof importLocalCursorCredential;
15
+ readonly importNativeCredential?: typeof importNativeCursorCredential;
15
16
  readonly importDeps?: LocalCursorImportDeps;
16
17
  /** Acknowledgement persistence seam; the default read-modify-writes the global settings file. */
17
18
  readonly persistAcknowledgement?: (cwd: string, acknowledgedAt: string) => void;
19
+ /** Enablement persistence seam; explicit login/import actions activate the fallback lane. */
20
+ readonly persistEnabled?: (cwd: string, enabled: boolean) => void;
18
21
  readonly now?: () => number;
19
22
  readonly generation?: CursorCliGenerationGuard;
20
23
  };
@@ -1 +1 @@
1
- {"version":3,"file":"account-command.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/cursor-cli-oauth/account-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UA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AAsB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IAChF,6FAA6F;IAC7F,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAClE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,wBAAwB,CAAC;CAC/C,CAAC;AAiCF;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,GAAE,2BAAgC,GAAG,IAAI,CAyD9G"}
@@ -2,10 +2,10 @@ import { emitProviderAccountsChanged } from "../claude-sdk-oauth/account-events.
2
2
  import { emptyCredential, listAccounts, pinAccount, removeAccount, } from "./accounts.js";
3
3
  import { selectAccount } from "./affinity.js";
4
4
  import { collectCursorCliStatus, NATIVE_CURSOR_PROVIDER_ID, registerCursorCliShutdownSafety, renderCursorCliStatus, } from "./diagnostics.js";
5
- import { CURSOR_CLI_OAUTH_PROVIDER_ID, confirmCursorCliNoApprovalAcknowledgement, importLocalCursorCredential, } from "./oauth-login.js";
5
+ import { CURSOR_CLI_OAUTH_PROVIDER_ID, confirmCursorCliNoApprovalAcknowledgement, importLocalCursorCredential, importNativeCursorCredential, } from "./oauth-login.js";
6
6
  import { cursorCliSessionRouter } from "./session-router.js";
7
- import { loadCursorCliOauthProviderSettingsFromDisk, persistCursorCliNoApprovalAcknowledgement, } from "./settings.js";
8
- const USAGE = "Usage: /cursor-account [list | add | remove <name> | pin <name> | unpin | import | acknowledge | status]";
7
+ import { loadCursorCliOauthProviderSettingsFromDisk, persistCursorCliNoApprovalAcknowledgement, persistCursorCliOauthEnabled, } from "./settings.js";
8
+ const USAGE = "Usage: /cursor-account [list | add | remove <name> | pin <name> | unpin | import [local | native] | acknowledge | status]";
9
9
  function asCursorCredential(value) {
10
10
  return value !== undefined && value.type === "oauth" ? value : emptyCredential();
11
11
  }
@@ -72,7 +72,12 @@ export function registerCursorCliAccountCommand(pi, deps = {}) {
72
72
  return;
73
73
  }
74
74
  if (action === "import") {
75
- await importAccount(ctx, deps);
75
+ const source = args[1] ?? "local";
76
+ if (source !== "local" && source !== "native") {
77
+ ctx.ui.notify(USAGE, "error");
78
+ return;
79
+ }
80
+ await importAccount(ctx, deps, source);
76
81
  return;
77
82
  }
78
83
  if (action === "acknowledge") {
@@ -217,8 +222,9 @@ async function unpinAccount(ctx) {
217
222
  emitProviderAccountsChanged(CURSOR_CLI_OAUTH_PROVIDER_ID);
218
223
  ctx.ui.notify("Unpinned Cursor CLI (OAuth) account.", "info");
219
224
  }
220
- async function importAccount(ctx, deps) {
225
+ async function importAccount(ctx, deps, source) {
221
226
  const importCredential = deps.importCredential ?? importLocalCursorCredential;
227
+ const importNativeCredential = deps.importNativeCredential ?? importNativeCursorCredential;
222
228
  const importDeps = { ...deps.importDeps };
223
229
  if (importDeps.onPrompt === undefined && ctx.hasUI) {
224
230
  importDeps.onPrompt = async (prompt) => {
@@ -232,7 +238,9 @@ async function importAccount(ctx, deps) {
232
238
  try {
233
239
  await ctx.modelRegistry.authStorage.modify(CURSOR_CLI_OAUTH_PROVIDER_ID, async (current) => {
234
240
  const before = asCursorCredential(current);
235
- const updated = await importCredential(before, importDeps);
241
+ const updated = source === "native"
242
+ ? await importNativeCredential(before, deps.readNativeCredential ?? (() => ctx.modelRegistry.authStorage.get(NATIVE_CURSOR_PROVIDER_ID)))
243
+ : await importCredential(before, importDeps);
236
244
  const existing = new Set(listAccounts(before).map((account) => account.name));
237
245
  importedName = listAccounts(updated).find((account) => !existing.has(account.name))?.name;
238
246
  return updated;
@@ -242,8 +250,20 @@ async function importAccount(ctx, deps) {
242
250
  ctx.ui.notify(`Failed to import local Cursor credential: ${error instanceof Error ? error.message : String(error)}`, "error");
243
251
  return;
244
252
  }
253
+ const persistEnabled = deps.persistEnabled ?? persistCursorCliOauthEnabled;
254
+ try {
255
+ persistEnabled(ctx.cwd, true);
256
+ await ctx.modelRegistry.modelRuntime.refresh({
257
+ allowNetwork: false,
258
+ providers: [CURSOR_CLI_OAUTH_PROVIDER_ID],
259
+ });
260
+ }
261
+ catch (error) {
262
+ ctx.ui.notify(`Imported ${source === "native" ? "native " : ""}Cursor credential, but provider activation failed: ${error instanceof Error ? error.message : String(error)}`, "warning");
263
+ return;
264
+ }
245
265
  emitProviderAccountsChanged(CURSOR_CLI_OAUTH_PROVIDER_ID);
246
- ctx.ui.notify(`Imported local Cursor credential as '${importedName ?? "a new account"}' (copied into this provider's store).`, "info");
266
+ ctx.ui.notify(`Imported ${source === "native" ? "native " : "local "}Cursor credential as '${importedName ?? "a new account"}' (copied into this provider's store).`, "info");
247
267
  }
248
268
  async function acknowledgeNoApproval(ctx, deps, generation) {
249
269
  if (!ctx.hasUI) {
@@ -1 +1 @@
1
- {"version":3,"file":"account-command.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/cursor-cli-oauth/account-command.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAGN,eAAe,EACf,YAAY,EACZ,UAAU,EACV,aAAa,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAEN,sBAAsB,EACtB,yBAAyB,EACzB,+BAA+B,EAC/B,qBAAqB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,4BAA4B,EAC5B,yCAAyC,EACzC,2BAA2B,GAE3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAA+B,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC1F,OAAO,EAEN,0CAA0C,EAC1C,yCAAyC,GACzC,MAAM,eAAe,CAAC;AAiBvB,MAAM,KAAK,GACV,0GAA0G,CAAC;AAE5G,SAAS,kBAAkB,CAAC,KAA6B;IACxD,O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C,EACjC,KAIC;IAED,2EAA2E;IAC3E,0EAA0E;IAC1E,MAAM,SAAS,GAAG,GAAG,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC;IACpD,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC;QAC3C,SAAS;QACT,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC;QACrC,cAAc,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,WAAW,CAAC,GAAG,CAAC,4BAA4B,CAAC;QACrF,oBAAoB,EACnB,IAAI,CAAC,oBAAoB,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,WAAW,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;QAClG,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,sBAAsB;QAC7C,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;QACzC,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,GAAG,EAAE,KAAK,CAAC,GAAG;KACd,CAAC,CAAC;IACH,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACjG,CAAC","sourcesContent":["import type { Credential } from \"@earendil-works/pi-ai\";\nimport type { ExtensionAPI, ExtensionCommandContext } from \"../../types.ts\";\nimport { emitProviderAccountsChanged } from \"../claude-sdk-oauth/account-events.ts\";\nimport {\n\ttype CursorCliAccountSlot,\n\ttype CursorCliOauthCredential,\n\temptyCredential,\n\tlistAccounts,\n\tpinAccount,\n\tremoveAccount,\n} from \"./accounts.ts\";\nimport { selectAccount } from \"./affinity.ts\";\nimport {\n\ttype CursorCliGenerationGuard,\n\tcollectCursorCliStatus,\n\tNATIVE_CURSOR_PROVIDER_ID,\n\tregisterCursorCliShutdownSafety,\n\trenderCursorCliStatus,\n} from \"./diagnostics.ts\";\nimport {\n\tCURSOR_CLI_OAUTH_PROVIDER_ID,\n\tconfirmCursorCliNoApprovalAcknowledgement,\n\timportLocalCursorCredential,\n\ttype LocalCursorImportDeps,\n} from \"./oauth-login.ts\";\nimport { type CursorCliSessionRouter, cursorCliSessionRouter } from \"./session-router.ts\";\nimport {\n\ttype CursorCliOauthProviderSettings,\n\tloadCursorCliOauthProviderSettingsFromDisk,\n\tpersistCursorCliNoApprovalAcknowledgement,\n} from \"./settings.ts\";\n\n/** Injectable seams; every default resolves real on-disk state at invocation time. */\nexport type CursorCliAccountCommandDeps = {\n\treadonly loadSettings?: (cwd: string) => CursorCliOauthProviderSettings;\n\treadonly router?: CursorCliSessionRouter;\n\treadonly resolveExecutable?: (settings: CursorCliOauthProviderSettings) => string;\n\treadonly probeVersion?: (executable: string) => Promise<string>;\n\treadonly readNativeCredential?: () => Credential | undefined | Promise<Credential | undefined>;\n\treadonly importCredential?: typeof importLocalCursorCredential;\n\treadonly importDeps?: LocalCursorImportDeps;\n\t/** Acknowledgement persistence seam; the default read-modify-writes the global settings file. */\n\treadonly persistAcknowledgement?: (cwd: string, acknowledgedAt: string) => void;\n\treadonly now?: () => number;\n\treadonly generation?: CursorCliGenerationGuard;\n};\n\nconst USAGE =\n\t\"Usage: /cursor-account [list | add | remove <name> | pin <name> | unpin | import | acknowledge | status]\";\n\nfunction asCursorCredential(value: Credential | undefined): CursorCliOauthCredential {\n\treturn value !== undefined && value.type === \"oauth\" ? (value as CursorCliOauthCredential) : emptyCredential();\n}\n\nfunction parseArgs(rawArgs: string): string[] {\n\treturn rawArgs.trim().split(/\\s+/).filter(Boolean);\n}\n\nfunction slotStatus(slot: CursorCliAccountSlot, now: number): string {\n\tif (slot.blockReason === \"auth_error\") return \"blocked until re-login\";\n\tif (slot.blockedUntil !== undefined && slot.blockedUntil > now) {\n\t\treturn `blocked until ${new Date(slot.blockedUntil).toISOString()} (${slot.blockReason ?? \"rate_limit\"})`;\n\t}\n\treturn \"available\";\n}\n\nfunction authEventMessage(event: unknown): string {\n\tif (event === null || typeof event !== \"object\") return \"Cursor CLI (OAuth) authentication update.\";\n\tconst value = event as Record<string, unknown>;\n\tif (value.type === \"auth_url\" && typeof value.url === \"string\") {\n\t\treturn `Open this URL to authorize Cursor CLI (OAuth):\\n${value.url}`;\n\t}\n\tif (value.type === \"device_code\" && typeof value.verificationUri === \"string\") {\n\t\treturn `Open this URL to authorize Cursor CLI (OAuth):\\n${value.verificationUri}`;\n\t}\n\treturn typeof value.message === \"string\" ? value.message : \"Cursor CLI (OAuth) authentication update.\";\n}\n\n/**\n * Registers `/cursor-account` plus the reload/shutdown teardown for this\n * extension generation: the command reads account state fresh from the\n * credential store on every invocation, and every deferred continuation is\n * fenced so a retired generation is never touched after a reload.\n */\nexport function registerCursorCliAccountCommand(pi: ExtensionAPI, deps: CursorCliAccountCommandDeps = {}): void {\n\tconst loadSettings = deps.loadSettings ?? ((cwd: string) => loadCursorCliOauthProviderSettingsFromDisk(cwd));\n\tconst now = deps.now ?? Date.now;\n\t// One guard per registration: a reload rebuilds the extension and gets a\n\t// fresh fence, while the child registry stays process-wide.\n\tconst generation = registerCursorCliShutdownSafety(pi, { generation: deps.generation });\n\n\tpi.registerCommand(\"cursor-account\", {\n\t\tdescription: \"List and manage Cursor CLI (OAuth) accounts.\",\n\t\targumentHint: \"[list | add | remove <name> | pin <name> | unpin | import | acknowledge | status]\",\n\t\thandler: async (rawArgs: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\ttry {\n\t\t\t\tconst args = parseArgs(rawArgs);\n\t\t\t\tconst action = args[0] ?? \"list\";\n\t\t\t\tif (action === \"list\") {\n\t\t\t\t\tshowAccounts(ctx, loadSettings(ctx.cwd), generation, now);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"add\") {\n\t\t\t\t\tawait addAccount(ctx);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"remove\") {\n\t\t\t\t\tawait removeNamedAccount(ctx, args[1]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"pin\" && args[1] !== undefined) {\n\t\t\t\t\tawait pinNamedAccount(ctx, args[1]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"unpin\") {\n\t\t\t\t\tawait unpinAccount(ctx);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"import\") {\n\t\t\t\t\tawait importAccount(ctx, deps);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"acknowledge\") {\n\t\t\t\t\tawait acknowledgeNoApproval(ctx, deps, generation);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"status\") {\n\t\t\t\t\tawait showStatus(ctx, deps, { loadSettings, generation, now });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tctx.ui.notify(USAGE, \"error\");\n\t\t\t} catch (error) {\n\t\t\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\t\t}\n\t\t},\n\t});\n}\n\nfunction showAccounts(\n\tctx: ExtensionCommandContext,\n\tsettings: CursorCliOauthProviderSettings,\n\tgeneration: CursorCliGenerationGuard,\n\tnow: () => number,\n): void {\n\tconst credential = asCursorCredential(ctx.modelRegistry.authStorage.get(CURSOR_CLI_OAUTH_PROVIDER_ID));\n\tconst accounts = listAccounts(credential);\n\tconst pinned = settings.pinnedAccount ?? credential.pinned;\n\tconst pinSource = settings.pinnedAccount !== undefined ? \"settings\" : \"stored\";\n\tlet affinityPick: string | undefined;\n\tlet affinityError: string | undefined;\n\tif (accounts.length > 0) {\n\t\ttry {\n\t\t\taffinityPick = selectAccount(accounts, {\n\t\t\t\tsessionId: ctx.sessionManager.getSessionId(),\n\t\t\t\tpinnedAccount: pinned,\n\t\t\t\tnow: now(),\n\t\t\t}).name;\n\t\t} catch (error) {\n\t\t\taffinityError = error instanceof Error ? error.message : String(error);\n\t\t}\n\t}\n\tconst lines = [\"Cursor CLI (OAuth) accounts:\"];\n\tif (accounts.length === 0) lines.push(\" (none)\");\n\tfor (const account of accounts) {\n\t\tconst states = [account.name, account.source, slotStatus(account, now())];\n\t\tif (account.name === pinned) states.push(\"pinned\");\n\t\tif (account.name === affinityPick) states.push(\"affinity pick\");\n\t\tlines.push(` ${states.join(\" | \")}`);\n\t}\n\tlines.push(`Pinned account: ${pinned === undefined ? \"none\" : `${pinned} (${pinSource})`}`);\n\tlines.push(`Affinity pick: ${affinityPick ?? (affinityError ? `unavailable - ${affinityError}` : \"none\")}`);\n\tgeneration.runFencedSync(ctx, () => ctx.ui.notify(lines.join(\"\\n\"), \"info\"));\n}\n\nasync function addAccount(ctx: ExtensionCommandContext): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tctx.ui.notify(\"/cursor-account add requires an interactive UI.\", \"error\");\n\t\treturn;\n\t}\n\ttry {\n\t\tawait ctx.modelRegistry.modelRuntime.login(CURSOR_CLI_OAUTH_PROVIDER_ID, \"oauth\", {\n\t\t\tsignal: ctx.signal,\n\t\t\tprompt: async (prompt: { message: string }) => {\n\t\t\t\tconst answer = await ctx.ui.input(prompt.message);\n\t\t\t\tif (answer === undefined) throw new Error(\"Login cancelled\");\n\t\t\t\treturn answer;\n\t\t\t},\n\t\t\tnotify: (event: unknown) => ctx.ui.notify(authEventMessage(event), \"info\"),\n\t\t});\n\t\temitProviderAccountsChanged(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\t\tctx.ui.notify(\"Cursor CLI (OAuth) account added.\", \"info\");\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tif (message !== \"Login cancelled\") {\n\t\t\tctx.ui.notify(`Failed to add Cursor CLI (OAuth) account: ${message}`, \"error\");\n\t\t}\n\t}\n}\n\nasync function removeNamedAccount(ctx: ExtensionCommandContext, name: string | undefined): Promise<void> {\n\tif (!name) {\n\t\tctx.ui.notify(\"Usage: /cursor-account remove <name>\", \"error\");\n\t\treturn;\n\t}\n\tlet removed = false;\n\ttry {\n\t\tawait ctx.modelRegistry.authStorage.modify(CURSOR_CLI_OAUTH_PROVIDER_ID, async (current) => {\n\t\t\tconst credential = asCursorCredential(current);\n\t\t\tif (!listAccounts(credential).some((account) => account.name === name)) return current;\n\t\t\tremoved = true;\n\t\t\treturn removeAccount(credential, name);\n\t\t});\n\t} catch (error) {\n\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\treturn;\n\t}\n\tif (!removed) {\n\t\tctx.ui.notify(`Cursor CLI (OAuth) account '${name}' does not exist.`, \"error\");\n\t\treturn;\n\t}\n\temitProviderAccountsChanged(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\tctx.ui.notify(`Removed Cursor CLI (OAuth) account: ${name}.`, \"info\");\n}\n\nasync function pinNamedAccount(ctx: ExtensionCommandContext, name: string): Promise<void> {\n\ttry {\n\t\tawait ctx.modelRegistry.authStorage.modify(CURSOR_CLI_OAUTH_PROVIDER_ID, async (current) => {\n\t\t\tconst credential = asCursorCredential(current);\n\t\t\tif (!listAccounts(credential).some((account) => account.name === name)) {\n\t\t\t\tthrow new Error(`Cursor CLI (OAuth) account '${name}' does not exist.`);\n\t\t\t}\n\t\t\treturn pinAccount(credential, name);\n\t\t});\n\t} catch (error) {\n\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\treturn;\n\t}\n\temitProviderAccountsChanged(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\tctx.ui.notify(`Pinned Cursor CLI (OAuth) account: ${name}.`, \"info\");\n}\n\nasync function unpinAccount(ctx: ExtensionCommandContext): Promise<void> {\n\tlet hadPin = false;\n\ttry {\n\t\tawait ctx.modelRegistry.authStorage.modify(CURSOR_CLI_OAUTH_PROVIDER_ID, async (current) => {\n\t\t\tconst credential = asCursorCredential(current);\n\t\t\tif (credential.pinned === undefined) return current;\n\t\t\thadPin = true;\n\t\t\tconst { pinned: _pinned, ...unpinned } = credential;\n\t\t\treturn unpinned;\n\t\t});\n\t} catch (error) {\n\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\treturn;\n\t}\n\tif (!hadPin) {\n\t\tctx.ui.notify(\"No stored Cursor CLI (OAuth) account pin is set.\", \"info\");\n\t\treturn;\n\t}\n\temitProviderAccountsChanged(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\tctx.ui.notify(\"Unpinned Cursor CLI (OAuth) account.\", \"info\");\n}\n\nasync function importAccount(ctx: ExtensionCommandContext, deps: CursorCliAccountCommandDeps): Promise<void> {\n\tconst importCredential = deps.importCredential ?? importLocalCursorCredential;\n\tconst importDeps: LocalCursorImportDeps = { ...deps.importDeps };\n\tif (importDeps.onPrompt === undefined && ctx.hasUI) {\n\t\timportDeps.onPrompt = async (prompt: { message: string }) => {\n\t\t\tconst answer = await ctx.ui.input(prompt.message);\n\t\t\tif (answer === undefined) throw new Error(\"Import cancelled\");\n\t\t\treturn answer;\n\t\t};\n\t}\n\tlet importedName: string | undefined;\n\ttry {\n\t\tawait ctx.modelRegistry.authStorage.modify(CURSOR_CLI_OAUTH_PROVIDER_ID, async (current) => {\n\t\t\tconst before = asCursorCredential(current);\n\t\t\tconst updated = await importCredential(before, importDeps);\n\t\t\tconst existing = new Set(listAccounts(before).map((account) => account.name));\n\t\t\timportedName = listAccounts(updated).find((account) => !existing.has(account.name))?.name;\n\t\t\treturn updated;\n\t\t});\n\t} catch (error) {\n\t\tctx.ui.notify(\n\t\t\t`Failed to import local Cursor credential: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\"error\",\n\t\t);\n\t\treturn;\n\t}\n\temitProviderAccountsChanged(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\tctx.ui.notify(\n\t\t`Imported local Cursor credential as '${importedName ?? \"a new account\"}' (copied into this provider's store).`,\n\t\t\"info\",\n\t);\n}\n\nasync function acknowledgeNoApproval(\n\tctx: ExtensionCommandContext,\n\tdeps: CursorCliAccountCommandDeps,\n\tgeneration: CursorCliGenerationGuard,\n): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tctx.ui.notify(\"/cursor-account acknowledge requires an interactive UI.\", \"error\");\n\t\treturn;\n\t}\n\tconst persist = deps.persistAcknowledgement ?? persistCursorCliNoApprovalAcknowledgement;\n\tconst acknowledgedAt = await confirmCursorCliNoApprovalAcknowledgement(\n\t\tasync (ask) => (await ctx.ui.input(ask.message)) ?? \"\",\n\t\t() => new Date((deps.now ?? Date.now)()),\n\t);\n\tif (acknowledgedAt === undefined) {\n\t\tgeneration.runFencedSync(ctx, () =>\n\t\t\tctx.ui.notify(\n\t\t\t\t\"No acknowledgement written: unattended Cursor CLI execution stays off until you acknowledge.\",\n\t\t\t\t\"info\",\n\t\t\t),\n\t\t);\n\t\treturn;\n\t}\n\tpersist(ctx.cwd, acknowledgedAt);\n\tgeneration.runFencedSync(ctx, () =>\n\t\tctx.ui.notify(`Acknowledged unattended Cursor CLI tool execution at ${acknowledgedAt}.`, \"info\"),\n\t);\n}\n\nasync function showStatus(\n\tctx: ExtensionCommandContext,\n\tdeps: CursorCliAccountCommandDeps,\n\tbound: {\n\t\tloadSettings: (cwd: string) => CursorCliOauthProviderSettings;\n\t\tgeneration: CursorCliGenerationGuard;\n\t\tnow: () => number;\n\t},\n): Promise<void> {\n\t// Context reads happen before any await; the render continuation is fenced\n\t// so a reload during the version probe can never touch a retired context.\n\tconst sessionId = ctx.sessionManager.getSessionId();\n\tconst report = await collectCursorCliStatus({\n\t\tsessionId,\n\t\tsettings: bound.loadSettings(ctx.cwd),\n\t\treadCredential: () => ctx.modelRegistry.authStorage.get(CURSOR_CLI_OAUTH_PROVIDER_ID),\n\t\treadNativeCredential:\n\t\t\tdeps.readNativeCredential ?? (() => ctx.modelRegistry.authStorage.get(NATIVE_CURSOR_PROVIDER_ID)),\n\t\trouter: deps.router ?? cursorCliSessionRouter,\n\t\tresolveExecutable: deps.resolveExecutable,\n\t\tprobeVersion: deps.probeVersion,\n\t\tnow: bound.now,\n\t});\n\tbound.generation.runFencedSync(ctx, () => ctx.ui.notify(renderCursorCliStatus(report), \"info\"));\n}\n"]}
1
+ {"version":3,"file":"account-command.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/cursor-cli-oauth/account-command.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAGN,eAAe,EACf,YAAY,EACZ,UAAU,EACV,aAAa,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAEN,sBAAsB,EACtB,yBAAyB,EACzB,+BAA+B,EAC/B,qBAAqB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,4BAA4B,EAC5B,yCAAyC,EACzC,2BAA2B,EAC3B,4BAA4B,GAE5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAA+B,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC1F,OAAO,EAEN,0CAA0C,EAC1C,yCAAyC,EACzC,4BAA4B,GAC5B,MAAM,eAAe,CAAC;AAoBvB,MAAM,KAAK,GACV,2HAA2H,CAAC;AAE7H,SAAS,kBAAkB,CAAC,KAA6B;IACxD,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAE,KAAkC,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;AAChH,CAAC;AAED,SAAS,SAAS,CAAC,OAAe;IACjC,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,UAAU,CAAC,IAA0B,EAAE,GAAW;IAC1D,IAAI,IAAI,CAAC,WAAW,KAAK,YAAY;QAAE,OAAO,wBAAwB,CAAC;IACvE,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,IAAI,IAAI,CAAC,YAAY,GAAG,G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ClG,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,sBAAsB;QAC7C,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;QACzC,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,GAAG,EAAE,KAAK,CAAC,GAAG;KACd,CAAC,CAAC;IACH,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACjG,CAAC","sourcesContent":["import type { Credential } from \"@earendil-works/pi-ai\";\nimport type { ExtensionAPI, ExtensionCommandContext } from \"../../types.ts\";\nimport { emitProviderAccountsChanged } from \"../claude-sdk-oauth/account-events.ts\";\nimport {\n\ttype CursorCliAccountSlot,\n\ttype CursorCliOauthCredential,\n\temptyCredential,\n\tlistAccounts,\n\tpinAccount,\n\tremoveAccount,\n} from \"./accounts.ts\";\nimport { selectAccount } from \"./affinity.ts\";\nimport {\n\ttype CursorCliGenerationGuard,\n\tcollectCursorCliStatus,\n\tNATIVE_CURSOR_PROVIDER_ID,\n\tregisterCursorCliShutdownSafety,\n\trenderCursorCliStatus,\n} from \"./diagnostics.ts\";\nimport {\n\tCURSOR_CLI_OAUTH_PROVIDER_ID,\n\tconfirmCursorCliNoApprovalAcknowledgement,\n\timportLocalCursorCredential,\n\timportNativeCursorCredential,\n\ttype LocalCursorImportDeps,\n} from \"./oauth-login.ts\";\nimport { type CursorCliSessionRouter, cursorCliSessionRouter } from \"./session-router.ts\";\nimport {\n\ttype CursorCliOauthProviderSettings,\n\tloadCursorCliOauthProviderSettingsFromDisk,\n\tpersistCursorCliNoApprovalAcknowledgement,\n\tpersistCursorCliOauthEnabled,\n} from \"./settings.ts\";\n\n/** Injectable seams; every default resolves real on-disk state at invocation time. */\nexport type CursorCliAccountCommandDeps = {\n\treadonly loadSettings?: (cwd: string) => CursorCliOauthProviderSettings;\n\treadonly router?: CursorCliSessionRouter;\n\treadonly resolveExecutable?: (settings: CursorCliOauthProviderSettings) => string;\n\treadonly probeVersion?: (executable: string) => Promise<string>;\n\treadonly readNativeCredential?: () => Credential | undefined | Promise<Credential | undefined>;\n\treadonly importCredential?: typeof importLocalCursorCredential;\n\treadonly importNativeCredential?: typeof importNativeCursorCredential;\n\treadonly importDeps?: LocalCursorImportDeps;\n\t/** Acknowledgement persistence seam; the default read-modify-writes the global settings file. */\n\treadonly persistAcknowledgement?: (cwd: string, acknowledgedAt: string) => void;\n\t/** Enablement persistence seam; explicit login/import actions activate the fallback lane. */\n\treadonly persistEnabled?: (cwd: string, enabled: boolean) => void;\n\treadonly now?: () => number;\n\treadonly generation?: CursorCliGenerationGuard;\n};\n\nconst USAGE =\n\t\"Usage: /cursor-account [list | add | remove <name> | pin <name> | unpin | import [local | native] | acknowledge | status]\";\n\nfunction asCursorCredential(value: Credential | undefined): CursorCliOauthCredential {\n\treturn value !== undefined && value.type === \"oauth\" ? (value as CursorCliOauthCredential) : emptyCredential();\n}\n\nfunction parseArgs(rawArgs: string): string[] {\n\treturn rawArgs.trim().split(/\\s+/).filter(Boolean);\n}\n\nfunction slotStatus(slot: CursorCliAccountSlot, now: number): string {\n\tif (slot.blockReason === \"auth_error\") return \"blocked until re-login\";\n\tif (slot.blockedUntil !== undefined && slot.blockedUntil > now) {\n\t\treturn `blocked until ${new Date(slot.blockedUntil).toISOString()} (${slot.blockReason ?? \"rate_limit\"})`;\n\t}\n\treturn \"available\";\n}\n\nfunction authEventMessage(event: unknown): string {\n\tif (event === null || typeof event !== \"object\") return \"Cursor CLI (OAuth) authentication update.\";\n\tconst value = event as Record<string, unknown>;\n\tif (value.type === \"auth_url\" && typeof value.url === \"string\") {\n\t\treturn `Open this URL to authorize Cursor CLI (OAuth):\\n${value.url}`;\n\t}\n\tif (value.type === \"device_code\" && typeof value.verificationUri === \"string\") {\n\t\treturn `Open this URL to authorize Cursor CLI (OAuth):\\n${value.verificationUri}`;\n\t}\n\treturn typeof value.message === \"string\" ? value.message : \"Cursor CLI (OAuth) authentication update.\";\n}\n\n/**\n * Registers `/cursor-account` plus the reload/shutdown teardown for this\n * extension generation: the command reads account state fresh from the\n * credential store on every invocation, and every deferred continuation is\n * fenced so a retired generation is never touched after a reload.\n */\nexport function registerCursorCliAccountCommand(pi: ExtensionAPI, deps: CursorCliAccountCommandDeps = {}): void {\n\tconst loadSettings = deps.loadSettings ?? ((cwd: string) => loadCursorCliOauthProviderSettingsFromDisk(cwd));\n\tconst now = deps.now ?? Date.now;\n\t// One guard per registration: a reload rebuilds the extension and gets a\n\t// fresh fence, while the child registry stays process-wide.\n\tconst generation = registerCursorCliShutdownSafety(pi, { generation: deps.generation });\n\n\tpi.registerCommand(\"cursor-account\", {\n\t\tdescription: \"List and manage Cursor CLI (OAuth) accounts.\",\n\t\targumentHint: \"[list | add | remove <name> | pin <name> | unpin | import | acknowledge | status]\",\n\t\thandler: async (rawArgs: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\ttry {\n\t\t\t\tconst args = parseArgs(rawArgs);\n\t\t\t\tconst action = args[0] ?? \"list\";\n\t\t\t\tif (action === \"list\") {\n\t\t\t\t\tshowAccounts(ctx, loadSettings(ctx.cwd), generation, now);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"add\") {\n\t\t\t\t\tawait addAccount(ctx);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"remove\") {\n\t\t\t\t\tawait removeNamedAccount(ctx, args[1]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"pin\" && args[1] !== undefined) {\n\t\t\t\t\tawait pinNamedAccount(ctx, args[1]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"unpin\") {\n\t\t\t\t\tawait unpinAccount(ctx);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"import\") {\n\t\t\t\t\tconst source = args[1] ?? \"local\";\n\t\t\t\t\tif (source !== \"local\" && source !== \"native\") {\n\t\t\t\t\t\tctx.ui.notify(USAGE, \"error\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait importAccount(ctx, deps, source);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"acknowledge\") {\n\t\t\t\t\tawait acknowledgeNoApproval(ctx, deps, generation);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (action === \"status\") {\n\t\t\t\t\tawait showStatus(ctx, deps, { loadSettings, generation, now });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tctx.ui.notify(USAGE, \"error\");\n\t\t\t} catch (error) {\n\t\t\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\t\t}\n\t\t},\n\t});\n}\n\nfunction showAccounts(\n\tctx: ExtensionCommandContext,\n\tsettings: CursorCliOauthProviderSettings,\n\tgeneration: CursorCliGenerationGuard,\n\tnow: () => number,\n): void {\n\tconst credential = asCursorCredential(ctx.modelRegistry.authStorage.get(CURSOR_CLI_OAUTH_PROVIDER_ID));\n\tconst accounts = listAccounts(credential);\n\tconst pinned = settings.pinnedAccount ?? credential.pinned;\n\tconst pinSource = settings.pinnedAccount !== undefined ? \"settings\" : \"stored\";\n\tlet affinityPick: string | undefined;\n\tlet affinityError: string | undefined;\n\tif (accounts.length > 0) {\n\t\ttry {\n\t\t\taffinityPick = selectAccount(accounts, {\n\t\t\t\tsessionId: ctx.sessionManager.getSessionId(),\n\t\t\t\tpinnedAccount: pinned,\n\t\t\t\tnow: now(),\n\t\t\t}).name;\n\t\t} catch (error) {\n\t\t\taffinityError = error instanceof Error ? error.message : String(error);\n\t\t}\n\t}\n\tconst lines = [\"Cursor CLI (OAuth) accounts:\"];\n\tif (accounts.length === 0) lines.push(\" (none)\");\n\tfor (const account of accounts) {\n\t\tconst states = [account.name, account.source, slotStatus(account, now())];\n\t\tif (account.name === pinned) states.push(\"pinned\");\n\t\tif (account.name === affinityPick) states.push(\"affinity pick\");\n\t\tlines.push(` ${states.join(\" | \")}`);\n\t}\n\tlines.push(`Pinned account: ${pinned === undefined ? \"none\" : `${pinned} (${pinSource})`}`);\n\tlines.push(`Affinity pick: ${affinityPick ?? (affinityError ? `unavailable - ${affinityError}` : \"none\")}`);\n\tgeneration.runFencedSync(ctx, () => ctx.ui.notify(lines.join(\"\\n\"), \"info\"));\n}\n\nasync function addAccount(ctx: ExtensionCommandContext): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tctx.ui.notify(\"/cursor-account add requires an interactive UI.\", \"error\");\n\t\treturn;\n\t}\n\ttry {\n\t\tawait ctx.modelRegistry.modelRuntime.login(CURSOR_CLI_OAUTH_PROVIDER_ID, \"oauth\", {\n\t\t\tsignal: ctx.signal,\n\t\t\tprompt: async (prompt: { message: string }) => {\n\t\t\t\tconst answer = await ctx.ui.input(prompt.message);\n\t\t\t\tif (answer === undefined) throw new Error(\"Login cancelled\");\n\t\t\t\treturn answer;\n\t\t\t},\n\t\t\tnotify: (event: unknown) => ctx.ui.notify(authEventMessage(event), \"info\"),\n\t\t});\n\t\temitProviderAccountsChanged(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\t\tctx.ui.notify(\"Cursor CLI (OAuth) account added.\", \"info\");\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tif (message !== \"Login cancelled\") {\n\t\t\tctx.ui.notify(`Failed to add Cursor CLI (OAuth) account: ${message}`, \"error\");\n\t\t}\n\t}\n}\n\nasync function removeNamedAccount(ctx: ExtensionCommandContext, name: string | undefined): Promise<void> {\n\tif (!name) {\n\t\tctx.ui.notify(\"Usage: /cursor-account remove <name>\", \"error\");\n\t\treturn;\n\t}\n\tlet removed = false;\n\ttry {\n\t\tawait ctx.modelRegistry.authStorage.modify(CURSOR_CLI_OAUTH_PROVIDER_ID, async (current) => {\n\t\t\tconst credential = asCursorCredential(current);\n\t\t\tif (!listAccounts(credential).some((account) => account.name === name)) return current;\n\t\t\tremoved = true;\n\t\t\treturn removeAccount(credential, name);\n\t\t});\n\t} catch (error) {\n\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\treturn;\n\t}\n\tif (!removed) {\n\t\tctx.ui.notify(`Cursor CLI (OAuth) account '${name}' does not exist.`, \"error\");\n\t\treturn;\n\t}\n\temitProviderAccountsChanged(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\tctx.ui.notify(`Removed Cursor CLI (OAuth) account: ${name}.`, \"info\");\n}\n\nasync function pinNamedAccount(ctx: ExtensionCommandContext, name: string): Promise<void> {\n\ttry {\n\t\tawait ctx.modelRegistry.authStorage.modify(CURSOR_CLI_OAUTH_PROVIDER_ID, async (current) => {\n\t\t\tconst credential = asCursorCredential(current);\n\t\t\tif (!listAccounts(credential).some((account) => account.name === name)) {\n\t\t\t\tthrow new Error(`Cursor CLI (OAuth) account '${name}' does not exist.`);\n\t\t\t}\n\t\t\treturn pinAccount(credential, name);\n\t\t});\n\t} catch (error) {\n\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\treturn;\n\t}\n\temitProviderAccountsChanged(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\tctx.ui.notify(`Pinned Cursor CLI (OAuth) account: ${name}.`, \"info\");\n}\n\nasync function unpinAccount(ctx: ExtensionCommandContext): Promise<void> {\n\tlet hadPin = false;\n\ttry {\n\t\tawait ctx.modelRegistry.authStorage.modify(CURSOR_CLI_OAUTH_PROVIDER_ID, async (current) => {\n\t\t\tconst credential = asCursorCredential(current);\n\t\t\tif (credential.pinned === undefined) return current;\n\t\t\thadPin = true;\n\t\t\tconst { pinned: _pinned, ...unpinned } = credential;\n\t\t\treturn unpinned;\n\t\t});\n\t} catch (error) {\n\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\treturn;\n\t}\n\tif (!hadPin) {\n\t\tctx.ui.notify(\"No stored Cursor CLI (OAuth) account pin is set.\", \"info\");\n\t\treturn;\n\t}\n\temitProviderAccountsChanged(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\tctx.ui.notify(\"Unpinned Cursor CLI (OAuth) account.\", \"info\");\n}\n\nasync function importAccount(\n\tctx: ExtensionCommandContext,\n\tdeps: CursorCliAccountCommandDeps,\n\tsource: \"local\" | \"native\",\n): Promise<void> {\n\tconst importCredential = deps.importCredential ?? importLocalCursorCredential;\n\tconst importNativeCredential = deps.importNativeCredential ?? importNativeCursorCredential;\n\tconst importDeps: LocalCursorImportDeps = { ...deps.importDeps };\n\tif (importDeps.onPrompt === undefined && ctx.hasUI) {\n\t\timportDeps.onPrompt = async (prompt: { message: string }) => {\n\t\t\tconst answer = await ctx.ui.input(prompt.message);\n\t\t\tif (answer === undefined) throw new Error(\"Import cancelled\");\n\t\t\treturn answer;\n\t\t};\n\t}\n\tlet importedName: string | undefined;\n\ttry {\n\t\tawait ctx.modelRegistry.authStorage.modify(CURSOR_CLI_OAUTH_PROVIDER_ID, async (current) => {\n\t\t\tconst before = asCursorCredential(current);\n\t\t\tconst updated =\n\t\t\t\tsource === \"native\"\n\t\t\t\t\t? await importNativeCredential(\n\t\t\t\t\t\t\tbefore,\n\t\t\t\t\t\t\tdeps.readNativeCredential ?? (() => ctx.modelRegistry.authStorage.get(NATIVE_CURSOR_PROVIDER_ID)),\n\t\t\t\t\t\t)\n\t\t\t\t\t: await importCredential(before, importDeps);\n\t\t\tconst existing = new Set(listAccounts(before).map((account) => account.name));\n\t\t\timportedName = listAccounts(updated).find((account) => !existing.has(account.name))?.name;\n\t\t\treturn updated;\n\t\t});\n\t} catch (error) {\n\t\tctx.ui.notify(\n\t\t\t`Failed to import local Cursor credential: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\"error\",\n\t\t);\n\t\treturn;\n\t}\n\tconst persistEnabled = deps.persistEnabled ?? persistCursorCliOauthEnabled;\n\ttry {\n\t\tpersistEnabled(ctx.cwd, true);\n\t\tawait ctx.modelRegistry.modelRuntime.refresh({\n\t\t\tallowNetwork: false,\n\t\t\tproviders: [CURSOR_CLI_OAUTH_PROVIDER_ID],\n\t\t});\n\t} catch (error) {\n\t\tctx.ui.notify(\n\t\t\t`Imported ${source === \"native\" ? \"native \" : \"\"}Cursor credential, but provider activation failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\"warning\",\n\t\t);\n\t\treturn;\n\t}\n\temitProviderAccountsChanged(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\tctx.ui.notify(\n\t\t`Imported ${source === \"native\" ? \"native \" : \"local \"}Cursor credential as '${importedName ?? \"a new account\"}' (copied into this provider's store).`,\n\t\t\"info\",\n\t);\n}\n\nasync function acknowledgeNoApproval(\n\tctx: ExtensionCommandContext,\n\tdeps: CursorCliAccountCommandDeps,\n\tgeneration: CursorCliGenerationGuard,\n): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tctx.ui.notify(\"/cursor-account acknowledge requires an interactive UI.\", \"error\");\n\t\treturn;\n\t}\n\tconst persist = deps.persistAcknowledgement ?? persistCursorCliNoApprovalAcknowledgement;\n\tconst acknowledgedAt = await confirmCursorCliNoApprovalAcknowledgement(\n\t\tasync (ask) => (await ctx.ui.input(ask.message)) ?? \"\",\n\t\t() => new Date((deps.now ?? Date.now)()),\n\t);\n\tif (acknowledgedAt === undefined) {\n\t\tgeneration.runFencedSync(ctx, () =>\n\t\t\tctx.ui.notify(\n\t\t\t\t\"No acknowledgement written: unattended Cursor CLI execution stays off until you acknowledge.\",\n\t\t\t\t\"info\",\n\t\t\t),\n\t\t);\n\t\treturn;\n\t}\n\tpersist(ctx.cwd, acknowledgedAt);\n\tgeneration.runFencedSync(ctx, () =>\n\t\tctx.ui.notify(`Acknowledged unattended Cursor CLI tool execution at ${acknowledgedAt}.`, \"info\"),\n\t);\n}\n\nasync function showStatus(\n\tctx: ExtensionCommandContext,\n\tdeps: CursorCliAccountCommandDeps,\n\tbound: {\n\t\tloadSettings: (cwd: string) => CursorCliOauthProviderSettings;\n\t\tgeneration: CursorCliGenerationGuard;\n\t\tnow: () => number;\n\t},\n): Promise<void> {\n\t// Context reads happen before any await; the render continuation is fenced\n\t// so a reload during the version probe can never touch a retired context.\n\tconst sessionId = ctx.sessionManager.getSessionId();\n\tconst report = await collectCursorCliStatus({\n\t\tsessionId,\n\t\tsettings: bound.loadSettings(ctx.cwd),\n\t\treadCredential: () => ctx.modelRegistry.authStorage.get(CURSOR_CLI_OAUTH_PROVIDER_ID),\n\t\treadNativeCredential:\n\t\t\tdeps.readNativeCredential ?? (() => ctx.modelRegistry.authStorage.get(NATIVE_CURSOR_PROVIDER_ID)),\n\t\trouter: deps.router ?? cursorCliSessionRouter,\n\t\tresolveExecutable: deps.resolveExecutable,\n\t\tprobeVersion: deps.probeVersion,\n\t\tnow: bound.now,\n\t});\n\tbound.generation.runFencedSync(ctx, () => ctx.ui.notify(renderCursorCliStatus(report), \"info\"));\n}\n"]}
@@ -9,6 +9,7 @@ export type CursorCliOauthExtensionDeps = {
9
9
  readonly agentDir?: string;
10
10
  readonly store?: CredentialStore;
11
11
  readonly readCurrent?: () => Promise<Credential | undefined>;
12
+ readonly readNativeCredential?: () => Credential | undefined | Promise<Credential | undefined>;
12
13
  readonly loadSettings?: (cwd: string) => CursorCliOauthProviderSettings;
13
14
  readonly resolveExecutable?: (settings: {
14
15
  executablePath?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/cursor-cli-oauth/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGzE,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,gBAAgB,CAAC;AAKxE,OAAO,EAAE,KAAK,8BAA8B,EAA8C,MAAM,eAAe,CAAC;AAGhH,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAChE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CA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B,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAC7D,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAC/F,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,8BAA8B,CAAC;IACxE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;CAC/E,CAAC;AAKF;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,GAAE,2BAAgC,GAAG,IAAI,CAkE9G;AAED,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAEtE"}
@@ -3,8 +3,9 @@ import { AuthStorage } from "../../../auth-storage.js";
3
3
  import { registerCursorCliAccountCommand } from "./account-command.js";
4
4
  import { defaultCursorAgentExecutableDeps, resolveCursorAgentExecutable } from "./executable.js";
5
5
  import { resolveCursorCliModelCatalog, STATIC_CURSOR_CLI_MODELS } from "./models.js";
6
+ import { createCursorCliOauthCredentialReader } from "./native-bootstrap.js";
6
7
  import { CURSOR_CLI_OAUTH_PROVIDER_ID, createCursorCliOauthConfig } from "./oauth-login.js";
7
- import { loadCursorCliOauthProviderSettingsFromDisk } from "./settings.js";
8
+ import { loadCursorCliOauthProviderSettingsFromDisk, persistCursorCliNoApprovalAcknowledgement, persistCursorCliOauthEnabled, } from "./settings.js";
8
9
  import { streamCursorCliOauth } from "./stream.js";
9
10
  export { CURSOR_CLI_OAUTH_PROVIDER_ID } from "./oauth-login.js";
10
11
  const defaultResolveExecutable = (settings) => resolveCursorAgentExecutable({ ...defaultCursorAgentExecutableDeps(), settings });
@@ -18,7 +19,23 @@ export function registerCursorCliOauthExtension(pi, deps = {}) {
18
19
  const cwd = deps.cwd ?? process.cwd();
19
20
  const agentDir = deps.agentDir ?? getAgentDir();
20
21
  const store = deps.store ?? AuthStorage.create();
21
- const readCurrent = deps.readCurrent ?? (async () => store.read(CURSOR_CLI_OAUTH_PROVIDER_ID));
22
+ const readCurrent = deps.readCurrent ??
23
+ createCursorCliOauthCredentialReader({
24
+ store,
25
+ readNativeCredential: deps.readNativeCredential ?? (() => store.read("cursor")),
26
+ canBootstrap: () => {
27
+ const settings = loadSettings(cwd);
28
+ if (!settings.enabled)
29
+ return false;
30
+ try {
31
+ resolveExecutable(settings);
32
+ return true;
33
+ }
34
+ catch {
35
+ return false;
36
+ }
37
+ },
38
+ });
22
39
  const loadSettings = deps.loadSettings ?? loadCursorCliOauthProviderSettingsFromDisk;
23
40
  const resolveExecutable = deps.resolveExecutable ?? defaultResolveExecutable;
24
41
  // Todo 21: /cursor-account command plus the reload/shutdown teardown for
@@ -36,6 +53,8 @@ export function registerCursorCliOauthExtension(pi, deps = {}) {
36
53
  readCurrent,
37
54
  readSettings: () => loadSettings(cwd),
38
55
  resolveExecutable,
56
+ persistAcknowledgement: (acknowledgedAt) => persistCursorCliNoApprovalAcknowledgement(cwd, acknowledgedAt),
57
+ persistEnabled: (enabled) => persistCursorCliOauthEnabled(cwd, enabled),
39
58
  }),
40
59
  });
41
60
  };