@code-yeongyu/senpi 2026.9.12-2 → 2026.9.12
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 +0 -17
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +1 -5
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +9 -13
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +121 -54
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/models.d.ts.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/models.js +1 -2
- package/dist/core/extensions/builtin/cursor-cli-oauth/models.js.map +1 -1
- package/dist/core/session-manager.d.ts +0 -2
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +13 -22
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-write-reservation.d.ts +0 -9
- package/dist/core/session-write-reservation.d.ts.map +1 -1
- package/dist/core/session-write-reservation.js +0 -33
- package/dist/core/session-write-reservation.js.map +1 -1
- package/dist/modes/interactive/components/ask-user-async-widget.d.ts +0 -2
- package/dist/modes/interactive/components/ask-user-async-widget.d.ts.map +1 -1
- package/dist/modes/interactive/components/ask-user-async-widget.js +1 -17
- package/dist/modes/interactive/components/ask-user-async-widget.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +2 -2
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +1 -2
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +0 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/rpc/session-registry.d.ts +1 -3
- package/dist/modes/rpc/session-registry.d.ts.map +1 -1
- package/dist/modes/rpc/session-registry.js.map +1 -1
- package/dist/modes/rpc/session-worker-client.d.ts +8 -10
- package/dist/modes/rpc/session-worker-client.d.ts.map +1 -1
- package/dist/modes/rpc/session-worker-client.js +23 -14
- package/dist/modes/rpc/session-worker-client.js.map +1 -1
- package/dist/modes/rpc/session-worker-protocol.d.ts +0 -10
- package/dist/modes/rpc/session-worker-protocol.d.ts.map +1 -1
- package/dist/modes/rpc/session-worker-protocol.js +0 -2
- package/dist/modes/rpc/session-worker-protocol.js.map +1 -1
- package/dist/modes/rpc/session-worker.js +16 -12
- package/dist/modes/rpc/session-worker.js.map +1 -1
- package/dist/modes/rpc/worker-session-registry.d.ts +0 -12
- package/dist/modes/rpc/worker-session-registry.d.ts.map +1 -1
- package/dist/modes/rpc/worker-session-registry.js +24 -51
- package/dist/modes/rpc/worker-session-registry.js.map +1 -1
- package/docs/rpc.md +6 -14
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +0 -12
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent/measure.d.ts +0 -11
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent/measure.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent/measure.js +0 -18
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent/measure.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.d.ts +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.js +1 -5
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/cursor/store-migration.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/cursor/store-migration.js +1 -2
- package/node_modules/@earendil-works/pi-ai/dist/cursor/store-migration.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cursor.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cursor.js +1 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/cursor.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- 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 +7 -7
- package/dist/core/cursor-history-admission.d.ts +0 -50
- package/dist/core/cursor-history-admission.d.ts.map +0 -1
- package/dist/core/cursor-history-admission.js +0 -130
- package/dist/core/cursor-history-admission.js.map +0 -1
- package/dist/modes/rpc/session-path-reservations.d.ts +0 -30
- package/dist/modes/rpc/session-path-reservations.d.ts.map +0 -1
- package/dist/modes/rpc/session-path-reservations.js +0 -58
- package/dist/modes/rpc/session-path-reservations.js.map +0 -1
- package/dist/modes/rpc/session-worker-credit.d.ts +0 -17
- package/dist/modes/rpc/session-worker-credit.d.ts.map +0 -1
- package/dist/modes/rpc/session-worker-credit.js +0 -39
- package/dist/modes/rpc/session-worker-credit.js.map +0 -1
- package/dist/modes/rpc/session-worker-signals.d.ts +0 -7
- package/dist/modes/rpc/session-worker-signals.d.ts.map +0 -1
- package/dist/modes/rpc/session-worker-signals.js +0 -19
- package/dist/modes/rpc/session-worker-signals.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/cursor/context-limit-store.d.ts +0 -32
- package/node_modules/@earendil-works/pi-ai/dist/cursor/context-limit-store.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/cursor/context-limit-store.js +0 -62
- package/node_modules/@earendil-works/pi-ai/dist/cursor/context-limit-store.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/cursor-context-limit.d.ts +0 -12
- package/node_modules/@earendil-works/pi-ai/dist/utils/cursor-context-limit.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/cursor-context-limit.js +0 -93
- package/node_modules/@earendil-works/pi-ai/dist/utils/cursor-context-limit.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-session-registry.js","sourceRoot":"","sources":["../../../src/modes/rpc/worker-session-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAE1E,OAAO,EAEN,wBAAwB,EACxB,uBAAuB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAIN,uBAAuB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAA0B,MAAM,8BAA8B,CAAC;AAE7F,2FAA2F;AAC3F,MAAM,OAAO,qBAAqB;IASjC,YAAY,OAA4F;QARvF,YAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;QAC7C,iBAAY,GAAG,IAAI,uBAAuB,EAAE,CAAC;QACtD,WAAM,GAAG,CAAC,CAAC;QAOlB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACxB,CAAC;IAED,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAgC;QACjD,IAAI,CAAC,UAAU,CAAC,OAAO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M,WAAW,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC;QACxD,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,WAAW;YAAE,OAAO;QACzB,KAAK,CAAC,cAAc,GAAG,WAAW,CAAC;QACnC,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,mGAAmG;IAC3F,eAAe,CAAC,KAAsB;QAC7C,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;QAC7E,IAAI,CAAC,QAAQ;YAAE,OAAO,SAAS,CAAC;QAChC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,gBAAgB,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC;IACpF,CAAC;IAEO,UAAU,CAAC,MAAc,EAAE,KAAsB;QACxD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC;QAC5C,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,uBAAuB,CAAC,aAAa,CAAC,CAAC;QAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,CAAC,SAAS,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;IACjG,CAAC;CACD","sourcesContent":["import { isAbsolute } from \"node:path\";\nimport { ProviderScope } from \"@earendil-works/pi-ai/node/provider-scope\";\nimport type { CliRuntimeConfiguration } from \"../../main.ts\";\nimport {\n\ttype LiveWorkerPaths,\n\tRESERVATION_DENIAL_CODES,\n\tSessionPathReservations,\n} from \"./session-path-reservations.ts\";\nimport {\n\ttype OpenRpcSession,\n\ttype RpcSessionEntry,\n\ttype RpcSessionLaunchProfile,\n\tRpcSessionRegistryError,\n} from \"./session-registry.ts\";\nimport { SessionWorkerClient } from \"./session-worker-client.ts\";\nimport { SESSION_WORKER_LIMITS, type SessionWriteGrant } from \"./session-worker-protocol.ts\";\n\n/** Transport-side lifecycle owner. Caller paths are never inspected on this event loop. */\nexport class WorkerSessionRegistry {\n\tprivate readonly entries = new Map<string, RpcSessionEntry>();\n\tprivate readonly reservations = new SessionPathReservations();\n\tprivate serial = 0;\n\treadonly closeGraceMs: number;\n\tprivate readonly now: () => number;\n\n\tprivate readonly options: { configuration: CliRuntimeConfiguration; closeGraceMs: number; now: () => number };\n\n\tconstructor(options: { configuration: CliRuntimeConfiguration; closeGraceMs: number; now: () => number }) {\n\t\tthis.options = options;\n\t\tthis.closeGraceMs = options.closeGraceMs;\n\t\tthis.now = options.now;\n\t}\n\n\tget size(): number {\n\t\treturn this.entries.size;\n\t}\n\n\tasync openSession(profile: RpcSessionLaunchProfile): Promise<OpenRpcSession> {\n\t\tif (!isAbsolute(profile.cwd) || (profile.sessionPath !== undefined && !isAbsolute(profile.sessionPath)))\n\t\t\tthrow new RpcSessionRegistryError(\"invalid_path\");\n\t\tif (profile.sessionPath) {\n\t\t\tconst key = this.knownReservationKey(profile.sessionPath);\n\t\t\tconst owner = key ? this.reservations.owner(key) : undefined;\n\t\t\tif (key && owner) return this.attach(owner, key);\n\t\t}\n\t\tif (this.size >= SESSION_WORKER_LIMITS.workers) throw new Error(\"too_many_sessions\");\n\t\tconst handle = `rpc-${++this.serial}`;\n\t\tconst entry: RpcSessionEntry = {\n\t\t\tstate: \"opening\",\n\t\t\tscope: new ProviderScope(),\n\t\t\tprofile: Object.freeze({ ...profile }),\n\t\t\tcwd: profile.cwd,\n\t\t\tattachments: 1,\n\t\t\tlastCommandAt: this.now(),\n\t\t\tlifecycleMutex: Promise.resolve(),\n\t\t};\n\t\tconst worker = new SessionWorkerClient({\n\t\t\treserve: (path) => this.reserve(handle, path),\n\t\t\treconcile: (livePaths) => this.reconcile(handle, livePaths),\n\t\t\texit: () => {\n\t\t\t\tif (this.entries.get(handle) !== entry) return;\n\t\t\t\tentry.state = \"closed\";\n\t\t\t\tthis.entries.delete(handle);\n\t\t\t\tthis.reservations.releaseAll(handle);\n\t\t\t\tentry.closeResolve?.();\n\t\t\t},\n\t\t\tfailure: (error) => {\n\t\t\t\tentry.state = \"quarantined\";\n\t\t\t\tprocess.stderr.write(`senpi rpc session ${handle} quarantined: ${error}\\n`);\n\t\t\t},\n\t\t});\n\t\tentry.worker = worker;\n\t\tthis.entries.set(handle, entry);\n\t\ttry {\n\t\t\tconst path = await worker.prepare(this.options.configuration, profile);\n\t\t\tconst owner = this.reservations.owner(path);\n\t\t\tif (owner) {\n\t\t\t\tconst attached = this.attach(owner, path);\n\t\t\t\tentry.state = \"quarantined\";\n\t\t\t\tworker.quarantine();\n\t\t\t\treturn attached;\n\t\t\t}\n\t\t\tconst grant = this.reserve(handle, path);\n\t\t\tif (grant !== \"granted\") throw new RpcSessionRegistryError(RESERVATION_DENIAL_CODES[grant]);\n\t\t\tentry.reservationKey = path;\n\t\t\tentry.requestedPathKey = profile.sessionPath ? path : undefined;\n\t\t\tentry.sessionPath = path;\n\t\t\tconst snapshot = await worker.commit();\n\t\t\tif (entry.state !== \"opening\") throw new RpcSessionRegistryError(\"session_closing\");\n\t\t\tentry.durableSessionId = snapshot.state.sessionId;\n\t\t\tentry.cwd = snapshot.state.cwd;\n\t\t\tentry.state = \"open\";\n\t\t\treturn this.openResult(handle, entry);\n\t\t} catch (cause) {\n\t\t\tentry.state = \"quarantined\";\n\t\t\tworker.quarantine();\n\t\t\tthrow cause;\n\t\t}\n\t}\n\n\tpeek(handle: string): RpcSessionEntry | undefined {\n\t\treturn this.entries.get(handle);\n\t}\n\n\tgetForCommand(handle: string, command: string): RpcSessionEntry {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (!entry) throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tif (\n\t\t\tentry.state === \"quarantined\" ||\n\t\t\t(entry.state === \"closing\" &&\n\t\t\t\t![\"abort\", \"abort_bash\", \"extension_ui_response\", \"extension_ui_progress\"].includes(command))\n\t\t)\n\t\t\tthrow new RpcSessionRegistryError(\"session_closing\");\n\t\tif (entry.state !== \"open\" && entry.state !== \"closing\") throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tentry.lastCommandAt = this.now();\n\t\treturn entry;\n\t}\n\n\tbeginClose(handle: string, onRole?: (finalizer: boolean) => void): RpcSessionEntry {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (!entry) throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tif (entry.state === \"closing\" || entry.state === \"quarantined\") {\n\t\t\tonRole?.(false);\n\t\t\treturn entry;\n\t\t}\n\t\tif (entry.state !== \"open\" && entry.state !== \"opening\") throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tentry.attachments--;\n\t\tif (entry.attachments > 0) return entry;\n\t\tentry.state = \"closing\";\n\t\tentry.closeCompletion = new Promise((resolve) => {\n\t\t\tentry.closeResolve = resolve;\n\t\t});\n\t\tonRole?.(true);\n\t\treturn entry;\n\t}\n\n\tclose(handle: string): Promise<void> {\n\t\tconst entry = this.beginClose(handle);\n\t\treturn entry.state === \"closing\" ? this.closeMarked(handle) : Promise.resolve();\n\t}\n\n\tasync closeMarked(handle: string): Promise<void> {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (entry?.state !== \"closing\" || !entry.worker) throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tif (entry.closeStarted) return entry.closeCompletion;\n\t\tentry.closeStarted = true;\n\t\t// Reply on a bounded deadline, but keep entry, attachments and reservations until exit.\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tawait Promise.race([\n\t\t\tentry.worker.close(this.closeGraceMs),\n\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\tif (entry.state !== \"closed\") entry.state = \"quarantined\";\n\t\t\t\t\tresolve();\n\t\t\t\t}, this.closeGraceMs);\n\t\t\t}),\n\t\t]);\n\t\tif (timer) clearTimeout(timer);\n\t}\n\n\tlist(): Array<{\n\t\tsessionId: string;\n\t\tdurableSessionId?: string;\n\t\tsessionPath?: string;\n\t\tcwd: string;\n\t\tname?: string;\n\t\tstatus: Exclude<RpcSessionEntry[\"state\"], \"quarantined\">;\n\t}> {\n\t\treturn [...this.entries].map(([sessionId, entry]) => {\n\t\t\tconst state = entry.worker?.snapshot?.state;\n\t\t\treturn {\n\t\t\t\tsessionId,\n\t\t\t\tdurableSessionId: state?.sessionId ?? entry.durableSessionId,\n\t\t\t\tsessionPath: state?.sessionFile ?? entry.sessionPath,\n\t\t\t\tcwd: state?.cwd ?? entry.cwd,\n\t\t\t\tname: state?.sessionName,\n\t\t\t\tstatus: entry.state === \"quarantined\" ? \"closing\" : entry.state,\n\t\t\t};\n\t\t});\n\t}\n\n\t/** Only compare spellings already tied to a granted identity; do not inspect caller paths here. */\n\tprivate knownReservationKey(path: string): string | undefined {\n\t\tif (this.reservations.owner(path)) return path;\n\t\tfor (const entry of this.entries.values()) {\n\t\t\t// An opening spelling maps only while the key granted for it is still held: a\n\t\t\t// superseded path belongs to nobody and must open its own worker.\n\t\t\tif (\n\t\t\t\tentry.profile.sessionPath === path &&\n\t\t\t\tentry.requestedPathKey &&\n\t\t\t\tthis.reservations.owner(entry.requestedPathKey)\n\t\t\t)\n\t\t\t\treturn entry.requestedPathKey;\n\t\t\tconst snapshot = entry.worker?.snapshot;\n\t\t\tif (snapshot?.state.sessionFile === path) return snapshot.sessionPath;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate attach(owner: string, path: string): OpenRpcSession {\n\t\tconst entry = this.entries.get(owner);\n\t\tif (entry?.state !== \"open\" || !entry.worker?.bindingReady || entry.worker.snapshot?.sessionPath !== path)\n\t\t\tthrow new RpcSessionRegistryError(\"session_path_in_use\");\n\t\tconst result = this.openResult(owner, entry);\n\t\tentry.attachments++;\n\t\tentry.lastCommandAt = this.now();\n\t\treturn { ...result, attached: true };\n\t}\n\n\t/** Granted paths currently held by a handle; the per-worker budget is bounded by it. */\n\treservationCount(handle: string): number {\n\t\treturn this.reservations.count(handle);\n\t}\n\n\tprivate reserve(handle: string, path: string): SessionWriteGrant {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (!entry) return \"conflict\";\n\t\tif (this.reservations.owner(path) === handle) return \"granted\";\n\t\tif (entry.state !== \"opening\" && entry.state !== \"open\") return \"conflict\";\n\t\treturn this.reservations.reserve(handle, path, this.liveWorkerPaths(entry));\n\t}\n\n\t/**\n\t * Releases the grants a worker's latest snapshot no longer claims.\n\t *\n\t * Only a fully open entry reports live writers. An entry still opening, closing or\n\t * quarantined keeps every grant until its real exit, because a worker stuck in a\n\t * syscall can still be writing a path it can no longer report.\n\t */\n\tprivate reconcile(handle: string, livePaths: readonly string[]): void {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (entry?.state !== \"open\") return;\n\t\tconst sessionPath = entry.worker?.snapshot?.sessionPath;\n\t\tthis.reservations.reconcile(handle, { livePaths, sessionPath });\n\t\tif (!sessionPath) return;\n\t\tentry.reservationKey = sessionPath;\n\t\tentry.sessionPath = sessionPath;\n\t}\n\n\t/** The live view a full budget is reconciled against; absent while the entry cannot report one. */\n\tprivate liveWorkerPaths(entry: RpcSessionEntry): LiveWorkerPaths | undefined {\n\t\tconst snapshot = entry.state === \"open\" ? entry.worker?.snapshot : undefined;\n\t\tif (!snapshot) return undefined;\n\t\treturn { livePaths: snapshot.liveSessionPaths, sessionPath: snapshot.sessionPath };\n\t}\n\n\tprivate openResult(handle: string, entry: RpcSessionEntry): OpenRpcSession {\n\t\tconst state = entry.worker?.snapshot?.state;\n\t\tif (!state) throw new RpcSessionRegistryError(\"open_failed\");\n\t\treturn { sessionId: handle, durableSessionId: state.sessionId, sessionPath: state.sessionFile };\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-session-registry.js","sourceRoot":"","sources":["../../../src/modes/rpc/worker-session-registry.ts"],"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,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,KAAK,KAAK,MAAM;YAAE,OAAO,KAAK,CAAC;QACtE,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;YAAE,IAAI,OAAO,KAAK,MAAM;gBAAE,KAAK,EAAE,CAAC;QAClF,IAAI,KAAK,IAAI,qBAAqB,CAAC,YAAY;YAAE,OAAO,KAAK,CAAC;QAC9D,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACpC,OAAO,IAAI,CAAC;IACb,CAAC;IAEO,UAAU,CAAC,MAAc,EAAE,KAAsB;QACxD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC;QAC5C,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,uBAAuB,CAAC,aAAa,CAAC,CAAC;QAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,CAAC,SAAS,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;IACjG,CAAC;CACD","sourcesContent":["import { isAbsolute } from \"node:path\";\nimport { ProviderScope } from \"@earendil-works/pi-ai/node/provider-scope\";\nimport type { CliRuntimeConfiguration } from \"../../main.ts\";\nimport {\n\ttype OpenRpcSession,\n\ttype RpcSessionEntry,\n\ttype RpcSessionLaunchProfile,\n\tRpcSessionRegistryError,\n} from \"./session-registry.ts\";\nimport { SessionWorkerClient } from \"./session-worker-client.ts\";\nimport { SESSION_WORKER_LIMITS } from \"./session-worker-protocol.ts\";\n\n/** Transport-side lifecycle owner. Caller paths are never inspected on this event loop. */\nexport class WorkerSessionRegistry {\n\tprivate readonly entries = new Map<string, RpcSessionEntry>();\n\tprivate readonly reservations = new Map<string, string>();\n\tprivate serial = 0;\n\treadonly closeGraceMs: number;\n\tprivate readonly now: () => number;\n\n\tprivate readonly options: { configuration: CliRuntimeConfiguration; closeGraceMs: number; now: () => number };\n\n\tconstructor(options: { configuration: CliRuntimeConfiguration; closeGraceMs: number; now: () => number }) {\n\t\tthis.options = options;\n\t\tthis.closeGraceMs = options.closeGraceMs;\n\t\tthis.now = options.now;\n\t}\n\n\tget size(): number {\n\t\treturn this.entries.size;\n\t}\n\n\tasync openSession(profile: RpcSessionLaunchProfile): Promise<OpenRpcSession> {\n\t\tif (!isAbsolute(profile.cwd) || (profile.sessionPath !== undefined && !isAbsolute(profile.sessionPath)))\n\t\t\tthrow new RpcSessionRegistryError(\"invalid_path\");\n\t\tif (profile.sessionPath) {\n\t\t\tconst key = this.knownReservationKey(profile.sessionPath);\n\t\t\tconst owner = key ? this.reservations.get(key) : undefined;\n\t\t\tif (key && owner) return this.attach(owner, key);\n\t\t}\n\t\tif (this.size >= SESSION_WORKER_LIMITS.workers) throw new Error(\"too_many_sessions\");\n\t\tconst handle = `rpc-${++this.serial}`;\n\t\tconst entry: RpcSessionEntry = {\n\t\t\tstate: \"opening\",\n\t\t\tscope: new ProviderScope(),\n\t\t\tprofile: Object.freeze({ ...profile }),\n\t\t\tcwd: profile.cwd,\n\t\t\tattachments: 1,\n\t\t\tlastCommandAt: this.now(),\n\t\t\tlifecycleMutex: Promise.resolve(),\n\t\t};\n\t\tconst worker = new SessionWorkerClient({\n\t\t\treserve: (path) => this.reserve(handle, path),\n\t\t\texit: () => {\n\t\t\t\tif (this.entries.get(handle) !== entry) return;\n\t\t\t\tentry.state = \"closed\";\n\t\t\t\tthis.entries.delete(handle);\n\t\t\t\tfor (const [path, owner] of this.reservations) if (owner === handle) this.reservations.delete(path);\n\t\t\t\tentry.closeResolve?.();\n\t\t\t},\n\t\t\tfailure: (error) => {\n\t\t\t\tentry.state = \"quarantined\";\n\t\t\t\tprocess.stderr.write(`senpi rpc session ${handle} quarantined: ${error}\\n`);\n\t\t\t},\n\t\t});\n\t\tentry.worker = worker;\n\t\tthis.entries.set(handle, entry);\n\t\ttry {\n\t\t\tconst path = await worker.prepare(this.options.configuration, profile);\n\t\t\tconst owner = this.reservations.get(path);\n\t\t\tif (owner) {\n\t\t\t\tconst attached = this.attach(owner, path);\n\t\t\t\tentry.state = \"quarantined\";\n\t\t\t\tworker.quarantine();\n\t\t\t\treturn attached;\n\t\t\t}\n\t\t\tif (!this.reserve(handle, path)) throw new RpcSessionRegistryError(\"session_path_in_use\");\n\t\t\tentry.reservationKey = path;\n\t\t\tentry.sessionPath = path;\n\t\t\tconst snapshot = await worker.commit();\n\t\t\tif (entry.state !== \"opening\") throw new RpcSessionRegistryError(\"session_closing\");\n\t\t\tentry.durableSessionId = snapshot.state.sessionId;\n\t\t\tentry.cwd = snapshot.state.cwd;\n\t\t\tentry.state = \"open\";\n\t\t\treturn this.openResult(handle, entry);\n\t\t} catch (cause) {\n\t\t\tentry.state = \"quarantined\";\n\t\t\tworker.quarantine();\n\t\t\tthrow cause;\n\t\t}\n\t}\n\n\tpeek(handle: string): RpcSessionEntry | undefined {\n\t\treturn this.entries.get(handle);\n\t}\n\n\tgetForCommand(handle: string, command: string): RpcSessionEntry {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (!entry) throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tif (\n\t\t\tentry.state === \"quarantined\" ||\n\t\t\t(entry.state === \"closing\" &&\n\t\t\t\t![\"abort\", \"abort_bash\", \"extension_ui_response\", \"extension_ui_progress\"].includes(command))\n\t\t)\n\t\t\tthrow new RpcSessionRegistryError(\"session_closing\");\n\t\tif (entry.state !== \"open\" && entry.state !== \"closing\") throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tentry.lastCommandAt = this.now();\n\t\treturn entry;\n\t}\n\n\tbeginClose(handle: string, onRole?: (finalizer: boolean) => void): RpcSessionEntry {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (!entry) throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tif (entry.state === \"closing\" || entry.state === \"quarantined\") {\n\t\t\tonRole?.(false);\n\t\t\treturn entry;\n\t\t}\n\t\tif (entry.state !== \"open\" && entry.state !== \"opening\") throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tentry.attachments--;\n\t\tif (entry.attachments > 0) return entry;\n\t\tentry.state = \"closing\";\n\t\tentry.closeCompletion = new Promise((resolve) => {\n\t\t\tentry.closeResolve = resolve;\n\t\t});\n\t\tonRole?.(true);\n\t\treturn entry;\n\t}\n\n\tclose(handle: string): Promise<void> {\n\t\tconst entry = this.beginClose(handle);\n\t\treturn entry.state === \"closing\" ? this.closeMarked(handle) : Promise.resolve();\n\t}\n\n\tasync closeMarked(handle: string): Promise<void> {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (entry?.state !== \"closing\" || !entry.worker) throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tif (entry.closeStarted) return entry.closeCompletion;\n\t\tentry.closeStarted = true;\n\t\t// Reply on a bounded deadline, but keep entry, attachments and reservations until exit.\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tawait Promise.race([\n\t\t\tentry.worker.close(this.closeGraceMs),\n\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\tif (entry.state !== \"closed\") entry.state = \"quarantined\";\n\t\t\t\t\tresolve();\n\t\t\t\t}, this.closeGraceMs);\n\t\t\t}),\n\t\t]);\n\t\tif (timer) clearTimeout(timer);\n\t}\n\n\tlist(): Array<{\n\t\tsessionId: string;\n\t\tdurableSessionId?: string;\n\t\tsessionPath?: string;\n\t\tcwd: string;\n\t\tname?: string;\n\t\tstatus: Exclude<RpcSessionEntry[\"state\"], \"quarantined\">;\n\t}> {\n\t\treturn [...this.entries].map(([sessionId, entry]) => {\n\t\t\tconst state = entry.worker?.snapshot?.state;\n\t\t\treturn {\n\t\t\t\tsessionId,\n\t\t\t\tdurableSessionId: state?.sessionId ?? entry.durableSessionId,\n\t\t\t\tsessionPath: state?.sessionFile ?? entry.sessionPath,\n\t\t\t\tcwd: state?.cwd ?? entry.cwd,\n\t\t\t\tname: state?.sessionName,\n\t\t\t\tstatus: entry.state === \"quarantined\" ? \"closing\" : entry.state,\n\t\t\t};\n\t\t});\n\t}\n\n\t/** Only compare spellings already tied to a granted identity; do not inspect caller paths here. */\n\tprivate knownReservationKey(path: string): string | undefined {\n\t\tif (this.reservations.has(path)) return path;\n\t\tfor (const entry of this.entries.values()) {\n\t\t\tif (entry.profile.sessionPath === path && entry.reservationKey) return entry.reservationKey;\n\t\t\tconst snapshot = entry.worker?.snapshot;\n\t\t\tif (snapshot?.state.sessionFile === path) return snapshot.sessionPath;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate attach(owner: string, path: string): OpenRpcSession {\n\t\tconst entry = this.entries.get(owner);\n\t\tif (entry?.state !== \"open\" || !entry.worker?.bindingReady || entry.worker.snapshot?.sessionPath !== path)\n\t\t\tthrow new RpcSessionRegistryError(\"session_path_in_use\");\n\t\tconst result = this.openResult(owner, entry);\n\t\tentry.attachments++;\n\t\tentry.lastCommandAt = this.now();\n\t\treturn { ...result, attached: true };\n\t}\n\n\tprivate reserve(handle: string, path: string): boolean {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (!entry) return false;\n\t\tconst owner = this.reservations.get(path);\n\t\tif (owner) return owner === handle;\n\t\tif (entry.state !== \"opening\" && entry.state !== \"open\") return false;\n\t\tlet count = 0;\n\t\tfor (const current of this.reservations.values()) if (current === handle) count++;\n\t\tif (count >= SESSION_WORKER_LIMITS.reservations) return false;\n\t\tthis.reservations.set(path, handle);\n\t\treturn true;\n\t}\n\n\tprivate openResult(handle: string, entry: RpcSessionEntry): OpenRpcSession {\n\t\tconst state = entry.worker?.snapshot?.state;\n\t\tif (!state) throw new RpcSessionRegistryError(\"open_failed\");\n\t\treturn { sessionId: handle, durableSessionId: state.sessionId, sessionPath: state.sessionFile };\n\t}\n}\n"]}
|
package/docs/rpc.md
CHANGED
|
@@ -222,17 +222,10 @@ and only then constructs its session writer and runtime. A conflicting alias att
|
|
|
222
222
|
explicitly before opening another writer.
|
|
223
223
|
|
|
224
224
|
SessionManager writes, switches, forks, new sessions and imports obtain the same grant before writer creation or
|
|
225
|
-
append-side normalization.
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
another `open_session` for that superseded path opens its own worker instead of attaching or failing, and the
|
|
230
|
-
previous opening spelling stops resolving to the replaced owner. Each worker may reserve at most 64 live paths
|
|
231
|
-
at once; a request past that budget first reconciles against the latest snapshot and only then fails with
|
|
232
|
-
`session_reservation_limit`, which is distinct from `session_path_in_use` (another owner holds the path). Only a
|
|
233
|
-
fully open entry reconciles. An entry that is opening, closing or quarantined keeps every acquired path, because a
|
|
234
|
-
worker stuck in a syscall can still be writing a path it can no longer report. Close or an opening deadline requests
|
|
235
|
-
worker termination, but does not release reservations or worker capacity until the actual exit event. A syscall that cannot yet be interrupted can therefore keep an entry
|
|
225
|
+
append-side normalization. Acquired paths are conservatively retained for that worker's entire lifetime, including
|
|
226
|
+
superseded paths after a switch. Each worker may reserve at most 64 paths; an exhausted reservation budget fails
|
|
227
|
+
explicitly. Close or an opening deadline requests worker termination, but does not release reservations or worker
|
|
228
|
+
capacity until the actual exit event. A syscall that cannot yet be interrupted can therefore keep an entry
|
|
236
229
|
internally quarantined after the routing handle has closed. `list_sessions` continues to publish `closing`, not a
|
|
237
230
|
new status: existing clients must not mistake a quarantined worker for a live reattach target. Retry the path only
|
|
238
231
|
after that entry disappears.
|
|
@@ -303,8 +296,7 @@ In the response `error` field, machine-matchable:
|
|
|
303
296
|
|
|
304
297
|
- `unknown_session`
|
|
305
298
|
- `session_closing`
|
|
306
|
-
- `session_path_in_use` (path held by an opening, closing, or
|
|
307
|
-
- `session_reservation_limit` (this worker already holds 64 live session paths; the open or session replacement was refused without disturbing the existing session)
|
|
299
|
+
- `session_path_in_use` (path held by an opening, closing, quarantined, or superseded owner; a fully-open current owner is attached instead)
|
|
308
300
|
- `missing_session_id` (session-scoped command without `sessionId` in multi mode)
|
|
309
301
|
- `multi_session_disabled` (`open_session` in classic mode)
|
|
310
302
|
- `invalid_path` (relative `sessionPath`/`cwd`)
|
|
@@ -321,7 +313,7 @@ Strict FIFO per session; one total stdout order; cross-session order unspecified
|
|
|
321
313
|
|
|
322
314
|
### Duplicate/idempotency
|
|
323
315
|
|
|
324
|
-
Duplicate `open_session` while a path reservation is held by a fully-open session → ATTACH (`attached: true`, same handle); while held by an `opening`/`closing` entry (including internal quarantine) → `session_path_in_use`.
|
|
316
|
+
Duplicate `open_session` while a path reservation is held by a fully-open session → ATTACH (`attached: true`, same handle); while held by an `opening`/`closing` entry (including internal quarantine) → `session_path_in_use`. `close_session` releases one attachment; the runtime is disposed only when the last attachment closes. A close for an entry already `closing` joins its in-flight teardown. `close_session` on unknown/already-closed → `unknown_session` error. The grace window is configurable by the host through `SENPI_RPC_CLOSE_GRACE_MS`. Request `id`s are client-owned; the server echoes them without dedup.
|
|
325
317
|
|
|
326
318
|
## Protocol Overview
|
|
327
319
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-yeongyu/senpi-codemode",
|
|
3
|
-
"version": "2026.9.12
|
|
3
|
+
"version": "2026.9.12",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Source-only senpi extension package for codemode evaluation tools",
|
|
6
6
|
"type": "module",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/parser": "8.0.4",
|
|
34
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.12
|
|
34
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.12",
|
|
35
35
|
"typebox": "1.3.18"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@code-yeongyu/senpi": "2026.9.12
|
|
38
|
+
"@code-yeongyu/senpi": "2026.9.12"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@code-yeongyu/senpi": "2026.9.12
|
|
41
|
+
"@code-yeongyu/senpi": "2026.9.12"
|
|
42
42
|
},
|
|
43
43
|
"keywords": [
|
|
44
44
|
"senpi",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@earendil-works/pi-agent-core",
|
|
3
|
-
"version": "2026.9.12
|
|
3
|
+
"version": "2026.9.12",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"prepublishOnly": "npm run build"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.12
|
|
39
|
-
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.9.12
|
|
38
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.12",
|
|
39
|
+
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.9.12",
|
|
40
40
|
"diff": "9.0.0",
|
|
41
41
|
"ignore": "7.0.6",
|
|
42
42
|
"typebox": "1.3.18",
|
|
@@ -15,17 +15,6 @@ export declare function buildCursorHistoryForTest(messages: Message[], activeUse
|
|
|
15
15
|
turnUserMessagesJson: unknown[];
|
|
16
16
|
turnStepMessagesJson: unknown[][];
|
|
17
17
|
};
|
|
18
|
-
/**
|
|
19
|
-
* Serialized byte cost of the MODEL INPUT alone: the `rootPromptMessagesJson`
|
|
20
|
-
* blobs Cursor's server replays as the prompt. `measureCursorHistorySerializedBytes`
|
|
21
|
-
* additionally counts the `turns[]` display copies of the same conversation, so
|
|
22
|
-
* it reports roughly twice this number and overstates what the model ingests.
|
|
23
|
-
* Each referenced blob is counted once per reference, because a blob replayed
|
|
24
|
-
* twice occupies the prompt twice.
|
|
25
|
-
*
|
|
26
|
-
* First proposed in #1614.
|
|
27
|
-
*/
|
|
28
|
-
export declare function measureCursorModelInputSerializedBytes(messages: Message[], activeUserMessageIndex?: number): number;
|
|
29
18
|
export declare function measureCursorHistorySerializedBytes(messages: Message[], activeUserMessageIndex?: number): number;
|
|
30
19
|
export declare function buildCursorHistoryWireBytesForTest(messages: Message[], activeUserMessageIndex?: number): Uint8Array[];
|
|
31
20
|
//# sourceMappingURL=measure.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measure.d.ts","sourceRoot":"","sources":["../../../src/api/cursor-agent/measure.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAkC,OAAO,EAA4C,MAAM,gBAAgB,CAAC;AAwJxH;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CASzG;AAwPD,yFAAyF;AACzF,wBAAgB,yBAAyB,CACxC,QAAQ,EAAE,OAAO,EAAE,EACnB,sBAAsB,SAAqC,GACzD;IACF,sBAAsB,EAAE,OAAO,EAAE,CAAC;IAClC,oBAAoB,EAAE,OAAO,EAAE,CAAC;IAChC,oBAAoB,EAAE,OAAO,EAAE,EAAE,CAAC;CAClC,CAsBA;AAoCD
|
|
1
|
+
{"version":3,"file":"measure.d.ts","sourceRoot":"","sources":["../../../src/api/cursor-agent/measure.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAkC,OAAO,EAA4C,MAAM,gBAAgB,CAAC;AAwJxH;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CASzG;AAwPD,yFAAyF;AACzF,wBAAgB,yBAAyB,CACxC,QAAQ,EAAE,OAAO,EAAE,EACnB,sBAAsB,SAAqC,GACzD;IACF,sBAAsB,EAAE,OAAO,EAAE,CAAC;IAClC,oBAAoB,EAAE,OAAO,EAAE,CAAC;IAChC,oBAAoB,EAAE,OAAO,EAAE,EAAE,CAAC;CAClC,CAsBA;AAoCD,wBAAgB,mCAAmC,CAClD,QAAQ,EAAE,OAAO,EAAE,EACnB,sBAAsB,SAAqC,GACzD,MAAM,CAKR;AACD,wBAAgB,kCAAkC,CACjD,QAAQ,EAAE,OAAO,EAAE,EACnB,sBAAsB,SAAqC,GACzD,UAAU,EAAE,CAKd"}
|
|
@@ -431,24 +431,6 @@ function extractImages(content) {
|
|
|
431
431
|
},
|
|
432
432
|
}));
|
|
433
433
|
}
|
|
434
|
-
/**
|
|
435
|
-
* Serialized byte cost of the MODEL INPUT alone: the `rootPromptMessagesJson`
|
|
436
|
-
* blobs Cursor's server replays as the prompt. `measureCursorHistorySerializedBytes`
|
|
437
|
-
* additionally counts the `turns[]` display copies of the same conversation, so
|
|
438
|
-
* it reports roughly twice this number and overstates what the model ingests.
|
|
439
|
-
* Each referenced blob is counted once per reference, because a blob replayed
|
|
440
|
-
* twice occupies the prompt twice.
|
|
441
|
-
*
|
|
442
|
-
* First proposed in #1614.
|
|
443
|
-
*/
|
|
444
|
-
export function measureCursorModelInputSerializedBytes(messages, activeUserMessageIndex = findLastUserMessageIndex(messages)) {
|
|
445
|
-
const blobStore = new Map();
|
|
446
|
-
let total = 0;
|
|
447
|
-
for (const blobId of buildRootPromptMessagesJson(messages, [], blobStore, activeUserMessageIndex)) {
|
|
448
|
-
total += readCursorBlob(blobStore, blobId).byteLength;
|
|
449
|
-
}
|
|
450
|
-
return total;
|
|
451
|
-
}
|
|
452
434
|
export function measureCursorHistorySerializedBytes(messages, activeUserMessageIndex = findLastUserMessageIndex(messages)) {
|
|
453
435
|
return buildCursorHistoryWireBytesForTest(messages, activeUserMessageIndex).reduce((total, bytes) => total + bytes.byteLength, 0);
|
|
454
436
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measure.js","sourceRoot":"","sources":["../../../src/api/cursor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AC,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,sBAAsB,CAAC,EAAE,CAAC;QACnG,KAAK,IAAI,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC;IACvD,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,mCAAmC,CAClD,QAAmB,EACnB,sBAAsB,GAAG,wBAAwB,CAAC,QAAQ,CAAC;IAE3D,OAAO,kCAAkC,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC,MAAM,CACjF,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,UAAU,EAC1C,CAAC,CACD,CAAC;AACH,CAAC;AACD,MAAM,UAAU,kCAAkC,CACjD,QAAmB,EACnB,sBAAsB,GAAG,wBAAwB,CAAC,QAAQ,CAAC;IAE3D,MAAM,SAAS,GAAG,IAAI,GAAG,EAAsB,CAAC;IAChD,2BAA2B,CAAC,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,sBAAsB,CAAC,CAAC;IAC7E,sBAAsB,CAAC,QAAQ,EAAE,SAAS,EAAE,sBAAsB,CAAC,CAAC;IACpE,OAAO,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/** Browser-safe Cursor history serialization. */\nimport { create, fromBinary, fromJson, type JsonValue as PbJsonValue, toBinary, toJson } from \"@bufbuild/protobuf\";\nimport { ValueSchema } from \"@bufbuild/protobuf/wkt\";\nimport { CURSOR_COMPOSER_PROMPT, isCursorComposerModel } from \"../../cursor/composer-prompt.ts\";\nimport type { AssistantMessage, ImageContent, Message, TextContent, ToolCall, ToolResultMessage } from \"../../types.ts\";\nimport type { ConversationStep } from \"./gen/agent_pb.ts\";\nimport {\n\tAgentConversationTurnStructureSchema,\n\tAssistantMessageSchema,\n\tConversationStepSchema,\n\tConversationTurnStructureSchema,\n\tMcpArgsSchema,\n\tMcpImageContentSchema,\n\tMcpSuccessSchema,\n\tMcpTextContentSchema,\n\tMcpToolCallSchema,\n\tMcpToolErrorSchema,\n\tMcpToolResultContentItemSchema,\n\tMcpToolResultSchema,\n\tSelectedContextSchema,\n\tSelectedImageSchema,\n\tToolCallSchema,\n\tUserMessageSchema,\n} from \"./gen/agent_pb.ts\";\n\nfunction hashBytes(input: Uint8Array | string): Uint8Array {\n\tconst out = new Uint8Array(32);\n\tconst b = typeof input === \"string\" ? new TextEncoder().encode(input) : input;\n\tfor (let i = 0; i < b.length; i++) out[i % 32] = (out[i % 32] + b[i] + i) & 255;\n\treturn out;\n}\nfunction createHash(input: Uint8Array | string) {\n\tlet data = typeof input === \"string\" ? input : new TextDecoder().decode(input);\n\treturn {\n\t\tupdate(v: Uint8Array | string) {\n\t\t\tdata += typeof v === \"string\" ? v : new TextDecoder().decode(v);\n\t\t\treturn this;\n\t\t},\n\t\tdigest(format?: string) {\n\t\t\tconst b = hashBytes(data);\n\t\t\treturn format === \"hex\" ? [...b].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\") : b;\n\t\t},\n\t} as any;\n}\nfunction deterministicUuid(s: string) {\n\tconst h = [...hashBytes(s)].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\");\n\treturn `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20, 32)}`;\n}\nfunction randomUUID() {\n\tconst h = [...hashBytes(String(Math.random()) + Date.now())].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\");\n\treturn `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20, 32)}`;\n}\nfunction storeCursorBlob(m: Map<string, Uint8Array>, d: Uint8Array) {\n\tconst id = hashBytes(d);\n\tm.set([...id].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\"), d);\n\treturn id;\n}\nfunction readCursorBlob(m: Map<string, Uint8Array>, id: Uint8Array) {\n\tconst d = m.get([...id].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\"));\n\tif (!d) throw Error(\"Cursor blob not found\");\n\treturn d;\n}\nfunction toolResultToText(r: ToolResultMessage) {\n\treturn r.content.map((i) => (i.type === \"text\" ? i.text : `[${i.mimeType} image]`)).join(\"\\n\");\n}\n/** Extract text content from a user message. */\nfunction extractUserMessageText(msg: Message): string {\n\tif (msg.role !== \"user\") return \"\";\n\tconst content = msg.content;\n\tif (typeof content === \"string\") return content.trim();\n\tconst text = content\n\t\t.filter((c): c is TextContent => c.type === \"text\")\n\t\t.map((c) => c.text)\n\t\t.join(\"\\n\");\n\treturn text.trim();\n}\n\nfunction hasUserMessageImages(msg: Message): boolean {\n\treturn msg.role === \"user\" && Array.isArray(msg.content) && msg.content.some((item) => item.type === \"image\");\n}\n\ntype CursorRootPromptContentPart = { type: \"text\"; text: string } | { type: \"image\"; image: string; mediaType: string };\n\nfunction buildCursorRootPromptContent(content: string | (TextContent | ImageContent)[]): CursorRootPromptContentPart[] {\n\tif (typeof content === \"string\") {\n\t\tconst text = content.trim();\n\t\treturn text ? [{ type: \"text\", text }] : [];\n\t}\n\tconst parts: CursorRootPromptContentPart[] = [];\n\tfor (const item of content) {\n\t\tif (item.type === \"text\") {\n\t\t\tconst text = item.text.trim();\n\t\t\tif (text) {\n\t\t\t\tparts.push({ type: \"text\", text });\n\t\t\t}\n\t\t} else {\n\t\t\tparts.push({ type: \"image\", image: `data:${item.mimeType};base64,${item.data}`, mediaType: item.mimeType });\n\t\t}\n\t}\n\treturn parts;\n}\n\nfunction cursorUserContentKey(content: string | (TextContent | ImageContent)[]): string {\n\tif (typeof content === \"string\") {\n\t\treturn content.trim();\n\t}\n\tconst hash = createHash(\"sha256\");\n\tfor (const item of content) {\n\t\thash.update(item.type);\n\t\tif (item.type === \"text\") {\n\t\t\thash.update(item.text);\n\t\t} else {\n\t\t\thash.update(item.mimeType);\n\t\t\thash.update(item.data);\n\t\t}\n\t}\n\treturn hash.digest(\"hex\");\n}\n\ntype CursorRootPromptAssistantContentPart =\n\t| { type: \"text\"; text: string }\n\t| { type: \"tool-call\"; toolCallId: string; toolName: string; args: Record<string, unknown> };\n\nfunction buildCursorAssistantContent(msg: AssistantMessage): CursorRootPromptAssistantContentPart[] {\n\tconst content: CursorRootPromptAssistantContentPart[] = [];\n\tfor (const item of msg.content) {\n\t\tif (item.type === \"text\") {\n\t\t\tif (item.text) content.push({ type: \"text\", text: item.text });\n\t\t} else if (item.type === \"toolCall\") {\n\t\t\tcontent.push({\n\t\t\t\ttype: \"tool-call\",\n\t\t\t\ttoolCallId: item.id,\n\t\t\t\ttoolName: item.name,\n\t\t\t\targs: item.arguments,\n\t\t\t});\n\t\t}\n\t\t// Thinking is never replayed: Cursor manages reasoning server-side and\n\t\t// foreign/hidden reasoning must not leak into history as native thinking.\n\t}\n\treturn content;\n}\n\n/**\n * Index of the last user message in `messages`, or -1 if none. Used to\n * exclude the current user turn from history builders — it goes in the\n * `userMessageAction`, not in history structures.\n */\nfunction findLastUserMessageIndex(messages: Message[]): number {\n\tfor (let i = messages.length - 1; i >= 0; i--) {\n\t\tif (messages[i].role === \"user\") {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n * Build one Cursor system-message JSON blob per system prompt. When no system\n * prompt is provided, returns a single default greeting so we never emit an\n * empty `rootPromptMessagesJson` head.\n *\n * Composer models get their operating prefix as its own leading blob rather\n * than concatenated into the host prompt, so Cursor's per-blob prompt cache\n * keeps the prefix stable while the host prompt changes underneath it.\n */\nexport function buildCursorSystemPromptJsons(systemPrompt: string | undefined, modelId?: string): string[] {\n\tconst trimmed = systemPrompt?.trim();\n\tconst host = trimmed\n\t\t? [JSON.stringify({ role: \"system\", content: trimmed })]\n\t\t: [JSON.stringify({ role: \"system\", content: \"You are a helpful assistant.\" })];\n\tif (modelId !== undefined && isCursorComposerModel(modelId)) {\n\t\treturn [JSON.stringify({ role: \"system\", content: CURSOR_COMPOSER_PROMPT }), ...host];\n\t}\n\treturn host;\n}\n\n/**\n * Build `ConversationStateStructure.rootPromptMessagesJson` blob IDs for the\n * system prompt plus prior conversation history, as JSON blobs matching\n * Cursor's internal Vercel-AI-SDK-shaped message format.\n *\n * Cursor's server uses `rootPromptMessagesJson` (not `turns[]`) to build the\n * actual model prompt; `turns[]` is UI/display metadata. The active user\n * message is excluded because it is sent in the action.\n */\nfunction buildRootPromptMessagesJson(\n\tmessages: Message[],\n\tsystemPromptIds: Uint8Array[],\n\tblobStore: Map<string, Uint8Array>,\n\tactiveUserMessageIndex = findLastUserMessageIndex(messages),\n): Uint8Array[] {\n\tconst entries: Uint8Array[] = [...systemPromptIds];\n\tconst pushJson = (obj: unknown) => {\n\t\tconst bytes = new TextEncoder().encode(JSON.stringify(obj));\n\t\tentries.push(storeCursorBlob(blobStore, bytes));\n\t};\n\n\tfor (let i = 0; i < messages.length; i++) {\n\t\tif (i === activeUserMessageIndex) break;\n\t\tconst msg = messages[i];\n\t\tif (msg.role === \"user\") {\n\t\t\tconst content = buildCursorRootPromptContent(msg.content);\n\t\t\tif (content.length === 0) continue;\n\t\t\tpushJson({ role: \"user\", content });\n\t\t} else if (msg.role === \"assistant\") {\n\t\t\tconst content = buildCursorAssistantContent(msg);\n\t\t\tif (content.length === 0) continue;\n\t\t\tpushJson({ role: \"assistant\", content });\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\t// Emit even when the result text is empty: the assistant `tool-call`\n\t\t\t// is already in history, so dropping the pair would replay an\n\t\t\t// orphaned call.\n\t\t\tpushJson({\n\t\t\t\trole: \"tool\",\n\t\t\t\tid: msg.toolCallId,\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"tool-result\",\n\t\t\t\t\t\ttoolName: msg.toolName,\n\t\t\t\t\t\ttoolCallId: msg.toolCallId,\n\t\t\t\t\t\tresult: toolResultToText(msg),\n\t\t\t\t\t\t...(msg.isError ? { isError: true } : {}),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\t}\n\n\treturn entries;\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nfunction isJsonValue(value: unknown): value is PbJsonValue {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return true;\n\tif (typeof value === \"number\") return Number.isFinite(value);\n\tif (Array.isArray(value)) return value.every(isJsonValue);\n\tif (!isPlainRecord(value)) return false;\n\tfor (const key in value) {\n\t\tif (!isJsonValue(value[key])) return false;\n\t}\n\treturn true;\n}\n\nfunction encodeCursorMcpArguments(toolCall: ToolCall): Record<string, Uint8Array> {\n\tconst encoded: Record<string, Uint8Array> = {};\n\tfor (const name in toolCall.arguments) {\n\t\tconst value = toolCall.arguments[name];\n\t\tif (value === undefined) continue;\n\t\tif (!isJsonValue(value)) {\n\t\t\tthrow new Error(`Cursor tool argument ${toolCall.name}.${name} is not JSON-serializable`);\n\t\t}\n\t\tencoded[name] = toBinary(ValueSchema, fromJson(ValueSchema, value));\n\t}\n\treturn encoded;\n}\n\nfunction createCursorMcpResult(result: ToolResultMessage) {\n\tif (result.isError) {\n\t\treturn create(McpToolResultSchema, {\n\t\t\tresult: {\n\t\t\t\tcase: \"error\",\n\t\t\t\tvalue: create(McpToolErrorSchema, { error: toolResultToText(result) }),\n\t\t\t},\n\t\t});\n\t}\n\treturn create(McpToolResultSchema, {\n\t\tresult: {\n\t\t\tcase: \"success\",\n\t\t\tvalue: create(McpSuccessSchema, {\n\t\t\t\tcontent: result.content.map((item) =>\n\t\t\t\t\titem.type === \"text\"\n\t\t\t\t\t\t? create(McpToolResultContentItemSchema, {\n\t\t\t\t\t\t\t\tcontent: { case: \"text\", value: create(McpTextContentSchema, { text: item.text }) },\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: create(McpToolResultContentItemSchema, {\n\t\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\tcase: \"image\",\n\t\t\t\t\t\t\t\t\tvalue: create(McpImageContentSchema, {\n\t\t\t\t\t\t\t\t\t\tdata: Uint8Array.from(Uint8Array.from(atob(item.data), (c) => c.charCodeAt(0))),\n\t\t\t\t\t\t\t\t\t\tmimeType: item.mimeType,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t}),\n\t\t},\n\t});\n}\n\nfunction createCursorToolCallStep(toolCall: ToolCall, result: ToolResultMessage | undefined) {\n\tconst mcpCall = create(McpToolCallSchema, {\n\t\targs: create(McpArgsSchema, {\n\t\t\tname: toolCall.name,\n\t\t\targs: encodeCursorMcpArguments(toolCall),\n\t\t\ttoolCallId: toolCall.id,\n\t\t\tproviderIdentifier: \"pi-agent\",\n\t\t\ttoolName: toolCall.name,\n\t\t}),\n\t\t...(result ? { result: createCursorMcpResult(result) } : {}),\n\t});\n\treturn create(ConversationStepSchema, {\n\t\tmessage: {\n\t\t\tcase: \"toolCall\",\n\t\t\tvalue: create(ToolCallSchema, {\n\t\t\t\ttool: { case: \"mcpToolCall\", value: mcpCall },\n\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t}),\n\t\t},\n\t});\n}\n\n/**\n * Convert context.messages to Cursor's ConversationTurnStructure blob IDs.\n * Groups messages into turns: each turn is a user message followed by the\n * assistant's response. Excludes the active user message (which goes in the\n * action).\n */\nfunction buildConversationTurns(\n\tmessages: Message[],\n\tblobStore: Map<string, Uint8Array>,\n\tactiveUserMessageIndex = findLastUserMessageIndex(messages),\n): Uint8Array[] {\n\tconst turns: Uint8Array[] = [];\n\tconst historyEnd = activeUserMessageIndex >= 0 ? activeUserMessageIndex : messages.length;\n\tconst toolResults = new Map<string, ToolResultMessage>();\n\tconst pairedToolCallIds = new Set<string>();\n\tfor (let index = 0; index < historyEnd; index++) {\n\t\tconst message = messages[index];\n\t\tif (message.role === \"toolResult\") {\n\t\t\ttoolResults.set(message.toolCallId, message);\n\t\t} else if (message.role === \"assistant\") {\n\t\t\tfor (const item of message.content) {\n\t\t\t\tif (item.type === \"toolCall\") pairedToolCallIds.add(item.id);\n\t\t\t}\n\t\t}\n\t}\n\n\tlet i = 0;\n\twhile (i < messages.length) {\n\t\tconst msg = messages[i];\n\t\tif (msg.role !== \"user\") {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (i === activeUserMessageIndex) break;\n\n\t\tconst userText = extractUserMessageText(msg);\n\t\tif (userText.length === 0 && !hasUserMessageImages(msg)) {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst userMessage = createCursorUserMessage(\n\t\t\tmsg.content,\n\t\t\tuserText,\n\t\t\tdeterministicUuid(`u:${turns.length}:${cursorUserContentKey(msg.content)}`),\n\t\t);\n\t\tconst userMessageBlobId = storeCursorBlob(blobStore, toBinary(UserMessageSchema, userMessage));\n\t\tconst stepBlobIds: Uint8Array[] = [];\n\t\ti++;\n\n\t\twhile (i < messages.length && messages[i].role !== \"user\") {\n\t\t\tconst stepMsg = messages[i];\n\t\t\tif (stepMsg.role === \"assistant\") {\n\t\t\t\tfor (const item of stepMsg.content) {\n\t\t\t\t\tlet step: ConversationStep;\n\t\t\t\t\tif (item.type === \"text\") {\n\t\t\t\t\t\tif (!item.text) continue;\n\t\t\t\t\t\tstep = create(ConversationStepSchema, {\n\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\tcase: \"assistantMessage\",\n\t\t\t\t\t\t\t\tvalue: create(AssistantMessageSchema, { text: item.text }),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (item.type === \"thinking\") {\n\t\t\t\t\t\t// Foreign/hidden reasoning never leaks into Cursor's turn\n\t\t\t\t\t\t// history as native thinking.\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t} else if (item.type === \"toolCall\") {\n\t\t\t\t\t\tstep = createCursorToolCallStep(item, toolResults.get(item.id));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tstepBlobIds.push(storeCursorBlob(blobStore, toBinary(ConversationStepSchema, step)));\n\t\t\t\t}\n\t\t\t} else if (stepMsg.role === \"toolResult\" && !pairedToolCallIds.has(stepMsg.toolCallId)) {\n\t\t\t\tconst text = toolResultToText(stepMsg);\n\t\t\t\tif (text) {\n\t\t\t\t\tconst prefix = stepMsg.isError ? \"[Tool Error]\" : \"[Tool Result]\";\n\t\t\t\t\tconst step = create(ConversationStepSchema, {\n\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\tcase: \"assistantMessage\",\n\t\t\t\t\t\t\tvalue: create(AssistantMessageSchema, { text: `${prefix}\\n${text}` }),\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\tstepBlobIds.push(storeCursorBlob(blobStore, toBinary(ConversationStepSchema, step)));\n\t\t\t\t}\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\n\t\tconst agentTurn = create(AgentConversationTurnStructureSchema, {\n\t\t\tuserMessage: userMessageBlobId,\n\t\t\tsteps: stepBlobIds,\n\t\t});\n\t\tconst turn = create(ConversationTurnStructureSchema, {\n\t\t\tturn: {\n\t\t\t\tcase: \"agentConversationTurn\",\n\t\t\t\tvalue: agentTurn,\n\t\t\t},\n\t\t});\n\t\tturns.push(storeCursorBlob(blobStore, toBinary(ConversationTurnStructureSchema, turn)));\n\t}\n\n\treturn turns;\n}\n\n/** Exported for tests: decodes Cursor history blobs built from conversation messages. */\nexport function buildCursorHistoryForTest(\n\tmessages: Message[],\n\tactiveUserMessageIndex = findLastUserMessageIndex(messages),\n): {\n\trootPromptMessagesJson: unknown[];\n\tturnUserMessagesJson: unknown[];\n\tturnStepMessagesJson: unknown[][];\n} {\n\tconst blobStore = new Map<string, Uint8Array>();\n\tconst rootPromptMessagesJson = buildRootPromptMessagesJson(messages, [], blobStore, activeUserMessageIndex).map(\n\t\t(blobId) => JSON.parse(new TextDecoder().decode(readCursorBlob(blobStore, blobId))),\n\t);\n\tconst turnUserMessagesJson: unknown[] = [];\n\tconst turnStepMessagesJson: unknown[][] = [];\n\tfor (const turnBlobId of buildConversationTurns(messages, blobStore, activeUserMessageIndex)) {\n\t\tconst turn = fromBinary(ConversationTurnStructureSchema, readCursorBlob(blobStore, turnBlobId));\n\t\tif (turn.turn.case !== \"agentConversationTurn\") {\n\t\t\tcontinue;\n\t\t}\n\t\tconst userMessage = fromBinary(UserMessageSchema, readCursorBlob(blobStore, turn.turn.value.userMessage));\n\t\tturnUserMessagesJson.push(toJson(UserMessageSchema, userMessage));\n\t\tturnStepMessagesJson.push(\n\t\t\tturn.turn.value.steps.map((stepBlobId) => {\n\t\t\t\tconst step = fromBinary(ConversationStepSchema, readCursorBlob(blobStore, stepBlobId));\n\t\t\t\treturn toJson(ConversationStepSchema, step);\n\t\t\t}),\n\t\t);\n\t}\n\treturn { rootPromptMessagesJson, turnUserMessagesJson, turnStepMessagesJson };\n}\n\nfunction createCursorUserMessage(\n\tcontent: string | (TextContent | ImageContent)[],\n\ttext: string,\n\tmessageId = randomUUID() as string,\n) {\n\tconst images = typeof content === \"string\" ? [] : extractImages(content);\n\treturn create(UserMessageSchema, {\n\t\ttext,\n\t\tmessageId,\n\t\t...(images.length > 0\n\t\t\t? {\n\t\t\t\t\tselectedContext: create(SelectedContextSchema, {\n\t\t\t\t\t\tselectedImages: images,\n\t\t\t\t\t}),\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n}\n\nfunction extractImages(content: (TextContent | ImageContent)[]) {\n\treturn content\n\t\t.filter((item): item is ImageContent => item.type === \"image\")\n\t\t.map((image) =>\n\t\t\tcreate(SelectedImageSchema, {\n\t\t\t\tuuid: randomUUID(),\n\t\t\t\tmimeType: image.mimeType,\n\t\t\t\tdataOrBlobId: {\n\t\t\t\t\tcase: \"data\",\n\t\t\t\t\tvalue: Uint8Array.from(atob(image.data), (c) => c.charCodeAt(0)),\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n}\n\n/**\n * Serialized byte cost of the MODEL INPUT alone: the `rootPromptMessagesJson`\n * blobs Cursor's server replays as the prompt. `measureCursorHistorySerializedBytes`\n * additionally counts the `turns[]` display copies of the same conversation, so\n * it reports roughly twice this number and overstates what the model ingests.\n * Each referenced blob is counted once per reference, because a blob replayed\n * twice occupies the prompt twice.\n *\n * First proposed in #1614.\n */\nexport function measureCursorModelInputSerializedBytes(\n\tmessages: Message[],\n\tactiveUserMessageIndex = findLastUserMessageIndex(messages),\n): number {\n\tconst blobStore = new Map<string, Uint8Array>();\n\tlet total = 0;\n\tfor (const blobId of buildRootPromptMessagesJson(messages, [], blobStore, activeUserMessageIndex)) {\n\t\ttotal += readCursorBlob(blobStore, blobId).byteLength;\n\t}\n\treturn total;\n}\n\nexport function measureCursorHistorySerializedBytes(\n\tmessages: Message[],\n\tactiveUserMessageIndex = findLastUserMessageIndex(messages),\n): number {\n\treturn buildCursorHistoryWireBytesForTest(messages, activeUserMessageIndex).reduce(\n\t\t(total, bytes) => total + bytes.byteLength,\n\t\t0,\n\t);\n}\nexport function buildCursorHistoryWireBytesForTest(\n\tmessages: Message[],\n\tactiveUserMessageIndex = findLastUserMessageIndex(messages),\n): Uint8Array[] {\n\tconst blobStore = new Map<string, Uint8Array>();\n\tbuildRootPromptMessagesJson(messages, [], blobStore, activeUserMessageIndex);\n\tbuildConversationTurns(messages, blobStore, activeUserMessageIndex);\n\treturn [...blobStore.values()];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"measure.js","sourceRoot":"","sources":["../../../src/api/cursor-agent/measure.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAiC,QAAQ,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACnH,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,i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C;IAC7E,sBAAsB,CAAC,QAAQ,EAAE,SAAS,EAAE,sBAAsB,CAAC,CAAC;IACpE,OAAO,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/** Browser-safe Cursor history serialization. */\nimport { create, fromBinary, fromJson, type JsonValue as PbJsonValue, toBinary, toJson } from \"@bufbuild/protobuf\";\nimport { ValueSchema } from \"@bufbuild/protobuf/wkt\";\nimport { CURSOR_COMPOSER_PROMPT, isCursorComposerModel } from \"../../cursor/composer-prompt.ts\";\nimport type { AssistantMessage, ImageContent, Message, TextContent, ToolCall, ToolResultMessage } from \"../../types.ts\";\nimport type { ConversationStep } from \"./gen/agent_pb.ts\";\nimport {\n\tAgentConversationTurnStructureSchema,\n\tAssistantMessageSchema,\n\tConversationStepSchema,\n\tConversationTurnStructureSchema,\n\tMcpArgsSchema,\n\tMcpImageContentSchema,\n\tMcpSuccessSchema,\n\tMcpTextContentSchema,\n\tMcpToolCallSchema,\n\tMcpToolErrorSchema,\n\tMcpToolResultContentItemSchema,\n\tMcpToolResultSchema,\n\tSelectedContextSchema,\n\tSelectedImageSchema,\n\tToolCallSchema,\n\tUserMessageSchema,\n} from \"./gen/agent_pb.ts\";\n\nfunction hashBytes(input: Uint8Array | string): Uint8Array {\n\tconst out = new Uint8Array(32);\n\tconst b = typeof input === \"string\" ? new TextEncoder().encode(input) : input;\n\tfor (let i = 0; i < b.length; i++) out[i % 32] = (out[i % 32] + b[i] + i) & 255;\n\treturn out;\n}\nfunction createHash(input: Uint8Array | string) {\n\tlet data = typeof input === \"string\" ? input : new TextDecoder().decode(input);\n\treturn {\n\t\tupdate(v: Uint8Array | string) {\n\t\t\tdata += typeof v === \"string\" ? v : new TextDecoder().decode(v);\n\t\t\treturn this;\n\t\t},\n\t\tdigest(format?: string) {\n\t\t\tconst b = hashBytes(data);\n\t\t\treturn format === \"hex\" ? [...b].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\") : b;\n\t\t},\n\t} as any;\n}\nfunction deterministicUuid(s: string) {\n\tconst h = [...hashBytes(s)].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\");\n\treturn `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20, 32)}`;\n}\nfunction randomUUID() {\n\tconst h = [...hashBytes(String(Math.random()) + Date.now())].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\");\n\treturn `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20, 32)}`;\n}\nfunction storeCursorBlob(m: Map<string, Uint8Array>, d: Uint8Array) {\n\tconst id = hashBytes(d);\n\tm.set([...id].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\"), d);\n\treturn id;\n}\nfunction readCursorBlob(m: Map<string, Uint8Array>, id: Uint8Array) {\n\tconst d = m.get([...id].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\"));\n\tif (!d) throw Error(\"Cursor blob not found\");\n\treturn d;\n}\nfunction toolResultToText(r: ToolResultMessage) {\n\treturn r.content.map((i) => (i.type === \"text\" ? i.text : `[${i.mimeType} image]`)).join(\"\\n\");\n}\n/** Extract text content from a user message. */\nfunction extractUserMessageText(msg: Message): string {\n\tif (msg.role !== \"user\") return \"\";\n\tconst content = msg.content;\n\tif (typeof content === \"string\") return content.trim();\n\tconst text = content\n\t\t.filter((c): c is TextContent => c.type === \"text\")\n\t\t.map((c) => c.text)\n\t\t.join(\"\\n\");\n\treturn text.trim();\n}\n\nfunction hasUserMessageImages(msg: Message): boolean {\n\treturn msg.role === \"user\" && Array.isArray(msg.content) && msg.content.some((item) => item.type === \"image\");\n}\n\ntype CursorRootPromptContentPart = { type: \"text\"; text: string } | { type: \"image\"; image: string; mediaType: string };\n\nfunction buildCursorRootPromptContent(content: string | (TextContent | ImageContent)[]): CursorRootPromptContentPart[] {\n\tif (typeof content === \"string\") {\n\t\tconst text = content.trim();\n\t\treturn text ? [{ type: \"text\", text }] : [];\n\t}\n\tconst parts: CursorRootPromptContentPart[] = [];\n\tfor (const item of content) {\n\t\tif (item.type === \"text\") {\n\t\t\tconst text = item.text.trim();\n\t\t\tif (text) {\n\t\t\t\tparts.push({ type: \"text\", text });\n\t\t\t}\n\t\t} else {\n\t\t\tparts.push({ type: \"image\", image: `data:${item.mimeType};base64,${item.data}`, mediaType: item.mimeType });\n\t\t}\n\t}\n\treturn parts;\n}\n\nfunction cursorUserContentKey(content: string | (TextContent | ImageContent)[]): string {\n\tif (typeof content === \"string\") {\n\t\treturn content.trim();\n\t}\n\tconst hash = createHash(\"sha256\");\n\tfor (const item of content) {\n\t\thash.update(item.type);\n\t\tif (item.type === \"text\") {\n\t\t\thash.update(item.text);\n\t\t} else {\n\t\t\thash.update(item.mimeType);\n\t\t\thash.update(item.data);\n\t\t}\n\t}\n\treturn hash.digest(\"hex\");\n}\n\ntype CursorRootPromptAssistantContentPart =\n\t| { type: \"text\"; text: string }\n\t| { type: \"tool-call\"; toolCallId: string; toolName: string; args: Record<string, unknown> };\n\nfunction buildCursorAssistantContent(msg: AssistantMessage): CursorRootPromptAssistantContentPart[] {\n\tconst content: CursorRootPromptAssistantContentPart[] = [];\n\tfor (const item of msg.content) {\n\t\tif (item.type === \"text\") {\n\t\t\tif (item.text) content.push({ type: \"text\", text: item.text });\n\t\t} else if (item.type === \"toolCall\") {\n\t\t\tcontent.push({\n\t\t\t\ttype: \"tool-call\",\n\t\t\t\ttoolCallId: item.id,\n\t\t\t\ttoolName: item.name,\n\t\t\t\targs: item.arguments,\n\t\t\t});\n\t\t}\n\t\t// Thinking is never replayed: Cursor manages reasoning server-side and\n\t\t// foreign/hidden reasoning must not leak into history as native thinking.\n\t}\n\treturn content;\n}\n\n/**\n * Index of the last user message in `messages`, or -1 if none. Used to\n * exclude the current user turn from history builders — it goes in the\n * `userMessageAction`, not in history structures.\n */\nfunction findLastUserMessageIndex(messages: Message[]): number {\n\tfor (let i = messages.length - 1; i >= 0; i--) {\n\t\tif (messages[i].role === \"user\") {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n * Build one Cursor system-message JSON blob per system prompt. When no system\n * prompt is provided, returns a single default greeting so we never emit an\n * empty `rootPromptMessagesJson` head.\n *\n * Composer models get their operating prefix as its own leading blob rather\n * than concatenated into the host prompt, so Cursor's per-blob prompt cache\n * keeps the prefix stable while the host prompt changes underneath it.\n */\nexport function buildCursorSystemPromptJsons(systemPrompt: string | undefined, modelId?: string): string[] {\n\tconst trimmed = systemPrompt?.trim();\n\tconst host = trimmed\n\t\t? [JSON.stringify({ role: \"system\", content: trimmed })]\n\t\t: [JSON.stringify({ role: \"system\", content: \"You are a helpful assistant.\" })];\n\tif (modelId !== undefined && isCursorComposerModel(modelId)) {\n\t\treturn [JSON.stringify({ role: \"system\", content: CURSOR_COMPOSER_PROMPT }), ...host];\n\t}\n\treturn host;\n}\n\n/**\n * Build `ConversationStateStructure.rootPromptMessagesJson` blob IDs for the\n * system prompt plus prior conversation history, as JSON blobs matching\n * Cursor's internal Vercel-AI-SDK-shaped message format.\n *\n * Cursor's server uses `rootPromptMessagesJson` (not `turns[]`) to build the\n * actual model prompt; `turns[]` is UI/display metadata. The active user\n * message is excluded because it is sent in the action.\n */\nfunction buildRootPromptMessagesJson(\n\tmessages: Message[],\n\tsystemPromptIds: Uint8Array[],\n\tblobStore: Map<string, Uint8Array>,\n\tactiveUserMessageIndex = findLastUserMessageIndex(messages),\n): Uint8Array[] {\n\tconst entries: Uint8Array[] = [...systemPromptIds];\n\tconst pushJson = (obj: unknown) => {\n\t\tconst bytes = new TextEncoder().encode(JSON.stringify(obj));\n\t\tentries.push(storeCursorBlob(blobStore, bytes));\n\t};\n\n\tfor (let i = 0; i < messages.length; i++) {\n\t\tif (i === activeUserMessageIndex) break;\n\t\tconst msg = messages[i];\n\t\tif (msg.role === \"user\") {\n\t\t\tconst content = buildCursorRootPromptContent(msg.content);\n\t\t\tif (content.length === 0) continue;\n\t\t\tpushJson({ role: \"user\", content });\n\t\t} else if (msg.role === \"assistant\") {\n\t\t\tconst content = buildCursorAssistantContent(msg);\n\t\t\tif (content.length === 0) continue;\n\t\t\tpushJson({ role: \"assistant\", content });\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\t// Emit even when the result text is empty: the assistant `tool-call`\n\t\t\t// is already in history, so dropping the pair would replay an\n\t\t\t// orphaned call.\n\t\t\tpushJson({\n\t\t\t\trole: \"tool\",\n\t\t\t\tid: msg.toolCallId,\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"tool-result\",\n\t\t\t\t\t\ttoolName: msg.toolName,\n\t\t\t\t\t\ttoolCallId: msg.toolCallId,\n\t\t\t\t\t\tresult: toolResultToText(msg),\n\t\t\t\t\t\t...(msg.isError ? { isError: true } : {}),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\t}\n\n\treturn entries;\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nfunction isJsonValue(value: unknown): value is PbJsonValue {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return true;\n\tif (typeof value === \"number\") return Number.isFinite(value);\n\tif (Array.isArray(value)) return value.every(isJsonValue);\n\tif (!isPlainRecord(value)) return false;\n\tfor (const key in value) {\n\t\tif (!isJsonValue(value[key])) return false;\n\t}\n\treturn true;\n}\n\nfunction encodeCursorMcpArguments(toolCall: ToolCall): Record<string, Uint8Array> {\n\tconst encoded: Record<string, Uint8Array> = {};\n\tfor (const name in toolCall.arguments) {\n\t\tconst value = toolCall.arguments[name];\n\t\tif (value === undefined) continue;\n\t\tif (!isJsonValue(value)) {\n\t\t\tthrow new Error(`Cursor tool argument ${toolCall.name}.${name} is not JSON-serializable`);\n\t\t}\n\t\tencoded[name] = toBinary(ValueSchema, fromJson(ValueSchema, value));\n\t}\n\treturn encoded;\n}\n\nfunction createCursorMcpResult(result: ToolResultMessage) {\n\tif (result.isError) {\n\t\treturn create(McpToolResultSchema, {\n\t\t\tresult: {\n\t\t\t\tcase: \"error\",\n\t\t\t\tvalue: create(McpToolErrorSchema, { error: toolResultToText(result) }),\n\t\t\t},\n\t\t});\n\t}\n\treturn create(McpToolResultSchema, {\n\t\tresult: {\n\t\t\tcase: \"success\",\n\t\t\tvalue: create(McpSuccessSchema, {\n\t\t\t\tcontent: result.content.map((item) =>\n\t\t\t\t\titem.type === \"text\"\n\t\t\t\t\t\t? create(McpToolResultContentItemSchema, {\n\t\t\t\t\t\t\t\tcontent: { case: \"text\", value: create(McpTextContentSchema, { text: item.text }) },\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: create(McpToolResultContentItemSchema, {\n\t\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\tcase: \"image\",\n\t\t\t\t\t\t\t\t\tvalue: create(McpImageContentSchema, {\n\t\t\t\t\t\t\t\t\t\tdata: Uint8Array.from(Uint8Array.from(atob(item.data), (c) => c.charCodeAt(0))),\n\t\t\t\t\t\t\t\t\t\tmimeType: item.mimeType,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t}),\n\t\t},\n\t});\n}\n\nfunction createCursorToolCallStep(toolCall: ToolCall, result: ToolResultMessage | undefined) {\n\tconst mcpCall = create(McpToolCallSchema, {\n\t\targs: create(McpArgsSchema, {\n\t\t\tname: toolCall.name,\n\t\t\targs: encodeCursorMcpArguments(toolCall),\n\t\t\ttoolCallId: toolCall.id,\n\t\t\tproviderIdentifier: \"pi-agent\",\n\t\t\ttoolName: toolCall.name,\n\t\t}),\n\t\t...(result ? { result: createCursorMcpResult(result) } : {}),\n\t});\n\treturn create(ConversationStepSchema, {\n\t\tmessage: {\n\t\t\tcase: \"toolCall\",\n\t\t\tvalue: create(ToolCallSchema, {\n\t\t\t\ttool: { case: \"mcpToolCall\", value: mcpCall },\n\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t}),\n\t\t},\n\t});\n}\n\n/**\n * Convert context.messages to Cursor's ConversationTurnStructure blob IDs.\n * Groups messages into turns: each turn is a user message followed by the\n * assistant's response. Excludes the active user message (which goes in the\n * action).\n */\nfunction buildConversationTurns(\n\tmessages: Message[],\n\tblobStore: Map<string, Uint8Array>,\n\tactiveUserMessageIndex = findLastUserMessageIndex(messages),\n): Uint8Array[] {\n\tconst turns: Uint8Array[] = [];\n\tconst historyEnd = activeUserMessageIndex >= 0 ? activeUserMessageIndex : messages.length;\n\tconst toolResults = new Map<string, ToolResultMessage>();\n\tconst pairedToolCallIds = new Set<string>();\n\tfor (let index = 0; index < historyEnd; index++) {\n\t\tconst message = messages[index];\n\t\tif (message.role === \"toolResult\") {\n\t\t\ttoolResults.set(message.toolCallId, message);\n\t\t} else if (message.role === \"assistant\") {\n\t\t\tfor (const item of message.content) {\n\t\t\t\tif (item.type === \"toolCall\") pairedToolCallIds.add(item.id);\n\t\t\t}\n\t\t}\n\t}\n\n\tlet i = 0;\n\twhile (i < messages.length) {\n\t\tconst msg = messages[i];\n\t\tif (msg.role !== \"user\") {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (i === activeUserMessageIndex) break;\n\n\t\tconst userText = extractUserMessageText(msg);\n\t\tif (userText.length === 0 && !hasUserMessageImages(msg)) {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst userMessage = createCursorUserMessage(\n\t\t\tmsg.content,\n\t\t\tuserText,\n\t\t\tdeterministicUuid(`u:${turns.length}:${cursorUserContentKey(msg.content)}`),\n\t\t);\n\t\tconst userMessageBlobId = storeCursorBlob(blobStore, toBinary(UserMessageSchema, userMessage));\n\t\tconst stepBlobIds: Uint8Array[] = [];\n\t\ti++;\n\n\t\twhile (i < messages.length && messages[i].role !== \"user\") {\n\t\t\tconst stepMsg = messages[i];\n\t\t\tif (stepMsg.role === \"assistant\") {\n\t\t\t\tfor (const item of stepMsg.content) {\n\t\t\t\t\tlet step: ConversationStep;\n\t\t\t\t\tif (item.type === \"text\") {\n\t\t\t\t\t\tif (!item.text) continue;\n\t\t\t\t\t\tstep = create(ConversationStepSchema, {\n\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\tcase: \"assistantMessage\",\n\t\t\t\t\t\t\t\tvalue: create(AssistantMessageSchema, { text: item.text }),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (item.type === \"thinking\") {\n\t\t\t\t\t\t// Foreign/hidden reasoning never leaks into Cursor's turn\n\t\t\t\t\t\t// history as native thinking.\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t} else if (item.type === \"toolCall\") {\n\t\t\t\t\t\tstep = createCursorToolCallStep(item, toolResults.get(item.id));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tstepBlobIds.push(storeCursorBlob(blobStore, toBinary(ConversationStepSchema, step)));\n\t\t\t\t}\n\t\t\t} else if (stepMsg.role === \"toolResult\" && !pairedToolCallIds.has(stepMsg.toolCallId)) {\n\t\t\t\tconst text = toolResultToText(stepMsg);\n\t\t\t\tif (text) {\n\t\t\t\t\tconst prefix = stepMsg.isError ? \"[Tool Error]\" : \"[Tool Result]\";\n\t\t\t\t\tconst step = create(ConversationStepSchema, {\n\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\tcase: \"assistantMessage\",\n\t\t\t\t\t\t\tvalue: create(AssistantMessageSchema, { text: `${prefix}\\n${text}` }),\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\tstepBlobIds.push(storeCursorBlob(blobStore, toBinary(ConversationStepSchema, step)));\n\t\t\t\t}\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\n\t\tconst agentTurn = create(AgentConversationTurnStructureSchema, {\n\t\t\tuserMessage: userMessageBlobId,\n\t\t\tsteps: stepBlobIds,\n\t\t});\n\t\tconst turn = create(ConversationTurnStructureSchema, {\n\t\t\tturn: {\n\t\t\t\tcase: \"agentConversationTurn\",\n\t\t\t\tvalue: agentTurn,\n\t\t\t},\n\t\t});\n\t\tturns.push(storeCursorBlob(blobStore, toBinary(ConversationTurnStructureSchema, turn)));\n\t}\n\n\treturn turns;\n}\n\n/** Exported for tests: decodes Cursor history blobs built from conversation messages. */\nexport function buildCursorHistoryForTest(\n\tmessages: Message[],\n\tactiveUserMessageIndex = findLastUserMessageIndex(messages),\n): {\n\trootPromptMessagesJson: unknown[];\n\tturnUserMessagesJson: unknown[];\n\tturnStepMessagesJson: unknown[][];\n} {\n\tconst blobStore = new Map<string, Uint8Array>();\n\tconst rootPromptMessagesJson = buildRootPromptMessagesJson(messages, [], blobStore, activeUserMessageIndex).map(\n\t\t(blobId) => JSON.parse(new TextDecoder().decode(readCursorBlob(blobStore, blobId))),\n\t);\n\tconst turnUserMessagesJson: unknown[] = [];\n\tconst turnStepMessagesJson: unknown[][] = [];\n\tfor (const turnBlobId of buildConversationTurns(messages, blobStore, activeUserMessageIndex)) {\n\t\tconst turn = fromBinary(ConversationTurnStructureSchema, readCursorBlob(blobStore, turnBlobId));\n\t\tif (turn.turn.case !== \"agentConversationTurn\") {\n\t\t\tcontinue;\n\t\t}\n\t\tconst userMessage = fromBinary(UserMessageSchema, readCursorBlob(blobStore, turn.turn.value.userMessage));\n\t\tturnUserMessagesJson.push(toJson(UserMessageSchema, userMessage));\n\t\tturnStepMessagesJson.push(\n\t\t\tturn.turn.value.steps.map((stepBlobId) => {\n\t\t\t\tconst step = fromBinary(ConversationStepSchema, readCursorBlob(blobStore, stepBlobId));\n\t\t\t\treturn toJson(ConversationStepSchema, step);\n\t\t\t}),\n\t\t);\n\t}\n\treturn { rootPromptMessagesJson, turnUserMessagesJson, turnStepMessagesJson };\n}\n\nfunction createCursorUserMessage(\n\tcontent: string | (TextContent | ImageContent)[],\n\ttext: string,\n\tmessageId = randomUUID() as string,\n) {\n\tconst images = typeof content === \"string\" ? [] : extractImages(content);\n\treturn create(UserMessageSchema, {\n\t\ttext,\n\t\tmessageId,\n\t\t...(images.length > 0\n\t\t\t? {\n\t\t\t\t\tselectedContext: create(SelectedContextSchema, {\n\t\t\t\t\t\tselectedImages: images,\n\t\t\t\t\t}),\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n}\n\nfunction extractImages(content: (TextContent | ImageContent)[]) {\n\treturn content\n\t\t.filter((item): item is ImageContent => item.type === \"image\")\n\t\t.map((image) =>\n\t\t\tcreate(SelectedImageSchema, {\n\t\t\t\tuuid: randomUUID(),\n\t\t\t\tmimeType: image.mimeType,\n\t\t\t\tdataOrBlobId: {\n\t\t\t\t\tcase: \"data\",\n\t\t\t\t\tvalue: Uint8Array.from(atob(image.data), (c) => c.charCodeAt(0)),\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n}\n\nexport function measureCursorHistorySerializedBytes(\n\tmessages: Message[],\n\tactiveUserMessageIndex = findLastUserMessageIndex(messages),\n): number {\n\treturn buildCursorHistoryWireBytesForTest(messages, activeUserMessageIndex).reduce(\n\t\t(total, bytes) => total + bytes.byteLength,\n\t\t0,\n\t);\n}\nexport function buildCursorHistoryWireBytesForTest(\n\tmessages: Message[],\n\tactiveUserMessageIndex = findLastUserMessageIndex(messages),\n): Uint8Array[] {\n\tconst blobStore = new Map<string, Uint8Array>();\n\tbuildRootPromptMessagesJson(messages, [], blobStore, activeUserMessageIndex);\n\tbuildConversationTurns(messages, blobStore, activeUserMessageIndex);\n\treturn [...blobStore.values()];\n}\n"]}
|
|
@@ -193,7 +193,7 @@ export declare function buildMcpToolDefinitions(tools: Tool[] | undefined): McpT
|
|
|
193
193
|
*/
|
|
194
194
|
export declare function buildCursorSystemPromptJsons(systemPrompt: string | undefined, modelId?: string): string[];
|
|
195
195
|
/** Returns the serialized byte cost of Cursor's complete stored history representation. */
|
|
196
|
-
export { buildCursorHistoryWireBytesForTest, measureCursorHistorySerializedBytes
|
|
196
|
+
export { buildCursorHistoryWireBytesForTest, measureCursorHistorySerializedBytes } from "./cursor-agent/measure.ts";
|
|
197
197
|
/** Exported for tests: decodes Cursor history blobs built from conversation messages. */
|
|
198
198
|
export declare function buildCursorHistoryForTest(messages: Message[], activeUserMessageIndex?: number): {
|
|
199
199
|
rootPromptMessagesJson: unknown[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cursor-agent.d.ts","sourceRoot":"","sources":["../../src/api/cursor-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAMpC,OAAO,KAAK,EAEX,gBAAgB,EAGhB,OAAO,EAEP,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,eAAe,EACf,IAAI,EACJ,QAAQ,EACR,iBAAiB,EACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAGN,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"cursor-agent.d.ts","sourceRoot":"","sources":["../../src/api/cursor-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAMpC,OAAO,KAAK,EAEX,gBAAgB,EAGhB,OAAO,EAEP,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,eAAe,EACf,IAAI,EACJ,QAAQ,EACR,iBAAiB,EACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAGN,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AA0BvE,OAAO,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,IAAI,EAAE,GAAG,SAAS,GAAG,iBAAiB,EAAE,CAyBtF;AA6FD;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CASzG;AAwPD,2FAA2F;AAC3F,OAAO,EAAE,kCAAkC,EAAE,mCAAmC,EAAE,MAAM,2BAA2B,CAAC;AAEpH,yFAAyF;AACzF,wBAAgB,yBAAyB,CACxC,QAAQ,EAAE,OAAO,EAAE,EACnB,sBAAsB,SAAqC,GACzD;IACF,sBAAsB,EAAE,OAAO,EAAE,CAAC;IAClC,oBAAoB,EAAE,OAAO,EAAE,CAAC;IAChC,oBAAoB,EAAE,OAAO,EAAE,EAAE,CAAC;CAClC,CAsBA;AAoND,MAAM,WAAW,qBAAqB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB,GAAG,OAAO,CAAC,qBAAqB,EAAE,GAAG,IAAI,CAAC,CAqG1C"}
|
|
@@ -23,7 +23,6 @@ import { CURSOR_COMPOSER_PROMPT, isCursorComposerModel } from "../cursor/compose
|
|
|
23
23
|
import { calculateCost } from "../models.js";
|
|
24
24
|
import { registerSessionResourceCleanup } from "../session-resources.js";
|
|
25
25
|
import { clearStreamingPartialJson, kCursorExecResolved, kStreamingBlockIndex, kStreamingBlockKind, kStreamingEnvelopeId, kStreamingLastParseLen, kStreamingPartialJson, } from "../utils/block-symbols.js";
|
|
26
|
-
import { recordCursorContextLimit } from "../utils/cursor-context-limit.js";
|
|
27
26
|
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
28
27
|
import { providerHeadersToRecord } from "../utils/headers.js";
|
|
29
28
|
import { parseJsonWithRepair, parseStreamingJson } from "../utils/json-parse.js";
|
|
@@ -681,9 +680,6 @@ export const stream = (model, context, options) => {
|
|
|
681
680
|
openBlockState = state;
|
|
682
681
|
const onConversationCheckpoint = (checkpoint) => {
|
|
683
682
|
attemptSawCheckpoint = true;
|
|
684
|
-
// The server states this model's real ceiling here; the catalog only
|
|
685
|
-
// guesses it. The first checkpoint of a conversation reports 0.
|
|
686
|
-
recordCursorContextLimit(model.id, checkpoint.tokenDetails?.maxTokens);
|
|
687
683
|
conversationStateCache.set(conversationId, checkpoint);
|
|
688
684
|
};
|
|
689
685
|
const healthFailThresholdMs = options?.streamHealthFailThresholdMs ?? CURSOR_STREAM_HEALTH_FAIL_THRESHOLD_MS;
|
|
@@ -3609,7 +3605,7 @@ function buildConversationTurns(messages, blobStore, activeUserMessageIndex = fi
|
|
|
3609
3605
|
return turns;
|
|
3610
3606
|
}
|
|
3611
3607
|
/** Returns the serialized byte cost of Cursor's complete stored history representation. */
|
|
3612
|
-
export { buildCursorHistoryWireBytesForTest, measureCursorHistorySerializedBytes
|
|
3608
|
+
export { buildCursorHistoryWireBytesForTest, measureCursorHistorySerializedBytes } from "./cursor-agent/measure.js";
|
|
3613
3609
|
/** Exported for tests: decodes Cursor history blobs built from conversation messages. */
|
|
3614
3610
|
export function buildCursorHistoryForTest(messages, activeUserMessageIndex = findLastUserMessageIndex(messages)) {
|
|
3615
3611
|
const blobStore = new Map();
|