@cursor/july 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/dist/bin/agent-serve.js +9 -0
  2. package/dist/channels/slack/post-update-delivery.d.ts +85 -0
  3. package/dist/channels/slack/post-update-delivery.d.ts.map +1 -0
  4. package/dist/docs/404.html +2 -2
  5. package/dist/docs/ab.html +3 -3
  6. package/dist/docs/assets/{app.BP8mAVMW.js → app.CY2buaEE.js} +1 -1
  7. package/dist/docs/assets/chunks/@localSearchIndexroot.OfDZ5CXg.js +1 -0
  8. package/dist/docs/assets/chunks/{VPLocalSearchBox.1FXIZbz8.js → VPLocalSearchBox.Ix954SFJ.js} +1 -1
  9. package/dist/docs/assets/chunks/{theme.Dm1R02v9.js → theme.PDwuJbyi.js} +2 -2
  10. package/dist/docs/assets/{deployment.md.BtfEsc9S.js → deployment.md.DC5-ImcM.js} +1 -1
  11. package/dist/docs/assets/{example-agents_approval-buddy.md.8R5phXb5.js → example-agents_approval-buddy.md.DFGBYLcc.js} +2 -2
  12. package/dist/docs/assets/{example-agents_approval-buddy.md.8R5phXb5.lean.js → example-agents_approval-buddy.md.DFGBYLcc.lean.js} +1 -1
  13. package/dist/docs/assets/{example-agents_index.md.CwtWu5ix.js → example-agents_index.md.BPXjUtRB.js} +2 -2
  14. package/dist/docs/assets/{example-agents_index.md.CwtWu5ix.lean.js → example-agents_index.md.BPXjUtRB.lean.js} +1 -1
  15. package/dist/docs/assets/{example-agents_security-reviewer.md.D2rtwDTO.js → example-agents_security-reviewer.md.CE9v-aKm.js} +2 -2
  16. package/dist/docs/assets/{example-agents_security-reviewer.md.D2rtwDTO.lean.js → example-agents_security-reviewer.md.CE9v-aKm.lean.js} +1 -1
  17. package/dist/docs/assets/{reference_cli.md.D189RBCH.js → reference_cli.md.CjfiV2Q-.js} +2 -1
  18. package/dist/docs/assets/{reference_connections.md.zaEYCLHT.js → reference_connections.md.FbWupyzW.js} +1 -1
  19. package/dist/docs/assets/{storage.md.Cu3MwM2a.js → storage.md.DRTdnFvd.js} +7 -1
  20. package/dist/docs/assets/{storage.md.Cu3MwM2a.lean.js → storage.md.DRTdnFvd.lean.js} +1 -1
  21. package/dist/docs/building-with-agents.html +3 -3
  22. package/dist/docs/concepts.html +3 -3
  23. package/dist/docs/deployment.html +5 -5
  24. package/dist/docs/evals.html +3 -3
  25. package/dist/docs/example-agents/approval-buddy.html +5 -5
  26. package/dist/docs/example-agents/benny.html +3 -3
  27. package/dist/docs/example-agents/bugbot.html +3 -3
  28. package/dist/docs/example-agents/codebase-wiki.html +3 -3
  29. package/dist/docs/example-agents/codeowners-review.html +3 -3
  30. package/dist/docs/example-agents/concierge.html +3 -3
  31. package/dist/docs/example-agents/fsd.html +3 -3
  32. package/dist/docs/example-agents/index.html +5 -5
  33. package/dist/docs/example-agents/knowledge-base.html +3 -3
  34. package/dist/docs/example-agents/oncall.html +3 -3
  35. package/dist/docs/example-agents/security-reviewer.html +6 -6
  36. package/dist/docs/example-agents/slack-agent.html +3 -3
  37. package/dist/docs/example-agents/weather-agent.html +3 -3
  38. package/dist/docs/guides/agent-to-agent.html +3 -3
  39. package/dist/docs/guides/cloud-runtime.html +3 -3
  40. package/dist/docs/guides/github.html +3 -3
  41. package/dist/docs/guides/human-in-the-loop.html +3 -3
  42. package/dist/docs/guides/slack.html +3 -3
  43. package/dist/docs/guides/webhooks.html +3 -3
  44. package/dist/docs/hashmap.json +1 -1
  45. package/dist/docs/hillclimbing.html +3 -3
  46. package/dist/docs/index.html +3 -3
  47. package/dist/docs/quickstart.html +3 -3
  48. package/dist/docs/reference/agent-config.html +3 -3
  49. package/dist/docs/reference/channels.html +3 -3
  50. package/dist/docs/reference/cli.html +6 -5
  51. package/dist/docs/reference/connections.html +5 -5
  52. package/dist/docs/reference/hooks.html +3 -3
  53. package/dist/docs/reference/http-api.html +3 -3
  54. package/dist/docs/reference/instructions.html +3 -3
  55. package/dist/docs/reference/playground.html +3 -3
  56. package/dist/docs/reference/project-layout.html +3 -3
  57. package/dist/docs/reference/schedules.html +3 -3
  58. package/dist/docs/reference/sessions.html +3 -3
  59. package/dist/docs/reference/skills.html +3 -3
  60. package/dist/docs/reference/subagents.html +3 -3
  61. package/dist/docs/reference/tools.html +3 -3
  62. package/dist/docs/scaffolding-agents.html +3 -3
  63. package/dist/docs/storage.html +11 -5
  64. package/dist/docs/troubleshooting.html +3 -3
  65. package/dist/internal/cli-ax.d.ts.map +1 -1
  66. package/dist/internal/cli-ax.js +7 -4
  67. package/dist/internal/cli-deploy.d.ts.map +1 -1
  68. package/dist/internal/cli-deploy.js +45 -18
  69. package/dist/internal/deploy-client.d.ts +7 -1
  70. package/dist/internal/deploy-client.d.ts.map +1 -1
  71. package/dist/internal/deploy-client.js +3 -0
  72. package/dist/internal/deploy-source.d.ts +3 -0
  73. package/dist/internal/deploy-source.d.ts.map +1 -1
  74. package/dist/internal/deploy-source.js +25 -7
  75. package/dist/internal/discovery.js +1 -1
  76. package/dist/internal/distribution.d.ts.map +1 -1
  77. package/dist/internal/distribution.js +1 -0
  78. package/dist/internal/hosting.d.ts +12 -2
  79. package/dist/internal/hosting.d.ts.map +1 -1
  80. package/dist/internal/hosting.js +21 -4
  81. package/dist/internal/json-dir-store.d.ts +32 -0
  82. package/dist/internal/json-dir-store.d.ts.map +1 -0
  83. package/dist/internal/logs-client.d.ts +16 -2
  84. package/dist/internal/logs-client.d.ts.map +1 -1
  85. package/dist/internal/logs-client.js +51 -16
  86. package/dist/internal/persistence-coordinator.d.ts +127 -0
  87. package/dist/internal/persistence-coordinator.d.ts.map +1 -0
  88. package/dist/internal/resolved-connections.d.ts +6 -0
  89. package/dist/internal/resolved-connections.d.ts.map +1 -1
  90. package/dist/internal/resolved-connections.js +6 -2
  91. package/dist/internal/server.d.ts.map +1 -1
  92. package/dist/internal/server.js +11 -1
  93. package/dist/internal/session-engine.d.ts +23 -1
  94. package/dist/internal/session-engine.d.ts.map +1 -1
  95. package/dist/internal/session-engine.js +100 -26
  96. package/dist/internal/sessions-client.d.ts +16 -2
  97. package/dist/internal/sessions-client.d.ts.map +1 -1
  98. package/dist/internal/sessions-client.js +28 -12
  99. package/dist/internal/storage-coordinator.d.ts +11 -0
  100. package/dist/internal/storage-coordinator.d.ts.map +1 -1
  101. package/dist/internal/storage-coordinator.js +30 -0
  102. package/dist/internal/workspace.d.ts +19 -0
  103. package/dist/internal/workspace.d.ts.map +1 -1
  104. package/dist/internal/workspace.js +47 -13
  105. package/dist/persistence.d.ts +184 -0
  106. package/dist/persistence.d.ts.map +1 -0
  107. package/dist/playground/assets/index-C0-QEG4O.js +86 -0
  108. package/dist/playground/assets/index-z3JY9O2x.css +1 -0
  109. package/dist/playground/index.html +2 -2
  110. package/dist/storage-backends/cursor-hosted.d.ts +75 -0
  111. package/dist/storage-backends/cursor-hosted.d.ts.map +1 -0
  112. package/dist/storage-backends/cursor-hosted.js +217 -0
  113. package/dist/storage-backends/postgres-kv.d.ts +5 -0
  114. package/dist/storage-backends/postgres-kv.d.ts.map +1 -1
  115. package/dist/storage-backends/postgres-kv.js +5 -0
  116. package/dist/types.d.ts +15 -0
  117. package/dist/types.d.ts.map +1 -1
  118. package/docs/deployment.md +7 -3
  119. package/docs/example-agents/approval-buddy.md +1 -1
  120. package/docs/example-agents/index.md +1 -1
  121. package/docs/example-agents/security-reviewer.md +5 -5
  122. package/docs/reference/cli.md +2 -0
  123. package/docs/reference/connections.md +4 -2
  124. package/docs/storage.md +18 -4
  125. package/package.json +8 -1
  126. package/src/bin/agent-serve.ts +10 -0
  127. package/src/internal/cli-ax.ts +10 -4
  128. package/src/internal/cli-deploy.ts +58 -20
  129. package/src/internal/deploy-client.ts +11 -0
  130. package/src/internal/deploy-source.ts +24 -6
  131. package/src/internal/discovery.ts +1 -1
  132. package/src/internal/distribution.ts +1 -0
  133. package/src/internal/hosting.ts +24 -4
  134. package/src/internal/logs-client.ts +67 -21
  135. package/src/internal/resolved-connections.ts +14 -4
  136. package/src/internal/server.ts +15 -1
  137. package/src/internal/session-engine.ts +105 -13
  138. package/src/internal/sessions-client.ts +49 -14
  139. package/src/internal/storage-coordinator.ts +36 -0
  140. package/src/internal/workspace.ts +48 -11
  141. package/src/storage-backends/cursor-hosted.ts +267 -0
  142. package/src/storage-backends/postgres-kv.ts +5 -0
  143. package/src/types.ts +16 -0
  144. package/dist/docs/assets/chunks/@localSearchIndexroot.DevOabKJ.js +0 -1
  145. package/dist/playground/assets/index-7GJIUFQj.css +0 -1
  146. package/dist/playground/assets/index-Bpr4Th4M.js +0 -319
  147. /package/dist/docs/assets/{deployment.md.BtfEsc9S.lean.js → deployment.md.DC5-ImcM.lean.js} +0 -0
  148. /package/dist/docs/assets/{reference_cli.md.D189RBCH.lean.js → reference_cli.md.CjfiV2Q-.lean.js} +0 -0
  149. /package/dist/docs/assets/{reference_connections.md.zaEYCLHT.lean.js → reference_connections.md.FbWupyzW.lean.js} +0 -0
@@ -46,12 +46,12 @@ import { createHostPlatforms } from "./host-platforms.js";
46
46
  import { formatContinuationToken, newContinuationKey, newSessionId, newToolCallId, } from "./ids.js";
47
47
  import { validateToolInput } from "./json-schema.js";
48
48
  import { McpHost } from "./mcp-host.js";
49
- import { buildIdentitySection, buildSessionContextBlock, SCHEDULE_CHANNEL_PREFIX, } from "./prompt-context.js";
49
+ import { buildSessionContextBlock, SCHEDULE_CHANNEL_PREFIX, } from "./prompt-context.js";
50
50
  import { assertCloudCanHonorAccountServersFilters } from "./resolved-connections.js";
51
51
  import { SessionStore } from "./session-store.js";
52
52
  import { StorageCoordinator } from "./storage-coordinator.js";
53
53
  import { normalizeToolResult, toolCallErrorMessage } from "./tool-result.js";
54
- import { buildAgentToolsCatalog, materializeWorkspace, writeWorkspaceFiles, } from "./workspace.js";
54
+ import { buildAgentsMdContent, isNestedInGitRepo, materializeWorkspace, writeWorkspaceFiles, } from "./workspace.js";
55
55
  export const HTTP_CHANNEL_ID = "http";
56
56
  export { SCHEDULE_CHANNEL_PREFIX } from "./prompt-context.js";
57
57
  export class SessionBusyError extends Error {
@@ -726,7 +726,15 @@ export class SessionEngine {
726
726
  return rest;
727
727
  });
728
728
  }
729
- const request = this.buildTurnRequest(record, agent, turnId, message, isFirstTurn, emit, (update) => __awaiter(this, void 0, void 0, function* () {
729
+ // The harness only loads the scaffolded AGENTS.md when the session
730
+ // workspace is its own project root. With a per-session cwd override
731
+ // (PR worktree) the scaffold lands elsewhere, and a workspace nested
732
+ // inside a git repo re-roots harness rules at that repo — in both
733
+ // cases deliver instructions inline on the first turn instead.
734
+ const instructionsInvisibleToHarness = isFirstTurn &&
735
+ (record.workspaceOverride !== undefined ||
736
+ (yield isNestedInGitRepo(harnessCwd)));
737
+ const request = this.buildTurnRequest(record, agent, turnId, message, isFirstTurn, instructionsInvisibleToHarness, emit, (update) => __awaiter(this, void 0, void 0, function* () {
730
738
  mapper.handleUpdate(update);
731
739
  // Yield so the HTTP NDJSON writer can flush tool start/result
732
740
  // events while sibling parallel tools are still executing.
@@ -797,9 +805,8 @@ export class SessionEngine {
797
805
  return Object.assign(Object.assign(Object.assign({}, outcome), (finalResult === undefined ? {} : { result: finalResult })), (finalUsage === undefined ? {} : { usage: finalUsage }));
798
806
  });
799
807
  }
800
- buildTurnRequest(record, agent, turnId, prompt, isFirstTurn, emit, onUpdate, signal) {
801
- var _a, _b, _c;
802
- var _d;
808
+ buildTurnRequest(record, agent, turnId, prompt, isFirstTurn, instructionsInvisibleToHarness, emit, onUpdate, signal) {
809
+ var _a, _b;
803
810
  // Per-session cloud attach (channel/tool handoff) forces cloud runtime
804
811
  // even when the agent defaults to local for chat server tools.
805
812
  const runtime = resolveSessionRuntime({
@@ -822,15 +829,22 @@ export class SessionEngine {
822
829
  });
823
830
  turnPrompt = `${contextBlock}\n\n${prompt}`;
824
831
  }
825
- if (runtime === "cloud" && isFirstTurn) {
826
- const preamble = [
827
- (_d = (_c = agent.instructions) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : "",
828
- buildIdentitySection(agent),
829
- buildAgentToolsCatalog(agent.tools, { includeScripts: true }),
830
- ]
831
- .filter((part) => part !== "")
832
- .join("\n\n");
833
- turnPrompt = `${preamble}\n\n${turnPrompt}`;
832
+ if (isFirstTurn) {
833
+ if (runtime === "cloud") {
834
+ // Cloud VMs have no materialized workspace: ship the full context,
835
+ // including agent tool script bodies.
836
+ const preamble = buildAgentsMdContent(agent, { includeScripts: true });
837
+ turnPrompt = `${preamble}\n\n${turnPrompt}`;
838
+ }
839
+ else if (instructionsInvisibleToHarness) {
840
+ // Local workspace whose AGENTS.md the harness will not load. With a
841
+ // per-session harness cwd override, agent tool scripts live only in
842
+ // the durable scaffold dir — embed bodies like cloud. Otherwise the
843
+ // catalog can reference on-disk paths under the harness cwd.
844
+ const includeScripts = record.workspaceOverride !== undefined;
845
+ const preamble = buildAgentsMdContent(agent, { includeScripts });
846
+ turnPrompt = `${preamble}\n\n${turnPrompt}`;
847
+ }
834
848
  }
835
849
  return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ sessionId: record.sessionId }, (record.sdkAgentId === undefined
836
850
  ? {}
@@ -1347,22 +1361,82 @@ export class SessionEngine {
1347
1361
  * observability surface across every principal (channel-driven runs,
1348
1362
  * schedule/task sessions, other callers). The route auth chain still
1349
1363
  * gates who may call this at all.
1364
+ *
1365
+ * When the project uses `cursorHostedStorage`, prefers durable Bugbot rows
1366
+ * (merged with any newer local records not flushed yet). Falls back to the
1367
+ * local `--state-root` store when the sink is unavailable.
1350
1368
  */
1351
1369
  listSessions(caller, options) {
1370
+ return __awaiter(this, void 0, void 0, function* () {
1371
+ return (yield this.listSessionsWithSource(caller, options)).sessions;
1372
+ });
1373
+ }
1374
+ /**
1375
+ * Same as {@link listSessions}, plus which store answered
1376
+ * (`cursor-hosted` = durable DB via the control-plane proxy; `local` =
1377
+ * `--state-root`).
1378
+ */
1379
+ listSessionsWithSource(caller, options) {
1352
1380
  return __awaiter(this, void 0, void 0, function* () {
1353
1381
  var _a;
1354
- const includeAll = (_a = options === null || options === void 0 ? void 0 : options.includeAll) !== null && _a !== void 0 ? _a : false;
1382
+ var _b;
1383
+ const includeAll = (_b = options === null || options === void 0 ? void 0 : options.includeAll) !== null && _b !== void 0 ? _b : false;
1384
+ if (((_a = this.storage) === null || _a === void 0 ? void 0 : _a.isCursorHosted) === true) {
1385
+ try {
1386
+ const records = yield this.mergeStoredAndLocalSessions();
1387
+ return {
1388
+ sessions: this.summarizeSessionRecords(records, caller, includeAll),
1389
+ source: "cursor-hosted",
1390
+ };
1391
+ }
1392
+ catch (error) {
1393
+ this.logger(`[agentkit] cursor-hosted session list failed; falling back to local: ${describeError(error)}`);
1394
+ }
1395
+ }
1355
1396
  const records = yield this.sessions.list();
1356
- return records
1357
- .filter((record) => includeAll || samePrincipal(record.auth, caller))
1358
- .map((record) => {
1359
- const externalUrl = externalUrlForSession(record);
1360
- return Object.assign(Object.assign(Object.assign({ sessionId: record.sessionId, channelId: record.channelId, mode: record.mode }, (record.title === undefined ? {} : { title: record.title })), { turnCount: record.turnCount, running: this.activeTurns.has(record.sessionId) ||
1361
- this.pendingTurns.has(record.sessionId), createdAt: record.createdAt, updatedAt: record.updatedAt, continuationToken: record.continuationKey === null
1362
- ? null
1363
- : formatContinuationToken(record.channelId, record.continuationKey) }), (externalUrl === undefined ? {} : { externalUrl }));
1364
- })
1365
- .reverse();
1397
+ // Local store is createdAt-asc; reverse so newest created leads.
1398
+ return {
1399
+ sessions: this.summarizeSessionRecords([...records].reverse(), caller, includeAll),
1400
+ source: "local",
1401
+ };
1402
+ });
1403
+ }
1404
+ /**
1405
+ * Durable sink rows plus local records (local wins on the same id when
1406
+ * newer — covers debounce windows that have not flushed yet). Newest
1407
+ * `updatedAt` first.
1408
+ */
1409
+ mergeStoredAndLocalSessions() {
1410
+ return __awaiter(this, void 0, void 0, function* () {
1411
+ const storage = this.storage;
1412
+ if (storage === undefined) {
1413
+ throw new Error("storage is not configured");
1414
+ }
1415
+ const stored = yield storage.listSessionsFromSink();
1416
+ const local = yield this.sessions.list();
1417
+ const byId = new Map();
1418
+ for (const record of stored) {
1419
+ byId.set(record.sessionId, record);
1420
+ }
1421
+ for (const record of local) {
1422
+ const existing = byId.get(record.sessionId);
1423
+ if (existing === undefined ||
1424
+ record.updatedAt.localeCompare(existing.updatedAt) >= 0) {
1425
+ byId.set(record.sessionId, record);
1426
+ }
1427
+ }
1428
+ return [...byId.values()].sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
1429
+ });
1430
+ }
1431
+ summarizeSessionRecords(records, caller, includeAll) {
1432
+ return records
1433
+ .filter((record) => includeAll || samePrincipal(record.auth, caller))
1434
+ .map((record) => {
1435
+ const externalUrl = externalUrlForSession(record);
1436
+ return Object.assign(Object.assign(Object.assign({ sessionId: record.sessionId, channelId: record.channelId, mode: record.mode }, (record.title === undefined ? {} : { title: record.title })), { turnCount: record.turnCount, running: this.activeTurns.has(record.sessionId) ||
1437
+ this.pendingTurns.has(record.sessionId), createdAt: record.createdAt, updatedAt: record.updatedAt, continuationToken: record.continuationKey === null
1438
+ ? null
1439
+ : formatContinuationToken(record.channelId, record.continuationKey) }), (externalUrl === undefined ? {} : { externalUrl }));
1366
1440
  });
1367
1441
  }
1368
1442
  /**
@@ -3,13 +3,23 @@
3
3
  *
4
4
  * Customer-facing errors never include hosting URLs or infra jargon.
5
5
  */
6
- import type { SessionEvent, SessionSummary } from "../types.js";
6
+ import type { SessionEvent, SessionListSource, SessionSummary } from "../types.js";
7
7
  import { type RequestAuth } from "./request-headers.js";
8
+ export interface ListedSessions {
9
+ sessions: SessionSummary[];
10
+ /** Present when the server reports which store answered. */
11
+ source?: SessionListSource;
12
+ }
8
13
  export declare function listSessions(args: {
9
14
  baseUrl: string;
10
15
  auth?: RequestAuth;
11
16
  fetchImpl?: typeof fetch;
12
17
  }): Promise<SessionSummary[]>;
18
+ export declare function listSessionsWithSource(args: {
19
+ baseUrl: string;
20
+ auth?: RequestAuth;
21
+ fetchImpl?: typeof fetch;
22
+ }): Promise<ListedSessions>;
13
23
  export declare function fetchSessionEvents(args: {
14
24
  baseUrl: string;
15
25
  sessionId: string;
@@ -29,6 +39,10 @@ export declare function resolvePreviousSessionId(args: {
29
39
  auth?: RequestAuth;
30
40
  fetchImpl?: typeof fetch;
31
41
  }): Promise<string | undefined>;
42
+ /** Human label for {@link SessionListSource} in CLI output. */
43
+ export declare function formatSessionListSource(source: SessionListSource): string;
32
44
  /** Format a sessions table (id, channel, mode, turns, running, updated). */
33
- export declare function formatSessionsTable(sessions: SessionSummary[]): string;
45
+ export declare function formatSessionsTable(sessions: SessionSummary[], options?: {
46
+ source?: SessionListSource;
47
+ }): string;
34
48
  //# sourceMappingURL=sessions-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sessions-client.d.ts","sourceRoot":"","sources":["../../src/internal/sessions-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAE7E,wBAAsB,YAAY,CAAC,IAAI,EAAE;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CA8B5B;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAuE1B;AAgCD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,SAAS,cAAc,EAAE,GAClC,cAAc,GAAG,SAAS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AAK,CAAC;CAC1B,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAuE1B;AAgCD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,SAAS,cAAc,EAAE,GAClC,cAAc,GAAG,SAAS,CAU5B;AAED,+DAA+D;AAC/D,wBAAsB,wBAAwB,CAAC,IAAI,EAAE;IACnD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAO9B;AAED,+DAA+D;AAC/D,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAIzE;AAED,4EAA4E;AAC5E,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,cAAc,EAAE,EAC1B,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,iBAAiB,CAAA;CAAE,GACvC,MAAM,CAkBR"}
@@ -15,6 +15,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15
15
  import { sanitizeCustomerError } from "./logs-client.js";
16
16
  import { mergeRequestHeaders } from "./request-headers.js";
17
17
  export function listSessions(args) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ return (yield listSessionsWithSource(args)).sessions;
20
+ });
21
+ }
22
+ export function listSessionsWithSource(args) {
18
23
  return __awaiter(this, void 0, void 0, function* () {
19
24
  var _a;
20
25
  const baseUrl = args.baseUrl.replace(/\/$/, "");
@@ -32,17 +37,19 @@ export function listSessions(args) {
32
37
  throw new Error(`Could not list sessions (HTTP ${resp.status}).`);
33
38
  }
34
39
  const body = (yield resp.json());
35
- if (!Array.isArray(body.sessions)) {
36
- return [];
37
- }
38
- const out = [];
39
- for (const row of body.sessions) {
40
- const parsed = parseSessionSummary(row);
41
- if (parsed !== undefined) {
42
- out.push(parsed);
40
+ const sessions = [];
41
+ if (Array.isArray(body.sessions)) {
42
+ for (const row of body.sessions) {
43
+ const parsed = parseSessionSummary(row);
44
+ if (parsed !== undefined) {
45
+ sessions.push(parsed);
46
+ }
43
47
  }
44
48
  }
45
- return out;
49
+ const source = body.source === "cursor-hosted" || body.source === "local"
50
+ ? body.source
51
+ : undefined;
52
+ return source === undefined ? { sessions } : { sessions, source };
46
53
  });
47
54
  }
48
55
  export function fetchSessionEvents(args) {
@@ -167,10 +174,19 @@ export function resolvePreviousSessionId(args) {
167
174
  return (_a = pickPreviousSession(sessions)) === null || _a === void 0 ? void 0 : _a.sessionId;
168
175
  });
169
176
  }
177
+ /** Human label for {@link SessionListSource} in CLI output. */
178
+ export function formatSessionListSource(source) {
179
+ return source === "cursor-hosted"
180
+ ? "Listing from cursor-hosted storage (durable DB)."
181
+ : "Listing from local session store.";
182
+ }
170
183
  /** Format a sessions table (id, channel, mode, turns, running, updated). */
171
- export function formatSessionsTable(sessions) {
184
+ export function formatSessionsTable(sessions, options) {
185
+ const sourceLine = (options === null || options === void 0 ? void 0 : options.source) === undefined
186
+ ? ""
187
+ : `${formatSessionListSource(options.source)}\n`;
172
188
  if (sessions.length === 0) {
173
- return "No sessions.\n";
189
+ return `${sourceLine}No sessions.\n`;
174
190
  }
175
191
  const header = ["SESSION", "CHANNEL", "MODE", "TURNS", "RUNNING", "UPDATED"];
176
192
  const rows = sessions.map((s) => [
@@ -181,7 +197,7 @@ export function formatSessionsTable(sessions) {
181
197
  s.running ? "yes" : "no",
182
198
  s.updatedAt,
183
199
  ]);
184
- return `${renderTable(header, rows)}\n`;
200
+ return `${sourceLine}${renderTable(header, rows)}\n`;
185
201
  }
186
202
  function renderTable(header, rows) {
187
203
  const widths = header.map((h, i) => Math.max(h.length, ...rows.map((row) => { var _a; return ((_a = row[i]) !== null && _a !== void 0 ? _a : "").length; })));
@@ -73,12 +73,23 @@ export declare class StorageCoordinator {
73
73
  private deleteOp;
74
74
  /** Whether the sink can serve the startup bulk restore (`list`). */
75
75
  get canBulkRestore(): boolean;
76
+ /**
77
+ * True when the authored sink is `cursorHostedStorage` (Bugbot via the
78
+ * control-plane proxy). `GET /v1/sessions` prefers this durable list.
79
+ */
80
+ get isCursorHosted(): boolean;
76
81
  /**
77
82
  * Saved session records for this agent (startup restore). Errors are
78
83
  * logged and read as "nothing saved" — a broken store must never block
79
84
  * serve start.
80
85
  */
81
86
  listSessions(): Promise<SessionRecord[]>;
87
+ /**
88
+ * Session records from the sink for the sessions API. Unlike
89
+ * {@link listSessions}, missing `list` or a thrown sink error **propagates**
90
+ * so the caller can fall back to the local session store.
91
+ */
92
+ listSessionsFromSink(): Promise<SessionRecord[]>;
82
93
  /**
83
94
  * Saved event stream for one session: chunk values concatenated in key
84
95
  * order (chunks are keyed by their first event's index, zero-padded, so
@@ -1 +1 @@
1
- {"version":3,"file":"storage-coordinator.d.ts","sourceRoot":"","sources":["../../src/internal/storage-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,EACL,KAAK,qBAAqB,EAE1B,KAAK,cAAc,EACnB,KAAK,iBAAiB,EAEvB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AA0C5E,MAAM,WAAW,yBAAyB;IACxC,UAAU,EAAE,iBAAiB,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AASD,qBAAa,kBAAkB;IAC7B,QAAQ,C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KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9D;IAED,oEAAoE;IAC9D,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG/C;IAMD;;;;OAIG;IACH,QAAQ,IAAI,cAAc,GAAG,SAAS,CA2CrC;IAMD,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAcrC;IAED;;;;OAIG;IACH,UAAU,CAAC,QAAQ,EAAE,UAAU,GAAG,IAAI,CAerC;IAED,sEAAsE;IAChE,mBAAmB,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAc3D;IAMD;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAqB3B;IAED,wEAAwE;IACxE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAExB;IAED,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,WAAW;IAgBnB,2EAA2E;YAC7D,OAAO;IAkBrB,OAAO,CAAC,OAAO;IA8Bf,OAAO,CAAC,OAAO;CAGhB"}
@@ -24,6 +24,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
24
24
  });
25
25
  };
26
26
  import { resolveStoragePolicy, storageKeys, } from "../storage.js";
27
+ import { isCursorHostedStorage } from "../storage-backends/cursor-hosted.js";
27
28
  import { describeError } from "./describe-error.js";
28
29
  import { isReminderRecord } from "./reminder-store.js";
29
30
  /** Event types that close a unit of work — flush point for turn-end batching. */
@@ -190,6 +191,13 @@ export class StorageCoordinator {
190
191
  get canBulkRestore() {
191
192
  return this.definition.list !== undefined;
192
193
  }
194
+ /**
195
+ * True when the authored sink is `cursorHostedStorage` (Bugbot via the
196
+ * control-plane proxy). `GET /v1/sessions` prefers this durable list.
197
+ */
198
+ get isCursorHosted() {
199
+ return isCursorHostedStorage(this.definition);
200
+ }
193
201
  /**
194
202
  * Saved session records for this agent (startup restore). Errors are
195
203
  * logged and read as "nothing saved" — a broken store must never block
@@ -203,6 +211,28 @@ export class StorageCoordinator {
203
211
  .filter((record) => record != null);
204
212
  });
205
213
  }
214
+ /**
215
+ * Session records from the sink for the sessions API. Unlike
216
+ * {@link listSessions}, missing `list` or a thrown sink error **propagates**
217
+ * so the caller can fall back to the local session store.
218
+ */
219
+ listSessionsFromSink() {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ const list = this.definition.list;
222
+ if (list === undefined) {
223
+ throw new Error("storage sink has no list");
224
+ }
225
+ const entries = yield list(storageKeys.sessionPrefix(this.agentName), this.context("restore"));
226
+ if (!Array.isArray(entries)) {
227
+ throw new Error("storage list returned a non-array");
228
+ }
229
+ return entries
230
+ .map((entry) => entry.value)
231
+ .filter((record) => record != null &&
232
+ typeof record.sessionId === "string" &&
233
+ record.sessionId !== "");
234
+ });
235
+ }
206
236
  /**
207
237
  * Saved event stream for one session: chunk values concatenated in key
208
238
  * order (chunks are keyed by their first event's index, zero-padded, so
@@ -38,6 +38,25 @@ export declare function withIdentityPreamble(name: string, instructions: string
38
38
  export declare function buildAgentToolsCatalog(tools: DiscoveredTool[], options?: {
39
39
  includeScripts: boolean;
40
40
  }): string;
41
+ /**
42
+ * The full AGENTS.md-equivalent context for an agent: instructions, identity
43
+ * section, and the agent-side tool catalog. Written to the session workspace
44
+ * as `AGENTS.md`, and inlined into the first turn's prompt when the harness
45
+ * cannot discover that file (cloud runtime, or a local workspace the harness
46
+ * will not treat as the project root — see {@link isNestedInGitRepo}).
47
+ */
48
+ export declare function buildAgentsMdContent(agent: ResolvedAgent, options: {
49
+ includeScripts: boolean;
50
+ }): string;
51
+ /**
52
+ * True when `dir` sits strictly inside a git repository (a `.git` exists in
53
+ * an ancestor directory but not in `dir` itself). The Cursor harness resolves
54
+ * its project root by walking up to the nearest git root, so a nested session
55
+ * workspace loses its own `AGENTS.md` / `.cursor` scaffold: the enclosing
56
+ * repo's rules load instead, and the (necessarily gitignored) workspace files
57
+ * are skipped by nested rule discovery.
58
+ */
59
+ export declare function isNestedInGitRepo(dir: string): Promise<boolean>;
41
60
  export declare function materializeWorkspace(options: MaterializeWorkspaceOptions): Promise<void>;
42
61
  /**
43
62
  * Generate the SKILL.md the harness reads: `name` + `description`
@@ -1 +1 @@
1
- {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/internal/workspace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,aAAa,EACd,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,aAAa,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,IAAI,EAAE,OAAO,CAAC;CACf;AAED,+EAA+E;AAC/E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,MAAM,GAAG,SAAS,CAapB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,GAAE;IAAE,cAAc,EAAE,OAAO,CAAA;CAA8B,GAC/D,MAAM,CA6CR;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,IAAI,CAAC,CAqCf;AAmDD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAO3D;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,IAAI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AM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,IAAI,CAAC,CAMf"}
@@ -16,7 +16,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
16
16
  });
17
17
  };
18
18
  import { chmod, copyFile, mkdir, stat, writeFile } from "node:fs/promises";
19
- import { dirname, join, relative, resolve } from "node:path";
19
+ import { dirname, join, parse, relative, resolve } from "node:path";
20
20
  import { parseFrontmatter, serializeFrontmatter } from "./frontmatter.js";
21
21
  import { buildIdentitySection } from "./prompt-context.js";
22
22
  /** Relative path of an agent-side tool script inside the session workspace. */
@@ -103,22 +103,56 @@ export function buildAgentToolsCatalog(tools, options = { includeScripts: false
103
103
  }
104
104
  return `${parts.join("\n").trimEnd()}\n`;
105
105
  }
106
+ /**
107
+ * The full AGENTS.md-equivalent context for an agent: instructions, identity
108
+ * section, and the agent-side tool catalog. Written to the session workspace
109
+ * as `AGENTS.md`, and inlined into the first turn's prompt when the harness
110
+ * cannot discover that file (cloud runtime, or a local workspace the harness
111
+ * will not treat as the project root — see {@link isNestedInGitRepo}).
112
+ */
113
+ export function buildAgentsMdContent(agent, options) {
114
+ var _a;
115
+ var _b;
116
+ return [
117
+ (_b = (_a = agent.instructions) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "",
118
+ buildIdentitySection(agent),
119
+ buildAgentToolsCatalog(agent.tools, {
120
+ includeScripts: options.includeScripts,
121
+ }),
122
+ ]
123
+ .filter((part) => part !== "")
124
+ .join("\n\n");
125
+ }
126
+ /**
127
+ * True when `dir` sits strictly inside a git repository (a `.git` exists in
128
+ * an ancestor directory but not in `dir` itself). The Cursor harness resolves
129
+ * its project root by walking up to the nearest git root, so a nested session
130
+ * workspace loses its own `AGENTS.md` / `.cursor` scaffold: the enclosing
131
+ * repo's rules load instead, and the (necessarily gitignored) workspace files
132
+ * are skipped by nested rule discovery.
133
+ */
134
+ export function isNestedInGitRepo(dir) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ let current = resolve(dir);
137
+ if (yield exists(join(current, ".git"))) {
138
+ // The workspace is itself a repo root; the harness roots rules here.
139
+ return false;
140
+ }
141
+ const { root } = parse(current);
142
+ while (current !== root) {
143
+ current = dirname(current);
144
+ if (yield exists(join(current, ".git"))) {
145
+ return true;
146
+ }
147
+ }
148
+ return false;
149
+ });
150
+ }
106
151
  export function materializeWorkspace(options) {
107
152
  return __awaiter(this, void 0, void 0, function* () {
108
- var _a;
109
- var _b;
110
153
  const { agent, workspaceDir, seed } = options;
111
154
  yield mkdir(workspaceDir, { recursive: true });
112
- const agentToolsSection = buildAgentToolsCatalog(agent.tools, {
113
- includeScripts: false,
114
- });
115
- const agentsMd = [
116
- (_b = (_a = agent.instructions) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "",
117
- buildIdentitySection(agent),
118
- agentToolsSection,
119
- ]
120
- .filter((part) => part !== "")
121
- .join("\n\n");
155
+ const agentsMd = buildAgentsMdContent(agent, { includeScripts: false });
122
156
  yield writeFile(join(workspaceDir, "AGENTS.md"), agentsMd, "utf8");
123
157
  for (const tool of agent.tools) {
124
158
  if (tool.execution !== "agent" || tool.script === undefined) {