mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-19 02:01:32 +00:00
feat(coding-agent): add Android/Termux support
- Make @mariozechner/clipboard an optional dependency - Lazy-load clipboard module with graceful fallback - Add Termux clipboard support via termux-clipboard-set - Skip image clipboard on Termux (not supported) fixes #1164
This commit is contained in:
parent
bc3fda518d
commit
cb850676e7
3 changed files with 33 additions and 4 deletions
|
|
@ -39,7 +39,6 @@
|
||||||
"prepublishOnly": "npm run clean && npm run build"
|
"prepublishOnly": "npm run clean && npm run build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mariozechner/clipboard": "^0.3.2",
|
|
||||||
"@mariozechner/jiti": "^2.6.2",
|
"@mariozechner/jiti": "^2.6.2",
|
||||||
"@mariozechner/pi-agent-core": "^0.50.9",
|
"@mariozechner/pi-agent-core": "^0.50.9",
|
||||||
"@mariozechner/pi-ai": "^0.50.9",
|
"@mariozechner/pi-ai": "^0.50.9",
|
||||||
|
|
@ -56,6 +55,9 @@
|
||||||
"proper-lockfile": "^4.1.2",
|
"proper-lockfile": "^4.1.2",
|
||||||
"yaml": "^2.8.2"
|
"yaml": "^2.8.2"
|
||||||
},
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@mariozechner/clipboard": "^0.3.2"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/diff": "^7.0.2",
|
"@types/diff": "^7.0.2",
|
||||||
"@types/ms": "^2.1.0",
|
"@types/ms": "^2.1.0",
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,22 @@
|
||||||
import Clipboard from "@mariozechner/clipboard";
|
|
||||||
import { spawnSync } from "child_process";
|
import { spawnSync } from "child_process";
|
||||||
|
import { createRequire } from "module";
|
||||||
|
|
||||||
import { loadPhoton } from "./photon.js";
|
import { loadPhoton } from "./photon.js";
|
||||||
|
|
||||||
|
type ClipboardModule = {
|
||||||
|
hasImage: () => boolean;
|
||||||
|
getImageBinary: () => Promise<Array<number>>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
let Clipboard: ClipboardModule | null = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Clipboard = require("@mariozechner/clipboard") as ClipboardModule;
|
||||||
|
} catch {
|
||||||
|
Clipboard = null;
|
||||||
|
}
|
||||||
|
|
||||||
export type ClipboardImage = {
|
export type ClipboardImage = {
|
||||||
bytes: Uint8Array;
|
bytes: Uint8Array;
|
||||||
mimeType: string;
|
mimeType: string;
|
||||||
|
|
@ -168,12 +182,16 @@ export async function readClipboardImage(options?: {
|
||||||
const env = options?.env ?? process.env;
|
const env = options?.env ?? process.env;
|
||||||
const platform = options?.platform ?? process.platform;
|
const platform = options?.platform ?? process.platform;
|
||||||
|
|
||||||
|
if (env.TERMUX_VERSION) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
let image: ClipboardImage | null = null;
|
let image: ClipboardImage | null = null;
|
||||||
|
|
||||||
if (platform === "linux" && isWaylandSession(env)) {
|
if (platform === "linux" && isWaylandSession(env)) {
|
||||||
image = readClipboardImageViaWlPaste() ?? readClipboardImageViaXclip();
|
image = readClipboardImageViaWlPaste() ?? readClipboardImageViaXclip();
|
||||||
} else {
|
} else {
|
||||||
if (!Clipboard.hasImage()) {
|
if (!Clipboard || !Clipboard.hasImage()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,16 @@ export function copyToClipboard(text: string): void {
|
||||||
} else if (p === "win32") {
|
} else if (p === "win32") {
|
||||||
execSync("clip", options);
|
execSync("clip", options);
|
||||||
} else {
|
} else {
|
||||||
// Linux - try wl-copy for Wayland, fall back to xclip/xsel for X11
|
// Linux. Try Termux, Wayland, or X11 clipboard tools.
|
||||||
|
if (process.env.TERMUX_VERSION) {
|
||||||
|
try {
|
||||||
|
execSync("termux-clipboard-set", options);
|
||||||
|
return;
|
||||||
|
} catch {
|
||||||
|
// Fall back to Wayland or X11 tools.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const isWayland = isWaylandSession();
|
const isWayland = isWaylandSession();
|
||||||
if (isWayland) {
|
if (isWayland) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue