@neta-art/cohub-cli 10.23.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/README.md +18 -5
- 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 -118
- 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 -64
- 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 -2139
- 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 -6
- package/dist/session-status.js +0 -16
- 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,62 +0,0 @@
|
|
|
1
|
-
import { createReadStream } from "node:fs";
|
|
2
|
-
import { basename, dirname } from "node:path";
|
|
3
|
-
import { iso, readFirstMatchingRecord, readTranscriptLines } from "../native/transcript.js";
|
|
4
|
-
import { text } from "./process.js";
|
|
5
|
-
/**
|
|
6
|
-
* `<data root>/projects/<project>/<session id>.jsonl`; sub-agent files live in deeper directories. A
|
|
7
|
-
* subdirectory's project name extends its parent's, so a prefix admits them; the header decides ownership.
|
|
8
|
-
*/
|
|
9
|
-
export function projectTranscript(path, root, project) {
|
|
10
|
-
return path.endsWith(".jsonl") && projectDirectory(dirname(path), root, project);
|
|
11
|
-
}
|
|
12
|
-
export function projectDirectory(path, root, project) {
|
|
13
|
-
return dirname(path) === root && basename(path).startsWith(project);
|
|
14
|
-
}
|
|
15
|
-
/** The session id is the file name; the first record carrying a `cwd` names the project. */
|
|
16
|
-
export async function chainedSessionHeader(path, harness, signal) {
|
|
17
|
-
const value = await readFirstMatchingRecord(createReadStream(path, { signal }), (entry) => Boolean(text(entry.cwd)) && Boolean(text(entry.sessionId)));
|
|
18
|
-
return value ? { harness, nativeSessionId: basename(path, ".jsonl"), cwd: text(value.cwd), thread: "user" } : null;
|
|
19
|
-
}
|
|
20
|
-
export async function readChainedLines(path, signal) {
|
|
21
|
-
const read = await readTranscriptLines(createReadStream(path, { signal }));
|
|
22
|
-
if (!read.lines.length)
|
|
23
|
-
throw new Error("Native transcript is empty");
|
|
24
|
-
return read;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* The branch ending at the file's last linked record, oldest first. These formats only append, so a
|
|
28
|
-
* parent is the latest earlier record with that id: a rewound or repeated id never forms a cycle.
|
|
29
|
-
*/
|
|
30
|
-
export function chainBranch(lines, id, parent) {
|
|
31
|
-
const latest = new Map();
|
|
32
|
-
const parents = [];
|
|
33
|
-
let leaf = -1;
|
|
34
|
-
lines.forEach((line, index) => {
|
|
35
|
-
const own = id(line.value);
|
|
36
|
-
parents[index] = -1;
|
|
37
|
-
if (!own)
|
|
38
|
-
return;
|
|
39
|
-
const before = latest.get(parent(line.value));
|
|
40
|
-
parents[index] = before ?? -1;
|
|
41
|
-
latest.set(own, index);
|
|
42
|
-
leaf = index;
|
|
43
|
-
});
|
|
44
|
-
const branch = [];
|
|
45
|
-
for (let index = leaf; index >= 0; index = parents[index] ?? -1)
|
|
46
|
-
branch.push(lines[index]);
|
|
47
|
-
return branch.reverse();
|
|
48
|
-
}
|
|
49
|
-
export function startTurn(line, key, parentKey, userContent, cloudTurnId) {
|
|
50
|
-
return {
|
|
51
|
-
key, parentKey, ...(cloudTurnId ? { cloudTurnId } : {}), userContent, messages: [], startedAt: iso(line.value.timestamp),
|
|
52
|
-
startBytes: line.startBytes, endBytes: line.endBytes, contentEndBytes: line.endBytes, boundaries: {}, sha256: line.sha256, result: null,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
/** Every branch record extends the Turn's bytes; only conversation records extend its content. */
|
|
56
|
-
export function extendTurn(turn, line, content) {
|
|
57
|
-
turn.endBytes = line.endBytes;
|
|
58
|
-
turn.sha256 = line.sha256;
|
|
59
|
-
turn.boundaries[line.endBytes] = line.sha256;
|
|
60
|
-
if (content)
|
|
61
|
-
turn.contentEndBytes = line.endBytes;
|
|
62
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { type ApprovalMode, type RuntimeTurnInput } from "@neta-art/cohub";
|
|
2
|
-
import { type JsonRecord } from "../json-rpc.js";
|
|
3
|
-
import type { ApprovalBroker, ApprovalRequest } from "../native/approvals.js";
|
|
4
|
-
/** Cards answer Claude Code's permission prompts, so without `--permission-prompt-tool stdio` no mode is offered. */
|
|
5
|
-
export declare function claudeApprovalModes(help: string): ApprovalMode[];
|
|
6
|
-
/**
|
|
7
|
-
* The platform's read-only access always wins. No mode follows local settings, as the picker shows;
|
|
8
|
-
* a CLI that cannot ask (no modes) keeps `acceptEdits` (`null`), since its prompts would be denied.
|
|
9
|
-
*/
|
|
10
|
-
export declare function claudeApprovalMode(input: RuntimeTurnInput, modes: readonly ApprovalMode[]): ApprovalMode | null;
|
|
11
|
-
export declare const claudePermissionMode: (mode: Exclude<ApprovalMode, "read_only"> | null) => string | null;
|
|
12
|
-
/**
|
|
13
|
-
* A `can_use_tool` request shown on a card, and what Allow for this chat remembers; other tools are denied.
|
|
14
|
-
* Claude Code reports no working directory: its shell keeps the last `cd`, so none is guessed.
|
|
15
|
-
*/
|
|
16
|
-
export declare function claudeApprovalRequest(request: JsonRecord): {
|
|
17
|
-
card: ApprovalRequest;
|
|
18
|
-
grants: string[];
|
|
19
|
-
} | null;
|
|
20
|
-
/**
|
|
21
|
-
* Allow for this chat, kept by the Runtime per Cohub Session: each Turn starts a new Claude Code
|
|
22
|
-
* process, and Claude's own settings are never written. Bounded and forgotten after a day unused.
|
|
23
|
-
*/
|
|
24
|
-
export declare class SessionGrants {
|
|
25
|
-
private readonly now;
|
|
26
|
-
private readonly sessions;
|
|
27
|
-
constructor(now?: () => number);
|
|
28
|
-
covers(sessionId: string, keys: string[]): boolean;
|
|
29
|
-
add(sessionId: string, keys: string[]): void;
|
|
30
|
-
private live;
|
|
31
|
-
private touch;
|
|
32
|
-
}
|
|
33
|
-
/** The `can_use_tool` answer: a card for Bash and file edits, a denial for anything else or without a card. */
|
|
34
|
-
export declare function answerClaudeApproval(request: JsonRecord, input: RuntimeTurnInput, approvals: ApprovalBroker, grants: SessionGrants, signal: AbortSignal): Promise<JsonRecord>;
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { APPROVAL_DECISIONS, APPROVAL_MODES } from "@neta-art/cohub";
|
|
2
|
-
import { record } from "../json-rpc.js";
|
|
3
|
-
import { text } from "./process.js";
|
|
4
|
-
const PERMISSION_MODES = { inherit: null, auto: "auto", full_access: "bypassPermissions", read_only: "plan" };
|
|
5
|
-
const EDIT_TOOLS = new Set(["Edit", "Write", "MultiEdit", "NotebookEdit"]);
|
|
6
|
-
/** Cards answer Claude Code's permission prompts, so without `--permission-prompt-tool stdio` no mode is offered. */
|
|
7
|
-
export function claudeApprovalModes(help) {
|
|
8
|
-
const start = help.search(/--permission-mode\b/);
|
|
9
|
-
const option = start < 0 ? "" : help.slice(start).split(/\n\s*-/)[0] ?? "";
|
|
10
|
-
const choices = new Set([...(/\(choices:([^)]*)\)/.exec(option)?.[1] ?? "").matchAll(/"([^"]+)"/g)].map((match) => match[1]));
|
|
11
|
-
return APPROVAL_MODES.filter((mode) => mode === "inherit" || choices.has(PERMISSION_MODES[mode] ?? ""));
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* The platform's read-only access always wins. No mode follows local settings, as the picker shows;
|
|
15
|
-
* a CLI that cannot ask (no modes) keeps `acceptEdits` (`null`), since its prompts would be denied.
|
|
16
|
-
*/
|
|
17
|
-
export function claudeApprovalMode(input, modes) {
|
|
18
|
-
if (input.accessMode === "read_only" && input.approvalMode && input.approvalMode !== "read_only") {
|
|
19
|
-
throw new Error("The approval mode conflicts with read-only access");
|
|
20
|
-
}
|
|
21
|
-
if (input.accessMode === "read_only")
|
|
22
|
-
return "read_only";
|
|
23
|
-
if (!input.approvalMode)
|
|
24
|
-
return modes.includes("inherit") ? "inherit" : null;
|
|
25
|
-
if (modes.includes(input.approvalMode))
|
|
26
|
-
return input.approvalMode;
|
|
27
|
-
throw new Error(`This Claude Code does not support the ${input.approvalMode} approval mode; update Claude Code and restart the Runtime`);
|
|
28
|
-
}
|
|
29
|
-
export const claudePermissionMode = (mode) => mode ? PERMISSION_MODES[mode] : "acceptEdits";
|
|
30
|
-
const clip = (value, max) => typeof value === "string" && value ? value.slice(0, max) : undefined;
|
|
31
|
-
/** What a card cannot show in full is not shown at all: a person approves exactly what runs. */
|
|
32
|
-
const whole = (value, max) => typeof value === "string" && value.length > max ? null : text(value) || undefined;
|
|
33
|
-
/**
|
|
34
|
-
* A `can_use_tool` request shown on a card, and what Allow for this chat remembers; other tools are denied.
|
|
35
|
-
* Claude Code reports no working directory: its shell keeps the last `cd`, so none is guessed.
|
|
36
|
-
*/
|
|
37
|
-
export function claudeApprovalRequest(request) {
|
|
38
|
-
const tool = text(request.tool_name), input = record(request.input);
|
|
39
|
-
const reason = clip(tool === "Bash" ? text(input.description) || request.decision_reason : request.decision_reason, 4096);
|
|
40
|
-
const card = (kind, grants, fields) => ({
|
|
41
|
-
grants,
|
|
42
|
-
card: { kind, decisions: APPROVAL_DECISIONS.filter((decision) => decision !== "accept_for_session" || grants.length > 0), ...fields, ...(reason ? { reason } : {}) },
|
|
43
|
-
});
|
|
44
|
-
if (tool === "Bash") {
|
|
45
|
-
const command = whole(input.command, 16_384);
|
|
46
|
-
return command === null ? null : card("command", command ? [`command:${command}`] : [], command ? { command } : {});
|
|
47
|
-
}
|
|
48
|
-
if (!EDIT_TOOLS.has(tool))
|
|
49
|
-
return null;
|
|
50
|
-
const path = whole(input.file_path ?? input.notebook_path, 4096);
|
|
51
|
-
return path === null ? null : card("file_change", path ? [`file:${path}`] : [], path ? { paths: [path] } : {});
|
|
52
|
-
}
|
|
53
|
-
const MAX_SESSIONS = 200;
|
|
54
|
-
const MAX_GRANTS = 200;
|
|
55
|
-
const GRANT_IDLE_MS = 24 * 60 * 60_000;
|
|
56
|
-
/**
|
|
57
|
-
* Allow for this chat, kept by the Runtime per Cohub Session: each Turn starts a new Claude Code
|
|
58
|
-
* process, and Claude's own settings are never written. Bounded and forgotten after a day unused.
|
|
59
|
-
*/
|
|
60
|
-
export class SessionGrants {
|
|
61
|
-
now;
|
|
62
|
-
sessions = new Map();
|
|
63
|
-
constructor(now = Date.now) {
|
|
64
|
-
this.now = now;
|
|
65
|
-
}
|
|
66
|
-
covers(sessionId, keys) {
|
|
67
|
-
const entry = this.live(sessionId);
|
|
68
|
-
if (!entry || !keys.length || !keys.every((key) => entry.keys.has(key)))
|
|
69
|
-
return false;
|
|
70
|
-
this.touch(sessionId, entry);
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
add(sessionId, keys) {
|
|
74
|
-
if (!keys.length)
|
|
75
|
-
return;
|
|
76
|
-
const entry = this.live(sessionId) ?? { keys: new Set(), usedAt: 0 };
|
|
77
|
-
for (const key of keys) {
|
|
78
|
-
entry.keys.delete(key);
|
|
79
|
-
entry.keys.add(key);
|
|
80
|
-
}
|
|
81
|
-
for (const key of entry.keys) {
|
|
82
|
-
if (entry.keys.size <= MAX_GRANTS)
|
|
83
|
-
break;
|
|
84
|
-
entry.keys.delete(key);
|
|
85
|
-
}
|
|
86
|
-
this.touch(sessionId, entry);
|
|
87
|
-
for (const oldest of this.sessions.keys()) {
|
|
88
|
-
if (this.sessions.size <= MAX_SESSIONS)
|
|
89
|
-
break;
|
|
90
|
-
this.sessions.delete(oldest);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
live(sessionId) {
|
|
94
|
-
const entry = this.sessions.get(sessionId);
|
|
95
|
-
if (entry && this.now() - entry.usedAt > GRANT_IDLE_MS)
|
|
96
|
-
this.sessions.delete(sessionId);
|
|
97
|
-
return this.sessions.get(sessionId);
|
|
98
|
-
}
|
|
99
|
-
touch(sessionId, entry) {
|
|
100
|
-
entry.usedAt = this.now();
|
|
101
|
-
this.sessions.delete(sessionId);
|
|
102
|
-
this.sessions.set(sessionId, entry);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const DENIED = "Approval requires an interactive local client";
|
|
106
|
-
/** The `can_use_tool` answer: a card for Bash and file edits, a denial for anything else or without a card. */
|
|
107
|
-
export async function answerClaudeApproval(request, input, approvals, grants, signal) {
|
|
108
|
-
const allow = { behavior: "allow", updatedInput: record(request.input) };
|
|
109
|
-
const asked = claudeApprovalRequest(request);
|
|
110
|
-
// A platform read-only Turn is never widened, whoever approves.
|
|
111
|
-
if (!asked || input.accessMode === "read_only" || !approvals.available || signal.aborted)
|
|
112
|
-
return { behavior: "deny", message: DENIED };
|
|
113
|
-
if (grants.covers(input.sessionId, asked.grants))
|
|
114
|
-
return allow;
|
|
115
|
-
const decision = await approvals.request(input.sessionId, input.turnId, asked.card, signal);
|
|
116
|
-
// A Turn that ended meanwhile grants nothing, not even to later Turns.
|
|
117
|
-
if (signal.aborted)
|
|
118
|
-
return { behavior: "deny", message: DENIED };
|
|
119
|
-
if (decision === "decline")
|
|
120
|
-
return { behavior: "deny", message: "The user declined this tool use" };
|
|
121
|
-
if (decision === "accept_for_session")
|
|
122
|
-
grants.add(input.sessionId, asked.grants);
|
|
123
|
-
return allow;
|
|
124
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type NativeTranscript } from "../native/transcript.js";
|
|
2
|
-
export declare const CLAUDE_REPLY_ENDED: string[];
|
|
3
|
-
/**
|
|
4
|
-
* Claude Code appends one record per content block, linked by `parentUuid` (`logicalParentUuid`
|
|
5
|
-
* across a compaction). A Turn starts at a prompt; its tool results and an interruption share the
|
|
6
|
-
* prompt's `promptId`. Interactive sessions record each end (`turn_duration`), `-p` sessions do not.
|
|
7
|
-
*/
|
|
8
|
-
export declare function readClaudeTranscript(path: string, nativeSessionId: string, signal?: AbortSignal): Promise<NativeTranscript>;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { record } from "../json-rpc.js";
|
|
2
|
-
import { iso } from "../native/transcript.js";
|
|
3
|
-
import { chainBranch, extendTurn, readChainedLines, startTurn } from "./chained-transcript.js";
|
|
4
|
-
import { array, text } from "./process.js";
|
|
5
|
-
import { streamContent, streamUsage } from "./stream-json.js";
|
|
6
|
-
const COMMAND = /^<command-name>\s*([^<]*)<\/command-name>/;
|
|
7
|
-
const COMMAND_ARGS = /<command-args>([\s\S]*?)<\/command-args>/;
|
|
8
|
-
const BASH_INPUT = /^<bash-input>([\s\S]*?)<\/bash-input>/;
|
|
9
|
-
/** Output of a local command or `!` shell, recorded as a user message but never sent as a prompt. */
|
|
10
|
-
const LOCAL_OUTPUT = /^<(?:local-command-(?:stdout|stderr|caveat)|bash-(?:stdout|stderr))>/;
|
|
11
|
-
const INTERRUPTED = "[Request interrupted by user";
|
|
12
|
-
export const CLAUDE_REPLY_ENDED = ["end_turn", "stop_sequence", "max_tokens", "refusal", "aborted", "error"];
|
|
13
|
-
const nonEmpty = (block) => !(block.type === "text" && !block.text) && !(block.type === "thinking" && !block.thinking);
|
|
14
|
-
/** A local `/command` or `!shell` is shown as typed; one that never reached the model is no Turn. */
|
|
15
|
-
function prompt(value) {
|
|
16
|
-
const content = typeof value === "string" ? [{ type: "text", text: value }] : streamContent(value).filter((block) => block.type === "text" || block.type === "image");
|
|
17
|
-
const first = content.find((block) => block.type === "text")?.text.trimStart() ?? "";
|
|
18
|
-
if (LOCAL_OUTPUT.test(first) || first.startsWith(INTERRUPTED))
|
|
19
|
-
return null;
|
|
20
|
-
const command = COMMAND.exec(first);
|
|
21
|
-
if (command)
|
|
22
|
-
return { content: [{ type: "text", text: `${command[1]?.trim() ?? ""} ${COMMAND_ARGS.exec(first)?.[1]?.trim() ?? ""}`.trim() }], local: true };
|
|
23
|
-
const bash = BASH_INPUT.exec(first);
|
|
24
|
-
if (bash)
|
|
25
|
-
return { content: [{ type: "text", text: `!${bash[1] ?? ""}` }], local: true };
|
|
26
|
-
const visible = content.filter(nonEmpty);
|
|
27
|
-
return visible.length ? { content: visible, local: false } : null;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Claude Code appends one record per content block, linked by `parentUuid` (`logicalParentUuid`
|
|
31
|
-
* across a compaction). A Turn starts at a prompt; its tool results and an interruption share the
|
|
32
|
-
* prompt's `promptId`. Interactive sessions record each end (`turn_duration`), `-p` sessions do not.
|
|
33
|
-
*/
|
|
34
|
-
export async function readClaudeTranscript(path, nativeSessionId, signal) {
|
|
35
|
-
const read = await readChainedLines(path, signal);
|
|
36
|
-
const branch = chainBranch(read.lines, (value) => value.isSidechain === true ? "" : text(value.uuid), (value) => text(value.parentUuid) || text(value.logicalParentUuid));
|
|
37
|
-
const turns = [];
|
|
38
|
-
const owners = new Map();
|
|
39
|
-
const messageIds = new Map();
|
|
40
|
-
let cwd = "", cloudSessionId = "";
|
|
41
|
-
let current = null;
|
|
42
|
-
let promptId = "", local = false, interrupted = false, completedAt = "";
|
|
43
|
-
const finish = () => {
|
|
44
|
-
if (!current)
|
|
45
|
-
return;
|
|
46
|
-
// A local command that never reached the model is not a conversation Turn.
|
|
47
|
-
if (local && !current.messages.length) {
|
|
48
|
-
current = null;
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const last = current.messages.at(-1);
|
|
52
|
-
const status = interrupted || !last || last.stopReason === "tool_use" ? "interrupted" : last.stopReason === "error" ? "failed" : "completed";
|
|
53
|
-
current.result = { messages: current.messages, completedAt: completedAt || current.startedAt, status };
|
|
54
|
-
turns.push(current);
|
|
55
|
-
current = null;
|
|
56
|
-
};
|
|
57
|
-
for (const line of branch) {
|
|
58
|
-
const value = line.value;
|
|
59
|
-
cwd ||= text(value.cwd);
|
|
60
|
-
if (value.type === "user") {
|
|
61
|
-
const message = record(value.message);
|
|
62
|
-
const results = array(message.content).map(record).filter((block) => block.type === "tool_result");
|
|
63
|
-
const opened = value.isMeta === true || value.isCompactSummary === true || results.length ? null : prompt(message.content);
|
|
64
|
-
if (opened && !(current && text(value.promptId) && text(value.promptId) === promptId)) {
|
|
65
|
-
finish();
|
|
66
|
-
const cohub = record(value.cohub);
|
|
67
|
-
cloudSessionId ||= text(cohub.sessionId);
|
|
68
|
-
// Cohub sends its Turn id as the prompt's record id; a projected record names its Turn.
|
|
69
|
-
current = startTurn(line, text(value.uuid), turns.at(-1)?.key ?? null, opened.content, text(cohub.turnId) || text(value.uuid));
|
|
70
|
-
promptId = text(value.promptId);
|
|
71
|
-
local = opened.local;
|
|
72
|
-
interrupted = false;
|
|
73
|
-
completedAt = current.startedAt;
|
|
74
|
-
owners.clear();
|
|
75
|
-
messageIds.clear();
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (!current)
|
|
79
|
-
continue;
|
|
80
|
-
for (const block of results) {
|
|
81
|
-
const id = text(block.tool_use_id);
|
|
82
|
-
const owner = owners.get(id);
|
|
83
|
-
if (!owner)
|
|
84
|
-
continue;
|
|
85
|
-
owner.content.push({ type: "tool_result", tool_use_id: id, content: typeof block.content === "string" ? block.content : streamContent(block.content), is_error: block.is_error === true });
|
|
86
|
-
}
|
|
87
|
-
if (array(message.content).some((block) => text(record(block).text).startsWith(INTERRUPTED)) || text(message.content).startsWith(INTERRUPTED)) {
|
|
88
|
-
interrupted = true;
|
|
89
|
-
current.ended = true;
|
|
90
|
-
}
|
|
91
|
-
completedAt = iso(value.timestamp);
|
|
92
|
-
extendTurn(current, line, true);
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
if (!current)
|
|
96
|
-
continue;
|
|
97
|
-
if (value.type === "assistant") {
|
|
98
|
-
const native = record(value.message);
|
|
99
|
-
const id = text(native.id);
|
|
100
|
-
let target = current.messages.at(-1);
|
|
101
|
-
if (!target || !id || messageIds.get(target) !== id) {
|
|
102
|
-
target = { content: [], provider: null, model: null, stopReason: null, errorMessage: null };
|
|
103
|
-
current.messages.push(target);
|
|
104
|
-
messageIds.set(target, id);
|
|
105
|
-
}
|
|
106
|
-
const content = streamContent(native.content).filter(nonEmpty);
|
|
107
|
-
for (const block of content) {
|
|
108
|
-
const index = block.type === "tool_use" ? target.content.findIndex((existing) => existing.type === "tool_use" && existing.id === block.id) : -1;
|
|
109
|
-
if (index >= 0)
|
|
110
|
-
target.content[index] = block;
|
|
111
|
-
else
|
|
112
|
-
target.content.push(block);
|
|
113
|
-
if (block.type === "tool_use")
|
|
114
|
-
owners.set(block.id, target);
|
|
115
|
-
}
|
|
116
|
-
const model = text(native.model);
|
|
117
|
-
if (model && model !== "<synthetic>")
|
|
118
|
-
target.model = model;
|
|
119
|
-
if (text(native.stop_reason))
|
|
120
|
-
target.stopReason = text(native.stop_reason);
|
|
121
|
-
const usage = streamUsage(native.usage, undefined);
|
|
122
|
-
if (usage)
|
|
123
|
-
target.usage = usage;
|
|
124
|
-
if (value.isApiErrorMessage === true) {
|
|
125
|
-
target.stopReason = "error";
|
|
126
|
-
target.errorMessage = content.flatMap((block) => block.type === "text" ? [block.text] : []).join("\n") || "API error";
|
|
127
|
-
}
|
|
128
|
-
completedAt = iso(value.timestamp);
|
|
129
|
-
extendTurn(current, line, true);
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
if (value.type === "system" && value.subtype === "turn_duration")
|
|
133
|
-
current.ended = true;
|
|
134
|
-
extendTurn(current, line, false);
|
|
135
|
-
}
|
|
136
|
-
finish();
|
|
137
|
-
return { nativeSessionId, cwd, ...(cloudSessionId ? { cloudSessionId } : {}), turns, prefixes: read.prefixes };
|
|
138
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { LocalHarnessAdapter } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Claude Code names a project directory by replacing every non-alphanumeric UTF-16 unit; a longer
|
|
4
|
-
* name keeps its first 200 units and appends the base-36 Java string hash of the path.
|
|
5
|
-
*/
|
|
6
|
-
export declare function claudeProjectName(cwd: string): string;
|
|
7
|
-
export declare const claudeProjectDirectory: (cwd: string) => string;
|
|
8
|
-
export declare const claudeHarness: LocalHarnessAdapter;
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { basename, join } from "node:path";
|
|
4
|
-
import { JsonRpcProcess, record } from "../json-rpc.js";
|
|
5
|
-
import { copyNativeArchive } from "../native/archive.js";
|
|
6
|
-
import { projectChainedSession, projectionMeta, projectionToolId, rebindSessionId } from "./chained-projection.js";
|
|
7
|
-
import { chainedSessionHeader, projectDirectory, projectTranscript } from "./chained-transcript.js";
|
|
8
|
-
import { answerClaudeApproval, claudeApprovalMode, claudeApprovalModes, claudePermissionMode, SessionGrants } from "./claude-approval.js";
|
|
9
|
-
import { CLAUDE_REPLY_ENDED, readClaudeTranscript } from "./claude-transcript.js";
|
|
10
|
-
import { array, harnessCommand, text } from "./process.js";
|
|
11
|
-
import { DEFAULT_MODEL, READ_ONLY_ARGS, runStreamJson, streamJsonHelp, streamJsonModel } from "./stream-json.js";
|
|
12
|
-
const MAX_PROJECT_NAME = 200;
|
|
13
|
-
const INITIALIZE_TIMEOUT_MS = 30_000;
|
|
14
|
-
const dataRoot = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join(homedir(), ".claude");
|
|
15
|
-
/**
|
|
16
|
-
* Claude Code names a project directory by replacing every non-alphanumeric UTF-16 unit; a longer
|
|
17
|
-
* name keeps its first 200 units and appends the base-36 Java string hash of the path.
|
|
18
|
-
*/
|
|
19
|
-
export function claudeProjectName(cwd) {
|
|
20
|
-
const name = cwd.replace(/[^a-zA-Z0-9]/g, "-");
|
|
21
|
-
if (name.length <= MAX_PROJECT_NAME)
|
|
22
|
-
return name;
|
|
23
|
-
let hash = 0;
|
|
24
|
-
for (let index = 0; index < cwd.length; index++)
|
|
25
|
-
hash = (hash * 31 + cwd.charCodeAt(index)) | 0;
|
|
26
|
-
return `${name.slice(0, MAX_PROJECT_NAME)}-${Math.abs(hash).toString(36)}`;
|
|
27
|
-
}
|
|
28
|
-
export const claudeProjectDirectory = (cwd) => join(dataRoot(), "projects", claudeProjectName(cwd));
|
|
29
|
-
const projectsRoot = () => join(dataRoot(), "projects");
|
|
30
|
-
/** Every subdirectory's project name starts with this; a hashed long name keeps its first 200 units. */
|
|
31
|
-
const projectPrefix = (cwd) => cwd.replace(/[^a-zA-Z0-9]/g, "-").slice(0, MAX_PROJECT_NAME);
|
|
32
|
-
const grants = new SessionGrants();
|
|
33
|
-
/** Probed once per executable and again with each catalog refresh; a failed probe is retried. */
|
|
34
|
-
const supportedModes = new Map();
|
|
35
|
-
/**
|
|
36
|
-
* `--permission-prompt-tool` is hidden from `--help`, so the CLI must accept it to answer `initialize`.
|
|
37
|
-
* A CLI that rejects it offers no modes; any other failure is retried.
|
|
38
|
-
*/
|
|
39
|
-
function probeApprovalModes(executable, cwd) {
|
|
40
|
-
const probe = (async () => {
|
|
41
|
-
const help = await streamJsonHelp(profile, executable, cwd);
|
|
42
|
-
try {
|
|
43
|
-
await claudeInitialize(executable, cwd, ["--permission-prompt-tool", "stdio"]);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
if (error instanceof Error && /unknown option '--permission-prompt-tool'/.test(error.message))
|
|
47
|
-
return [];
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
return claudeApprovalModes(help);
|
|
51
|
-
})();
|
|
52
|
-
supportedModes.set(executable, probe);
|
|
53
|
-
probe.catch(() => { if (supportedModes.get(executable) === probe)
|
|
54
|
-
supportedModes.delete(executable); });
|
|
55
|
-
return probe;
|
|
56
|
-
}
|
|
57
|
-
const profile = {
|
|
58
|
-
harness: "claude",
|
|
59
|
-
label: "Claude Code",
|
|
60
|
-
binary: "claude",
|
|
61
|
-
provider: "anthropic",
|
|
62
|
-
dataRoot,
|
|
63
|
-
projectDirectory: claudeProjectDirectory,
|
|
64
|
-
effortLevels: ["low", "medium", "high", "xhigh", "max"],
|
|
65
|
-
promptUuid: true,
|
|
66
|
-
async approvals(executor, input) {
|
|
67
|
-
const executable = executor.executables.claude || profile.binary;
|
|
68
|
-
const modes = await (supportedModes.get(executable) ?? probeApprovalModes(executable, executor.cwd)).catch(() => []);
|
|
69
|
-
const mode = claudeApprovalMode(input, modes);
|
|
70
|
-
if (mode === "read_only")
|
|
71
|
-
return { args: READ_ONLY_ARGS };
|
|
72
|
-
const permission = claudePermissionMode(mode);
|
|
73
|
-
return {
|
|
74
|
-
args: [...(modes.length ? ["--permission-prompt-tool", "stdio"] : []), ...(permission ? ["--permission-mode", permission] : [])],
|
|
75
|
-
...(modes.length ? { answer: (request, signal) => answerClaudeApproval(request, input, executor.approvals, grants, signal) } : {}),
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
function anthropicBlock(block) {
|
|
80
|
-
if (block.type === "text")
|
|
81
|
-
return { type: "text", text: block.text };
|
|
82
|
-
if (block.type === "image" && block.source.type === "base64")
|
|
83
|
-
return { type: "image", source: { type: "base64", media_type: block.source.media_type, data: block.source.data } };
|
|
84
|
-
if (block.type === "tool_use")
|
|
85
|
-
return { type: "tool_use", id: projectionToolId(block.id), name: block.name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 128) || "tool", input: block.input };
|
|
86
|
-
if (block.type === "tool_result") {
|
|
87
|
-
const content = typeof block.content === "string" ? block.content : block.content.map(anthropicBlock).filter((item) => item !== null);
|
|
88
|
-
return { type: "tool_result", tool_use_id: projectionToolId(block.tool_use_id), content, is_error: block.is_error ?? false };
|
|
89
|
-
}
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
/** Claude Code merges consecutive assistant records sharing a message id; each projected call gets its own. */
|
|
93
|
-
function withAssistantIds(projection) {
|
|
94
|
-
return { ...projection, records: projection.records.map((entry) => entry.record.type !== "assistant" ? entry : {
|
|
95
|
-
...entry, record: { ...entry.record, message: { id: `msg_${String(entry.record.uuid).replaceAll("-", "")}`, ...entry.record.message } },
|
|
96
|
-
}) };
|
|
97
|
-
}
|
|
98
|
-
/** Claude Code's own `/model` list (what the SDK's `supportedModels()` reads), gateway-discovered models included. */
|
|
99
|
-
async function claudeInitialize(executable, cwd, extra = []) {
|
|
100
|
-
const args = ["-p", "--input-format", "stream-json", "--output-format", "stream-json", "--verbose", "--no-session-persistence", "--strict-mcp-config", ...extra];
|
|
101
|
-
const host = new JsonRpcProcess(...harnessCommand(executable, args, cwd), cwd, "stream");
|
|
102
|
-
const requestId = randomUUID();
|
|
103
|
-
let timer;
|
|
104
|
-
try {
|
|
105
|
-
return await new Promise((resolve, reject) => {
|
|
106
|
-
timer = setTimeout(() => reject(new Error("Claude Code initialize timed out")), INITIALIZE_TIMEOUT_MS);
|
|
107
|
-
host.onFailure(reject);
|
|
108
|
-
host.onEvent((event) => {
|
|
109
|
-
const response = record(event.response);
|
|
110
|
-
if (event.type !== "control_response" || response.request_id !== requestId)
|
|
111
|
-
return;
|
|
112
|
-
if (response.subtype === "success")
|
|
113
|
-
resolve(record(response.response));
|
|
114
|
-
else
|
|
115
|
-
reject(new Error(text(response.error) || "Claude Code initialize failed"));
|
|
116
|
-
});
|
|
117
|
-
host.write({ type: "control_request", request_id: requestId, request: { subtype: "initialize" } });
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
finally {
|
|
121
|
-
clearTimeout(timer);
|
|
122
|
-
await host.close();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* A gateway at `ANTHROPIC_BASE_URL` serves every model, built-in aliases included, so all carry its host.
|
|
127
|
-
* Discovered gateway models without a visible base URL (e.g. set in Claude settings) get a generic name.
|
|
128
|
-
*/
|
|
129
|
-
function claudeProvider(baseUrl, discovered = false) {
|
|
130
|
-
let host = "";
|
|
131
|
-
try {
|
|
132
|
-
if (baseUrl)
|
|
133
|
-
host = new URL(baseUrl).hostname.slice(0, 100);
|
|
134
|
-
}
|
|
135
|
-
catch { /* Unparsable; use the generic name. */ }
|
|
136
|
-
if (host === "api.anthropic.com")
|
|
137
|
-
return profile.provider;
|
|
138
|
-
return host || (baseUrl || discovered ? "gateway" : profile.provider);
|
|
139
|
-
}
|
|
140
|
-
function claudeModelCatalog(entries, baseUrl) {
|
|
141
|
-
const provider = claudeProvider(baseUrl, entries.some((value) => text(record(value).description).startsWith("From gateway")));
|
|
142
|
-
const seen = new Set();
|
|
143
|
-
return entries.flatMap((value) => {
|
|
144
|
-
const model = record(value);
|
|
145
|
-
const id = text(model.value);
|
|
146
|
-
if (!id || id.length > 255 || seen.has(id))
|
|
147
|
-
return [];
|
|
148
|
-
seen.add(id);
|
|
149
|
-
const effortLevels = model.supportsEffort === true ? array(model.supportedEffortLevels).filter((level) => typeof level === "string") : [];
|
|
150
|
-
return [streamJsonModel(profile, id, (text(model.displayName) || id).slice(0, 255), {
|
|
151
|
-
reasoning: effortLevels.length > 0, effortLevels, isDefault: id === DEFAULT_MODEL, provider,
|
|
152
|
-
})];
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
export const claudeHarness = {
|
|
156
|
-
id: "claude",
|
|
157
|
-
binary: profile.binary,
|
|
158
|
-
async models(executable, cwd, options) {
|
|
159
|
-
await streamJsonHelp(profile, executable, cwd);
|
|
160
|
-
try {
|
|
161
|
-
const models = claudeModelCatalog(array((await claudeInitialize(executable, cwd)).models), process.env.ANTHROPIC_BASE_URL);
|
|
162
|
-
if (models.some((model) => model.isDefault))
|
|
163
|
-
return models;
|
|
164
|
-
if (options?.strict)
|
|
165
|
-
throw new Error("Claude Code initialize lists no default model");
|
|
166
|
-
}
|
|
167
|
-
catch (error) {
|
|
168
|
-
// A CLI without the initialize model list keeps the account aliases.
|
|
169
|
-
if (options?.strict)
|
|
170
|
-
throw error;
|
|
171
|
-
}
|
|
172
|
-
// Aliases follow the signed-in account; Haiku takes no effort level.
|
|
173
|
-
const provider = claudeProvider(process.env.ANTHROPIC_BASE_URL);
|
|
174
|
-
return [
|
|
175
|
-
streamJsonModel(profile, DEFAULT_MODEL, "Default", { reasoning: true, isDefault: true, provider }),
|
|
176
|
-
streamJsonModel(profile, "opus", "Claude Opus", { reasoning: true, provider }),
|
|
177
|
-
streamJsonModel(profile, "sonnet", "Claude Sonnet", { reasoning: true, provider }),
|
|
178
|
-
streamJsonModel(profile, "haiku", "Claude Haiku", { reasoning: false, provider }),
|
|
179
|
-
];
|
|
180
|
-
},
|
|
181
|
-
approvalModes: probeApprovalModes,
|
|
182
|
-
run: (executor, turn) => runStreamJson(profile, executor, turn),
|
|
183
|
-
session: {
|
|
184
|
-
path: (nativeSessionId, cwd) => join(claudeProjectDirectory(cwd), `${nativeSessionId}.jsonl`),
|
|
185
|
-
startsWithoutFile: true,
|
|
186
|
-
project: (input) => withAssistantIds(projectChainedSession(input, "claude", { id: "uuid", parent: "parentUuid" }, (segment) => {
|
|
187
|
-
const content = segment.blocks.map(anthropicBlock).filter((block) => block !== null);
|
|
188
|
-
return [{
|
|
189
|
-
isSidechain: false, userType: "external", cwd: input.cwd, sessionId: input.nativeSessionId, version: "cohub",
|
|
190
|
-
type: segment.role, timestamp: segment.message.createdAt || input.timestamp || new Date(0).toISOString(),
|
|
191
|
-
...(segment.compactSummary ? { isCompactSummary: true } : {}),
|
|
192
|
-
message: segment.role === "user"
|
|
193
|
-
? { role: "user", content }
|
|
194
|
-
: {
|
|
195
|
-
type: "message", role: "assistant", model: segment.message.model || "cohub", content,
|
|
196
|
-
stop_reason: segment.blocks.some((block) => block.type === "tool_use") ? "tool_use" : "end_turn", stop_sequence: null,
|
|
197
|
-
usage: { input_tokens: 0, output_tokens: 0 },
|
|
198
|
-
},
|
|
199
|
-
cohub: projectionMeta(input, segment.message),
|
|
200
|
-
}];
|
|
201
|
-
})),
|
|
202
|
-
rebind: rebindSessionId,
|
|
203
|
-
archive: {
|
|
204
|
-
// The copy takes a fresh id: the archived one may already exist here, and is never replaced.
|
|
205
|
-
target: ({ id, cwd }) => join(claudeProjectDirectory(cwd), `${id}.jsonl`),
|
|
206
|
-
async import(input) {
|
|
207
|
-
const { checksum } = await copyNativeArchive({ ...input, sessionId: input.id });
|
|
208
|
-
return { checksum, nativeSessionId: input.id };
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
transcript: {
|
|
213
|
-
roots: () => [projectsRoot()],
|
|
214
|
-
acceptsDirectory: (path, root, cwd) => projectDirectory(path, root, projectPrefix(cwd)),
|
|
215
|
-
acceptsTranscript: (path, cwd) => projectTranscript(path, projectsRoot(), projectPrefix(cwd)),
|
|
216
|
-
header: (path, signal) => chainedSessionHeader(path, "claude", signal),
|
|
217
|
-
read: (path, signal) => readClaudeTranscript(path, basename(path, ".jsonl"), signal),
|
|
218
|
-
boundaries: ['"promptSource"', '"subtype":"turn_duration"', '"interruptedMessageId"', '"isApiErrorMessage":true', ...CLAUDE_REPLY_ENDED.map((reason) => `"stop_reason":"${reason}"`)],
|
|
219
|
-
turnEndRecorded: false,
|
|
220
|
-
replyEnded: (turn) => CLAUDE_REPLY_ENDED.includes(turn.messages.at(-1)?.stopReason ?? ""),
|
|
221
|
-
userFinalMarked: false,
|
|
222
|
-
globalTurnKeys: false,
|
|
223
|
-
marksCohubTurns: true,
|
|
224
|
-
},
|
|
225
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { type ApprovalDecision, type ApprovalMode, type RuntimeTurnInput } from "@neta-art/cohub";
|
|
2
|
-
import type { ApprovalRequest } from "../native/approvals.js";
|
|
3
|
-
import { type JsonRecord } from "../json-rpc.js";
|
|
4
|
-
import type { CodexChannel } from "../native/codex-link.js";
|
|
5
|
-
import { type Version } from "../native/version.js";
|
|
6
|
-
/** First app-server whose thread and Turn approval overrides Cohub has verified. */
|
|
7
|
-
export declare const CODEX_APPROVAL_MIN_VERSION: Version;
|
|
8
|
-
export declare const codexApprovalModes: (version: Version | null) => ApprovalMode[];
|
|
9
|
-
/** The platform's read-only access always wins; `null` keeps the legacy behaviour. */
|
|
10
|
-
export declare function codexApprovalMode(input: RuntimeTurnInput, version: Version | null): ApprovalMode | null;
|
|
11
|
-
/** Overrides for opening the thread and for `turn/start`, which a loaded thread keeps for later Turns. */
|
|
12
|
-
export type CodexApproval = {
|
|
13
|
-
thread: JsonRecord;
|
|
14
|
-
turn: JsonRecord;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* `inherit` sends the machine's own settings, so an existing thread drops what an earlier mode set;
|
|
18
|
-
* a new thread starts with them anyway. Only Codex resolves them (profiles, requirements).
|
|
19
|
-
*/
|
|
20
|
-
export declare function resolveCodexApproval(mode: ApprovalMode, codex: CodexChannel, cwd: string, existing: boolean): Promise<CodexApproval>;
|
|
21
|
-
export declare const codexDecision: (decision: ApprovalDecision) => {
|
|
22
|
-
decision: string;
|
|
23
|
-
};
|
|
24
|
-
/** A Codex request a person can answer on a card; others are refused as before. */
|
|
25
|
-
export declare function codexApprovalRequest(method: string, params: JsonRecord, paths: string[] | undefined): ApprovalRequest | null;
|