@neta-art/cohub-cli 10.24.0 → 10.25.0
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/bin/cohub.js +4 -1
- package/dist/board-gpu/page.js +1566 -71230
- package/dist/bootstrap.js +67 -27
- package/dist/build.json +1 -1
- package/dist/{board-kernel/FilterPipe.js → chunks/Geometry.js} +10447 -10469
- package/dist/chunks/about.js +102 -0
- package/dist/chunks/app-realtime.js +2216 -0
- package/dist/chunks/app-realtime2.js +2 -0
- package/dist/chunks/app-ref.js +88 -0
- package/dist/chunks/apps.js +1423 -0
- package/dist/chunks/auth.js +175 -0
- package/dist/chunks/avatar.js +146 -0
- package/dist/chunks/board-export-resources.js +232 -0
- package/dist/chunks/board-export.js +874 -0
- package/dist/chunks/board-export2.js +2 -0
- package/dist/{board-kernel.js → chunks/board-kernel.js} +18032 -28512
- package/dist/chunks/board-kernel2.js +4 -0
- package/dist/chunks/board-profile.js +69 -0
- package/dist/chunks/board-simulate.js +315 -0
- package/dist/chunks/board-time.js +34 -0
- package/dist/chunks/boards.js +1943 -0
- package/dist/{board-kernel → chunks}/browserAll.js +9 -8
- package/dist/chunks/channels.js +64 -0
- package/dist/chunks/client.js +12606 -0
- package/dist/chunks/command-input.js +17 -0
- package/dist/chunks/commander.js +2962 -0
- package/dist/chunks/cron-jobs.js +163 -0
- package/dist/chunks/daemon.js +545 -0
- package/dist/chunks/daemon2.js +2 -0
- package/dist/chunks/desktop.js +172 -0
- package/dist/chunks/endpoint-options.js +26 -0
- package/dist/chunks/env-proxy.js +35 -0
- package/dist/chunks/environment.js +154 -0
- package/dist/chunks/feedback.js +120 -0
- package/dist/chunks/generations.js +379 -0
- package/dist/chunks/host.js +9 -0
- package/dist/chunks/http-put.js +131 -0
- package/dist/chunks/id.js +2416 -0
- package/dist/{board-kernel → chunks}/init.js +1 -1
- package/dist/chunks/install.js +11959 -0
- package/dist/chunks/launch.js +374 -0
- package/dist/chunks/local-media.js +47 -0
- package/dist/chunks/me.js +134 -0
- package/dist/chunks/media.js +315 -0
- package/dist/chunks/models.js +242 -0
- package/dist/chunks/operands.js +46 -0
- package/dist/chunks/package-paths.js +13 -0
- package/dist/chunks/policy.js +221 -0
- package/dist/chunks/preferences.js +29 -0
- package/dist/chunks/profile.js +64 -0
- package/dist/chunks/prompts.js +41 -0
- package/dist/chunks/public.js +2 -0
- package/dist/chunks/public2.js +244 -0
- package/dist/chunks/references.js +197 -0
- package/dist/chunks/referrals.js +90 -0
- package/dist/chunks/rolldown-runtime.js +26 -0
- package/dist/chunks/rooms-connect.js +2 -0
- package/dist/chunks/rooms-connect2.js +151 -0
- package/dist/chunks/rooms-rtc.js +309 -0
- package/dist/chunks/rooms.js +211 -0
- package/dist/chunks/run.js +220 -0
- package/dist/chunks/runtime.js +638 -0
- package/dist/chunks/runtime2.js +286 -0
- package/dist/chunks/runtimes.js +48 -0
- package/dist/chunks/safe-remote-image.js +198 -0
- package/dist/chunks/schemas.js +6017 -0
- package/dist/chunks/search.js +113 -0
- package/dist/chunks/self-update.js +238 -0
- package/dist/chunks/serve.js +1246 -0
- package/dist/chunks/session-status.js +24 -0
- package/dist/chunks/skills.js +35 -0
- package/dist/chunks/spaces.js +5080 -0
- package/dist/chunks/src.js +405 -0
- package/dist/chunks/supervisor.js +2511 -0
- package/dist/chunks/supervisor2.js +2 -0
- package/dist/chunks/tasks.js +82 -0
- package/dist/chunks/themes.js +2898 -0
- package/dist/chunks/version.js +2 -0
- package/dist/chunks/version2.js +22 -0
- package/dist/chunks/version3.js +18 -0
- package/dist/chunks/web.js +7 -0
- package/dist/{board-kernel → chunks}/webworkerAll.js +1 -1
- package/dist/runtime/native/pi-extension.js +174 -166
- package/dist/runtime/worker.js +27 -16
- package/package.json +8 -9
- package/dist/about.d.ts +0 -2
- package/dist/about.js +0 -71
- package/dist/app-download.d.ts +0 -11
- package/dist/app-download.js +0 -252
- package/dist/app-ref.d.ts +0 -5
- package/dist/app-ref.js +0 -8
- package/dist/app-target.d.ts +0 -26
- package/dist/app-target.js +0 -55
- package/dist/auth.d.ts +0 -45
- package/dist/auth.js +0 -307
- package/dist/avatar.d.ts +0 -55
- package/dist/avatar.js +0 -104
- package/dist/board-command-support.d.ts +0 -6
- package/dist/board-command-support.js +0 -88
- package/dist/board-export-resources.d.ts +0 -12
- package/dist/board-export-resources.js +0 -51
- package/dist/board-export.d.ts +0 -110
- package/dist/board-export.js +0 -592
- package/dist/board-fonts.d.ts +0 -11
- package/dist/board-fonts.js +0 -10
- package/dist/board-gpu/daemon.d.ts +0 -11
- package/dist/board-gpu/daemon.js +0 -295
- package/dist/board-gpu/index.d.ts +0 -33
- package/dist/board-gpu/index.js +0 -189
- package/dist/board-gpu/protocol.d.ts +0 -77
- package/dist/board-gpu/protocol.js +0 -1
- package/dist/board-kernel.d.ts +0 -5
- package/dist/board-media-export.d.ts +0 -17
- package/dist/board-media-export.js +0 -164
- package/dist/board-media.d.ts +0 -5
- package/dist/board-media.js +0 -66
- package/dist/board-profile.d.ts +0 -21
- package/dist/board-profile.js +0 -67
- package/dist/board-simulate.d.ts +0 -67
- package/dist/board-simulate.js +0 -259
- package/dist/board-time.d.ts +0 -3
- package/dist/board-time.js +0 -34
- package/dist/bootstrap.d.ts +0 -2
- package/dist/client.d.ts +0 -5
- package/dist/client.js +0 -24
- package/dist/command-input.d.ts +0 -4
- package/dist/command-input.js +0 -16
- package/dist/commands/app-commerce.d.ts +0 -2
- package/dist/commands/app-commerce.js +0 -228
- package/dist/commands/app-domains.d.ts +0 -2
- package/dist/commands/app-domains.js +0 -133
- package/dist/commands/apps.d.ts +0 -4
- package/dist/commands/apps.js +0 -827
- package/dist/commands/auth.d.ts +0 -2
- package/dist/commands/auth.js +0 -186
- package/dist/commands/boards/authoring.d.ts +0 -2
- package/dist/commands/boards/authoring.js +0 -166
- package/dist/commands/boards/examples.d.ts +0 -10
- package/dist/commands/boards/examples.js +0 -118
- package/dist/commands/boards.d.ts +0 -13
- package/dist/commands/boards.js +0 -836
- package/dist/commands/channels.d.ts +0 -2
- package/dist/commands/channels.js +0 -74
- package/dist/commands/cron-jobs.d.ts +0 -2
- package/dist/commands/cron-jobs.js +0 -155
- package/dist/commands/decision.d.ts +0 -4
- package/dist/commands/decision.js +0 -113
- package/dist/commands/desktop.d.ts +0 -10
- package/dist/commands/desktop.js +0 -233
- package/dist/commands/feedback.d.ts +0 -2
- package/dist/commands/feedback.js +0 -131
- package/dist/commands/generations.d.ts +0 -2
- package/dist/commands/generations.js +0 -427
- package/dist/commands/host.d.ts +0 -2
- package/dist/commands/host.js +0 -11
- package/dist/commands/me.d.ts +0 -2
- package/dist/commands/me.js +0 -121
- package/dist/commands/models.d.ts +0 -28
- package/dist/commands/models.js +0 -271
- package/dist/commands/profile.d.ts +0 -2
- package/dist/commands/profile.js +0 -81
- package/dist/commands/prompts.d.ts +0 -2
- package/dist/commands/prompts.js +0 -37
- package/dist/commands/public.d.ts +0 -20
- package/dist/commands/public.js +0 -291
- package/dist/commands/references.d.ts +0 -2
- package/dist/commands/references.js +0 -193
- package/dist/commands/referrals.d.ts +0 -2
- package/dist/commands/referrals.js +0 -88
- package/dist/commands/rooms-connect.d.ts +0 -17
- package/dist/commands/rooms-connect.js +0 -140
- package/dist/commands/rooms-rtc-binary.d.ts +0 -2
- package/dist/commands/rooms-rtc-binary.js +0 -107
- package/dist/commands/rooms-rtc.d.ts +0 -21
- package/dist/commands/rooms-rtc.js +0 -171
- package/dist/commands/rooms.d.ts +0 -3
- package/dist/commands/rooms.js +0 -277
- package/dist/commands/run.d.ts +0 -13
- package/dist/commands/run.js +0 -246
- package/dist/commands/runtime.d.ts +0 -3
- package/dist/commands/runtime.js +0 -320
- package/dist/commands/sandboxd-binary.d.ts +0 -11
- package/dist/commands/sandboxd-binary.js +0 -238
- package/dist/commands/search.d.ts +0 -2
- package/dist/commands/search.js +0 -114
- package/dist/commands/session-access.d.ts +0 -2
- package/dist/commands/session-access.js +0 -70
- package/dist/commands/skills.d.ts +0 -2
- package/dist/commands/skills.js +0 -34
- package/dist/commands/space-activity.d.ts +0 -26
- package/dist/commands/space-activity.js +0 -147
- package/dist/commands/space-commerce.d.ts +0 -2
- package/dist/commands/space-commerce.js +0 -514
- package/dist/commands/space-displays.d.ts +0 -2
- package/dist/commands/space-displays.js +0 -620
- package/dist/commands/space-files.d.ts +0 -5
- package/dist/commands/space-files.js +0 -215
- package/dist/commands/space-invitations.d.ts +0 -29
- package/dist/commands/space-invitations.js +0 -189
- package/dist/commands/space-turns.d.ts +0 -49
- package/dist/commands/space-turns.js +0 -205
- package/dist/commands/space-wallet.d.ts +0 -2
- package/dist/commands/space-wallet.js +0 -141
- package/dist/commands/space-webhooks.d.ts +0 -7
- package/dist/commands/space-webhooks.js +0 -73
- package/dist/commands/spaces.d.ts +0 -25
- package/dist/commands/spaces.js +0 -2170
- package/dist/commands/tasks.d.ts +0 -8
- package/dist/commands/tasks.js +0 -80
- package/dist/commands/version.d.ts +0 -2
- package/dist/commands/version.js +0 -21
- package/dist/endpoint-options.d.ts +0 -4
- package/dist/endpoint-options.js +0 -26
- package/dist/env-proxy.d.ts +0 -5
- package/dist/env-proxy.js +0 -20
- package/dist/help-path.d.ts +0 -18
- package/dist/help-path.js +0 -223
- package/dist/host/auth.d.ts +0 -20
- package/dist/host/auth.js +0 -119
- package/dist/host/login-env.d.ts +0 -1
- package/dist/host/login-env.js +0 -31
- package/dist/host/runtime.d.ts +0 -35
- package/dist/host/runtime.js +0 -395
- package/dist/host/runtimes.d.ts +0 -9
- package/dist/host/runtimes.js +0 -42
- package/dist/host/serve.d.ts +0 -2
- package/dist/host/serve.js +0 -117
- package/dist/host/workspaces.d.ts +0 -2
- package/dist/host/workspaces.js +0 -18
- package/dist/http-put.d.ts +0 -25
- package/dist/http-put.js +0 -132
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -129
- package/dist/launcher.d.ts +0 -4
- package/dist/launcher.js +0 -38
- package/dist/local-media.d.ts +0 -2
- package/dist/local-media.js +0 -30
- package/dist/network-error.d.ts +0 -3
- package/dist/network-error.js +0 -22
- package/dist/output.d.ts +0 -46
- package/dist/output.js +0 -244
- package/dist/runtime/archive-store.d.ts +0 -54
- package/dist/runtime/archive-store.js +0 -379
- package/dist/runtime/cli-path.d.ts +0 -5
- package/dist/runtime/cli-path.js +0 -27
- package/dist/runtime/codex-usage.d.ts +0 -7
- package/dist/runtime/codex-usage.js +0 -11
- package/dist/runtime/connection.d.ts +0 -42
- package/dist/runtime/connection.js +0 -789
- package/dist/runtime/diagnostics.d.ts +0 -107
- package/dist/runtime/diagnostics.js +0 -392
- package/dist/runtime/harnesses/chained-projection.d.ts +0 -40
- package/dist/runtime/harnesses/chained-projection.js +0 -95
- package/dist/runtime/harnesses/chained-transcript.d.ts +0 -24
- package/dist/runtime/harnesses/chained-transcript.js +0 -62
- package/dist/runtime/harnesses/claude-approval.d.ts +0 -34
- package/dist/runtime/harnesses/claude-approval.js +0 -124
- package/dist/runtime/harnesses/claude-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/claude-transcript.js +0 -138
- package/dist/runtime/harnesses/claude.d.ts +0 -8
- package/dist/runtime/harnesses/claude.js +0 -225
- package/dist/runtime/harnesses/codex-approval.d.ts +0 -25
- package/dist/runtime/harnesses/codex-approval.js +0 -69
- package/dist/runtime/harnesses/codex.d.ts +0 -4
- package/dist/runtime/harnesses/codex.js +0 -269
- package/dist/runtime/harnesses/cursor-transcript.d.ts +0 -37
- package/dist/runtime/harnesses/cursor-transcript.js +0 -183
- package/dist/runtime/harnesses/cursor.d.ts +0 -24
- package/dist/runtime/harnesses/cursor.js +0 -620
- package/dist/runtime/harnesses/index.d.ts +0 -16
- package/dist/runtime/harnesses/index.js +0 -73
- package/dist/runtime/harnesses/pi.d.ts +0 -4
- package/dist/runtime/harnesses/pi.js +0 -247
- package/dist/runtime/harnesses/process.d.ts +0 -31
- package/dist/runtime/harnesses/process.js +0 -75
- package/dist/runtime/harnesses/stream-json.d.ts +0 -48
- package/dist/runtime/harnesses/stream-json.js +0 -336
- package/dist/runtime/harnesses/types.d.ts +0 -117
- package/dist/runtime/harnesses/types.js +0 -1
- package/dist/runtime/harnesses/workbuddy-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/workbuddy-transcript.js +0 -127
- package/dist/runtime/harnesses/workbuddy.d.ts +0 -21
- package/dist/runtime/harnesses/workbuddy.js +0 -123
- package/dist/runtime/instance.d.ts +0 -20
- package/dist/runtime/instance.js +0 -247
- package/dist/runtime/json-rpc.d.ts +0 -53
- package/dist/runtime/json-rpc.js +0 -212
- package/dist/runtime/launch.d.ts +0 -25
- package/dist/runtime/launch.js +0 -247
- package/dist/runtime/local-workspace.d.ts +0 -15
- package/dist/runtime/local-workspace.js +0 -52
- package/dist/runtime/model-catalog.d.ts +0 -12
- package/dist/runtime/model-catalog.js +0 -84
- package/dist/runtime/native/adapters.d.ts +0 -15
- package/dist/runtime/native/adapters.js +0 -11
- package/dist/runtime/native/approvals.d.ts +0 -18
- package/dist/runtime/native/approvals.js +0 -54
- package/dist/runtime/native/archive.d.ts +0 -19
- package/dist/runtime/native/archive.js +0 -142
- package/dist/runtime/native/attach.d.ts +0 -36
- package/dist/runtime/native/attach.js +0 -128
- package/dist/runtime/native/codex-link.d.ts +0 -60
- package/dist/runtime/native/codex-link.js +0 -322
- package/dist/runtime/native/config.d.ts +0 -16
- package/dist/runtime/native/config.js +0 -24
- package/dist/runtime/native/daemon.d.ts +0 -92
- package/dist/runtime/native/daemon.js +0 -380
- package/dist/runtime/native/execution.d.ts +0 -26
- package/dist/runtime/native/execution.js +0 -34
- package/dist/runtime/native/identity.d.ts +0 -9
- package/dist/runtime/native/identity.js +0 -15
- package/dist/runtime/native/ingest.d.ts +0 -263
- package/dist/runtime/native/ingest.js +0 -884
- package/dist/runtime/native/install.d.ts +0 -9
- package/dist/runtime/native/install.js +0 -113
- package/dist/runtime/native/paths.d.ts +0 -2
- package/dist/runtime/native/paths.js +0 -7
- package/dist/runtime/native/pi-extension.d.ts +0 -36
- package/dist/runtime/native/pi-link.d.ts +0 -69
- package/dist/runtime/native/pi-link.js +0 -269
- package/dist/runtime/native/results.d.ts +0 -41
- package/dist/runtime/native/results.js +0 -128
- package/dist/runtime/native/sessions.d.ts +0 -45
- package/dist/runtime/native/sessions.js +0 -87
- package/dist/runtime/native/transcript.d.ts +0 -89
- package/dist/runtime/native/transcript.js +0 -656
- package/dist/runtime/native/translate.d.ts +0 -46
- package/dist/runtime/native/translate.js +0 -299
- package/dist/runtime/native/transport.d.ts +0 -7
- package/dist/runtime/native/transport.js +0 -16
- package/dist/runtime/native/version.d.ts +0 -5
- package/dist/runtime/native/version.js +0 -21
- package/dist/runtime/preferences.d.ts +0 -7
- package/dist/runtime/preferences.js +0 -22
- package/dist/runtime/presentation.d.ts +0 -32
- package/dist/runtime/presentation.js +0 -124
- package/dist/runtime/process-group.d.ts +0 -5
- package/dist/runtime/process-group.js +0 -161
- package/dist/runtime/projection-store.d.ts +0 -27
- package/dist/runtime/projection-store.js +0 -30
- package/dist/runtime/space-binding.d.ts +0 -48
- package/dist/runtime/space-binding.js +0 -342
- package/dist/runtime/supervisor.d.ts +0 -19
- package/dist/runtime/supervisor.js +0 -441
- package/dist/runtime/turn-projection.d.ts +0 -41
- package/dist/runtime/turn-projection.js +0 -120
- package/dist/runtime/worker.d.ts +0 -1
- package/dist/safe-remote-image.d.ts +0 -36
- package/dist/safe-remote-image.js +0 -191
- package/dist/self-update.d.ts +0 -7
- package/dist/self-update.js +0 -202
- package/dist/session-status.d.ts +0 -10
- package/dist/session-status.js +0 -25
- package/dist/space-files/limit.d.ts +0 -2
- package/dist/space-files/limit.js +0 -16
- package/dist/space-files/operands.d.ts +0 -17
- package/dist/space-files/operands.js +0 -33
- package/dist/space-files/transfer.d.ts +0 -53
- package/dist/space-files/transfer.js +0 -297
- package/dist/space-files/upload.d.ts +0 -17
- package/dist/space-files/upload.js +0 -76
- package/dist/space.d.ts +0 -44
- package/dist/space.js +0 -192
- package/dist/version.d.ts +0 -2
- package/dist/version.js +0 -17
- package/dist/web.d.ts +0 -1
- package/dist/web.js +0 -4
- /package/dist/{board-kernel → chunks}/lexer.js +0 -0
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { APPROVAL_DECISIONS, APPROVAL_MODES } from "@neta-art/cohub";
|
|
2
|
-
import { record } from "../json-rpc.js";
|
|
3
|
-
import { atLeast } from "../native/version.js";
|
|
4
|
-
/** First app-server whose thread and Turn approval overrides Cohub has verified. */
|
|
5
|
-
export const CODEX_APPROVAL_MIN_VERSION = [0, 162, 1];
|
|
6
|
-
export const codexApprovalModes = (version) => atLeast(version, CODEX_APPROVAL_MIN_VERSION) ? [...APPROVAL_MODES] : [];
|
|
7
|
-
/** The platform's read-only access always wins; `null` keeps the legacy behaviour. */
|
|
8
|
-
export function codexApprovalMode(input, version) {
|
|
9
|
-
if (input.accessMode === "read_only" && input.approvalMode && input.approvalMode !== "read_only") {
|
|
10
|
-
throw new Error("The approval mode conflicts with read-only access");
|
|
11
|
-
}
|
|
12
|
-
const mode = input.accessMode === "read_only" ? "read_only" : input.approvalMode;
|
|
13
|
-
if (!mode || codexApprovalModes(version).includes(mode))
|
|
14
|
-
return mode ?? null;
|
|
15
|
-
if (!input.approvalMode)
|
|
16
|
-
return null;
|
|
17
|
-
throw new Error(`Codex approval modes need app-server ${CODEX_APPROVAL_MIN_VERSION.join(".")} or newer; update Codex and restart its app-server`);
|
|
18
|
-
}
|
|
19
|
-
const PRESETS = {
|
|
20
|
-
// Like Codex's own Read Only; Cohub refuses the approvals it would ask for.
|
|
21
|
-
read_only: { sandbox: "read-only", sandboxPolicy: { type: "readOnly", networkAccess: false }, approvalPolicy: "on-request", approvalsReviewer: "user" },
|
|
22
|
-
auto: {
|
|
23
|
-
sandbox: "workspace-write", approvalPolicy: "on-request", approvalsReviewer: "auto_review",
|
|
24
|
-
sandboxPolicy: { type: "workspaceWrite", writableRoots: [], networkAccess: false, excludeTmpdirEnvVar: false, excludeSlashTmp: false },
|
|
25
|
-
},
|
|
26
|
-
full_access: { sandbox: "danger-full-access", sandboxPolicy: { type: "dangerFullAccess" }, approvalPolicy: "never", approvalsReviewer: "user" },
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* `inherit` sends the machine's own settings, so an existing thread drops what an earlier mode set;
|
|
30
|
-
* a new thread starts with them anyway. Only Codex resolves them (profiles, requirements).
|
|
31
|
-
*/
|
|
32
|
-
export async function resolveCodexApproval(mode, codex, cwd, existing) {
|
|
33
|
-
if (mode !== "inherit") {
|
|
34
|
-
const { sandbox, sandboxPolicy, ...approval } = PRESETS[mode];
|
|
35
|
-
return { thread: { sandbox, ...approval }, turn: { sandboxPolicy, ...approval } };
|
|
36
|
-
}
|
|
37
|
-
if (!existing)
|
|
38
|
-
return { thread: {}, turn: {} };
|
|
39
|
-
const probe = await codex.request("thread/start", { cwd, ephemeral: true, config: { "features.hooks": false } });
|
|
40
|
-
const probeId = record(probe.thread).id;
|
|
41
|
-
if (typeof probeId === "string" && probeId)
|
|
42
|
-
await codex.request("thread/unsubscribe", { threadId: probeId }).catch(() => undefined);
|
|
43
|
-
const sandbox = record(probe.sandbox);
|
|
44
|
-
if (probe.approvalPolicy == null || typeof probe.approvalsReviewer !== "string" || !sandbox.type)
|
|
45
|
-
throw new Error("Codex did not report its local approval settings");
|
|
46
|
-
const approval = { approvalPolicy: probe.approvalPolicy, approvalsReviewer: probe.approvalsReviewer };
|
|
47
|
-
const profile = record(probe.activePermissionProfile).id;
|
|
48
|
-
// A named profile carries more than its sandbox policy; built-in ones are exactly it.
|
|
49
|
-
return { thread: {}, turn: typeof profile === "string" && profile && !profile.startsWith(":") ? { ...approval, permissions: profile } : { ...approval, sandboxPolicy: probe.sandbox } };
|
|
50
|
-
}
|
|
51
|
-
const CODEX_DECISIONS = { accept: "accept", accept_for_session: "acceptForSession", decline: "decline" };
|
|
52
|
-
export const codexDecision = (decision) => ({ decision: CODEX_DECISIONS[decision] });
|
|
53
|
-
const clip = (value, max) => typeof value === "string" && value ? value.slice(0, max) : undefined;
|
|
54
|
-
/** A Codex request a person can answer on a card; others are refused as before. */
|
|
55
|
-
export function codexApprovalRequest(method, params, paths) {
|
|
56
|
-
if (method !== "item/commandExecution/requestApproval" && method !== "item/fileChange/requestApproval")
|
|
57
|
-
return null;
|
|
58
|
-
// Codex may leave `decline` out of its list but accepts it; a card can always say no.
|
|
59
|
-
const offered = Array.isArray(params.availableDecisions) ? params.availableDecisions : null;
|
|
60
|
-
const decisions = APPROVAL_DECISIONS.filter((decision) => decision === "decline" || !offered || offered.includes(CODEX_DECISIONS[decision]));
|
|
61
|
-
const reason = clip(params.reason, 4096);
|
|
62
|
-
if (method === "item/fileChange/requestApproval") {
|
|
63
|
-
const changed = [...paths ?? [], ...typeof params.grantRoot === "string" ? [params.grantRoot] : []].slice(0, 100).map((path) => path.slice(0, 4096));
|
|
64
|
-
return { kind: "file_change", decisions, ...(reason ? { reason } : {}), ...(changed.length ? { paths: changed } : {}) };
|
|
65
|
-
}
|
|
66
|
-
const command = clip(params.command, 16_384);
|
|
67
|
-
const cwd = clip(params.cwd, 4096);
|
|
68
|
-
return { kind: "command", decisions, ...(command ? { command } : {}), ...(cwd ? { cwd } : {}), ...(reason ? { reason } : {}) };
|
|
69
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { LocalHarnessAdapter, ThreadKind } from "./types.js";
|
|
2
|
-
/** Codex's first line is the only place a thread's purpose is recorded. */
|
|
3
|
-
export declare function codexThreadKind(payload: Record<string, unknown>): ThreadKind;
|
|
4
|
-
export declare const codexHarness: LocalHarnessAdapter;
|
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import { homedir } from "node:os";
|
|
2
|
-
import { basename, join } from "node:path";
|
|
3
|
-
import { projectNativeSession } from "@neta-art/cohub";
|
|
4
|
-
import { JsonRpcProcess, record } from "../json-rpc.js";
|
|
5
|
-
import { codexModelCatalog } from "../model-catalog.js";
|
|
6
|
-
import { describeError } from "../../network-error.js";
|
|
7
|
-
import { CODEX_UNLOAD_DELAY_SECS, openPrivateServer, resumeThread, runningSharedVersion } from "../native/codex-link.js";
|
|
8
|
-
import { ArchiveNotRestorableError, copyNativeArchive } from "../native/archive.js";
|
|
9
|
-
import { codexArchivedSessionsDirectory, codexRolloutBytes, codexRolloutIdOf, codexSessionsDirectory, ensurePlainCodexRollout, readFirstRecord, readNativeTranscript, } from "../native/transcript.js";
|
|
10
|
-
import { codexTranslator } from "../native/translate.js";
|
|
11
|
-
import { atLeast, harnessVersion } from "../native/version.js";
|
|
12
|
-
import { codexApprovalMode, codexApprovalModes, codexApprovalRequest, codexDecision, resolveCodexApproval } from "./codex-approval.js";
|
|
13
|
-
import { array, closeHost, harnessCommand, inlineImage, text, turnEnvironment, watchHost } from "./process.js";
|
|
14
|
-
/** A stop request that the harness does not honour within this long ends its private process. */
|
|
15
|
-
const ABORT_ESCALATION_MS = 5_000;
|
|
16
|
-
function codexSessionPath(nativeSessionId) {
|
|
17
|
-
const home = process.env.CODEX_HOME?.trim() || join(homedir(), ".codex");
|
|
18
|
-
const day = new Date().toISOString().replace(/\.\d{3}Z$/, "").replaceAll(":", "-");
|
|
19
|
-
return join(home, "sessions", day.slice(0, 4), day.slice(5, 7), day.slice(8, 10), `rollout-${day}-${nativeSessionId}.jsonl`);
|
|
20
|
-
}
|
|
21
|
-
async function initializeCodex(rpc) {
|
|
22
|
-
await rpc.request("initialize", { clientInfo: { name: "cohub", title: "Cohub", version: "1" }, capabilities: { experimentalApi: true } });
|
|
23
|
-
rpc.write({ method: "initialized", params: {} });
|
|
24
|
-
}
|
|
25
|
-
/** Codex's first line is the only place a thread's purpose is recorded. */
|
|
26
|
-
export function codexThreadKind(payload) {
|
|
27
|
-
const source = payload.source;
|
|
28
|
-
if (source && typeof source === "object")
|
|
29
|
-
return record(record(source).subagent).thread_spawn ? "spawned" : "internal";
|
|
30
|
-
return ["subagent", "guardian_review", "memory_consolidation"].includes(text(payload.thread_source)) ? "internal" : "user";
|
|
31
|
-
}
|
|
32
|
-
async function runCodex(executor, turn) {
|
|
33
|
-
const { input, signal, context } = turn;
|
|
34
|
-
const shared = await executor.codex.get();
|
|
35
|
-
const prepared = await executor.sessions.prepare({
|
|
36
|
-
sessionId: input.sessionId, turnId: input.turnId, harness: "codex", cwd: executor.cwd,
|
|
37
|
-
provider: input.provider, context: input.context, signal,
|
|
38
|
-
// Only the shared server coordinates with terminal clients; a private one never opens their files.
|
|
39
|
-
resumable: (transcript) => transcript.path !== turn.diverged && (transcript.origin === "cohub" || shared !== null),
|
|
40
|
-
});
|
|
41
|
-
let session = prepared.session;
|
|
42
|
-
let host = null;
|
|
43
|
-
let channel = shared;
|
|
44
|
-
let message = { ordinal: 0, content: [] };
|
|
45
|
-
let begun = false;
|
|
46
|
-
let joined = null;
|
|
47
|
-
try {
|
|
48
|
-
if (!channel) {
|
|
49
|
-
host = new JsonRpcProcess(...harnessCommand(executor.executables.codex || "codex", ["app-server", "--listen", "stdio://"], executor.cwd), executor.cwd, "jsonrpc", turnEnvironment(input));
|
|
50
|
-
watchHost(host, executor.diagnostics, context);
|
|
51
|
-
channel = await openPrivateServer(host);
|
|
52
|
-
}
|
|
53
|
-
const codex = channel;
|
|
54
|
-
const mode = codexApprovalMode(input, codex.version);
|
|
55
|
-
const approval = mode ? await resolveCodexApproval(mode, codex, executor.cwd, prepared.resume !== "new") : null;
|
|
56
|
-
const threadOptions = {
|
|
57
|
-
cwd: executor.cwd,
|
|
58
|
-
...(input.model ? { model: input.model } : {}),
|
|
59
|
-
...(input.provider && input.provider !== "codex" ? { modelProvider: input.provider } : {}),
|
|
60
|
-
...(approval ? approval.thread : input.accessMode === "read_only" ? { sandbox: "read-only" } : {}),
|
|
61
|
-
// Tools of a shared server otherwise see the environment of whoever started that server.
|
|
62
|
-
config: {
|
|
63
|
-
"shell_environment_policy.set.COHUB_SPACE_ID": input.spaceId, "shell_environment_policy.set.COHUB_SESSION_ID": input.sessionId,
|
|
64
|
-
...(codex.shared ? { thread_unload_delay_secs: CODEX_UNLOAD_DELAY_SECS } : {}),
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
const existing = { ...threadOptions, threadId: session.nativeSessionId, path: session.path, excludeTurns: true };
|
|
68
|
-
const opened = prepared.resume === "new" ? await codex.request("thread/start", threadOptions)
|
|
69
|
-
: prepared.resume === "restored" ? await codex.request("thread/fork", existing)
|
|
70
|
-
: await resumeThread(codex, existing);
|
|
71
|
-
const thread = record(opened.thread);
|
|
72
|
-
joined = text(thread.id) || null;
|
|
73
|
-
if (typeof thread.id !== "string" || typeof thread.path !== "string")
|
|
74
|
-
throw new Error("Codex did not provide a durable native thread");
|
|
75
|
-
const threadId = thread.id;
|
|
76
|
-
if (thread.path !== session.path || threadId !== session.nativeSessionId) {
|
|
77
|
-
session = { ...session, nativeSessionId: threadId, path: thread.path };
|
|
78
|
-
executor.ingest.adopt(session, input.sessionId);
|
|
79
|
-
}
|
|
80
|
-
const translator = codexTranslator(turn.emit, { provider: text(opened.modelProvider) || "codex", model: text(opened.model) || input.model || null });
|
|
81
|
-
const content = await codexPrompt(input);
|
|
82
|
-
signal.throwIfAborted();
|
|
83
|
-
await turn.started(session);
|
|
84
|
-
begun = true;
|
|
85
|
-
let nativeTurnId = null;
|
|
86
|
-
const changedPaths = new Map();
|
|
87
|
-
executor.codex.driving.add(threadId);
|
|
88
|
-
await new Promise((resolve, reject) => {
|
|
89
|
-
let escalation;
|
|
90
|
-
let done = false;
|
|
91
|
-
const finish = (error) => {
|
|
92
|
-
if (done)
|
|
93
|
-
return;
|
|
94
|
-
done = true;
|
|
95
|
-
off();
|
|
96
|
-
offClose();
|
|
97
|
-
signal.removeEventListener("abort", abort);
|
|
98
|
-
clearTimeout(escalation);
|
|
99
|
-
if (error)
|
|
100
|
-
reject(error);
|
|
101
|
-
else
|
|
102
|
-
resolve();
|
|
103
|
-
};
|
|
104
|
-
const interrupt = () => { if (nativeTurnId)
|
|
105
|
-
void codex.request("turn/interrupt", { threadId, turnId: nativeTurnId }).catch(() => undefined); };
|
|
106
|
-
const off = codex.onEvent((event) => {
|
|
107
|
-
const params = event.params;
|
|
108
|
-
if (event.id != null) {
|
|
109
|
-
// A terminal user's requests on the shared server are theirs to answer.
|
|
110
|
-
if (codex.shared && (params.threadId !== threadId || nativeTurnId && params.turnId !== nativeTurnId))
|
|
111
|
-
return;
|
|
112
|
-
const request = codexApprovalRequest(event.method, params, changedPaths.get(text(params.itemId)));
|
|
113
|
-
// A platform read-only Turn is never widened, whoever approves.
|
|
114
|
-
if (!request || input.accessMode === "read_only" || !executor.approvals.available) {
|
|
115
|
-
codex.refuse(event.id, "Approval requires an interactive local client");
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const requestId = event.id;
|
|
119
|
-
void executor.approvals.request(input.sessionId, input.turnId, request, signal).then((decision) => codex.respond(requestId, codexDecision(decision)));
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (params.threadId !== threadId)
|
|
123
|
-
return;
|
|
124
|
-
const item = record(params.item);
|
|
125
|
-
if (item.type === "fileChange" && Array.isArray(item.changes))
|
|
126
|
-
changedPaths.set(text(item.id), item.changes.map((change) => text(record(change).path)).filter(Boolean));
|
|
127
|
-
// A resumed thread replays its last usage; only this Turn's counts belong to it.
|
|
128
|
-
if (event.method === "thread/tokenUsage/updated" && params.turnId !== nativeTurnId)
|
|
129
|
-
return;
|
|
130
|
-
if (event.method === "turn/started" && !nativeTurnId) {
|
|
131
|
-
nativeTurnId = text(record(params.turn).id) || null;
|
|
132
|
-
if (signal.aborted)
|
|
133
|
-
interrupt();
|
|
134
|
-
}
|
|
135
|
-
if (event.method === "turn/completed" && nativeTurnId && text(record(params.turn).id) !== nativeTurnId)
|
|
136
|
-
return;
|
|
137
|
-
try {
|
|
138
|
-
if (translator.push(event))
|
|
139
|
-
finish();
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
finish(error);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
const offClose = codex.onClose((error) => finish(error));
|
|
146
|
-
const abort = () => {
|
|
147
|
-
interrupt();
|
|
148
|
-
if (host)
|
|
149
|
-
escalation = setTimeout(() => void host?.close().catch(() => undefined), ABORT_ESCALATION_MS);
|
|
150
|
-
};
|
|
151
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
152
|
-
codex.request("turn/start", {
|
|
153
|
-
threadId, clientUserMessageId: input.turnId, input: content,
|
|
154
|
-
// A loaded thread ignores open-time overrides and keeps these for later Turns.
|
|
155
|
-
...approval?.turn,
|
|
156
|
-
...(input.thinkingLevel ? { effort: input.thinkingLevel === "off" ? "none" : input.thinkingLevel } : {}),
|
|
157
|
-
// Only this Turn: the thread's own tier, and so a terminal user's, stays as it was.
|
|
158
|
-
...(input.serviceTier ? { serviceTierForTurn: input.serviceTier } : {}),
|
|
159
|
-
})
|
|
160
|
-
.then((result) => { nativeTurnId ??= text(record(result.turn).id) || null; if (signal.aborted)
|
|
161
|
-
interrupt(); })
|
|
162
|
-
.catch(finish);
|
|
163
|
-
}).finally(() => executor.codex.driving.delete(threadId));
|
|
164
|
-
message = translator.last();
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
if (!begun) {
|
|
168
|
-
if (host)
|
|
169
|
-
await closeHost(host, null).catch(() => undefined);
|
|
170
|
-
throw error;
|
|
171
|
-
}
|
|
172
|
-
message = { ...message, stopReason: signal.aborted ? "aborted" : "error", errorMessage: signal.aborted ? null : describeError(error) };
|
|
173
|
-
}
|
|
174
|
-
finally {
|
|
175
|
-
if (joined && channel?.shared)
|
|
176
|
-
await executor.codex.release(joined);
|
|
177
|
-
}
|
|
178
|
-
return { session, resume: prepared.resume, message, host };
|
|
179
|
-
}
|
|
180
|
-
async function codexPrompt(input) {
|
|
181
|
-
return await Promise.all(input.messages.flatMap((message) => message.content).map(async (block) => {
|
|
182
|
-
if (block.type === "image") {
|
|
183
|
-
const image = await inlineImage(block);
|
|
184
|
-
return { type: "image", url: `data:${image.mimeType};base64,${image.data}` };
|
|
185
|
-
}
|
|
186
|
-
return { type: "text", text: block.type === "text" ? block.text : JSON.stringify(block), text_elements: [] };
|
|
187
|
-
}));
|
|
188
|
-
}
|
|
189
|
-
export const codexHarness = {
|
|
190
|
-
id: "codex",
|
|
191
|
-
binary: "codex",
|
|
192
|
-
async models(executable, cwd) {
|
|
193
|
-
const rpc = new JsonRpcProcess(...harnessCommand(executable, ["app-server", "--listen", "stdio://"], cwd), cwd, "jsonrpc");
|
|
194
|
-
try {
|
|
195
|
-
await initializeCodex(rpc);
|
|
196
|
-
const config = await rpc.request("config/read", { includeLayers: false, cwd });
|
|
197
|
-
const entries = [];
|
|
198
|
-
const cursors = new Set();
|
|
199
|
-
let cursor = null;
|
|
200
|
-
do {
|
|
201
|
-
const result = await rpc.request("model/list", { cursor, limit: 100 });
|
|
202
|
-
entries.push(...array(result.data));
|
|
203
|
-
cursor = typeof result.nextCursor === "string" ? result.nextCursor : null;
|
|
204
|
-
if (entries.length > 2000 || cursor && cursors.has(cursor))
|
|
205
|
-
throw new Error("Invalid model catalog pagination");
|
|
206
|
-
if (cursor)
|
|
207
|
-
cursors.add(cursor);
|
|
208
|
-
} while (cursor);
|
|
209
|
-
return codexModelCatalog(config, entries);
|
|
210
|
-
}
|
|
211
|
-
finally {
|
|
212
|
-
await rpc.close();
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
async approvalModes(executable) {
|
|
216
|
-
const [binary, running] = await Promise.all([harnessVersion(executable), runningSharedVersion()]);
|
|
217
|
-
// A failed probe keeps the previous modes; Turns still check the server they run on.
|
|
218
|
-
if (!binary)
|
|
219
|
-
throw new Error("Codex did not report its version");
|
|
220
|
-
// Turns use the binary or, when sharing, a server already running: offer only what both support.
|
|
221
|
-
return codexApprovalModes(running && !atLeast(running, binary) ? running : binary);
|
|
222
|
-
},
|
|
223
|
-
run: runCodex,
|
|
224
|
-
session: {
|
|
225
|
-
path: (nativeSessionId) => codexSessionPath(nativeSessionId),
|
|
226
|
-
startsWithoutFile: true,
|
|
227
|
-
project: (input) => projectNativeSession(input, "codex"),
|
|
228
|
-
rebind: (records, nativeSessionId) => records.map((entry) => entry.sourceTurnId === null && entry.record.type === "session_meta"
|
|
229
|
-
? { ...entry, record: { ...entry.record, payload: { ...record(entry.record.payload), id: nativeSessionId, session_id: nativeSessionId } } }
|
|
230
|
-
: entry),
|
|
231
|
-
archive: {
|
|
232
|
-
target: ({ id }) => codexSessionPath(id),
|
|
233
|
-
async import(input) {
|
|
234
|
-
const { checksum } = await copyNativeArchive({
|
|
235
|
-
...input,
|
|
236
|
-
header: (header) => {
|
|
237
|
-
const payload = record(header.payload);
|
|
238
|
-
if (header.type !== "session_meta" || payload.id !== input.nativeSessionId)
|
|
239
|
-
throw new Error("Codex archive identity mismatch");
|
|
240
|
-
// A leaf archive does not carry its ancestor rollout.
|
|
241
|
-
if (payload.history_base != null)
|
|
242
|
-
throw new ArchiveNotRestorableError("Codex archive references history it does not carry; rebuild from the Session instead");
|
|
243
|
-
return { ...header, payload: { ...payload, id: input.id, ...(payload.session_id != null ? { session_id: input.id } : {}), history_mode: "legacy", cwd: input.cwd } };
|
|
244
|
-
},
|
|
245
|
-
});
|
|
246
|
-
return { checksum, nativeSessionId: input.id };
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
},
|
|
250
|
-
transcript: {
|
|
251
|
-
roots: () => [codexSessionsDirectory(), codexArchivedSessionsDirectory()],
|
|
252
|
-
acceptsDirectory: () => true,
|
|
253
|
-
acceptsTranscript: (path) => codexRolloutIdOf(basename(path)) !== null,
|
|
254
|
-
async header(path, signal) {
|
|
255
|
-
const header = await readFirstRecord(codexRolloutBytes(path, null, signal));
|
|
256
|
-
const payload = record(header.payload);
|
|
257
|
-
if (header.type !== "session_meta" || !text(payload.id) || !text(payload.cwd))
|
|
258
|
-
return null;
|
|
259
|
-
return { harness: "codex", nativeSessionId: text(payload.id), cwd: text(payload.cwd), thread: codexThreadKind(payload) };
|
|
260
|
-
},
|
|
261
|
-
read: (path, signal) => readNativeTranscript(path, "codex", { signal }),
|
|
262
|
-
boundaries: ['"UserMessage"', '"user_message"', '"turn_complete"', '"task_complete"', '"turn_aborted"'],
|
|
263
|
-
turnEndRecorded: true,
|
|
264
|
-
userFinalMarked: true,
|
|
265
|
-
globalTurnKeys: true,
|
|
266
|
-
marksCohubTurns: true,
|
|
267
|
-
archiveSource: (path, cacheDirectory) => ensurePlainCodexRollout(path, cacheDirectory),
|
|
268
|
-
},
|
|
269
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { NativeTranscript } from "../native/transcript.js";
|
|
2
|
-
import type { SessionHeader } from "./types.js";
|
|
3
|
-
/** Chats (`store.db` and `meta.json`) live under the config directory, transcripts under the data directory. */
|
|
4
|
-
export declare const cursorConfigDirectory: () => string;
|
|
5
|
-
export declare const cursorProjectsRoot: () => string;
|
|
6
|
-
export declare const cursorChatsRoot: () => string;
|
|
7
|
-
/** Cursor's project name for a workspace path. */
|
|
8
|
-
export declare const cursorProjectName: (cwd: string) => string;
|
|
9
|
-
export declare const cursorTranscriptPath: (nativeSessionId: string, cwd: string) => string;
|
|
10
|
-
/** A chat's store directory is keyed by the MD5 of the directory the CLI ran in. */
|
|
11
|
-
export declare const cursorChatDirectory: (nativeSessionId: string, cwd: string) => string;
|
|
12
|
-
export declare function acceptsCursorDirectory(path: string, root: string, cwd: string): boolean;
|
|
13
|
-
export declare function acceptsCursorTranscript(path: string, cwd: string): boolean;
|
|
14
|
-
/**
|
|
15
|
-
* The directory a project name stands for, matched against real directories. On Windows the name
|
|
16
|
-
* starts with the drive letter and matching ignores case. Several directories with the same name
|
|
17
|
-
* (`a/b` and `a-b`) cannot be told apart, so none is chosen.
|
|
18
|
-
*/
|
|
19
|
-
type Entry = {
|
|
20
|
-
name: string;
|
|
21
|
-
isDirectory(): boolean;
|
|
22
|
-
isSymbolicLink(): boolean;
|
|
23
|
-
};
|
|
24
|
-
export declare function projectDirectory(name: string, platform?: NodeJS.Platform, list?: (directory: string) => Promise<Entry[]>): Promise<string | null>;
|
|
25
|
-
/**
|
|
26
|
-
* The transcript does not name its project. A CLI chat's `meta.json` does; the IDE writes the same
|
|
27
|
-
* transcripts without one, so its project name is resolved to the directory it stands for.
|
|
28
|
-
*/
|
|
29
|
-
export declare function cursorSessionHeader(path: string): Promise<SessionHeader | null>;
|
|
30
|
-
/**
|
|
31
|
-
* Cursor writes the model's messages without ids or times: a prompt (`<user_query>`, or a bare text
|
|
32
|
-
* that no other user line follows), one line per reply step with its tool calls (results are not
|
|
33
|
-
* recorded), and `turn_ended` after every Turn. A user line followed by another is context. A Turn
|
|
34
|
-
* is keyed by the file's checksum through its prompt, so a rewritten history never reuses a key.
|
|
35
|
-
*/
|
|
36
|
-
export declare function readCursorTranscript(path: string, nativeSessionId: string, signal?: AbortSignal): Promise<NativeTranscript>;
|
|
37
|
-
export {};
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { readdirSync } from "node:fs";
|
|
3
|
-
import { readdir, readFile, stat } from "node:fs/promises";
|
|
4
|
-
import { homedir } from "node:os";
|
|
5
|
-
import { basename, dirname, join, posix, relative, resolve, sep, win32 } from "node:path";
|
|
6
|
-
import { record } from "../json-rpc.js";
|
|
7
|
-
import { extendTurn, readChainedLines } from "./chained-transcript.js";
|
|
8
|
-
import { array, missing, text } from "./process.js";
|
|
9
|
-
const TRANSCRIPTS = "agent-transcripts";
|
|
10
|
-
const USER_QUERY = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
|
|
11
|
-
const TIMESTAMP = /<timestamp>([^<]*)<\/timestamp>/;
|
|
12
|
-
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
13
|
-
/** Chats (`store.db` and `meta.json`) live under the config directory, transcripts under the data directory. */
|
|
14
|
-
export const cursorConfigDirectory = () => process.env.CURSOR_CONFIG_DIR?.trim()
|
|
15
|
-
|| (process.env.XDG_CONFIG_HOME?.trim() ? join(process.env.XDG_CONFIG_HOME.trim(), "cursor") : join(homedir(), ".cursor"));
|
|
16
|
-
const dataDirectory = () => process.env.CURSOR_DATA_DIR?.trim() || join(homedir(), ".cursor");
|
|
17
|
-
export const cursorProjectsRoot = () => join(dataDirectory(), "projects");
|
|
18
|
-
export const cursorChatsRoot = () => join(cursorConfigDirectory(), "chats");
|
|
19
|
-
/** Cursor's project name for a workspace path. */
|
|
20
|
-
export const cursorProjectName = (cwd) => cwd.replace(/[^a-zA-Z0-9]/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
|
|
21
|
-
/** Windows reuses a project folder whose name differs only in case, and file events name that folder. */
|
|
22
|
-
function projectFolder(cwd) {
|
|
23
|
-
const name = cursorProjectName(cwd);
|
|
24
|
-
if (process.platform !== "win32")
|
|
25
|
-
return name;
|
|
26
|
-
try {
|
|
27
|
-
return readdirSync(cursorProjectsRoot()).find((entry) => entry.toLowerCase() === name.toLowerCase()) ?? name;
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return name;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export const cursorTranscriptPath = (nativeSessionId, cwd) => join(cursorProjectsRoot(), projectFolder(cwd), TRANSCRIPTS, nativeSessionId, `${nativeSessionId}.jsonl`);
|
|
34
|
-
/** A chat's store directory is keyed by the MD5 of the directory the CLI ran in. */
|
|
35
|
-
export const cursorChatDirectory = (nativeSessionId, cwd) => join(cursorChatsRoot(), createHash("md5").update(resolve(cwd)).digest("hex"), nativeSessionId);
|
|
36
|
-
/** A chat's project never changes, so its header is read once. */
|
|
37
|
-
const headers = new Map();
|
|
38
|
-
/** `<project>/agent-transcripts/<id>/<id>.jsonl`; a subdirectory's project name extends its parent's. Sub-agent files are skipped. */
|
|
39
|
-
function transcriptParts(path, root) {
|
|
40
|
-
const parts = relative(root, path).split(sep);
|
|
41
|
-
return parts.length && !parts[0]?.startsWith("..") ? parts : null;
|
|
42
|
-
}
|
|
43
|
-
/** Windows paths ignore case, so a terminal opened as `c:\\users` names the same project as `C:\\Users`. */
|
|
44
|
-
const fold = (value, platform) => platform === "win32" ? value.toLowerCase() : value;
|
|
45
|
-
const ownsProject = (name, cwd, platform = process.platform) => {
|
|
46
|
-
const project = fold(cursorProjectName(cwd), platform), own = fold(name ?? "", platform);
|
|
47
|
-
return own === project || own.startsWith(`${project}-`);
|
|
48
|
-
};
|
|
49
|
-
export function acceptsCursorDirectory(path, root, cwd) {
|
|
50
|
-
const parts = transcriptParts(path, root);
|
|
51
|
-
if (!parts || parts.length > 3 || !ownsProject(parts[0], cwd))
|
|
52
|
-
return false;
|
|
53
|
-
return parts.length === 1 || parts[1] === TRANSCRIPTS;
|
|
54
|
-
}
|
|
55
|
-
export function acceptsCursorTranscript(path, cwd) {
|
|
56
|
-
const parts = transcriptParts(path, cursorProjectsRoot());
|
|
57
|
-
return parts?.length === 4 && ownsProject(parts[0], cwd) && parts[1] === TRANSCRIPTS && parts[3] === `${parts[2]}.jsonl`;
|
|
58
|
-
}
|
|
59
|
-
export async function projectDirectory(name, platform = process.platform, list = (directory) => readdir(directory, { withFileTypes: true })) {
|
|
60
|
-
const paths = platform === "win32" ? win32 : posix;
|
|
61
|
-
const drive = platform === "win32" ? /^([A-Za-z])(?:-(.*))?$/.exec(name) : null;
|
|
62
|
-
if (platform === "win32" && !drive)
|
|
63
|
-
return null;
|
|
64
|
-
const found = [];
|
|
65
|
-
const walk = async (directory, rest) => {
|
|
66
|
-
if (found.length > 1)
|
|
67
|
-
return;
|
|
68
|
-
if (!rest) {
|
|
69
|
-
found.push(directory);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const entries = await list(directory).catch(() => []);
|
|
73
|
-
for (const entry of entries) {
|
|
74
|
-
if (!entry.isDirectory() && !entry.isSymbolicLink())
|
|
75
|
-
continue;
|
|
76
|
-
const part = fold(cursorProjectName(entry.name), platform);
|
|
77
|
-
if (part && (fold(rest, platform) === part || fold(rest, platform).startsWith(`${part}-`)))
|
|
78
|
-
await walk(paths.join(directory, entry.name), rest.slice(part.length + 1));
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
await (drive ? walk(`${drive[1]?.toUpperCase()}:\\`, drive[2] ?? "") : walk("/", name));
|
|
82
|
-
return found.length === 1 ? found[0] ?? null : null;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* The transcript does not name its project. A CLI chat's `meta.json` does; the IDE writes the same
|
|
86
|
-
* transcripts without one, so its project name is resolved to the directory it stands for.
|
|
87
|
-
*/
|
|
88
|
-
export async function cursorSessionHeader(path) {
|
|
89
|
-
const nativeSessionId = basename(path, ".jsonl");
|
|
90
|
-
if (basename(dirname(path)) !== nativeSessionId)
|
|
91
|
-
return null;
|
|
92
|
-
const known = headers.get(nativeSessionId);
|
|
93
|
-
if (known)
|
|
94
|
-
return known;
|
|
95
|
-
let header = null;
|
|
96
|
-
const hashes = await readdir(cursorChatsRoot()).catch((error) => { if (missing(error))
|
|
97
|
-
return []; throw error; });
|
|
98
|
-
for (const hash of hashes) {
|
|
99
|
-
const meta = await readFile(join(cursorChatsRoot(), hash, nativeSessionId, "meta.json"), "utf8").then((raw) => record(JSON.parse(raw)), () => null);
|
|
100
|
-
if (!meta || !text(meta.cwd))
|
|
101
|
-
continue;
|
|
102
|
-
header = { harness: "cursor", nativeSessionId, cwd: text(meta.cwd), thread: meta.isSubagent === true ? "spawned" : "user" };
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
const project = basename(dirname(dirname(dirname(path))));
|
|
106
|
-
const cwd = header ? null : await projectDirectory(project);
|
|
107
|
-
header ??= cwd ? { harness: "cursor", nativeSessionId, cwd, thread: "user" } : null;
|
|
108
|
-
if (header)
|
|
109
|
-
headers.set(nativeSessionId, header);
|
|
110
|
-
return header;
|
|
111
|
-
}
|
|
112
|
-
/** "Saturday, Aug 01, 2026, 9:30 AM (UTC+8)": minutes only, so Turn times are approximate. */
|
|
113
|
-
function promptTime(value) {
|
|
114
|
-
const match = /^\w+, (\w{3}) (\d{1,2}), (\d{4}), (\d{1,2}):(\d{2}) (AM|PM) \(UTC(?:([+-])(\d{1,2})(?::(\d{2}))?)?\)$/.exec(value.trim());
|
|
115
|
-
const month = MONTHS.indexOf(match?.[1] ?? "");
|
|
116
|
-
if (!match || month < 0)
|
|
117
|
-
return null;
|
|
118
|
-
const hour = Number(match[4]) % 12 + (match[6] === "PM" ? 12 : 0);
|
|
119
|
-
const offset = (match[7] === "-" ? -1 : 1) * (Number(match[8] ?? 0) * 60 + Number(match[9] ?? 0));
|
|
120
|
-
const time = Date.UTC(Number(match[3]), month, Number(match[2]), hour, Number(match[5])) - offset * 60_000;
|
|
121
|
-
return Number.isFinite(time) ? new Date(time).toISOString() : null;
|
|
122
|
-
}
|
|
123
|
-
const blocks = (value) => array(record(record(value).message).content).map(record);
|
|
124
|
-
/**
|
|
125
|
-
* Cursor writes the model's messages without ids or times: a prompt (`<user_query>`, or a bare text
|
|
126
|
-
* that no other user line follows), one line per reply step with its tool calls (results are not
|
|
127
|
-
* recorded), and `turn_ended` after every Turn. A user line followed by another is context. A Turn
|
|
128
|
-
* is keyed by the file's checksum through its prompt, so a rewritten history never reuses a key.
|
|
129
|
-
*/
|
|
130
|
-
export async function readCursorTranscript(path, nativeSessionId, signal) {
|
|
131
|
-
const read = await readChainedLines(path, signal);
|
|
132
|
-
const modified = (await stat(path)).mtime.toISOString();
|
|
133
|
-
const turns = [];
|
|
134
|
-
let current = null;
|
|
135
|
-
for (const [index, line] of read.lines.entries()) {
|
|
136
|
-
const value = line.value;
|
|
137
|
-
if (value.role === "user") {
|
|
138
|
-
const raw = blocks(value).map((block) => text(block.text)).join("\n");
|
|
139
|
-
// A bare text is a prompt only once a reply or end follows it; until then it may be context.
|
|
140
|
-
const next = read.lines[index + 1]?.value;
|
|
141
|
-
const query = USER_QUERY.exec(raw)?.[1] ?? (next && next.role !== "user" ? raw.replace(TIMESTAMP, "").trim() : null);
|
|
142
|
-
if (!query)
|
|
143
|
-
continue;
|
|
144
|
-
const startedAt = promptTime(TIMESTAMP.exec(raw)?.[1] ?? "") ?? current?.startedAt ?? modified;
|
|
145
|
-
current = {
|
|
146
|
-
key: line.sha256, parentKey: turns.at(-1)?.key ?? null, userContent: [{ type: "text", text: query }], messages: [], startedAt,
|
|
147
|
-
startBytes: line.startBytes, endBytes: line.endBytes, contentEndBytes: line.endBytes, boundaries: {}, sha256: line.sha256, result: null,
|
|
148
|
-
};
|
|
149
|
-
turns.push(current);
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
if (!current)
|
|
153
|
-
continue;
|
|
154
|
-
if (value.role === "assistant") {
|
|
155
|
-
const content = blocks(value).flatMap((block, position) => {
|
|
156
|
-
if (block.type === "text")
|
|
157
|
-
return text(block.text) ? [{ type: "text", text: text(block.text) }] : [];
|
|
158
|
-
if (block.type !== "tool_use")
|
|
159
|
-
return [];
|
|
160
|
-
return [{ type: "tool_use", id: `cursor_${line.sha256.slice(0, 24)}_${position}`, name: text(block.name) || "tool", input: record(block.input) }];
|
|
161
|
-
});
|
|
162
|
-
if (content.length)
|
|
163
|
-
current.messages.push({ content, provider: null, model: null, stopReason: content.some((block) => block.type === "tool_use") ? "tool_use" : "stop", errorMessage: null });
|
|
164
|
-
extendTurn(current, line, true);
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
if (value.type === "turn_ended" && !current.result) {
|
|
168
|
-
const status = text(value.status) || "success";
|
|
169
|
-
const last = current.messages.at(-1);
|
|
170
|
-
if (last && status === "error")
|
|
171
|
-
Object.assign(last, { stopReason: "error", errorMessage: text(value.error) || "Turn failed" });
|
|
172
|
-
if (last && status === "aborted")
|
|
173
|
-
last.stopReason = "aborted";
|
|
174
|
-
current.result = { messages: current.messages, completedAt: modified, status: status === "error" ? "failed" : status === "aborted" ? "interrupted" : "completed" };
|
|
175
|
-
current.ended = true;
|
|
176
|
-
extendTurn(current, line, false);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
// A Turn ends no later than the next one starts.
|
|
180
|
-
turns.forEach((turn, index) => { if (turn.result)
|
|
181
|
-
turn.result.completedAt = turns[index + 1]?.startedAt ?? modified; });
|
|
182
|
-
return { nativeSessionId, cwd: (await cursorSessionHeader(path))?.cwd ?? "", turns, prefixes: read.prefixes };
|
|
183
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { RuntimeExecutionEvent, RuntimeMessage } from "@neta-art/cohub";
|
|
2
|
-
import { type JsonRecord } from "../json-rpc.js";
|
|
3
|
-
import type { HarnessModel, LocalHarnessAdapter } from "./types.js";
|
|
4
|
-
/** The process a Cursor CLI invocation runs, and the variables its launcher would set. */
|
|
5
|
-
export declare function cursorCommand(executable: string, args: string[], cwd: string): {
|
|
6
|
-
command: [string, string[]];
|
|
7
|
-
env: Record<string, string>;
|
|
8
|
-
};
|
|
9
|
-
/** `cursor-agent models`: `<id> - <name> (current, default)` per line. */
|
|
10
|
-
export declare function cursorModels(output: string): HarnessModel[];
|
|
11
|
-
/**
|
|
12
|
-
* Maps `--output-format stream-json --stream-partial-output` onto Cohub's streaming protocol. A reply
|
|
13
|
-
* step ends once its tool calls returned. Cursor repeats a step's streamed text as one line right
|
|
14
|
-
* before a tool call, question or retry (with a timestamp) and at the end (without one); such a line
|
|
15
|
-
* is held until the next event says whether it was a repeat.
|
|
16
|
-
*/
|
|
17
|
-
export declare function cursorTranslator(emit: (event: RuntimeExecutionEvent) => void, identity: {
|
|
18
|
-
model: string | null;
|
|
19
|
-
}): {
|
|
20
|
-
result: () => RuntimeMessage | null;
|
|
21
|
-
last: () => RuntimeMessage;
|
|
22
|
-
push(event: JsonRecord): boolean;
|
|
23
|
-
};
|
|
24
|
-
export declare const cursorHarness: LocalHarnessAdapter;
|