@bivy/bivy 0.18.3 → 0.18.4-staging.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -25
- package/bin/codex-app-server-shim.mjs +6 -1
- package/dist/apps/gateway.js +82 -8
- package/dist/apps/inspector.js +7 -2
- package/dist/apps/preview-shell.js +81 -29
- package/dist/apps/registry.js +7 -1
- package/dist/apps/remote-preview.js +4 -2
- package/dist/apps/styles.css +40 -48
- package/dist/apps/tokens.css +58 -51
- package/dist/git-auth.js +13 -5
- package/dist/runtime/activation-readiness.js +15 -0
- package/dist/runtime/anthropic-preflight.js +1 -1
- package/dist/server.js +43 -177
- package/dist/session/prompt-attachments.js +135 -0
- package/package.json +2 -2
package/dist/server.js
CHANGED
|
@@ -50,6 +50,7 @@ import { passWebhookFilter } from "./automation-filter-gate.js";
|
|
|
50
50
|
import { isModelAuthError, authProviderForSession, classifyModelAuthError } from "./runtime/auth-errors.js";
|
|
51
51
|
import { createCredentialVault, migrateVaultDir } from "./runtime/credential-store.js";
|
|
52
52
|
import { probeAnthropicAccess } from "./runtime/anthropic-preflight.js";
|
|
53
|
+
import { credentialReadiness } from "./runtime/activation-readiness.js";
|
|
53
54
|
import { createSessionNamer, fallbackSessionName } from "./session/session-namer.js";
|
|
54
55
|
import { createBranchPublish } from "./session/branch-publish.js";
|
|
55
56
|
import { createForkStandUp } from "./session/fork-standup.js";
|
|
@@ -132,6 +133,7 @@ import { EventLog } from "./session/event-log.js";
|
|
|
132
133
|
import { SessionEventSequencer } from "./session/event-sequencer.js";
|
|
133
134
|
import { revertFile } from "./session/revert-file.js";
|
|
134
135
|
import { buildDiagnosticsReport, activationRecord } from "./diagnostics.js";
|
|
136
|
+
import { attachmentsFrom, materializeAttachments, sanitizeAttachmentFilename } from "./session/prompt-attachments.js";
|
|
135
137
|
import { AttachmentStore, isValidAttachmentHash } from "./session/attachment-store.js";
|
|
136
138
|
import { planAttachment, isAttachPlanError, MAX_AGENT_ATTACHMENT_BYTES } from "./session/attach-to-chat.js";
|
|
137
139
|
import { ReplicationService } from "./session/replication-service.js";
|
|
@@ -1007,6 +1009,7 @@ async function setDefaultRuntime(id) {
|
|
|
1007
1009
|
broadcast({ type: "runtime.updated", current: runtimeSummary(rt), runtimes: runtimeList(rt.id) });
|
|
1008
1010
|
return rt;
|
|
1009
1011
|
}
|
|
1012
|
+
// StreamingBehavior + PromptImage moved to ./session/record.ts (step 2a).
|
|
1010
1013
|
function streamingBehaviorFrom(value) {
|
|
1011
1014
|
return value === "steer" || value === "followUp" ? value : undefined;
|
|
1012
1015
|
}
|
|
@@ -1029,151 +1032,6 @@ function promptForAgent(_record, promptText) {
|
|
|
1029
1032
|
// remote PWA when history arrives.
|
|
1030
1033
|
return promptText;
|
|
1031
1034
|
}
|
|
1032
|
-
function safeAttachmentName(value) {
|
|
1033
|
-
return String(value || "attachment").replace(/[\r\n]/g, " ").slice(0, 180);
|
|
1034
|
-
}
|
|
1035
|
-
/**
|
|
1036
|
-
* Split composer attachments into channels:
|
|
1037
|
-
* - `images` — base64 blobs passed to the model as vision.
|
|
1038
|
-
* - `imageNotes` — one prose line per image for the persisted transcript.
|
|
1039
|
-
* - `imageRefs` — durable AttachmentStore references for the images, persisted
|
|
1040
|
-
* in the event log so they rehydrate after a reload / on
|
|
1041
|
-
* another device (images used to be vision-only, then lost).
|
|
1042
|
-
* - `files` — decoded file attachments (bytes or text) to be written to
|
|
1043
|
-
* disk by materializeAttachments so the agent can open them
|
|
1044
|
-
* with its normal file tools. Any file type is supported;
|
|
1045
|
-
* binary files arrive as base64 `data`.
|
|
1046
|
-
*/
|
|
1047
|
-
const MAX_PROMPT_ATTACHMENT_BYTES = 10 * 1024 * 1024;
|
|
1048
|
-
const MAX_PROMPT_ATTACHMENTS_BYTES = 40 * 1024 * 1024;
|
|
1049
|
-
function attachmentsFrom(value) {
|
|
1050
|
-
if (!Array.isArray(value))
|
|
1051
|
-
return { images: [], imageNotes: [], imageRefs: [], files: [] };
|
|
1052
|
-
const images = [];
|
|
1053
|
-
const imageNotes = [];
|
|
1054
|
-
const imageRefs = [];
|
|
1055
|
-
const files = [];
|
|
1056
|
-
let totalBytes = 0;
|
|
1057
|
-
if (value.length > 12)
|
|
1058
|
-
throw new Error("A message can include at most 12 attachments");
|
|
1059
|
-
for (const raw of value) {
|
|
1060
|
-
if (!raw || typeof raw !== "object")
|
|
1061
|
-
continue;
|
|
1062
|
-
const attachment = raw;
|
|
1063
|
-
const name = safeAttachmentName(attachment.name);
|
|
1064
|
-
const size = Number(attachment.size || 0);
|
|
1065
|
-
const mimeType = typeof attachment.mimeType === "string" && attachment.mimeType ? attachment.mimeType : undefined;
|
|
1066
|
-
const encodedBytes = typeof attachment.data === "string" ? Math.floor(attachment.data.length * 3 / 4) : 0;
|
|
1067
|
-
const textBytes = attachment.kind === "file" && typeof attachment.text === "string" ? Buffer.byteLength(attachment.text) : 0;
|
|
1068
|
-
const actualBytes = encodedBytes || textBytes;
|
|
1069
|
-
if (actualBytes > MAX_PROMPT_ATTACHMENT_BYTES)
|
|
1070
|
-
throw new Error(`${name} exceeds the 10 MiB attachment limit`);
|
|
1071
|
-
totalBytes += actualBytes;
|
|
1072
|
-
if (totalBytes > MAX_PROMPT_ATTACHMENTS_BYTES)
|
|
1073
|
-
throw new Error("Attachments exceed the 40 MiB per-message limit");
|
|
1074
|
-
if (attachment.kind === "image" && typeof attachment.data === "string") {
|
|
1075
|
-
const imgMime = mimeType ?? "image/png";
|
|
1076
|
-
images.push({ type: "image", data: attachment.data, mimeType: imgMime });
|
|
1077
|
-
imageNotes.push(`[Image attachment: ${name}${size ? ` (${size} bytes)` : ""}]`);
|
|
1078
|
-
// Persist the image bytes durably (dedup by hash). Best-effort: a store
|
|
1079
|
-
// failure must not break vision for the turn, so it only costs the ref.
|
|
1080
|
-
try {
|
|
1081
|
-
imageRefs.push(attachmentStore.put(Buffer.from(attachment.data, "base64"), { name, mimeType: imgMime, kind: "image" }));
|
|
1082
|
-
}
|
|
1083
|
-
catch (error) {
|
|
1084
|
-
console.warn("[attachments] failed to store image:", error instanceof Error ? error.message : String(error));
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
else if (attachment.kind === "file") {
|
|
1088
|
-
if (typeof attachment.data === "string" && attachment.data) {
|
|
1089
|
-
files.push({ name, mimeType: mimeType ?? "application/octet-stream", size, bytes: Buffer.from(attachment.data, "base64"), truncated: !!attachment.truncated });
|
|
1090
|
-
}
|
|
1091
|
-
else if (typeof attachment.text === "string" && attachment.text) {
|
|
1092
|
-
files.push({ name, mimeType: mimeType ?? "text/plain", size, text: attachment.text, truncated: !!attachment.truncated });
|
|
1093
|
-
}
|
|
1094
|
-
// A file with neither bytes nor text (e.g. omitted/unreadable) carries
|
|
1095
|
-
// nothing to write, so there is nothing to hand the agent — skip it.
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
return { images, imageNotes, imageRefs, files };
|
|
1099
|
-
}
|
|
1100
|
-
/** Strip a user-supplied filename to a safe basename — no path traversal, no
|
|
1101
|
-
* characters that would break the placeholder note or the filesystem. */
|
|
1102
|
-
function sanitizeAttachmentFilename(name) {
|
|
1103
|
-
const base = path
|
|
1104
|
-
.basename(String(name || ""))
|
|
1105
|
-
.replace(/[/\\\r\n\t[\]]/g, "_")
|
|
1106
|
-
.replace(/^\.+/, "")
|
|
1107
|
-
.trim()
|
|
1108
|
-
.slice(0, 180);
|
|
1109
|
-
return base || "attachment";
|
|
1110
|
-
}
|
|
1111
|
-
/**
|
|
1112
|
-
* Write decoded file attachments into `<workdir>/.bivy-attachments/` and return
|
|
1113
|
-
* one prose note per file (carrying the relative path) to append to the prompt.
|
|
1114
|
-
* This is what makes an uploaded file of ANY type — binary included — readable
|
|
1115
|
-
* by the agent's file tools. Filenames are sanitized and de-duplicated so two
|
|
1116
|
-
* `report.pdf`s don't clobber. Best-effort: a failure degrades to a note rather
|
|
1117
|
-
* than throwing, so a bad attachment never sinks the whole turn.
|
|
1118
|
-
*/
|
|
1119
|
-
function materializeAttachments(record, files) {
|
|
1120
|
-
if (!files.length)
|
|
1121
|
-
return { note: "", refs: [] };
|
|
1122
|
-
const refs = [];
|
|
1123
|
-
// Store every file durably in the global content-addressed store first (for
|
|
1124
|
-
// re-findability), independent of the per-workdir copy below. Best-effort per
|
|
1125
|
-
// file so one bad blob doesn't lose the others.
|
|
1126
|
-
for (const file of files) {
|
|
1127
|
-
const bytes = file.bytes ?? (typeof file.text === "string" ? Buffer.from(file.text, "utf8") : undefined);
|
|
1128
|
-
if (!bytes)
|
|
1129
|
-
continue;
|
|
1130
|
-
try {
|
|
1131
|
-
refs.push(attachmentStore.put(bytes, { name: sanitizeAttachmentFilename(file.name), mimeType: file.mimeType, kind: "file" }));
|
|
1132
|
-
}
|
|
1133
|
-
catch (error) {
|
|
1134
|
-
console.warn("[attachments] failed to store file:", error instanceof Error ? error.message : String(error));
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
const workdir = harnessDirFor(record);
|
|
1138
|
-
const dir = path.join(workdir, ".bivy-attachments");
|
|
1139
|
-
try {
|
|
1140
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
1141
|
-
}
|
|
1142
|
-
catch (error) {
|
|
1143
|
-
const why = error instanceof Error ? error.message : String(error);
|
|
1144
|
-
return { note: files.map((f) => `[File attachment: ${sanitizeAttachmentFilename(f.name)} could not be saved: ${why}]`).join("\n"), refs };
|
|
1145
|
-
}
|
|
1146
|
-
const notes = [];
|
|
1147
|
-
const used = new Set();
|
|
1148
|
-
for (const file of files) {
|
|
1149
|
-
const safeBase = sanitizeAttachmentFilename(file.name);
|
|
1150
|
-
const ext = path.extname(safeBase);
|
|
1151
|
-
const stem = safeBase.slice(0, safeBase.length - ext.length) || safeBase;
|
|
1152
|
-
let safe = safeBase;
|
|
1153
|
-
let n = 1;
|
|
1154
|
-
while (used.has(safe) || fs.existsSync(path.join(dir, safe))) {
|
|
1155
|
-
safe = `${stem}-${n}${ext}`;
|
|
1156
|
-
n += 1;
|
|
1157
|
-
}
|
|
1158
|
-
used.add(safe);
|
|
1159
|
-
const dest = path.join(dir, safe);
|
|
1160
|
-
const label = `${safe} (${file.size ? `${file.size} bytes, ` : ""}${file.mimeType}${file.truncated ? ", truncated" : ""})`;
|
|
1161
|
-
try {
|
|
1162
|
-
if (file.bytes)
|
|
1163
|
-
fs.writeFileSync(dest, file.bytes);
|
|
1164
|
-
else if (typeof file.text === "string")
|
|
1165
|
-
fs.writeFileSync(dest, file.text, "utf8");
|
|
1166
|
-
else
|
|
1167
|
-
continue;
|
|
1168
|
-
const rel = path.relative(workdir, dest) || safe;
|
|
1169
|
-
notes.push(`[File attachment: ${label} saved to ${rel} - read it with your file tools]`);
|
|
1170
|
-
}
|
|
1171
|
-
catch (error) {
|
|
1172
|
-
notes.push(`[File attachment: ${label} could not be saved: ${error instanceof Error ? error.message : String(error)}]`);
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
return { note: notes.join("\n"), refs };
|
|
1176
|
-
}
|
|
1177
1035
|
/**
|
|
1178
1036
|
* Store attachment bytes, persist a durable outbound reference anchored at the
|
|
1179
1037
|
* current transcript position (so a reload or another device shows it), and
|
|
@@ -1796,6 +1654,8 @@ function referencedAttachmentHashes() {
|
|
|
1796
1654
|
hashes.add(entry.ref.hash);
|
|
1797
1655
|
}
|
|
1798
1656
|
}
|
|
1657
|
+
for (const hash of appRegistry.notePictureHashes())
|
|
1658
|
+
hashes.add(hash);
|
|
1799
1659
|
return eventLog.health().ok ? hashes : null;
|
|
1800
1660
|
}
|
|
1801
1661
|
// --- Warm session replication (docs/session-replication.md) -----------------
|
|
@@ -1984,8 +1844,18 @@ const appSignIn = (view, pagePath) => {
|
|
|
1984
1844
|
return undefined;
|
|
1985
1845
|
return `${new URL(client).origin}/sessions/${encodeURIComponent(view.app.sessionId)}?node=${encodeURIComponent(identity.nodeId)}#preview=${view.app.id}.${view.view.id}.${encodeURIComponent(pagePath)}`;
|
|
1986
1846
|
};
|
|
1987
|
-
|
|
1988
|
-
|
|
1847
|
+
// Public notes get owner-only encrypted pictures, never a screenshot response
|
|
1848
|
+
// on the public origin. The annotation service honors appScreenshots being off.
|
|
1849
|
+
const captureReviewerNote = async (entry, mark) => {
|
|
1850
|
+
const result = await appService.annotate(entry.app.sessionId, mark);
|
|
1851
|
+
if (!result.image)
|
|
1852
|
+
return undefined;
|
|
1853
|
+
const image = result.image;
|
|
1854
|
+
const ref = attachmentStore.put(Buffer.from(image.data, "base64"), { name: "Reviewer note (approximate).png", mimeType: "image/png", kind: "image" });
|
|
1855
|
+
return { hash: ref.hash, size: ref.size, width: image.width, height: image.height };
|
|
1856
|
+
};
|
|
1857
|
+
const appGateway = process.env.BIVY_APPS_ORIGIN ? new AppGateway(appRegistry, process.env.BIVY_APPS_ORIGIN, appReturnOrigins, appSignIn, captureReviewerNote) : undefined;
|
|
1858
|
+
const remotePreview = new RemotePreview(appRegistry, appReturnOrigins, appSignIn, captureReviewerNote);
|
|
1989
1859
|
// Desktop app views: one private display per view, started on first open.
|
|
1990
1860
|
const appDisplays = createDisplayHost(appDir);
|
|
1991
1861
|
/** Review cards: screenshots become encrypted attachments (fetched by hash
|
|
@@ -3000,7 +2870,7 @@ const RELAY_COMMANDS = {
|
|
|
3000
2870
|
},
|
|
3001
2871
|
async prompt(msg, ctx) {
|
|
3002
2872
|
const text = String(msg.text ?? "").trim();
|
|
3003
|
-
const { images, imageNotes,
|
|
2873
|
+
const { images, imageNotes, files } = attachmentsFrom(msg.attachments);
|
|
3004
2874
|
if (!text && !images.length && !files.length)
|
|
3005
2875
|
return;
|
|
3006
2876
|
// Title/naming can only see what we have before the session exists; the file
|
|
@@ -3043,12 +2913,12 @@ const RELAY_COMMANDS = {
|
|
|
3043
2913
|
touchSession(record);
|
|
3044
2914
|
// Now that the session (and its workdir) exists, write file attachments to
|
|
3045
2915
|
// disk and fold their path notes into the prompt the agent actually sees.
|
|
3046
|
-
const { note: fileNote, refs: fileRefs } = materializeAttachments(record, files);
|
|
3047
|
-
const promptText = [text,
|
|
2916
|
+
const { note: fileNote, refs: fileRefs } = materializeAttachments(harnessDirFor(record), files, attachmentStore);
|
|
2917
|
+
const promptText = [text, fileNote].filter(Boolean).join("\n\n") ||
|
|
3048
2918
|
(images.length ? "Please review the attached image(s)." : files.length ? "Please review the attached file(s)." : "");
|
|
3049
2919
|
// Persist durable attachment refs keyed by the exact text the transcript
|
|
3050
2920
|
// stores for this user message, so history rehydrates thumbnails by hash.
|
|
3051
|
-
eventLog.appendAttachments(record.id, promptText,
|
|
2921
|
+
eventLog.appendAttachments(record.id, promptText, fileRefs);
|
|
3052
2922
|
const agentPrompt = promptForAgent(record, promptText);
|
|
3053
2923
|
const cmid = typeof msg.clientMessageId === "string" && msg.clientMessageId ? msg.clientMessageId : undefined;
|
|
3054
2924
|
// A retry of a prompt we already took: the caller missed our echo (that is
|
|
@@ -11140,32 +11010,28 @@ app.get("/api/repos", async (_req, res) => {
|
|
|
11140
11010
|
// live. Inconclusive provider/network failures remain "unknown" instead of
|
|
11141
11011
|
// falsely blocking activation.
|
|
11142
11012
|
async function activationReadinessSnapshot() {
|
|
11143
|
-
const
|
|
11144
|
-
|
|
11145
|
-
|
|
11146
|
-
|
|
11147
|
-
|
|
11148
|
-
|
|
11149
|
-
|
|
11150
|
-
|
|
11151
|
-
|
|
11152
|
-
|
|
11013
|
+
const [credential, repositoryChosen, workspaceReady] = await Promise.all([
|
|
11014
|
+
listProviders(credsDir, piDir).then((providers) => credentialReadiness(providers, async (provider) => {
|
|
11015
|
+
if (provider !== "anthropic")
|
|
11016
|
+
return { probed: false, ok: true };
|
|
11017
|
+
const credential = await createCredentialVault(credsDir, piDir).read(provider);
|
|
11018
|
+
if (credential?.type === "oauth")
|
|
11019
|
+
return { probed: false, ok: true };
|
|
11020
|
+
return probeAnthropicAccess(credential?.type === "api_key" && typeof credential.key === "string"
|
|
11021
|
+
? credential.key : process.env.ANTHROPIC_API_KEY);
|
|
11022
|
+
})),
|
|
11023
|
+
gitRepoRoot(defaultWorkspace).then(Boolean),
|
|
11024
|
+
fs.promises.access(defaultWorkspace, fs.constants.R_OK | fs.constants.W_OK).then(() => true, () => false),
|
|
11025
|
+
]);
|
|
11153
11026
|
return {
|
|
11154
|
-
credential
|
|
11155
|
-
configured: configured.length > 0,
|
|
11156
|
-
providers: configured.map((entry) => entry.providerId),
|
|
11157
|
-
probed: Boolean(anthropicProbe?.probed),
|
|
11158
|
-
ok: configured.length > 0 && anthropicProbe?.ok !== false,
|
|
11159
|
-
...(anthropicProbe?.reason ? { reason: anthropicProbe.reason } : {}),
|
|
11160
|
-
},
|
|
11027
|
+
credential,
|
|
11161
11028
|
repository: {
|
|
11162
11029
|
chosen: repositoryChosen,
|
|
11163
11030
|
probed: true,
|
|
11164
|
-
//
|
|
11165
|
-
//
|
|
11166
|
-
ok:
|
|
11167
|
-
authed:
|
|
11168
|
-
...(repos.error ? { reason: repos.error } : {}),
|
|
11031
|
+
// A first message can run in the default workspace without a Git repo.
|
|
11032
|
+
// Listing remote repositories is unrelated and can take tens of seconds.
|
|
11033
|
+
ok: workspaceReady,
|
|
11034
|
+
authed: false,
|
|
11169
11035
|
},
|
|
11170
11036
|
};
|
|
11171
11037
|
}
|
|
@@ -11257,7 +11123,7 @@ app.post("/api/session/prompt", async (req, res, next) => {
|
|
|
11257
11123
|
if (text === "/login" || text.startsWith("/login ")) {
|
|
11258
11124
|
return res.status(400).json({ error: "Use the Login / API tokens dialog from the phone UI. If it is not visible, refresh this page after updating Bivy." });
|
|
11259
11125
|
}
|
|
11260
|
-
const { images, imageNotes,
|
|
11126
|
+
const { images, imageNotes, files } = attachmentsFrom(req.body?.attachments);
|
|
11261
11127
|
if (!text && !images.length && !files.length)
|
|
11262
11128
|
return res.status(400).json({ error: "Missing text" });
|
|
11263
11129
|
// File notes (with on-disk paths) are folded in once the workdir exists; the
|
|
@@ -11285,10 +11151,10 @@ app.post("/api/session/prompt", async (req, res, next) => {
|
|
|
11285
11151
|
}
|
|
11286
11152
|
notePresence(record.id, deviceFrom(req.body?.device), "chat");
|
|
11287
11153
|
const session = record.session;
|
|
11288
|
-
const { note: fileNote, refs: fileRefs } = materializeAttachments(record, files);
|
|
11289
|
-
const promptText = [text,
|
|
11154
|
+
const { note: fileNote, refs: fileRefs } = materializeAttachments(harnessDirFor(record), files, attachmentStore);
|
|
11155
|
+
const promptText = [text, fileNote].filter(Boolean).join("\n\n") ||
|
|
11290
11156
|
(images.length ? "Please review the attached image(s)." : files.length ? "Please review the attached file(s)." : "");
|
|
11291
|
-
eventLog.appendAttachments(record.id, promptText,
|
|
11157
|
+
eventLog.appendAttachments(record.id, promptText, fileRefs);
|
|
11292
11158
|
const agentPrompt = promptForAgent(record, promptText);
|
|
11293
11159
|
const cmid = typeof req.body?.clientMessageId === "string" && req.body.clientMessageId ? req.body.clientMessageId : undefined;
|
|
11294
11160
|
markSessionWorking(record, { type: "agent_start" });
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
function safeAttachmentName(value) {
|
|
5
|
+
return String(value || "attachment").replace(/[\r\n]/g, " ").slice(0, 180);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Split composer attachments into channels:
|
|
9
|
+
* - `images` — base64 blobs passed to the model as vision.
|
|
10
|
+
* - `imageNotes` — short image labels for naming a new session.
|
|
11
|
+
* - `files` — all decoded attachments (including images) to be written to
|
|
12
|
+
* disk by materializeAttachments so the agent can open them
|
|
13
|
+
* with its normal file tools. Any file type is supported;
|
|
14
|
+
* binary files arrive as base64 `data`.
|
|
15
|
+
*/
|
|
16
|
+
const MAX_PROMPT_ATTACHMENT_BYTES = 10 * 1024 * 1024;
|
|
17
|
+
const MAX_PROMPT_ATTACHMENTS_BYTES = 40 * 1024 * 1024;
|
|
18
|
+
export function attachmentsFrom(value) {
|
|
19
|
+
if (!Array.isArray(value))
|
|
20
|
+
return { images: [], imageNotes: [], files: [] };
|
|
21
|
+
const images = [];
|
|
22
|
+
const imageNotes = [];
|
|
23
|
+
const files = [];
|
|
24
|
+
let totalBytes = 0;
|
|
25
|
+
if (value.length > 12)
|
|
26
|
+
throw new Error("A message can include at most 12 attachments");
|
|
27
|
+
for (const raw of value) {
|
|
28
|
+
if (!raw || typeof raw !== "object")
|
|
29
|
+
continue;
|
|
30
|
+
const attachment = raw;
|
|
31
|
+
const name = safeAttachmentName(attachment.name);
|
|
32
|
+
const size = Number(attachment.size || 0);
|
|
33
|
+
const mimeType = typeof attachment.mimeType === "string" && attachment.mimeType ? attachment.mimeType : undefined;
|
|
34
|
+
const encodedBytes = typeof attachment.data === "string" ? Math.floor(attachment.data.length * 3 / 4) : 0;
|
|
35
|
+
const textBytes = attachment.kind === "file" && typeof attachment.text === "string" ? Buffer.byteLength(attachment.text) : 0;
|
|
36
|
+
const actualBytes = encodedBytes || textBytes;
|
|
37
|
+
if (actualBytes > MAX_PROMPT_ATTACHMENT_BYTES)
|
|
38
|
+
throw new Error(`${name} exceeds the 10 MiB attachment limit`);
|
|
39
|
+
totalBytes += actualBytes;
|
|
40
|
+
if (totalBytes > MAX_PROMPT_ATTACHMENTS_BYTES)
|
|
41
|
+
throw new Error("Attachments exceed the 40 MiB per-message limit");
|
|
42
|
+
if (attachment.kind === "image" && typeof attachment.data === "string") {
|
|
43
|
+
const imgMime = mimeType ?? "image/png";
|
|
44
|
+
images.push({ type: "image", data: attachment.data, mimeType: imgMime });
|
|
45
|
+
imageNotes.push(`[Image attachment: ${name}${size ? ` (${size} bytes)` : ""}]`);
|
|
46
|
+
files.push({ kind: "image", name, mimeType: imgMime, size, bytes: Buffer.from(attachment.data, "base64") });
|
|
47
|
+
}
|
|
48
|
+
else if (attachment.kind === "file") {
|
|
49
|
+
if (typeof attachment.data === "string" && attachment.data) {
|
|
50
|
+
files.push({ kind: "file", name, mimeType: mimeType ?? "application/octet-stream", size, bytes: Buffer.from(attachment.data, "base64"), truncated: !!attachment.truncated });
|
|
51
|
+
}
|
|
52
|
+
else if (typeof attachment.text === "string" && attachment.text) {
|
|
53
|
+
files.push({ kind: "file", name, mimeType: mimeType ?? "text/plain", size, text: attachment.text, truncated: !!attachment.truncated });
|
|
54
|
+
}
|
|
55
|
+
// A file with neither bytes nor text (e.g. omitted/unreadable) carries
|
|
56
|
+
// nothing to write, so there is nothing to hand the agent — skip it.
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { images, imageNotes, files };
|
|
60
|
+
}
|
|
61
|
+
/** Strip a user-supplied filename to a safe basename — no path traversal, no
|
|
62
|
+
* characters that would break the placeholder note or the filesystem. */
|
|
63
|
+
export function sanitizeAttachmentFilename(name) {
|
|
64
|
+
const base = path
|
|
65
|
+
.basename(String(name || ""))
|
|
66
|
+
.replace(/[/\\\r\n\t[\]]/g, "_")
|
|
67
|
+
.replace(/^\.+/, "")
|
|
68
|
+
.trim()
|
|
69
|
+
.slice(0, 180);
|
|
70
|
+
return base || "attachment";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Write decoded attachments into `<workdir>/.bivy-attachments/` and return
|
|
74
|
+
* one prose note per file (carrying the absolute path) to append to the prompt.
|
|
75
|
+
* This is what makes an uploaded file of ANY type — binary included — readable
|
|
76
|
+
* by the agent's file tools. Filenames are sanitized and de-duplicated so two
|
|
77
|
+
* `report.pdf`s don't clobber. Best-effort: a failure degrades to a note rather
|
|
78
|
+
* than throwing, so a bad attachment never sinks the whole turn.
|
|
79
|
+
*/
|
|
80
|
+
export function materializeAttachments(workdir, files, attachmentStore) {
|
|
81
|
+
if (!files.length)
|
|
82
|
+
return { note: "", refs: [] };
|
|
83
|
+
const refs = [];
|
|
84
|
+
// Store every file durably in the global content-addressed store first (for
|
|
85
|
+
// re-findability), independent of the per-workdir copy below. Best-effort per
|
|
86
|
+
// file so one bad blob doesn't lose the others.
|
|
87
|
+
for (const file of files) {
|
|
88
|
+
const bytes = file.bytes ?? (typeof file.text === "string" ? Buffer.from(file.text, "utf8") : undefined);
|
|
89
|
+
if (!bytes)
|
|
90
|
+
continue;
|
|
91
|
+
try {
|
|
92
|
+
refs.push(attachmentStore.put(bytes, { name: sanitizeAttachmentFilename(file.name), mimeType: file.mimeType, kind: file.kind }));
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.warn("[attachments] failed to store file:", error instanceof Error ? error.message : String(error));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const dir = path.join(workdir, ".bivy-attachments");
|
|
99
|
+
try {
|
|
100
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
104
|
+
return { note: files.map((f) => `[${f.kind === "image" ? "Image" : "File"} attachment: ${sanitizeAttachmentFilename(f.name)} could not be saved: ${why}]`).join("\n"), refs };
|
|
105
|
+
}
|
|
106
|
+
const notes = [];
|
|
107
|
+
const used = new Set();
|
|
108
|
+
for (const file of files) {
|
|
109
|
+
const safeBase = sanitizeAttachmentFilename(file.name);
|
|
110
|
+
const ext = path.extname(safeBase);
|
|
111
|
+
const stem = safeBase.slice(0, safeBase.length - ext.length) || safeBase;
|
|
112
|
+
let safe = safeBase;
|
|
113
|
+
let n = 1;
|
|
114
|
+
while (used.has(safe) || fs.existsSync(path.join(dir, safe))) {
|
|
115
|
+
safe = `${stem}-${n}${ext}`;
|
|
116
|
+
n += 1;
|
|
117
|
+
}
|
|
118
|
+
used.add(safe);
|
|
119
|
+
const dest = path.join(dir, safe);
|
|
120
|
+
const label = `${safe} (${file.size ? `${file.size} bytes, ` : ""}${file.mimeType}${file.truncated ? ", truncated" : ""})`;
|
|
121
|
+
try {
|
|
122
|
+
if (file.bytes)
|
|
123
|
+
fs.writeFileSync(dest, file.bytes);
|
|
124
|
+
else if (typeof file.text === "string")
|
|
125
|
+
fs.writeFileSync(dest, file.text, "utf8");
|
|
126
|
+
else
|
|
127
|
+
continue;
|
|
128
|
+
notes.push(`[${file.kind === "image" ? "Image" : "File"} attachment: ${label} saved to ${dest} - read it with your file tools]`);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
notes.push(`[${file.kind === "image" ? "Image" : "File"} attachment: ${label} could not be saved: ${error instanceof Error ? error.message : String(error)}]`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { note: notes.join("\n"), refs };
|
|
135
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bivy/bivy",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.4-staging.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"description": "Run coding agents on machines you own. Open-source, self-hostable agent workspace.",
|
|
@@ -71,6 +71,6 @@
|
|
|
71
71
|
"lodash-es": "4.18.1",
|
|
72
72
|
"undici": "8.10.2"
|
|
73
73
|
},
|
|
74
|
-
"readme": "# Bivy\n\n[](https://www.npmjs.com/package/@bivy/bivy)\n[](LICENSE)\n[](https://nodejs.org)\n\n**Run coding agents on your machines and use them from anywhere — from a phone,\nbrowser, terminal, GitHub issue, Slack message, schedule, or webhook.**\n\nBivy is an open-source workspace for coding-agent work. Turn prompts, GitHub\nissues, CI failures, Slack messages, and schedules into live sessions on your\nmachines. Choose the agent and model, sync supported API keys and OAuth logins,\nand steer and review the work from your browser, phone, or terminal.\n\nKeep Claude Code, Codex, Pi, OpenCode, or another supported agent. Keep your\nrepos, tools, and development environment. Bivy connects them into a workflow\nthat doesn't end when you leave your desk.\n\n**[Start free on Bivy Cloud](https://app.bivy.sh)** ·\n**[Quickstart](docs/quickstart.md)** ·\n**[Documentation](docs/README.md)** ·\n**[Self-host](docs/deploy-images.md)** ·\n**[Website](https://bivy.sh)**\n\n**Recommended:** sign in at [app.bivy.sh](https://app.bivy.sh), then copy your\npersonalized **Connect a Machine** command into a terminal on your Mac or Linux\ncomputer. It installs and enrolls the machine without another Bivy login. The\nbrowser connects automatically; choose a repository and send your first task\nright there.\n\nPrefer starting from the terminal?\n\n```bash\ncurl -fsSL https://bivy.sh/install.sh | bash # install + guided setup\ncd your-repo\nbivy run claude # or codex, pi, opencode\nbivy open # continue in the web app (needs remote setup)\n```\n\nBivy Cloud hosts the app, control plane, and relay—not the machines running your\nagents. Connect a Mac, Linux computer, or existing server and bring your own\nagent subscription, model API key, or local model. You can also self-host the\nentire remote-access stack.\n\n> **Bivy is 0.x software.** Claude Code, Codex, Pi, and OpenCode are the\n> release-tested paths. Credential sync, resume, handoffs, approvals, and\n> sandboxing depend on the runtime. See the\n> [runtime support matrix](docs/runtime-support-matrix.md).\n\n## More than remote access\n\nRemote access lets you reach an agent. Bivy also connects **what starts the\nwork, where it runs, which agent and credentials it uses, and how you review\nwhat happened**.\n\n| Capability | What it means for you |\n|---|---|\n| **One workspace, multiple agents** | Use different agents and models for different tasks without maintaining a separate workflow for each. |\n| **Your machines and environment** | Work beside your existing repos, dev servers, databases, private networks, toolchains, and GPUs. |\n| **Automations and triggers** | Let issues, failed CI, messages, schedules, and webhooks start work instead of copying requests into a chat. |\n| **Encrypted key and OAuth sync** | Reuse Bivy-managed provider credentials across enrolled machines and compatible runtimes, with less repeated setup. |\n| **Live sessions from anywhere** | Start at your desk, answer a question or approve an action from your phone, then return to the terminal. |\n| **Reviewable results** | See changes, declared checks, artifacts, and pull requests—not just an agent's claim that it finished. |\n| **Hosted convenience or self-hosting** | Use Bivy Cloud for managed remote access, or run the same open-source core yourself. |\n\n## One workflow, from trigger to review\n\n```text\nPrompt · GitHub issue · CI failure · Linear · Slack · Schedule · Webhook\n │\n ▼\n Choose machine + agent + model\n + supported credentials\n │\n ▼\n Live agent session\n Join · steer · approve · stop\n │\n ▼\n Changes · checks · artifacts · PR\n```\n\nA **Machine** is a computer or server you connect. A **Session** is live agent\nwork on that machine. A **Run** is delegated background work that creates a\nsession and tracks its outcome. An **Automation** is a reusable definition that\ncreates runs when an event matches.\n\nManual and automated work use the same kind of live session. You can join a run\nwhen it needs help rather than wait for a black-box job to finish.\n\n### Work in the environment you already have\n\nA clean cloud sandbox isn't always enough. Your agent may need the database\nrunning on localhost, an uncommitted change, an internal API behind your VPN,\nor a model running on your GPU. Bivy runs the agent where those things already\nexist, subject to that machine's permissions and the runtime's protection.\n\nConnect several machines to the same account: a laptop for interactive work,\na Linux server for background jobs, or a GPU box for local inference. Choose\nthe machine for each session or pin it in an automation. Repository runs can\nuse isolated Git worktrees without rebuilding the whole development environment.\n\n**The execution machine must stay awake and online.** To close your laptop and\nleave work running, run the agent on a different, always-on machine.\n\n[Environment and multi-machine recipes →](docs/capability-recipes.md)\n\n### Use multiple agents, not multiple disconnected workflows\n\nRun Claude Code for one task, Codex for another, and Pi or OpenCode where they\nfit. Bivy supplies the shared session, remote-access, automation, and review\nsurfaces; your chosen agent still does the coding and uses your model provider.\n\n- Choose an agent and, where supported, a model for each session or run.\n- Import existing Claude Code and Codex sessions.\n- Fork or move work to another agent or machine when a different setup fits\n better. Continuation fidelity varies: some paths preserve native history,\n while others replay portable turns or seed the destination with context.\n- Use agent-native logins, Bivy-managed credentials, or local inference.\n Bivy's custom OpenAI-compatible endpoint registry currently feeds Pi;\n other agents may need their own provider configuration.\n- Register your own ACP or headless process agent with `bivy agent add`.\n\nBivy does not replace your agent, provide model inference, or make every agent's\nfeatures identical. Consult the [support matrix](docs/runtime-support-matrix.md)\nand [handoff recipes](docs/capability-recipes.md#fork-or-move-a-session).\n\n### Less signing in. Less copying secrets.\n\nBivy syncs **Bivy-managed API keys and supported OAuth credentials** across\nenrolled machines for compatible runtimes. Connect supported credentials once\nand reuse them where you run work, rather than manually distributing keys to\neach machine.\n\nFor ordinary account sync, credentials are encrypted on the node before upload.\nThe control plane stores ciphertext and wrapped-key metadata; enrolled nodes\nshare access by wrapping the vault key to one another. Bivy Cloud does not\nreceive plaintext credentials through this sync path.\n\nYou can also keep credentials local, use labeled keys and project presets, or\nreference environment variables and 1Password instead of embedding secrets in\nconfiguration:\n\n```bash\nbivy provider login\nbivy credentials add anthropic work\nbivy secrets ref github.repo-token op://Bivy/GitHub/repo-token\n```\n\n**Not every CLI login syncs.** Native agent logins may still be per-machine;\nGitHub App private-key sync is separately opt-in. If you lose every node and\ndevice able to unwrap a vault, you must sign in to providers again. Explicit\nhosted-provisioning custody grants are separate from ordinary encrypted sync.\n\n[Credential sync and runtime coverage →](docs/credential-sync.md) ·\n[Credentials guide →](docs/credentials-guide.md) ·\n[Key storage →](docs/key-management.md)\n\n### Let events start the work\n\nAutomations turn recurring or incoming work into sessions you can join,\nsupervise, and review. Choose the repository, machine, agent, model, approval\nmode, sandbox setting, and maximum attempts.\n\n| Trigger | Example workflow |\n|---|---|\n| **GitHub issues and mentions** | Label an issue `bivy` or `bivy/<machine>`, or mention your Bivy GitHub App, to work toward a pull request. |\n| **Failed CI** | Match a failed workflow, ask the agent to reproduce it, make a fix, and run the affected checks. |\n| **Linear** | Label an issue to start work without copying its description into an agent. |\n| **Slack** | Send a request from the conversation where the work came up. |\n| **Schedules** | Run a weekly dependency review, recurring maintenance, or a one-time task. |\n| **Signed webhooks** | Connect alerts, internal tools, or your own event sources. |\n\nConfigure automations in the app or version them with your repository in\n`.bivy/automations.yaml`:\n\n```bash\nbivy automation init\n# Edit the generated definition for your repository and workflow.\nbivy automation validate\nbivy automation test --event .bivy/events/failed-ci.yaml # supply a local event fixture\nbivy automation apply\n```\n\nOr delegate a one-off job without creating an automation:\n\n```bash\nbivy runs start \"Review outdated dependencies and propose a small, tested update.\"\nbivy runs wait <id>\n```\n\nRuns keep routing and lifecycle evidence, check results, and output references\nin a reviewable Receipt. For unattended issue work, Bivy runs declared repository\nchecks after the agent's turn; failed required checks fail the run even if the\nagent reports success. A completed process alone is not proof that the task\nsucceeded.\n\n[Automation recipes →](docs/capability-recipes.md#let-events-start-runs) ·\n[Automations as code →](docs/automations-as-code.md) ·\n[Run outcomes and reliability limits →](docs/automation-runs.md)\n\n### Start at your desk. Continue anywhere.\n\nOpen the same session in the browser, phone PWA, or terminal. Watch work live,\nanswer questions, approve supported tool calls, or stop the agent.\n\n- Send screenshots, images, logs, and other files from your phone.\n- Download reports and artifacts the agent creates.\n- Publish [session apps](docs/apps.md) with web and CLI/TUI views using\n `bivy app publish bivy.app.json`. Linked machines automatically discover web\n preview delivery through Bivy's relay—no per-machine domains, certificates or\n public ports. Terminal views use the existing connection.\n- Use voice input and read-aloud where supported; provider-backed voice may\n send audio or text to the selected provider.\n- Keep a native terminal workflow or use structured chat, depending on the agent.\n\n```bash\nbivy run claude --no-follow # start without attaching\nbivy open # open the web app\nbivy resume # return to the session in your terminal\nbivy link # pair a device directly via QR\n```\n\nNo phone app installation is required. Open [app.bivy.sh](https://app.bivy.sh)\nin your browser; adding it to your home screen is optional.\n\n[Remote access →](docs/remote-access.md) ·\n[Voice, files, and terminal recipes →](docs/capability-recipes.md)\n\n## Get started\n\n### Install\n\nBivy supports **macOS and Linux with Node.js 20+**. The installer installs the\n`@bivy/bivy` package, runs guided setup, and starts a launchd or systemd service:\n\n```bash\ncurl -fsSL https://bivy.sh/install.sh | bash\n```\n\nSetup helps you choose an agent and configure remote access. Existing agents\nkeep their command, login, and configuration. The installer may use `sudo` to\ninstall missing Node.js or Debian/Ubuntu build tools, but never for `npm install`. To inspect it first,\ndownload it with `curl -fsSL https://bivy.sh/install.sh -o install.sh`.\n\nAlready have Node.js and want to avoid sudo?\n\n```bash\nnpm install -g @bivy/bivy\nbivy setup\n```\n\nThen try one small task:\n\n```bash\ncd your-repo\nbivy run claude\n# Ask: \"Explain this repo and make one small, safe improvement. Run the relevant checks.\"\nbivy open\n```\n\nOpen that same session on your phone while it runs. Once that works, connect\nanother machine or add your first automation.\n\n**Local-only works too.** `bivy run`, `bivy resume`, and `bivy sessions` need no\naccount or server. Choose **local only for now** during setup; use `bivy login`\nlater. Browser and phone access need a hosted or self-hosted control plane;\nthe node itself does not serve a web UI.\n\n[Full quickstart →](docs/quickstart.md) ·\n[Installer options, service management, and uninstall →](docs/install.md)\n\n### Choose hosted or self-hosted\n\n| Option | What you get |\n|---|---|\n| **Free Cloud — $0** | Every launch feature, including automations; 10 new remote sessions per rolling seven days. No credit card required. |\n| **Cloud — $15/month** | The same features with unlimited remote sessions. |\n| **Self-hosted Core** | Operate the app, control plane, and relay yourself, with no Bivy usage limits. |\n\nManual and automated sessions share the Cloud allowance. Resuming existing\nsessions and viewing history do not consume it. Agent subscriptions and model\nprovider charges are separate. See [current pricing](https://bivy.sh#pricing).\n\n**Self-host anywhere:** deploy the public control-plane (including the web app)\nand relay images with Postgres and [a small set of environment variables](docs/deploy-images.md).\nYour server or container platform handles HTTPS. Set up owner access in the\nbrowser—no SSH, external authentication provider, or Bivy Cloud account required.\nFor a bare VPS, the [Compose installer](docs/self-host-quickstart.md) automates the\nsame stack. These onboarding features require a release containing them.\n\nStart on Cloud and self-host later if you prefer. Deploy the stack, reconnect\nmachines with `bivy relay:setup`, and pair devices to your server. This is not a\none-click migration of your Cloud account; your local repos and agent\nconfiguration stay in place.\n\n```bash\nbivy relay:setup \\\n --control-plane https://bivy.example.com \\\n --relay wss://relay.example.com\n```\n\nSelf-hosting is community-supported: you own TLS, backups, upgrades, and\nhardening. Public multi-architecture images are available as\n`ghcr.io/bivysh/bivy-control-plane` and `ghcr.io/bivysh/bivy-relay`; pin a release\nversion or full commit SHA.\n\n[Deploy the images anywhere →](docs/deploy-images.md) ·\n[Optional VPS installer →](docs/self-host-quickstart.md) ·\n[Operations reference →](docs/self-host.md)\n\n## Architecture\n\nYour environment, with clear security boundaries:\n\n```text\nYour machine Hosted or self-hosted\n┌──────────────────────┐ ┌──────────────────────┐\n│ Node daemon │──outbound──▶│ Relay │\n│ Agents, repos, tools │ │ Encrypted frames │\n│ Local credentials │ └──────────┬───────────┘\n└──────────────────────┘ │\n Browser / phone\n + control plane\n (app, accounts, metadata)\n```\n\n- **Execution stays on your machine.** Bivy Cloud does not run your agents.\n Your model provider still sees whatever the agent sends it.\n- **Interactive traffic is end-to-end encrypted** between the node and paired\n devices. The relay forwards opaque frames; your node dials out, so no inbound\n public port is required.\n- **Ordinary credential sync uploads ciphertext, not plaintext keys.**\n Supported credentials and recovery limits are documented separately.\n- **Encryption is not universal across integrations.** Slack commands and\n generic webhook instructions reach the control plane in plaintext. Do not\n put secrets in them. Routing and bounded run metadata are also visible there.\n- **Device authorization matters.** QR pairing authorizes a device directly\n through the node. Hosted account pairing trusts the control plane to authorize\n devices and serve the web app that holds client keys.\n- **Bivy is not an OS-level sandbox.** The default approval mode is\n `autonomous`; protection depends on the runtime. Some agents enforce sandbox\n tiers, while process agents may run with your full user permissions.\n Heuristic tool checks help prevent accidents but are not isolation.\n\nReview the runtime's Protection label and configure approval/sandbox settings\nfor the task, especially before enabling unattended work.\n\n[Security model and known limitations →](docs/security-model.md) ·\n[Runtime protection matrix →](docs/runtime-support-matrix.md) ·\n[Configuration →](docs/configuration.md)\n\n## Agents and everyday commands\n\n**Claude Code, Codex, Pi, and OpenCode are release-tested.** Additional adapters\ninclude Gemini CLI, Qwen Code, Goose, Aider, Cline, Crush, Cursor, GitHub Copilot,\nGrok, Amp, Auggie, Droid, Continue, Kilo Code, and Rovo Dev. Installation,\nresume, model selection, and tool protection vary—see the\n[support matrix](docs/runtime-support-matrix.md) and [agent guides](docs/agents/README.md).\n\nRun an arbitrary command with `bivy run -- ./your-agent --flags`, register a\nreusable entry with `bivy agent add`, or package a declarative integration with\nexperimental [plugins](docs/plugins.md).\n\n```bash\nbivy run claude # launch a durable session; also codex, pi, opencode\nbivy sessions # list live and saved sessions\nbivy resume # resume the most recent session\nbivy open # open the web app (requires remote setup)\nbivy nodes # list connected account machines\nbivy runs list # inspect delegated work\nbivy automation init # scaffold repo-owned automations\nbivy provider login # connect supported model credentials\nbivy agent add # register an ACP or process agent\nbivy doctor # check installation and connectivity\nbivy logs -f # follow node logs\nbivy update # update and restart the service\n```\n\n`bivy update` uses your original installation method and waits for an active\nturn to finish before restarting. Use `--force` to skip that wait.\n\n[CLI reference →](docs/cli-reference.md) ·\n[Node and project configuration →](docs/config-as-code.md) ·\n[GitHub setup →](docs/github-setup.md) ·\n[Linear setup →](docs/linear-work-queue.md)\n\n## Development and contributions\n\n```bash\npnpm install\npnpm run dev # node daemon on http://localhost:4317\npnpm run dev:web # web client dev server\n```\n\n| Directory | Contents |\n|---|---|\n| `src/`, `bin/` | Node daemon, CLI, runtime adapters, sessions, approvals, secrets |\n| `packages/core/` | Shared protocol, pairing, and wire format |\n| `packages/web/`, `packages/ui/` | React PWA and shared design system |\n| `services/relay/` | Self-hostable encrypted relay |\n| `services/control-plane/` | Self-hostable control plane |\n| `deploy/` | Deployment examples |\n\n```bash\npnpm run typecheck\npnpm run typecheck:web\npnpm run lint\npnpm run test:unit\npnpm run test:core\npnpm run check:licenses\npnpm run check:secrets\n```\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for the development workflow. Releases\nare published from CI with provenance attestations; see\n[release verification](docs/releasing.md).\n\n**Found a security issue?** Use\n[GitHub private vulnerability reporting](https://github.com/bivysh/bivy/security/advisories/new),\nnot a public issue. See [SECURITY.md](SECURITY.md).\n\n### In development—not available at launch\n\nAutomatically provisioned, short-lived **ephemeral machines** are in development\nfor hosted and bring-your-own-cloud deployments. Neither path is ready or\nsupported for this launch. Use an existing computer or server you operate.\nExperimental provisioning has different credential-custody and encryption\nboundaries; see the [provisioning trust model](docs/hosted-provisioning-trust-model.md).\n\n## License\n\nEverything in this repository—node, CLI, web/PWA, relay, and control plane—is\nfree and open-source **AGPL-3.0-only Core**, with no Bivy usage limits. You may\nuse, modify, and self-host it under that license. If users interact with your\nmodified version over a network, section 13 requires you to offer its\ncorresponding source. See [LICENSE](LICENSE).\n\nBivy Cloud is the hosted operation of that stack plus billing and plans, in a\nseparate private repository. Contributions use the\n[DCO](CONTRIBUTING.md#certificate-of-origin); there is no CLA.\n",
|
|
74
|
+
"readme": "# Bivy\n\n[](https://www.npmjs.com/package/@bivy/bivy)\n[](LICENSE)\n[](https://nodejs.org)\n\n**Build, try, and review apps from your phone. Your coding agent and dev\nenvironment stay on your own machines.**\n\nBivy is an open-source remote development environment built around coding\nagents. Ask for a change, try the running app, and point to or draw on what\nneeds fixing. Send that feedback to the agent and try again—all in the same\nsession, without going back to your computer.\n\nLive previews bring your app to your phone or browser without deploying it to\nRender, building a Docker image, or setting up a separate preview server.\nShare a preview link so someone else can try it and leave notes, too.\n\nKeep Claude Code, Codex, Pi, OpenCode, or another supported agent. Keep your\nrepos, tools, databases, and development environment. Bivy connects them to\nchat, a terminal, app previews, and code review wherever you are. Start work\nyourself, or let an issue, CI failure, message, schedule, or webhook start it.\n\n**[Start free on Bivy Cloud](https://app.bivy.sh)** ·\n**[Quickstart](docs/quickstart.md)** ·\n**[Documentation](docs/README.md)** ·\n**[Self-host](docs/deploy-images.md)** ·\n**[Website](https://bivy.sh)**\n\n**Recommended:** sign in at [app.bivy.sh](https://app.bivy.sh), then copy your\npersonalized **Connect a Machine** command into a terminal on your Mac or Linux\ncomputer. It installs and enrolls the machine without another Bivy login. The\nbrowser connects automatically; choose a repository and send your first task\nright there.\n\nPrefer starting from the terminal?\n\n```bash\ncurl -fsSL https://bivy.sh/install.sh | bash # install + guided setup\ncd your-repo\nbivy run claude # or codex, pi, opencode\nbivy open # continue in the web app (needs remote setup)\n```\n\nBivy Cloud hosts the app, control plane, and relay—not the machines running your\nagents. Connect a Mac, Linux computer, or existing server and bring your own\nagent subscription, model API key, or local model. You can also self-host the\nentire remote-access stack.\n\n> **Bivy is 0.x software.** Claude Code, Codex, Pi, and OpenCode are the\n> release-tested paths. Credential sync, resume, handoffs, approvals, and\n> sandboxing depend on the runtime. See the\n> [runtime support matrix](docs/runtime-support-matrix.md).\n\n## Build → preview → mark up → iterate\n\nRemote chat lets you ask an agent for a change. Bivy also lets you **use what\nit built and show it what to fix**, without a separate deployment step.\n\n1. **Ask for a change.** The agent works in your repo with your existing tools\n and local services.\n2. **Try the app.** Open a live preview from the session. Use the running app,\n not just a screenshot of what the agent says it finished. Bivy can discover\n dev servers running in the session workspace; tap **Preview** to open one.\n3. **Mark up what needs work.** Point at an element or circle and draw on the\n preview. Add a note, then send the draft to the agent with the element and\n page context. Marked-up screenshots and before/after comparison are available\n when agent screenshots are enabled.\n4. **Iterate and review.** Try the next version, inspect the diff, review checks,\n and decide when the work is ready—not just when the agent stops.\n5. **Bring someone else into the review.** Copy a public preview link so they\n can use the app without a Bivy account and leave notes on specific elements.\n Bring their notes into the session when you're ready to act on them.\n\nOn Bivy Cloud, preview delivery is built in: no per-app domains, certificates,\npublic ports, or tunnels to configure. Self-hosters configure preview delivery\nonce for their Bivy deployment, not for every app. The app still needs its normal\nbuild or dev-server setup, and **the machine serving it must stay awake and\nonline**. These are development previews, not production hosting.\n\n**Share deliberately:** anyone with a preview link can use that app, including\nits live backend. Links expire after 24 hours and can be revoked sooner.\nReviewer notes aren't sent to the agent automatically; you send them or explicitly\nallow agent access. Preview traffic uses HTTPS through the preview relay, not\nsession end-to-end encryption; the relay operator can see it.\n\n[App previews, visual feedback, and sharing →](docs/apps.md)\n\n## Your agents and machines, one workspace\n\n| Capability | What it means for you |\n|---|---|\n| **One workspace, multiple agents** | Use different agents and models for different tasks without maintaining a separate workflow for each. |\n| **Your machines and environment** | Work beside your existing repos, dev servers, databases, private networks, toolchains, and GPUs. |\n| **Automations and triggers** | Let issues, failed CI, messages, schedules, and webhooks start work instead of copying requests into a chat. |\n| **Encrypted key and OAuth sync** | Reuse Bivy-managed provider credentials across enrolled machines and compatible runtimes, with less repeated setup. |\n| **Live sessions from anywhere** | Build and review from your phone, browser, or terminal; answer questions and approve supported actions in the same session. |\n| **Live app previews** | Try the running app without deploying it to a separate hosting service. |\n| **Visual feedback and sharing** | Point, draw, and send specific feedback to the agent; share a preview link for outside review. |\n| **Reviewable results** | Inspect the app, changes, declared checks, artifacts, and pull requests—not just an agent's claim that it finished. |\n| **Hosted convenience or self-hosting** | Use Bivy Cloud for managed remote access, or run the same open-source core yourself. |\n\n## One workflow, from trigger to review\n\n```text\nPrompt · GitHub issue · CI failure · Linear · Slack · Schedule · Webhook\n │\n ▼\n Choose machine + agent + model\n + supported credentials\n │\n ▼\n Live agent session\n Join · steer · approve · stop\n │\n ▼\n Try app · inspect changes · checks\n │\n ▼\n Mark up · send feedback · iterate\n │\n ▼\n Share preview · review PR\n```\n\nA **Machine** is a computer or server you connect. A **Session** is live agent\nwork on that machine. A **Run** is delegated background work that creates a\nsession and tracks its outcome. An **Automation** is a reusable definition that\ncreates runs when an event matches.\n\nManual and automated work use the same kind of live session. You can join a run\nwhen it needs help rather than wait for a black-box job to finish.\n\n### Work in the environment you already have\n\nA clean cloud sandbox isn't always enough. Your agent may need the database\nrunning on localhost, an uncommitted change, an internal API behind your VPN,\nor a model running on your GPU. Bivy runs the agent where those things already\nexist, subject to that machine's permissions and the runtime's protection.\n\nConnect several machines to the same account: a laptop for interactive work,\na Linux server for background jobs, or a GPU box for local inference. Choose\nthe machine for each session or pin it in an automation. Repository runs can\nuse isolated Git worktrees without rebuilding the whole development environment.\n\n**The execution machine must stay awake and online.** To close your laptop and\nleave work running, run the agent on a different, always-on machine.\n\n[Environment and multi-machine recipes →](docs/capability-recipes.md)\n\n### Use multiple agents, not multiple disconnected workflows\n\nRun Claude Code for one task, Codex for another, and Pi or OpenCode where they\nfit. Bivy supplies the shared session, remote-access, automation, and review\nsurfaces; your chosen agent still does the coding and uses your model provider.\n\n- Choose an agent and, where supported, a model for each session or run.\n- Import existing Claude Code and Codex sessions.\n- Fork or move work to another agent or machine when a different setup fits\n better. Continuation fidelity varies: some paths preserve native history,\n while others replay portable turns or seed the destination with context.\n- Use agent-native logins, Bivy-managed credentials, or local inference.\n Bivy's custom OpenAI-compatible endpoint registry currently feeds Pi;\n other agents may need their own provider configuration.\n- Register your own ACP or headless process agent with `bivy agent add`.\n\nBivy does not replace your agent, provide model inference, or make every agent's\nfeatures identical. Consult the [support matrix](docs/runtime-support-matrix.md)\nand [handoff recipes](docs/capability-recipes.md#fork-or-move-a-session).\n\n### Less signing in. Less copying secrets.\n\nBivy syncs **Bivy-managed API keys and supported OAuth credentials** across\nenrolled machines for compatible runtimes. Connect supported credentials once\nand reuse them where you run work, rather than manually distributing keys to\neach machine.\n\nFor ordinary account sync, credentials are encrypted on the node before upload.\nThe control plane stores ciphertext and wrapped-key metadata; enrolled nodes\nshare access by wrapping the vault key to one another. Bivy Cloud does not\nreceive plaintext credentials through this sync path.\n\nYou can also keep credentials local, use labeled keys and project presets, or\nreference environment variables and 1Password instead of embedding secrets in\nconfiguration:\n\n```bash\nbivy provider login\nbivy credentials add anthropic work\nbivy secrets ref github.repo-token op://Bivy/GitHub/repo-token\n```\n\n**Not every CLI login syncs.** Native agent logins may still be per-machine;\nGitHub App private-key sync is separately opt-in. If you lose every node and\ndevice able to unwrap a vault, you must sign in to providers again. Explicit\nhosted-provisioning custody grants are separate from ordinary encrypted sync.\n\n[Credential sync and runtime coverage →](docs/credential-sync.md) ·\n[Credentials guide →](docs/credentials-guide.md) ·\n[Key storage →](docs/key-management.md)\n\n### Let events start the work\n\nAutomations turn recurring or incoming work into sessions you can join,\nsupervise, and review. Choose the repository, machine, agent, model, approval\nmode, sandbox setting, and maximum attempts.\n\n| Trigger | Example workflow |\n|---|---|\n| **GitHub issues and mentions** | Label an issue `bivy` or `bivy/<machine>`, or mention your Bivy GitHub App, to work toward a pull request. |\n| **Failed CI** | Match a failed workflow, ask the agent to reproduce it, make a fix, and run the affected checks. |\n| **Linear** | Label an issue to start work without copying its description into an agent. |\n| **Slack** | Send a request from the conversation where the work came up. |\n| **Schedules** | Run a weekly dependency review, recurring maintenance, or a one-time task. |\n| **Signed webhooks** | Connect alerts, internal tools, or your own event sources. |\n\nConfigure automations in the app or version them with your repository in\n`.bivy/automations.yaml`:\n\n```bash\nbivy automation init\n# Edit the generated definition for your repository and workflow.\nbivy automation validate\nbivy automation test --event .bivy/events/failed-ci.yaml # supply a local event fixture\nbivy automation apply\n```\n\nOr delegate a one-off job without creating an automation:\n\n```bash\nbivy runs start \"Review outdated dependencies and propose a small, tested update.\"\nbivy runs wait <id>\n```\n\nRuns keep routing and lifecycle evidence, check results, and output references\nin a reviewable Receipt. For unattended issue work, Bivy runs declared repository\nchecks after the agent's turn; failed required checks fail the run even if the\nagent reports success. A completed process alone is not proof that the task\nsucceeded.\n\n[Automation recipes →](docs/capability-recipes.md#let-events-start-runs) ·\n[Automations as code →](docs/automations-as-code.md) ·\n[Run outcomes and reliability limits →](docs/automation-runs.md)\n\n### Start at your desk. Continue anywhere.\n\nOpen the same session in the browser, phone PWA, or terminal. Watch work live,\nanswer questions, approve supported tool calls, or stop the agent.\n\n- Send screenshots, images, logs, and other files from your phone.\n- Download reports and artifacts the agent creates.\n- Open [session apps](docs/apps.md) from chat or the **Apps** menu: live web\n previews, desktop app views, and CLI/TUI tools. Agents can publish views with\n `bivy app publish bivy.app.json` and create share links with `bivy app share`.\n- Use voice input and read-aloud where supported; provider-backed voice may\n send audio or text to the selected provider.\n- Keep a native terminal workflow or use structured chat, depending on the agent.\n\n```bash\nbivy run claude --no-follow # start without attaching\nbivy open # open the web app\nbivy resume # return to the session in your terminal\nbivy link # pair a device directly via QR\n```\n\nNo phone app installation is required. Open [app.bivy.sh](https://app.bivy.sh)\nin your browser; adding it to your home screen is optional.\n\n[Remote access →](docs/remote-access.md) ·\n[Voice, files, and terminal recipes →](docs/capability-recipes.md)\n\n## Get started\n\n### Install\n\nBivy supports **macOS and Linux with Node.js 20+**. The installer installs the\n`@bivy/bivy` package, runs guided setup, and starts a launchd or systemd service:\n\n```bash\ncurl -fsSL https://bivy.sh/install.sh | bash\n```\n\nSetup helps you choose an agent and configure remote access. Existing agents\nkeep their command, login, and configuration. The installer may use `sudo` to\ninstall missing Node.js or Debian/Ubuntu build tools, but never for `npm install`. To inspect it first,\ndownload it with `curl -fsSL https://bivy.sh/install.sh -o install.sh`.\n\nAlready have Node.js and want to avoid sudo?\n\n```bash\nnpm install -g @bivy/bivy\nbivy setup\n```\n\nThen try one small task:\n\n```bash\ncd your-repo\nbivy run claude\n# Ask: \"Explain this repo and make one small, safe improvement. Run the relevant checks.\"\nbivy open\n```\n\nOpen that same session on your phone while it runs. For a web app, ask the agent\nto start its dev server, then open **Apps → Running in this workspace → Preview**.\nTry a page, point to something you'd change, and send the feedback back to the\nagent. No separate preview deployment needed.\n\nOnce that works, share a preview for review, connect another machine, or add\nyour first automation.\n\n**Local-only works too.** `bivy run`, `bivy resume`, and `bivy sessions` need no\naccount or server. Choose **local only for now** during setup; use `bivy login`\nlater. Browser and phone access need a hosted or self-hosted control plane;\nthe node itself does not serve a web UI.\n\n[Full quickstart →](docs/quickstart.md) ·\n[Installer options, service management, and uninstall →](docs/install.md)\n\n### Choose hosted or self-hosted\n\n| Option | What you get |\n|---|---|\n| **Free Cloud — $0** | Every launch feature, including automations; 10 new remote sessions per rolling seven days. No credit card required. |\n| **Cloud — $15/month** | The same features with unlimited remote sessions. |\n| **Self-hosted Core** | Operate the app, control plane, and relay yourself, with no Bivy usage limits. |\n\nManual and automated sessions share the Cloud allowance. Resuming existing\nsessions and viewing history do not consume it. Agent subscriptions and model\nprovider charges are separate. See [current pricing](https://bivy.sh#pricing).\n\n**Self-host anywhere:** deploy the public control-plane (including the web app)\nand relay images with Postgres and [a small set of environment variables](docs/deploy-images.md).\nYour server or container platform handles HTTPS. Set up owner access in the\nbrowser—no SSH, external authentication provider, or Bivy Cloud account required.\nFor a bare VPS, the [Compose installer](docs/self-host-quickstart.md) automates the\nsame stack. These onboarding features require a release containing them.\n\nStart on Cloud and self-host later if you prefer. Deploy the stack, reconnect\nmachines with `bivy relay:setup`, and pair devices to your server. This is not a\none-click migration of your Cloud account; your local repos and agent\nconfiguration stay in place.\n\n```bash\nbivy relay:setup \\\n --control-plane https://bivy.example.com \\\n --relay wss://relay.example.com\n```\n\nSelf-hosting is community-supported: you own TLS, backups, upgrades, and\nhardening. Public multi-architecture images are available as\n`ghcr.io/bivysh/bivy-control-plane` and `ghcr.io/bivysh/bivy-relay`; pin a release\nversion or full commit SHA.\n\n[Deploy the images anywhere →](docs/deploy-images.md) ·\n[Optional VPS installer →](docs/self-host-quickstart.md) ·\n[Operations reference →](docs/self-host.md)\n\n## Architecture\n\nYour environment, with clear security boundaries:\n\n```text\nYour machine Hosted or self-hosted\n┌──────────────────────┐ ┌──────────────────────┐\n│ Node daemon │──outbound──▶│ Relay │\n│ Agents, repos, tools │ │ Encrypted frames │\n│ Local credentials │ └──────────┬───────────┘\n└──────────────────────┘ │\n Browser / phone\n + control plane\n (app, accounts, metadata)\n```\n\n- **Execution stays on your machine.** Bivy Cloud does not run your agents.\n Your model provider still sees whatever the agent sends it.\n- **Interactive session traffic is end-to-end encrypted** between the node and\n paired devices. The relay forwards opaque session frames; your node dials out,\n so no inbound public port is required.\n- **App previews have a separate security boundary.** Preview traffic uses HTTPS\n and an outbound tunnel, not session E2E encryption. The preview ingress/relay\n operator can see it. Public preview links grant anyone holding them access to\n that view and its live backend until expiry or revocation. See\n [preview security and sharing](docs/apps.md#runtime-and-security-boundaries).\n- **Ordinary credential sync uploads ciphertext, not plaintext keys.**\n Supported credentials and recovery limits are documented separately.\n- **Encryption is not universal across integrations.** Slack commands and\n generic webhook instructions reach the control plane in plaintext. Do not\n put secrets in them. Routing and bounded run metadata are also visible there.\n- **Device authorization matters.** QR pairing authorizes a device directly\n through the node. Hosted account pairing trusts the control plane to authorize\n devices and serve the web app that holds client keys.\n- **Bivy is not an OS-level sandbox.** The default approval mode is\n `autonomous`; protection depends on the runtime. Some agents enforce sandbox\n tiers, while process agents may run with your full user permissions.\n Heuristic tool checks help prevent accidents but are not isolation.\n\nReview the runtime's Protection label and configure approval/sandbox settings\nfor the task, especially before enabling unattended work.\n\n[Security model and known limitations →](docs/security-model.md) ·\n[Runtime protection matrix →](docs/runtime-support-matrix.md) ·\n[Configuration →](docs/configuration.md)\n\n## Agents and everyday commands\n\n**Claude Code, Codex, Pi, and OpenCode are release-tested.** Additional adapters\ninclude Gemini CLI, Qwen Code, Goose, Aider, Cline, Crush, Cursor, GitHub Copilot,\nGrok, Amp, Auggie, Droid, Continue, Kilo Code, and Rovo Dev. Installation,\nresume, model selection, and tool protection vary—see the\n[support matrix](docs/runtime-support-matrix.md) and [agent guides](docs/agents/README.md).\n\nRun an arbitrary command with `bivy run -- ./your-agent --flags`, register a\nreusable entry with `bivy agent add`, or package a declarative integration with\nexperimental [plugins](docs/plugins.md).\n\n```bash\nbivy run claude # launch a durable session; also codex, pi, opencode\nbivy sessions # list live and saved sessions\nbivy resume # resume the most recent session\nbivy open # open the web app (requires remote setup)\nbivy nodes # list connected account machines\nbivy runs list # inspect delegated work\nbivy automation init # scaffold repo-owned automations\nbivy provider login # connect supported model credentials\nbivy agent add # register an ACP or process agent\nbivy doctor # check installation and connectivity\nbivy logs -f # follow node logs\nbivy update # update and restart the service\n```\n\n`bivy update` uses your original installation method and waits for an active\nturn to finish before restarting. Use `--force` to skip that wait.\n\n[CLI reference →](docs/cli-reference.md) ·\n[Node and project configuration →](docs/config-as-code.md) ·\n[GitHub setup →](docs/github-setup.md) ·\n[Linear setup →](docs/linear-work-queue.md)\n\n## Development and contributions\n\n```bash\npnpm install\npnpm run dev # node daemon on http://localhost:4317\npnpm run dev:web # web client dev server\n```\n\n| Directory | Contents |\n|---|---|\n| `src/`, `bin/` | Node daemon, CLI, runtime adapters, sessions, approvals, secrets |\n| `packages/core/` | Shared protocol, pairing, and wire format |\n| `packages/web/`, `packages/ui/` | React PWA and shared design system |\n| `services/relay/` | Self-hostable encrypted relay |\n| `services/control-plane/` | Self-hostable control plane |\n| `deploy/` | Deployment examples |\n\n```bash\npnpm run typecheck\npnpm run typecheck:web\npnpm run lint\npnpm run test:unit\npnpm run test:core\npnpm run check:licenses\npnpm run check:secrets\n```\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for the development workflow. Releases\nare published from CI with provenance attestations; see\n[release verification](docs/releasing.md).\n\n**Found a security issue?** Use\n[GitHub private vulnerability reporting](https://github.com/bivysh/bivy/security/advisories/new),\nnot a public issue. See [SECURITY.md](SECURITY.md).\n\n### In development—not available at launch\n\nAutomatically provisioned, short-lived **ephemeral machines** are in development\nfor hosted and bring-your-own-cloud deployments. Neither path is ready or\nsupported for this launch. Use an existing computer or server you operate.\nExperimental provisioning has different credential-custody and encryption\nboundaries; see the [provisioning trust model](docs/hosted-provisioning-trust-model.md).\n\n## License\n\nEverything in this repository—node, CLI, web/PWA, relay, and control plane—is\nfree and open-source **AGPL-3.0-only Core**, with no Bivy usage limits. You may\nuse, modify, and self-host it under that license. If users interact with your\nmodified version over a network, section 13 requires you to offer its\ncorresponding source. See [LICENSE](LICENSE).\n\nBivy Cloud is the hosted operation of that stack plus billing and plans, in a\nseparate private repository. Contributions use the\n[DCO](CONTRIBUTING.md#certificate-of-origin); there is no CLA.\n",
|
|
75
75
|
"readmeFilename": "README.md"
|
|
76
76
|
}
|