hypeframe 0.5.0 → 0.6.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 +26 -7
- package/dist/index.js +592 -330
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -213,7 +213,6 @@ var id = {
|
|
|
213
213
|
"agent.loggingIn": "Masuk akun {name}...",
|
|
214
214
|
"agent.loggedIn": "{name} siap. Buka HypeFrame Web lalu pilih {name} di Asisten (mesin harus menyala).",
|
|
215
215
|
"agent.loginFailed": "{name} belum bisa dipakai: masuk akun belum berhasil. Coba lagi dari menu Asisten AI.",
|
|
216
|
-
"agent.claudeKey": "Claude Code di HypeFrame memakai kunci API Anthropic (console.anthropic.com). Langganan Pro/Max hanya boleh dipakai di aplikasi Anthropic sendiri.",
|
|
217
216
|
"agent.askKey": "Tempel {name}",
|
|
218
217
|
"agent.removed": "{name} dilepas dari mesin ini.",
|
|
219
218
|
"agent.unknown": "Agen {id} tidak didukung. Pilihan: {list}",
|
|
@@ -221,6 +220,13 @@ var id = {
|
|
|
221
220
|
"agent.webHint": "Mengobrol dengan agen dilakukan di HypeFrame Web, halaman Asisten, selama mesin menyala.",
|
|
222
221
|
"agent.toolNoTab": "Agen memanggil alat HypeFrame, tapi tab HypeFrame Web tidak terbuka. Buka HypeFrame Web lalu kirim pesannya lagi.",
|
|
223
222
|
"agent.toolNoAnswer": "Agen memanggil alat HypeFrame, tapi HypeFrame Web tidak menjawab. Pastikan tabnya terbuka.",
|
|
223
|
+
"agent.unpacking": "100% · membuka paket (di HP bisa sampai beberapa menit)...",
|
|
224
|
+
"linux.preparing": "Agen di HP berjalan di Linux mini (Ubuntu lewat proot). Menyiapkannya sekali saja, unduhan sekitar 100 MB...",
|
|
225
|
+
"linux.pkg": "Memasang proot-distro...",
|
|
226
|
+
"linux.distro": "Mengunduh Ubuntu...",
|
|
227
|
+
"linux.apt": "Menyiapkan Ubuntu (sertifikat dan curl)...",
|
|
228
|
+
"linux.ready": "Linux mini siap.",
|
|
229
|
+
"linux.openUrl": "Buka di browser HP: {url}",
|
|
224
230
|
"agent.keyFromShellAsk": "Pakai {name} yang sudah ada di terminal ini?",
|
|
225
231
|
"agent.keyFromShell": "Memakai {name} dari terminal ini (disimpan untuk agen ini saja).",
|
|
226
232
|
"agent.own": "{name} sudah terpasang di komputer ini ({path}); yang itu dipakai, tidak diunduh lagi.",
|
|
@@ -302,7 +308,7 @@ var id = {
|
|
|
302
308
|
"help.open": "buka HypeFrame Web di browser",
|
|
303
309
|
"help.doctor": "periksa Node, Chrome, ffmpeg, koneksi, ruang disk",
|
|
304
310
|
"help.bench": "ukur kecepatan render 720p dan 1080p",
|
|
305
|
-
"help.agent": "pasang dan masuk akun agen AI
|
|
311
|
+
"help.agent": "pasang dan masuk akun agen AI dengan langgananmu sendiri (Antigravity, Codex, OpenCode)",
|
|
306
312
|
"help.history": "render 24 jam terakhir",
|
|
307
313
|
"help.autostart": "nyalakan mesin saat masuk ke komputer",
|
|
308
314
|
"help.config": "nama perangkat, GPU, bahasa",
|
|
@@ -381,7 +387,6 @@ var en = {
|
|
|
381
387
|
"agent.loggingIn": "Logging in to {name}...",
|
|
382
388
|
"agent.loggedIn": "{name} is ready. Open HypeFrame Web and pick {name} in the Assistant (the engine must be running).",
|
|
383
389
|
"agent.loginFailed": "{name} is not usable yet: the login did not succeed. Try again from the AI assistant menu.",
|
|
384
|
-
"agent.claudeKey": "Claude Code in HypeFrame uses an Anthropic API key (console.anthropic.com). Pro/Max subscriptions may only be used in Anthropic’s own apps.",
|
|
385
390
|
"agent.askKey": "Paste {name}",
|
|
386
391
|
"agent.removed": "{name} removed from this machine.",
|
|
387
392
|
"agent.unknown": "Agent {id} is not supported. Choices: {list}",
|
|
@@ -389,6 +394,13 @@ var en = {
|
|
|
389
394
|
"agent.webHint": "Chatting with agents happens in HypeFrame Web, on the Assistant page, while the engine runs.",
|
|
390
395
|
"agent.toolNoTab": "An agent called a HypeFrame tool, but no HypeFrame Web tab is open. Open HypeFrame Web and send the message again.",
|
|
391
396
|
"agent.toolNoAnswer": "An agent called a HypeFrame tool, but HypeFrame Web did not answer. Make sure its tab is open.",
|
|
397
|
+
"agent.unpacking": "100% · unpacking (this can take a few minutes on a phone)...",
|
|
398
|
+
"linux.preparing": "Agents on a phone run in a Linux mini (Ubuntu under proot). Setting it up once, about 100 MB to download...",
|
|
399
|
+
"linux.pkg": "Installing proot-distro...",
|
|
400
|
+
"linux.distro": "Downloading Ubuntu...",
|
|
401
|
+
"linux.apt": "Preparing Ubuntu (certificates and curl)...",
|
|
402
|
+
"linux.ready": "Linux mini ready.",
|
|
403
|
+
"linux.openUrl": "Open in the phone browser: {url}",
|
|
392
404
|
"agent.keyFromShellAsk": "Use the {name} already set in this terminal?",
|
|
393
405
|
"agent.keyFromShell": "Using {name} from this terminal (saved for this agent only).",
|
|
394
406
|
"agent.own": "{name} is already installed on this computer ({path}); that copy is used, nothing is downloaded.",
|
|
@@ -470,7 +482,7 @@ var en = {
|
|
|
470
482
|
"help.open": "open HypeFrame Web in the browser",
|
|
471
483
|
"help.doctor": "check Node, Chrome, ffmpeg, network, disk space",
|
|
472
484
|
"help.bench": "measure render speed at 720p and 1080p",
|
|
473
|
-
"help.agent": "install and log in AI agents
|
|
485
|
+
"help.agent": "install and log in AI agents with your own subscription (Antigravity, Codex, OpenCode)",
|
|
474
486
|
"help.history": "renders from the last 24 hours",
|
|
475
487
|
"help.autostart": "start the engine when you sign in",
|
|
476
488
|
"help.config": "device name, GPU, language",
|
|
@@ -565,7 +577,7 @@ var log = {
|
|
|
565
577
|
};
|
|
566
578
|
|
|
567
579
|
// src/cli/commands/start.ts
|
|
568
|
-
import
|
|
580
|
+
import crypto8 from "node:crypto";
|
|
569
581
|
|
|
570
582
|
// ../protocol/src/index.ts
|
|
571
583
|
var PROTOCOL_VERSION = 1;
|
|
@@ -591,13 +603,13 @@ var EngineError = {
|
|
|
591
603
|
};
|
|
592
604
|
|
|
593
605
|
// src/agent/service.ts
|
|
594
|
-
import
|
|
595
|
-
import
|
|
596
|
-
import
|
|
606
|
+
import crypto3 from "node:crypto";
|
|
607
|
+
import fs10 from "node:fs";
|
|
608
|
+
import path7 from "node:path";
|
|
597
609
|
// package.json
|
|
598
610
|
var package_default = {
|
|
599
611
|
name: "hypeframe",
|
|
600
|
-
version: "0.
|
|
612
|
+
version: "0.6.0",
|
|
601
613
|
description: "Local engine for HypeFrame Web: code clips, video renders and AI agents run on your own machine; the web is just the view.",
|
|
602
614
|
keywords: [
|
|
603
615
|
"hypeframe",
|
|
@@ -666,7 +678,7 @@ You are running on the user's computer through the HypeFrame engine. The user ty
|
|
|
666
678
|
// src/agent/registry.ts
|
|
667
679
|
import { spawnSync } from "node:child_process";
|
|
668
680
|
import fs5 from "node:fs";
|
|
669
|
-
var SUPPORTED_AGENTS = ["
|
|
681
|
+
var SUPPORTED_AGENTS = ["antigravity-acp", "codex-acp", "opencode"];
|
|
670
682
|
var isSupported = (id) => SUPPORTED_AGENTS.includes(id);
|
|
671
683
|
var OFFICIAL_REGISTRY = "https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json";
|
|
672
684
|
var registryUrl = () => process.env.HYPEFRAME_ACP_REGISTRY || OFFICIAL_REGISTRY;
|
|
@@ -695,10 +707,168 @@ async function fetchRegistry() {
|
|
|
695
707
|
return (Array.isArray(j.agents) ? j.agents : []).filter(valid).map((a) => local ? a : { ...a, distribution: { ...a.distribution, local: undefined } });
|
|
696
708
|
}
|
|
697
709
|
|
|
698
|
-
// src/agent/
|
|
710
|
+
// src/agent/linux.ts
|
|
711
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
699
712
|
import crypto from "node:crypto";
|
|
713
|
+
import fs7 from "node:fs";
|
|
714
|
+
import path4 from "node:path";
|
|
715
|
+
|
|
716
|
+
// src/util/which.ts
|
|
700
717
|
import fs6 from "node:fs";
|
|
701
718
|
import path3 from "node:path";
|
|
719
|
+
function isAndroid() {
|
|
720
|
+
return process.platform === "android" || !!process.env.TERMUX_VERSION || (process.env.PREFIX ?? "").includes("/com.termux/");
|
|
721
|
+
}
|
|
722
|
+
function onPath(name) {
|
|
723
|
+
if (!/^[\w.@+-]{1,80}$/.test(name))
|
|
724
|
+
return null;
|
|
725
|
+
const file = process.platform === "win32" ? /\.exe$/i.test(name) ? name : `${name}.exe` : name;
|
|
726
|
+
for (const dir of (process.env.PATH || "").split(path3.delimiter).filter(Boolean)) {
|
|
727
|
+
const f = path3.join(dir, file);
|
|
728
|
+
try {
|
|
729
|
+
const st = fs6.statSync(f);
|
|
730
|
+
if (st.isFile() && (process.platform === "win32" || st.mode & 73))
|
|
731
|
+
return f;
|
|
732
|
+
} catch {}
|
|
733
|
+
}
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// src/agent/linux.ts
|
|
738
|
+
var DISTRO = "ubuntu";
|
|
739
|
+
var prefix = () => process.env.PREFIX || "/data/data/com.termux/files/usr";
|
|
740
|
+
function linuxDir() {
|
|
741
|
+
const d = path4.join(dataDir(), "linux");
|
|
742
|
+
fs7.mkdirSync(path4.join(d, "bin"), { recursive: true });
|
|
743
|
+
return d;
|
|
744
|
+
}
|
|
745
|
+
var rootfs = () => path4.join(prefix(), "var", "lib", "proot-distro", "installed-rootfs", DISTRO);
|
|
746
|
+
var readyFile = () => path4.join(linuxDir(), "siap");
|
|
747
|
+
var openFile = () => path4.join(linuxDir(), "buka-url");
|
|
748
|
+
var bridgeScript = () => path4.join(linuxDir(), "bin", "hf-mcp-bridge");
|
|
749
|
+
function linuxReady() {
|
|
750
|
+
return !!onPath("proot-distro") && fs7.existsSync(path4.join(rootfs(), "usr", "bin", "env")) && fs7.existsSync(readyFile());
|
|
751
|
+
}
|
|
752
|
+
var shQuote = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`;
|
|
753
|
+
var VAR = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
754
|
+
function linuxCommand(cmd, args, env = {}) {
|
|
755
|
+
const hf = dataDir();
|
|
756
|
+
const bin = path4.join(linuxDir(), "bin");
|
|
757
|
+
const vars = {
|
|
758
|
+
HOME: "/root",
|
|
759
|
+
LANG: "C.UTF-8",
|
|
760
|
+
DISPLAY: ":0",
|
|
761
|
+
BROWSER: path4.join(bin, "xdg-open"),
|
|
762
|
+
PATH: `${bin}:/root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`,
|
|
763
|
+
...env
|
|
764
|
+
};
|
|
765
|
+
const script = [
|
|
766
|
+
"#!/bin/bash",
|
|
767
|
+
"# HypeFrame: one command in the Linux mini (written by the engine)",
|
|
768
|
+
...Object.entries(vars).filter(([k]) => VAR.test(k)).map(([k, v]) => `export ${k}=${shQuote(v)}`),
|
|
769
|
+
`exec ${[cmd, ...args].map(shQuote).join(" ")}`,
|
|
770
|
+
""
|
|
771
|
+
].join(`
|
|
772
|
+
`);
|
|
773
|
+
const dir = path4.join(linuxDir(), "jalan");
|
|
774
|
+
fs7.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
775
|
+
const file = path4.join(dir, `${crypto.createHash("sha256").update(script).digest("hex").slice(0, 24)}.sh`);
|
|
776
|
+
if (!fs7.existsSync(file))
|
|
777
|
+
fs7.writeFileSync(file, script, { mode: 384 });
|
|
778
|
+
return ["proot-distro", ["login", DISTRO, "--shared-tmp", "--bind", `${hf}:${hf}`, "--", "/bin/bash", file]];
|
|
779
|
+
}
|
|
780
|
+
var BRIDGE_SH = `#!/bin/bash
|
|
781
|
+
# HypeFrame tools for an agent in the Linux mini: stdio MCP <-> the engine on 127.0.0.1 (HF_MCP_URL, HF_MCP_KUNCI)
|
|
782
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
783
|
+
[ -z "$line" ] && continue
|
|
784
|
+
out=$(printf '%s' "$line" | curl -sS --max-time 600 -X POST -H "authorization: Bearer $HF_MCP_KUNCI" -H 'content-type: application/json' --data-binary @- "$HF_MCP_URL" 2>/dev/null)
|
|
785
|
+
if [ $? -ne 0 ]; then
|
|
786
|
+
id=$(printf '%s' "$line" | sed -nE 's/.*"id"[[:space:]]*:[[:space:]]*("[^"]*"|[0-9]+).*/\\1/p')
|
|
787
|
+
[ -n "$id" ] && printf '{"jsonrpc":"2.0","id":%s,"error":{"code":-32000,"message":"The HypeFrame engine is not running on this phone."}}\\n' "$id"
|
|
788
|
+
continue
|
|
789
|
+
fi
|
|
790
|
+
[ -n "$out" ] && printf '%s\\n' "$out"
|
|
791
|
+
done
|
|
792
|
+
`;
|
|
793
|
+
function writeHelpers() {
|
|
794
|
+
const bin = path4.join(linuxDir(), "bin");
|
|
795
|
+
const open = `#!/bin/sh
|
|
796
|
+
# HypeFrame: open a link in the phone's browser (the engine watches this file)
|
|
797
|
+
[ -n "$1" ] || exit 0
|
|
798
|
+
printf '%s\\n' "$1" >> "${openFile()}"
|
|
799
|
+
`;
|
|
800
|
+
fs7.writeFileSync(path4.join(bin, "xdg-open"), open, { mode: 493 });
|
|
801
|
+
for (const n of ["x-www-browser", "www-browser", "sensible-browser"])
|
|
802
|
+
fs7.writeFileSync(path4.join(bin, n), open, { mode: 493 });
|
|
803
|
+
fs7.writeFileSync(bridgeScript(), BRIDGE_SH, { mode: 493 });
|
|
804
|
+
}
|
|
805
|
+
function prepareLinux(say = () => {
|
|
806
|
+
return;
|
|
807
|
+
}) {
|
|
808
|
+
const run = (cmd, args) => spawnSync2(cmd, args, { stdio: ["ignore", "inherit", "inherit"], env: { ...process.env, DEBIAN_FRONTEND: "noninteractive" } }).status === 0;
|
|
809
|
+
writeHelpers();
|
|
810
|
+
if (linuxReady())
|
|
811
|
+
return;
|
|
812
|
+
say("linux.preparing");
|
|
813
|
+
if (!onPath("proot-distro")) {
|
|
814
|
+
say("linux.pkg");
|
|
815
|
+
if (!run("pkg", ["install", "-y", "proot-distro"]))
|
|
816
|
+
throw new Error("pkg install proot-distro");
|
|
817
|
+
}
|
|
818
|
+
if (!fs7.existsSync(path4.join(rootfs(), "usr", "bin", "env"))) {
|
|
819
|
+
say("linux.distro");
|
|
820
|
+
if (!run("proot-distro", ["install", DISTRO]))
|
|
821
|
+
throw new Error(`proot-distro install ${DISTRO}`);
|
|
822
|
+
}
|
|
823
|
+
say("linux.apt");
|
|
824
|
+
const [cmd, args] = linuxCommand("/bin/sh", ["-c", "apt-get update -q && DEBIAN_FRONTEND=noninteractive apt-get install -y -q ca-certificates curl"]);
|
|
825
|
+
if (!run(cmd, args))
|
|
826
|
+
throw new Error("apt-get install ca-certificates curl");
|
|
827
|
+
fs7.writeFileSync(readyFile(), `${DISTRO}
|
|
828
|
+
`);
|
|
829
|
+
say("linux.ready");
|
|
830
|
+
}
|
|
831
|
+
function runInLinux(script) {
|
|
832
|
+
const [cmd, args] = linuxCommand("/bin/bash", ["-c", script]);
|
|
833
|
+
return spawnSync2(cmd, args, { stdio: ["ignore", "inherit", "inherit"] }).status === 0;
|
|
834
|
+
}
|
|
835
|
+
function watchOpenRequests(open, everyMs = 1000) {
|
|
836
|
+
const f = openFile();
|
|
837
|
+
try {
|
|
838
|
+
fs7.writeFileSync(f, "");
|
|
839
|
+
} catch {}
|
|
840
|
+
let seen = 0;
|
|
841
|
+
const tick = () => {
|
|
842
|
+
let text = "";
|
|
843
|
+
try {
|
|
844
|
+
text = fs7.readFileSync(f, "utf8");
|
|
845
|
+
} catch {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
if (text.length < seen)
|
|
849
|
+
seen = 0;
|
|
850
|
+
const fresh = text.slice(seen);
|
|
851
|
+
const end = fresh.lastIndexOf(`
|
|
852
|
+
`);
|
|
853
|
+
if (end < 0)
|
|
854
|
+
return;
|
|
855
|
+
seen += end + 1;
|
|
856
|
+
for (const line of fresh.slice(0, end).split(`
|
|
857
|
+
`)) {
|
|
858
|
+
const url = line.trim();
|
|
859
|
+
if (/^https?:\/\/[^\s]{1,2000}$/.test(url))
|
|
860
|
+
open(url);
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
const timer = setInterval(tick, everyMs);
|
|
864
|
+
timer.unref?.();
|
|
865
|
+
return () => clearInterval(timer);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// src/agent/session.ts
|
|
869
|
+
import crypto2 from "node:crypto";
|
|
870
|
+
import fs8 from "node:fs";
|
|
871
|
+
import path5 from "node:path";
|
|
702
872
|
|
|
703
873
|
// src/agent/acp.ts
|
|
704
874
|
import { spawn } from "node:child_process";
|
|
@@ -713,6 +883,13 @@ class RpcError extends Error {
|
|
|
713
883
|
this.data = data;
|
|
714
884
|
}
|
|
715
885
|
}
|
|
886
|
+
function agentSpawn(agent, env = {}, extraArgs = []) {
|
|
887
|
+
if (agent.launch.linux) {
|
|
888
|
+
const [cmd, args] = linuxCommand(agent.launch.cmd, [...agent.launch.args, ...extraArgs], { ...agent.launch.env, ...env });
|
|
889
|
+
return [cmd, args, { ...process.env }];
|
|
890
|
+
}
|
|
891
|
+
return [agent.launch.cmd, [...agent.launch.args, ...extraArgs], { ...process.env, ...agent.launch.env, ...env }];
|
|
892
|
+
}
|
|
716
893
|
|
|
717
894
|
class AcpProcess extends EventEmitter {
|
|
718
895
|
child;
|
|
@@ -732,7 +909,8 @@ class AcpProcess extends EventEmitter {
|
|
|
732
909
|
return this.stderrTail;
|
|
733
910
|
}
|
|
734
911
|
async start(agent, cwd, env = {}, timeoutMs = 180000) {
|
|
735
|
-
const
|
|
912
|
+
const [cmd, args, childEnv] = agentSpawn(agent, env);
|
|
913
|
+
const child = spawn(cmd, args, { cwd, env: childEnv, stdio: ["pipe", "pipe", "pipe"], windowsHide: true });
|
|
736
914
|
this.child = child;
|
|
737
915
|
child.stderr?.on("data", (d) => this.stderrTail = (this.stderrTail + d).slice(-4096));
|
|
738
916
|
child.stdin?.on("error", () => {
|
|
@@ -848,7 +1026,7 @@ function splitId(id) {
|
|
|
848
1026
|
}
|
|
849
1027
|
var lexists = (p) => {
|
|
850
1028
|
try {
|
|
851
|
-
|
|
1029
|
+
fs8.lstatSync(p);
|
|
852
1030
|
return true;
|
|
853
1031
|
} catch {
|
|
854
1032
|
return false;
|
|
@@ -857,16 +1035,16 @@ var lexists = (p) => {
|
|
|
857
1035
|
function insideFolder(folder, p) {
|
|
858
1036
|
if (typeof p !== "string" || !p)
|
|
859
1037
|
return false;
|
|
860
|
-
const abs =
|
|
861
|
-
const rel =
|
|
862
|
-
if (rel.startsWith("..") ||
|
|
1038
|
+
const abs = path5.resolve(folder, p);
|
|
1039
|
+
const rel = path5.relative(folder, abs);
|
|
1040
|
+
if (rel.startsWith("..") || path5.isAbsolute(rel))
|
|
863
1041
|
return false;
|
|
864
1042
|
let probe = abs;
|
|
865
|
-
while (!lexists(probe) &&
|
|
866
|
-
probe =
|
|
1043
|
+
while (!lexists(probe) && path5.dirname(probe) !== probe)
|
|
1044
|
+
probe = path5.dirname(probe);
|
|
867
1045
|
try {
|
|
868
|
-
const r =
|
|
869
|
-
return !(r.startsWith("..") ||
|
|
1046
|
+
const r = path5.relative(fs8.realpathSync(folder), fs8.realpathSync(probe));
|
|
1047
|
+
return !(r.startsWith("..") || path5.isAbsolute(r));
|
|
870
1048
|
} catch {
|
|
871
1049
|
return false;
|
|
872
1050
|
}
|
|
@@ -911,8 +1089,8 @@ class AgentSessions {
|
|
|
911
1089
|
}
|
|
912
1090
|
this.o.onExit(agentId, code);
|
|
913
1091
|
});
|
|
914
|
-
const cwd =
|
|
915
|
-
|
|
1092
|
+
const cwd = path5.join(agentDir(), agentId, "kerja");
|
|
1093
|
+
fs8.mkdirSync(cwd, { recursive: true });
|
|
916
1094
|
const p = proc.start(agent, cwd, this.o.env?.(agentId) ?? {}, this.o.startTimeoutMs ?? 180000).then((init) => {
|
|
917
1095
|
const entry = { proc, init };
|
|
918
1096
|
this.procs.set(agentId, entry);
|
|
@@ -933,9 +1111,9 @@ class AgentSessions {
|
|
|
933
1111
|
if (live)
|
|
934
1112
|
return { sessionId: key(resume), init, raw: {}, dimuat: "hidup", routeId: live.routeId, opsi: live.opsi ?? {} };
|
|
935
1113
|
const cwd = projectDir(projectId);
|
|
936
|
-
|
|
937
|
-
const routeId =
|
|
938
|
-
const params = { cwd, mcpServers: this.o.mcpServers(cwd, projectId, routeId) };
|
|
1114
|
+
fs8.writeFileSync(path5.join(cwd, "AGENTS.md"), AGENTS_MD);
|
|
1115
|
+
const routeId = crypto2.randomBytes(9).toString("base64url");
|
|
1116
|
+
const params = { cwd, mcpServers: this.o.mcpServers(cwd, projectId, routeId, this.o.agent(agentId)) };
|
|
939
1117
|
const limit = this.o.sessionTimeoutMs ?? 90000;
|
|
940
1118
|
let raw;
|
|
941
1119
|
let dimuat = "baru";
|
|
@@ -1086,12 +1264,12 @@ class AgentSessions {
|
|
|
1086
1264
|
if (method === "fs/read_text_file") {
|
|
1087
1265
|
if (!insideFolder(s.cwd, p.path))
|
|
1088
1266
|
throw new RpcError(-32602, OUTSIDE);
|
|
1089
|
-
const st =
|
|
1267
|
+
const st = fs8.statSync(path5.resolve(s.cwd, p.path), { throwIfNoEntry: false });
|
|
1090
1268
|
if (!st?.isFile())
|
|
1091
1269
|
throw new RpcError(-32602, "Not a regular file");
|
|
1092
1270
|
if (st.size > MAX_READ)
|
|
1093
1271
|
throw new RpcError(-32602, "File too large (over 10 MB)");
|
|
1094
|
-
let content =
|
|
1272
|
+
let content = fs8.readFileSync(path5.resolve(s.cwd, p.path), "utf8");
|
|
1095
1273
|
if (p.line || p.limit) {
|
|
1096
1274
|
const lines = content.split(`
|
|
1097
1275
|
`);
|
|
@@ -1104,9 +1282,9 @@ class AgentSessions {
|
|
|
1104
1282
|
if (method === "fs/write_text_file") {
|
|
1105
1283
|
if (!insideFolder(s.cwd, p.path))
|
|
1106
1284
|
throw new RpcError(-32602, OUTSIDE);
|
|
1107
|
-
const f =
|
|
1108
|
-
|
|
1109
|
-
|
|
1285
|
+
const f = path5.resolve(s.cwd, p.path);
|
|
1286
|
+
fs8.mkdirSync(path5.dirname(f), { recursive: true });
|
|
1287
|
+
fs8.writeFileSync(f, String(p.content ?? ""));
|
|
1110
1288
|
return null;
|
|
1111
1289
|
}
|
|
1112
1290
|
throw new RpcError(-32601, `Method not found: ${method}`);
|
|
@@ -1114,8 +1292,8 @@ class AgentSessions {
|
|
|
1114
1292
|
}
|
|
1115
1293
|
|
|
1116
1294
|
// src/agent/store.ts
|
|
1117
|
-
import
|
|
1118
|
-
import
|
|
1295
|
+
import fs9 from "node:fs";
|
|
1296
|
+
import path6 from "node:path";
|
|
1119
1297
|
function setReady(id, ready) {
|
|
1120
1298
|
const a = readInstalled().find((x) => x.id === id);
|
|
1121
1299
|
if (a)
|
|
@@ -1125,15 +1303,15 @@ var AGENT_ID = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
|
1125
1303
|
var folder = (id) => {
|
|
1126
1304
|
if (typeof id !== "string" || !AGENT_ID.test(id))
|
|
1127
1305
|
throw new Error(`Invalid agent id: ${JSON.stringify(String(id)).slice(0, 60)}`);
|
|
1128
|
-
return
|
|
1306
|
+
return path6.join(agentDir(), id);
|
|
1129
1307
|
};
|
|
1130
1308
|
function readInstalled() {
|
|
1131
1309
|
const out = [];
|
|
1132
|
-
for (const id of
|
|
1310
|
+
for (const id of fs9.readdirSync(agentDir())) {
|
|
1133
1311
|
if (!AGENT_ID.test(id))
|
|
1134
1312
|
continue;
|
|
1135
1313
|
try {
|
|
1136
|
-
const a = JSON.parse(
|
|
1314
|
+
const a = JSON.parse(fs9.readFileSync(path6.join(folder(id), "agent.json"), "utf8"));
|
|
1137
1315
|
if (a.id === id && a.launch?.cmd)
|
|
1138
1316
|
out.push(a);
|
|
1139
1317
|
} catch {}
|
|
@@ -1141,26 +1319,26 @@ function readInstalled() {
|
|
|
1141
1319
|
return out;
|
|
1142
1320
|
}
|
|
1143
1321
|
function writeInstalled(a) {
|
|
1144
|
-
|
|
1145
|
-
const f =
|
|
1146
|
-
|
|
1147
|
-
|
|
1322
|
+
fs9.mkdirSync(folder(a.id), { recursive: true });
|
|
1323
|
+
const f = path6.join(folder(a.id), "agent.json");
|
|
1324
|
+
fs9.writeFileSync(`${f}.tmp`, JSON.stringify(a, null, 2));
|
|
1325
|
+
fs9.renameSync(`${f}.tmp`, f);
|
|
1148
1326
|
}
|
|
1149
1327
|
function removeAgent(id) {
|
|
1150
|
-
|
|
1328
|
+
fs9.rmSync(folder(id), { recursive: true, force: true });
|
|
1151
1329
|
}
|
|
1152
1330
|
function agentEnv(id) {
|
|
1153
1331
|
try {
|
|
1154
|
-
return JSON.parse(
|
|
1332
|
+
return JSON.parse(fs9.readFileSync(path6.join(folder(id), "env.json"), "utf8"));
|
|
1155
1333
|
} catch {
|
|
1156
1334
|
return {};
|
|
1157
1335
|
}
|
|
1158
1336
|
}
|
|
1159
1337
|
function saveAgentEnv(id, env) {
|
|
1160
|
-
|
|
1161
|
-
const f =
|
|
1162
|
-
|
|
1163
|
-
|
|
1338
|
+
fs9.mkdirSync(folder(id), { recursive: true });
|
|
1339
|
+
const f = path6.join(folder(id), "env.json");
|
|
1340
|
+
fs9.writeFileSync(`${f}.tmp`, JSON.stringify({ ...agentEnv(id), ...env }), { mode: 384 });
|
|
1341
|
+
fs9.renameSync(`${f}.tmp`, f);
|
|
1164
1342
|
}
|
|
1165
1343
|
|
|
1166
1344
|
// src/agent/service.ts
|
|
@@ -1267,29 +1445,38 @@ function commandText(req) {
|
|
|
1267
1445
|
return c.map((a) => typeof a === "string" && /^[\w@%+=:,./-]+$/.test(a) ? a : JSON.stringify(String(a))).join(" ");
|
|
1268
1446
|
return typeof c === "string" ? c : String(req.toolCall.title ?? "");
|
|
1269
1447
|
}
|
|
1448
|
+
function mcpServerFor(agent, url, key, bridge) {
|
|
1449
|
+
const env = [
|
|
1450
|
+
{ name: "HF_MCP_URL", value: url },
|
|
1451
|
+
{ name: "HF_MCP_KUNCI", value: key }
|
|
1452
|
+
];
|
|
1453
|
+
if (agent?.launch.linux)
|
|
1454
|
+
return { name: "hypeframe", command: bridgeScript(), args: [], env };
|
|
1455
|
+
return { name: "hypeframe", command: bridge.command, args: bridge.args, env: [...bridge.env, ...env] };
|
|
1456
|
+
}
|
|
1270
1457
|
function historyFile(projectId, sessionId) {
|
|
1271
|
-
return
|
|
1458
|
+
return path7.join(projectDir(projectId), "riwayat", `${crypto3.createHash("sha256").update(sessionId).digest("hex").slice(0, 32)}.jsonl`);
|
|
1272
1459
|
}
|
|
1273
1460
|
function record(file, updates) {
|
|
1274
1461
|
if (!updates.length)
|
|
1275
1462
|
return;
|
|
1276
1463
|
try {
|
|
1277
|
-
|
|
1278
|
-
|
|
1464
|
+
fs10.mkdirSync(path7.dirname(file), { recursive: true });
|
|
1465
|
+
fs10.appendFileSync(file, `${updates.map((u) => JSON.stringify(u)).join(`
|
|
1279
1466
|
`)}
|
|
1280
1467
|
`);
|
|
1281
|
-
if (
|
|
1282
|
-
const text =
|
|
1468
|
+
if (fs10.statSync(file).size > MAX_HISTORY) {
|
|
1469
|
+
const text = fs10.readFileSync(file, "utf8");
|
|
1283
1470
|
const from = text.indexOf(`
|
|
1284
1471
|
`, text.length - MAX_HISTORY / 2);
|
|
1285
|
-
|
|
1472
|
+
fs10.writeFileSync(file, from >= 0 ? text.slice(from + 1) : "");
|
|
1286
1473
|
}
|
|
1287
1474
|
} catch {}
|
|
1288
1475
|
}
|
|
1289
1476
|
function readHistory(file) {
|
|
1290
1477
|
let text = "";
|
|
1291
1478
|
try {
|
|
1292
|
-
text =
|
|
1479
|
+
text = fs10.readFileSync(file, "utf8");
|
|
1293
1480
|
} catch {
|
|
1294
1481
|
return { update: [], potong: false };
|
|
1295
1482
|
}
|
|
@@ -1308,7 +1495,7 @@ function readHistory(file) {
|
|
|
1308
1495
|
return { update: out.reverse(), potong: false };
|
|
1309
1496
|
}
|
|
1310
1497
|
function createAgentService(o) {
|
|
1311
|
-
const key =
|
|
1498
|
+
const key = crypto3.randomBytes(24).toString("base64url");
|
|
1312
1499
|
const routes = new Map;
|
|
1313
1500
|
const sessionRoute = new Map;
|
|
1314
1501
|
const permissions = new Map;
|
|
@@ -1339,18 +1526,7 @@ function createAgentService(o) {
|
|
|
1339
1526
|
const sessions = new AgentSessions({
|
|
1340
1527
|
agent: (id) => readInstalled().find((a) => a.id === id),
|
|
1341
1528
|
env: (id) => agentEnv(id),
|
|
1342
|
-
mcpServers: (_cwd, projectId, routeId) => [
|
|
1343
|
-
{
|
|
1344
|
-
name: "hypeframe",
|
|
1345
|
-
command: o.bridge.command,
|
|
1346
|
-
args: o.bridge.args,
|
|
1347
|
-
env: [
|
|
1348
|
-
...o.bridge.env,
|
|
1349
|
-
{ name: "HF_MCP_URL", value: `http://127.0.0.1:${o.port()}/agen/mcp/${projectId}/${routeId}` },
|
|
1350
|
-
{ name: "HF_MCP_KUNCI", value: key }
|
|
1351
|
-
]
|
|
1352
|
-
}
|
|
1353
|
-
],
|
|
1529
|
+
mcpServers: (_cwd, projectId, routeId, agent) => [mcpServerFor(agent, `http://127.0.0.1:${o.port()}/agen/mcp/${projectId}/${routeId}`, key, o.bridge)],
|
|
1354
1530
|
onUpdate: (sessionId, list, info) => {
|
|
1355
1531
|
const p = pending.get(sessionId);
|
|
1356
1532
|
if (p)
|
|
@@ -1362,7 +1538,7 @@ function createAgentService(o) {
|
|
|
1362
1538
|
record(file, packUpdates(list).flat());
|
|
1363
1539
|
},
|
|
1364
1540
|
onPermission: (sessionId, req, info) => new Promise((ok) => {
|
|
1365
|
-
const id = `i${
|
|
1541
|
+
const id = `i${crypto3.randomBytes(6).toString("hex")}`;
|
|
1366
1542
|
const done = (v) => (permissions.delete(id), ok(v));
|
|
1367
1543
|
permissions.set(id, done);
|
|
1368
1544
|
setTimeout(() => permissions.has(id) && done(null), 5 * 60000).unref();
|
|
@@ -1441,19 +1617,19 @@ function createAgentService(o) {
|
|
|
1441
1617
|
const folder = projectDir(projectId);
|
|
1442
1618
|
if (!p || !insideFolder(folder, p))
|
|
1443
1619
|
return fail(`Only files inside the HypeFrame project folder (${folder}) can be added.`);
|
|
1444
|
-
const file =
|
|
1445
|
-
const st =
|
|
1620
|
+
const file = path7.resolve(folder, p);
|
|
1621
|
+
const st = fs10.statSync(file, { throwIfNoEntry: false });
|
|
1446
1622
|
if (!st?.isFile())
|
|
1447
1623
|
return fail(`${p} is not a file in the project folder.`);
|
|
1448
|
-
const nama =
|
|
1449
|
-
const mime = MEDIA[
|
|
1624
|
+
const nama = path7.basename(file).slice(0, 120);
|
|
1625
|
+
const mime = MEDIA[path7.extname(file).slice(1).toLowerCase()];
|
|
1450
1626
|
if (!mime)
|
|
1451
1627
|
return fail(`${nama}: only images, audio, video, fonts and Lottie/JSON files can be added to a HypeFrame project.`);
|
|
1452
1628
|
if (st.size > MAX_FILE2)
|
|
1453
1629
|
return fail(`${nama} is ${(st.size / 1048576).toFixed(1)} MB; files up to 4 MB can be sent to HypeFrame Web. Make it smaller (lower resolution or bitrate) and try again.`);
|
|
1454
|
-
const data =
|
|
1630
|
+
const data = fs10.readFileSync(file).toString("base64");
|
|
1455
1631
|
const n = Math.max(1, Math.ceil(data.length / PIECE));
|
|
1456
|
-
const id =
|
|
1632
|
+
const id = crypto3.randomBytes(8).toString("hex");
|
|
1457
1633
|
let last = {};
|
|
1458
1634
|
for (let i = 0;i < n; i++) {
|
|
1459
1635
|
last = await o.conn.request(target.dari, "alat", { nama: "_berkas", arg: { id, i, n, nama, mime, ukuran: st.size, data: data.slice(i * PIECE, (i + 1) * PIECE) } });
|
|
@@ -1476,7 +1652,7 @@ function createAgentService(o) {
|
|
|
1476
1652
|
if (!m)
|
|
1477
1653
|
return false;
|
|
1478
1654
|
const auth = String(req.headers.authorization || "").replace(/^Bearer\s+/i, "");
|
|
1479
|
-
if (req.method !== "POST" || auth.length !== key.length || !
|
|
1655
|
+
if (req.method !== "POST" || auth.length !== key.length || !crypto3.timingSafeEqual(Buffer.from(auth), Buffer.from(key)))
|
|
1480
1656
|
return reply(res, 401, { error: "unauthorized" }), true;
|
|
1481
1657
|
let s = "";
|
|
1482
1658
|
for await (const d of req)
|
|
@@ -1527,15 +1703,15 @@ function createAgentService(o) {
|
|
|
1527
1703
|
}
|
|
1528
1704
|
|
|
1529
1705
|
// src/agent/mcp-bridge.ts
|
|
1530
|
-
import
|
|
1531
|
-
import
|
|
1706
|
+
import fs12 from "node:fs";
|
|
1707
|
+
import path9 from "node:path";
|
|
1532
1708
|
import readline2 from "node:readline";
|
|
1533
1709
|
|
|
1534
1710
|
// src/util/runtime.ts
|
|
1535
|
-
import
|
|
1536
|
-
import
|
|
1711
|
+
import fs11 from "node:fs";
|
|
1712
|
+
import path8 from "node:path";
|
|
1537
1713
|
function isStandalone() {
|
|
1538
|
-
return
|
|
1714
|
+
return path8.basename(process.execPath).toLowerCase().startsWith("hypeframe");
|
|
1539
1715
|
}
|
|
1540
1716
|
function runtimeLabel() {
|
|
1541
1717
|
const bun = process.versions.bun;
|
|
@@ -1545,7 +1721,7 @@ function launchCommand() {
|
|
|
1545
1721
|
if (isStandalone())
|
|
1546
1722
|
return [process.execPath];
|
|
1547
1723
|
try {
|
|
1548
|
-
const script =
|
|
1724
|
+
const script = fs11.realpathSync(process.argv[1] || "");
|
|
1549
1725
|
return /[\\/]_npx[\\/]/.test(script) ? null : [process.execPath, script];
|
|
1550
1726
|
} catch {
|
|
1551
1727
|
return null;
|
|
@@ -1581,13 +1757,13 @@ rl.on('line', (line) => {
|
|
|
1581
1757
|
rl.on('close', () => Promise.all(busy).then(() => process.exit(0)));
|
|
1582
1758
|
`;
|
|
1583
1759
|
function bridgeLaunch() {
|
|
1584
|
-
const file =
|
|
1760
|
+
const file = path9.join(agentDir(), "mcp-bridge.mjs");
|
|
1585
1761
|
let now = "";
|
|
1586
1762
|
try {
|
|
1587
|
-
now =
|
|
1763
|
+
now = fs12.readFileSync(file, "utf8");
|
|
1588
1764
|
} catch {}
|
|
1589
1765
|
if (now !== BRIDGE_SOURCE)
|
|
1590
|
-
|
|
1766
|
+
fs12.writeFileSync(file, BRIDGE_SOURCE);
|
|
1591
1767
|
return { command: process.execPath, args: [file], env: isStandalone() ? [{ name: "BUN_BE_BUN", value: "1" }] : [] };
|
|
1592
1768
|
}
|
|
1593
1769
|
async function runMcpBridge() {
|
|
@@ -1633,7 +1809,7 @@ async function runMcpBridge() {
|
|
|
1633
1809
|
}
|
|
1634
1810
|
|
|
1635
1811
|
// src/config/lock.ts
|
|
1636
|
-
import
|
|
1812
|
+
import fs13 from "node:fs";
|
|
1637
1813
|
class AlreadyRunning extends Error {
|
|
1638
1814
|
code = "SUDAH_JALAN";
|
|
1639
1815
|
}
|
|
@@ -1647,7 +1823,7 @@ var alive = (pid) => {
|
|
|
1647
1823
|
};
|
|
1648
1824
|
function runningPid() {
|
|
1649
1825
|
try {
|
|
1650
|
-
const pid = Number(
|
|
1826
|
+
const pid = Number(fs13.readFileSync(lockFile(), "utf8"));
|
|
1651
1827
|
return Number.isInteger(pid) && pid > 0 && pid !== process.pid && alive(pid) ? pid : null;
|
|
1652
1828
|
} catch {
|
|
1653
1829
|
return null;
|
|
@@ -1657,13 +1833,13 @@ function singleInstance() {
|
|
|
1657
1833
|
const f = lockFile();
|
|
1658
1834
|
for (let attempt = 0;attempt < 2; attempt++) {
|
|
1659
1835
|
try {
|
|
1660
|
-
const fd =
|
|
1661
|
-
|
|
1662
|
-
|
|
1836
|
+
const fd = fs13.openSync(f, "wx");
|
|
1837
|
+
fs13.writeSync(fd, String(process.pid));
|
|
1838
|
+
fs13.closeSync(fd);
|
|
1663
1839
|
const release = () => {
|
|
1664
1840
|
try {
|
|
1665
|
-
if (
|
|
1666
|
-
|
|
1841
|
+
if (fs13.readFileSync(f, "utf8") === String(process.pid))
|
|
1842
|
+
fs13.rmSync(f, { force: true });
|
|
1667
1843
|
} catch {}
|
|
1668
1844
|
process.off("exit", release);
|
|
1669
1845
|
};
|
|
@@ -1672,17 +1848,17 @@ function singleInstance() {
|
|
|
1672
1848
|
} catch (e) {
|
|
1673
1849
|
if (e.code !== "EEXIST")
|
|
1674
1850
|
throw e;
|
|
1675
|
-
const pid = Number(
|
|
1851
|
+
const pid = Number(fs13.readFileSync(f, "utf8"));
|
|
1676
1852
|
if (Number.isInteger(pid) && pid > 0 && alive(pid))
|
|
1677
1853
|
throw new AlreadyRunning("engine already running");
|
|
1678
|
-
|
|
1854
|
+
fs13.rmSync(f, { force: true });
|
|
1679
1855
|
}
|
|
1680
1856
|
}
|
|
1681
1857
|
throw new AlreadyRunning("engine already running");
|
|
1682
1858
|
}
|
|
1683
1859
|
|
|
1684
1860
|
// src/engine/connection.ts
|
|
1685
|
-
import
|
|
1861
|
+
import crypto4 from "node:crypto";
|
|
1686
1862
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
1687
1863
|
import WebSocket from "ws";
|
|
1688
1864
|
var SILENCE_MAX_MS = 70000;
|
|
@@ -1728,7 +1904,7 @@ class Connection extends EventEmitter2 {
|
|
|
1728
1904
|
request(ke, kind, body, timeoutMs = 55000) {
|
|
1729
1905
|
if (!this.connected)
|
|
1730
1906
|
return Promise.resolve({ ok: false, error: "terputus" });
|
|
1731
|
-
const id = `q${this.nextReq++}${
|
|
1907
|
+
const id = `q${this.nextReq++}${crypto4.randomBytes(6).toString("hex")}`;
|
|
1732
1908
|
return new Promise((ok) => {
|
|
1733
1909
|
const timer = setTimeout(() => (this.waiting.delete(id), ok({ ok: false, error: "waktu" })), timeoutMs);
|
|
1734
1910
|
timer.unref?.();
|
|
@@ -1911,54 +2087,50 @@ async function pair(o) {
|
|
|
1911
2087
|
}
|
|
1912
2088
|
|
|
1913
2089
|
// src/render/chrome.ts
|
|
1914
|
-
import
|
|
1915
|
-
import fs12 from "node:fs";
|
|
2090
|
+
import fs14 from "node:fs";
|
|
1916
2091
|
import http from "node:http";
|
|
1917
|
-
import
|
|
2092
|
+
import path10 from "node:path";
|
|
1918
2093
|
import { Browser, detectBrowserPlatform, getInstalledBrowsers, install, resolveBuildId } from "@puppeteer/browsers";
|
|
1919
2094
|
import puppeteer from "puppeteer-core";
|
|
2095
|
+
function chromePlatformArgs(android = isAndroid()) {
|
|
2096
|
+
return android ? ["--no-sandbox"] : [];
|
|
2097
|
+
}
|
|
1920
2098
|
function candidates() {
|
|
1921
2099
|
const e = process.env;
|
|
1922
2100
|
if (process.platform === "win32") {
|
|
1923
|
-
return [e.PROGRAMFILES, e["PROGRAMFILES(X86)"], e.LOCALAPPDATA].filter((d) => !!d).flatMap((d) => [
|
|
2101
|
+
return [e.PROGRAMFILES, e["PROGRAMFILES(X86)"], e.LOCALAPPDATA].filter((d) => !!d).flatMap((d) => [path10.join(d, "Google", "Chrome", "Application", "chrome.exe"), path10.join(d, "Microsoft", "Edge", "Application", "msedge.exe")]);
|
|
1924
2102
|
}
|
|
1925
2103
|
if (process.platform === "darwin") {
|
|
1926
2104
|
return ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "/Applications/Chromium.app/Contents/MacOS/Chromium", "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"];
|
|
1927
2105
|
}
|
|
1928
|
-
|
|
1929
|
-
for (const n of ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"]) {
|
|
1930
|
-
try {
|
|
1931
|
-
const p = execFileSync("which", [n], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
1932
|
-
if (p)
|
|
1933
|
-
found.push(p);
|
|
1934
|
-
} catch {}
|
|
1935
|
-
}
|
|
1936
|
-
return found;
|
|
2106
|
+
return ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"].map((n) => onPath(n)).filter((p) => !!p);
|
|
1937
2107
|
}
|
|
1938
2108
|
function findChrome() {
|
|
1939
2109
|
const forced = process.env.HYPEFRAME_CHROME;
|
|
1940
2110
|
if (forced)
|
|
1941
|
-
return
|
|
1942
|
-
return candidates().find((p) =>
|
|
2111
|
+
return fs14.existsSync(forced) ? forced : null;
|
|
2112
|
+
return candidates().find((p) => fs14.existsSync(p)) || null;
|
|
1943
2113
|
}
|
|
1944
2114
|
async function cachedChrome(cacheDir) {
|
|
1945
2115
|
try {
|
|
1946
|
-
const all = await getInstalledBrowsers({ cacheDir:
|
|
1947
|
-
return all.find((b) => b.browser === Browser.CHROME &&
|
|
2116
|
+
const all = await getInstalledBrowsers({ cacheDir: path10.join(cacheDir, "chrome") });
|
|
2117
|
+
return all.find((b) => b.browser === Browser.CHROME && fs14.existsSync(b.executablePath))?.executablePath ?? null;
|
|
1948
2118
|
} catch {
|
|
1949
2119
|
return null;
|
|
1950
2120
|
}
|
|
1951
2121
|
}
|
|
1952
2122
|
async function prepareChrome(cacheDir, progress = () => {
|
|
1953
2123
|
return;
|
|
1954
|
-
}) {
|
|
2124
|
+
}, opts = {}) {
|
|
1955
2125
|
const found = findChrome();
|
|
1956
2126
|
if (found)
|
|
1957
2127
|
return found;
|
|
2128
|
+
if (opts.android ?? isAndroid())
|
|
2129
|
+
throw new Error("Chromium belum terpasang. Di Termux jalankan: pkg install x11-repo && pkg install chromium");
|
|
1958
2130
|
const platform = detectBrowserPlatform();
|
|
1959
2131
|
if (!platform)
|
|
1960
2132
|
throw new Error("Sistem ini belum didukung untuk render (Chrome tidak tersedia).");
|
|
1961
|
-
const dir =
|
|
2133
|
+
const dir = path10.join(cacheDir, "chrome");
|
|
1962
2134
|
const buildId = await resolveBuildId(Browser.CHROME, platform, "stable");
|
|
1963
2135
|
progress(0, `Chrome ${buildId}`);
|
|
1964
2136
|
const r = await install({
|
|
@@ -1989,7 +2161,7 @@ var TRY_ENCODER = `async (c) => {
|
|
|
1989
2161
|
async function checkChrome(chrome, { gpu = false } = {}) {
|
|
1990
2162
|
const srv = http.createServer((_q, r) => (r.writeHead(200, { "content-type": "text/html" }), r.end("<!doctype html><title>check</title>")));
|
|
1991
2163
|
await new Promise((ok) => srv.listen(0, "127.0.0.1", ok));
|
|
1992
|
-
const b = await puppeteer.launch({ executablePath: chrome, headless: true, protocolTimeout: 60000, args: ["--no-first-run", "--disable-extensions", ...gpu ? [] : softwareGpuArgs] });
|
|
2164
|
+
const b = await puppeteer.launch({ executablePath: chrome, headless: true, protocolTimeout: 60000, args: ["--no-first-run", "--disable-extensions", ...gpu ? [] : softwareGpuArgs, ...chromePlatformArgs()] });
|
|
1993
2165
|
try {
|
|
1994
2166
|
const p = await b.newPage();
|
|
1995
2167
|
await p.goto(`http://127.0.0.1:${srv.address().port}/`);
|
|
@@ -2008,10 +2180,10 @@ async function checkChrome(chrome, { gpu = false } = {}) {
|
|
|
2008
2180
|
}
|
|
2009
2181
|
|
|
2010
2182
|
// src/render/ffmpeg.ts
|
|
2011
|
-
import
|
|
2012
|
-
import
|
|
2183
|
+
import crypto5 from "node:crypto";
|
|
2184
|
+
import fs15 from "node:fs";
|
|
2013
2185
|
import fsp from "node:fs/promises";
|
|
2014
|
-
import
|
|
2186
|
+
import path11 from "node:path";
|
|
2015
2187
|
import { pipeline } from "node:stream/promises";
|
|
2016
2188
|
import { Readable } from "node:stream";
|
|
2017
2189
|
import zlib from "node:zlib";
|
|
@@ -2025,19 +2197,22 @@ var FFMPEG_PINNED = {
|
|
|
2025
2197
|
"darwin-arm64": { sha256: "6be74d6f449889c2e87a75873894f8520cad56c08ac76f2a628d85b0519daaca", size: 19253088 }
|
|
2026
2198
|
};
|
|
2027
2199
|
var exe = process.platform === "win32" ? "ffmpeg.exe" : "ffmpeg";
|
|
2028
|
-
var cached2 = (cacheDir) =>
|
|
2029
|
-
|
|
2200
|
+
var cached2 = (cacheDir) => path11.join(cacheDir, "ffmpeg", FFMPEG_RELEASE, exe);
|
|
2201
|
+
var thisPlatform = () => `${process.platform}-${process.arch}`;
|
|
2202
|
+
async function findFfmpeg(cacheDir, key = thisPlatform()) {
|
|
2030
2203
|
const forced = process.env.HYPEFRAME_FFMPEG;
|
|
2031
2204
|
if (forced)
|
|
2032
|
-
return
|
|
2205
|
+
return fs15.existsSync(forced) ? forced : null;
|
|
2206
|
+
if (!FFMPEG_PINNED[key])
|
|
2207
|
+
return onPath("ffmpeg");
|
|
2033
2208
|
try {
|
|
2034
2209
|
const mod = await import("ffmpeg-static");
|
|
2035
2210
|
const p = typeof mod.default === "string" ? mod.default : null;
|
|
2036
|
-
if (p &&
|
|
2211
|
+
if (p && fs15.existsSync(p))
|
|
2037
2212
|
return p;
|
|
2038
2213
|
} catch {}
|
|
2039
2214
|
const c = cached2(cacheDir);
|
|
2040
|
-
return
|
|
2215
|
+
return fs15.existsSync(c) ? c : null;
|
|
2041
2216
|
}
|
|
2042
2217
|
async function downloadVerified(url, sha256, dest, progress = () => {
|
|
2043
2218
|
return;
|
|
@@ -2046,9 +2221,9 @@ async function downloadVerified(url, sha256, dest, progress = () => {
|
|
|
2046
2221
|
if (!r.ok || !r.body)
|
|
2047
2222
|
throw new Error(`download ${r.status}`);
|
|
2048
2223
|
const total = Number(r.headers.get("content-length")) || 0;
|
|
2049
|
-
await fsp.mkdir(
|
|
2224
|
+
await fsp.mkdir(path11.dirname(dest), { recursive: true });
|
|
2050
2225
|
const tmp = `${dest}.download`;
|
|
2051
|
-
const hash =
|
|
2226
|
+
const hash = crypto5.createHash("sha256");
|
|
2052
2227
|
let got = 0;
|
|
2053
2228
|
let last = -10;
|
|
2054
2229
|
const body = Readable.fromWeb(r.body).on("data", (c) => {
|
|
@@ -2058,13 +2233,13 @@ async function downloadVerified(url, sha256, dest, progress = () => {
|
|
|
2058
2233
|
if (pct - last >= 10)
|
|
2059
2234
|
last = pct, progress(pct);
|
|
2060
2235
|
});
|
|
2061
|
-
await pipeline(body,
|
|
2236
|
+
await pipeline(body, fs15.createWriteStream(tmp));
|
|
2062
2237
|
if (hash.digest("hex") !== sha256) {
|
|
2063
2238
|
await fsp.rm(tmp, { force: true });
|
|
2064
2239
|
throw new Error("ffmpeg: sidik unduhan tidak cocok, berkas ditolak.");
|
|
2065
2240
|
}
|
|
2066
2241
|
if (gunzip) {
|
|
2067
|
-
await pipeline(
|
|
2242
|
+
await pipeline(fs15.createReadStream(tmp), zlib.createGunzip(), fs15.createWriteStream(`${tmp}.raw`));
|
|
2068
2243
|
await fsp.rm(tmp, { force: true });
|
|
2069
2244
|
await fsp.rename(`${tmp}.raw`, dest);
|
|
2070
2245
|
} else
|
|
@@ -2074,14 +2249,13 @@ async function downloadVerified(url, sha256, dest, progress = () => {
|
|
|
2074
2249
|
}
|
|
2075
2250
|
async function prepareFfmpeg(cacheDir, progress = () => {
|
|
2076
2251
|
return;
|
|
2077
|
-
}) {
|
|
2078
|
-
const found = await findFfmpeg(cacheDir);
|
|
2252
|
+
}, key = thisPlatform()) {
|
|
2253
|
+
const found = await findFfmpeg(cacheDir, key);
|
|
2079
2254
|
if (found)
|
|
2080
2255
|
return found;
|
|
2081
|
-
const key = `${process.platform}-${process.arch}`;
|
|
2082
2256
|
const pin = FFMPEG_PINNED[key];
|
|
2083
2257
|
if (!pin)
|
|
2084
|
-
throw new Error(`ffmpeg tidak tersedia untuk ${key}`);
|
|
2258
|
+
throw new Error(key.startsWith("android") ? "ffmpeg belum terpasang. Di Termux jalankan: pkg install ffmpeg" : `ffmpeg tidak tersedia untuk ${key}`);
|
|
2085
2259
|
progress(0);
|
|
2086
2260
|
await downloadVerified(`${BASE}ffmpeg-${key}.gz`, pin.sha256, cached2(cacheDir), progress, true);
|
|
2087
2261
|
return cached2(cacheDir);
|
|
@@ -2089,10 +2263,10 @@ async function prepareFfmpeg(cacheDir, progress = () => {
|
|
|
2089
2263
|
|
|
2090
2264
|
// src/render/job.ts
|
|
2091
2265
|
import { spawn as spawn2 } from "node:child_process";
|
|
2092
|
-
import
|
|
2093
|
-
import
|
|
2266
|
+
import crypto6 from "node:crypto";
|
|
2267
|
+
import fs16 from "node:fs";
|
|
2094
2268
|
import fsp2 from "node:fs/promises";
|
|
2095
|
-
import
|
|
2269
|
+
import path12 from "node:path";
|
|
2096
2270
|
import puppeteer2 from "puppeteer-core";
|
|
2097
2271
|
var LIMIT_SECONDS = 1800;
|
|
2098
2272
|
function run(cmd, args, limitSeconds = 600) {
|
|
@@ -2109,7 +2283,7 @@ function run(cmd, args, limitSeconds = 600) {
|
|
|
2109
2283
|
function saveBody(req, to, max) {
|
|
2110
2284
|
return new Promise((ok, fail) => {
|
|
2111
2285
|
let n = 0;
|
|
2112
|
-
const out =
|
|
2286
|
+
const out = fs16.createWriteStream(to);
|
|
2113
2287
|
req.on("data", (d) => {
|
|
2114
2288
|
n += d.length;
|
|
2115
2289
|
if (n > max)
|
|
@@ -2140,7 +2314,7 @@ function createJobRunner(o) {
|
|
|
2140
2314
|
const renderer = async (task, { progress, signal }) => {
|
|
2141
2315
|
if (task.kind === "klip" && task.transparent && !transparent)
|
|
2142
2316
|
throw new Error(EngineError.NoTransparent);
|
|
2143
|
-
const key =
|
|
2317
|
+
const key = crypto6.randomBytes(16).toString("hex");
|
|
2144
2318
|
let finish;
|
|
2145
2319
|
const finished = new Promise((ok) => finish = ok);
|
|
2146
2320
|
running.set(task.job, { key, task, progress, finish });
|
|
@@ -2151,9 +2325,9 @@ function createJobRunner(o) {
|
|
|
2151
2325
|
let browser;
|
|
2152
2326
|
try {
|
|
2153
2327
|
progress(0, "Menyiapkan");
|
|
2154
|
-
const profile =
|
|
2155
|
-
await fsp2.mkdir(
|
|
2156
|
-
await fsp2.writeFile(
|
|
2328
|
+
const profile = path12.join(task.dir, "profil");
|
|
2329
|
+
await fsp2.mkdir(path12.join(profile, "Default"), { recursive: true });
|
|
2330
|
+
await fsp2.writeFile(path12.join(profile, "Default", "Preferences"), JSON.stringify({ webkit: { webprefs: { fonts: { standard: { Zyyy: "Roboto" }, sansserif: { Zyyy: "Roboto" }, serif: { Zyyy: "Noto Serif" } } } } }));
|
|
2157
2331
|
browser = await puppeteer2.launch({
|
|
2158
2332
|
executablePath: chrome,
|
|
2159
2333
|
headless: true,
|
|
@@ -2171,7 +2345,8 @@ function createJobRunner(o) {
|
|
|
2171
2345
|
"--enable-unsafe-webgpu",
|
|
2172
2346
|
...gpu ? [] : ["--use-webgpu-adapter=swiftshader"],
|
|
2173
2347
|
"--enable-features=Vulkan",
|
|
2174
|
-
"--host-resolver-rules=MAP * ~NOTFOUND , EXCLUDE 127.0.0.1"
|
|
2348
|
+
"--host-resolver-rules=MAP * ~NOTFOUND , EXCLUDE 127.0.0.1",
|
|
2349
|
+
...chromePlatformArgs()
|
|
2175
2350
|
]
|
|
2176
2351
|
});
|
|
2177
2352
|
browser.on("disconnected", () => finish({ error: EngineError.ChromeStopped }));
|
|
@@ -2183,9 +2358,9 @@ function createJobRunner(o) {
|
|
|
2183
2358
|
if (result.error)
|
|
2184
2359
|
throw new Error(result.error);
|
|
2185
2360
|
progress(99, clip ? "Menyelesaikan klip" : "Menyelesaikan video");
|
|
2186
|
-
const raw =
|
|
2361
|
+
const raw = path12.join(task.dir, "mentah.mp4");
|
|
2187
2362
|
const webm = clip && task.transparent;
|
|
2188
|
-
const file =
|
|
2363
|
+
const file = path12.join(task.dir, webm ? "hasil.webm" : "hasil.mp4");
|
|
2189
2364
|
if (clip)
|
|
2190
2365
|
await fsp2.rename(raw, file);
|
|
2191
2366
|
else
|
|
@@ -2212,11 +2387,11 @@ function createJobRunner(o) {
|
|
|
2212
2387
|
return res.writeHead(403), res.end(), true;
|
|
2213
2388
|
const pkg = r.task.packageDir;
|
|
2214
2389
|
if (m[2] === "proyek.json" || m[2] === "klip.json" || m[3]) {
|
|
2215
|
-
const f = m[3] ?
|
|
2216
|
-
if (!
|
|
2390
|
+
const f = m[3] ? path12.join(pkg, "aset", m[3]) : path12.join(pkg, m[2]);
|
|
2391
|
+
if (!fs16.existsSync(f))
|
|
2217
2392
|
return res.writeHead(404), res.end(), true;
|
|
2218
2393
|
res.writeHead(200, { "content-type": m[3] ? "application/octet-stream" : "application/json", "content-length": (await fsp2.stat(f)).size });
|
|
2219
|
-
|
|
2394
|
+
fs16.createReadStream(f).pipe(res);
|
|
2220
2395
|
return true;
|
|
2221
2396
|
}
|
|
2222
2397
|
if (m[2] === "kemajuan") {
|
|
@@ -2233,7 +2408,7 @@ function createJobRunner(o) {
|
|
|
2233
2408
|
r.finish({ error: String(b.pesan || "Render gagal.").slice(0, 300) });
|
|
2234
2409
|
return res.writeHead(204), res.end(), true;
|
|
2235
2410
|
}
|
|
2236
|
-
await saveBody(req,
|
|
2411
|
+
await saveBody(req, path12.join(r.task.dir, "mentah.mp4"), 8 * 1073741824);
|
|
2237
2412
|
r.finish({ audio: String(req.headers["x-kodek-audio"] || "") });
|
|
2238
2413
|
res.writeHead(204);
|
|
2239
2414
|
res.end();
|
|
@@ -2243,9 +2418,9 @@ function createJobRunner(o) {
|
|
|
2243
2418
|
}
|
|
2244
2419
|
|
|
2245
2420
|
// src/render/page.ts
|
|
2246
|
-
import
|
|
2421
|
+
import fs17 from "node:fs";
|
|
2247
2422
|
import fsp3 from "node:fs/promises";
|
|
2248
|
-
import
|
|
2423
|
+
import path13 from "node:path";
|
|
2249
2424
|
var TYPES = {
|
|
2250
2425
|
".html": "text/html; charset=utf-8",
|
|
2251
2426
|
".js": "text/javascript",
|
|
@@ -2266,13 +2441,13 @@ var SAFE_PATH = /^[\w@.+-]+(?:\/[\w@.+-]+)*$/;
|
|
|
2266
2441
|
var VERSION_ID = /^[0-9a-f]{12}$/;
|
|
2267
2442
|
function createPage({ web, cacheDir }) {
|
|
2268
2443
|
const base = `${String(web || "").replace(/\/+$/, "")}/render/`;
|
|
2269
|
-
const root =
|
|
2444
|
+
const root = path13.join(cacheDir, "halaman");
|
|
2270
2445
|
let version = null;
|
|
2271
|
-
const versionDir = () =>
|
|
2446
|
+
const versionDir = () => path13.join(root, version);
|
|
2272
2447
|
const pending = new Map;
|
|
2273
2448
|
async function download(rel) {
|
|
2274
|
-
const target =
|
|
2275
|
-
if (
|
|
2449
|
+
const target = path13.join(versionDir(), rel);
|
|
2450
|
+
if (fs17.existsSync(target))
|
|
2276
2451
|
return target;
|
|
2277
2452
|
if (!pending.has(rel)) {
|
|
2278
2453
|
pending.set(rel, (async () => {
|
|
@@ -2280,7 +2455,7 @@ function createPage({ web, cacheDir }) {
|
|
|
2280
2455
|
if (!r.ok)
|
|
2281
2456
|
throw Object.assign(new Error(`halaman ${rel}: ${r.status}`), { status: r.status });
|
|
2282
2457
|
const body = Buffer.from(await r.arrayBuffer());
|
|
2283
|
-
await fsp3.mkdir(
|
|
2458
|
+
await fsp3.mkdir(path13.dirname(target), { recursive: true });
|
|
2284
2459
|
await fsp3.writeFile(`${target}.tmp`, body);
|
|
2285
2460
|
await fsp3.rename(`${target}.tmp`, target);
|
|
2286
2461
|
return target;
|
|
@@ -2304,10 +2479,10 @@ function createPage({ web, cacheDir }) {
|
|
|
2304
2479
|
await download(f);
|
|
2305
2480
|
if (old !== version) {
|
|
2306
2481
|
const all = (await fsp3.readdir(root).catch(() => [])).filter((d) => VERSION_ID.test(d));
|
|
2307
|
-
const dated = await Promise.all(all.map(async (d) => ({ d, t: (await fsp3.stat(
|
|
2482
|
+
const dated = await Promise.all(all.map(async (d) => ({ d, t: (await fsp3.stat(path13.join(root, d))).mtimeMs })));
|
|
2308
2483
|
for (const { d } of dated.sort((a, b) => b.t - a.t).slice(2))
|
|
2309
2484
|
if (d !== version)
|
|
2310
|
-
await fsp3.rm(
|
|
2485
|
+
await fsp3.rm(path13.join(root, d), { recursive: true, force: true });
|
|
2311
2486
|
}
|
|
2312
2487
|
return { version };
|
|
2313
2488
|
}
|
|
@@ -2324,8 +2499,8 @@ function createPage({ web, cacheDir }) {
|
|
|
2324
2499
|
return res.writeHead(404), res.end(), true;
|
|
2325
2500
|
try {
|
|
2326
2501
|
const f = await download(rel);
|
|
2327
|
-
res.writeHead(200, { "content-type": TYPES[
|
|
2328
|
-
|
|
2502
|
+
res.writeHead(200, { "content-type": TYPES[path13.extname(f)] || "application/octet-stream", "cache-control": "no-store" });
|
|
2503
|
+
fs17.createReadStream(f).pipe(res);
|
|
2329
2504
|
} catch (e) {
|
|
2330
2505
|
res.writeHead(e.status === 404 ? 404 : 502);
|
|
2331
2506
|
res.end();
|
|
@@ -2342,14 +2517,14 @@ function createPage({ web, cacheDir }) {
|
|
|
2342
2517
|
}
|
|
2343
2518
|
|
|
2344
2519
|
// src/render/service.ts
|
|
2345
|
-
import
|
|
2346
|
-
import
|
|
2520
|
+
import crypto7 from "node:crypto";
|
|
2521
|
+
import fs18 from "node:fs";
|
|
2347
2522
|
import fsp4 from "node:fs/promises";
|
|
2348
2523
|
import http2 from "node:http";
|
|
2349
|
-
import
|
|
2524
|
+
import path14 from "node:path";
|
|
2350
2525
|
import yauzl from "yauzl";
|
|
2351
2526
|
var ACTIVE = new Set(["unggah", "antre", "jalan"]);
|
|
2352
|
-
var safeEqual = (a, b) => a.length === b.length &&
|
|
2527
|
+
var safeEqual = (a, b) => a.length === b.length && crypto7.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
2353
2528
|
var BAD_ENTRY = /relative path|absolute path|invalid characters/i;
|
|
2354
2529
|
function listZip(f) {
|
|
2355
2530
|
return new Promise((ok, fail) => {
|
|
@@ -2373,14 +2548,14 @@ function extractZip(f, to) {
|
|
|
2373
2548
|
zip.on("entry", (en) => {
|
|
2374
2549
|
if (en.fileName.endsWith("/"))
|
|
2375
2550
|
return zip.readEntry();
|
|
2376
|
-
const target =
|
|
2377
|
-
if (!target.startsWith(to +
|
|
2551
|
+
const target = path14.join(to, en.fileName);
|
|
2552
|
+
if (!target.startsWith(to + path14.sep))
|
|
2378
2553
|
return fail(new Error(EngineError.BadPackage));
|
|
2379
|
-
|
|
2554
|
+
fs18.mkdirSync(path14.dirname(target), { recursive: true });
|
|
2380
2555
|
zip.openReadStream(en, (e2, s) => {
|
|
2381
2556
|
if (e2 || !s)
|
|
2382
2557
|
return fail(e2 ?? new Error("zip"));
|
|
2383
|
-
const out =
|
|
2558
|
+
const out = fs18.createWriteStream(target);
|
|
2384
2559
|
s.pipe(out);
|
|
2385
2560
|
out.on("finish", () => zip.readEntry());
|
|
2386
2561
|
out.on("error", fail);
|
|
@@ -2395,13 +2570,13 @@ function extractZip(f, to) {
|
|
|
2395
2570
|
function saveBody2(req, to, max) {
|
|
2396
2571
|
return new Promise((ok, fail) => {
|
|
2397
2572
|
let n = 0;
|
|
2398
|
-
const out =
|
|
2573
|
+
const out = fs18.createWriteStream(to);
|
|
2399
2574
|
req.on("data", (d) => {
|
|
2400
2575
|
n += d.length;
|
|
2401
2576
|
if (n > max) {
|
|
2402
2577
|
req.destroy();
|
|
2403
2578
|
out.destroy();
|
|
2404
|
-
|
|
2579
|
+
fs18.rm(to, { force: true }, () => fail(new Error("terlalu besar")));
|
|
2405
2580
|
}
|
|
2406
2581
|
});
|
|
2407
2582
|
req.pipe(out);
|
|
@@ -2429,8 +2604,8 @@ async function createRenderService(o) {
|
|
|
2429
2604
|
return;
|
|
2430
2605
|
} } = o;
|
|
2431
2606
|
const origins = new Set([].concat(o.origin || []));
|
|
2432
|
-
const sign = (kind, body) =>
|
|
2433
|
-
const dir = (job) =>
|
|
2607
|
+
const sign = (kind, body) => crypto7.createHmac("sha256", key).update(`${kind}.${body}`).digest("base64url");
|
|
2608
|
+
const dir = (job) => path14.join(folder, job);
|
|
2434
2609
|
await fsp4.mkdir(folder, { recursive: true });
|
|
2435
2610
|
function readTicket(req) {
|
|
2436
2611
|
const tk = String(req.headers.authorization || "").replace(/^Bearer\s+/i, "");
|
|
@@ -2452,7 +2627,7 @@ async function createRenderService(o) {
|
|
|
2452
2627
|
const jobs = new Map;
|
|
2453
2628
|
const queue = [];
|
|
2454
2629
|
let current = null;
|
|
2455
|
-
const persist = (t) => fsp4.writeFile(
|
|
2630
|
+
const persist = (t) => fsp4.writeFile(path14.join(dir(t.job), "status.json"), JSON.stringify(t)).catch(() => {
|
|
2456
2631
|
return;
|
|
2457
2632
|
});
|
|
2458
2633
|
const update = (t, patch) => (Object.assign(t, patch, { diperbarui: Date.now() }), void persist(t));
|
|
@@ -2471,19 +2646,19 @@ async function createRenderService(o) {
|
|
|
2471
2646
|
});
|
|
2472
2647
|
async function clearFiles(t, all = false) {
|
|
2473
2648
|
for (const n of all ? ["."] : ["paket", "paket.zip", "profil", "mentah.mp4", "mentah.webm"])
|
|
2474
|
-
await fsp4.rm(
|
|
2649
|
+
await fsp4.rm(path14.join(dir(t.job), n), { recursive: true, force: true }).catch(() => {
|
|
2475
2650
|
return;
|
|
2476
2651
|
});
|
|
2477
2652
|
if (!all) {
|
|
2478
2653
|
for (const f of await fsp4.readdir(dir(t.job)).catch(() => []))
|
|
2479
2654
|
if (/^p\d+$/.test(f))
|
|
2480
|
-
await fsp4.rm(
|
|
2655
|
+
await fsp4.rm(path14.join(dir(t.job), f), { force: true });
|
|
2481
2656
|
}
|
|
2482
2657
|
}
|
|
2483
2658
|
async function openPackage(t) {
|
|
2484
2659
|
const d = dir(t.job);
|
|
2485
2660
|
const main = t.tiket.jenis === "klip" ? "klip.json" : "proyek.json";
|
|
2486
|
-
const entries = await listZip(
|
|
2661
|
+
const entries = await listZip(path14.join(d, "paket.zip"));
|
|
2487
2662
|
const names = entries.map((x) => x.name).filter((n) => !n.endsWith("/"));
|
|
2488
2663
|
if (names.some((n) => n.startsWith("/") || n.includes("..") || n.includes("\\") || n !== main && !/^aset\/[\w-]+$/.test(n)))
|
|
2489
2664
|
throw new Error(EngineError.BadPackage);
|
|
@@ -2491,10 +2666,10 @@ async function createRenderService(o) {
|
|
|
2491
2666
|
throw new Error(`Paket tidak berisi ${main}.`);
|
|
2492
2667
|
if (entries.reduce((a, x) => a + x.size, 0) > maxUnzippedMb * 1048576)
|
|
2493
2668
|
throw new Error("Isi paket terlalu besar.");
|
|
2494
|
-
await extractZip(
|
|
2495
|
-
await fsp4.rm(
|
|
2496
|
-
const j = JSON.parse(await fsp4.readFile(
|
|
2497
|
-
const has = (id) => /^[\w-]+$/.test(id) &&
|
|
2669
|
+
await extractZip(path14.join(d, "paket.zip"), path14.join(d, "paket"));
|
|
2670
|
+
await fsp4.rm(path14.join(d, "paket.zip"), { force: true });
|
|
2671
|
+
const j = JSON.parse(await fsp4.readFile(path14.join(d, "paket", main), "utf8"));
|
|
2672
|
+
const has = (id) => /^[\w-]+$/.test(id) && fs18.existsSync(path14.join(d, "paket", "aset", id));
|
|
2498
2673
|
if (main === "klip.json") {
|
|
2499
2674
|
const k = j.klip || {};
|
|
2500
2675
|
const seconds = Number(k.durationInFrames) / Number(k.fps);
|
|
@@ -2542,7 +2717,7 @@ async function createRenderService(o) {
|
|
|
2542
2717
|
job: t.job,
|
|
2543
2718
|
kind: t.tiket.jenis,
|
|
2544
2719
|
dir: dir(t.job),
|
|
2545
|
-
packageDir:
|
|
2720
|
+
packageDir: path14.join(dir(t.job), "paket"),
|
|
2546
2721
|
transparent: !!t.transparan,
|
|
2547
2722
|
persen: t.persen,
|
|
2548
2723
|
width: t.tiket.w,
|
|
@@ -2562,7 +2737,7 @@ async function createRenderService(o) {
|
|
|
2562
2737
|
const size = (await fsp4.stat(h.file)).size;
|
|
2563
2738
|
if (size < 200)
|
|
2564
2739
|
throw new Error(EngineError.EmptyResult);
|
|
2565
|
-
update(t, { status: "selesai", persen: 100, tahap: "", selesaiPada: Date.now(), hasilUkuran: size, hasilBerkas:
|
|
2740
|
+
update(t, { status: "selesai", persen: 100, tahap: "", selesaiPada: Date.now(), hasilUkuran: size, hasilBerkas: path14.basename(h.file), hasilJenis: h.type });
|
|
2566
2741
|
onJob("done", t);
|
|
2567
2742
|
} catch (e) {
|
|
2568
2743
|
if (t.status !== "batal") {
|
|
@@ -2600,10 +2775,10 @@ async function createRenderService(o) {
|
|
|
2600
2775
|
if (a > z)
|
|
2601
2776
|
return res.writeHead(416, { ...h, "content-range": `bytes */${st.size}` }), res.end();
|
|
2602
2777
|
res.writeHead(206, { ...h, "content-length": z - a + 1, "content-range": `bytes ${a}-${z}/${st.size}` });
|
|
2603
|
-
return void
|
|
2778
|
+
return void fs18.createReadStream(f, { start: a, end: z }).pipe(res);
|
|
2604
2779
|
}
|
|
2605
2780
|
res.writeHead(200, { ...h, "content-length": st.size });
|
|
2606
|
-
|
|
2781
|
+
fs18.createReadStream(f).pipe(res);
|
|
2607
2782
|
}
|
|
2608
2783
|
const ROUTE = /^\/tugas(?:\/(r_[a-f0-9]{16})(\/potongan\/(\d{1,4})|\/mulai|\/hasil)?)?$/;
|
|
2609
2784
|
const server = http2.createServer(async (req, res) => {
|
|
@@ -2642,13 +2817,13 @@ async function createRenderService(o) {
|
|
|
2642
2817
|
if (t.status !== "unggah")
|
|
2643
2818
|
return json(req, res, 409, { galat: "Unggahan sudah ditutup." });
|
|
2644
2819
|
const n = Number(m[3]);
|
|
2645
|
-
const f =
|
|
2646
|
-
const before =
|
|
2820
|
+
const f = path14.join(dir(job), `p${n}`);
|
|
2821
|
+
const before = fs18.existsSync(f) ? (await fsp4.stat(f)).size : 0;
|
|
2647
2822
|
const room = Number(ticket.maksMb) * 1048576 - (t.terunggah - before);
|
|
2648
2823
|
const size = await saveBody2(req, f, Math.min(partMb * 1048576 + 1024, room));
|
|
2649
2824
|
const expected = String(req.headers["x-sha256"] || "").toLowerCase();
|
|
2650
2825
|
if (expected) {
|
|
2651
|
-
const digest =
|
|
2826
|
+
const digest = crypto7.createHash("sha256").update(await fsp4.readFile(f)).digest("hex");
|
|
2652
2827
|
if (digest !== expected) {
|
|
2653
2828
|
await fsp4.rm(f, { force: true });
|
|
2654
2829
|
update(t, { terunggah: t.terunggah - before });
|
|
@@ -2665,13 +2840,13 @@ async function createRenderService(o) {
|
|
|
2665
2840
|
const count = Number(b.jumlah);
|
|
2666
2841
|
if (!(count > 0 && count < 1e4))
|
|
2667
2842
|
return json(req, res, 400, { galat: "Jumlah potongan tidak valid." });
|
|
2668
|
-
const zip =
|
|
2669
|
-
const out =
|
|
2670
|
-
const hash =
|
|
2843
|
+
const zip = path14.join(dir(job), "paket.zip");
|
|
2844
|
+
const out = fs18.createWriteStream(zip);
|
|
2845
|
+
const hash = crypto7.createHash("sha256");
|
|
2671
2846
|
let total = 0;
|
|
2672
2847
|
for (let i = 0;i < count; i++) {
|
|
2673
|
-
const f =
|
|
2674
|
-
if (!
|
|
2848
|
+
const f = path14.join(dir(job), `p${i}`);
|
|
2849
|
+
if (!fs18.existsSync(f))
|
|
2675
2850
|
return out.destroy(), json(req, res, 400, { galat: `Potongan ${i + 1} belum terunggah.` });
|
|
2676
2851
|
const part = await fsp4.readFile(f);
|
|
2677
2852
|
hash.update(part);
|
|
@@ -2701,8 +2876,8 @@ async function createRenderService(o) {
|
|
|
2701
2876
|
return json(req, res, 200, summary(t));
|
|
2702
2877
|
}
|
|
2703
2878
|
if (m[2] === "/hasil" && (req.method === "GET" || req.method === "HEAD")) {
|
|
2704
|
-
const f = t.hasilBerkas ?
|
|
2705
|
-
if (t.status !== "selesai" || !f || !
|
|
2879
|
+
const f = t.hasilBerkas ? path14.join(dir(job), t.hasilBerkas) : "";
|
|
2880
|
+
if (t.status !== "selesai" || !f || !fs18.existsSync(f))
|
|
2706
2881
|
return json(req, res, 409, { galat: "Video belum jadi." });
|
|
2707
2882
|
const webm = t.hasilJenis === "video/webm";
|
|
2708
2883
|
return sendFile(req, res, f, webm ? "video/webm" : "video/mp4", `hypeframe-${job}.${webm ? "webm" : "mp4"}`);
|
|
@@ -2733,7 +2908,7 @@ async function createRenderService(o) {
|
|
|
2733
2908
|
if (!JOB_ID.test(job))
|
|
2734
2909
|
continue;
|
|
2735
2910
|
try {
|
|
2736
|
-
const t = JSON.parse(await fsp4.readFile(
|
|
2911
|
+
const t = JSON.parse(await fsp4.readFile(path14.join(dir(job), "status.json"), "utf8"));
|
|
2737
2912
|
if (t.status === "jalan" || t.status === "antre")
|
|
2738
2913
|
update(t, { status: "gagal", galat: EngineError.Restarted });
|
|
2739
2914
|
jobs.set(job, t);
|
|
@@ -2817,8 +2992,17 @@ function table(rows, indent = " ") {
|
|
|
2817
2992
|
import { spawn as spawn3 } from "node:child_process";
|
|
2818
2993
|
var PAIRING_LINK = new RegExp(`^https?://[A-Za-z0-9.-]+(:\\d+)?/sambung\\?kode=${PAIRING_CODE.source.slice(1, -1)}$`);
|
|
2819
2994
|
var WEB_ORIGIN = /^https?:\/\/[A-Za-z0-9.-]+(:\d+)?\/?$/;
|
|
2820
|
-
function
|
|
2821
|
-
|
|
2995
|
+
function openCommand(target, platform, url) {
|
|
2996
|
+
if (platform === "win32")
|
|
2997
|
+
return ["explorer.exe", [target]];
|
|
2998
|
+
if (platform === "darwin")
|
|
2999
|
+
return ["open", [target]];
|
|
3000
|
+
if (platform === "android")
|
|
3001
|
+
return [url ? "termux-open-url" : "termux-open", [target]];
|
|
3002
|
+
return ["xdg-open", [target]];
|
|
3003
|
+
}
|
|
3004
|
+
function launch(target, url) {
|
|
3005
|
+
const [cmd, args] = openCommand(target, isAndroid() ? "android" : process.platform, url);
|
|
2822
3006
|
const p = spawn3(cmd, args, { stdio: "ignore", detached: true });
|
|
2823
3007
|
p.on("error", () => {
|
|
2824
3008
|
return;
|
|
@@ -2828,11 +3012,17 @@ function launch(target) {
|
|
|
2828
3012
|
function openUrl(url, allowed) {
|
|
2829
3013
|
if (!allowed.test(url))
|
|
2830
3014
|
return false;
|
|
2831
|
-
launch(url);
|
|
3015
|
+
launch(url, true);
|
|
2832
3016
|
return true;
|
|
2833
3017
|
}
|
|
2834
3018
|
function openFolder(dir) {
|
|
2835
|
-
launch(dir);
|
|
3019
|
+
launch(dir, false);
|
|
3020
|
+
}
|
|
3021
|
+
function openOnPhone(url) {
|
|
3022
|
+
if (!/^https?:\/\/[^\s]{1,2000}$/.test(url))
|
|
3023
|
+
return false;
|
|
3024
|
+
launch(url, true);
|
|
3025
|
+
return true;
|
|
2836
3026
|
}
|
|
2837
3027
|
|
|
2838
3028
|
// src/cli/commands/start.ts
|
|
@@ -2887,8 +3077,13 @@ async function start(args, { fromMenu = false } = {}) {
|
|
|
2887
3077
|
bridge: bridgeLaunch(),
|
|
2888
3078
|
onToolError: (e) => log.warn(t(e === "tab" ? "agent.toolNoTab" : "agent.toolNoAnswer"))
|
|
2889
3079
|
});
|
|
3080
|
+
if (isAndroid())
|
|
3081
|
+
watchOpenRequests((url) => {
|
|
3082
|
+
log.info(t("linux.openUrl", { url }));
|
|
3083
|
+
openOnPhone(url);
|
|
3084
|
+
});
|
|
2890
3085
|
const capabilities = { render: false, chrome: null, transparan: false, agen: agents.capabilities() };
|
|
2891
|
-
const key =
|
|
3086
|
+
const key = crypto8.randomBytes(32).toString("base64url");
|
|
2892
3087
|
const cache = cacheDir();
|
|
2893
3088
|
const page = createPage({ web: s.web, cacheDir: cache });
|
|
2894
3089
|
let runner = null;
|
|
@@ -3024,24 +3219,24 @@ function logout() {
|
|
|
3024
3219
|
}
|
|
3025
3220
|
|
|
3026
3221
|
// src/cli/commands/autostart.ts
|
|
3027
|
-
import { spawnSync as
|
|
3028
|
-
import
|
|
3222
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
3223
|
+
import fs19 from "node:fs";
|
|
3029
3224
|
import os3 from "node:os";
|
|
3030
|
-
import
|
|
3225
|
+
import path15 from "node:path";
|
|
3031
3226
|
function entryFile() {
|
|
3032
3227
|
const home = os3.homedir();
|
|
3033
3228
|
if (process.platform === "win32")
|
|
3034
|
-
return
|
|
3229
|
+
return path15.join(process.env.APPDATA || path15.join(home, "AppData", "Roaming"), "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "HypeFrame.cmd");
|
|
3035
3230
|
if (process.platform === "darwin")
|
|
3036
|
-
return
|
|
3231
|
+
return path15.join(home, "Library", "LaunchAgents", "com.hypeframe.engine.plist");
|
|
3037
3232
|
if (hasSystemd())
|
|
3038
|
-
return
|
|
3039
|
-
return
|
|
3233
|
+
return path15.join(home, ".config", "systemd", "user", "hypeframe.service");
|
|
3234
|
+
return path15.join(home, ".config", "autostart", "hypeframe.desktop");
|
|
3040
3235
|
}
|
|
3041
3236
|
function hasSystemd() {
|
|
3042
|
-
return process.platform === "linux" &&
|
|
3237
|
+
return process.platform === "linux" && spawnSync3("systemctl", ["--user", "--version"], { stdio: "ignore" }).status === 0;
|
|
3043
3238
|
}
|
|
3044
|
-
var autostartEnabled = () =>
|
|
3239
|
+
var autostartEnabled = () => fs19.existsSync(entryFile());
|
|
3045
3240
|
var xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
3046
3241
|
function autostart(mode) {
|
|
3047
3242
|
const file = entryFile();
|
|
@@ -3052,8 +3247,8 @@ function autostart(mode) {
|
|
|
3052
3247
|
}
|
|
3053
3248
|
if (mode === "off") {
|
|
3054
3249
|
if (process.platform === "linux" && file.endsWith(".service"))
|
|
3055
|
-
|
|
3056
|
-
|
|
3250
|
+
spawnSync3("systemctl", ["--user", "disable", "hypeframe.service"], { stdio: "ignore" });
|
|
3251
|
+
fs19.rmSync(file, { force: true });
|
|
3057
3252
|
log.ok(t("autostart.off"));
|
|
3058
3253
|
return;
|
|
3059
3254
|
}
|
|
@@ -3068,14 +3263,14 @@ function autostart(mode) {
|
|
|
3068
3263
|
return;
|
|
3069
3264
|
}
|
|
3070
3265
|
const quoted = cmd.map((c) => `"${c}"`).join(" ");
|
|
3071
|
-
|
|
3266
|
+
fs19.mkdirSync(path15.dirname(file), { recursive: true });
|
|
3072
3267
|
if (process.platform === "win32") {
|
|
3073
|
-
|
|
3268
|
+
fs19.writeFileSync(file, `@echo off\r
|
|
3074
3269
|
start "HypeFrame" /min ${quoted} start --no-browser\r
|
|
3075
3270
|
`);
|
|
3076
3271
|
} else if (process.platform === "darwin") {
|
|
3077
|
-
const out =
|
|
3078
|
-
|
|
3272
|
+
const out = path15.join(logDir(), "autostart.log");
|
|
3273
|
+
fs19.writeFileSync(file, `<?xml version="1.0" encoding="UTF-8"?>
|
|
3079
3274
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3080
3275
|
<plist version="1.0"><dict>
|
|
3081
3276
|
<key>Label</key><string>com.hypeframe.engine</string>
|
|
@@ -3086,7 +3281,7 @@ start "HypeFrame" /min ${quoted} start --no-browser\r
|
|
|
3086
3281
|
</dict></plist>
|
|
3087
3282
|
`);
|
|
3088
3283
|
} else if (file.endsWith(".service")) {
|
|
3089
|
-
|
|
3284
|
+
fs19.writeFileSync(file, `[Unit]
|
|
3090
3285
|
Description=HypeFrame engine
|
|
3091
3286
|
After=network-online.target
|
|
3092
3287
|
|
|
@@ -3098,10 +3293,10 @@ RestartSec=60
|
|
|
3098
3293
|
[Install]
|
|
3099
3294
|
WantedBy=default.target
|
|
3100
3295
|
`);
|
|
3101
|
-
|
|
3102
|
-
|
|
3296
|
+
spawnSync3("systemctl", ["--user", "daemon-reload"], { stdio: "ignore" });
|
|
3297
|
+
spawnSync3("systemctl", ["--user", "enable", "hypeframe.service"], { stdio: "ignore" });
|
|
3103
3298
|
} else {
|
|
3104
|
-
|
|
3299
|
+
fs19.writeFileSync(file, `[Desktop Entry]
|
|
3105
3300
|
Type=Application
|
|
3106
3301
|
Name=HypeFrame engine
|
|
3107
3302
|
Exec=${quoted} start --no-browser
|
|
@@ -3167,7 +3362,7 @@ async function bench(args) {
|
|
|
3167
3362
|
executablePath: chrome,
|
|
3168
3363
|
headless: true,
|
|
3169
3364
|
protocolTimeout: 300000,
|
|
3170
|
-
args: ["--no-first-run", "--disable-extensions", ...s.gpu ? [] : softwareGpuArgs]
|
|
3365
|
+
args: ["--no-first-run", "--disable-extensions", ...s.gpu ? [] : softwareGpuArgs, ...chromePlatformArgs()]
|
|
3171
3366
|
});
|
|
3172
3367
|
const rows = [];
|
|
3173
3368
|
try {
|
|
@@ -3203,9 +3398,9 @@ async function bench(args) {
|
|
|
3203
3398
|
import * as p from "@clack/prompts";
|
|
3204
3399
|
|
|
3205
3400
|
// src/agent/install.ts
|
|
3206
|
-
import
|
|
3401
|
+
import fs20 from "node:fs";
|
|
3207
3402
|
import fsp5 from "node:fs/promises";
|
|
3208
|
-
import
|
|
3403
|
+
import path16 from "node:path";
|
|
3209
3404
|
import yauzl2 from "yauzl";
|
|
3210
3405
|
function unzip(file, to) {
|
|
3211
3406
|
return new Promise((ok, fail) => {
|
|
@@ -3213,16 +3408,16 @@ function unzip(file, to) {
|
|
|
3213
3408
|
if (e || !zip)
|
|
3214
3409
|
return fail(e ?? new Error("zip"));
|
|
3215
3410
|
zip.on("entry", (en) => {
|
|
3216
|
-
const target =
|
|
3217
|
-
if (!target.startsWith(to +
|
|
3411
|
+
const target = path16.join(to, en.fileName);
|
|
3412
|
+
if (!target.startsWith(to + path16.sep))
|
|
3218
3413
|
return fail(new Error("archive path outside the agent folder"));
|
|
3219
3414
|
if (en.fileName.endsWith("/"))
|
|
3220
|
-
return
|
|
3221
|
-
|
|
3415
|
+
return fs20.mkdirSync(target, { recursive: true }), zip.readEntry();
|
|
3416
|
+
fs20.mkdirSync(path16.dirname(target), { recursive: true });
|
|
3222
3417
|
zip.openReadStream(en, (e2, s) => {
|
|
3223
3418
|
if (e2 || !s)
|
|
3224
3419
|
return fail(e2 ?? new Error("zip"));
|
|
3225
|
-
const out =
|
|
3420
|
+
const out = fs20.createWriteStream(target);
|
|
3226
3421
|
s.pipe(out);
|
|
3227
3422
|
out.on("finish", () => zip.readEntry());
|
|
3228
3423
|
out.on("error", fail);
|
|
@@ -3237,7 +3432,7 @@ function unzip(file, to) {
|
|
|
3237
3432
|
async function untarGz(file, to) {
|
|
3238
3433
|
const { gunzipSync } = await import("node:zlib");
|
|
3239
3434
|
const data = gunzipSync(await fsp5.readFile(file));
|
|
3240
|
-
const root =
|
|
3435
|
+
const root = path16.resolve(to);
|
|
3241
3436
|
const str = (b) => b.toString("utf8").replace(/\0[\s\S]*$/, "");
|
|
3242
3437
|
const octal = (b) => Number.parseInt(str(b).trim() || "0", 8) || 0;
|
|
3243
3438
|
let off = 0;
|
|
@@ -3268,8 +3463,8 @@ async function untarGz(file, to) {
|
|
|
3268
3463
|
name = name.replace(/^\.\//, "");
|
|
3269
3464
|
if (!name)
|
|
3270
3465
|
continue;
|
|
3271
|
-
const target =
|
|
3272
|
-
if (target !== root && !target.startsWith(root +
|
|
3466
|
+
const target = path16.resolve(root, name);
|
|
3467
|
+
if (target !== root && !target.startsWith(root + path16.sep))
|
|
3273
3468
|
throw new Error("archive path outside the agent folder");
|
|
3274
3469
|
if (type === "5") {
|
|
3275
3470
|
await fsp5.mkdir(target, { recursive: true });
|
|
@@ -3277,36 +3472,22 @@ async function untarGz(file, to) {
|
|
|
3277
3472
|
}
|
|
3278
3473
|
if (type !== "0" && type !== "7")
|
|
3279
3474
|
continue;
|
|
3280
|
-
await fsp5.mkdir(
|
|
3475
|
+
await fsp5.mkdir(path16.dirname(target), { recursive: true });
|
|
3281
3476
|
await fsp5.writeFile(target, body, { mode: octal(h.subarray(100, 108)) & 73 ? 493 : 420 });
|
|
3282
3477
|
}
|
|
3283
3478
|
}
|
|
3284
3479
|
function npxRunner(pkg, extra = []) {
|
|
3285
3480
|
if (isStandalone())
|
|
3286
3481
|
return { cmd: process.execPath, args: ["x", pkg, ...extra], env: { BUN_BE_BUN: "1" } };
|
|
3287
|
-
const npxCli =
|
|
3288
|
-
if (!
|
|
3482
|
+
const npxCli = path16.join(path16.dirname(process.execPath), process.platform === "win32" ? "" : "..", process.platform === "win32" ? "node_modules" : "lib/node_modules", "npm", "bin", "npx-cli.js");
|
|
3483
|
+
if (!fs20.existsSync(npxCli))
|
|
3289
3484
|
throw new Error("npx was not found next to Node.js");
|
|
3290
3485
|
return { cmd: process.execPath, args: [npxCli, "-y", pkg, ...extra], env: {} };
|
|
3291
3486
|
}
|
|
3292
|
-
function onPath(name) {
|
|
3293
|
-
if (!/^[\w.@+-]{1,80}$/.test(name))
|
|
3294
|
-
return null;
|
|
3295
|
-
const file = process.platform === "win32" ? /\.exe$/i.test(name) ? name : `${name}.exe` : name;
|
|
3296
|
-
for (const dir of (process.env.PATH || "").split(path14.delimiter).filter(Boolean)) {
|
|
3297
|
-
const f = path14.join(dir, file);
|
|
3298
|
-
try {
|
|
3299
|
-
const st = fs18.statSync(f);
|
|
3300
|
-
if (st.isFile() && (process.platform === "win32" || st.mode & 73))
|
|
3301
|
-
return f;
|
|
3302
|
-
} catch {}
|
|
3303
|
-
}
|
|
3304
|
-
return null;
|
|
3305
|
-
}
|
|
3306
3487
|
function ownCopy(a) {
|
|
3307
3488
|
const bin = a.distribution.binary?.[platformKey()];
|
|
3308
3489
|
if (bin) {
|
|
3309
|
-
const cmd = onPath(
|
|
3490
|
+
const cmd = onPath(path16.basename(bin.cmd).replace(/\.exe$/i, ""));
|
|
3310
3491
|
return cmd ? { cmd, args: bin.args ?? [], env: bin.env ?? {} } : null;
|
|
3311
3492
|
}
|
|
3312
3493
|
const npx = a.distribution.npx;
|
|
@@ -3317,6 +3498,108 @@ function ownCopy(a) {
|
|
|
3317
3498
|
}
|
|
3318
3499
|
return null;
|
|
3319
3500
|
}
|
|
3501
|
+
async function unpackBinary(id, version, bin, progress) {
|
|
3502
|
+
if (!/^[0-9a-f]{64}$/i.test(bin.sha256 || ""))
|
|
3503
|
+
throw new Error(`Agent ${id}: the registry gives no sha256; not installed`);
|
|
3504
|
+
const dir = path16.join(agentDir(), id, version);
|
|
3505
|
+
const tmp = `${dir}.tmp`;
|
|
3506
|
+
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
3507
|
+
await fsp5.mkdir(tmp, { recursive: true });
|
|
3508
|
+
try {
|
|
3509
|
+
const name = path16.basename(new URL(bin.archive).pathname);
|
|
3510
|
+
const cmdRel = bin.cmd.replace(/^\.\//, "");
|
|
3511
|
+
if (/\.zip$/i.test(name)) {
|
|
3512
|
+
const file = path16.join(tmp, ".download.zip");
|
|
3513
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
3514
|
+
await unzip(file, tmp);
|
|
3515
|
+
await fsp5.rm(file, { force: true });
|
|
3516
|
+
} else if (/\.(tar\.gz|tgz)$/i.test(name)) {
|
|
3517
|
+
const file = path16.join(tmp, ".download.tar.gz");
|
|
3518
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
3519
|
+
await untarGz(file, tmp);
|
|
3520
|
+
await fsp5.rm(file, { force: true });
|
|
3521
|
+
} else if (/\.gz$/i.test(name)) {
|
|
3522
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), path16.join(tmp, cmdRel), progress, true);
|
|
3523
|
+
} else
|
|
3524
|
+
throw new Error(`Agent ${id}: unsupported archive ${name}`);
|
|
3525
|
+
const cmd = path16.join(tmp, cmdRel);
|
|
3526
|
+
if (!fs20.existsSync(cmd))
|
|
3527
|
+
throw new Error(`Agent ${id}: ${bin.cmd} is not in the download`);
|
|
3528
|
+
if (process.platform !== "win32")
|
|
3529
|
+
await fsp5.chmod(cmd, 493);
|
|
3530
|
+
await fsp5.rm(dir, { recursive: true, force: true });
|
|
3531
|
+
await fsp5.rename(tmp, dir);
|
|
3532
|
+
return { cmd: path16.join(dir, cmdRel), args: bin.args ?? [], env: bin.env ?? {} };
|
|
3533
|
+
} catch (e) {
|
|
3534
|
+
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
3535
|
+
throw e;
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
var codexAcpRelease = () => process.env.HYPEFRAME_CODEX_ACP_RELEASE || "https://api.github.com/repos/zed-industries/codex-acp/releases/latest";
|
|
3539
|
+
async function codexAcpBuild(arch) {
|
|
3540
|
+
const j = await (await fetch(codexAcpRelease(), { headers: { accept: "application/vnd.github+json", "user-agent": "hypeframe" }, signal: AbortSignal.timeout(20000) })).json();
|
|
3541
|
+
const triple = arch === "x64" ? "x86_64" : "aarch64";
|
|
3542
|
+
const asset = (j.assets ?? []).find((x) => new RegExp(`${triple}-unknown-linux-musl\\.tar\\.gz$`).test(String(x.name)));
|
|
3543
|
+
const sha256 = /^sha256:([0-9a-f]{64})$/i.exec(String(asset?.digest ?? ""))?.[1];
|
|
3544
|
+
const url = String(asset?.browser_download_url ?? "");
|
|
3545
|
+
if (!asset || !sha256 || !url)
|
|
3546
|
+
throw new Error("codex-acp: no checked Linux build for this phone");
|
|
3547
|
+
if (!process.env.HYPEFRAME_CODEX_ACP_RELEASE && !url.startsWith("https://github.com/"))
|
|
3548
|
+
throw new Error("codex-acp: unexpected download address");
|
|
3549
|
+
return { url, sha256: sha256.toLowerCase(), version: String(j.tag_name ?? "latest").replace(/^v/, "") };
|
|
3550
|
+
}
|
|
3551
|
+
var findFile = (dir, name) => {
|
|
3552
|
+
for (const n of fs20.readdirSync(dir)) {
|
|
3553
|
+
const f = path16.join(dir, n);
|
|
3554
|
+
const st = fs20.lstatSync(f);
|
|
3555
|
+
if (st.isFile() && n === name)
|
|
3556
|
+
return f;
|
|
3557
|
+
if (st.isDirectory()) {
|
|
3558
|
+
const inner = findFile(f, name);
|
|
3559
|
+
if (inner)
|
|
3560
|
+
return inner;
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
return null;
|
|
3564
|
+
};
|
|
3565
|
+
async function installInLinux(a, id, progress, steps, arch) {
|
|
3566
|
+
steps.prepare();
|
|
3567
|
+
if (id === "antigravity-acp") {
|
|
3568
|
+
if (!steps.run("curl -fsSL https://antigravity.google/cli/install.sh | bash"))
|
|
3569
|
+
throw new Error("Antigravity: Google's installer did not finish in the Linux mini");
|
|
3570
|
+
if (!fs20.existsSync(path16.join(rootfs(), "root", ".local", "bin", "agy")))
|
|
3571
|
+
throw new Error("Antigravity: agy was not installed in the Linux mini");
|
|
3572
|
+
return { launch: { cmd: "/root/.local/bin/agy", args: ["acp"], env: {}, linux: true }, version: a.version };
|
|
3573
|
+
}
|
|
3574
|
+
if (id === "codex-acp") {
|
|
3575
|
+
const b = await codexAcpBuild(arch);
|
|
3576
|
+
const dir = path16.join(agentDir(), id, b.version);
|
|
3577
|
+
const tmp = `${dir}.tmp`;
|
|
3578
|
+
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
3579
|
+
await fsp5.mkdir(tmp, { recursive: true });
|
|
3580
|
+
try {
|
|
3581
|
+
const file = path16.join(tmp, ".download.tar.gz");
|
|
3582
|
+
await downloadVerified(b.url, b.sha256, file, progress);
|
|
3583
|
+
await untarGz(file, tmp);
|
|
3584
|
+
await fsp5.rm(file, { force: true });
|
|
3585
|
+
const found = findFile(tmp, "codex-acp");
|
|
3586
|
+
if (!found)
|
|
3587
|
+
throw new Error("codex-acp: the program is not in the download");
|
|
3588
|
+
const rel = path16.relative(tmp, found);
|
|
3589
|
+
await fsp5.chmod(found, 493);
|
|
3590
|
+
await fsp5.rm(dir, { recursive: true, force: true });
|
|
3591
|
+
await fsp5.rename(tmp, dir);
|
|
3592
|
+
return { launch: { cmd: path16.join(dir, rel), args: [], env: {}, linux: true }, version: b.version };
|
|
3593
|
+
} catch (e) {
|
|
3594
|
+
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
3595
|
+
throw e;
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
const bin = a.distribution.binary?.[`linux-${arch === "x64" ? "x86_64" : "aarch64"}`];
|
|
3599
|
+
if (!bin)
|
|
3600
|
+
throw new Error(`Agent ${id} has no Linux build to run on this phone`);
|
|
3601
|
+
return { launch: { ...await unpackBinary(id, a.version, bin, progress), linux: true }, version: a.version };
|
|
3602
|
+
}
|
|
3320
3603
|
async function installAgent(id, progress = () => {
|
|
3321
3604
|
return;
|
|
3322
3605
|
}, opts = {}) {
|
|
@@ -3326,6 +3609,13 @@ async function installAgent(id, progress = () => {
|
|
|
3326
3609
|
const local = a.distribution.local;
|
|
3327
3610
|
if (!isSupported(id) && !local)
|
|
3328
3611
|
throw new Error(`Agent ${id} is not supported`);
|
|
3612
|
+
if (!local && (opts.android ?? isAndroid())) {
|
|
3613
|
+
const steps = opts.linux ?? { prepare: () => prepareLinux(opts.say), run: runInLinux };
|
|
3614
|
+
const r = await installInLinux(a, id, progress, steps, opts.arch ?? process.arch);
|
|
3615
|
+
const installed = { id, name: a.name, version: r.version, launch: r.launch };
|
|
3616
|
+
writeInstalled(installed);
|
|
3617
|
+
return installed;
|
|
3618
|
+
}
|
|
3329
3619
|
let launch;
|
|
3330
3620
|
const bin = a.distribution.binary?.[platformKey()];
|
|
3331
3621
|
const own = local || opts.download ? null : ownCopy(a);
|
|
@@ -3334,41 +3624,7 @@ async function installAgent(id, progress = () => {
|
|
|
3334
3624
|
} else if (own) {
|
|
3335
3625
|
launch = own;
|
|
3336
3626
|
} else if (bin) {
|
|
3337
|
-
|
|
3338
|
-
throw new Error(`Agent ${id}: the registry gives no sha256; not installed`);
|
|
3339
|
-
const dir = path14.join(agentDir(), id, a.version);
|
|
3340
|
-
const tmp = `${dir}.tmp`;
|
|
3341
|
-
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
3342
|
-
await fsp5.mkdir(tmp, { recursive: true });
|
|
3343
|
-
try {
|
|
3344
|
-
const name = path14.basename(new URL(bin.archive).pathname);
|
|
3345
|
-
const cmdRel = bin.cmd.replace(/^\.\//, "");
|
|
3346
|
-
if (/\.zip$/i.test(name)) {
|
|
3347
|
-
const file = path14.join(tmp, ".download.zip");
|
|
3348
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
3349
|
-
await unzip(file, tmp);
|
|
3350
|
-
await fsp5.rm(file, { force: true });
|
|
3351
|
-
} else if (/\.(tar\.gz|tgz)$/i.test(name)) {
|
|
3352
|
-
const file = path14.join(tmp, ".download.tar.gz");
|
|
3353
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
3354
|
-
await untarGz(file, tmp);
|
|
3355
|
-
await fsp5.rm(file, { force: true });
|
|
3356
|
-
} else if (/\.gz$/i.test(name)) {
|
|
3357
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), path14.join(tmp, cmdRel), progress, true);
|
|
3358
|
-
} else
|
|
3359
|
-
throw new Error(`Agent ${id}: unsupported archive ${name}`);
|
|
3360
|
-
const cmd = path14.join(tmp, cmdRel);
|
|
3361
|
-
if (!fs18.existsSync(cmd))
|
|
3362
|
-
throw new Error(`Agent ${id}: ${bin.cmd} is not in the download`);
|
|
3363
|
-
if (process.platform !== "win32")
|
|
3364
|
-
await fsp5.chmod(cmd, 493);
|
|
3365
|
-
await fsp5.rm(dir, { recursive: true, force: true });
|
|
3366
|
-
await fsp5.rename(tmp, dir);
|
|
3367
|
-
launch = { cmd: path14.join(dir, cmdRel), args: bin.args ?? [], env: bin.env ?? {} };
|
|
3368
|
-
} catch (e) {
|
|
3369
|
-
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
3370
|
-
throw e;
|
|
3371
|
-
}
|
|
3627
|
+
launch = await unpackBinary(id, a.version, bin, progress);
|
|
3372
3628
|
} else if (a.distribution.npx) {
|
|
3373
3629
|
launch = { ...npxRunner(a.distribution.npx.package, a.distribution.npx.args), env: { ...a.distribution.npx.env ?? {} } };
|
|
3374
3630
|
if (isStandalone())
|
|
@@ -3381,7 +3637,7 @@ async function installAgent(id, progress = () => {
|
|
|
3381
3637
|
}
|
|
3382
3638
|
|
|
3383
3639
|
// src/agent/login.ts
|
|
3384
|
-
import { spawnSync as
|
|
3640
|
+
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
3385
3641
|
async function keyFromShell(name, io) {
|
|
3386
3642
|
const value = process.env[name];
|
|
3387
3643
|
if (!value)
|
|
@@ -3391,7 +3647,6 @@ async function keyFromShell(name, io) {
|
|
|
3391
3647
|
io.say(t("agent.keyFromShell", { name }));
|
|
3392
3648
|
return value;
|
|
3393
3649
|
}
|
|
3394
|
-
var API_KEY_ONLY = { "claude-acp": "ANTHROPIC_API_KEY" };
|
|
3395
3650
|
async function checkReady(id) {
|
|
3396
3651
|
const a = readInstalled().find((x) => x.id === id);
|
|
3397
3652
|
if (!a)
|
|
@@ -3409,37 +3664,31 @@ async function checkReady(id) {
|
|
|
3409
3664
|
await proc.stop();
|
|
3410
3665
|
}
|
|
3411
3666
|
}
|
|
3667
|
+
var isKey = (m) => m.type === "env_var" || !!m.varName;
|
|
3412
3668
|
function pick(methods) {
|
|
3413
|
-
return methods.find((m) => m.type === "terminal") ?? methods.find((m) => m.type === "
|
|
3669
|
+
return methods.find((m) => m.type === "terminal") ?? methods.find((m) => (!m.type || m.type === "agent") && !isKey(m)) ?? methods.find(isKey);
|
|
3414
3670
|
}
|
|
3415
3671
|
async function loginAgent(id, io) {
|
|
3416
3672
|
const a = readInstalled().find((x) => x.id === id);
|
|
3417
3673
|
if (!a)
|
|
3418
3674
|
throw new Error(`Agent ${id} is not installed`);
|
|
3419
|
-
const onlyKey = API_KEY_ONLY[id];
|
|
3420
|
-
if (onlyKey) {
|
|
3421
|
-
const value = await keyFromShell(onlyKey, io) || await io.ask(onlyKey);
|
|
3422
|
-
if (!value)
|
|
3423
|
-
return false;
|
|
3424
|
-
saveAgentEnv(id, { [onlyKey]: value.trim() });
|
|
3425
|
-
return checkReady(id);
|
|
3426
|
-
}
|
|
3427
3675
|
const proc = new AcpProcess;
|
|
3428
3676
|
let method;
|
|
3429
3677
|
try {
|
|
3430
3678
|
const init = await proc.start(a, projectDir("_cek"), agentEnv(id));
|
|
3431
3679
|
method = pick(init.authMethods ?? []);
|
|
3432
|
-
if (method && (!method.type || method.type === "agent"))
|
|
3680
|
+
if (method && (!method.type || method.type === "agent") && !isKey(method))
|
|
3433
3681
|
await proc.request("authenticate", { methodId: method.id }, 10 * 60000);
|
|
3434
3682
|
} finally {
|
|
3435
3683
|
await proc.stop();
|
|
3436
3684
|
}
|
|
3437
3685
|
if (method?.type === "terminal") {
|
|
3438
3686
|
io.say(method.name || method.description || id);
|
|
3439
|
-
const
|
|
3687
|
+
const [cmd, args, env] = agentSpawn(a, { ...agentEnv(id), ...method.env ?? {} }, method.args ?? []);
|
|
3688
|
+
const r = spawnSync4(cmd, args, { stdio: "inherit", env });
|
|
3440
3689
|
if (r.status !== 0)
|
|
3441
3690
|
return setReady(id, false), false;
|
|
3442
|
-
} else if (method && (method
|
|
3691
|
+
} else if (method && isKey(method)) {
|
|
3443
3692
|
const name = method.varName || method.id;
|
|
3444
3693
|
const value = await keyFromShell(name, io) || await io.ask(name);
|
|
3445
3694
|
if (!value)
|
|
@@ -3450,7 +3699,7 @@ async function loginAgent(id, io) {
|
|
|
3450
3699
|
}
|
|
3451
3700
|
|
|
3452
3701
|
// src/cli/commands/agent.ts
|
|
3453
|
-
var NAMES = { "
|
|
3702
|
+
var NAMES = { "antigravity-acp": "Antigravity", "codex-acp": "Codex", opencode: "OpenCode" };
|
|
3454
3703
|
var agentName = (id) => NAMES[id] ?? readInstalled().find((a) => a.id === id)?.name ?? id;
|
|
3455
3704
|
function agentState(id) {
|
|
3456
3705
|
const a = readInstalled().find((x) => x.id === id);
|
|
@@ -3493,9 +3742,11 @@ async function addAgent(id, download = false) {
|
|
|
3493
3742
|
log.info(t("agent.installing", { name: agentName(id) }));
|
|
3494
3743
|
let last = -10;
|
|
3495
3744
|
const a = await installAgent(id, (pc) => {
|
|
3496
|
-
if (pc - last >= 20)
|
|
3497
|
-
last = pc
|
|
3498
|
-
|
|
3745
|
+
if (pc - last >= 20 || pc >= 100 && last < 100) {
|
|
3746
|
+
last = pc;
|
|
3747
|
+
log.detail(pc >= 100 ? t("agent.unpacking") : `${pc}%`);
|
|
3748
|
+
}
|
|
3749
|
+
}, { download, say: (k) => log.info(t(k)) });
|
|
3499
3750
|
if (a.own)
|
|
3500
3751
|
log.ok(t("agent.own", { name: a.name, path: a.launch.cmd }));
|
|
3501
3752
|
else
|
|
@@ -3506,10 +3757,14 @@ async function addAgent(id, download = false) {
|
|
|
3506
3757
|
return ok;
|
|
3507
3758
|
}
|
|
3508
3759
|
async function loginOne(id) {
|
|
3509
|
-
if (id === "claude-acp")
|
|
3510
|
-
log.detail(t("agent.claudeKey"));
|
|
3511
3760
|
log.info(t("agent.loggingIn", { name: agentName(id) }));
|
|
3512
|
-
const
|
|
3761
|
+
const stop = isAndroid() ? watchOpenRequests((url) => {
|
|
3762
|
+
log.info(t("linux.openUrl", { url }));
|
|
3763
|
+
openOnPhone(url);
|
|
3764
|
+
}) : () => {
|
|
3765
|
+
return;
|
|
3766
|
+
};
|
|
3767
|
+
const ok = await loginAgent(id, io).finally(stop);
|
|
3513
3768
|
if (ok)
|
|
3514
3769
|
log.ok(t("agent.loggedIn", { name: agentName(id) }));
|
|
3515
3770
|
else
|
|
@@ -3635,9 +3890,9 @@ async function config(args) {
|
|
|
3635
3890
|
}
|
|
3636
3891
|
|
|
3637
3892
|
// src/cli/commands/doctor.ts
|
|
3638
|
-
import { spawnSync as
|
|
3639
|
-
import
|
|
3640
|
-
import
|
|
3893
|
+
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
3894
|
+
import fs21 from "node:fs";
|
|
3895
|
+
import path17 from "node:path";
|
|
3641
3896
|
var mark = { ok: color.ok(icon.ok), warn: color.warn(icon.warn), error: color.error(icon.error) };
|
|
3642
3897
|
async function reach(url) {
|
|
3643
3898
|
const t0 = Date.now();
|
|
@@ -3666,10 +3921,10 @@ async function doctor(args) {
|
|
|
3666
3921
|
show({ label: "Node.js", result: maj > 20 || maj === 20 && min >= 3 ? "ok" : "error", detail: `${process.versions.node}${maj < 20 || maj === 20 && min < 3 ? ` ${t("doctor.nodeOld")}` : ""}` });
|
|
3667
3922
|
}
|
|
3668
3923
|
try {
|
|
3669
|
-
const probe =
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
const st =
|
|
3924
|
+
const probe = path17.join(dataDir(), `.probe-${process.pid}`);
|
|
3925
|
+
fs21.writeFileSync(probe, "x");
|
|
3926
|
+
fs21.rmSync(probe);
|
|
3927
|
+
const st = fs21.statfsSync(dataDir());
|
|
3673
3928
|
const free = st.bavail * st.bsize;
|
|
3674
3929
|
show({ label: t("doctor.disk"), result: free > 2 * 1024 ** 3 ? "ok" : "warn", detail: `${dataDir()} ${color.muted(icon.dot)} ${t("doctor.free", { size: bytes2(free) })}` });
|
|
3675
3930
|
} catch (e) {
|
|
@@ -3680,7 +3935,7 @@ async function doctor(args) {
|
|
|
3680
3935
|
const canDownload = !!FFMPEG_PINNED[`${process.platform}-${process.arch}`];
|
|
3681
3936
|
show({ label: "ffmpeg", result: canDownload ? "warn" : "error", detail: canDownload ? t("doctor.ffmpegLater") : t("doctor.noFfmpeg") });
|
|
3682
3937
|
} else {
|
|
3683
|
-
const r =
|
|
3938
|
+
const r = spawnSync5(ff, ["-hide_banner", "-version"], { encoding: "utf8", timeout: 15000 });
|
|
3684
3939
|
const v = /ffmpeg version (\S+)/.exec(r.stdout || "")?.[1];
|
|
3685
3940
|
show({ label: "ffmpeg", result: v ? "ok" : "error", detail: v || t("doctor.noFfmpeg") });
|
|
3686
3941
|
}
|
|
@@ -3713,21 +3968,21 @@ async function doctor(args) {
|
|
|
3713
3968
|
}
|
|
3714
3969
|
|
|
3715
3970
|
// src/cli/commands/history.ts
|
|
3716
|
-
import
|
|
3717
|
-
import
|
|
3971
|
+
import fs22 from "node:fs";
|
|
3972
|
+
import path18 from "node:path";
|
|
3718
3973
|
function readHistory2(hours = 24) {
|
|
3719
3974
|
const root = renderDir();
|
|
3720
3975
|
const since = Date.now() - hours * 3600000;
|
|
3721
3976
|
const out = [];
|
|
3722
|
-
for (const name of
|
|
3977
|
+
for (const name of fs22.readdirSync(root)) {
|
|
3723
3978
|
if (!JOB_ID.test(name))
|
|
3724
3979
|
continue;
|
|
3725
3980
|
try {
|
|
3726
|
-
const j = JSON.parse(
|
|
3981
|
+
const j = JSON.parse(fs22.readFileSync(path18.join(root, name, "status.json"), "utf8"));
|
|
3727
3982
|
if ((j.diperbarui || j.dibuat) < since)
|
|
3728
3983
|
continue;
|
|
3729
|
-
const f = j.hasilBerkas ?
|
|
3730
|
-
out.push({ job: j, file: f &&
|
|
3984
|
+
const f = j.hasilBerkas ? path18.join(root, name, j.hasilBerkas) : null;
|
|
3985
|
+
out.push({ job: j, file: f && fs22.existsSync(f) ? f : null });
|
|
3731
3986
|
} catch {}
|
|
3732
3987
|
}
|
|
3733
3988
|
return out.sort((a, b) => (b.job.diperbarui || 0) - (a.job.diperbarui || 0));
|
|
@@ -3753,31 +4008,31 @@ function history() {
|
|
|
3753
4008
|
}
|
|
3754
4009
|
|
|
3755
4010
|
// src/cli/commands/maintenance.ts
|
|
3756
|
-
import { spawnSync as
|
|
3757
|
-
import
|
|
4011
|
+
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
4012
|
+
import fs23 from "node:fs";
|
|
3758
4013
|
import os4 from "node:os";
|
|
3759
|
-
import
|
|
4014
|
+
import path19 from "node:path";
|
|
3760
4015
|
async function clean() {
|
|
3761
4016
|
if (runningPid()) {
|
|
3762
4017
|
log.warn(t("clean.running"));
|
|
3763
4018
|
return;
|
|
3764
4019
|
}
|
|
3765
|
-
const targets = [
|
|
3766
|
-
for (const job of
|
|
4020
|
+
const targets = [path19.join(cacheDir(), "chrome"), path19.join(cacheDir(), "halaman"), path19.join(logDir(), "hypeframe.log.1")];
|
|
4021
|
+
for (const job of fs23.readdirSync(renderDir())) {
|
|
3767
4022
|
if (!JOB_ID.test(job))
|
|
3768
4023
|
continue;
|
|
3769
4024
|
try {
|
|
3770
|
-
const s = JSON.parse(
|
|
4025
|
+
const s = JSON.parse(fs23.readFileSync(path19.join(renderDir(), job, "status.json"), "utf8")).status;
|
|
3771
4026
|
if (s === "gagal" || s === "batal" || s === "unggah")
|
|
3772
|
-
targets.push(
|
|
4027
|
+
targets.push(path19.join(renderDir(), job));
|
|
3773
4028
|
} catch {
|
|
3774
|
-
targets.push(
|
|
4029
|
+
targets.push(path19.join(renderDir(), job));
|
|
3775
4030
|
}
|
|
3776
4031
|
}
|
|
3777
4032
|
let freed = 0;
|
|
3778
4033
|
for (const p of targets) {
|
|
3779
4034
|
freed += await sizeOf(p);
|
|
3780
|
-
|
|
4035
|
+
fs23.rmSync(p, { recursive: true, force: true });
|
|
3781
4036
|
}
|
|
3782
4037
|
log.ok(t("clean.done", { size: bytes2(freed) }));
|
|
3783
4038
|
}
|
|
@@ -3786,7 +4041,7 @@ function report() {
|
|
|
3786
4041
|
const a = readAccount();
|
|
3787
4042
|
let recent = "";
|
|
3788
4043
|
try {
|
|
3789
|
-
recent =
|
|
4044
|
+
recent = fs23.readFileSync(path19.join(logDir(), "hypeframe.log"), "utf8").split(`
|
|
3790
4045
|
`).slice(-400).join(`
|
|
3791
4046
|
`);
|
|
3792
4047
|
} catch {
|
|
@@ -3807,13 +4062,20 @@ function report() {
|
|
|
3807
4062
|
recent
|
|
3808
4063
|
];
|
|
3809
4064
|
const stamp = new Date().toISOString().slice(0, 19).replace(/[-:T]/g, "");
|
|
3810
|
-
const file =
|
|
3811
|
-
|
|
4065
|
+
const file = path19.join(dataDir(), `laporan-${stamp}.txt`);
|
|
4066
|
+
fs23.writeFileSync(file, mask(lines.join(`
|
|
3812
4067
|
`)), { mode: 384 });
|
|
3813
4068
|
log.ok(t("report.done", { file }));
|
|
3814
4069
|
log.detail(t("report.hint"));
|
|
3815
4070
|
return file;
|
|
3816
4071
|
}
|
|
4072
|
+
function updateCommand(o) {
|
|
4073
|
+
if (o.standalone && o.windows)
|
|
4074
|
+
return ["powershell.exe", ["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", `irm ${INSTALL_URL}.ps1 | iex`], {}];
|
|
4075
|
+
if (o.standalone || o.android)
|
|
4076
|
+
return ["bash", ["-c", `curl -fsSL ${INSTALL_URL} | bash`], {}];
|
|
4077
|
+
return ["npm", ["i", "-g", "hypeframe@latest"], { shell: o.windows }];
|
|
4078
|
+
}
|
|
3817
4079
|
function update() {
|
|
3818
4080
|
if (!launchCommand()) {
|
|
3819
4081
|
log.info(t("update.npx"));
|
|
@@ -3821,8 +4083,8 @@ function update() {
|
|
|
3821
4083
|
return;
|
|
3822
4084
|
}
|
|
3823
4085
|
log.info(t("update.running"));
|
|
3824
|
-
const
|
|
3825
|
-
const r =
|
|
4086
|
+
const [cmd, args, extra] = updateCommand({ standalone: isStandalone(), android: isAndroid(), windows: process.platform === "win32" });
|
|
4087
|
+
const r = spawnSync6(cmd, args, { stdio: "inherit", ...extra });
|
|
3826
4088
|
if (r.status === 0)
|
|
3827
4089
|
log.ok(t("update.done"));
|
|
3828
4090
|
else
|
|
@@ -3837,13 +4099,13 @@ function openWeb(args) {
|
|
|
3837
4099
|
}
|
|
3838
4100
|
|
|
3839
4101
|
// src/cli/commands/status.ts
|
|
3840
|
-
import
|
|
3841
|
-
import
|
|
4102
|
+
import fs24 from "node:fs";
|
|
4103
|
+
import path20 from "node:path";
|
|
3842
4104
|
function statusRows(args) {
|
|
3843
4105
|
const s = resolveSettings(args?.flags);
|
|
3844
4106
|
const a = readAccount();
|
|
3845
4107
|
const pid = runningPid();
|
|
3846
|
-
const chrome = findChrome() ||
|
|
4108
|
+
const chrome = findChrome() || fs24.existsSync(path20.join(cacheDir(), "chrome"));
|
|
3847
4109
|
const recent = readHistory2();
|
|
3848
4110
|
const k = (key) => color.muted(t(key));
|
|
3849
4111
|
return [
|