@code-yeongyu/senpi 2026.9.24-3 → 2026.9.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/dist/bundle/chunks/{app-server-command-OTRHYRIB.js → app-server-command-RB6QUPRI.js} +1 -1
- package/dist/bundle/chunks/{chunk-UM43CBL4.js → chunk-JJ3NJZBD.js} +118 -111
- package/dist/bundle/chunks/chunk-SGYEOIOJ.js +8 -0
- package/dist/bundle/chunks/chunk-YS5YEX4S.js +2 -0
- package/dist/bundle/chunks/{cli-main-TX6I4X4F.js → cli-main-KO53KYDN.js} +1 -1
- package/dist/bundle/chunks/{interactive-mode-UI5Q6FGY.js → interactive-mode-ABDNLJSI.js} +1 -1
- package/dist/bundle/chunks/{multi-session-host-D6HMI3RQ.js → multi-session-host-JV3MNWXZ.js} +1 -1
- package/dist/bundle/chunks/{package-manager-cli-3UWH3ZZS.js → package-manager-cli-ZYYAVCXU.js} +1 -1
- package/dist/bundle/chunks/{rpc-mode-LXIZHJSJ.js → rpc-mode-Q2OUJURB.js} +1 -1
- package/dist/bundle/chunks/runtime-session-XBT646O5.js +2 -0
- package/dist/bundle/chunks/session-worker.js +184 -177
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/stream.d.ts +7 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/stream.d.ts.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/stream.js +23 -4
- package/dist/core/extensions/builtin/cursor-cli-oauth/stream.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/durable-command.d.ts +11 -16
- package/dist/core/extensions/builtin/terminal/durable-command.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/durable-command.js +97 -43
- package/dist/core/extensions/builtin/terminal/durable-command.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/durable-file.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/durable-file.js +11 -4
- package/dist/core/extensions/builtin/terminal/durable-file.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension-state.d.ts +26 -0
- package/dist/core/extensions/builtin/terminal/extension-state.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/extension-state.js +151 -0
- package/dist/core/extensions/builtin/terminal/extension-state.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/extension.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.js +32 -308
- package/dist/core/extensions/builtin/terminal/extension.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/lease-file.d.ts +52 -0
- package/dist/core/extensions/builtin/terminal/lease-file.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/lease-file.js +205 -0
- package/dist/core/extensions/builtin/terminal/lease-file.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/lease-keeper.d.ts +33 -0
- package/dist/core/extensions/builtin/terminal/lease-keeper.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/lease-keeper.js +110 -0
- package/dist/core/extensions/builtin/terminal/lease-keeper.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/manager.d.ts +1 -0
- package/dist/core/extensions/builtin/terminal/manager.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/manager.js +6 -0
- package/dist/core/extensions/builtin/terminal/manager.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/manifest-lease.d.ts +48 -4
- package/dist/core/extensions/builtin/terminal/manifest-lease.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/manifest-lease.js +141 -59
- package/dist/core/extensions/builtin/terminal/manifest-lease.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts +2 -0
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.js +15 -10
- package/dist/core/extensions/builtin/terminal/monitor-registry.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-state-dir.d.ts +11 -0
- package/dist/core/extensions/builtin/terminal/monitor-state-dir.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/monitor-state-dir.js +28 -0
- package/dist/core/extensions/builtin/terminal/monitor-state-dir.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/orphan-reaper.d.ts +41 -0
- package/dist/core/extensions/builtin/terminal/orphan-reaper.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/orphan-reaper.js +131 -0
- package/dist/core/extensions/builtin/terminal/orphan-reaper.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/process-identity.d.ts +21 -0
- package/dist/core/extensions/builtin/terminal/process-identity.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/process-identity.js +34 -0
- package/dist/core/extensions/builtin/terminal/process-identity.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/process-start-probe.d.ts +6 -0
- package/dist/core/extensions/builtin/terminal/process-start-probe.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/process-start-probe.js +60 -0
- package/dist/core/extensions/builtin/terminal/process-start-probe.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/prompt.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.js +8 -4
- package/dist/core/extensions/builtin/terminal/prompt.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/restore-digest.d.ts +54 -0
- package/dist/core/extensions/builtin/terminal/restore-digest.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/restore-digest.js +133 -0
- package/dist/core/extensions/builtin/terminal/restore-digest.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/restore-session.d.ts +56 -0
- package/dist/core/extensions/builtin/terminal/restore-session.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/restore-session.js +238 -0
- package/dist/core/extensions/builtin/terminal/restore-session.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/restore.d.ts +52 -19
- package/dist/core/extensions/builtin/terminal/restore.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/restore.js +63 -138
- package/dist/core/extensions/builtin/terminal/restore.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/runtime-session.d.ts +5 -0
- package/dist/core/extensions/builtin/terminal/runtime-session.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/runtime-session.js +17 -0
- package/dist/core/extensions/builtin/terminal/runtime-session.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/session-activity.d.ts +8 -0
- package/dist/core/extensions/builtin/terminal/session-activity.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/session-activity.js +41 -0
- package/dist/core/extensions/builtin/terminal/session-activity.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/shared.d.ts +14 -0
- package/dist/core/extensions/builtin/terminal/shared.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/shared.js +14 -0
- package/dist/core/extensions/builtin/terminal/shared.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/terminal-manifest-model.d.ts +8 -0
- package/dist/core/extensions/builtin/terminal/terminal-manifest-model.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/terminal-manifest-model.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/terminal-manifest-parse.d.ts +15 -0
- package/dist/core/extensions/builtin/terminal/terminal-manifest-parse.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/terminal-manifest-parse.js +148 -0
- package/dist/core/extensions/builtin/terminal/terminal-manifest-parse.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/terminal-manifest.d.ts +15 -2
- package/dist/core/extensions/builtin/terminal/terminal-manifest.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/terminal-manifest.js +62 -11
- package/dist/core/extensions/builtin/terminal/terminal-manifest.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/terminal-state-gc.d.ts +17 -0
- package/dist/core/extensions/builtin/terminal/terminal-state-gc.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/terminal-state-gc.js +81 -0
- package/dist/core/extensions/builtin/terminal/terminal-state-gc.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/tools/context.d.ts +5 -0
- package/dist/core/extensions/builtin/terminal/tools/context.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/context.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/kill-bash.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/kill-bash.js +16 -1
- package/dist/core/extensions/builtin/terminal/tools/kill-bash.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor-manifest-binding.d.ts +27 -0
- package/dist/core/extensions/builtin/terminal/tools/monitor-manifest-binding.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/tools/monitor-manifest-binding.js +75 -0
- package/dist/core/extensions/builtin/terminal/tools/monitor-manifest-binding.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/tools/monitor-schema.d.ts +35 -0
- package/dist/core/extensions/builtin/terminal/tools/monitor-schema.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/tools/monitor-schema.js +67 -0
- package/dist/core/extensions/builtin/terminal/tools/monitor-schema.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/tools/monitor.d.ts +14 -35
- package/dist/core/extensions/builtin/terminal/tools/monitor.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.js +30 -110
- package/dist/core/extensions/builtin/terminal/tools/monitor.js.map +1 -1
- package/dist/core/extensions/builtin/todotools/first-turn.d.ts +7 -6
- package/dist/core/extensions/builtin/todotools/first-turn.d.ts.map +1 -1
- package/dist/core/extensions/builtin/todotools/first-turn.js +8 -8
- package/dist/core/extensions/builtin/todotools/first-turn.js.map +1 -1
- package/dist/core/extensions/builtin/todotools/index.js +1 -1
- package/dist/core/extensions/builtin/todotools/index.js.map +1 -1
- package/dist/core/extensions/builtin/todotools/todo-format.js +1 -1
- package/dist/core/extensions/builtin/todotools/todo-format.js.map +1 -1
- package/dist/core/extensions/builtin/ttsr/detectors/repetitive-turns.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ttsr/detectors/repetitive-turns.js +4 -0
- package/dist/core/extensions/builtin/ttsr/detectors/repetitive-turns.js.map +1 -1
- package/dist/core/extensions/builtin/ttsr/prompts.js +1 -1
- package/dist/core/extensions/builtin/ttsr/prompts.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +1 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +6 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/docs/extensions.md +2 -0
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +12 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-desktop-engine/README.md +31 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/dist/handshake.d.ts +38 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/dist/handshake.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/dist/handshake.js +117 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/dist/handshake.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/dist/index.d.ts +3 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/dist/index.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/dist/index.js +3 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/dist/index.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/dist/locator.d.ts +42 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/dist/locator.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/dist/locator.js +79 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/dist/locator.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/native/check-prebuild-fresh.mjs +160 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/native/index.d.ts +20 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/native/index.js +23 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/native/prebuilds/darwin-arm64/senpi-desktop-engine +0 -0
- package/node_modules/@code-yeongyu/senpi-desktop-engine/package.json +53 -0
- package/node_modules/@code-yeongyu/senpi-desktop-prelude/README.md +20 -0
- package/node_modules/@code-yeongyu/senpi-desktop-prelude/dist/index.d.ts +2 -0
- package/node_modules/@code-yeongyu/senpi-desktop-prelude/dist/index.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-prelude/dist/index.js +2 -0
- package/node_modules/@code-yeongyu/senpi-desktop-prelude/dist/index.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-prelude/package.json +44 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/README.md +20 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/audit.d.ts +38 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/audit.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/audit.js +2 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/audit.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/call.d.ts +28 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/call.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/call.js +102 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/call.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/engine-schema.generated.d.ts +14 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/engine-schema.generated.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/engine-schema.generated.js +71 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/engine-schema.generated.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/index.d.ts +7 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/index.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/index.js +4 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/index.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/json-rpc.d.ts +66 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/json-rpc.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/json-rpc.js +8 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/json-rpc.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/session.d.ts +44 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/session.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/session.js +2 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/session.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/wire.d.ts +59 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/wire.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/wire.js +2 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/dist/wire.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-protocol/package.json +45 -0
- package/node_modules/@code-yeongyu/senpi-desktop-service/README.md +27 -0
- package/node_modules/@code-yeongyu/senpi-desktop-service/dist/index.d.ts +2 -0
- package/node_modules/@code-yeongyu/senpi-desktop-service/dist/index.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-service/dist/index.js +2 -0
- package/node_modules/@code-yeongyu/senpi-desktop-service/dist/index.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-service/package.json +44 -0
- package/node_modules/@code-yeongyu/senpi-desktop-tool/README.md +20 -0
- package/node_modules/@code-yeongyu/senpi-desktop-tool/dist/index.d.ts +2 -0
- package/node_modules/@code-yeongyu/senpi-desktop-tool/dist/index.d.ts.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-tool/dist/index.js +2 -0
- package/node_modules/@code-yeongyu/senpi-desktop-tool/dist/index.js.map +1 -0
- package/node_modules/@code-yeongyu/senpi-desktop-tool/package.json +44 -0
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/dist/pipe-fallback.d.ts +2 -0
- package/node_modules/@earendil-works/pi-pty/dist/pipe-fallback.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/pipe-fallback.js +6 -0
- package/node_modules/@earendil-works/pi-pty/dist/pipe-fallback.js.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/session-bun.d.ts +1 -0
- package/node_modules/@earendil-works/pi-pty/dist/session-bun.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/session-bun.js +1 -0
- package/node_modules/@earendil-works/pi-pty/dist/session-bun.js.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/session-native.js +5 -0
- package/node_modules/@earendil-works/pi-pty/dist/session-native.js.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/session-raw-tail.d.ts +11 -0
- package/node_modules/@earendil-works/pi-pty/dist/session-raw-tail.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-pty/dist/session-raw-tail.js +24 -0
- package/node_modules/@earendil-works/pi-pty/dist/session-raw-tail.js.map +1 -0
- package/node_modules/@earendil-works/pi-pty/dist/session-types.d.ts +2 -0
- package/node_modules/@earendil-works/pi-pty/dist/session-types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/session-types.js.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/session.d.ts +4 -5
- package/node_modules/@earendil-works/pi-pty/dist/session.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/session.js +11 -16
- package/node_modules/@earendil-works/pi-pty/dist/session.js.map +1 -1
- package/node_modules/@earendil-works/pi-pty/native/prebuilds/darwin-arm64/senpi_pty.darwin-arm64.node +0 -0
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +22 -7
- package/dist/bundle/chunks/chunk-GFUZPFHN.js +0 -2
- package/dist/bundle/chunks/chunk-JBOV6VNK.js +0 -8
- package/dist/bundle/chunks/runtime-session-F3EXC44D.js +0 -2
|
@@ -17,6 +17,13 @@ export type CursorCliStreamDeps = {
|
|
|
17
17
|
readonly log?: (line: string) => void;
|
|
18
18
|
readonly executableDeps?: CursorAgentExecutableDeps;
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* The prompt for this turn: every user-role message after the last non-user message, in order.
|
|
22
|
+
* A turn can carry more than the request - hidden extension messages such as the first-turn plan
|
|
23
|
+
* reminder reach providers as user messages after it - and the CLI takes a single prompt, so
|
|
24
|
+
* sending only the last one dropped the request itself (senpi#2139).
|
|
25
|
+
*/
|
|
26
|
+
export declare function turnPrompt(context: Context): string;
|
|
20
27
|
/**
|
|
21
28
|
* Streams one Cursor CLI print-mode turn onto senpi's assistant event stream.
|
|
22
29
|
* The CLI owns tool execution; senpi owns the context and reports only its own
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/cursor-cli-oauth/stream.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,GAAG,EAER,KAAK,2BAA2B,EAChC,KAAK,OAAO,EACZ,KAAK,eAAe,EAIpB,KAAK,KAAK,EACV,KAAK,mBAAmB,EACxB,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EACN,KAAK,yBAAyB,EAG9B,MAAM,iBAAiB,CAAC;AASzB,OAAO,EAEN,KAAK,oBAAoB,EAIzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAGN,KAAK,sBAAsB,EAG3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,8BAA8B,EAA8C,MAAM,eAAe,CAAC;AAKhH,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAMhE,sFAAsF;AACtF,MAAM,MAAM,mBAAmB,GAAG;IACjC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,EAAE,8BAA8B,CAAC;IACnD,QAAQ,CAAC,MAAM,CAAC,EAAE,sBAAsB,CAAC;IACzC,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,cAAc,CAAC,CAAC;IAC5D,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAC5B,uFAAuF;IACvF,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,QAAQ,CAAC,cAAc,CAAC,EAAE,yBAAyB,CAAC;CACpD,CAAC;
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/cursor-cli-oauth/stream.ts"],"names":[],"mappings":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ChB,OAAO,CAAC,EAAE,mBAAmB,EAC7B,IAAI,GAAE,mBAAwB,GAC5B,2BAA2B,CAuR7B"}
|
|
@@ -252,12 +252,31 @@ function blockText(blocks) {
|
|
|
252
252
|
}
|
|
253
253
|
return parts.join("\n");
|
|
254
254
|
}
|
|
255
|
-
function
|
|
255
|
+
function userText(message) {
|
|
256
|
+
return typeof message.content === "string" ? message.content : blockText(message.content);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* The prompt for this turn: every user-role message after the last non-user message, in order.
|
|
260
|
+
* A turn can carry more than the request - hidden extension messages such as the first-turn plan
|
|
261
|
+
* reminder reach providers as user messages after it - and the CLI takes a single prompt, so
|
|
262
|
+
* sending only the last one dropped the request itself (senpi#2139).
|
|
263
|
+
*/
|
|
264
|
+
export function turnPrompt(context) {
|
|
265
|
+
const trailing = [];
|
|
256
266
|
for (let index = context.messages.length - 1; index >= 0; index -= 1) {
|
|
257
267
|
const message = context.messages[index];
|
|
258
268
|
if (message === undefined || message.role !== "user")
|
|
259
|
-
|
|
260
|
-
|
|
269
|
+
break;
|
|
270
|
+
const text = userText(message);
|
|
271
|
+
if (text.length > 0)
|
|
272
|
+
trailing.unshift(text);
|
|
273
|
+
}
|
|
274
|
+
if (trailing.length > 0)
|
|
275
|
+
return trailing.join("\n\n");
|
|
276
|
+
for (let index = context.messages.length - 1; index >= 0; index -= 1) {
|
|
277
|
+
const message = context.messages[index];
|
|
278
|
+
if (message?.role === "user")
|
|
279
|
+
return userText(message);
|
|
261
280
|
}
|
|
262
281
|
throw new Error("cursor-cli-oauth needs a user message to prompt the Cursor CLI");
|
|
263
282
|
}
|
|
@@ -378,7 +397,7 @@ export function streamCursorCliOauth(model, context, options, deps = {}) {
|
|
|
378
397
|
throw new Error(DISABLED_MESSAGE);
|
|
379
398
|
if (storedAccounts.length === 0)
|
|
380
399
|
throw new Error(NO_ACCOUNTS_MESSAGE);
|
|
381
|
-
const prompt =
|
|
400
|
+
const prompt = turnPrompt(context);
|
|
382
401
|
const senpiSessionId = options?.affinitySessionId ?? options?.sessionId ?? DEFAULT_CURSOR_AFFINITY_KEY;
|
|
383
402
|
const spawnModel = resolveCursorCliSpawnModel(model, options?.thinkingSelection);
|
|
384
403
|
const turnInput = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/cursor-cli-oauth/stream.ts"],"names":[],"mappings":"AACA,OAAO,EAMN,aAAa,EACb,gCAAgC,EAChC,iCAAiC,GAGjC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAA4D,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACxH,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAEN,gCAAgC,EAChC,4BAA4B,GAC5B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAA8D,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACjH,OAAO,EACN,wBAAwB,EACxB,8BAA8B,EAC9B,+BAA+B,EAC/B,+BAA+B,GAC/B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EACN,4BAA4B,EAE5B,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAKN,sBAAsB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAuC,0CAA0C,EAAE,MAAM,eAAe,CAAC;AAChH,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,mBAAmB,EAAiC,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEpG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AC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9C,IAAI,aAAa;gBAAE,aAAa,EAAE,KAAK,EAAE,CAAC;YAC1C,MAAM,CAAC,GAAG,EAAE,CAAC;QACd,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;IACL,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport {\n\ttype Api,\n\ttype AssistantMessage,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\ttype CredentialStore,\n\tcalculateCost,\n\tcreateAssistantMessageDiagnostic,\n\tcreateAssistantMessageEventStream,\n\ttype Model,\n\ttype SimpleStreamOptions,\n} from \"@earendil-works/pi-ai\";\nimport { getAgentDir } from \"../../../../config.ts\";\nimport { AuthStorage } from \"../../../auth-storage.ts\";\nimport { estimateTokens } from \"../../../compaction/compaction.ts\";\nimport { type CursorCliAccountSlot, type CursorCliOauthCredential, emptyCredential, listAccounts } from \"./accounts.ts\";\nimport { DEFAULT_CURSOR_AFFINITY_KEY } from \"./affinity.ts\";\nimport {\n\ttype CursorAgentExecutableDeps,\n\tdefaultCursorAgentExecutableDeps,\n\tresolveCursorAgentExecutable,\n} from \"./executable.ts\";\nimport { type CursorCliAttemptOptions, type CursorCliFailoverNotice, runCursorCliFailover } from \"./failover.ts\";\nimport {\n\tapplyCursorCliDenyConfig,\n\tCursorCliExecutionRefusalError,\n\tcreateCursorCliGuardrailSession,\n\tresolveCursorCliExecutionPolicy,\n} from \"./guardrails.ts\";\nimport { runInCursorAccountHome } from \"./home-store.ts\";\nimport {\n\tCURSOR_CLI_OAUTH_PROVIDER_ID,\n\ttype CursorCliOauthConfig,\n\tcreateCursorCliOauthConfig,\n\tcursorAgentNotInstalledError,\n\tisCursorCliOauthLaneEnabled,\n} from \"./oauth-login.ts\";\nimport {\n\ttype CursorCliRecapExchange,\n\ttype CursorCliSessionRestartNotice,\n\ttype CursorCliSessionRouter,\n\ttype CursorCliSessionTurnInput,\n\tcursorCliSessionRouter,\n} from \"./session-router.ts\";\nimport { type CursorCliOauthProviderSettings, loadCursorCliOauthProviderSettingsFromDisk } from \"./settings.ts\";\nimport { resolveCursorCliSpawnModel } from \"./spawn-model.ts\";\nimport type { CursorCliStreamEvent } from \"./stream-parser.ts\";\nimport { CursorCliAbortError, type CursorCliTransportHandle, spawnCursorCli } from \"./transport.ts\";\n\nexport { CURSOR_CLI_OAUTH_PROVIDER_ID } from \"./oauth-login.ts\";\n\nconst DISABLED_MESSAGE = \"disabled by settings\";\nconst NO_ACCOUNTS_MESSAGE = \"no accounts: run /login cursor-cli-oauth\";\nconst RECENT_EXCHANGE_LIMIT = 12;\n\n/** Injectable seams so tests stay hermetic; every default is re-resolved per turn. */\nexport type CursorCliStreamDeps = {\n\treadonly cwd?: string;\n\treadonly agentDir?: string;\n\treadonly store?: CredentialStore;\n\treadonly settings?: CursorCliOauthProviderSettings;\n\treadonly router?: CursorCliSessionRouter;\n\treadonly oauth?: Pick<CursorCliOauthConfig, \"refreshToken\">;\n\treadonly now?: () => number;\n\t/** Credential-home log line sink; receives byte lengths only, never token material. */\n\treadonly log?: (line: string) => void;\n\treadonly executableDeps?: CursorAgentExecutableDeps;\n};\n\n/**\n * A non-zero cursor-agent exit that produced no result event. Carries the\n * captured stderr so `classifyCursorCliError` can match the real cause instead\n * of the generic \"no assistant text\" wrapper.\n */\nclass CursorCliProcessFailureError extends Error {\n\treadonly exitCode: number | null;\n\treadonly stderr: string;\n\n\tconstructor(exitCode: number | null, stderr: string) {\n\t\tsuper(stderr.trim().length > 0 ? stderr.trim() : `cursor-agent exited with code ${String(exitCode)}`);\n\t\tthis.name = \"CursorCliProcessFailureError\";\n\t\tthis.exitCode = exitCode;\n\t\tthis.stderr = stderr;\n\t}\n}\n\n/** Minimal async queue bridging the home-store-wrapped transport run into a pullable iterable. */\nclass CursorCliEventBuffer<T> {\n\tprivate readonly values: T[] = [];\n\tprivate readonly waiters: Array<(error?: unknown) => void> = [];\n\tprivate ended = false;\n\tprivate failure: unknown;\n\tprivate settled = false;\n\n\tprivate wake(error?: unknown): void {\n\t\tconst waiter = this.waiters.shift();\n\t\tif (waiter) waiter(error);\n\t}\n\n\tpush(value: T): void {\n\t\tif (this.ended || this.failure !== undefined) return;\n\t\tthis.values.push(value);\n\t\tthis.wake();\n\t}\n\n\tclose(): void {\n\t\tif (this.settled) return;\n\t\tthis.settled = true;\n\t\tthis.ended = true;\n\t\tfor (const waiter of this.waiters.splice(0)) waiter();\n\t}\n\n\tfail(error: unknown): void {\n\t\tif (this.settled) return;\n\t\tthis.settled = true;\n\t\tthis.failure = error;\n\t\tfor (const waiter of this.waiters.splice(0)) waiter(error);\n\t}\n\n\tasync *events(): AsyncGenerator<T, void, unknown> {\n\t\twhile (true) {\n\t\t\tconst value = this.values.shift();\n\t\t\tif (value !== undefined) {\n\t\t\t\tyield value;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (this.failure !== undefined) throw this.failure;\n\t\t\tif (this.ended) return;\n\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\tthis.waiters.push((error?: unknown) => {\n\t\t\t\t\tif (error !== undefined) reject(error);\n\t\t\t\t\telse resolve();\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\t}\n}\n\ntype OpenBlockKind = \"text\" | \"thinking\" | \"tool\";\n\ntype StreamMapper = {\n\treadonly stream: AssistantMessageEventStream;\n\treadonly output: AssistantMessage;\n\tstarted: boolean;\n\topenKind: OpenBlockKind | undefined;\n\topenIndex: number;\n\topenText: string;\n\t/** Assistant text seen so far in the open text block, for cumulative-snapshot detection. */\n\ttextAccumulated: string;\n};\n\nfunction emptyCursorCliOutput(model: Model<Api>): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent: [],\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tusage: {\n\t\t\tinput: 0,\n\t\t\toutput: 0,\n\t\t\tcacheRead: 0,\n\t\t\tcacheWrite: 0,\n\t\t\ttotalTokens: 0,\n\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t},\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction ensureStarted(mapper: StreamMapper): void {\n\tif (mapper.started) return;\n\tmapper.started = true;\n\tmapper.stream.push({ type: \"start\", partial: mapper.output });\n}\n\nfunction openBlock(mapper: StreamMapper, kind: OpenBlockKind): void {\n\tensureStarted(mapper);\n\tif (kind === \"thinking\") {\n\t\tmapper.output.content.push({ type: \"thinking\", thinking: \"\" });\n\t} else {\n\t\tmapper.output.content.push({ type: \"text\", text: \"\" });\n\t}\n\tmapper.openKind = kind;\n\tmapper.openIndex = mapper.output.content.length - 1;\n\tmapper.openText = \"\";\n\tmapper.textAccumulated = \"\";\n\tmapper.stream.push({\n\t\ttype: kind === \"thinking\" ? \"thinking_start\" : \"text_start\",\n\t\tcontentIndex: mapper.openIndex,\n\t\tpartial: mapper.output,\n\t});\n}\n\nfunction closeOpen(mapper: StreamMapper): void {\n\tif (mapper.openKind === undefined) return;\n\tconst block = mapper.output.content[mapper.openIndex];\n\tif (mapper.openKind === \"thinking\") {\n\t\tif (block !== undefined && block.type === \"thinking\") block.thinking = mapper.openText;\n\t\tmapper.stream.push({\n\t\t\ttype: \"thinking_end\",\n\t\t\tcontentIndex: mapper.openIndex,\n\t\t\tcontent: mapper.openText,\n\t\t\tpartial: mapper.output,\n\t\t});\n\t} else {\n\t\tif (block !== undefined && block.type === \"text\") block.text = mapper.openText;\n\t\tmapper.stream.push({\n\t\t\ttype: \"text_end\",\n\t\t\tcontentIndex: mapper.openIndex,\n\t\t\tcontent: mapper.openText,\n\t\t\tpartial: mapper.output,\n\t\t});\n\t}\n\tmapper.openKind = undefined;\n}\n\nfunction ensureOpen(mapper: StreamMapper, kind: OpenBlockKind): void {\n\tif (mapper.openKind === kind) return;\n\tcloseOpen(mapper);\n\topenBlock(mapper, kind);\n}\n\nfunction resetTextSegment(mapper: StreamMapper): void {\n\tcloseOpen(mapper);\n\tmapper.textAccumulated = \"\";\n}\n\nfunction pushTextDelta(mapper: StreamMapper, delta: string): void {\n\tconst block = mapper.output.content[mapper.openIndex];\n\tmapper.openText += delta;\n\tif (block !== undefined && block.type === \"text\") block.text = mapper.openText;\n\tmapper.stream.push({ type: \"text_delta\", contentIndex: mapper.openIndex, delta, partial: mapper.output });\n}\n\nfunction pushThinkingDelta(mapper: StreamMapper, delta: string): void {\n\tconst block = mapper.output.content[mapper.openIndex];\n\tmapper.openText += delta;\n\tif (block !== undefined && block.type === \"thinking\") block.thinking = mapper.openText;\n\tmapper.stream.push({\n\t\ttype: \"thinking_delta\",\n\t\tcontentIndex: mapper.openIndex,\n\t\tdelta,\n\t\tpartial: mapper.output,\n\t});\n}\n\n/**\n * Appends one assistant fragment as a text delta. The CLI streams partial\n * output deltas and then repeats the full message in a final frame, so a\n * fragment that already starts with the accumulated text is the cumulative\n * snapshot: replace instead of appending so the answer is never duplicated.\n */\nfunction appendAssistantFragment(mapper: StreamMapper, fragment: string): void {\n\tif (fragment.length === 0) return;\n\tensureOpen(mapper, \"text\");\n\tlet delta: string;\n\tif (\n\t\tfragment.length >= mapper.textAccumulated.length &&\n\t\t(mapper.textAccumulated.length === 0 || fragment.startsWith(mapper.textAccumulated))\n\t) {\n\t\tdelta = fragment.slice(mapper.textAccumulated.length);\n\t\tmapper.textAccumulated = fragment;\n\t} else {\n\t\tdelta = fragment;\n\t\tmapper.textAccumulated += fragment;\n\t}\n\tif (delta.length > 0) pushTextDelta(mapper, delta);\n}\n\nfunction appendNotice(mapper: StreamMapper, message: string): void {\n\tensureOpen(mapper, \"text\");\n\tpushTextDelta(mapper, `${message}\\n`);\n}\n\n/**\n * Records the result event: senpi's own token estimate of the payload it sent,\n * the CLI's output tokens, and the CLI's input/cache numbers quarantined in a\n * telemetry diagnostic. estimateContextTokens treats the last assistant usage\n * as the authoritative context base, so CLI-side context numbers must never\n * reach `usage` or senpi would demand a compaction only the CLI could perform.\n */\nfunction applyResultEvent(\n\tmapper: StreamMapper,\n\tmodel: Model<Api>,\n\tsentPromptTokens: number,\n\tusage: {\n\t\tinputTokens: number;\n\t\toutputTokens: number;\n\t\tcacheReadTokens: number;\n\t\tcacheWriteTokens: number;\n\t},\n\trequestId: string,\n\tdurationMs: number,\n): void {\n\tconst output = mapper.output;\n\toutput.usage.input = sentPromptTokens;\n\toutput.usage.output = usage.outputTokens;\n\toutput.usage.cacheRead = 0;\n\toutput.usage.cacheWrite = 0;\n\toutput.usage.totalTokens = 0;\n\toutput.usage.cost = calculateCost(model, output.usage);\n\toutput.stopReason = \"stop\";\n\toutput.diagnostics = [\n\t\t...(output.diagnostics ?? []),\n\t\tcreateAssistantMessageDiagnostic(\n\t\t\t\"cursor_cli_oauth_cli_usage\",\n\t\t\t\"cursor-agent reported usage (telemetry only; never used for senpi context accounting)\",\n\t\t\t{\n\t\t\t\tinputTokens: usage.inputTokens,\n\t\t\t\toutputTokens: usage.outputTokens,\n\t\t\t\tcacheReadTokens: usage.cacheReadTokens,\n\t\t\t\tcacheWriteTokens: usage.cacheWriteTokens,\n\t\t\t\trequestId,\n\t\t\t\tdurationMs,\n\t\t\t},\n\t\t),\n\t];\n}\n\nfunction blockText(blocks: readonly unknown[]): string {\n\tconst parts: string[] = [];\n\tfor (const block of blocks) {\n\t\tif (typeof block !== \"object\" || block === null) continue;\n\t\tconst candidate = block as { type?: unknown; text?: unknown };\n\t\tif (candidate.type === \"text\" && typeof candidate.text === \"string\" && candidate.text.length > 0) {\n\t\t\tparts.push(candidate.text);\n\t\t}\n\t}\n\treturn parts.join(\"\\n\");\n}\n\nfunction lastUserPrompt(context: Context): string {\n\tfor (let index = context.messages.length - 1; index >= 0; index -= 1) {\n\t\tconst message = context.messages[index];\n\t\tif (message === undefined || message.role !== \"user\") continue;\n\t\treturn typeof message.content === \"string\" ? message.content : blockText(message.content);\n\t}\n\tthrow new Error(\"cursor-cli-oauth needs a user message to prompt the Cursor CLI\");\n}\n\nfunction recapExchanges(context: Context): CursorCliRecapExchange[] {\n\tconst exchanges: CursorCliRecapExchange[] = [];\n\tfor (const message of context.messages) {\n\t\tif (message.role === \"user\") {\n\t\t\tconst text = typeof message.content === \"string\" ? message.content : blockText(message.content);\n\t\t\tif (text.length > 0) exchanges.push({ role: \"user\", text });\n\t\t} else if (message.role === \"assistant\") {\n\t\t\tconst text = blockText(message.content);\n\t\t\tif (text.length > 0) exchanges.push({ role: \"assistant\", text });\n\t\t}\n\t}\n\treturn exchanges.slice(-RECENT_EXCHANGE_LIMIT);\n}\n\nfunction isFailoverNotice(event: unknown): event is CursorCliFailoverNotice {\n\treturn (event as { type?: unknown }).type === \"cursor_account_changed\";\n}\n\nfunction isRestartNotice(event: unknown): event is CursorCliSessionRestartNotice {\n\treturn (event as { type?: unknown }).type === \"cursor_chat_restarted\";\n}\n\nfunction turnErrorMessage(error: unknown): string {\n\t// Failover wraps every surfaced failure and the router hands classification\n\t// inputs around as { thrown } records; the innermost cause is what the user needs.\n\tlet detail = error;\n\tfor (let depth = 0; depth < 3 && typeof detail === \"object\" && detail !== null; depth += 1) {\n\t\tconst wrapper = detail as { original?: unknown; thrown?: unknown };\n\t\tif (wrapper.original !== undefined) detail = wrapper.original;\n\t\telse if (wrapper.thrown !== undefined) detail = wrapper.thrown;\n\t\telse break;\n\t}\n\tif (detail instanceof Error) return detail.message;\n\tif (typeof detail === \"string\") return detail;\n\tconst message = (detail as { message?: unknown } | null)?.message;\n\treturn typeof message === \"string\" && message.length > 0 ? message : \"Cursor CLI turn failed\";\n}\n\n/**\n * Streams one Cursor CLI print-mode turn onto senpi's assistant event stream.\n * The CLI owns tool execution; senpi owns the context and reports only its own\n * token estimates, so no CLI-side number ever feeds compaction accounting.\n */\nexport function streamCursorCliOauth(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n\tdeps: CursorCliStreamDeps = {},\n): AssistantMessageEventStream {\n\tconst stream = createAssistantMessageEventStream();\n\tvoid (async () => {\n\t\tconst mapper: StreamMapper = {\n\t\t\tstream,\n\t\t\toutput: emptyCursorCliOutput(model),\n\t\t\tstarted: false,\n\t\t\topenKind: undefined,\n\t\t\topenIndex: -1,\n\t\t\topenText: \"\",\n\t\t\ttextAccumulated: \"\",\n\t\t};\n\t\tconst now = deps.now ?? Date.now;\n\t\tconst cwdDirectory = deps.cwd ?? process.cwd();\n\t\tconst agentDir = deps.agentDir ?? getAgentDir();\n\t\tconst store = deps.store ?? AuthStorage.create();\n\t\tconst router = deps.router ?? cursorCliSessionRouter;\n\t\tconst signal = options?.signal;\n\t\tlet wasAborted = signal?.aborted === true;\n\t\tlet sentPromptTokens = 0;\n\t\tlet runningHandle: CursorCliTransportHandle | undefined;\n\t\tlet handleRunning = false;\n\t\tconst onAbort = (): void => {\n\t\t\twasAborted = true;\n\t\t};\n\t\tif (!wasAborted) signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\ttry {\n\t\t\t// Fresh per turn: settings, credentials, and executable resolution are\n\t\t\t// never cached across turns, so back-to-back turns observe changes.\n\t\t\tconst settings = deps.settings ?? loadCursorCliOauthProviderSettingsFromDisk(cwdDirectory);\n\t\t\t// An explicit `enabled: false` is the kill switch; the flagless ambient\n\t\t\t// case is refused below, once the stored slots are known, so the turn path\n\t\t\t// and `assessConfiguration` share one opt-in rule.\n\t\t\tif (settings.explicitlyDisabled) throw new Error(DISABLED_MESSAGE);\n\t\t\tconst executableDeps: CursorAgentExecutableDeps = {\n\t\t\t\t...defaultCursorAgentExecutableDeps(),\n\t\t\t\tsettings: { executablePath: settings.executablePath },\n\t\t\t};\n\t\t\t// The executable gates the TURN before any guardrail or auth work: the\n\t\t\t// oauth check keeps a credential-backed lane selectable so turns reach\n\t\t\t// this point, and `cursor-agent not installed` + the install guidance\n\t\t\t// must originate here - before a spawn could report it without the marker.\n\t\t\ttry {\n\t\t\t\tresolveCursorAgentExecutable(deps.executableDeps ?? executableDeps);\n\t\t\t} catch (error) {\n\t\t\t\tthrow cursorAgentNotInstalledError(error);\n\t\t\t}\n\t\t\t// Guardrails decide before any spawn: an unacknowledged force attempt is\n\t\t\t// the turn's error outcome, and only the policy's force/plan/sandbox\n\t\t\t// verdict reaches the argv. Warnings surface as turn notices.\n\t\t\tconst guardrailSession = createCursorCliGuardrailSession();\n\t\t\tconst policy = resolveCursorCliExecutionPolicy(\n\t\t\t\t{\n\t\t\t\t\tforceExecution: settings.forceExecution,\n\t\t\t\t\tnoApprovalAcknowledgedAt: settings.noApprovalAcknowledgedAt,\n\t\t\t\t\texecutionMode: settings.executionMode,\n\t\t\t\t\tsandboxMode: settings.sandboxMode,\n\t\t\t\t},\n\t\t\t\tguardrailSession,\n\t\t\t\tsettings.denyCommands ?? [],\n\t\t\t);\n\t\t\tif (policy.status === \"refused\") throw new CursorCliExecutionRefusalError(policy.refusal);\n\t\t\tfor (const warning of policy.warnings) appendNotice(mapper, warning.message);\n\t\t\tconst stored = await store.read(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\t\t\tconst storedAccounts = stored?.type === \"oauth\" ? listAccounts(stored as CursorCliOauthCredential) : [];\n\t\t\tif (!isCursorCliOauthLaneEnabled(settings, storedAccounts.length)) throw new Error(DISABLED_MESSAGE);\n\t\t\tif (storedAccounts.length === 0) throw new Error(NO_ACCOUNTS_MESSAGE);\n\n\t\t\tconst prompt = lastUserPrompt(context);\n\t\t\tconst senpiSessionId = options?.affinitySessionId ?? options?.sessionId ?? DEFAULT_CURSOR_AFFINITY_KEY;\n\t\t\tconst spawnModel = resolveCursorCliSpawnModel(model as Model<\"cursor-agent\">, options?.thinkingSelection);\n\t\t\tconst turnInput: CursorCliSessionTurnInput = {\n\t\t\t\tprompt,\n\t\t\t\tmodel: spawnModel,\n\t\t\t\trecentExchanges: recapExchanges(context),\n\t\t\t};\n\n\t\t\tconst spawnAndStream = (\n\t\t\t\tattempt: { prompt: string; resumeChatId: string | undefined },\n\t\t\t\tslot: CursorCliAccountSlot,\n\t\t\t): AsyncIterable<CursorCliStreamEvent> => {\n\t\t\t\tsentPromptTokens = estimateTokens({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: attempt.prompt,\n\t\t\t\t\ttimestamp: now(),\n\t\t\t\t} satisfies AgentMessage);\n\t\t\t\tconst buffer = new CursorCliEventBuffer<CursorCliStreamEvent>();\n\t\t\t\tvoid (async () => {\n\t\t\t\t\tlet sawResult = false;\n\t\t\t\t\t// Malformed events are held until the exit outcome is known: a\n\t\t\t\t\t// non-zero exit without a result means the captured stderr is the\n\t\t\t\t\t// real cause, and the parser's trailing incomplete_stream event\n\t\t\t\t\t// would otherwise mask it.\n\t\t\t\t\tconst heldMalformed: CursorCliStreamEvent[] = [];\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait runInCursorAccountHome(\n\t\t\t\t\t\t\tagentDir,\n\t\t\t\t\t\t\tslot,\n\t\t\t\t\t\t\tasync ({ home }) => {\n\t\t\t\t\t\t\t\t// The CLI rewrites cli-config.json during every invocation, so the\n\t\t\t\t\t\t\t\t// deny list must ride the same per-spawn cadence as the home-store\n\t\t\t\t\t\t\t\t// auth.json preparation directly above this spawn.\n\t\t\t\t\t\t\t\tapplyCursorCliDenyConfig(home, policy.denyCommands);\n\t\t\t\t\t\t\t\tconst handle = spawnCursorCli({\n\t\t\t\t\t\t\t\t\tprompt: attempt.prompt,\n\t\t\t\t\t\t\t\t\tmodel: spawnModel,\n\t\t\t\t\t\t\t\t\tresumeChatId: attempt.resumeChatId,\n\t\t\t\t\t\t\t\t\tforce: policy.force,\n\t\t\t\t\t\t\t\t\texecutionMode: policy.executionMode,\n\t\t\t\t\t\t\t\t\tsandboxMode: policy.sandboxMode,\n\t\t\t\t\t\t\t\t\taccountHome: home,\n\t\t\t\t\t\t\t\t\tcwd: cwdDirectory,\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t\texecutableDeps: deps.executableDeps ?? executableDeps,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\trunningHandle = handle;\n\t\t\t\t\t\t\t\thandleRunning = true;\n\t\t\t\t\t\t\t\tif (wasAborted) handle.abort();\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tfor await (const event of handle.events) {\n\t\t\t\t\t\t\t\t\t\tif (event instanceof CursorCliAbortError) {\n\t\t\t\t\t\t\t\t\t\t\tbuffer.fail(event);\n\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tif (event.type === \"result\") sawResult = true;\n\t\t\t\t\t\t\t\t\t\tif (event.type === \"malformed_stream\") {\n\t\t\t\t\t\t\t\t\t\t\theldMalformed.push(event);\n\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tbuffer.push(event);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst outcome = await handle.completed;\n\t\t\t\t\t\t\t\t\tif (outcome.type === \"completed\" && outcome.exitCode !== 0 && !sawResult) {\n\t\t\t\t\t\t\t\t\t\tbuffer.fail(new CursorCliProcessFailureError(outcome.exitCode, outcome.stderr));\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tfor (const event of heldMalformed) buffer.push(event);\n\t\t\t\t\t\t\t\t\tbuffer.close();\n\t\t\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\t\t\thandleRunning = false;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdeps.log,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbuffer.close();\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tbuffer.fail(error);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t\treturn buffer.events();\n\t\t\t};\n\n\t\t\tconst turn = runCursorCliFailover<CursorCliStreamEvent | CursorCliSessionRestartNotice>({\n\t\t\t\tstore,\n\t\t\t\tproviderId: CURSOR_CLI_OAUTH_PROVIDER_ID,\n\t\t\t\taffinity: {\n\t\t\t\t\tsessionId: senpiSessionId,\n\t\t\t\t\tpinnedAccount: settings.pinnedAccount,\n\t\t\t\t\tnow: now(),\n\t\t\t\t},\n\t\t\t\tnow: () => now(),\n\t\t\t\trunAttempt: async (selected, _options: CursorCliAttemptOptions) => {\n\t\t\t\t\tlet slot = selected;\n\t\t\t\t\tconst current = await store.read(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\t\t\t\t\tif (current?.type === \"oauth\") {\n\t\t\t\t\t\tconst fresh = (current as CursorCliOauthCredential).accounts?.find(\n\t\t\t\t\t\t\t(candidate) => candidate.name === slot.name,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (fresh) slot = fresh;\n\t\t\t\t\t}\n\t\t\t\t\t// An expired access token would classify as auth_error and block the\n\t\t\t\t\t// account until re-login; refresh it while the refresh token exists.\n\t\t\t\t\tif (now() >= slot.expires) {\n\t\t\t\t\t\tconst oauth =\n\t\t\t\t\t\t\tdeps.oauth ??\n\t\t\t\t\t\t\tcreateCursorCliOauthConfig({\n\t\t\t\t\t\t\t\treadCurrent: () => store.read(CURSOR_CLI_OAUTH_PROVIDER_ID),\n\t\t\t\t\t\t\t\treadSettings: () => settings,\n\t\t\t\t\t\t\t\tresolveExecutable: (oauthSettings) =>\n\t\t\t\t\t\t\t\t\tresolveCursorAgentExecutable({\n\t\t\t\t\t\t\t\t\t\t...(deps.executableDeps ?? executableDeps),\n\t\t\t\t\t\t\t\t\t\tsettings: { executablePath: oauthSettings.executablePath },\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst storedCredential =\n\t\t\t\t\t\t\tcurrent?.type === \"oauth\" ? (current as CursorCliOauthCredential) : emptyCredential();\n\t\t\t\t\t\tconst refreshed = await oauth.refreshToken(storedCredential, signal ?? new AbortController().signal);\n\t\t\t\t\t\t// refreshToken re-applies the sentinel fields over the stored credential,\n\t\t\t\t\t\t// so the result keeps the persisted oauth shape.\n\t\t\t\t\t\tawait store.modify(CURSOR_CLI_OAUTH_PROVIDER_ID, async () => refreshed as CursorCliOauthCredential);\n\t\t\t\t\t\tconst reread = await store.read(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\t\t\t\t\t\tconst updated =\n\t\t\t\t\t\t\treread?.type === \"oauth\"\n\t\t\t\t\t\t\t\t? (reread as CursorCliOauthCredential).accounts?.find(\n\t\t\t\t\t\t\t\t\t\t(candidate) => candidate.name === slot.name,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\tif (!updated) {\n\t\t\t\t\t\t\tthrow new Error(`cursor-cli-oauth account '${slot.name}' disappeared during token refresh`);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tslot = updated;\n\t\t\t\t\t}\n\t\t\t\t\t// Cross-account chats live in each account's HOME, so a fresh-chat\n\t\t\t\t\t// failover needs no flag here: the router resumes only its own account's chat.\n\t\t\t\t\treturn router.runTurn(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsenpiSessionId,\n\t\t\t\t\t\t\taccountName: slot.name,\n\t\t\t\t\t\t\trunAttempt: (attempt) => spawnAndStream(attempt, slot),\n\t\t\t\t\t\t\tresumeMode: settings.resumeMode,\n\t\t\t\t\t\t\tcontextRecapOnModelSwitch: settings.contextRecapOnModelSwitch,\n\t\t\t\t\t\t\tnow: () => now(),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tturnInput,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tfor await (const event of turn) {\n\t\t\t\tif (isFailoverNotice(event) || isRestartNotice(event)) {\n\t\t\t\t\tappendNotice(mapper, event.message);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tswitch (event.type) {\n\t\t\t\t\tcase \"system\":\n\t\t\t\t\t\t// The session router already recorded chat id and model from init.\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"thinking\":\n\t\t\t\t\t\tif (event.subtype === \"completed\") {\n\t\t\t\t\t\t\tif (mapper.openKind === \"thinking\") closeOpen(mapper);\n\t\t\t\t\t\t} else if (event.text.length > 0) {\n\t\t\t\t\t\t\tensureOpen(mapper, \"thinking\");\n\t\t\t\t\t\t\tpushThinkingDelta(mapper, event.text);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"assistant\":\n\t\t\t\t\t\tfor (const block of event.message.content) appendAssistantFragment(mapper, block.text);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"tool_call\":\n\t\t\t\t\t\t// Preserve the text-segment boundary and cumulative snapshot reset,\n\t\t\t\t\t\t// but do not expose provider protocol frames as assistant text or map\n\t\t\t\t\t\t// them to host tool calls that Senpi could execute a second time.\n\t\t\t\t\t\tresetTextSegment(mapper);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"result\":\n\t\t\t\t\t\tif (event.subtype === \"success\" && !event.is_error) {\n\t\t\t\t\t\t\tapplyResultEvent(\n\t\t\t\t\t\t\t\tmapper,\n\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\tsentPromptTokens,\n\t\t\t\t\t\t\t\tevent.usage,\n\t\t\t\t\t\t\t\tevent.request_id,\n\t\t\t\t\t\t\t\tevent.duration_ms,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t// malformed_stream events are converted to failures inside the\n\t\t\t\t\t\t// session router and never reach this loop.\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcloseOpen(mapper);\n\t\t\tstream.push({ type: \"done\", reason: \"stop\", message: mapper.output });\n\t\t} catch (error) {\n\t\t\tcloseOpen(mapper);\n\t\t\tconst aborted = wasAborted || signal?.aborted === true;\n\t\t\tmapper.output.stopReason = aborted ? \"aborted\" : \"error\";\n\t\t\tmapper.output.errorMessage = turnErrorMessage(error);\n\t\t\tstream.push({ type: \"error\", reason: mapper.output.stopReason, error: mapper.output });\n\t\t} finally {\n\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\tif (handleRunning) runningHandle?.abort();\n\t\t\tstream.end();\n\t\t}\n\t})();\n\treturn stream;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/cursor-cli-oauth/stream.ts"],"names":[],"mappings":"AACA,OAAO,EAMN,aAAa,EACb,gCAAgC,EAChC,iCAAiC,GAGjC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAA4D,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACxH,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAEN,gCAAgC,EAChC,4BAA4B,GAC5B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAA8D,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACjH,OAAO,EACN,wBAAwB,EACxB,8BAA8B,EAC9B,+BAA+B,EAC/B,+BAA+B,GAC/B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EACN,4BAA4B,EAE5B,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAKN,sBAAsB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAuC,0CAA0C,EAAE,MAAM,eAAe,CAAC;AAChH,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,mB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ED,SAAS,CAAC,MAAM,CAAC,CAAC;YAClB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACvE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,SAAS,CAAC,MAAM,CAAC,CAAC;YAClB,MAAM,OAAO,GAAG,UAAU,IAAI,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;YACvD,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;YACzD,MAAM,CAAC,MAAM,CAAC,YAAY,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;YACrD,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACxF,CAAC;gBAAS,CAAC;YACV,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9C,IAAI,aAAa;gBAAE,aAAa,EAAE,KAAK,EAAE,CAAC;YAC1C,MAAM,CAAC,GAAG,EAAE,CAAC;QACd,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;IACL,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport {\n\ttype Api,\n\ttype AssistantMessage,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\ttype CredentialStore,\n\tcalculateCost,\n\tcreateAssistantMessageDiagnostic,\n\tcreateAssistantMessageEventStream,\n\ttype Model,\n\ttype SimpleStreamOptions,\n} from \"@earendil-works/pi-ai\";\nimport { getAgentDir } from \"../../../../config.ts\";\nimport { AuthStorage } from \"../../../auth-storage.ts\";\nimport { estimateTokens } from \"../../../compaction/compaction.ts\";\nimport { type CursorCliAccountSlot, type CursorCliOauthCredential, emptyCredential, listAccounts } from \"./accounts.ts\";\nimport { DEFAULT_CURSOR_AFFINITY_KEY } from \"./affinity.ts\";\nimport {\n\ttype CursorAgentExecutableDeps,\n\tdefaultCursorAgentExecutableDeps,\n\tresolveCursorAgentExecutable,\n} from \"./executable.ts\";\nimport { type CursorCliAttemptOptions, type CursorCliFailoverNotice, runCursorCliFailover } from \"./failover.ts\";\nimport {\n\tapplyCursorCliDenyConfig,\n\tCursorCliExecutionRefusalError,\n\tcreateCursorCliGuardrailSession,\n\tresolveCursorCliExecutionPolicy,\n} from \"./guardrails.ts\";\nimport { runInCursorAccountHome } from \"./home-store.ts\";\nimport {\n\tCURSOR_CLI_OAUTH_PROVIDER_ID,\n\ttype CursorCliOauthConfig,\n\tcreateCursorCliOauthConfig,\n\tcursorAgentNotInstalledError,\n\tisCursorCliOauthLaneEnabled,\n} from \"./oauth-login.ts\";\nimport {\n\ttype CursorCliRecapExchange,\n\ttype CursorCliSessionRestartNotice,\n\ttype CursorCliSessionRouter,\n\ttype CursorCliSessionTurnInput,\n\tcursorCliSessionRouter,\n} from \"./session-router.ts\";\nimport { type CursorCliOauthProviderSettings, loadCursorCliOauthProviderSettingsFromDisk } from \"./settings.ts\";\nimport { resolveCursorCliSpawnModel } from \"./spawn-model.ts\";\nimport type { CursorCliStreamEvent } from \"./stream-parser.ts\";\nimport { CursorCliAbortError, type CursorCliTransportHandle, spawnCursorCli } from \"./transport.ts\";\n\nexport { CURSOR_CLI_OAUTH_PROVIDER_ID } from \"./oauth-login.ts\";\n\nconst DISABLED_MESSAGE = \"disabled by settings\";\nconst NO_ACCOUNTS_MESSAGE = \"no accounts: run /login cursor-cli-oauth\";\nconst RECENT_EXCHANGE_LIMIT = 12;\n\n/** Injectable seams so tests stay hermetic; every default is re-resolved per turn. */\nexport type CursorCliStreamDeps = {\n\treadonly cwd?: string;\n\treadonly agentDir?: string;\n\treadonly store?: CredentialStore;\n\treadonly settings?: CursorCliOauthProviderSettings;\n\treadonly router?: CursorCliSessionRouter;\n\treadonly oauth?: Pick<CursorCliOauthConfig, \"refreshToken\">;\n\treadonly now?: () => number;\n\t/** Credential-home log line sink; receives byte lengths only, never token material. */\n\treadonly log?: (line: string) => void;\n\treadonly executableDeps?: CursorAgentExecutableDeps;\n};\n\n/**\n * A non-zero cursor-agent exit that produced no result event. Carries the\n * captured stderr so `classifyCursorCliError` can match the real cause instead\n * of the generic \"no assistant text\" wrapper.\n */\nclass CursorCliProcessFailureError extends Error {\n\treadonly exitCode: number | null;\n\treadonly stderr: string;\n\n\tconstructor(exitCode: number | null, stderr: string) {\n\t\tsuper(stderr.trim().length > 0 ? stderr.trim() : `cursor-agent exited with code ${String(exitCode)}`);\n\t\tthis.name = \"CursorCliProcessFailureError\";\n\t\tthis.exitCode = exitCode;\n\t\tthis.stderr = stderr;\n\t}\n}\n\n/** Minimal async queue bridging the home-store-wrapped transport run into a pullable iterable. */\nclass CursorCliEventBuffer<T> {\n\tprivate readonly values: T[] = [];\n\tprivate readonly waiters: Array<(error?: unknown) => void> = [];\n\tprivate ended = false;\n\tprivate failure: unknown;\n\tprivate settled = false;\n\n\tprivate wake(error?: unknown): void {\n\t\tconst waiter = this.waiters.shift();\n\t\tif (waiter) waiter(error);\n\t}\n\n\tpush(value: T): void {\n\t\tif (this.ended || this.failure !== undefined) return;\n\t\tthis.values.push(value);\n\t\tthis.wake();\n\t}\n\n\tclose(): void {\n\t\tif (this.settled) return;\n\t\tthis.settled = true;\n\t\tthis.ended = true;\n\t\tfor (const waiter of this.waiters.splice(0)) waiter();\n\t}\n\n\tfail(error: unknown): void {\n\t\tif (this.settled) return;\n\t\tthis.settled = true;\n\t\tthis.failure = error;\n\t\tfor (const waiter of this.waiters.splice(0)) waiter(error);\n\t}\n\n\tasync *events(): AsyncGenerator<T, void, unknown> {\n\t\twhile (true) {\n\t\t\tconst value = this.values.shift();\n\t\t\tif (value !== undefined) {\n\t\t\t\tyield value;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (this.failure !== undefined) throw this.failure;\n\t\t\tif (this.ended) return;\n\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\tthis.waiters.push((error?: unknown) => {\n\t\t\t\t\tif (error !== undefined) reject(error);\n\t\t\t\t\telse resolve();\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\t}\n}\n\ntype OpenBlockKind = \"text\" | \"thinking\" | \"tool\";\n\ntype StreamMapper = {\n\treadonly stream: AssistantMessageEventStream;\n\treadonly output: AssistantMessage;\n\tstarted: boolean;\n\topenKind: OpenBlockKind | undefined;\n\topenIndex: number;\n\topenText: string;\n\t/** Assistant text seen so far in the open text block, for cumulative-snapshot detection. */\n\ttextAccumulated: string;\n};\n\nfunction emptyCursorCliOutput(model: Model<Api>): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent: [],\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tusage: {\n\t\t\tinput: 0,\n\t\t\toutput: 0,\n\t\t\tcacheRead: 0,\n\t\t\tcacheWrite: 0,\n\t\t\ttotalTokens: 0,\n\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t},\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction ensureStarted(mapper: StreamMapper): void {\n\tif (mapper.started) return;\n\tmapper.started = true;\n\tmapper.stream.push({ type: \"start\", partial: mapper.output });\n}\n\nfunction openBlock(mapper: StreamMapper, kind: OpenBlockKind): void {\n\tensureStarted(mapper);\n\tif (kind === \"thinking\") {\n\t\tmapper.output.content.push({ type: \"thinking\", thinking: \"\" });\n\t} else {\n\t\tmapper.output.content.push({ type: \"text\", text: \"\" });\n\t}\n\tmapper.openKind = kind;\n\tmapper.openIndex = mapper.output.content.length - 1;\n\tmapper.openText = \"\";\n\tmapper.textAccumulated = \"\";\n\tmapper.stream.push({\n\t\ttype: kind === \"thinking\" ? \"thinking_start\" : \"text_start\",\n\t\tcontentIndex: mapper.openIndex,\n\t\tpartial: mapper.output,\n\t});\n}\n\nfunction closeOpen(mapper: StreamMapper): void {\n\tif (mapper.openKind === undefined) return;\n\tconst block = mapper.output.content[mapper.openIndex];\n\tif (mapper.openKind === \"thinking\") {\n\t\tif (block !== undefined && block.type === \"thinking\") block.thinking = mapper.openText;\n\t\tmapper.stream.push({\n\t\t\ttype: \"thinking_end\",\n\t\t\tcontentIndex: mapper.openIndex,\n\t\t\tcontent: mapper.openText,\n\t\t\tpartial: mapper.output,\n\t\t});\n\t} else {\n\t\tif (block !== undefined && block.type === \"text\") block.text = mapper.openText;\n\t\tmapper.stream.push({\n\t\t\ttype: \"text_end\",\n\t\t\tcontentIndex: mapper.openIndex,\n\t\t\tcontent: mapper.openText,\n\t\t\tpartial: mapper.output,\n\t\t});\n\t}\n\tmapper.openKind = undefined;\n}\n\nfunction ensureOpen(mapper: StreamMapper, kind: OpenBlockKind): void {\n\tif (mapper.openKind === kind) return;\n\tcloseOpen(mapper);\n\topenBlock(mapper, kind);\n}\n\nfunction resetTextSegment(mapper: StreamMapper): void {\n\tcloseOpen(mapper);\n\tmapper.textAccumulated = \"\";\n}\n\nfunction pushTextDelta(mapper: StreamMapper, delta: string): void {\n\tconst block = mapper.output.content[mapper.openIndex];\n\tmapper.openText += delta;\n\tif (block !== undefined && block.type === \"text\") block.text = mapper.openText;\n\tmapper.stream.push({ type: \"text_delta\", contentIndex: mapper.openIndex, delta, partial: mapper.output });\n}\n\nfunction pushThinkingDelta(mapper: StreamMapper, delta: string): void {\n\tconst block = mapper.output.content[mapper.openIndex];\n\tmapper.openText += delta;\n\tif (block !== undefined && block.type === \"thinking\") block.thinking = mapper.openText;\n\tmapper.stream.push({\n\t\ttype: \"thinking_delta\",\n\t\tcontentIndex: mapper.openIndex,\n\t\tdelta,\n\t\tpartial: mapper.output,\n\t});\n}\n\n/**\n * Appends one assistant fragment as a text delta. The CLI streams partial\n * output deltas and then repeats the full message in a final frame, so a\n * fragment that already starts with the accumulated text is the cumulative\n * snapshot: replace instead of appending so the answer is never duplicated.\n */\nfunction appendAssistantFragment(mapper: StreamMapper, fragment: string): void {\n\tif (fragment.length === 0) return;\n\tensureOpen(mapper, \"text\");\n\tlet delta: string;\n\tif (\n\t\tfragment.length >= mapper.textAccumulated.length &&\n\t\t(mapper.textAccumulated.length === 0 || fragment.startsWith(mapper.textAccumulated))\n\t) {\n\t\tdelta = fragment.slice(mapper.textAccumulated.length);\n\t\tmapper.textAccumulated = fragment;\n\t} else {\n\t\tdelta = fragment;\n\t\tmapper.textAccumulated += fragment;\n\t}\n\tif (delta.length > 0) pushTextDelta(mapper, delta);\n}\n\nfunction appendNotice(mapper: StreamMapper, message: string): void {\n\tensureOpen(mapper, \"text\");\n\tpushTextDelta(mapper, `${message}\\n`);\n}\n\n/**\n * Records the result event: senpi's own token estimate of the payload it sent,\n * the CLI's output tokens, and the CLI's input/cache numbers quarantined in a\n * telemetry diagnostic. estimateContextTokens treats the last assistant usage\n * as the authoritative context base, so CLI-side context numbers must never\n * reach `usage` or senpi would demand a compaction only the CLI could perform.\n */\nfunction applyResultEvent(\n\tmapper: StreamMapper,\n\tmodel: Model<Api>,\n\tsentPromptTokens: number,\n\tusage: {\n\t\tinputTokens: number;\n\t\toutputTokens: number;\n\t\tcacheReadTokens: number;\n\t\tcacheWriteTokens: number;\n\t},\n\trequestId: string,\n\tdurationMs: number,\n): void {\n\tconst output = mapper.output;\n\toutput.usage.input = sentPromptTokens;\n\toutput.usage.output = usage.outputTokens;\n\toutput.usage.cacheRead = 0;\n\toutput.usage.cacheWrite = 0;\n\toutput.usage.totalTokens = 0;\n\toutput.usage.cost = calculateCost(model, output.usage);\n\toutput.stopReason = \"stop\";\n\toutput.diagnostics = [\n\t\t...(output.diagnostics ?? []),\n\t\tcreateAssistantMessageDiagnostic(\n\t\t\t\"cursor_cli_oauth_cli_usage\",\n\t\t\t\"cursor-agent reported usage (telemetry only; never used for senpi context accounting)\",\n\t\t\t{\n\t\t\t\tinputTokens: usage.inputTokens,\n\t\t\t\toutputTokens: usage.outputTokens,\n\t\t\t\tcacheReadTokens: usage.cacheReadTokens,\n\t\t\t\tcacheWriteTokens: usage.cacheWriteTokens,\n\t\t\t\trequestId,\n\t\t\t\tdurationMs,\n\t\t\t},\n\t\t),\n\t];\n}\n\nfunction blockText(blocks: readonly unknown[]): string {\n\tconst parts: string[] = [];\n\tfor (const block of blocks) {\n\t\tif (typeof block !== \"object\" || block === null) continue;\n\t\tconst candidate = block as { type?: unknown; text?: unknown };\n\t\tif (candidate.type === \"text\" && typeof candidate.text === \"string\" && candidate.text.length > 0) {\n\t\t\tparts.push(candidate.text);\n\t\t}\n\t}\n\treturn parts.join(\"\\n\");\n}\n\nfunction userText(message: Extract<Context[\"messages\"][number], { role: \"user\" }>): string {\n\treturn typeof message.content === \"string\" ? message.content : blockText(message.content);\n}\n\n/**\n * The prompt for this turn: every user-role message after the last non-user message, in order.\n * A turn can carry more than the request - hidden extension messages such as the first-turn plan\n * reminder reach providers as user messages after it - and the CLI takes a single prompt, so\n * sending only the last one dropped the request itself (senpi#2139).\n */\nexport function turnPrompt(context: Context): string {\n\tconst trailing: string[] = [];\n\tfor (let index = context.messages.length - 1; index >= 0; index -= 1) {\n\t\tconst message = context.messages[index];\n\t\tif (message === undefined || message.role !== \"user\") break;\n\t\tconst text = userText(message);\n\t\tif (text.length > 0) trailing.unshift(text);\n\t}\n\tif (trailing.length > 0) return trailing.join(\"\\n\\n\");\n\tfor (let index = context.messages.length - 1; index >= 0; index -= 1) {\n\t\tconst message = context.messages[index];\n\t\tif (message?.role === \"user\") return userText(message);\n\t}\n\tthrow new Error(\"cursor-cli-oauth needs a user message to prompt the Cursor CLI\");\n}\n\nfunction recapExchanges(context: Context): CursorCliRecapExchange[] {\n\tconst exchanges: CursorCliRecapExchange[] = [];\n\tfor (const message of context.messages) {\n\t\tif (message.role === \"user\") {\n\t\t\tconst text = typeof message.content === \"string\" ? message.content : blockText(message.content);\n\t\t\tif (text.length > 0) exchanges.push({ role: \"user\", text });\n\t\t} else if (message.role === \"assistant\") {\n\t\t\tconst text = blockText(message.content);\n\t\t\tif (text.length > 0) exchanges.push({ role: \"assistant\", text });\n\t\t}\n\t}\n\treturn exchanges.slice(-RECENT_EXCHANGE_LIMIT);\n}\n\nfunction isFailoverNotice(event: unknown): event is CursorCliFailoverNotice {\n\treturn (event as { type?: unknown }).type === \"cursor_account_changed\";\n}\n\nfunction isRestartNotice(event: unknown): event is CursorCliSessionRestartNotice {\n\treturn (event as { type?: unknown }).type === \"cursor_chat_restarted\";\n}\n\nfunction turnErrorMessage(error: unknown): string {\n\t// Failover wraps every surfaced failure and the router hands classification\n\t// inputs around as { thrown } records; the innermost cause is what the user needs.\n\tlet detail = error;\n\tfor (let depth = 0; depth < 3 && typeof detail === \"object\" && detail !== null; depth += 1) {\n\t\tconst wrapper = detail as { original?: unknown; thrown?: unknown };\n\t\tif (wrapper.original !== undefined) detail = wrapper.original;\n\t\telse if (wrapper.thrown !== undefined) detail = wrapper.thrown;\n\t\telse break;\n\t}\n\tif (detail instanceof Error) return detail.message;\n\tif (typeof detail === \"string\") return detail;\n\tconst message = (detail as { message?: unknown } | null)?.message;\n\treturn typeof message === \"string\" && message.length > 0 ? message : \"Cursor CLI turn failed\";\n}\n\n/**\n * Streams one Cursor CLI print-mode turn onto senpi's assistant event stream.\n * The CLI owns tool execution; senpi owns the context and reports only its own\n * token estimates, so no CLI-side number ever feeds compaction accounting.\n */\nexport function streamCursorCliOauth(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n\tdeps: CursorCliStreamDeps = {},\n): AssistantMessageEventStream {\n\tconst stream = createAssistantMessageEventStream();\n\tvoid (async () => {\n\t\tconst mapper: StreamMapper = {\n\t\t\tstream,\n\t\t\toutput: emptyCursorCliOutput(model),\n\t\t\tstarted: false,\n\t\t\topenKind: undefined,\n\t\t\topenIndex: -1,\n\t\t\topenText: \"\",\n\t\t\ttextAccumulated: \"\",\n\t\t};\n\t\tconst now = deps.now ?? Date.now;\n\t\tconst cwdDirectory = deps.cwd ?? process.cwd();\n\t\tconst agentDir = deps.agentDir ?? getAgentDir();\n\t\tconst store = deps.store ?? AuthStorage.create();\n\t\tconst router = deps.router ?? cursorCliSessionRouter;\n\t\tconst signal = options?.signal;\n\t\tlet wasAborted = signal?.aborted === true;\n\t\tlet sentPromptTokens = 0;\n\t\tlet runningHandle: CursorCliTransportHandle | undefined;\n\t\tlet handleRunning = false;\n\t\tconst onAbort = (): void => {\n\t\t\twasAborted = true;\n\t\t};\n\t\tif (!wasAborted) signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\ttry {\n\t\t\t// Fresh per turn: settings, credentials, and executable resolution are\n\t\t\t// never cached across turns, so back-to-back turns observe changes.\n\t\t\tconst settings = deps.settings ?? loadCursorCliOauthProviderSettingsFromDisk(cwdDirectory);\n\t\t\t// An explicit `enabled: false` is the kill switch; the flagless ambient\n\t\t\t// case is refused below, once the stored slots are known, so the turn path\n\t\t\t// and `assessConfiguration` share one opt-in rule.\n\t\t\tif (settings.explicitlyDisabled) throw new Error(DISABLED_MESSAGE);\n\t\t\tconst executableDeps: CursorAgentExecutableDeps = {\n\t\t\t\t...defaultCursorAgentExecutableDeps(),\n\t\t\t\tsettings: { executablePath: settings.executablePath },\n\t\t\t};\n\t\t\t// The executable gates the TURN before any guardrail or auth work: the\n\t\t\t// oauth check keeps a credential-backed lane selectable so turns reach\n\t\t\t// this point, and `cursor-agent not installed` + the install guidance\n\t\t\t// must originate here - before a spawn could report it without the marker.\n\t\t\ttry {\n\t\t\t\tresolveCursorAgentExecutable(deps.executableDeps ?? executableDeps);\n\t\t\t} catch (error) {\n\t\t\t\tthrow cursorAgentNotInstalledError(error);\n\t\t\t}\n\t\t\t// Guardrails decide before any spawn: an unacknowledged force attempt is\n\t\t\t// the turn's error outcome, and only the policy's force/plan/sandbox\n\t\t\t// verdict reaches the argv. Warnings surface as turn notices.\n\t\t\tconst guardrailSession = createCursorCliGuardrailSession();\n\t\t\tconst policy = resolveCursorCliExecutionPolicy(\n\t\t\t\t{\n\t\t\t\t\tforceExecution: settings.forceExecution,\n\t\t\t\t\tnoApprovalAcknowledgedAt: settings.noApprovalAcknowledgedAt,\n\t\t\t\t\texecutionMode: settings.executionMode,\n\t\t\t\t\tsandboxMode: settings.sandboxMode,\n\t\t\t\t},\n\t\t\t\tguardrailSession,\n\t\t\t\tsettings.denyCommands ?? [],\n\t\t\t);\n\t\t\tif (policy.status === \"refused\") throw new CursorCliExecutionRefusalError(policy.refusal);\n\t\t\tfor (const warning of policy.warnings) appendNotice(mapper, warning.message);\n\t\t\tconst stored = await store.read(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\t\t\tconst storedAccounts = stored?.type === \"oauth\" ? listAccounts(stored as CursorCliOauthCredential) : [];\n\t\t\tif (!isCursorCliOauthLaneEnabled(settings, storedAccounts.length)) throw new Error(DISABLED_MESSAGE);\n\t\t\tif (storedAccounts.length === 0) throw new Error(NO_ACCOUNTS_MESSAGE);\n\n\t\t\tconst prompt = turnPrompt(context);\n\t\t\tconst senpiSessionId = options?.affinitySessionId ?? options?.sessionId ?? DEFAULT_CURSOR_AFFINITY_KEY;\n\t\t\tconst spawnModel = resolveCursorCliSpawnModel(model as Model<\"cursor-agent\">, options?.thinkingSelection);\n\t\t\tconst turnInput: CursorCliSessionTurnInput = {\n\t\t\t\tprompt,\n\t\t\t\tmodel: spawnModel,\n\t\t\t\trecentExchanges: recapExchanges(context),\n\t\t\t};\n\n\t\t\tconst spawnAndStream = (\n\t\t\t\tattempt: { prompt: string; resumeChatId: string | undefined },\n\t\t\t\tslot: CursorCliAccountSlot,\n\t\t\t): AsyncIterable<CursorCliStreamEvent> => {\n\t\t\t\tsentPromptTokens = estimateTokens({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: attempt.prompt,\n\t\t\t\t\ttimestamp: now(),\n\t\t\t\t} satisfies AgentMessage);\n\t\t\t\tconst buffer = new CursorCliEventBuffer<CursorCliStreamEvent>();\n\t\t\t\tvoid (async () => {\n\t\t\t\t\tlet sawResult = false;\n\t\t\t\t\t// Malformed events are held until the exit outcome is known: a\n\t\t\t\t\t// non-zero exit without a result means the captured stderr is the\n\t\t\t\t\t// real cause, and the parser's trailing incomplete_stream event\n\t\t\t\t\t// would otherwise mask it.\n\t\t\t\t\tconst heldMalformed: CursorCliStreamEvent[] = [];\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait runInCursorAccountHome(\n\t\t\t\t\t\t\tagentDir,\n\t\t\t\t\t\t\tslot,\n\t\t\t\t\t\t\tasync ({ home }) => {\n\t\t\t\t\t\t\t\t// The CLI rewrites cli-config.json during every invocation, so the\n\t\t\t\t\t\t\t\t// deny list must ride the same per-spawn cadence as the home-store\n\t\t\t\t\t\t\t\t// auth.json preparation directly above this spawn.\n\t\t\t\t\t\t\t\tapplyCursorCliDenyConfig(home, policy.denyCommands);\n\t\t\t\t\t\t\t\tconst handle = spawnCursorCli({\n\t\t\t\t\t\t\t\t\tprompt: attempt.prompt,\n\t\t\t\t\t\t\t\t\tmodel: spawnModel,\n\t\t\t\t\t\t\t\t\tresumeChatId: attempt.resumeChatId,\n\t\t\t\t\t\t\t\t\tforce: policy.force,\n\t\t\t\t\t\t\t\t\texecutionMode: policy.executionMode,\n\t\t\t\t\t\t\t\t\tsandboxMode: policy.sandboxMode,\n\t\t\t\t\t\t\t\t\taccountHome: home,\n\t\t\t\t\t\t\t\t\tcwd: cwdDirectory,\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t\texecutableDeps: deps.executableDeps ?? executableDeps,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\trunningHandle = handle;\n\t\t\t\t\t\t\t\thandleRunning = true;\n\t\t\t\t\t\t\t\tif (wasAborted) handle.abort();\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tfor await (const event of handle.events) {\n\t\t\t\t\t\t\t\t\t\tif (event instanceof CursorCliAbortError) {\n\t\t\t\t\t\t\t\t\t\t\tbuffer.fail(event);\n\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tif (event.type === \"result\") sawResult = true;\n\t\t\t\t\t\t\t\t\t\tif (event.type === \"malformed_stream\") {\n\t\t\t\t\t\t\t\t\t\t\theldMalformed.push(event);\n\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tbuffer.push(event);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst outcome = await handle.completed;\n\t\t\t\t\t\t\t\t\tif (outcome.type === \"completed\" && outcome.exitCode !== 0 && !sawResult) {\n\t\t\t\t\t\t\t\t\t\tbuffer.fail(new CursorCliProcessFailureError(outcome.exitCode, outcome.stderr));\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tfor (const event of heldMalformed) buffer.push(event);\n\t\t\t\t\t\t\t\t\tbuffer.close();\n\t\t\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\t\t\thandleRunning = false;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdeps.log,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbuffer.close();\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tbuffer.fail(error);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t\treturn buffer.events();\n\t\t\t};\n\n\t\t\tconst turn = runCursorCliFailover<CursorCliStreamEvent | CursorCliSessionRestartNotice>({\n\t\t\t\tstore,\n\t\t\t\tproviderId: CURSOR_CLI_OAUTH_PROVIDER_ID,\n\t\t\t\taffinity: {\n\t\t\t\t\tsessionId: senpiSessionId,\n\t\t\t\t\tpinnedAccount: settings.pinnedAccount,\n\t\t\t\t\tnow: now(),\n\t\t\t\t},\n\t\t\t\tnow: () => now(),\n\t\t\t\trunAttempt: async (selected, _options: CursorCliAttemptOptions) => {\n\t\t\t\t\tlet slot = selected;\n\t\t\t\t\tconst current = await store.read(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\t\t\t\t\tif (current?.type === \"oauth\") {\n\t\t\t\t\t\tconst fresh = (current as CursorCliOauthCredential).accounts?.find(\n\t\t\t\t\t\t\t(candidate) => candidate.name === slot.name,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (fresh) slot = fresh;\n\t\t\t\t\t}\n\t\t\t\t\t// An expired access token would classify as auth_error and block the\n\t\t\t\t\t// account until re-login; refresh it while the refresh token exists.\n\t\t\t\t\tif (now() >= slot.expires) {\n\t\t\t\t\t\tconst oauth =\n\t\t\t\t\t\t\tdeps.oauth ??\n\t\t\t\t\t\t\tcreateCursorCliOauthConfig({\n\t\t\t\t\t\t\t\treadCurrent: () => store.read(CURSOR_CLI_OAUTH_PROVIDER_ID),\n\t\t\t\t\t\t\t\treadSettings: () => settings,\n\t\t\t\t\t\t\t\tresolveExecutable: (oauthSettings) =>\n\t\t\t\t\t\t\t\t\tresolveCursorAgentExecutable({\n\t\t\t\t\t\t\t\t\t\t...(deps.executableDeps ?? executableDeps),\n\t\t\t\t\t\t\t\t\t\tsettings: { executablePath: oauthSettings.executablePath },\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst storedCredential =\n\t\t\t\t\t\t\tcurrent?.type === \"oauth\" ? (current as CursorCliOauthCredential) : emptyCredential();\n\t\t\t\t\t\tconst refreshed = await oauth.refreshToken(storedCredential, signal ?? new AbortController().signal);\n\t\t\t\t\t\t// refreshToken re-applies the sentinel fields over the stored credential,\n\t\t\t\t\t\t// so the result keeps the persisted oauth shape.\n\t\t\t\t\t\tawait store.modify(CURSOR_CLI_OAUTH_PROVIDER_ID, async () => refreshed as CursorCliOauthCredential);\n\t\t\t\t\t\tconst reread = await store.read(CURSOR_CLI_OAUTH_PROVIDER_ID);\n\t\t\t\t\t\tconst updated =\n\t\t\t\t\t\t\treread?.type === \"oauth\"\n\t\t\t\t\t\t\t\t? (reread as CursorCliOauthCredential).accounts?.find(\n\t\t\t\t\t\t\t\t\t\t(candidate) => candidate.name === slot.name,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\tif (!updated) {\n\t\t\t\t\t\t\tthrow new Error(`cursor-cli-oauth account '${slot.name}' disappeared during token refresh`);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tslot = updated;\n\t\t\t\t\t}\n\t\t\t\t\t// Cross-account chats live in each account's HOME, so a fresh-chat\n\t\t\t\t\t// failover needs no flag here: the router resumes only its own account's chat.\n\t\t\t\t\treturn router.runTurn(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsenpiSessionId,\n\t\t\t\t\t\t\taccountName: slot.name,\n\t\t\t\t\t\t\trunAttempt: (attempt) => spawnAndStream(attempt, slot),\n\t\t\t\t\t\t\tresumeMode: settings.resumeMode,\n\t\t\t\t\t\t\tcontextRecapOnModelSwitch: settings.contextRecapOnModelSwitch,\n\t\t\t\t\t\t\tnow: () => now(),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tturnInput,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tfor await (const event of turn) {\n\t\t\t\tif (isFailoverNotice(event) || isRestartNotice(event)) {\n\t\t\t\t\tappendNotice(mapper, event.message);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tswitch (event.type) {\n\t\t\t\t\tcase \"system\":\n\t\t\t\t\t\t// The session router already recorded chat id and model from init.\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"thinking\":\n\t\t\t\t\t\tif (event.subtype === \"completed\") {\n\t\t\t\t\t\t\tif (mapper.openKind === \"thinking\") closeOpen(mapper);\n\t\t\t\t\t\t} else if (event.text.length > 0) {\n\t\t\t\t\t\t\tensureOpen(mapper, \"thinking\");\n\t\t\t\t\t\t\tpushThinkingDelta(mapper, event.text);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"assistant\":\n\t\t\t\t\t\tfor (const block of event.message.content) appendAssistantFragment(mapper, block.text);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"tool_call\":\n\t\t\t\t\t\t// Preserve the text-segment boundary and cumulative snapshot reset,\n\t\t\t\t\t\t// but do not expose provider protocol frames as assistant text or map\n\t\t\t\t\t\t// them to host tool calls that Senpi could execute a second time.\n\t\t\t\t\t\tresetTextSegment(mapper);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"result\":\n\t\t\t\t\t\tif (event.subtype === \"success\" && !event.is_error) {\n\t\t\t\t\t\t\tapplyResultEvent(\n\t\t\t\t\t\t\t\tmapper,\n\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\tsentPromptTokens,\n\t\t\t\t\t\t\t\tevent.usage,\n\t\t\t\t\t\t\t\tevent.request_id,\n\t\t\t\t\t\t\t\tevent.duration_ms,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t// malformed_stream events are converted to failures inside the\n\t\t\t\t\t\t// session router and never reach this loop.\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcloseOpen(mapper);\n\t\t\tstream.push({ type: \"done\", reason: \"stop\", message: mapper.output });\n\t\t} catch (error) {\n\t\t\tcloseOpen(mapper);\n\t\t\tconst aborted = wasAborted || signal?.aborted === true;\n\t\t\tmapper.output.stopReason = aborted ? \"aborted\" : \"error\";\n\t\t\tmapper.output.errorMessage = turnErrorMessage(error);\n\t\t\tstream.push({ type: \"error\", reason: mapper.output.stopReason, error: mapper.output });\n\t\t} finally {\n\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\tif (handleRunning) runningHandle?.abort();\n\t\t\tstream.end();\n\t\t}\n\t})();\n\treturn stream;\n}\n"]}
|
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `restartable-command`
|
|
3
|
-
* command
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* The `restartable-command` restore handler. It stops a verified crash-orphaned watcher first,
|
|
3
|
+
* re-spawns the saved command once in the saved cwd with the restore environment (stable id,
|
|
4
|
+
* state dir, restored flag, downtime bound), and only calls the watch restored if it is still
|
|
5
|
+
* running when the grace window closes: an immediate non-zero exit is lost with its exit code and
|
|
6
|
+
* first output line, an immediate zero exit is a completed one-shot gate. A persistent watch has
|
|
7
|
+
* no deadline; an ephemeral one gets exactly the time it had left. Nothing the pre-restart PTY
|
|
8
|
+
* produced is replayed.
|
|
8
9
|
*/
|
|
9
10
|
import type { MonitorRegistry } from "./monitor-registry.ts";
|
|
11
|
+
import { type ReapResult } from "./orphan-reaper.ts";
|
|
12
|
+
import type { ChildProcessIdentity } from "./process-identity.ts";
|
|
10
13
|
import { type RestoreHandler } from "./restore.ts";
|
|
11
14
|
import type { TerminalToolContext } from "./tools/context.ts";
|
|
12
15
|
import { spawnCommandSession } from "./tools/spawn.ts";
|
|
13
16
|
export interface RestartableCommandDeps {
|
|
14
|
-
/** Spawn target: supplies the terminal manager, shell config, env and default geometry. */
|
|
15
17
|
readonly ctx: TerminalToolContext;
|
|
16
|
-
/** The live registry this generation owns; the restored watch is registered here. */
|
|
17
18
|
readonly registry: MonitorRegistry;
|
|
18
|
-
/** Seam for tests and future callers; defaults to the real PTY spawn. */
|
|
19
19
|
readonly spawn?: typeof spawnCommandSession;
|
|
20
|
-
/** Directory existence probe; defaults to a real stat of the saved cwd. */
|
|
21
20
|
readonly directoryExists?: (path: string) => Promise<boolean>;
|
|
22
|
-
/** Called after a successful restore with the stable id and its fresh runtime id. */
|
|
23
21
|
readonly onRestored?: (monitorId: string, runtimeId: string) => void;
|
|
22
|
+
readonly graceMs?: number;
|
|
23
|
+
readonly reapOrphan?: (runtime: ChildProcessIdentity, monitorId: string) => Promise<ReapResult>;
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Build the `restartable-command` restore handler. Every guard rejects BEFORE spawning, so a
|
|
27
|
-
* rejected entry costs zero PTY sessions; a spawn failure is reported lost rather than thrown,
|
|
28
|
-
* because restore must never fail the startup path for one unrecoverable watch.
|
|
29
|
-
*/
|
|
30
25
|
export declare function createRestartableCommandHandler(deps: RestartableCommandDeps): RestoreHandler;
|
|
31
26
|
//# sourceMappingURL=durable-command.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durable-command.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/durable-command.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"durable-command.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/durable-command.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,EAAE,KAAK,UAAU,EAAqB,MAAM,oBAAoB,CAAC;AAExE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAEN,KAAK,cAAc,EAGnB,MAAM,cAAc,CAAC;AAYtB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,GAAG,EAAE,mBAAmB,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,mBAAmB,CAAC;IAC5C,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9D,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACrE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CAChG;AA8ED,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,sBAAsB,GAAG,cAAc,CAkE5F"}
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `restartable-command`
|
|
3
|
-
* command
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* The `restartable-command` restore handler. It stops a verified crash-orphaned watcher first,
|
|
3
|
+
* re-spawns the saved command once in the saved cwd with the restore environment (stable id,
|
|
4
|
+
* state dir, restored flag, downtime bound), and only calls the watch restored if it is still
|
|
5
|
+
* running when the grace window closes: an immediate non-zero exit is lost with its exit code and
|
|
6
|
+
* first output line, an immediate zero exit is a completed one-shot gate. A persistent watch has
|
|
7
|
+
* no deadline; an ephemeral one gets exactly the time it had left. Nothing the pre-restart PTY
|
|
8
|
+
* produced is replayed.
|
|
8
9
|
*/
|
|
9
10
|
import { stat } from "node:fs/promises";
|
|
10
11
|
import { isAbsolute } from "node:path";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
12
|
+
import { ensureMonitorStateDir, terminalStateDir } from "./monitor-state-dir.js";
|
|
13
|
+
import { formatElapsedSeconds } from "./monitor-status.js";
|
|
14
|
+
import { reapBeforeRespawn } from "./orphan-reaper.js";
|
|
15
|
+
import { sanitizeTerminalOutput } from "./output-format.js";
|
|
16
|
+
import { reapplyPersistedMute, } from "./restore.js";
|
|
17
|
+
import { DEFAULT_COLS, DEFAULT_ROWS, MONITOR_ENV_DOWNTIME_MS, MONITOR_ENV_ID, MONITOR_ENV_RESTORED, MONITOR_ENV_STATE_DIR, RESTORE_GRACE_MS, } from "./shared.js";
|
|
13
18
|
import { spawnCommandSession } from "./tools/spawn.js";
|
|
14
|
-
const
|
|
19
|
+
const MAX_REASON_OUTPUT_CHARS = 200;
|
|
20
|
+
const lost = (reason, orphan) => ({
|
|
21
|
+
outcome: "lost",
|
|
22
|
+
reason,
|
|
23
|
+
...(orphan !== undefined ? { orphan } : {}),
|
|
24
|
+
});
|
|
15
25
|
async function defaultDirectoryExists(path) {
|
|
16
26
|
try {
|
|
17
27
|
return (await stat(path)).isDirectory();
|
|
@@ -34,66 +44,110 @@ function compileFilter(source) {
|
|
|
34
44
|
function dimension(value, fallback) {
|
|
35
45
|
return value !== undefined && Number.isFinite(value) && value >= 1 ? Math.trunc(value) : fallback;
|
|
36
46
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
function exitsWithin(runtime, ms) {
|
|
48
|
+
if (runtime.exited)
|
|
49
|
+
return Promise.resolve(true);
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
|
+
const timer = setTimeout(() => {
|
|
52
|
+
unsubscribe();
|
|
53
|
+
resolve(false);
|
|
54
|
+
}, ms);
|
|
55
|
+
const unsubscribe = runtime.session.onExit(() => {
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
resolve(true);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function firstOutputLine(runtime) {
|
|
62
|
+
const line = sanitizeTerminalOutput(runtime.fullOutput())
|
|
63
|
+
.split("\n")
|
|
64
|
+
.map((text) => text.trim())
|
|
65
|
+
.find((text) => text.length > 0);
|
|
66
|
+
return (line ?? "").slice(0, MAX_REASON_OUTPUT_CHARS);
|
|
67
|
+
}
|
|
68
|
+
function orphanOf(runtime, reap) {
|
|
69
|
+
if (runtime === undefined || reap === undefined)
|
|
50
70
|
return undefined;
|
|
51
|
-
|
|
71
|
+
if (reap.action === "killed")
|
|
72
|
+
return { pid: runtime.pid, action: "killed" };
|
|
73
|
+
if (reap.reason !== undefined)
|
|
74
|
+
return { pid: runtime.pid, action: "unverified" };
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
async function restoreEnvironment(deps, monitor, context) {
|
|
78
|
+
const env = {
|
|
79
|
+
[MONITOR_ENV_ID]: monitor.monitorId,
|
|
80
|
+
[MONITOR_ENV_RESTORED]: "1",
|
|
81
|
+
[MONITOR_ENV_DOWNTIME_MS]: String(context.downtimeMs),
|
|
82
|
+
};
|
|
83
|
+
const terminalDir = terminalStateDir(deps.ctx.getSessionContext?.());
|
|
84
|
+
if (monitor.persistent && terminalDir !== undefined) {
|
|
85
|
+
env[MONITOR_ENV_STATE_DIR] = await ensureMonitorStateDir(terminalDir, monitor.monitorId);
|
|
86
|
+
}
|
|
87
|
+
return env;
|
|
52
88
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Build the `restartable-command` restore handler. Every guard rejects BEFORE spawning, so a
|
|
55
|
-
* rejected entry costs zero PTY sessions; a spawn failure is reported lost rather than thrown,
|
|
56
|
-
* because restore must never fail the startup path for one unrecoverable watch.
|
|
57
|
-
*/
|
|
58
89
|
export function createRestartableCommandHandler(deps) {
|
|
59
90
|
const spawn = deps.spawn ?? spawnCommandSession;
|
|
60
91
|
const directoryExists = deps.directoryExists ?? defaultDirectoryExists;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
return
|
|
92
|
+
const reapOrphan = deps.reapOrphan ?? reapBeforeRespawn;
|
|
93
|
+
const graceMs = deps.graceMs ?? RESTORE_GRACE_MS;
|
|
94
|
+
return async (monitor, context) => {
|
|
95
|
+
const ephemeralTimeLeft = monitor.persistent ? undefined : context.remainingMs;
|
|
96
|
+
if (monitor.runtimeKind !== "command" || (!monitor.persistent && ephemeralTimeLeft === undefined)) {
|
|
97
|
+
return lost("not a restorable command watch");
|
|
98
|
+
}
|
|
99
|
+
const { command, cwd } = monitor;
|
|
100
|
+
if (command === undefined || command.length === 0)
|
|
101
|
+
return lost("no command was recorded");
|
|
102
|
+
if (cwd === undefined || !isAbsolute(cwd))
|
|
103
|
+
return lost("no absolute cwd was recorded");
|
|
104
|
+
if (!(await directoryExists(cwd)))
|
|
105
|
+
return lost(`cwd no longer exists: ${cwd}`);
|
|
106
|
+
const reap = monitor.runtime === undefined ? undefined : await reapOrphan(monitor.runtime, monitor.monitorId);
|
|
107
|
+
const orphan = orphanOf(monitor.runtime, reap);
|
|
67
108
|
let spawned;
|
|
68
109
|
try {
|
|
69
110
|
spawned = await spawn(deps.ctx, {
|
|
70
|
-
command
|
|
111
|
+
command,
|
|
71
112
|
cols: dimension(deps.ctx.defaultCols, DEFAULT_COLS),
|
|
72
113
|
rows: dimension(deps.ctx.defaultRows, DEFAULT_ROWS),
|
|
73
|
-
cwd
|
|
74
|
-
|
|
114
|
+
cwd,
|
|
115
|
+
envOverrides: await restoreEnvironment(deps, monitor, context),
|
|
116
|
+
...(ephemeralTimeLeft !== undefined ? { timeoutMs: ephemeralTimeLeft } : {}),
|
|
75
117
|
});
|
|
76
118
|
}
|
|
77
|
-
catch {
|
|
78
|
-
return
|
|
119
|
+
catch (error) {
|
|
120
|
+
return lost(`spawn failed: ${error instanceof Error ? error.message : String(error)}`, orphan);
|
|
79
121
|
}
|
|
80
122
|
deps.registry.register({
|
|
81
123
|
id: spawned.id,
|
|
82
124
|
monitorId: monitor.monitorId,
|
|
83
125
|
description: monitor.description,
|
|
84
|
-
command
|
|
85
|
-
persistent:
|
|
86
|
-
deadlineMs: null,
|
|
126
|
+
command,
|
|
127
|
+
persistent: monitor.persistent,
|
|
128
|
+
deadlineMs: ephemeralTimeLeft !== undefined ? Date.now() + ephemeralTimeLeft : null,
|
|
87
129
|
runtime: spawned.runtime,
|
|
88
130
|
filter: compileFilter(monitor.filter),
|
|
89
131
|
// The persisted deadline rides through verbatim; a restore never extends it.
|
|
90
132
|
...(monitor.expiresAt !== null ? { expiresAt: monitor.expiresAt } : {}),
|
|
91
133
|
});
|
|
92
134
|
deps.ctx.manager.bindMonitorId(monitor.monitorId, spawned.id);
|
|
135
|
+
const startedAt = Date.now();
|
|
136
|
+
if (await exitsWithin(spawned.runtime, graceMs)) {
|
|
137
|
+
const code = spawned.runtime.exitResult?.exitCode ?? null;
|
|
138
|
+
if (code === 0)
|
|
139
|
+
return { outcome: "completed", ...(orphan !== undefined ? { orphan } : {}) };
|
|
140
|
+
const output = firstOutputLine(spawned.runtime);
|
|
141
|
+
const exit = code === null ? "exited" : `exited ${code}`;
|
|
142
|
+
return lost(`${exit} in ${Date.now() - startedAt}ms${output.length > 0 ? `: ${output}` : ""}`, orphan);
|
|
143
|
+
}
|
|
144
|
+
deps.registry.emitLine(spawned.id, `restored after up to ${formatElapsedSeconds(context.downtimeMs / 1000)} offline; the command started fresh`);
|
|
93
145
|
deps.onRestored?.(monitor.monitorId, spawned.id);
|
|
94
146
|
// A persisted mute is re-applied by the FRESH runtime id; the registry resolves
|
|
95
147
|
// records by runtime id only, so the mon_ id would silently no-op here.
|
|
96
|
-
|
|
148
|
+
const outcome = reapplyPersistedMute(deps.registry, monitor, spawned.id);
|
|
149
|
+
const runtime = spawned.runtime.identity();
|
|
150
|
+
return { outcome, ...(orphan !== undefined ? { orphan } : {}), ...(runtime !== undefined ? { runtime } : {}) };
|
|
97
151
|
};
|
|
98
152
|
}
|
|
99
153
|
//# sourceMappingURL=durable-command.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durable-command.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/durable-command.ts"],"names":[],"mappings":"AAAA;;;;;;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W,EAAE,OAAO,CAAC,WAAW;YAChC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,IAAI;YAChB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;YACrC,6EAA6E;YAC7E,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACvE,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QACjD,gFAAgF;QAChF,wEAAwE;QACxE,OAAO,EAAE,OAAO,EAAE,oBAAoB,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;IAC9E,CAAC,CAAC;AACH,CAAC","sourcesContent":["/**\n * The `restartable-command` durability class: the restore handler that brings a persistent\n * command monitor back after a restart. It re-spawns the saved command EXACTLY ONCE, in the\n * saved working directory, with NO timeout (a persistent watch has no deadline), and\n * re-registers it under the SAVED `mon_` id so the stable handle the agent already knows\n * keeps resolving. Nothing the pre-restart PTY produced is replayed — no output is persisted\n * anywhere, so a restored watch starts from an empty buffer by construction.\n */\n\nimport { stat } from \"node:fs/promises\";\nimport { isAbsolute } from \"node:path\";\nimport type { MonitorRegistry } from \"./monitor-registry.ts\";\nimport { type RestoreHandler, type RestoreHandlerResult, reapplyPersistedMute } from \"./restore.ts\";\nimport { DEFAULT_COLS, DEFAULT_ROWS } from \"./shared.ts\";\nimport type { ManifestMonitor } from \"./terminal-manifest.ts\";\nimport type { TerminalToolContext } from \"./tools/context.ts\";\nimport { spawnCommandSession } from \"./tools/spawn.ts\";\n\nexport interface RestartableCommandDeps {\n\t/** Spawn target: supplies the terminal manager, shell config, env and default geometry. */\n\treadonly ctx: TerminalToolContext;\n\t/** The live registry this generation owns; the restored watch is registered here. */\n\treadonly registry: MonitorRegistry;\n\t/** Seam for tests and future callers; defaults to the real PTY spawn. */\n\treadonly spawn?: typeof spawnCommandSession;\n\t/** Directory existence probe; defaults to a real stat of the saved cwd. */\n\treadonly directoryExists?: (path: string) => Promise<boolean>;\n\t/** Called after a successful restore with the stable id and its fresh runtime id. */\n\treadonly onRestored?: (monitorId: string, runtimeId: string) => void;\n}\n\nconst LOST: RestoreHandlerResult = { outcome: \"lost\" };\n\nasync function defaultDirectoryExists(path: string): Promise<boolean> {\n\ttry {\n\t\treturn (await stat(path)).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction compileFilter(source: string | undefined): RegExp | undefined {\n\tif (source === undefined) return undefined;\n\ttry {\n\t\treturn new RegExp(source);\n\t} catch {\n\t\t// A filter that no longer compiles must not sink the watch: restore it unfiltered.\n\t\treturn undefined;\n\t}\n}\n\nfunction dimension(value: number | undefined, fallback: number): number {\n\treturn value !== undefined && Number.isFinite(value) && value >= 1 ? Math.trunc(value) : fallback;\n}\n\n/**\n * Decide whether a manifest entry is a restorable persistent command watch. Only the\n * command runtime kind qualifies, only when it was created `persistent: true` (a\n * non-persistent watch had a deadline and is deliberately not resurrected), and only\n * when it actually carries a command and an absolute cwd to spawn it in.\n */\nfunction restorable(monitor: ManifestMonitor): { command: string; cwd: string } | undefined {\n\tif (monitor.runtimeKind !== \"command\" || !monitor.persistent) return undefined;\n\tconst { command, cwd } = monitor;\n\tif (command === undefined || command.length === 0) return undefined;\n\tif (cwd === undefined || !isAbsolute(cwd)) return undefined;\n\treturn { command, cwd };\n}\n\n/**\n * Build the `restartable-command` restore handler. Every guard rejects BEFORE spawning, so a\n * rejected entry costs zero PTY sessions; a spawn failure is reported lost rather than thrown,\n * because restore must never fail the startup path for one unrecoverable watch.\n */\nexport function createRestartableCommandHandler(deps: RestartableCommandDeps): RestoreHandler {\n\tconst spawn = deps.spawn ?? spawnCommandSession;\n\tconst directoryExists = deps.directoryExists ?? defaultDirectoryExists;\n\treturn async (monitor: ManifestMonitor): Promise<RestoreHandlerResult> => {\n\t\tconst target = restorable(monitor);\n\t\tif (target === undefined) return LOST;\n\t\tif (!(await directoryExists(target.cwd))) return LOST;\n\n\t\tlet spawned: Awaited<ReturnType<typeof spawnCommandSession>>;\n\t\ttry {\n\t\t\tspawned = await spawn(deps.ctx, {\n\t\t\t\tcommand: target.command,\n\t\t\t\tcols: dimension(deps.ctx.defaultCols, DEFAULT_COLS),\n\t\t\t\trows: dimension(deps.ctx.defaultRows, DEFAULT_ROWS),\n\t\t\t\tcwd: target.cwd,\n\t\t\t\t// Persistent watches carry no deadline: omit timeoutMs entirely.\n\t\t\t});\n\t\t} catch {\n\t\t\treturn LOST;\n\t\t}\n\n\t\tdeps.registry.register({\n\t\t\tid: spawned.id,\n\t\t\tmonitorId: monitor.monitorId,\n\t\t\tdescription: monitor.description,\n\t\t\tcommand: monitor.command,\n\t\t\tpersistent: true,\n\t\t\tdeadlineMs: null,\n\t\t\truntime: spawned.runtime,\n\t\t\tfilter: compileFilter(monitor.filter),\n\t\t\t// The persisted deadline rides through verbatim; a restore never extends it.\n\t\t\t...(monitor.expiresAt !== null ? { expiresAt: monitor.expiresAt } : {}),\n\t\t});\n\t\tdeps.ctx.manager.bindMonitorId(monitor.monitorId, spawned.id);\n\t\tdeps.onRestored?.(monitor.monitorId, spawned.id);\n\t\t// A persisted mute is re-applied by the FRESH runtime id; the registry resolves\n\t\t// records by runtime id only, so the mon_ id would silently no-op here.\n\t\treturn { outcome: reapplyPersistedMute(deps.registry, monitor, spawned.id) };\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"durable-command.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/durable-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AC,QAAQ,EAAE,CAAC;QAC3C,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAChH,CAAC,CAAC;AACH,CAAC","sourcesContent":["/**\n * The `restartable-command` restore handler. It stops a verified crash-orphaned watcher first,\n * re-spawns the saved command once in the saved cwd with the restore environment (stable id,\n * state dir, restored flag, downtime bound), and only calls the watch restored if it is still\n * running when the grace window closes: an immediate non-zero exit is lost with its exit code and\n * first output line, an immediate zero exit is a completed one-shot gate. A persistent watch has\n * no deadline; an ephemeral one gets exactly the time it had left. Nothing the pre-restart PTY\n * produced is replayed.\n */\n\nimport { stat } from \"node:fs/promises\";\nimport { isAbsolute } from \"node:path\";\nimport type { MonitorRegistry } from \"./monitor-registry.ts\";\nimport { ensureMonitorStateDir, terminalStateDir } from \"./monitor-state-dir.ts\";\nimport { formatElapsedSeconds } from \"./monitor-status.ts\";\nimport { type ReapResult, reapBeforeRespawn } from \"./orphan-reaper.ts\";\nimport { sanitizeTerminalOutput } from \"./output-format.ts\";\nimport type { ChildProcessIdentity } from \"./process-identity.ts\";\nimport {\n\ttype RestoreContext,\n\ttype RestoreHandler,\n\ttype RestoreHandlerResult,\n\treapplyPersistedMute,\n} from \"./restore.ts\";\nimport type { TerminalRuntimeSession } from \"./runtime-session.ts\";\nimport {\n\tDEFAULT_COLS,\n\tDEFAULT_ROWS,\n\tMONITOR_ENV_DOWNTIME_MS,\n\tMONITOR_ENV_ID,\n\tMONITOR_ENV_RESTORED,\n\tMONITOR_ENV_STATE_DIR,\n\tRESTORE_GRACE_MS,\n} from \"./shared.ts\";\nimport type { ManifestMonitor } from \"./terminal-manifest.ts\";\nimport type { TerminalToolContext } from \"./tools/context.ts\";\nimport { spawnCommandSession } from \"./tools/spawn.ts\";\n\nexport interface RestartableCommandDeps {\n\treadonly ctx: TerminalToolContext;\n\treadonly registry: MonitorRegistry;\n\treadonly spawn?: typeof spawnCommandSession;\n\treadonly directoryExists?: (path: string) => Promise<boolean>;\n\treadonly onRestored?: (monitorId: string, runtimeId: string) => void;\n\treadonly graceMs?: number;\n\treadonly reapOrphan?: (runtime: ChildProcessIdentity, monitorId: string) => Promise<ReapResult>;\n}\n\nconst MAX_REASON_OUTPUT_CHARS = 200;\n\nconst lost = (reason: string, orphan?: RestoreHandlerResult[\"orphan\"]): RestoreHandlerResult => ({\n\toutcome: \"lost\",\n\treason,\n\t...(orphan !== undefined ? { orphan } : {}),\n});\n\nasync function defaultDirectoryExists(path: string): Promise<boolean> {\n\ttry {\n\t\treturn (await stat(path)).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction compileFilter(source: string | undefined): RegExp | undefined {\n\tif (source === undefined) return undefined;\n\ttry {\n\t\treturn new RegExp(source);\n\t} catch {\n\t\t// A filter that no longer compiles must not sink the watch: restore it unfiltered.\n\t\treturn undefined;\n\t}\n}\n\nfunction dimension(value: number | undefined, fallback: number): number {\n\treturn value !== undefined && Number.isFinite(value) && value >= 1 ? Math.trunc(value) : fallback;\n}\n\nfunction exitsWithin(runtime: TerminalRuntimeSession, ms: number): Promise<boolean> {\n\tif (runtime.exited) return Promise.resolve(true);\n\treturn new Promise((resolve) => {\n\t\tconst timer = setTimeout(() => {\n\t\t\tunsubscribe();\n\t\t\tresolve(false);\n\t\t}, ms);\n\t\tconst unsubscribe = runtime.session.onExit(() => {\n\t\t\tclearTimeout(timer);\n\t\t\tresolve(true);\n\t\t});\n\t});\n}\n\nfunction firstOutputLine(runtime: TerminalRuntimeSession): string {\n\tconst line = sanitizeTerminalOutput(runtime.fullOutput())\n\t\t.split(\"\\n\")\n\t\t.map((text) => text.trim())\n\t\t.find((text) => text.length > 0);\n\treturn (line ?? \"\").slice(0, MAX_REASON_OUTPUT_CHARS);\n}\n\nfunction orphanOf(runtime: ChildProcessIdentity | undefined, reap: ReapResult | undefined) {\n\tif (runtime === undefined || reap === undefined) return undefined;\n\tif (reap.action === \"killed\") return { pid: runtime.pid, action: \"killed\" } as const;\n\tif (reap.reason !== undefined) return { pid: runtime.pid, action: \"unverified\" } as const;\n\treturn undefined;\n}\n\nasync function restoreEnvironment(\n\tdeps: RestartableCommandDeps,\n\tmonitor: ManifestMonitor,\n\tcontext: RestoreContext,\n): Promise<Record<string, string>> {\n\tconst env: Record<string, string> = {\n\t\t[MONITOR_ENV_ID]: monitor.monitorId,\n\t\t[MONITOR_ENV_RESTORED]: \"1\",\n\t\t[MONITOR_ENV_DOWNTIME_MS]: String(context.downtimeMs),\n\t};\n\tconst terminalDir = terminalStateDir(deps.ctx.getSessionContext?.());\n\tif (monitor.persistent && terminalDir !== undefined) {\n\t\tenv[MONITOR_ENV_STATE_DIR] = await ensureMonitorStateDir(terminalDir, monitor.monitorId);\n\t}\n\treturn env;\n}\n\nexport function createRestartableCommandHandler(deps: RestartableCommandDeps): RestoreHandler {\n\tconst spawn = deps.spawn ?? spawnCommandSession;\n\tconst directoryExists = deps.directoryExists ?? defaultDirectoryExists;\n\tconst reapOrphan = deps.reapOrphan ?? reapBeforeRespawn;\n\tconst graceMs = deps.graceMs ?? RESTORE_GRACE_MS;\n\treturn async (monitor: ManifestMonitor, context: RestoreContext): Promise<RestoreHandlerResult> => {\n\t\tconst ephemeralTimeLeft = monitor.persistent ? undefined : context.remainingMs;\n\t\tif (monitor.runtimeKind !== \"command\" || (!monitor.persistent && ephemeralTimeLeft === undefined)) {\n\t\t\treturn lost(\"not a restorable command watch\");\n\t\t}\n\t\tconst { command, cwd } = monitor;\n\t\tif (command === undefined || command.length === 0) return lost(\"no command was recorded\");\n\t\tif (cwd === undefined || !isAbsolute(cwd)) return lost(\"no absolute cwd was recorded\");\n\t\tif (!(await directoryExists(cwd))) return lost(`cwd no longer exists: ${cwd}`);\n\n\t\tconst reap = monitor.runtime === undefined ? undefined : await reapOrphan(monitor.runtime, monitor.monitorId);\n\t\tconst orphan = orphanOf(monitor.runtime, reap);\n\n\t\tlet spawned: Awaited<ReturnType<typeof spawnCommandSession>>;\n\t\ttry {\n\t\t\tspawned = await spawn(deps.ctx, {\n\t\t\t\tcommand,\n\t\t\t\tcols: dimension(deps.ctx.defaultCols, DEFAULT_COLS),\n\t\t\t\trows: dimension(deps.ctx.defaultRows, DEFAULT_ROWS),\n\t\t\t\tcwd,\n\t\t\t\tenvOverrides: await restoreEnvironment(deps, monitor, context),\n\t\t\t\t...(ephemeralTimeLeft !== undefined ? { timeoutMs: ephemeralTimeLeft } : {}),\n\t\t\t});\n\t\t} catch (error) {\n\t\t\treturn lost(`spawn failed: ${error instanceof Error ? error.message : String(error)}`, orphan);\n\t\t}\n\n\t\tdeps.registry.register({\n\t\t\tid: spawned.id,\n\t\t\tmonitorId: monitor.monitorId,\n\t\t\tdescription: monitor.description,\n\t\t\tcommand,\n\t\t\tpersistent: monitor.persistent,\n\t\t\tdeadlineMs: ephemeralTimeLeft !== undefined ? Date.now() + ephemeralTimeLeft : null,\n\t\t\truntime: spawned.runtime,\n\t\t\tfilter: compileFilter(monitor.filter),\n\t\t\t// The persisted deadline rides through verbatim; a restore never extends it.\n\t\t\t...(monitor.expiresAt !== null ? { expiresAt: monitor.expiresAt } : {}),\n\t\t});\n\t\tdeps.ctx.manager.bindMonitorId(monitor.monitorId, spawned.id);\n\n\t\tconst startedAt = Date.now();\n\t\tif (await exitsWithin(spawned.runtime, graceMs)) {\n\t\t\tconst code = spawned.runtime.exitResult?.exitCode ?? null;\n\t\t\tif (code === 0) return { outcome: \"completed\", ...(orphan !== undefined ? { orphan } : {}) };\n\t\t\tconst output = firstOutputLine(spawned.runtime);\n\t\t\tconst exit = code === null ? \"exited\" : `exited ${code}`;\n\t\t\treturn lost(`${exit} in ${Date.now() - startedAt}ms${output.length > 0 ? `: ${output}` : \"\"}`, orphan);\n\t\t}\n\n\t\tdeps.registry.emitLine(\n\t\t\tspawned.id,\n\t\t\t`restored after up to ${formatElapsedSeconds(context.downtimeMs / 1000)} offline; the command started fresh`,\n\t\t);\n\t\tdeps.onRestored?.(monitor.monitorId, spawned.id);\n\t\t// A persisted mute is re-applied by the FRESH runtime id; the registry resolves\n\t\t// records by runtime id only, so the mon_ id would silently no-op here.\n\t\tconst outcome = reapplyPersistedMute(deps.registry, monitor, spawned.id);\n\t\tconst runtime = spawned.runtime.identity();\n\t\treturn { outcome, ...(orphan !== undefined ? { orphan } : {}), ...(runtime !== undefined ? { runtime } : {}) };\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durable-file.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/durable-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"durable-file.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/durable-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAkB,cAAc,EAAwB,MAAM,cAAc,CAAC;AACzF,OAAO,KAAK,EAAmB,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAElH;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC;AAEjF,uFAAuF;AACvF,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,eAAe,EAAE,cAAc,GAAG,gBAAgB,GAAG,cAAc,GAAG,UAAU,CAAC,CAAC;IAC1G,6FAA6F;IAC7F,QAAQ,CAAC,MAAM,C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