@cursor/july 0.1.79 → 0.1.82
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/AGENTS.md +0 -12
- package/dist/channels/github/api.d.ts.map +1 -1
- package/dist/channels/github/api.js +8 -1
- package/dist/channels/github/cursor-account.d.ts +28 -0
- package/dist/channels/github/cursor-account.d.ts.map +1 -1
- package/dist/channels/github/cursor-account.js +60 -0
- package/dist/channels/github/github-channel.d.ts.map +1 -1
- package/dist/channels/github/github-channel.js +29 -1
- package/dist/channels/github/types.d.ts +8 -0
- package/dist/channels/github/types.d.ts.map +1 -1
- package/dist/channels/origin/origin-channel.d.ts.map +1 -1
- package/dist/channels/origin/origin-channel.js +32 -10
- package/dist/channels/origin/types.d.ts +7 -0
- package/dist/channels/origin/types.d.ts.map +1 -1
- package/dist/channels/slack/cursor-account.d.ts.map +1 -1
- package/dist/channels/slack/cursor-account.js +2 -2
- package/dist/channels/slack/dispatch.d.ts +3 -0
- package/dist/channels/slack/dispatch.d.ts.map +1 -1
- package/dist/channels/slack/dispatch.js +18 -18
- package/dist/channels/slack/interactive.d.ts +2 -0
- package/dist/channels/slack/interactive.d.ts.map +1 -1
- package/dist/channels/slack/interactive.js +4 -16
- package/dist/channels/slack/slack-channel.d.ts +1 -1
- package/dist/channels/slack/slack-channel.d.ts.map +1 -1
- package/dist/channels/slack/slack-channel.js +21 -10
- package/dist/channels/slack/types.d.ts +7 -0
- package/dist/channels/slack/types.d.ts.map +1 -1
- package/dist/channels.d.ts.map +1 -1
- package/dist/channels.js +4 -0
- package/dist/continuation.d.ts +20 -0
- package/dist/continuation.d.ts.map +1 -0
- package/dist/continuation.js +18 -0
- package/dist/files.d.ts +9 -3
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +9 -3
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/internal/continuation-channel.d.ts +29 -0
- package/dist/internal/continuation-channel.d.ts.map +1 -0
- package/dist/internal/continuation-channel.js +88 -0
- package/dist/internal/continuation-identity.d.ts +95 -0
- package/dist/internal/continuation-identity.d.ts.map +1 -0
- package/dist/internal/continuation-identity.js +445 -0
- package/dist/internal/deploy-manifest.d.ts +12 -2
- package/dist/internal/deploy-manifest.d.ts.map +1 -1
- package/dist/internal/deploy-manifest.js +15 -7
- package/dist/internal/discovery.d.ts.map +1 -1
- package/dist/internal/discovery.js +32 -5
- package/dist/internal/review-comments.d.ts +37 -7
- package/dist/internal/review-comments.d.ts.map +1 -1
- package/dist/internal/review-comments.js +209 -10
- package/dist/internal/server.d.ts.map +1 -1
- package/dist/internal/server.js +117 -55
- package/dist/internal/session-engine.d.ts +24 -0
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +104 -34
- package/dist/internal/session-store.d.ts.map +1 -1
- package/dist/internal/session-store.js +6 -0
- package/dist/internal/skills-sync.d.ts +25 -0
- package/dist/internal/skills-sync.d.ts.map +1 -0
- package/dist/internal/skills-sync.js +96 -0
- package/dist/playground/assets/{index-DJzcIeGt.css → index-ChETdG-_.css} +1 -1
- package/dist/playground/assets/{index-K3Sxyx0I.js → index-CkuIrhg4.js} +3 -3
- package/dist/playground/index.html +2 -2
- package/dist/types.d.ts +44 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/channels/github/api.ts +8 -0
- package/src/channels/github/cursor-account.ts +76 -0
- package/src/channels/github/github-channel.ts +52 -1
- package/src/channels/github/types.ts +8 -0
- package/src/channels/origin/origin-channel.ts +48 -10
- package/src/channels/origin/types.ts +7 -0
- package/src/channels/slack/cursor-account.ts +1 -0
- package/src/channels/slack/dispatch.ts +44 -2
- package/src/channels/slack/interactive.ts +5 -0
- package/src/channels/slack/slack-channel.ts +23 -2
- package/src/channels/slack/types.ts +7 -0
- package/src/channels.ts +7 -0
- package/src/continuation.ts +49 -0
- package/src/files.ts +10 -3
- package/src/index.ts +30 -1
- package/src/internal/continuation-channel.ts +129 -0
- package/src/internal/continuation-identity.ts +597 -0
- package/src/internal/deploy-manifest.ts +36 -3
- package/src/internal/discovery.ts +40 -2
- package/src/internal/review-comments.ts +257 -16
- package/src/internal/server.ts +146 -68
- package/src/internal/session-engine.ts +132 -37
- package/src/internal/session-store.ts +6 -0
- package/src/internal/skills-sync.ts +107 -0
- package/src/types.ts +55 -0
package/src/internal/server.ts
CHANGED
|
@@ -20,11 +20,14 @@ import {
|
|
|
20
20
|
} from "../channels/deployments/deployments-channel.js";
|
|
21
21
|
import type { DeploymentsChannelOptions } from "../channels/deployments/types.js";
|
|
22
22
|
import {
|
|
23
|
+
type CursorAccountGithubTokenResolver,
|
|
23
24
|
type CursorGithubRepoScope,
|
|
24
25
|
createCursorAccountGithubTokenResolver,
|
|
26
|
+
createCursorGithubProxyHostResolver,
|
|
27
|
+
cursorGithubPermissionsForChannel,
|
|
25
28
|
type GithubCursorAccountRuntime,
|
|
26
29
|
getGithubCursorAccountRuntime,
|
|
27
|
-
|
|
30
|
+
resolveCursorGithubCredentialScope,
|
|
28
31
|
resolveCursorGithubPermissions,
|
|
29
32
|
resolveCursorGithubProxyUrl,
|
|
30
33
|
} from "../channels/github/cursor-account.js";
|
|
@@ -315,79 +318,127 @@ export async function startServer(
|
|
|
315
318
|
: requireCursorEventsAuth(effectiveCursorEvents, accountKey);
|
|
316
319
|
|
|
317
320
|
let cursorGithubCredentials: CursorGithubCredentialProvider | undefined;
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
321
|
+
// Proxy-wired GitHub token resolver for `ctx.host.github` when no startup
|
|
322
|
+
// token mint runs (empty repo scope): host Octokit calls must route
|
|
323
|
+
// through github-proxy exactly like channel Octokit calls.
|
|
324
|
+
let hostGithubProxyResolver: CursorAccountGithubTokenResolver | undefined;
|
|
325
|
+
if (cursorGithubTargets.length > 0) {
|
|
326
|
+
const githubProxyRequested = options.cursorGithubProxy === true;
|
|
327
|
+
const needsGithubAuth =
|
|
328
|
+
cursorGithubConfig.scope !== undefined || githubProxyRequested;
|
|
329
|
+
if (needsGithubAuth) {
|
|
330
|
+
const cursorGithubAuth =
|
|
331
|
+
cursorEventsAuth ??
|
|
332
|
+
(accountKey?.apiKey !== undefined && accountKey.apiKey.trim() !== ""
|
|
333
|
+
? {
|
|
334
|
+
apiKey: accountKey.apiKey.trim(),
|
|
335
|
+
baseUrl: cursorExternalApiUrl(),
|
|
336
|
+
}
|
|
337
|
+
: undefined);
|
|
338
|
+
if (cursorGithubAuth === undefined) {
|
|
326
339
|
throw new Error(
|
|
327
|
-
"githubChannel({ cursorAccount: true })
|
|
340
|
+
"githubChannel({ cursorAccount: true }) could not resolve Cursor event authentication."
|
|
328
341
|
);
|
|
329
342
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
const provider = new CursorGithubCredentialProvider({
|
|
340
|
-
client: new CursorBackendClient({
|
|
341
|
-
backendUrl: cursorEventsAuth.baseUrl,
|
|
342
|
-
apiKey: cursorEventsAuth.apiKey,
|
|
343
|
-
logger,
|
|
344
|
-
}),
|
|
345
|
-
scope: cursorGithubConfig.scope,
|
|
346
|
-
logger,
|
|
347
|
-
});
|
|
348
|
-
cursorGithubCredentials = provider;
|
|
349
|
-
const githubProxyUrl =
|
|
350
|
-
options.cursorGithubProxy === true
|
|
351
|
-
? resolveCursorGithubProxyUrl(cursorEventsAuth.baseUrl)
|
|
352
|
-
: undefined;
|
|
353
|
-
if (githubProxyUrl !== undefined) {
|
|
354
|
-
// Proxy mode: channel Octokit calls carry the Cursor API key to the
|
|
355
|
-
// backend forwarder, which swaps in the installation token server-side
|
|
356
|
-
// and logs every call with per-deployment attribution. The provider
|
|
357
|
-
// still runs so child `gh` processes get a `GH_TOKEN` lease (v1).
|
|
358
|
-
const proxyTransport = {
|
|
359
|
-
apiBaseUrl: githubProxyUrl,
|
|
360
|
-
headers: {
|
|
361
|
-
"x-cursor-github-repos": cursorGithubConfig.scope.repos.join(","),
|
|
362
|
-
"x-cursor-github-permissions": cursorGithubConfig.scope.permissions,
|
|
363
|
-
},
|
|
364
|
-
};
|
|
365
|
-
for (const target of cursorGithubTargets) {
|
|
366
|
-
target.accountRuntime.credentials.bind(
|
|
367
|
-
async () => cursorEventsAuth.apiKey
|
|
343
|
+
if (options.allowAnonymous === true) {
|
|
344
|
+
if (options.allowAnonymousCursorGithub !== true) {
|
|
345
|
+
throw new Error(
|
|
346
|
+
"githubChannel({ cursorAccount: true }) cannot be served with --allow-anonymous because admitted callers could use the signed-in account's GitHub access. If every admitted caller is trusted (e.g. behind an SSO proxy), opt in with --allow-anonymous-cursor-github."
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
logger(
|
|
350
|
+
"[agent-sdk] warning: --allow-anonymous-cursor-github — every admitted HTTP caller can drive sessions holding the signed-in account's repo-scoped GitHub credential; serve this only behind a trusted boundary (e.g. an SSO proxy)"
|
|
368
351
|
);
|
|
369
|
-
target.accountRuntime.credentials.bindProxyTransport(proxyTransport);
|
|
370
352
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
353
|
+
if (cursorGithubConfig.permissions === "contents-write") {
|
|
354
|
+
logger(
|
|
355
|
+
'[agent-sdk] warning: Cursor GitHub credentials include contents:write — the host holds a push-capable token shared with model-driven tools and untrusted webhook content; prefer permissions: "pr-write" unless this agent must push code'
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
const githubProxyUrl = githubProxyRequested
|
|
359
|
+
? resolveCursorGithubProxyUrl(cursorGithubAuth.baseUrl)
|
|
360
|
+
: undefined;
|
|
361
|
+
if (cursorGithubConfig.scope !== undefined) {
|
|
362
|
+
const provider = new CursorGithubCredentialProvider({
|
|
363
|
+
client: new CursorBackendClient({
|
|
364
|
+
backendUrl: cursorGithubAuth.baseUrl,
|
|
365
|
+
apiKey: cursorGithubAuth.apiKey,
|
|
366
|
+
logger,
|
|
367
|
+
}),
|
|
368
|
+
scope: cursorGithubConfig.scope,
|
|
369
|
+
logger,
|
|
370
|
+
});
|
|
371
|
+
cursorGithubCredentials = provider;
|
|
372
|
+
if (githubProxyUrl !== undefined) {
|
|
373
|
+
// Proxy mode: channel Octokit calls carry the Cursor API key to the
|
|
374
|
+
// backend forwarder, which swaps in the installation token server-side
|
|
375
|
+
// and logs every call with per-deployment attribution. The provider
|
|
376
|
+
// still runs so child `gh` processes get a `GH_TOKEN` lease (v1).
|
|
377
|
+
const proxyTransport = {
|
|
378
|
+
apiBaseUrl: githubProxyUrl,
|
|
379
|
+
headers: {
|
|
380
|
+
"x-cursor-github-repos": cursorGithubConfig.scope.repos.join(","),
|
|
381
|
+
"x-cursor-github-permissions": cursorGithubConfig.permissions,
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
for (const target of cursorGithubTargets) {
|
|
385
|
+
target.accountRuntime.credentials.bind(
|
|
386
|
+
async () => cursorGithubAuth.apiKey
|
|
387
|
+
);
|
|
388
|
+
target.accountRuntime.credentials.bindProxyTransport(
|
|
389
|
+
proxyTransport
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
logger(
|
|
393
|
+
`[agent-sdk] GitHub auth: channel API calls route through ${githubProxyUrl}`
|
|
394
|
+
);
|
|
395
|
+
} else {
|
|
396
|
+
for (const target of cursorGithubTargets) {
|
|
397
|
+
target.accountRuntime.credentials.bind(() => provider.getToken());
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
} else if (githubProxyUrl !== undefined) {
|
|
401
|
+
// `cursorAccount: true` with no `--repo`: skip the startup token mint
|
|
402
|
+
// (it requires a repo list) and let github-proxy take the repo from
|
|
403
|
+
// each Octokit call. Hosted multi-tenant uses this with the
|
|
404
|
+
// deployment event stream.
|
|
405
|
+
const proxyTransport = {
|
|
406
|
+
apiBaseUrl: githubProxyUrl,
|
|
407
|
+
headers: {
|
|
408
|
+
"x-cursor-github-permissions": cursorGithubConfig.permissions,
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
for (const target of cursorGithubTargets) {
|
|
412
|
+
target.accountRuntime.credentials.bind(
|
|
413
|
+
async () => cursorGithubAuth.apiKey
|
|
414
|
+
);
|
|
415
|
+
target.accountRuntime.credentials.bindProxyTransport(proxyTransport);
|
|
416
|
+
}
|
|
417
|
+
// `ctx.host.github` gets the same proxy transport; without this it
|
|
418
|
+
// would fall back to ambient auth (env token / `gh`) or an
|
|
419
|
+
// unauthenticated Octokit, and every host GitHub call would 404.
|
|
420
|
+
hostGithubProxyResolver = createCursorGithubProxyHostResolver({
|
|
421
|
+
getApiKey: async () => cursorGithubAuth.apiKey,
|
|
422
|
+
transport: proxyTransport,
|
|
423
|
+
});
|
|
424
|
+
logger(
|
|
425
|
+
`[agent-sdk] GitHub auth: channel and host API calls route through ${githubProxyUrl} (repo scope per request)`
|
|
426
|
+
);
|
|
377
427
|
}
|
|
378
428
|
}
|
|
379
429
|
}
|
|
380
430
|
const resolvedCursorGithubCredentials = cursorGithubCredentials;
|
|
431
|
+
const hostGithubToken =
|
|
432
|
+
hostGithubProxyResolver ??
|
|
433
|
+
(resolvedCursorGithubCredentials === undefined
|
|
434
|
+
? undefined
|
|
435
|
+
: createCursorAccountGithubTokenResolver(() =>
|
|
436
|
+
resolvedCursorGithubCredentials.getToken()
|
|
437
|
+
));
|
|
381
438
|
const hostPlatforms = createHostPlatforms(
|
|
382
|
-
|
|
439
|
+
hostGithubToken === undefined
|
|
383
440
|
? {}
|
|
384
|
-
: {
|
|
385
|
-
githubCredentials: {
|
|
386
|
-
token: createCursorAccountGithubTokenResolver(() =>
|
|
387
|
-
resolvedCursorGithubCredentials.getToken()
|
|
388
|
-
),
|
|
389
|
-
},
|
|
390
|
-
}
|
|
441
|
+
: { githubCredentials: { token: hostGithubToken } }
|
|
391
442
|
);
|
|
392
443
|
|
|
393
444
|
if (playground) {
|
|
@@ -2003,6 +2054,20 @@ function collectCursorGithubTargets(
|
|
|
2003
2054
|
interface CursorGithubConfigResolution {
|
|
2004
2055
|
cursorEvents: ServeOptions["cursorEvents"];
|
|
2005
2056
|
scope: CursorGithubRepoScope | undefined;
|
|
2057
|
+
permissions: CursorGithubRepoScope["permissions"];
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
function cursorGithubPermissionsForTarget(
|
|
2061
|
+
target: CursorGithubTarget
|
|
2062
|
+
): CursorGithubRepoScope["permissions"] {
|
|
2063
|
+
const authored =
|
|
2064
|
+
typeof target.accountRuntime.options.cursorAccount === "object"
|
|
2065
|
+
? target.accountRuntime.options.cursorAccount.permissions
|
|
2066
|
+
: undefined;
|
|
2067
|
+
return (
|
|
2068
|
+
target.accountRuntime.scope?.permissions ??
|
|
2069
|
+
cursorGithubPermissionsForChannel(target.accountRuntime.options, authored)
|
|
2070
|
+
);
|
|
2006
2071
|
}
|
|
2007
2072
|
|
|
2008
2073
|
function resolveCursorGithubEventConfig(input: {
|
|
@@ -2010,7 +2075,11 @@ function resolveCursorGithubEventConfig(input: {
|
|
|
2010
2075
|
targets: CursorGithubTarget[];
|
|
2011
2076
|
}): CursorGithubConfigResolution {
|
|
2012
2077
|
if (input.targets.length === 0) {
|
|
2013
|
-
return {
|
|
2078
|
+
return {
|
|
2079
|
+
cursorEvents: input.configured,
|
|
2080
|
+
scope: undefined,
|
|
2081
|
+
permissions: "pr-write",
|
|
2082
|
+
};
|
|
2014
2083
|
}
|
|
2015
2084
|
const repos = [
|
|
2016
2085
|
...(input.configured?.repos ?? []),
|
|
@@ -2019,17 +2088,23 @@ function resolveCursorGithubEventConfig(input: {
|
|
|
2019
2088
|
]),
|
|
2020
2089
|
];
|
|
2021
2090
|
const permissions = resolveCursorGithubPermissions(
|
|
2022
|
-
input.targets.map(
|
|
2023
|
-
(target) => target.accountRuntime.scope?.permissions ?? "pr-write"
|
|
2024
|
-
)
|
|
2091
|
+
input.targets.map(cursorGithubPermissionsForTarget)
|
|
2025
2092
|
);
|
|
2026
|
-
const scope =
|
|
2093
|
+
const scope = resolveCursorGithubCredentialScope(repos, permissions);
|
|
2094
|
+
if (scope === undefined) {
|
|
2095
|
+
return {
|
|
2096
|
+
cursorEvents: input.configured,
|
|
2097
|
+
scope: undefined,
|
|
2098
|
+
permissions,
|
|
2099
|
+
};
|
|
2100
|
+
}
|
|
2027
2101
|
return {
|
|
2028
2102
|
cursorEvents: {
|
|
2029
2103
|
...input.configured,
|
|
2030
2104
|
repos: [...scope.repos],
|
|
2031
2105
|
},
|
|
2032
2106
|
scope,
|
|
2107
|
+
permissions,
|
|
2033
2108
|
};
|
|
2034
2109
|
}
|
|
2035
2110
|
|
|
@@ -2078,6 +2153,9 @@ function resolveCursorOriginRepoScope(input: {
|
|
|
2078
2153
|
(target) => target.accountRuntime.scope?.repos ?? []
|
|
2079
2154
|
),
|
|
2080
2155
|
];
|
|
2156
|
+
if (repos.length === 0) {
|
|
2157
|
+
return undefined;
|
|
2158
|
+
}
|
|
2081
2159
|
return parseCursorOriginRepoScope(repos);
|
|
2082
2160
|
}
|
|
2083
2161
|
|
|
@@ -24,7 +24,10 @@ import {
|
|
|
24
24
|
SlackNudgeStore,
|
|
25
25
|
} from "../channels/slack/nudge-store.js";
|
|
26
26
|
import { resolveDedicatedSlackHostBinding } from "../channels/slack/slack-channel.js";
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
cursorHostedFiles,
|
|
29
|
+
isCursorHostedFilesAvailable,
|
|
30
|
+
} from "../files-backends/cursor-hosted.js";
|
|
28
31
|
import {
|
|
29
32
|
type AgentProject,
|
|
30
33
|
type ApprovalDecision,
|
|
@@ -80,6 +83,16 @@ import {
|
|
|
80
83
|
isUnpricedCompletedTurn,
|
|
81
84
|
mapSdkTokenUsage,
|
|
82
85
|
} from "./cloud-turn-cost.js";
|
|
86
|
+
import {
|
|
87
|
+
applyAgentContinuationDefaults,
|
|
88
|
+
channelContinuationIdentity,
|
|
89
|
+
httpContinuationIdentity,
|
|
90
|
+
} from "./continuation-channel.js";
|
|
91
|
+
import {
|
|
92
|
+
continuationSource,
|
|
93
|
+
resolveV2Key,
|
|
94
|
+
V2EngineError,
|
|
95
|
+
} from "./continuation-identity.js";
|
|
83
96
|
import { isDevMode } from "./dev-mode.js";
|
|
84
97
|
import { type EventLogMemoryStats, EventLogStore } from "./event-log.js";
|
|
85
98
|
import { TurnEventMapper } from "./event-mapper.js";
|
|
@@ -113,6 +126,7 @@ import { assertCloudCanHonorAccountServersFilters } from "./resolved-connections
|
|
|
113
126
|
import type { AgentRunner } from "./sdk-runner.js";
|
|
114
127
|
import { sessionExternalLinks } from "./session-links.js";
|
|
115
128
|
import { SessionStore } from "./session-store.js";
|
|
129
|
+
import { syncSkillsToStore } from "./skills-sync.js";
|
|
116
130
|
import { StorageCoordinator } from "./storage-coordinator.js";
|
|
117
131
|
import type { FrameworkSessionStore } from "./storage-roles.js";
|
|
118
132
|
import { normalizeToolResult, toolCallErrorMessage } from "./tool-result.js";
|
|
@@ -302,6 +316,8 @@ export class SessionEngine {
|
|
|
302
316
|
>();
|
|
303
317
|
/** Once-per-process cache for the A/B snapshot backfill (see abSnapshot). */
|
|
304
318
|
private restoredAbSnapshot: Promise<ABSnapshot | undefined> | undefined;
|
|
319
|
+
/** In-flight skills → deployment store sync (see ensureCloudSkillsSynced). */
|
|
320
|
+
private cloudSkillsSync: Promise<boolean> | undefined;
|
|
305
321
|
|
|
306
322
|
private readonly runner: AgentRunner;
|
|
307
323
|
private readonly logger: (line: string) => void;
|
|
@@ -366,6 +382,7 @@ export class SessionEngine {
|
|
|
366
382
|
|
|
367
383
|
constructor(options: SessionEngineOptions) {
|
|
368
384
|
this.project = options.project;
|
|
385
|
+
applyAgentContinuationDefaults(this.project);
|
|
369
386
|
this.stateRoot = options.stateRoot;
|
|
370
387
|
this.runner = options.runner;
|
|
371
388
|
this.logger = options.logger ?? (() => {});
|
|
@@ -734,26 +751,50 @@ export class SessionEngine {
|
|
|
734
751
|
* Start or resume a session on a channel. When `continuationToken`
|
|
735
752
|
* addresses an existing session this is a follow-up turn; otherwise a new
|
|
736
753
|
* session is created (keyed by the provided token, or a fresh one).
|
|
754
|
+
*
|
|
755
|
+
* v2 (`/v2` selectors) refuses `continuationToken` and looks
|
|
756
|
+
* up `(agentId, cKey)` from a mailbox stamp or structured claim.
|
|
737
757
|
*/
|
|
738
758
|
async send(
|
|
739
759
|
channelId: string,
|
|
740
760
|
message: string,
|
|
741
761
|
options: EngineSendOptions = {}
|
|
742
762
|
): Promise<ChannelSession> {
|
|
743
|
-
const
|
|
763
|
+
const identity =
|
|
764
|
+
channelId === HTTP_CHANNEL_ID
|
|
765
|
+
? httpContinuationIdentity(this.project.httpChannel)
|
|
766
|
+
: channelContinuationIdentity(this.channelsById.get(channelId));
|
|
767
|
+
let sendOptions = options;
|
|
768
|
+
let skipContinuationLookup = false;
|
|
769
|
+
if (continuationSource(identity) === "control-plane") {
|
|
770
|
+
if (options.continuationToken !== undefined) {
|
|
771
|
+
throw new V2EngineError(
|
|
772
|
+
"v2: do not pass continuationToken; use mailboxContinuation or claim"
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
const cKey = resolveV2Key(identity, options);
|
|
776
|
+
sendOptions = { ...options, continuationToken: cKey };
|
|
777
|
+
skipContinuationLookup = cKey.startsWith("evt:");
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
const auth = sendOptions.auth ?? null;
|
|
744
781
|
let existing =
|
|
745
|
-
|
|
782
|
+
skipContinuationLookup || sendOptions.continuationToken === undefined
|
|
746
783
|
? undefined
|
|
747
784
|
: await this.sessions.findByContinuation(
|
|
748
785
|
channelId,
|
|
749
|
-
|
|
786
|
+
sendOptions.continuationToken
|
|
750
787
|
);
|
|
751
|
-
if (
|
|
788
|
+
if (
|
|
789
|
+
existing === undefined &&
|
|
790
|
+
!skipContinuationLookup &&
|
|
791
|
+
sendOptions.continuationToken !== undefined
|
|
792
|
+
) {
|
|
752
793
|
// Local miss: the session may live only in the storage sink (it
|
|
753
794
|
// fell outside the startup restore window, or restore is lazy-only).
|
|
754
795
|
existing = await this.restoreSessionByContinuation(
|
|
755
796
|
channelId,
|
|
756
|
-
|
|
797
|
+
sendOptions.continuationToken
|
|
757
798
|
);
|
|
758
799
|
}
|
|
759
800
|
|
|
@@ -765,25 +806,25 @@ export class SessionEngine {
|
|
|
765
806
|
// synchronize). Leave the durable continuation key unchanged.
|
|
766
807
|
let record = existing;
|
|
767
808
|
const refreshWorkspace =
|
|
768
|
-
|
|
769
|
-
|
|
809
|
+
sendOptions.workspaceDir !== undefined &&
|
|
810
|
+
sendOptions.workspaceDir !== existing.workspaceOverride;
|
|
770
811
|
if (
|
|
771
812
|
refreshWorkspace ||
|
|
772
|
-
|
|
773
|
-
|
|
813
|
+
sendOptions.workspaceFiles !== undefined ||
|
|
814
|
+
sendOptions.images !== undefined
|
|
774
815
|
) {
|
|
775
816
|
record = await this.updateRecord(existing.sessionId, (current) => ({
|
|
776
817
|
...current,
|
|
777
818
|
workspaceOverride: refreshWorkspace
|
|
778
|
-
?
|
|
819
|
+
? sendOptions.workspaceDir
|
|
779
820
|
: current.workspaceOverride,
|
|
780
821
|
pendingWorkspaceFiles: mergePendingWorkspaceFiles(
|
|
781
822
|
current.pendingWorkspaceFiles,
|
|
782
|
-
|
|
823
|
+
sendOptions.workspaceFiles
|
|
783
824
|
),
|
|
784
825
|
pendingImages: mergePendingImages(
|
|
785
826
|
current.pendingImages,
|
|
786
|
-
|
|
827
|
+
sendOptions.images
|
|
787
828
|
),
|
|
788
829
|
}));
|
|
789
830
|
}
|
|
@@ -792,31 +833,32 @@ export class SessionEngine {
|
|
|
792
833
|
// and the first send's snapshot must not pin this session's turns to a
|
|
793
834
|
// stale repo/prUrl for the session's lifetime.
|
|
794
835
|
if (
|
|
795
|
-
|
|
796
|
-
JSON.stringify(
|
|
836
|
+
sendOptions.cloud !== undefined &&
|
|
837
|
+
JSON.stringify(sendOptions.cloud) !==
|
|
838
|
+
JSON.stringify(record.cloudOverride)
|
|
797
839
|
) {
|
|
798
840
|
record = await this.updateRecord(record.sessionId, (current) => ({
|
|
799
841
|
...current,
|
|
800
|
-
cloudOverride:
|
|
842
|
+
cloudOverride: sendOptions.cloud,
|
|
801
843
|
}));
|
|
802
844
|
}
|
|
803
845
|
// Refresh wake-derived channel state (GitHub headSha / refs) without
|
|
804
846
|
// wiping sticky fields. Null patch values are skipped.
|
|
805
|
-
if (
|
|
847
|
+
if (sendOptions.refreshState !== undefined) {
|
|
806
848
|
record = await this.updateRecord(record.sessionId, (current) => ({
|
|
807
849
|
...current,
|
|
808
850
|
channelState: mergeChannelStateSkipNull(
|
|
809
851
|
current.channelState,
|
|
810
|
-
|
|
852
|
+
sendOptions.refreshState
|
|
811
853
|
),
|
|
812
854
|
}));
|
|
813
855
|
}
|
|
814
856
|
const since = (await this.logs.get(record.sessionId)).count;
|
|
815
857
|
const coalesced = await this.startTurn(record.sessionId, message, {
|
|
816
|
-
admission:
|
|
817
|
-
...(
|
|
858
|
+
admission: sendOptions.admission ?? "preempt",
|
|
859
|
+
...(sendOptions.coalesceSourceTs === undefined
|
|
818
860
|
? {}
|
|
819
|
-
: { sourceTs:
|
|
861
|
+
: { sourceTs: sendOptions.coalesceSourceTs }),
|
|
820
862
|
});
|
|
821
863
|
return this.channelSession(
|
|
822
864
|
record.sessionId,
|
|
@@ -828,22 +870,22 @@ export class SessionEngine {
|
|
|
828
870
|
}
|
|
829
871
|
|
|
830
872
|
const now = new Date().toISOString();
|
|
831
|
-
const channelState = this.initialChannelState(channelId,
|
|
832
|
-
const purpose =
|
|
873
|
+
const channelState = this.initialChannelState(channelId, sendOptions.state);
|
|
874
|
+
const purpose = sendOptions.purpose === "eval" ? "eval" : "live";
|
|
833
875
|
let record: SessionRecord = {
|
|
834
876
|
sessionId: newSessionId(),
|
|
835
877
|
channelId,
|
|
836
|
-
mode:
|
|
878
|
+
mode: sendOptions.mode ?? "chat",
|
|
837
879
|
purpose,
|
|
838
|
-
continuationKey:
|
|
880
|
+
continuationKey: sendOptions.continuationToken ?? newContinuationKey(),
|
|
839
881
|
auth,
|
|
840
|
-
title:
|
|
882
|
+
title: sendOptions.title,
|
|
841
883
|
channelState,
|
|
842
|
-
workspaceOverride:
|
|
843
|
-
pendingWorkspaceFiles:
|
|
844
|
-
pendingImages:
|
|
845
|
-
cloudOverride:
|
|
846
|
-
sdkAgentId:
|
|
884
|
+
workspaceOverride: sendOptions.workspaceDir,
|
|
885
|
+
pendingWorkspaceFiles: sendOptions.workspaceFiles,
|
|
886
|
+
pendingImages: sendOptions.images,
|
|
887
|
+
cloudOverride: sendOptions.cloud,
|
|
888
|
+
sdkAgentId: sendOptions.sdkAgentId,
|
|
847
889
|
turnCount: 0,
|
|
848
890
|
createdAt: now,
|
|
849
891
|
updatedAt: now,
|
|
@@ -857,10 +899,10 @@ export class SessionEngine {
|
|
|
857
899
|
record = await this.enrollABs(record);
|
|
858
900
|
const since = (await this.logs.get(record.sessionId)).count;
|
|
859
901
|
await this.startTurn(record.sessionId, message, {
|
|
860
|
-
admission:
|
|
861
|
-
...(
|
|
902
|
+
admission: sendOptions.admission ?? "preempt",
|
|
903
|
+
...(sendOptions.coalesceSourceTs === undefined
|
|
862
904
|
? {}
|
|
863
|
-
: { sourceTs:
|
|
905
|
+
: { sourceTs: sendOptions.coalesceSourceTs }),
|
|
864
906
|
});
|
|
865
907
|
return this.channelSession(record.sessionId, record, true, false, since);
|
|
866
908
|
}
|
|
@@ -1753,6 +1795,51 @@ export class SessionEngine {
|
|
|
1753
1795
|
};
|
|
1754
1796
|
}
|
|
1755
1797
|
|
|
1798
|
+
/**
|
|
1799
|
+
* Sync authored skills onto the deployment store at `skills/<name>/…`
|
|
1800
|
+
* before the first cloud prompt, so `--agent-store-skills-dir` and the
|
|
1801
|
+
* first-turn S3 scan can discover them. False when the sync fails: the
|
|
1802
|
+
* turn then runs without store skills rather than pointing discovery at
|
|
1803
|
+
* paths that do not exist.
|
|
1804
|
+
*
|
|
1805
|
+
* With skills authored, every first cloud turn re-copies the authored
|
|
1806
|
+
* bytes and the memo only dedupes concurrent first turns. The mount is
|
|
1807
|
+
* writable from cloud sessions, so a once-per-process copy would let one
|
|
1808
|
+
* session's edits masquerade as agent definition for every later session
|
|
1809
|
+
* until the engine restarts; re-syncing keeps the store true to discovery
|
|
1810
|
+
* the same way local materialization always rewrites skills. Without
|
|
1811
|
+
* skills the sync is best-effort stale cleanup and one attempt per
|
|
1812
|
+
* process is enough, success or not — a deployment without the files
|
|
1813
|
+
* surface must not fail and log on every new session for a feature it
|
|
1814
|
+
* does not use.
|
|
1815
|
+
*/
|
|
1816
|
+
private ensureCloudSkillsSynced(): Promise<boolean> {
|
|
1817
|
+
if (this.cloudSkillsSync !== undefined) {
|
|
1818
|
+
return this.cloudSkillsSync;
|
|
1819
|
+
}
|
|
1820
|
+
const skills = this.project.agent.skills;
|
|
1821
|
+
let sync = syncSkillsToStore({
|
|
1822
|
+
sink: cursorHostedFiles(),
|
|
1823
|
+
agentName: this.project.name,
|
|
1824
|
+
skills,
|
|
1825
|
+
}).then(
|
|
1826
|
+
() => true,
|
|
1827
|
+
(error) => {
|
|
1828
|
+
this.logger(
|
|
1829
|
+
`[skills] deployment store sync failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1830
|
+
);
|
|
1831
|
+
return false;
|
|
1832
|
+
}
|
|
1833
|
+
);
|
|
1834
|
+
if (skills.length > 0) {
|
|
1835
|
+
sync = sync.finally(() => {
|
|
1836
|
+
this.cloudSkillsSync = undefined;
|
|
1837
|
+
});
|
|
1838
|
+
}
|
|
1839
|
+
this.cloudSkillsSync = sync;
|
|
1840
|
+
return sync;
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1756
1843
|
private async buildTurnRequest(
|
|
1757
1844
|
record: SessionRecord,
|
|
1758
1845
|
agent: ResolvedAgent,
|
|
@@ -1815,8 +1902,9 @@ export class SessionEngine {
|
|
|
1815
1902
|
if (isFirstTurn) {
|
|
1816
1903
|
if (runtime === "cloud") {
|
|
1817
1904
|
// Cloud VMs have no materialized workspace: ship the full context,
|
|
1818
|
-
// including agent tool script bodies. On hosted deployments
|
|
1819
|
-
//
|
|
1905
|
+
// including agent tool script bodies. On hosted deployments authored
|
|
1906
|
+
// skills land on the store mount for native discovery, and the
|
|
1907
|
+
// shared memory journal is on that mount too — say where. When the
|
|
1820
1908
|
// turn carries the session-bound server-tool MCP endpoint, the
|
|
1821
1909
|
// preamble catalogs server tools under that MCP server name *before*
|
|
1822
1910
|
// the agent-tool "write the script if missing" recipe, so a model
|
|
@@ -1828,7 +1916,14 @@ export class SessionEngine {
|
|
|
1828
1916
|
? undefined
|
|
1829
1917
|
: SERVER_TOOLS_MCP_SERVER_NAME,
|
|
1830
1918
|
});
|
|
1831
|
-
const
|
|
1919
|
+
const hosted = isCursorHostedFilesAvailable();
|
|
1920
|
+
// Synced whenever hosted, not just when skills exist: removing the
|
|
1921
|
+
// last skill has to delete its store copies too. Discovery is native
|
|
1922
|
+
// (`--agent-store-skills-dir`); this only has to land the bytes.
|
|
1923
|
+
if (hosted) {
|
|
1924
|
+
await this.ensureCloudSkillsSynced();
|
|
1925
|
+
}
|
|
1926
|
+
const memorySection = hosted
|
|
1832
1927
|
? `\n\n${buildCloudMemorySection(this.project.name)}`
|
|
1833
1928
|
: "";
|
|
1834
1929
|
turnPrompt = `${preamble}${memorySection}\n\n${turnPrompt}`;
|
|
@@ -11,6 +11,7 @@ import { mkdir, readdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
|
11
11
|
import { join } from "node:path";
|
|
12
12
|
import type { SessionRecord } from "../types.js";
|
|
13
13
|
import { isSafeSessionId } from "./auth.js";
|
|
14
|
+
import { isV2DurableContinuationKey } from "./continuation-identity.js";
|
|
14
15
|
|
|
15
16
|
export class SessionStore {
|
|
16
17
|
private readonly cache = new Map<string, SessionRecord>();
|
|
@@ -39,6 +40,11 @@ export class SessionStore {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
private continuationKeyOf(channelId: string, key: string): string {
|
|
43
|
+
// v2 index is (agentId, cKey). This store is already per-agent, so drop
|
|
44
|
+
// channelId for `cont:` / `evt:` keys. v1 stays `{channelId}\n{token}`.
|
|
45
|
+
if (isV2DurableContinuationKey(key)) {
|
|
46
|
+
return `\0v2\n${key}`;
|
|
47
|
+
}
|
|
42
48
|
return `${channelId}\n${key}`;
|
|
43
49
|
}
|
|
44
50
|
|