hypeframe 0.9.1 → 0.9.3
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 +15 -6
- package/dist/index.js +1022 -607
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/cli/args.ts
|
|
1
|
+
// packages/hypeframe/src/cli/args.ts
|
|
2
2
|
var VALUE = new Map([
|
|
3
3
|
["--gateway", "gateway"],
|
|
4
4
|
["--web", "web"],
|
|
@@ -49,10 +49,10 @@ function parseArgs(argv) {
|
|
|
49
49
|
return out;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
// src/config/account.ts
|
|
52
|
+
// packages/hypeframe/src/config/account.ts
|
|
53
53
|
import fs2 from "node:fs";
|
|
54
54
|
|
|
55
|
-
// src/config/paths.ts
|
|
55
|
+
// packages/hypeframe/src/config/paths.ts
|
|
56
56
|
import fs from "node:fs";
|
|
57
57
|
import os from "node:os";
|
|
58
58
|
import path from "node:path";
|
|
@@ -79,7 +79,7 @@ function projectDir(projectId) {
|
|
|
79
79
|
return sub("proyek", projectId);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// src/config/account.ts
|
|
82
|
+
// packages/hypeframe/src/config/account.ts
|
|
83
83
|
function readAccount() {
|
|
84
84
|
try {
|
|
85
85
|
const a = JSON.parse(fs2.readFileSync(accountFile(), "utf8"));
|
|
@@ -101,11 +101,11 @@ function maskEmail(email) {
|
|
|
101
101
|
return m ? `${m[1]}***${m[2]}`.replace(/[\u0000-\u001f\u007f]/g, "") : "-";
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
// src/config/settings.ts
|
|
104
|
+
// packages/hypeframe/src/config/settings.ts
|
|
105
105
|
import fs4 from "node:fs";
|
|
106
106
|
import os2 from "node:os";
|
|
107
107
|
|
|
108
|
-
// src/util/which.ts
|
|
108
|
+
// packages/hypeframe/src/util/which.ts
|
|
109
109
|
import fs3 from "node:fs";
|
|
110
110
|
import path2 from "node:path";
|
|
111
111
|
function isAndroid() {
|
|
@@ -126,7 +126,7 @@ function onPath(name) {
|
|
|
126
126
|
return null;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
// src/config/settings.ts
|
|
129
|
+
// packages/hypeframe/src/config/settings.ts
|
|
130
130
|
var DEFAULT_GATEWAY = "https://api.sairipedia.com";
|
|
131
131
|
var DEFAULT_WEB = "https://hype-frame.com";
|
|
132
132
|
function readSettings() {
|
|
@@ -155,7 +155,7 @@ function osName() {
|
|
|
155
155
|
return { win32: "windows", darwin: "macos", linux: "linux", android: "android" }[process.platform] || process.platform;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
// src/ui/locale.ts
|
|
158
|
+
// packages/hypeframe/src/ui/locale.ts
|
|
159
159
|
function systemLang() {
|
|
160
160
|
const env = process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || Intl.DateTimeFormat().resolvedOptions().locale || "";
|
|
161
161
|
return /^id\b|^id[-_]|^in[-_]/i.test(env) ? "id" : "en";
|
|
@@ -244,6 +244,8 @@ var id = {
|
|
|
244
244
|
"agentLog.option": "{agent}: {what} diganti ke {value}",
|
|
245
245
|
"agentLog.stopped": "✦ {agent} berhenti (kode {code}). Obrolan baru menyalakannya lagi.",
|
|
246
246
|
"agentLog.account": "✦ Akun {agent} berganti: dimuat ulang, obrolan berikutnya memakai akun baru.",
|
|
247
|
+
"agentLog.terminal": "✦ Terminal penuh {agent} dibuka dari web.",
|
|
248
|
+
"agentLog.terminalClosed": "Terminal penuh {agent} ditutup.",
|
|
247
249
|
"engine.agentsReady": "Asisten AI siap: {list}",
|
|
248
250
|
"engine.agentsNone": "Belum ada asisten AI. Pasang dari menu hypeframe > Asisten AI.",
|
|
249
251
|
"engine.statusHint": "Tekan Enter kapan saja untuk melihat status.",
|
|
@@ -383,6 +385,7 @@ Tekan Esc untuk melewati satu langkah. Panduan ini bisa dibuka lagi dari Bantuan
|
|
|
383
385
|
"doctor.alpha": "Klip transparan",
|
|
384
386
|
"doctor.alphaNo": "tidak didukung Chrome ini; dibuat di server atau HP",
|
|
385
387
|
"doctor.tryChromiumMini": "Chromium Termux belum bisa render di HP ini. Coba Chromium di Linux mini: hypeframe chromium",
|
|
388
|
+
"render.tryChromiumMini": "Perbaikannya: buka sesi Termux baru lalu jalankan hypeframe chromium. Mesin ini mencoba render lagi begitu Chromium itu siap.",
|
|
386
389
|
"doctor.yes": "bisa",
|
|
387
390
|
"doctor.no": "tidak bisa",
|
|
388
391
|
"doctor.unreachable": "tidak terjangkau",
|
|
@@ -515,6 +518,8 @@ var en = {
|
|
|
515
518
|
"agentLog.option": "{agent}: {what} changed to {value}",
|
|
516
519
|
"agentLog.stopped": "✦ {agent} stopped (code {code}). A new chat starts it again.",
|
|
517
520
|
"agentLog.account": "✦ {agent} account changed: reloaded, the next chat uses the new account.",
|
|
521
|
+
"agentLog.terminal": "✦ {agent} full terminal opened from the web.",
|
|
522
|
+
"agentLog.terminalClosed": "{agent} full terminal closed.",
|
|
518
523
|
"engine.agentsReady": "AI assistants ready: {list}",
|
|
519
524
|
"engine.agentsNone": "No AI assistant yet. Add one from the hypeframe menu > AI assistant.",
|
|
520
525
|
"engine.statusHint": "Press Enter at any time to see the status.",
|
|
@@ -654,6 +659,7 @@ Press Esc to skip a step. You can open this guide again from Help & maintenance.
|
|
|
654
659
|
"doctor.alpha": "Transparent clips",
|
|
655
660
|
"doctor.alphaNo": "not supported by this Chrome; made on the server or phone",
|
|
656
661
|
"doctor.tryChromiumMini": "Termux's Chromium cannot render on this phone yet. Try Chromium in the Linux mini: hypeframe chromium",
|
|
662
|
+
"render.tryChromiumMini": "The fix: open a new Termux session and run hypeframe chromium. This engine tries rendering again as soon as that Chromium is ready.",
|
|
657
663
|
"doctor.yes": "yes",
|
|
658
664
|
"doctor.no": "no",
|
|
659
665
|
"doctor.unreachable": "unreachable",
|
|
@@ -717,11 +723,11 @@ function t(key, vars = {}) {
|
|
|
717
723
|
return s.replace(/\{(\w+)\}/g, (_, k) => String(vars[k] ?? `{${k}}`));
|
|
718
724
|
}
|
|
719
725
|
|
|
720
|
-
// src/ui/log.ts
|
|
726
|
+
// packages/hypeframe/src/ui/log.ts
|
|
721
727
|
import fs5 from "node:fs";
|
|
722
728
|
import path3 from "node:path";
|
|
723
729
|
|
|
724
|
-
// src/ui/theme.ts
|
|
730
|
+
// packages/hypeframe/src/ui/theme.ts
|
|
725
731
|
import picocolors from "picocolors";
|
|
726
732
|
var env = process.env;
|
|
727
733
|
var enabled = !("NO_COLOR" in env) && env.TERM !== "dumb" && ("FORCE_COLOR" in env ? env.FORCE_COLOR !== "0" : !!process.stdout.isTTY);
|
|
@@ -755,7 +761,7 @@ var icon = {
|
|
|
755
761
|
};
|
|
756
762
|
var plain = (s) => s.replace(/\x1b\[[0-9;]*m/g, "");
|
|
757
763
|
|
|
758
|
-
// src/ui/log.ts
|
|
764
|
+
// packages/hypeframe/src/ui/log.ts
|
|
759
765
|
var SECRET = /\b(hfm_[A-Za-z0-9_-]{20,}|hms_[A-Za-z0-9_-]{20,}|npm_[A-Za-z0-9]{20,}|gh[pousr]_[A-Za-z0-9]{20,}|v1\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,})\b/g;
|
|
760
766
|
var mask = (s) => s.replace(SECRET, (m) => `${m.slice(0, 4)}…`);
|
|
761
767
|
var MAX_FILE = 1024 * 1024;
|
|
@@ -793,13 +799,13 @@ var log = {
|
|
|
793
799
|
detail: (m) => write("detail", m)
|
|
794
800
|
};
|
|
795
801
|
|
|
796
|
-
// src/cli/commands/start.ts
|
|
797
|
-
import
|
|
802
|
+
// packages/hypeframe/src/cli/commands/start.ts
|
|
803
|
+
import crypto10 from "node:crypto";
|
|
798
804
|
import readline3 from "node:readline";
|
|
799
805
|
|
|
800
|
-
//
|
|
806
|
+
// packages/protocol/src/index.ts
|
|
801
807
|
var PROTOCOL_VERSION = 1;
|
|
802
|
-
var ALLOWED_KINDS = ["status", "kunci", "agen.mulai", "agen.kirim", "agen.izin", "agen.batal", "agen.opsi", "agen.riwayat", "agen.akun", "render.relai"];
|
|
808
|
+
var ALLOWED_KINDS = ["status", "kunci", "agen.mulai", "agen.kirim", "agen.izin", "agen.batal", "agen.opsi", "agen.riwayat", "agen.akun", "terminal.buka", "terminal.tutup", "render.relai"];
|
|
803
809
|
var CloseCode = {
|
|
804
810
|
BadHello: 4001,
|
|
805
811
|
Replaced: 4002,
|
|
@@ -820,14 +826,14 @@ var EngineError = {
|
|
|
820
826
|
BadPackage: "Paket berisi berkas yang tidak diizinkan."
|
|
821
827
|
};
|
|
822
828
|
|
|
823
|
-
// src/agent/service.ts
|
|
824
|
-
import
|
|
825
|
-
import
|
|
826
|
-
import
|
|
827
|
-
// package.json
|
|
829
|
+
// packages/hypeframe/src/agent/service.ts
|
|
830
|
+
import crypto5 from "node:crypto";
|
|
831
|
+
import fs15 from "node:fs";
|
|
832
|
+
import path12 from "node:path";
|
|
833
|
+
// packages/hypeframe/package.json
|
|
828
834
|
var package_default = {
|
|
829
835
|
name: "hypeframe",
|
|
830
|
-
version: "0.9.
|
|
836
|
+
version: "0.9.3",
|
|
831
837
|
description: "Local engine for HypeFrame Web: code clips, video renders and AI agents run on your own machine; the web is just the view.",
|
|
832
838
|
keywords: [
|
|
833
839
|
"hypeframe",
|
|
@@ -877,11 +883,11 @@ var package_default = {
|
|
|
877
883
|
}
|
|
878
884
|
};
|
|
879
885
|
|
|
880
|
-
// src/config/version.ts
|
|
886
|
+
// packages/hypeframe/src/config/version.ts
|
|
881
887
|
var VERSION = process.env.HF_MESIN_VERSI || package_default.version;
|
|
882
888
|
|
|
883
|
-
// src/agent/instructions.ts
|
|
884
|
-
var MCP_INSTRUCTIONS = "Tools to make videos from code in HypeFrame Web, open in the user's browser. Tools run in that browser tab, so HypeFrame Web must stay open. " +
|
|
889
|
+
// packages/hypeframe/src/agent/instructions.ts
|
|
890
|
+
var MCP_INSTRUCTIONS = "Tools to make videos from code in HypeFrame Web, open in the user's browser. Tools run in that browser tab, so HypeFrame Web must stay open. " + 'A project is a sequence of scenes written in code plus sound written in code (create_audio, Web Audio). Every scene is ONE complete HTML page whose script defines window.seek(t) (the only engine: "halaman"); built in, offline: GSAP (window.gsap), three.js, Lottie, PixiJS and HF.shader for GLSL shaders (see the motion code rules in the tool descriptions). ' + "CODE FIRST (the main feature of HypeFrame): build every scene of a new video by writing that page and passing it in the html argument of preview_motion and then create_motion, and make sound with create_audio. Writing that code through these tools is your main job here; never say you cannot write code. Do not build scenes from add_text, add_shape or add_image layers: use those (and set_keyframe) only when the user asks for a small manual change to a video that already exists. " + "Try code with preview_motion first. Depending on the permission setting of the user, create_motion / create_audio runs at once (the code is still shown in HypeFrame Web) or waits until the user approves it, so wait for the job result with get_job_status. " + "At the start of every conversation call get_memory first: it shows unfinished work saved by earlier conversations. If there is unfinished work, say in one or two sentences what it was and ask whether to continue it. " + "Keep the memory current: call save_memory after every finished step. " + "Before creating a project, call list_skills, pick the best skill (say which) and read it with use_skill. A skill can be a package with files: read examples with read_skill_file and put assets into the project with import_skill_files. " + "All times are in frames (seconds x project fps). " + "render_video may ask the user to approve (their setting) and returns immediately: poll get_render_status until it finishes. Most users write in Indonesian: write every message, including progress notes, in their language.";
|
|
885
891
|
var AGENTS_MD = `# HypeFrame
|
|
886
892
|
|
|
887
893
|
You are running on the user's computer through the HypeFrame engine. The user types to you from HypeFrame Web (in a browser, possibly on another device) to make videos. This folder is the only place you may read or write files.
|
|
@@ -893,7 +899,7 @@ You are running on the user's computer through the HypeFrame engine. The user ty
|
|
|
893
899
|
- A file you made or downloaded in this folder (image, audio, video, font, Lottie/JSON, up to 4 MB) reaches the video only through add_file_from_computer, which returns its asset id (use it as asset://<id>).
|
|
894
900
|
`;
|
|
895
901
|
|
|
896
|
-
// src/agent/registry.ts
|
|
902
|
+
// packages/hypeframe/src/agent/registry.ts
|
|
897
903
|
import { spawnSync } from "node:child_process";
|
|
898
904
|
import fs6 from "node:fs";
|
|
899
905
|
var SUPPORTED_AGENTS = ["antigravity-acp", "codex-acp", "opencode"];
|
|
@@ -925,7 +931,7 @@ async function fetchRegistry() {
|
|
|
925
931
|
return (Array.isArray(j.agents) ? j.agents : []).filter(valid).map((a) => local ? a : { ...a, distribution: { ...a.distribution, local: undefined } });
|
|
926
932
|
}
|
|
927
933
|
|
|
928
|
-
// src/agent/linux.ts
|
|
934
|
+
// packages/hypeframe/src/agent/linux.ts
|
|
929
935
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
930
936
|
import crypto from "node:crypto";
|
|
931
937
|
import fs7 from "node:fs";
|
|
@@ -1112,10 +1118,10 @@ function watchOpenRequests(open, everyMs = 1000) {
|
|
|
1112
1118
|
return () => clearInterval(timer);
|
|
1113
1119
|
}
|
|
1114
1120
|
|
|
1115
|
-
// src/agent/login.ts
|
|
1121
|
+
// packages/hypeframe/src/agent/login.ts
|
|
1116
1122
|
import { spawn as spawn2 } from "node:child_process";
|
|
1117
1123
|
|
|
1118
|
-
// src/agent/acp.ts
|
|
1124
|
+
// packages/hypeframe/src/agent/acp.ts
|
|
1119
1125
|
import { spawn } from "node:child_process";
|
|
1120
1126
|
import { EventEmitter } from "node:events";
|
|
1121
1127
|
import readline from "node:readline";
|
|
@@ -1256,7 +1262,7 @@ class AcpProcess extends EventEmitter {
|
|
|
1256
1262
|
}
|
|
1257
1263
|
}
|
|
1258
1264
|
|
|
1259
|
-
// src/agent/store.ts
|
|
1265
|
+
// packages/hypeframe/src/agent/store.ts
|
|
1260
1266
|
import fs8 from "node:fs";
|
|
1261
1267
|
import path5 from "node:path";
|
|
1262
1268
|
function setReady(id, ready) {
|
|
@@ -1322,7 +1328,7 @@ function saveAgentEnv(id, env) {
|
|
|
1322
1328
|
fs8.renameSync(`${f}.tmp`, f);
|
|
1323
1329
|
}
|
|
1324
1330
|
|
|
1325
|
-
// src/agent/login.ts
|
|
1331
|
+
// packages/hypeframe/src/agent/login.ts
|
|
1326
1332
|
var SIGN_IN = /https?:\/\/[^\s"'<>]{8,2000}/g;
|
|
1327
1333
|
var looksLikeSignIn = (u) => /oauth|auth|login|signin|sign-in|device|accounts\./i.test(u);
|
|
1328
1334
|
function linkScanner(found) {
|
|
@@ -1555,7 +1561,7 @@ function cancelRemoteLogin(id) {
|
|
|
1555
1561
|
r.cancel();
|
|
1556
1562
|
}
|
|
1557
1563
|
|
|
1558
|
-
// src/agent/opencode.ts
|
|
1564
|
+
// packages/hypeframe/src/agent/opencode.ts
|
|
1559
1565
|
import fs9 from "node:fs";
|
|
1560
1566
|
import path6 from "node:path";
|
|
1561
1567
|
var OPENCODE = "opencode";
|
|
@@ -1621,7 +1627,7 @@ async function fetchApiModels(url, key, timeoutMs = 1e4) {
|
|
|
1621
1627
|
}
|
|
1622
1628
|
}
|
|
1623
1629
|
|
|
1624
|
-
// src/agent/session.ts
|
|
1630
|
+
// packages/hypeframe/src/agent/session.ts
|
|
1625
1631
|
import crypto2 from "node:crypto";
|
|
1626
1632
|
import fs10 from "node:fs";
|
|
1627
1633
|
import path7 from "node:path";
|
|
@@ -1940,7 +1946,692 @@ class AgentSessions {
|
|
|
1940
1946
|
}
|
|
1941
1947
|
}
|
|
1942
1948
|
|
|
1943
|
-
// src/agent/
|
|
1949
|
+
// packages/hypeframe/src/agent/terminal.ts
|
|
1950
|
+
import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
|
|
1951
|
+
import crypto4 from "node:crypto";
|
|
1952
|
+
import fs14 from "node:fs";
|
|
1953
|
+
import fsp3 from "node:fs/promises";
|
|
1954
|
+
import os3 from "node:os";
|
|
1955
|
+
import path11 from "node:path";
|
|
1956
|
+
|
|
1957
|
+
// packages/hypeframe/src/render/ffmpeg.ts
|
|
1958
|
+
import crypto3 from "node:crypto";
|
|
1959
|
+
import fs11 from "node:fs";
|
|
1960
|
+
import fsp from "node:fs/promises";
|
|
1961
|
+
import path8 from "node:path";
|
|
1962
|
+
import { pipeline } from "node:stream/promises";
|
|
1963
|
+
import { Readable } from "node:stream";
|
|
1964
|
+
import zlib from "node:zlib";
|
|
1965
|
+
var FFMPEG_RELEASE = "b6.0";
|
|
1966
|
+
var BASE = `https://github.com/eugeneware/ffmpeg-static/releases/download/${FFMPEG_RELEASE}/`;
|
|
1967
|
+
var FFMPEG_PINNED = {
|
|
1968
|
+
"win32-x64": { sha256: "450d66226c79405c724e821f291cab0911e934bfa9fa2231adcab587f3e07b50", size: 28894894 },
|
|
1969
|
+
"linux-x64": { sha256: "17c1ae10b52ac499180679fe6ba77e17642390c4eedb0f1e3b0ac045da55128f", size: 28928723 },
|
|
1970
|
+
"linux-arm64": { sha256: "2b708b2d15041d2a192c1db24c7a8a1d24f645a8242dce1c744ff2392b86ada1", size: 25131803 },
|
|
1971
|
+
"darwin-x64": { sha256: "a12354fce7eb62361473bbe10d53a1893695babd35869ec8e92e5dfea8d0440b", size: 25067704 },
|
|
1972
|
+
"darwin-arm64": { sha256: "6be74d6f449889c2e87a75873894f8520cad56c08ac76f2a628d85b0519daaca", size: 19253088 }
|
|
1973
|
+
};
|
|
1974
|
+
var exe = process.platform === "win32" ? "ffmpeg.exe" : "ffmpeg";
|
|
1975
|
+
var cached2 = (cacheDir) => path8.join(cacheDir, "ffmpeg", FFMPEG_RELEASE, exe);
|
|
1976
|
+
var thisPlatform = () => `${process.platform}-${process.arch}`;
|
|
1977
|
+
async function findFfmpeg(cacheDir, key = thisPlatform()) {
|
|
1978
|
+
const forced = process.env.HYPEFRAME_FFMPEG;
|
|
1979
|
+
if (forced)
|
|
1980
|
+
return fs11.existsSync(forced) ? forced : null;
|
|
1981
|
+
if (!FFMPEG_PINNED[key])
|
|
1982
|
+
return onPath("ffmpeg");
|
|
1983
|
+
try {
|
|
1984
|
+
const mod = await import("ffmpeg-static");
|
|
1985
|
+
const p = typeof mod.default === "string" ? mod.default : null;
|
|
1986
|
+
if (p && fs11.existsSync(p))
|
|
1987
|
+
return p;
|
|
1988
|
+
} catch {}
|
|
1989
|
+
const c = cached2(cacheDir);
|
|
1990
|
+
return fs11.existsSync(c) ? c : null;
|
|
1991
|
+
}
|
|
1992
|
+
async function downloadVerified(url, sha256, dest, progress = () => {
|
|
1993
|
+
return;
|
|
1994
|
+
}, gunzip = false) {
|
|
1995
|
+
const r = await fetch(url, { signal: AbortSignal.timeout(900000) });
|
|
1996
|
+
if (!r.ok || !r.body)
|
|
1997
|
+
throw new Error(`download ${r.status}`);
|
|
1998
|
+
const total = Number(r.headers.get("content-length")) || 0;
|
|
1999
|
+
await fsp.mkdir(path8.dirname(dest), { recursive: true });
|
|
2000
|
+
const tmp = `${dest}.download`;
|
|
2001
|
+
const hash = crypto3.createHash("sha256");
|
|
2002
|
+
let got = 0;
|
|
2003
|
+
let last = -10;
|
|
2004
|
+
const body = Readable.fromWeb(r.body).on("data", (c) => {
|
|
2005
|
+
hash.update(c);
|
|
2006
|
+
got += c.length;
|
|
2007
|
+
const pct = total ? Math.floor(got / total * 100) : 0;
|
|
2008
|
+
if (pct - last >= 10)
|
|
2009
|
+
last = pct, progress(pct);
|
|
2010
|
+
});
|
|
2011
|
+
await pipeline(body, fs11.createWriteStream(tmp));
|
|
2012
|
+
if (hash.digest("hex") !== sha256) {
|
|
2013
|
+
await fsp.rm(tmp, { force: true });
|
|
2014
|
+
throw new Error("ffmpeg: sidik unduhan tidak cocok, berkas ditolak.");
|
|
2015
|
+
}
|
|
2016
|
+
if (gunzip) {
|
|
2017
|
+
await pipeline(fs11.createReadStream(tmp), zlib.createGunzip(), fs11.createWriteStream(`${tmp}.raw`));
|
|
2018
|
+
await fsp.rm(tmp, { force: true });
|
|
2019
|
+
await fsp.rename(`${tmp}.raw`, dest);
|
|
2020
|
+
} else
|
|
2021
|
+
await fsp.rename(tmp, dest);
|
|
2022
|
+
if (process.platform !== "win32")
|
|
2023
|
+
await fsp.chmod(dest, 493);
|
|
2024
|
+
}
|
|
2025
|
+
async function prepareFfmpeg(cacheDir, progress = () => {
|
|
2026
|
+
return;
|
|
2027
|
+
}, key = thisPlatform()) {
|
|
2028
|
+
const found = await findFfmpeg(cacheDir, key);
|
|
2029
|
+
if (found)
|
|
2030
|
+
return found;
|
|
2031
|
+
const pin = FFMPEG_PINNED[key];
|
|
2032
|
+
if (!pin)
|
|
2033
|
+
throw new Error(key.startsWith("android") ? "ffmpeg belum terpasang. Di Termux jalankan: pkg install ffmpeg" : `ffmpeg tidak tersedia untuk ${key}`);
|
|
2034
|
+
progress(0);
|
|
2035
|
+
await downloadVerified(`${BASE}ffmpeg-${key}.gz`, pin.sha256, cached2(cacheDir), progress, true);
|
|
2036
|
+
return cached2(cacheDir);
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
// packages/hypeframe/src/agent/install.ts
|
|
2040
|
+
import fs13 from "node:fs";
|
|
2041
|
+
import fsp2 from "node:fs/promises";
|
|
2042
|
+
import path10 from "node:path";
|
|
2043
|
+
import yauzl from "yauzl";
|
|
2044
|
+
|
|
2045
|
+
// packages/hypeframe/src/util/runtime.ts
|
|
2046
|
+
import fs12 from "node:fs";
|
|
2047
|
+
import path9 from "node:path";
|
|
2048
|
+
function isStandalone() {
|
|
2049
|
+
return path9.basename(process.execPath).toLowerCase().startsWith("hypeframe");
|
|
2050
|
+
}
|
|
2051
|
+
function runtimeLabel() {
|
|
2052
|
+
const bun = process.versions.bun;
|
|
2053
|
+
return bun && !isStandalone() ? `Bun ${bun}` : isStandalone() ? `Bun ${bun ?? "?"} (standalone)` : `Node ${process.versions.node}`;
|
|
2054
|
+
}
|
|
2055
|
+
function launchCommand() {
|
|
2056
|
+
if (isStandalone())
|
|
2057
|
+
return [process.execPath];
|
|
2058
|
+
try {
|
|
2059
|
+
const script = fs12.realpathSync(process.argv[1] || "");
|
|
2060
|
+
return /[\\/]_npx[\\/]/.test(script) ? null : [process.execPath, script];
|
|
2061
|
+
} catch {
|
|
2062
|
+
return null;
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
var INSTALL_URL = "https://hype-frame.com/install";
|
|
2066
|
+
|
|
2067
|
+
// packages/hypeframe/src/agent/install.ts
|
|
2068
|
+
function unzip(file, to) {
|
|
2069
|
+
return new Promise((ok, fail) => {
|
|
2070
|
+
yauzl.open(file, { lazyEntries: true }, (e, zip) => {
|
|
2071
|
+
if (e || !zip)
|
|
2072
|
+
return fail(e ?? new Error("zip"));
|
|
2073
|
+
zip.on("entry", (en) => {
|
|
2074
|
+
const target = path10.join(to, en.fileName);
|
|
2075
|
+
if (!target.startsWith(to + path10.sep))
|
|
2076
|
+
return fail(new Error("archive path outside the agent folder"));
|
|
2077
|
+
if (en.fileName.endsWith("/"))
|
|
2078
|
+
return fs13.mkdirSync(target, { recursive: true }), zip.readEntry();
|
|
2079
|
+
fs13.mkdirSync(path10.dirname(target), { recursive: true });
|
|
2080
|
+
zip.openReadStream(en, (e2, s) => {
|
|
2081
|
+
if (e2 || !s)
|
|
2082
|
+
return fail(e2 ?? new Error("zip"));
|
|
2083
|
+
const out = fs13.createWriteStream(target);
|
|
2084
|
+
s.pipe(out);
|
|
2085
|
+
out.on("finish", () => zip.readEntry());
|
|
2086
|
+
out.on("error", fail);
|
|
2087
|
+
});
|
|
2088
|
+
});
|
|
2089
|
+
zip.on("end", () => ok());
|
|
2090
|
+
zip.on("error", fail);
|
|
2091
|
+
zip.readEntry();
|
|
2092
|
+
});
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2095
|
+
async function untarGz(file, to) {
|
|
2096
|
+
const { gunzipSync } = await import("node:zlib");
|
|
2097
|
+
const data = gunzipSync(await fsp2.readFile(file));
|
|
2098
|
+
const root = path10.resolve(to);
|
|
2099
|
+
const str = (b) => b.toString("utf8").replace(/\0[\s\S]*$/, "");
|
|
2100
|
+
const octal = (b) => Number.parseInt(str(b).trim() || "0", 8) || 0;
|
|
2101
|
+
let off = 0;
|
|
2102
|
+
let longName = null;
|
|
2103
|
+
while (off + 512 <= data.length) {
|
|
2104
|
+
const h = data.subarray(off, off + 512);
|
|
2105
|
+
if (h.every((x) => x === 0))
|
|
2106
|
+
break;
|
|
2107
|
+
const size = octal(h.subarray(124, 136));
|
|
2108
|
+
const type = String.fromCharCode(h[156] || 48);
|
|
2109
|
+
const body = data.subarray(off + 512, off + 512 + size);
|
|
2110
|
+
off += 512 + Math.ceil(size / 512) * 512;
|
|
2111
|
+
const prefix = str(h.subarray(345, 500));
|
|
2112
|
+
let name = longName ?? (prefix ? `${prefix}/${str(h.subarray(0, 100))}` : str(h.subarray(0, 100)));
|
|
2113
|
+
longName = null;
|
|
2114
|
+
if (type === "x") {
|
|
2115
|
+
const m = body.toString("utf8").match(/(?:^|\n)\d+ path=([^\n]*)\n/);
|
|
2116
|
+
if (m)
|
|
2117
|
+
longName = m[1];
|
|
2118
|
+
continue;
|
|
2119
|
+
}
|
|
2120
|
+
if (type === "L") {
|
|
2121
|
+
longName = str(body);
|
|
2122
|
+
continue;
|
|
2123
|
+
}
|
|
2124
|
+
if (type === "g")
|
|
2125
|
+
continue;
|
|
2126
|
+
name = name.replace(/^\.\//, "");
|
|
2127
|
+
if (!name)
|
|
2128
|
+
continue;
|
|
2129
|
+
const target = path10.resolve(root, name);
|
|
2130
|
+
if (target !== root && !target.startsWith(root + path10.sep))
|
|
2131
|
+
throw new Error("archive path outside the agent folder");
|
|
2132
|
+
if (type === "5") {
|
|
2133
|
+
await fsp2.mkdir(target, { recursive: true });
|
|
2134
|
+
continue;
|
|
2135
|
+
}
|
|
2136
|
+
if (type !== "0" && type !== "7")
|
|
2137
|
+
continue;
|
|
2138
|
+
await fsp2.mkdir(path10.dirname(target), { recursive: true });
|
|
2139
|
+
await fsp2.writeFile(target, body, { mode: octal(h.subarray(100, 108)) & 73 ? 493 : 420 });
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
function npxRunner(pkg, extra = []) {
|
|
2143
|
+
if (isStandalone())
|
|
2144
|
+
return { cmd: process.execPath, args: ["x", pkg, ...extra], env: { BUN_BE_BUN: "1" } };
|
|
2145
|
+
const npxCli = path10.join(path10.dirname(process.execPath), process.platform === "win32" ? "" : "..", process.platform === "win32" ? "node_modules" : "lib/node_modules", "npm", "bin", "npx-cli.js");
|
|
2146
|
+
if (!fs13.existsSync(npxCli))
|
|
2147
|
+
throw new Error("npx was not found next to Node.js");
|
|
2148
|
+
return { cmd: process.execPath, args: [npxCli, "-y", pkg, ...extra], env: {} };
|
|
2149
|
+
}
|
|
2150
|
+
function ownCopy(a) {
|
|
2151
|
+
const bin = a.distribution.binary?.[platformKey()];
|
|
2152
|
+
if (bin) {
|
|
2153
|
+
const cmd = onPath(path10.basename(bin.cmd).replace(/\.exe$/i, ""));
|
|
2154
|
+
return cmd ? { cmd, args: bin.args ?? [], env: bin.env ?? {} } : null;
|
|
2155
|
+
}
|
|
2156
|
+
const npx = a.distribution.npx;
|
|
2157
|
+
if (npx) {
|
|
2158
|
+
const name = npx.package.replace(/(?!^)@[^@/]*$/, "").split("/").pop() ?? "";
|
|
2159
|
+
const cmd = onPath(name);
|
|
2160
|
+
return cmd ? { cmd, args: npx.args ?? [], env: npx.env ?? {} } : null;
|
|
2161
|
+
}
|
|
2162
|
+
return null;
|
|
2163
|
+
}
|
|
2164
|
+
async function unpackBinary(id, version, bin, progress) {
|
|
2165
|
+
if (!/^[0-9a-f]{64}$/i.test(bin.sha256 || ""))
|
|
2166
|
+
throw new Error(`Agent ${id}: the registry gives no sha256; not installed`);
|
|
2167
|
+
const dir = path10.join(agentDir(), id, version);
|
|
2168
|
+
const tmp = `${dir}.tmp`;
|
|
2169
|
+
await fsp2.rm(tmp, { recursive: true, force: true });
|
|
2170
|
+
await fsp2.mkdir(tmp, { recursive: true });
|
|
2171
|
+
try {
|
|
2172
|
+
const name = path10.basename(new URL(bin.archive).pathname);
|
|
2173
|
+
const cmdRel = bin.cmd.replace(/^\.\//, "");
|
|
2174
|
+
if (/\.zip$/i.test(name)) {
|
|
2175
|
+
const file = path10.join(tmp, ".download.zip");
|
|
2176
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
2177
|
+
await unzip(file, tmp);
|
|
2178
|
+
await fsp2.rm(file, { force: true });
|
|
2179
|
+
} else if (/\.(tar\.gz|tgz)$/i.test(name)) {
|
|
2180
|
+
const file = path10.join(tmp, ".download.tar.gz");
|
|
2181
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
2182
|
+
await untarGz(file, tmp);
|
|
2183
|
+
await fsp2.rm(file, { force: true });
|
|
2184
|
+
} else if (/\.gz$/i.test(name)) {
|
|
2185
|
+
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), path10.join(tmp, cmdRel), progress, true);
|
|
2186
|
+
} else
|
|
2187
|
+
throw new Error(`Agent ${id}: unsupported archive ${name}`);
|
|
2188
|
+
const cmd = path10.join(tmp, cmdRel);
|
|
2189
|
+
if (!fs13.existsSync(cmd))
|
|
2190
|
+
throw new Error(`Agent ${id}: ${bin.cmd} is not in the download`);
|
|
2191
|
+
if (process.platform !== "win32")
|
|
2192
|
+
await fsp2.chmod(cmd, 493);
|
|
2193
|
+
await fsp2.rm(dir, { recursive: true, force: true });
|
|
2194
|
+
await fsp2.rename(tmp, dir);
|
|
2195
|
+
return { cmd: path10.join(dir, cmdRel), args: bin.args ?? [], env: bin.env ?? {} };
|
|
2196
|
+
} catch (e) {
|
|
2197
|
+
await fsp2.rm(tmp, { recursive: true, force: true });
|
|
2198
|
+
throw e;
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
var codexAcpRelease = () => process.env.HYPEFRAME_CODEX_ACP_RELEASE || "https://api.github.com/repos/zed-industries/codex-acp/releases/latest";
|
|
2202
|
+
async function codexAcpBuild(arch) {
|
|
2203
|
+
const j = await (await fetch(codexAcpRelease(), { headers: { accept: "application/vnd.github+json", "user-agent": "hypeframe" }, signal: AbortSignal.timeout(20000) })).json();
|
|
2204
|
+
const triple = arch === "x64" ? "x86_64" : "aarch64";
|
|
2205
|
+
const asset = (j.assets ?? []).find((x) => new RegExp(`${triple}-unknown-linux-musl\\.tar\\.gz$`).test(String(x.name)));
|
|
2206
|
+
const sha256 = /^sha256:([0-9a-f]{64})$/i.exec(String(asset?.digest ?? ""))?.[1];
|
|
2207
|
+
const url = String(asset?.browser_download_url ?? "");
|
|
2208
|
+
if (!asset || !sha256 || !url)
|
|
2209
|
+
throw new Error("codex-acp: no checked Linux build for this phone");
|
|
2210
|
+
if (!process.env.HYPEFRAME_CODEX_ACP_RELEASE && !url.startsWith("https://github.com/"))
|
|
2211
|
+
throw new Error("codex-acp: unexpected download address");
|
|
2212
|
+
return { url, sha256: sha256.toLowerCase(), version: String(j.tag_name ?? "latest").replace(/^v/, "") };
|
|
2213
|
+
}
|
|
2214
|
+
var findFile = (dir, name) => {
|
|
2215
|
+
for (const n of fs13.readdirSync(dir)) {
|
|
2216
|
+
const f = path10.join(dir, n);
|
|
2217
|
+
const st = fs13.lstatSync(f);
|
|
2218
|
+
if (st.isFile() && n === name)
|
|
2219
|
+
return f;
|
|
2220
|
+
if (st.isDirectory()) {
|
|
2221
|
+
const inner = findFile(f, name);
|
|
2222
|
+
if (inner)
|
|
2223
|
+
return inner;
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
return null;
|
|
2227
|
+
};
|
|
2228
|
+
async function installInLinux(a, id, progress, steps, arch) {
|
|
2229
|
+
steps.prepare();
|
|
2230
|
+
if (id === "antigravity-acp") {
|
|
2231
|
+
if (!steps.run("(test -x /root/.local/bin/agy || curl -fsSL https://antigravity.google/cli/install.sh | bash) && test -x /root/.local/bin/agy"))
|
|
2232
|
+
throw new Error("Antigravity: Google's installer did not finish in the Linux mini, or agy is not at /root/.local/bin/agy");
|
|
2233
|
+
return { launch: { cmd: "/root/.local/bin/agy", args: ["acp"], env: {}, linux: true }, version: a.version };
|
|
2234
|
+
}
|
|
2235
|
+
if (id === "codex-acp") {
|
|
2236
|
+
const b = await codexAcpBuild(arch);
|
|
2237
|
+
const dir = path10.join(agentDir(), id, b.version);
|
|
2238
|
+
const tmp = `${dir}.tmp`;
|
|
2239
|
+
await fsp2.rm(tmp, { recursive: true, force: true });
|
|
2240
|
+
await fsp2.mkdir(tmp, { recursive: true });
|
|
2241
|
+
try {
|
|
2242
|
+
const file = path10.join(tmp, ".download.tar.gz");
|
|
2243
|
+
await downloadVerified(b.url, b.sha256, file, progress);
|
|
2244
|
+
await untarGz(file, tmp);
|
|
2245
|
+
await fsp2.rm(file, { force: true });
|
|
2246
|
+
const found = findFile(tmp, "codex-acp");
|
|
2247
|
+
if (!found)
|
|
2248
|
+
throw new Error("codex-acp: the program is not in the download");
|
|
2249
|
+
const rel = path10.relative(tmp, found);
|
|
2250
|
+
await fsp2.chmod(found, 493);
|
|
2251
|
+
await fsp2.rm(dir, { recursive: true, force: true });
|
|
2252
|
+
await fsp2.rename(tmp, dir);
|
|
2253
|
+
return { launch: { cmd: path10.join(dir, rel), args: [], env: {}, linux: true }, version: b.version };
|
|
2254
|
+
} catch (e) {
|
|
2255
|
+
await fsp2.rm(tmp, { recursive: true, force: true });
|
|
2256
|
+
throw e;
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
const bin = a.distribution.binary?.[`linux-${arch === "x64" ? "x86_64" : "aarch64"}`];
|
|
2260
|
+
if (!bin)
|
|
2261
|
+
throw new Error(`Agent ${id} has no Linux build to run on this phone`);
|
|
2262
|
+
return { launch: { ...await unpackBinary(id, a.version, bin, progress), linux: true }, version: a.version };
|
|
2263
|
+
}
|
|
2264
|
+
async function installAgent(id, progress = () => {
|
|
2265
|
+
return;
|
|
2266
|
+
}, opts = {}) {
|
|
2267
|
+
const a = (await fetchRegistry()).find((x) => x.id === id);
|
|
2268
|
+
if (!a)
|
|
2269
|
+
throw new Error(`Agent ${id} is not in the registry`);
|
|
2270
|
+
const local = a.distribution.local;
|
|
2271
|
+
if (!isSupported(id) && !local)
|
|
2272
|
+
throw new Error(`Agent ${id} is not supported`);
|
|
2273
|
+
if (!local && (opts.android ?? isAndroid())) {
|
|
2274
|
+
const steps = opts.linux ?? { prepare: () => prepareLinux(opts.say), run: runInLinux };
|
|
2275
|
+
const r = await installInLinux(a, id, progress, steps, opts.arch ?? process.arch);
|
|
2276
|
+
const installed = { id, name: a.name, version: r.version, launch: r.launch };
|
|
2277
|
+
writeInstalled(installed);
|
|
2278
|
+
return installed;
|
|
2279
|
+
}
|
|
2280
|
+
let launch;
|
|
2281
|
+
const bin = a.distribution.binary?.[platformKey()];
|
|
2282
|
+
const own = local || opts.download ? null : ownCopy(a);
|
|
2283
|
+
if (local) {
|
|
2284
|
+
launch = { cmd: local.cmd, args: local.args ?? [], env: {} };
|
|
2285
|
+
} else if (own) {
|
|
2286
|
+
launch = own;
|
|
2287
|
+
} else if (bin) {
|
|
2288
|
+
launch = await unpackBinary(id, a.version, bin, progress);
|
|
2289
|
+
} else if (a.distribution.npx) {
|
|
2290
|
+
launch = { ...npxRunner(a.distribution.npx.package, a.distribution.npx.args), env: { ...a.distribution.npx.env ?? {} } };
|
|
2291
|
+
if (isStandalone())
|
|
2292
|
+
launch.env.BUN_BE_BUN = "1";
|
|
2293
|
+
} else
|
|
2294
|
+
throw new Error(`Agent ${id} has no download for ${platformKey()}`);
|
|
2295
|
+
const installed = { id, name: a.name, version: a.version, launch, ...own ? { own: true } : {} };
|
|
2296
|
+
writeInstalled(installed);
|
|
2297
|
+
return installed;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
// packages/hypeframe/src/agent/terminal.ts
|
|
2301
|
+
var MAX_TERMINALS = 4;
|
|
2302
|
+
var KEEP = 160 * 1024;
|
|
2303
|
+
var PIECE = 60 * 1024;
|
|
2304
|
+
var GAP_MS = 25;
|
|
2305
|
+
var IDLE_MS = 15 * 60000;
|
|
2306
|
+
var MAX_INPUT = 64 * 1024;
|
|
2307
|
+
var bun = () => globalThis.Bun?.spawn ? globalThis.Bun : null;
|
|
2308
|
+
function ptySupported() {
|
|
2309
|
+
return !!bun() || isAndroid() || process.platform === "linux" && !!onPath("script");
|
|
2310
|
+
}
|
|
2311
|
+
function agyOnComputer() {
|
|
2312
|
+
const own = onPath("agy");
|
|
2313
|
+
if (own)
|
|
2314
|
+
return own;
|
|
2315
|
+
const f = path11.join(os3.homedir(), ".local", "bin", process.platform === "win32" ? "agy.exe" : "agy");
|
|
2316
|
+
return fs14.existsSync(f) ? f : null;
|
|
2317
|
+
}
|
|
2318
|
+
function hasTerminal(a) {
|
|
2319
|
+
if (!ptySupported())
|
|
2320
|
+
return false;
|
|
2321
|
+
if (a.id === "antigravity-acp")
|
|
2322
|
+
return !!a.launch.linux || !!agyOnComputer();
|
|
2323
|
+
return true;
|
|
2324
|
+
}
|
|
2325
|
+
var codexRelease = () => process.env.HYPEFRAME_CODEX_RELEASE || "https://api.github.com/repos/openai/codex/releases/latest";
|
|
2326
|
+
function codexTriple(linux) {
|
|
2327
|
+
const arch = process.arch === "arm64" ? "aarch64" : "x86_64";
|
|
2328
|
+
if (linux || isAndroid() || process.platform === "linux")
|
|
2329
|
+
return `${arch}-unknown-linux-musl`;
|
|
2330
|
+
if (process.platform === "darwin")
|
|
2331
|
+
return `${arch}-apple-darwin`;
|
|
2332
|
+
if (process.platform === "win32")
|
|
2333
|
+
return `${arch}-pc-windows-msvc.exe`;
|
|
2334
|
+
throw new Error(`Codex CLI tidak tersedia untuk ${process.platform}.`);
|
|
2335
|
+
}
|
|
2336
|
+
async function untar(file, to) {
|
|
2337
|
+
const r = spawnSync3("tar", ["-xzf", file, "-C", to], { stdio: "ignore", windowsHide: true, timeout: 10 * 60000 });
|
|
2338
|
+
if (r.status === 0)
|
|
2339
|
+
return;
|
|
2340
|
+
await untarGz(file, to);
|
|
2341
|
+
}
|
|
2342
|
+
async function codexCli(linux, say) {
|
|
2343
|
+
if (!linux) {
|
|
2344
|
+
const own = onPath("codex");
|
|
2345
|
+
if (own)
|
|
2346
|
+
return own;
|
|
2347
|
+
}
|
|
2348
|
+
const triple = codexTriple(linux);
|
|
2349
|
+
const base = path11.join(agentDir(), "codex-acp", "cli");
|
|
2350
|
+
const mark = path11.join(base, `${triple}.json`);
|
|
2351
|
+
try {
|
|
2352
|
+
const saved = JSON.parse(fs14.readFileSync(mark, "utf8"));
|
|
2353
|
+
if (saved.cmd && fs14.existsSync(saved.cmd))
|
|
2354
|
+
return saved.cmd;
|
|
2355
|
+
} catch {}
|
|
2356
|
+
const j = await (await fetch(codexRelease(), { headers: { accept: "application/vnd.github+json", "user-agent": "hypeframe" }, signal: AbortSignal.timeout(20000) })).json();
|
|
2357
|
+
const asset = (j.assets ?? []).find((x) => x.name === `codex-${triple}.tar.gz`);
|
|
2358
|
+
const sha256 = /^sha256:([0-9a-f]{64})$/i.exec(String(asset?.digest ?? ""))?.[1]?.toLowerCase();
|
|
2359
|
+
const url = String(asset?.browser_download_url ?? "");
|
|
2360
|
+
if (!asset || !sha256 || !url)
|
|
2361
|
+
throw new Error("Codex CLI: tidak ada unduhan resmi yang bisa diperiksa untuk perangkat ini.");
|
|
2362
|
+
if (!process.env.HYPEFRAME_CODEX_RELEASE && !url.startsWith("https://github.com/"))
|
|
2363
|
+
throw new Error("Codex CLI: alamat unduhan tidak dikenal.");
|
|
2364
|
+
const version = String(j.tag_name ?? "latest").replace(/^rust-v|^v/, "");
|
|
2365
|
+
const mb = asset.size ? ` (${Math.round(asset.size / 1048576)} MB)` : "";
|
|
2366
|
+
say(`Mengunduh Codex CLI ${version}${mb}, sekali saja...`);
|
|
2367
|
+
const dir = path11.join(base, `${triple}-${version}`);
|
|
2368
|
+
const tmp = `${dir}.tmp`;
|
|
2369
|
+
await fsp3.rm(tmp, { recursive: true, force: true });
|
|
2370
|
+
await fsp3.mkdir(tmp, { recursive: true });
|
|
2371
|
+
try {
|
|
2372
|
+
const file = path11.join(tmp, ".unduh.tar.gz");
|
|
2373
|
+
await downloadVerified(url, sha256, file, (p) => say(`Codex CLI ${p}%`));
|
|
2374
|
+
say("Membuka unduhan...");
|
|
2375
|
+
await untar(file, tmp);
|
|
2376
|
+
await fsp3.rm(file, { force: true });
|
|
2377
|
+
const found = fs14.readdirSync(tmp).find((n) => /^codex/.test(n) && !/\.(tar\.gz|zip|zst)$/.test(n));
|
|
2378
|
+
if (!found)
|
|
2379
|
+
throw new Error("Codex CLI: programnya tidak ada di unduhan.");
|
|
2380
|
+
if (process.platform !== "win32")
|
|
2381
|
+
await fsp3.chmod(path11.join(tmp, found), 493);
|
|
2382
|
+
await fsp3.rm(dir, { recursive: true, force: true });
|
|
2383
|
+
await fsp3.rename(tmp, dir);
|
|
2384
|
+
const cmd = path11.join(dir, found);
|
|
2385
|
+
fs14.writeFileSync(mark, JSON.stringify({ cmd, version }));
|
|
2386
|
+
return cmd;
|
|
2387
|
+
} catch (e) {
|
|
2388
|
+
await fsp3.rm(tmp, { recursive: true, force: true });
|
|
2389
|
+
throw e;
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
var envOf = (m) => Object.fromEntries((m?.env ?? []).map((e) => [e.name, e.value]));
|
|
2393
|
+
var tomlTable = (o) => `{${Object.entries(o).map(([k, v]) => `${/^[A-Za-z0-9_-]+$/.test(k) ? k : JSON.stringify(k)} = ${JSON.stringify(v)}`).join(", ")}}`;
|
|
2394
|
+
var codexMcpArgs = (mcp) => ["-c", `mcp_servers.hypeframe.command=${JSON.stringify(mcp.command)}`, "-c", `mcp_servers.hypeframe.args=${JSON.stringify(mcp.args)}`, "-c", `mcp_servers.hypeframe.env=${tomlTable(envOf(mcp))}`];
|
|
2395
|
+
async function tuiSpec(a, mcp, say) {
|
|
2396
|
+
const linux = !!a.launch.linux;
|
|
2397
|
+
const env = { ...a.launch.env, ...agentEnv(a.id), TERM: "xterm-256color", COLORTERM: "truecolor" };
|
|
2398
|
+
const tools = envOf(mcp);
|
|
2399
|
+
if (a.id === "opencode") {
|
|
2400
|
+
if (mcp)
|
|
2401
|
+
env.OPENCODE_CONFIG_CONTENT = JSON.stringify({ mcp: { hypeframe: { type: "local", command: [mcp.command, ...mcp.args], environment: tools, enabled: true } } });
|
|
2402
|
+
return { cmd: a.launch.cmd, args: a.launch.args.filter((x) => x !== "acp"), env, linux };
|
|
2403
|
+
}
|
|
2404
|
+
if (a.id === "codex-acp") {
|
|
2405
|
+
delete env.BUN_BE_BUN;
|
|
2406
|
+
const cmd = await codexCli(linux, say);
|
|
2407
|
+
return { cmd, args: mcp ? codexMcpArgs(mcp) : [], env, linux };
|
|
2408
|
+
}
|
|
2409
|
+
if (a.id === "antigravity-acp") {
|
|
2410
|
+
if (linux)
|
|
2411
|
+
return { cmd: "/root/.local/bin/agy", args: [], env, linux };
|
|
2412
|
+
const agy = agyOnComputer();
|
|
2413
|
+
if (!agy)
|
|
2414
|
+
throw new Error("Antigravity CLI (agy) belum ada di komputer ini. Pasang dari antigravity.google/cli, lalu buka terminal ini lagi.");
|
|
2415
|
+
return { cmd: agy, args: [], env, linux };
|
|
2416
|
+
}
|
|
2417
|
+
return { cmd: a.launch.cmd, args: a.launch.args, env: { ...env, ...tools, HYPEFRAME_TUI: "1" }, linux };
|
|
2418
|
+
}
|
|
2419
|
+
function killTree(pid) {
|
|
2420
|
+
if (!pid)
|
|
2421
|
+
return;
|
|
2422
|
+
if (process.platform === "win32") {
|
|
2423
|
+
const k = spawn3("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore" });
|
|
2424
|
+
k.on("error", () => {
|
|
2425
|
+
return;
|
|
2426
|
+
});
|
|
2427
|
+
return;
|
|
2428
|
+
}
|
|
2429
|
+
try {
|
|
2430
|
+
process.kill(pid, "SIGTERM");
|
|
2431
|
+
} catch {}
|
|
2432
|
+
}
|
|
2433
|
+
function scriptInner(spec, cwd, cols, rows, sizeFile) {
|
|
2434
|
+
const loop = `(while kill -0 $$ 2>/dev/null; do if [ -s ${shQuote(sizeFile)} ]; then read r c < ${shQuote(sizeFile)}; : > ${shQuote(sizeFile)}; stty rows "$r" cols "$c" < /dev/tty 2>/dev/null; fi; sleep 0.3; done) >/dev/null 2>&1 &`;
|
|
2435
|
+
return `cd ${shQuote(cwd)} 2>/dev/null; stty rows ${rows} cols ${cols} 2>/dev/null; ${loop} exec ${[spec.cmd, ...spec.args].map(shQuote).join(" ")}`;
|
|
2436
|
+
}
|
|
2437
|
+
function startPty(spec, cwd, cols, rows, sizeFile, onData, onExit) {
|
|
2438
|
+
const dec = new TextDecoder;
|
|
2439
|
+
const b = bun();
|
|
2440
|
+
if (!spec.linux && b) {
|
|
2441
|
+
let ended = false;
|
|
2442
|
+
const p = b.spawn([spec.cmd, ...spec.args], {
|
|
2443
|
+
cwd,
|
|
2444
|
+
env: { ...process.env, ...spec.env },
|
|
2445
|
+
terminal: { cols, rows, data: (_t, d) => onData(dec.decode(d, { stream: true })) }
|
|
2446
|
+
});
|
|
2447
|
+
p.exited.then((code) => (ended = true, onExit(code)), () => (ended = true, onExit(null)));
|
|
2448
|
+
return {
|
|
2449
|
+
write: (s) => !ended && p.terminal?.write(s),
|
|
2450
|
+
resize: (c, r) => !ended && p.terminal?.resize(c, r),
|
|
2451
|
+
kill: () => {
|
|
2452
|
+
killTree(p.pid);
|
|
2453
|
+
try {
|
|
2454
|
+
p.kill();
|
|
2455
|
+
p.terminal?.close();
|
|
2456
|
+
} catch {}
|
|
2457
|
+
}
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
let child;
|
|
2461
|
+
const inner = scriptInner(spec, cwd, cols, rows, sizeFile);
|
|
2462
|
+
if (spec.linux) {
|
|
2463
|
+
const [cmd, args] = linuxCommand("/usr/bin/script", ["-qfec", inner, "/dev/null"], spec.env);
|
|
2464
|
+
child = spawn3(cmd, args, { stdio: ["pipe", "pipe", "pipe"], env: { ...process.env } });
|
|
2465
|
+
} else if (process.platform === "linux" && onPath("script")) {
|
|
2466
|
+
child = spawn3("script", ["-qfec", inner, "/dev/null"], { cwd, stdio: ["pipe", "pipe", "pipe"], env: { ...process.env, ...spec.env } });
|
|
2467
|
+
} else
|
|
2468
|
+
throw new Error("Terminal penuh butuh mesin dari pemasang HypeFrame (bukan npm) di komputer ini. Jalankan: hypeframe update");
|
|
2469
|
+
child.stdout?.on("data", (d) => onData(dec.decode(d, { stream: true })));
|
|
2470
|
+
child.stderr?.on("data", (d) => onData(dec.decode(d, { stream: true })));
|
|
2471
|
+
child.stdin?.on("error", () => {
|
|
2472
|
+
return;
|
|
2473
|
+
});
|
|
2474
|
+
let ended = false;
|
|
2475
|
+
child.on("error", () => (ended = true, onExit(null)));
|
|
2476
|
+
child.on("exit", (code) => (ended = true, onExit(code)));
|
|
2477
|
+
return {
|
|
2478
|
+
write: (s) => !ended && child.stdin?.write(s),
|
|
2479
|
+
resize: (c, r) => {
|
|
2480
|
+
try {
|
|
2481
|
+
fs14.writeFileSync(sizeFile, `${r} ${c}
|
|
2482
|
+
`);
|
|
2483
|
+
} catch {}
|
|
2484
|
+
},
|
|
2485
|
+
kill: () => killTree(child.pid)
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
var clampInt = (v, lo, hi, d) => {
|
|
2489
|
+
const n = Math.round(Number(v));
|
|
2490
|
+
return Number.isFinite(n) ? Math.min(hi, Math.max(lo, n)) : d;
|
|
2491
|
+
};
|
|
2492
|
+
var cutAt = (s, n) => s.length <= n ? s.length : /[\uD800-\uDBFF]/.test(s[n - 1]) ? n - 1 : n;
|
|
2493
|
+
function createTerminals(h) {
|
|
2494
|
+
const list = new Map;
|
|
2495
|
+
let lastSend = 0;
|
|
2496
|
+
const str = (c, k) => typeof c[k] === "string" ? c[k] : "";
|
|
2497
|
+
function flush(t) {
|
|
2498
|
+
t.timer = null;
|
|
2499
|
+
if (!t.pend)
|
|
2500
|
+
return;
|
|
2501
|
+
const wait = lastSend + GAP_MS - Date.now();
|
|
2502
|
+
if (wait > 0)
|
|
2503
|
+
return void (t.timer = setTimeout(() => flush(t), wait));
|
|
2504
|
+
const n = cutAt(t.pend, PIECE);
|
|
2505
|
+
const data = t.pend.slice(0, n);
|
|
2506
|
+
t.pend = t.pend.slice(n);
|
|
2507
|
+
lastSend = Date.now();
|
|
2508
|
+
h.conn.tty(t.dari, { id: t.id, data });
|
|
2509
|
+
if (t.pend)
|
|
2510
|
+
t.timer = setTimeout(() => flush(t), GAP_MS);
|
|
2511
|
+
}
|
|
2512
|
+
function out(t, s) {
|
|
2513
|
+
if (!s || t.ended)
|
|
2514
|
+
return;
|
|
2515
|
+
t.keep = (t.keep + s).slice(-KEEP);
|
|
2516
|
+
t.pend = (t.pend + s).slice(-4 * KEEP);
|
|
2517
|
+
if (!t.timer)
|
|
2518
|
+
t.timer = setTimeout(() => flush(t), t.pend.length >= PIECE ? 0 : 12);
|
|
2519
|
+
}
|
|
2520
|
+
const note = (t, s) => out(t, `\x1B[2m${s}\x1B[0m\r
|
|
2521
|
+
`);
|
|
2522
|
+
function end(t, code) {
|
|
2523
|
+
if (t.ended)
|
|
2524
|
+
return;
|
|
2525
|
+
t.ended = true;
|
|
2526
|
+
if (t.timer)
|
|
2527
|
+
clearTimeout(t.timer);
|
|
2528
|
+
while (t.pend) {
|
|
2529
|
+
const n = cutAt(t.pend, PIECE);
|
|
2530
|
+
h.conn.tty(t.dari, { id: t.id, data: t.pend.slice(0, n) });
|
|
2531
|
+
t.pend = t.pend.slice(n);
|
|
2532
|
+
}
|
|
2533
|
+
h.conn.tty(t.dari, { id: t.id, selesai: code });
|
|
2534
|
+
list.delete(t.id);
|
|
2535
|
+
h.dropRoute(t.routeId);
|
|
2536
|
+
fs14.rmSync(t.sizeFile, { force: true });
|
|
2537
|
+
h.onEvent?.({ type: "closed", agent: t.name, code });
|
|
2538
|
+
}
|
|
2539
|
+
async function launch(t, a, mcp) {
|
|
2540
|
+
try {
|
|
2541
|
+
const spec = await tuiSpec(a, mcp, (s) => note(t, s));
|
|
2542
|
+
if (t.ended)
|
|
2543
|
+
return;
|
|
2544
|
+
t.pty = startPty(spec, projectDir(t.projectId), t.cols, t.rows, t.sizeFile, (s) => out(t, s), (code) => end(t, code));
|
|
2545
|
+
h.onEvent?.({ type: "open", agent: t.name });
|
|
2546
|
+
} catch (e) {
|
|
2547
|
+
note(t, `${e.message}`.slice(0, 400));
|
|
2548
|
+
end(t, null);
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
const work = {
|
|
2552
|
+
"terminal.buka": async (c) => {
|
|
2553
|
+
const agentId = str(c, "agentId");
|
|
2554
|
+
const projectId = str(c, "projectId");
|
|
2555
|
+
if (!/^[A-Za-z0-9_-]{1,80}$/.test(projectId))
|
|
2556
|
+
throw new Error("Buka project dulu.");
|
|
2557
|
+
const a = h.agent(agentId);
|
|
2558
|
+
if (!a)
|
|
2559
|
+
throw new Error("Agen belum dipasang di mesin ini.");
|
|
2560
|
+
if (!ptySupported())
|
|
2561
|
+
throw new Error("Terminal penuh butuh mesin dari pemasang HypeFrame (bukan npm) di komputer ini. Jalankan: hypeframe update");
|
|
2562
|
+
if (!hasTerminal(a))
|
|
2563
|
+
throw new Error(`${a.name} belum punya program terminal di komputer ini.`);
|
|
2564
|
+
const dari = str(c, "dari");
|
|
2565
|
+
const tab = str(c, "tab");
|
|
2566
|
+
const alat = Array.isArray(c.alat) ? c.alat : undefined;
|
|
2567
|
+
const cols = clampInt(c.cols, 20, 400, 100);
|
|
2568
|
+
const rows = clampInt(c.rows, 5, 200, 30);
|
|
2569
|
+
const old = [...list.values()].find((x) => x.agentId === agentId && x.projectId === projectId && !x.ended);
|
|
2570
|
+
if (old) {
|
|
2571
|
+
old.dari = dari;
|
|
2572
|
+
old.tab = tab;
|
|
2573
|
+
old.seen = Date.now();
|
|
2574
|
+
h.moveRoute(old.routeId, dari, tab, alat);
|
|
2575
|
+
const ulang = old.keep;
|
|
2576
|
+
old.pend = "";
|
|
2577
|
+
if (old.pty) {
|
|
2578
|
+
old.pty.resize(cols, Math.max(5, rows - 1));
|
|
2579
|
+
setTimeout(() => (old.pty?.resize(cols, rows), old.cols = cols, old.rows = rows), 60);
|
|
2580
|
+
}
|
|
2581
|
+
return { terminal: old.id, nama: old.name, ulang, lama: true };
|
|
2582
|
+
}
|
|
2583
|
+
if (list.size >= MAX_TERMINALS)
|
|
2584
|
+
throw new Error(`Sudah ada ${MAX_TERMINALS} terminal terbuka di mesin ini. Tutup salah satu dulu.`);
|
|
2585
|
+
const id = `t${crypto4.randomBytes(8).toString("hex")}`;
|
|
2586
|
+
const r = h.openRoute({ dari, tab, alat: alat ?? [], projectId, agentId });
|
|
2587
|
+
const ttyDir = path11.join(dataDir(), "tty");
|
|
2588
|
+
fs14.mkdirSync(ttyDir, { recursive: true, mode: 448 });
|
|
2589
|
+
const t = { id, agentId, projectId, name: a.name, dari, tab, routeId: r.routeId, cols, rows, keep: "", pend: "", timer: null, seen: Date.now(), pty: null, ended: false, sizeFile: path11.join(ttyDir, id) };
|
|
2590
|
+
list.set(id, t);
|
|
2591
|
+
launch(t, a, r.mcp);
|
|
2592
|
+
return { terminal: id, nama: a.name, ulang: "", lama: false };
|
|
2593
|
+
},
|
|
2594
|
+
"terminal.tutup": async (c) => {
|
|
2595
|
+
const t = list.get(str(c, "terminal"));
|
|
2596
|
+
if (t)
|
|
2597
|
+
t.pty ? t.pty.kill() : end(t, null);
|
|
2598
|
+
return {};
|
|
2599
|
+
}
|
|
2600
|
+
};
|
|
2601
|
+
function input(dari, m) {
|
|
2602
|
+
const t = list.get(String(m.id ?? ""));
|
|
2603
|
+
if (!t || t.ended || t.dari !== dari)
|
|
2604
|
+
return;
|
|
2605
|
+
t.seen = Date.now();
|
|
2606
|
+
if (typeof m.data === "string" && m.data && m.data.length <= MAX_INPUT)
|
|
2607
|
+
t.pty?.write(m.data);
|
|
2608
|
+
if (Array.isArray(m.ukuran) && m.ukuran.length === 2) {
|
|
2609
|
+
const cols = clampInt(m.ukuran[0], 20, 400, t.cols);
|
|
2610
|
+
const rows = clampInt(m.ukuran[1], 5, 200, t.rows);
|
|
2611
|
+
if (cols !== t.cols || rows !== t.rows)
|
|
2612
|
+
t.cols = cols, t.rows = rows, t.pty?.resize(cols, rows);
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
const sweep = setInterval(() => {
|
|
2616
|
+
for (const t of list.values())
|
|
2617
|
+
if (Date.now() - t.seen > IDLE_MS)
|
|
2618
|
+
note(t, "Ditutup karena 15 menit tidak dibuka."), t.pty ? t.pty.kill() : end(t, null);
|
|
2619
|
+
}, 60000);
|
|
2620
|
+
sweep.unref();
|
|
2621
|
+
return {
|
|
2622
|
+
work,
|
|
2623
|
+
input,
|
|
2624
|
+
count: () => list.size,
|
|
2625
|
+
stopAll: () => {
|
|
2626
|
+
clearInterval(sweep);
|
|
2627
|
+
for (const t of list.values())
|
|
2628
|
+
t.pty?.kill();
|
|
2629
|
+
list.clear();
|
|
2630
|
+
}
|
|
2631
|
+
};
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
// packages/hypeframe/src/agent/service.ts
|
|
1944
2635
|
var hostOf = (u) => {
|
|
1945
2636
|
try {
|
|
1946
2637
|
return new URL(u).host;
|
|
@@ -1960,7 +2651,7 @@ var ERRORS = {
|
|
|
1960
2651
|
var MAX_HISTORY = 2 * 1024 * 1024;
|
|
1961
2652
|
var HISTORY_ANSWER = 170 * 1024;
|
|
1962
2653
|
var MAX_FILE2 = 4 * 1024 * 1024;
|
|
1963
|
-
var
|
|
2654
|
+
var PIECE2 = 150 * 1024;
|
|
1964
2655
|
var MEDIA = {
|
|
1965
2656
|
png: "image/png",
|
|
1966
2657
|
jpg: "image/jpeg",
|
|
@@ -2061,28 +2752,28 @@ function mcpServerFor(agent, url, key, bridge) {
|
|
|
2061
2752
|
return { name: "hypeframe", command: bridge.command, args: bridge.args, env: [...bridge.env, ...env] };
|
|
2062
2753
|
}
|
|
2063
2754
|
function historyFile(projectId, sessionId) {
|
|
2064
|
-
return
|
|
2755
|
+
return path12.join(projectDir(projectId), "riwayat", `${crypto5.createHash("sha256").update(sessionId).digest("hex").slice(0, 32)}.jsonl`);
|
|
2065
2756
|
}
|
|
2066
2757
|
function record(file, updates) {
|
|
2067
2758
|
if (!updates.length)
|
|
2068
2759
|
return;
|
|
2069
2760
|
try {
|
|
2070
|
-
|
|
2071
|
-
|
|
2761
|
+
fs15.mkdirSync(path12.dirname(file), { recursive: true });
|
|
2762
|
+
fs15.appendFileSync(file, `${updates.map((u) => JSON.stringify(u)).join(`
|
|
2072
2763
|
`)}
|
|
2073
2764
|
`);
|
|
2074
|
-
if (
|
|
2075
|
-
const text =
|
|
2765
|
+
if (fs15.statSync(file).size > MAX_HISTORY) {
|
|
2766
|
+
const text = fs15.readFileSync(file, "utf8");
|
|
2076
2767
|
const from = text.indexOf(`
|
|
2077
2768
|
`, text.length - MAX_HISTORY / 2);
|
|
2078
|
-
|
|
2769
|
+
fs15.writeFileSync(file, from >= 0 ? text.slice(from + 1) : "");
|
|
2079
2770
|
}
|
|
2080
2771
|
} catch {}
|
|
2081
2772
|
}
|
|
2082
2773
|
function readHistory(file) {
|
|
2083
2774
|
let text = "";
|
|
2084
2775
|
try {
|
|
2085
|
-
text =
|
|
2776
|
+
text = fs15.readFileSync(file, "utf8");
|
|
2086
2777
|
} catch {
|
|
2087
2778
|
return { update: [], potong: false };
|
|
2088
2779
|
}
|
|
@@ -2101,7 +2792,7 @@ function readHistory(file) {
|
|
|
2101
2792
|
return { update: out.reverse(), potong: false };
|
|
2102
2793
|
}
|
|
2103
2794
|
function createAgentService(o) {
|
|
2104
|
-
const key =
|
|
2795
|
+
const key = crypto5.randomBytes(24).toString("base64url");
|
|
2105
2796
|
const routes = new Map;
|
|
2106
2797
|
const sessionRoute = new Map;
|
|
2107
2798
|
const permissions = new Map;
|
|
@@ -2159,7 +2850,7 @@ function createAgentService(o) {
|
|
|
2159
2850
|
record(file, packUpdates(list).flat());
|
|
2160
2851
|
},
|
|
2161
2852
|
onPermission: (sessionId, req, info) => new Promise((ok) => {
|
|
2162
|
-
const id = `i${
|
|
2853
|
+
const id = `i${crypto5.randomBytes(6).toString("hex")}`;
|
|
2163
2854
|
const done = (v) => (permissions.delete(id), asked.delete(id), ok(v));
|
|
2164
2855
|
permissions.set(id, done);
|
|
2165
2856
|
const agent = nameOf(sessions.agentOf(sessionId));
|
|
@@ -2177,7 +2868,26 @@ function createAgentService(o) {
|
|
|
2177
2868
|
flushMs: o.flushMs ?? 100
|
|
2178
2869
|
});
|
|
2179
2870
|
const text = (c, k) => typeof c[k] === "string" ? c[k] : "";
|
|
2871
|
+
const terminals = createTerminals({
|
|
2872
|
+
conn: { tty: (ke, b) => o.conn.tty?.(ke, b) },
|
|
2873
|
+
agent: (id) => readInstalled().find((a) => a.id === id),
|
|
2874
|
+
openRoute: (r) => {
|
|
2875
|
+
const routeId = `t${crypto5.randomBytes(12).toString("base64url")}`;
|
|
2876
|
+
routes.set(routeId, { ...r });
|
|
2877
|
+
const agent = readInstalled().find((a) => a.id === r.agentId);
|
|
2878
|
+
return { routeId, mcp: mcpServerFor(agent, `http://127.0.0.1:${o.port()}/agen/mcp/${r.projectId}/${routeId}`, key, o.bridge) };
|
|
2879
|
+
},
|
|
2880
|
+
moveRoute: (id, dari, tab, alat) => {
|
|
2881
|
+
const r = routes.get(id);
|
|
2882
|
+
if (r)
|
|
2883
|
+
r.dari = dari, r.tab = tab || r.tab, alat && (r.alat = alat);
|
|
2884
|
+
},
|
|
2885
|
+
dropRoute: (id) => void routes.delete(id),
|
|
2886
|
+
onEvent: (e) => emit(e.type === "open" ? { type: "terminal", agent: e.agent } : { type: "terminalClosed", agent: e.agent, code: e.code ?? null })
|
|
2887
|
+
});
|
|
2180
2888
|
const work = {
|
|
2889
|
+
"terminal.buka": (c) => terminals.work["terminal.buka"](c),
|
|
2890
|
+
"terminal.tutup": (c) => terminals.work["terminal.tutup"](c),
|
|
2181
2891
|
"agen.mulai": async (c) => {
|
|
2182
2892
|
const agentId = text(c, "agentId");
|
|
2183
2893
|
const projectId = text(c, "projectId");
|
|
@@ -2315,22 +3025,22 @@ function createAgentService(o) {
|
|
|
2315
3025
|
const folder = projectDir(projectId);
|
|
2316
3026
|
if (!p || !insideFolder(folder, p))
|
|
2317
3027
|
return fail(`Only files inside the HypeFrame project folder (${folder}) can be added.`);
|
|
2318
|
-
const file =
|
|
2319
|
-
const st =
|
|
3028
|
+
const file = path12.resolve(folder, p);
|
|
3029
|
+
const st = fs15.statSync(file, { throwIfNoEntry: false });
|
|
2320
3030
|
if (!st?.isFile())
|
|
2321
3031
|
return fail(`${p} is not a file in the project folder.`);
|
|
2322
|
-
const nama =
|
|
2323
|
-
const mime = MEDIA[
|
|
3032
|
+
const nama = path12.basename(file).slice(0, 120);
|
|
3033
|
+
const mime = MEDIA[path12.extname(file).slice(1).toLowerCase()];
|
|
2324
3034
|
if (!mime)
|
|
2325
3035
|
return fail(`${nama}: only images, audio, video, fonts and Lottie/JSON files can be added to a HypeFrame project.`);
|
|
2326
3036
|
if (st.size > MAX_FILE2)
|
|
2327
3037
|
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.`);
|
|
2328
|
-
const data =
|
|
2329
|
-
const n = Math.max(1, Math.ceil(data.length /
|
|
2330
|
-
const id =
|
|
3038
|
+
const data = fs15.readFileSync(file).toString("base64");
|
|
3039
|
+
const n = Math.max(1, Math.ceil(data.length / PIECE2));
|
|
3040
|
+
const id = crypto5.randomBytes(8).toString("hex");
|
|
2331
3041
|
let last = {};
|
|
2332
3042
|
for (let i = 0;i < n; i++) {
|
|
2333
|
-
last = await o.conn.request(target.dari, "alat", { nama: "_berkas", arg: { id, i, n, nama, mime, ukuran: st.size, data: data.slice(i *
|
|
3043
|
+
last = await o.conn.request(target.dari, "alat", { nama: "_berkas", arg: { id, i, n, nama, mime, ukuran: st.size, data: data.slice(i * PIECE2, (i + 1) * PIECE2) } });
|
|
2334
3044
|
if (last.ok === false) {
|
|
2335
3045
|
const error = String(last.error) in ERRORS ? String(last.error) : "tab";
|
|
2336
3046
|
o.onToolError?.(error);
|
|
@@ -2350,7 +3060,7 @@ function createAgentService(o) {
|
|
|
2350
3060
|
if (!m)
|
|
2351
3061
|
return false;
|
|
2352
3062
|
const auth = String(req.headers.authorization || "").replace(/^Bearer\s+/i, "");
|
|
2353
|
-
if (req.method !== "POST" || auth.length !== key.length || !
|
|
3063
|
+
if (req.method !== "POST" || auth.length !== key.length || !crypto5.timingSafeEqual(Buffer.from(auth), Buffer.from(key)))
|
|
2354
3064
|
return reply(res, 401, { error: "unauthorized" }), true;
|
|
2355
3065
|
let s = "";
|
|
2356
3066
|
for await (const d of req)
|
|
@@ -2399,10 +3109,10 @@ function createAgentService(o) {
|
|
|
2399
3109
|
}
|
|
2400
3110
|
function capabilities() {
|
|
2401
3111
|
const api = opencodeApi();
|
|
2402
|
-
return readInstalled().filter((a) => isSupported(a.id) || process.env.HYPEFRAME_ACP_REGISTRY).slice(0, 8).map((a) => ({ id: a.id, nama: a.name, siap: a.ready === true, ...a.id === OPENCODE && api ? { api: hostOf(api.url) } : {} }));
|
|
3112
|
+
return readInstalled().filter((a) => isSupported(a.id) || process.env.HYPEFRAME_ACP_REGISTRY).slice(0, 8).map((a) => ({ id: a.id, nama: a.name, siap: a.ready === true, ...a.id === OPENCODE && api ? { api: hostOf(api.url) } : {}, ...hasTerminal(a) ? { terminal: true } : {} }));
|
|
2403
3113
|
}
|
|
2404
3114
|
const stamps = new Map;
|
|
2405
|
-
const stampOf = (id) => [
|
|
3115
|
+
const stampOf = (id) => [path12.join(agentDir(), id, "agent.json"), path12.join(agentDir(), id, "env.json"), ...id === OPENCODE ? [path12.join(dataDir(), "opencode.json")] : []].map((f) => fs15.statSync(f, { throwIfNoEntry: false })?.mtimeMs ?? 0).join(":");
|
|
2406
3116
|
function checkAccounts() {
|
|
2407
3117
|
const running = sessions.running();
|
|
2408
3118
|
const restarted = [];
|
|
@@ -2425,37 +3135,22 @@ function createAgentService(o) {
|
|
|
2425
3135
|
function activity() {
|
|
2426
3136
|
return { chats: sessions.count(), working: sessions.working(), agents: sessions.running().map((id) => nameOf(id)) };
|
|
2427
3137
|
}
|
|
2428
|
-
return {
|
|
3138
|
+
return {
|
|
3139
|
+
work,
|
|
3140
|
+
route,
|
|
3141
|
+
capabilities,
|
|
3142
|
+
checkAccounts,
|
|
3143
|
+
activity,
|
|
3144
|
+
key,
|
|
3145
|
+
tty: terminals.input,
|
|
3146
|
+
stop: () => (stopping = true, clearInterval(ticker), terminals.stopAll(), sessions.stopAll())
|
|
3147
|
+
};
|
|
2429
3148
|
}
|
|
2430
3149
|
|
|
2431
|
-
// src/agent/mcp-bridge.ts
|
|
2432
|
-
import
|
|
2433
|
-
import
|
|
3150
|
+
// packages/hypeframe/src/agent/mcp-bridge.ts
|
|
3151
|
+
import fs16 from "node:fs";
|
|
3152
|
+
import path13 from "node:path";
|
|
2434
3153
|
import readline2 from "node:readline";
|
|
2435
|
-
|
|
2436
|
-
// src/util/runtime.ts
|
|
2437
|
-
import fs12 from "node:fs";
|
|
2438
|
-
import path9 from "node:path";
|
|
2439
|
-
function isStandalone() {
|
|
2440
|
-
return path9.basename(process.execPath).toLowerCase().startsWith("hypeframe");
|
|
2441
|
-
}
|
|
2442
|
-
function runtimeLabel() {
|
|
2443
|
-
const bun = process.versions.bun;
|
|
2444
|
-
return bun && !isStandalone() ? `Bun ${bun}` : isStandalone() ? `Bun ${bun ?? "?"} (standalone)` : `Node ${process.versions.node}`;
|
|
2445
|
-
}
|
|
2446
|
-
function launchCommand() {
|
|
2447
|
-
if (isStandalone())
|
|
2448
|
-
return [process.execPath];
|
|
2449
|
-
try {
|
|
2450
|
-
const script = fs12.realpathSync(process.argv[1] || "");
|
|
2451
|
-
return /[\\/]_npx[\\/]/.test(script) ? null : [process.execPath, script];
|
|
2452
|
-
} catch {
|
|
2453
|
-
return null;
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
var INSTALL_URL = "https://hype-frame.com/install";
|
|
2457
|
-
|
|
2458
|
-
// src/agent/mcp-bridge.ts
|
|
2459
3154
|
var BRIDGE_SOURCE = `// HypeFrame MCP bridge (written by hypeframe; do not edit). stdin JSON-RPC lines -> engine -> stdout.
|
|
2460
3155
|
import readline from 'node:readline';
|
|
2461
3156
|
const url = process.env.HF_MCP_URL, key = process.env.HF_MCP_KUNCI;
|
|
@@ -2483,13 +3178,13 @@ rl.on('line', (line) => {
|
|
|
2483
3178
|
rl.on('close', () => Promise.all(busy).then(() => process.exit(0)));
|
|
2484
3179
|
`;
|
|
2485
3180
|
function bridgeLaunch() {
|
|
2486
|
-
const file =
|
|
3181
|
+
const file = path13.join(agentDir(), "mcp-bridge.mjs");
|
|
2487
3182
|
let now = "";
|
|
2488
3183
|
try {
|
|
2489
|
-
now =
|
|
3184
|
+
now = fs16.readFileSync(file, "utf8");
|
|
2490
3185
|
} catch {}
|
|
2491
3186
|
if (now !== BRIDGE_SOURCE)
|
|
2492
|
-
|
|
3187
|
+
fs16.writeFileSync(file, BRIDGE_SOURCE);
|
|
2493
3188
|
return { command: process.execPath, args: [file], env: isStandalone() ? [{ name: "BUN_BE_BUN", value: "1" }] : [] };
|
|
2494
3189
|
}
|
|
2495
3190
|
async function runMcpBridge() {
|
|
@@ -2534,8 +3229,8 @@ async function runMcpBridge() {
|
|
|
2534
3229
|
await Promise.all(busy);
|
|
2535
3230
|
}
|
|
2536
3231
|
|
|
2537
|
-
// src/config/lock.ts
|
|
2538
|
-
import
|
|
3232
|
+
// packages/hypeframe/src/config/lock.ts
|
|
3233
|
+
import fs17 from "node:fs";
|
|
2539
3234
|
class AlreadyRunning extends Error {
|
|
2540
3235
|
code = "SUDAH_JALAN";
|
|
2541
3236
|
}
|
|
@@ -2549,7 +3244,7 @@ var alive = (pid) => {
|
|
|
2549
3244
|
};
|
|
2550
3245
|
function runningPid() {
|
|
2551
3246
|
try {
|
|
2552
|
-
const pid = Number(
|
|
3247
|
+
const pid = Number(fs17.readFileSync(lockFile(), "utf8"));
|
|
2553
3248
|
return Number.isInteger(pid) && pid > 0 && pid !== process.pid && alive(pid) ? pid : null;
|
|
2554
3249
|
} catch {
|
|
2555
3250
|
return null;
|
|
@@ -2559,13 +3254,13 @@ function singleInstance() {
|
|
|
2559
3254
|
const f = lockFile();
|
|
2560
3255
|
for (let attempt = 0;attempt < 2; attempt++) {
|
|
2561
3256
|
try {
|
|
2562
|
-
const fd =
|
|
2563
|
-
|
|
2564
|
-
|
|
3257
|
+
const fd = fs17.openSync(f, "wx");
|
|
3258
|
+
fs17.writeSync(fd, String(process.pid));
|
|
3259
|
+
fs17.closeSync(fd);
|
|
2565
3260
|
const release = () => {
|
|
2566
3261
|
try {
|
|
2567
|
-
if (
|
|
2568
|
-
|
|
3262
|
+
if (fs17.readFileSync(f, "utf8") === String(process.pid))
|
|
3263
|
+
fs17.rmSync(f, { force: true });
|
|
2569
3264
|
} catch {}
|
|
2570
3265
|
process.off("exit", release);
|
|
2571
3266
|
};
|
|
@@ -2574,17 +3269,17 @@ function singleInstance() {
|
|
|
2574
3269
|
} catch (e) {
|
|
2575
3270
|
if (e.code !== "EEXIST")
|
|
2576
3271
|
throw e;
|
|
2577
|
-
const pid = Number(
|
|
3272
|
+
const pid = Number(fs17.readFileSync(f, "utf8"));
|
|
2578
3273
|
if (Number.isInteger(pid) && pid > 0 && alive(pid))
|
|
2579
3274
|
throw new AlreadyRunning("engine already running");
|
|
2580
|
-
|
|
3275
|
+
fs17.rmSync(f, { force: true });
|
|
2581
3276
|
}
|
|
2582
3277
|
}
|
|
2583
3278
|
throw new AlreadyRunning("engine already running");
|
|
2584
3279
|
}
|
|
2585
3280
|
|
|
2586
|
-
// src/engine/connection.ts
|
|
2587
|
-
import
|
|
3281
|
+
// packages/hypeframe/src/engine/connection.ts
|
|
3282
|
+
import crypto6 from "node:crypto";
|
|
2588
3283
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
2589
3284
|
import WebSocket from "ws";
|
|
2590
3285
|
var SILENCE_MAX_MS = 70000;
|
|
@@ -2625,12 +3320,15 @@ class Connection extends EventEmitter2 {
|
|
|
2625
3320
|
news(kind, body = {}) {
|
|
2626
3321
|
this.send({ ...body, t: "kabar", jenis: kind });
|
|
2627
3322
|
}
|
|
3323
|
+
tty(ke, body) {
|
|
3324
|
+
this.send({ ...body, t: "tty", ke });
|
|
3325
|
+
}
|
|
2628
3326
|
nextReq = 1;
|
|
2629
3327
|
waiting = new Map;
|
|
2630
3328
|
request(ke, kind, body, timeoutMs = 55000) {
|
|
2631
3329
|
if (!this.connected)
|
|
2632
3330
|
return Promise.resolve({ ok: false, error: "terputus" });
|
|
2633
|
-
const id = `q${this.nextReq++}${
|
|
3331
|
+
const id = `q${this.nextReq++}${crypto6.randomBytes(6).toString("hex")}`;
|
|
2634
3332
|
return new Promise((ok) => {
|
|
2635
3333
|
const timer = setTimeout(() => (this.waiting.delete(id), ok({ ok: false, error: "waktu" })), timeoutMs);
|
|
2636
3334
|
timer.unref?.();
|
|
@@ -2692,6 +3390,8 @@ class Connection extends EventEmitter2 {
|
|
|
2692
3390
|
this.send({ t: "balas", ke: m.dari, id: m.id, ...result });
|
|
2693
3391
|
} else if (m.t === "jawab") {
|
|
2694
3392
|
this.answer(m);
|
|
3393
|
+
} else if (m.t === "tty") {
|
|
3394
|
+
this.emit("tty", m);
|
|
2695
3395
|
}
|
|
2696
3396
|
});
|
|
2697
3397
|
ws.on("error", () => {
|
|
@@ -2721,7 +3421,7 @@ class Connection extends EventEmitter2 {
|
|
|
2721
3421
|
}
|
|
2722
3422
|
}
|
|
2723
3423
|
|
|
2724
|
-
// src/engine/handler.ts
|
|
3424
|
+
// packages/hypeframe/src/engine/handler.ts
|
|
2725
3425
|
function createHandler(work) {
|
|
2726
3426
|
return async function handle(c) {
|
|
2727
3427
|
const kind = String(c?.jenis || "");
|
|
@@ -2736,7 +3436,7 @@ function createHandler(work) {
|
|
|
2736
3436
|
};
|
|
2737
3437
|
}
|
|
2738
3438
|
|
|
2739
|
-
// src/engine/pairing.ts
|
|
3439
|
+
// packages/hypeframe/src/engine/pairing.ts
|
|
2740
3440
|
var sleep = (ms, signal) => new Promise((ok, fail) => {
|
|
2741
3441
|
const timer = setTimeout(ok, ms);
|
|
2742
3442
|
signal?.addEventListener("abort", () => (clearTimeout(timer), fail(new Error("Dibatalkan."))), { once: true });
|
|
@@ -2812,26 +3512,28 @@ async function pair(o) {
|
|
|
2812
3512
|
}
|
|
2813
3513
|
}
|
|
2814
3514
|
|
|
2815
|
-
// src/render/chrome.ts
|
|
2816
|
-
import
|
|
3515
|
+
// packages/hypeframe/src/render/chrome.ts
|
|
3516
|
+
import fs18 from "node:fs";
|
|
2817
3517
|
import http from "node:http";
|
|
2818
|
-
import
|
|
3518
|
+
import path14 from "node:path";
|
|
2819
3519
|
import { Browser, detectBrowserPlatform, getInstalledBrowsers, install, resolveBuildId } from "@puppeteer/browsers";
|
|
2820
3520
|
import puppeteer from "puppeteer-core";
|
|
2821
3521
|
var ANDROID_ARGS = ["--no-sandbox", "--disable-dev-shm-usage"];
|
|
2822
3522
|
var ANDROID_FALLBACKS = [
|
|
2823
3523
|
{ args: [], pipe: false },
|
|
2824
3524
|
{ args: [], pipe: true },
|
|
3525
|
+
{ args: ["--disable-gpu"], pipe: true },
|
|
2825
3526
|
{ args: ["--enable-features=NetworkServiceInProcess2"], pipe: true },
|
|
3527
|
+
{ args: ["--disable-gpu", "--single-process", "--no-zygote"], pipe: true },
|
|
2826
3528
|
{ args: ["--single-process", "--no-zygote"], pipe: true },
|
|
2827
3529
|
{ args: ["--enable-features=NetworkServiceInProcess2"], pipe: false },
|
|
2828
3530
|
{ args: ["--single-process", "--no-zygote"], pipe: false }
|
|
2829
3531
|
];
|
|
2830
|
-
var flagsFile = () =>
|
|
3532
|
+
var flagsFile = () => path14.join(dataDir(), "chrome-flags.json");
|
|
2831
3533
|
var sameCara = (a, b) => a.pipe === b.pipe && a.args.length === b.args.length && a.args.every((x, i) => x === b.args[i]);
|
|
2832
3534
|
function savedCara() {
|
|
2833
3535
|
try {
|
|
2834
|
-
const j = JSON.parse(
|
|
3536
|
+
const j = JSON.parse(fs18.readFileSync(flagsFile(), "utf8"));
|
|
2835
3537
|
const c = { args: Array.isArray(j.args) ? j.args.map(String) : [], pipe: j.pipe === true };
|
|
2836
3538
|
return ANDROID_FALLBACKS.some((f) => sameCara(f, c)) ? c : { args: [], pipe: false };
|
|
2837
3539
|
} catch {
|
|
@@ -2841,9 +3543,9 @@ function savedCara() {
|
|
|
2841
3543
|
function saveCara(c) {
|
|
2842
3544
|
try {
|
|
2843
3545
|
if (c.args.length || c.pipe)
|
|
2844
|
-
|
|
3546
|
+
fs18.writeFileSync(flagsFile(), JSON.stringify(c));
|
|
2845
3547
|
else
|
|
2846
|
-
|
|
3548
|
+
fs18.rmSync(flagsFile(), { force: true });
|
|
2847
3549
|
} catch {}
|
|
2848
3550
|
}
|
|
2849
3551
|
function chromePlatformArgs(android = isAndroid()) {
|
|
@@ -2856,7 +3558,7 @@ async function probeChrome(attempt, android = isAndroid()) {
|
|
|
2856
3558
|
if (!android)
|
|
2857
3559
|
return attempt({ args: [], pipe: false });
|
|
2858
3560
|
const saved = savedCara();
|
|
2859
|
-
|
|
3561
|
+
const errors = [];
|
|
2860
3562
|
for (const cara of [saved, ...ANDROID_FALLBACKS.filter((f) => !sameCara(f, saved))]) {
|
|
2861
3563
|
try {
|
|
2862
3564
|
const r = await attempt({ args: [...cara.args], pipe: cara.pipe });
|
|
@@ -2864,10 +3566,19 @@ async function probeChrome(attempt, android = isAndroid()) {
|
|
|
2864
3566
|
saveCara(cara);
|
|
2865
3567
|
return r;
|
|
2866
3568
|
} catch (e) {
|
|
2867
|
-
|
|
3569
|
+
errors.push(e);
|
|
2868
3570
|
}
|
|
2869
3571
|
}
|
|
2870
|
-
|
|
3572
|
+
const reasons = [...new Set(errors.map((e) => e instanceof Error ? e.message : String(e)))];
|
|
3573
|
+
if (reasons.length === 1)
|
|
3574
|
+
throw errors[0];
|
|
3575
|
+
throw new Error(reasons.slice(0, 4).join(" / "));
|
|
3576
|
+
}
|
|
3577
|
+
function renderHelp(message, { android, miniReady }) {
|
|
3578
|
+
return {
|
|
3579
|
+
renderGalat: message.replace(/\s+/g, " ").trim().slice(0, 240),
|
|
3580
|
+
renderSaran: android && !miniReady ? "hypeframe chromium" : "hypeframe doctor"
|
|
3581
|
+
};
|
|
2871
3582
|
}
|
|
2872
3583
|
function chromeLogHint(log) {
|
|
2873
3584
|
return log.split(`
|
|
@@ -2876,7 +3587,7 @@ function chromeLogHint(log) {
|
|
|
2876
3587
|
function candidates() {
|
|
2877
3588
|
const e = process.env;
|
|
2878
3589
|
if (process.platform === "win32") {
|
|
2879
|
-
return [e.PROGRAMFILES, e["PROGRAMFILES(X86)"], e.LOCALAPPDATA].filter((d) => !!d).flatMap((d) => [
|
|
3590
|
+
return [e.PROGRAMFILES, e["PROGRAMFILES(X86)"], e.LOCALAPPDATA].filter((d) => !!d).flatMap((d) => [path14.join(d, "Google", "Chrome", "Application", "chrome.exe"), path14.join(d, "Microsoft", "Edge", "Application", "msedge.exe")]);
|
|
2880
3591
|
}
|
|
2881
3592
|
if (process.platform === "darwin") {
|
|
2882
3593
|
return ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "/Applications/Chromium.app/Contents/MacOS/Chromium", "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"];
|
|
@@ -2886,15 +3597,15 @@ function candidates() {
|
|
|
2886
3597
|
function findChrome(android = isAndroid()) {
|
|
2887
3598
|
const forced = process.env.HYPEFRAME_CHROME;
|
|
2888
3599
|
if (forced)
|
|
2889
|
-
return
|
|
3600
|
+
return fs18.existsSync(forced) ? forced : null;
|
|
2890
3601
|
if (android && linuxChromiumReady())
|
|
2891
3602
|
return chromiumWrapper();
|
|
2892
|
-
return candidates().find((p) =>
|
|
3603
|
+
return candidates().find((p) => fs18.existsSync(p)) || null;
|
|
2893
3604
|
}
|
|
2894
3605
|
async function cachedChrome(cacheDir) {
|
|
2895
3606
|
try {
|
|
2896
|
-
const all = await getInstalledBrowsers({ cacheDir:
|
|
2897
|
-
return all.find((b) => b.browser === Browser.CHROME &&
|
|
3607
|
+
const all = await getInstalledBrowsers({ cacheDir: path14.join(cacheDir, "chrome") });
|
|
3608
|
+
return all.find((b) => b.browser === Browser.CHROME && fs18.existsSync(b.executablePath))?.executablePath ?? null;
|
|
2898
3609
|
} catch {
|
|
2899
3610
|
return null;
|
|
2900
3611
|
}
|
|
@@ -2913,7 +3624,7 @@ async function prepareChrome(cacheDir, progress = () => {
|
|
|
2913
3624
|
const platform = detectBrowserPlatform();
|
|
2914
3625
|
if (!platform)
|
|
2915
3626
|
throw new Error("Sistem ini belum didukung untuk render (Chrome tidak tersedia).");
|
|
2916
|
-
const dir =
|
|
3627
|
+
const dir = path14.join(cacheDir, "chrome");
|
|
2917
3628
|
const buildId = await resolveBuildId(Browser.CHROME, platform, "stable");
|
|
2918
3629
|
progress(0, `Chrome ${buildId}`);
|
|
2919
3630
|
const r = await install({
|
|
@@ -2973,102 +3684,20 @@ async function checkOnce(chrome, gpu, platformArgs, pipe = false) {
|
|
|
2973
3684
|
return;
|
|
2974
3685
|
});
|
|
2975
3686
|
srv.close();
|
|
2976
|
-
}
|
|
2977
|
-
}
|
|
2978
|
-
|
|
2979
|
-
// src/render/
|
|
2980
|
-
import
|
|
2981
|
-
import
|
|
2982
|
-
import
|
|
2983
|
-
import
|
|
2984
|
-
import
|
|
2985
|
-
import { Readable } from "node:stream";
|
|
2986
|
-
import zlib from "node:zlib";
|
|
2987
|
-
var FFMPEG_RELEASE = "b6.0";
|
|
2988
|
-
var BASE = `https://github.com/eugeneware/ffmpeg-static/releases/download/${FFMPEG_RELEASE}/`;
|
|
2989
|
-
var FFMPEG_PINNED = {
|
|
2990
|
-
"win32-x64": { sha256: "450d66226c79405c724e821f291cab0911e934bfa9fa2231adcab587f3e07b50", size: 28894894 },
|
|
2991
|
-
"linux-x64": { sha256: "17c1ae10b52ac499180679fe6ba77e17642390c4eedb0f1e3b0ac045da55128f", size: 28928723 },
|
|
2992
|
-
"linux-arm64": { sha256: "2b708b2d15041d2a192c1db24c7a8a1d24f645a8242dce1c744ff2392b86ada1", size: 25131803 },
|
|
2993
|
-
"darwin-x64": { sha256: "a12354fce7eb62361473bbe10d53a1893695babd35869ec8e92e5dfea8d0440b", size: 25067704 },
|
|
2994
|
-
"darwin-arm64": { sha256: "6be74d6f449889c2e87a75873894f8520cad56c08ac76f2a628d85b0519daaca", size: 19253088 }
|
|
2995
|
-
};
|
|
2996
|
-
var exe = process.platform === "win32" ? "ffmpeg.exe" : "ffmpeg";
|
|
2997
|
-
var cached2 = (cacheDir) => path12.join(cacheDir, "ffmpeg", FFMPEG_RELEASE, exe);
|
|
2998
|
-
var thisPlatform = () => `${process.platform}-${process.arch}`;
|
|
2999
|
-
async function findFfmpeg(cacheDir, key = thisPlatform()) {
|
|
3000
|
-
const forced = process.env.HYPEFRAME_FFMPEG;
|
|
3001
|
-
if (forced)
|
|
3002
|
-
return fs16.existsSync(forced) ? forced : null;
|
|
3003
|
-
if (!FFMPEG_PINNED[key])
|
|
3004
|
-
return onPath("ffmpeg");
|
|
3005
|
-
try {
|
|
3006
|
-
const mod = await import("ffmpeg-static");
|
|
3007
|
-
const p = typeof mod.default === "string" ? mod.default : null;
|
|
3008
|
-
if (p && fs16.existsSync(p))
|
|
3009
|
-
return p;
|
|
3010
|
-
} catch {}
|
|
3011
|
-
const c = cached2(cacheDir);
|
|
3012
|
-
return fs16.existsSync(c) ? c : null;
|
|
3013
|
-
}
|
|
3014
|
-
async function downloadVerified(url, sha256, dest, progress = () => {
|
|
3015
|
-
return;
|
|
3016
|
-
}, gunzip = false) {
|
|
3017
|
-
const r = await fetch(url, { signal: AbortSignal.timeout(900000) });
|
|
3018
|
-
if (!r.ok || !r.body)
|
|
3019
|
-
throw new Error(`download ${r.status}`);
|
|
3020
|
-
const total = Number(r.headers.get("content-length")) || 0;
|
|
3021
|
-
await fsp.mkdir(path12.dirname(dest), { recursive: true });
|
|
3022
|
-
const tmp = `${dest}.download`;
|
|
3023
|
-
const hash = crypto5.createHash("sha256");
|
|
3024
|
-
let got = 0;
|
|
3025
|
-
let last = -10;
|
|
3026
|
-
const body = Readable.fromWeb(r.body).on("data", (c) => {
|
|
3027
|
-
hash.update(c);
|
|
3028
|
-
got += c.length;
|
|
3029
|
-
const pct = total ? Math.floor(got / total * 100) : 0;
|
|
3030
|
-
if (pct - last >= 10)
|
|
3031
|
-
last = pct, progress(pct);
|
|
3032
|
-
});
|
|
3033
|
-
await pipeline(body, fs16.createWriteStream(tmp));
|
|
3034
|
-
if (hash.digest("hex") !== sha256) {
|
|
3035
|
-
await fsp.rm(tmp, { force: true });
|
|
3036
|
-
throw new Error("ffmpeg: sidik unduhan tidak cocok, berkas ditolak.");
|
|
3037
|
-
}
|
|
3038
|
-
if (gunzip) {
|
|
3039
|
-
await pipeline(fs16.createReadStream(tmp), zlib.createGunzip(), fs16.createWriteStream(`${tmp}.raw`));
|
|
3040
|
-
await fsp.rm(tmp, { force: true });
|
|
3041
|
-
await fsp.rename(`${tmp}.raw`, dest);
|
|
3042
|
-
} else
|
|
3043
|
-
await fsp.rename(tmp, dest);
|
|
3044
|
-
if (process.platform !== "win32")
|
|
3045
|
-
await fsp.chmod(dest, 493);
|
|
3046
|
-
}
|
|
3047
|
-
async function prepareFfmpeg(cacheDir, progress = () => {
|
|
3048
|
-
return;
|
|
3049
|
-
}, key = thisPlatform()) {
|
|
3050
|
-
const found = await findFfmpeg(cacheDir, key);
|
|
3051
|
-
if (found)
|
|
3052
|
-
return found;
|
|
3053
|
-
const pin = FFMPEG_PINNED[key];
|
|
3054
|
-
if (!pin)
|
|
3055
|
-
throw new Error(key.startsWith("android") ? "ffmpeg belum terpasang. Di Termux jalankan: pkg install ffmpeg" : `ffmpeg tidak tersedia untuk ${key}`);
|
|
3056
|
-
progress(0);
|
|
3057
|
-
await downloadVerified(`${BASE}ffmpeg-${key}.gz`, pin.sha256, cached2(cacheDir), progress, true);
|
|
3058
|
-
return cached2(cacheDir);
|
|
3059
|
-
}
|
|
3060
|
-
|
|
3061
|
-
// src/render/job.ts
|
|
3062
|
-
import { spawn as spawn3 } from "node:child_process";
|
|
3063
|
-
import crypto6 from "node:crypto";
|
|
3064
|
-
import fs17 from "node:fs";
|
|
3065
|
-
import fsp2 from "node:fs/promises";
|
|
3066
|
-
import path13 from "node:path";
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
|
|
3690
|
+
// packages/hypeframe/src/render/job.ts
|
|
3691
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
3692
|
+
import crypto7 from "node:crypto";
|
|
3693
|
+
import fs19 from "node:fs";
|
|
3694
|
+
import fsp4 from "node:fs/promises";
|
|
3695
|
+
import path15 from "node:path";
|
|
3067
3696
|
import puppeteer2 from "puppeteer-core";
|
|
3068
3697
|
var LIMIT_SECONDS = 1800;
|
|
3069
3698
|
function run(cmd, args, limitSeconds = 600) {
|
|
3070
3699
|
return new Promise((ok, fail) => {
|
|
3071
|
-
const p =
|
|
3700
|
+
const p = spawn4(cmd, args, { stdio: ["ignore", "ignore", "pipe"] });
|
|
3072
3701
|
let err = "";
|
|
3073
3702
|
p.stderr.on("data", (d) => err = (err + d).slice(-2000));
|
|
3074
3703
|
const timer = setTimeout(() => p.kill("SIGKILL"), limitSeconds * 1000);
|
|
@@ -3080,7 +3709,7 @@ function run(cmd, args, limitSeconds = 600) {
|
|
|
3080
3709
|
function saveBody(req, to, max) {
|
|
3081
3710
|
return new Promise((ok, fail) => {
|
|
3082
3711
|
let n = 0;
|
|
3083
|
-
const out =
|
|
3712
|
+
const out = fs19.createWriteStream(to);
|
|
3084
3713
|
req.on("data", (d) => {
|
|
3085
3714
|
n += d.length;
|
|
3086
3715
|
if (n > max)
|
|
@@ -3111,7 +3740,7 @@ function createJobRunner(o) {
|
|
|
3111
3740
|
const renderer = async (task, { progress, signal }) => {
|
|
3112
3741
|
if (task.kind === "klip" && task.transparent && !transparent)
|
|
3113
3742
|
throw new Error(EngineError.NoTransparent);
|
|
3114
|
-
const key =
|
|
3743
|
+
const key = crypto7.randomBytes(16).toString("hex");
|
|
3115
3744
|
let finish;
|
|
3116
3745
|
const finished = new Promise((ok) => finish = ok);
|
|
3117
3746
|
running.set(task.job, { key, task, progress, finish });
|
|
@@ -3122,9 +3751,9 @@ function createJobRunner(o) {
|
|
|
3122
3751
|
let browser;
|
|
3123
3752
|
try {
|
|
3124
3753
|
progress(0, "Menyiapkan");
|
|
3125
|
-
const profile =
|
|
3126
|
-
await
|
|
3127
|
-
await
|
|
3754
|
+
const profile = path15.join(task.dir, "profil");
|
|
3755
|
+
await fsp4.mkdir(path15.join(profile, "Default"), { recursive: true });
|
|
3756
|
+
await fsp4.writeFile(path15.join(profile, "Default", "Preferences"), JSON.stringify({ webkit: { webprefs: { fonts: { standard: { Zyyy: "Roboto" }, sansserif: { Zyyy: "Roboto" }, serif: { Zyyy: "Noto Serif" } } } } }));
|
|
3128
3757
|
browser = await puppeteer2.launch({
|
|
3129
3758
|
executablePath: chrome,
|
|
3130
3759
|
headless: true,
|
|
@@ -3156,11 +3785,11 @@ function createJobRunner(o) {
|
|
|
3156
3785
|
if (result.error)
|
|
3157
3786
|
throw new Error(result.error);
|
|
3158
3787
|
progress(99, clip ? "Menyelesaikan klip" : "Menyelesaikan video");
|
|
3159
|
-
const raw =
|
|
3788
|
+
const raw = path15.join(task.dir, "mentah.mp4");
|
|
3160
3789
|
const webm = clip && task.transparent;
|
|
3161
|
-
const file =
|
|
3790
|
+
const file = path15.join(task.dir, webm ? "hasil.webm" : "hasil.mp4");
|
|
3162
3791
|
if (clip)
|
|
3163
|
-
await
|
|
3792
|
+
await fsp4.rename(raw, file);
|
|
3164
3793
|
else
|
|
3165
3794
|
await run(ffmpeg, ["-y", "-v", "error", "-i", raw, "-map", "0", "-c:v", "copy", ...result.audio === "opus" ? ["-c:a", "aac", "-b:a", "192k"] : ["-c:a", "copy"], "-movflags", "+faststart", file]);
|
|
3166
3795
|
return { file, type: webm ? "video/webm" : "video/mp4" };
|
|
@@ -3185,11 +3814,11 @@ function createJobRunner(o) {
|
|
|
3185
3814
|
return res.writeHead(403), res.end(), true;
|
|
3186
3815
|
const pkg = r.task.packageDir;
|
|
3187
3816
|
if (m[2] === "proyek.json" || m[2] === "klip.json" || m[3]) {
|
|
3188
|
-
const f = m[3] ?
|
|
3189
|
-
if (!
|
|
3817
|
+
const f = m[3] ? path15.join(pkg, "aset", m[3]) : path15.join(pkg, m[2]);
|
|
3818
|
+
if (!fs19.existsSync(f))
|
|
3190
3819
|
return res.writeHead(404), res.end(), true;
|
|
3191
|
-
res.writeHead(200, { "content-type": m[3] ? "application/octet-stream" : "application/json", "content-length": (await
|
|
3192
|
-
|
|
3820
|
+
res.writeHead(200, { "content-type": m[3] ? "application/octet-stream" : "application/json", "content-length": (await fsp4.stat(f)).size });
|
|
3821
|
+
fs19.createReadStream(f).pipe(res);
|
|
3193
3822
|
return true;
|
|
3194
3823
|
}
|
|
3195
3824
|
if (m[2] === "kemajuan") {
|
|
@@ -3206,7 +3835,7 @@ function createJobRunner(o) {
|
|
|
3206
3835
|
r.finish({ error: String(b.pesan || "Render gagal.").slice(0, 300) });
|
|
3207
3836
|
return res.writeHead(204), res.end(), true;
|
|
3208
3837
|
}
|
|
3209
|
-
await saveBody(req,
|
|
3838
|
+
await saveBody(req, path15.join(r.task.dir, "mentah.mp4"), 8 * 1073741824);
|
|
3210
3839
|
r.finish({ audio: String(req.headers["x-kodek-audio"] || "") });
|
|
3211
3840
|
res.writeHead(204);
|
|
3212
3841
|
res.end();
|
|
@@ -3215,10 +3844,10 @@ function createJobRunner(o) {
|
|
|
3215
3844
|
return { renderer, route, setPort: (p) => void (port = p) };
|
|
3216
3845
|
}
|
|
3217
3846
|
|
|
3218
|
-
// src/render/page.ts
|
|
3219
|
-
import
|
|
3220
|
-
import
|
|
3221
|
-
import
|
|
3847
|
+
// packages/hypeframe/src/render/page.ts
|
|
3848
|
+
import fs20 from "node:fs";
|
|
3849
|
+
import fsp5 from "node:fs/promises";
|
|
3850
|
+
import path16 from "node:path";
|
|
3222
3851
|
var TYPES = {
|
|
3223
3852
|
".html": "text/html; charset=utf-8",
|
|
3224
3853
|
".js": "text/javascript",
|
|
@@ -3239,13 +3868,13 @@ var SAFE_PATH = /^[\w@.+-]+(?:\/[\w@.+-]+)*$/;
|
|
|
3239
3868
|
var VERSION_ID = /^[0-9a-f]{12}$/;
|
|
3240
3869
|
function createPage({ web, cacheDir }) {
|
|
3241
3870
|
const base = `${String(web || "").replace(/\/+$/, "")}/render/`;
|
|
3242
|
-
const root =
|
|
3871
|
+
const root = path16.join(cacheDir, "halaman");
|
|
3243
3872
|
let version = null;
|
|
3244
|
-
const versionDir = () =>
|
|
3873
|
+
const versionDir = () => path16.join(root, version);
|
|
3245
3874
|
const pending = new Map;
|
|
3246
3875
|
async function download(rel) {
|
|
3247
|
-
const target =
|
|
3248
|
-
if (
|
|
3876
|
+
const target = path16.join(versionDir(), rel);
|
|
3877
|
+
if (fs20.existsSync(target))
|
|
3249
3878
|
return target;
|
|
3250
3879
|
if (!pending.has(rel)) {
|
|
3251
3880
|
pending.set(rel, (async () => {
|
|
@@ -3253,9 +3882,9 @@ function createPage({ web, cacheDir }) {
|
|
|
3253
3882
|
if (!r.ok)
|
|
3254
3883
|
throw Object.assign(new Error(`halaman ${rel}: ${r.status}`), { status: r.status });
|
|
3255
3884
|
const body = Buffer.from(await r.arrayBuffer());
|
|
3256
|
-
await
|
|
3257
|
-
await
|
|
3258
|
-
await
|
|
3885
|
+
await fsp5.mkdir(path16.dirname(target), { recursive: true });
|
|
3886
|
+
await fsp5.writeFile(`${target}.tmp`, body);
|
|
3887
|
+
await fsp5.rename(`${target}.tmp`, target);
|
|
3259
3888
|
return target;
|
|
3260
3889
|
})().finally(() => pending.delete(rel)));
|
|
3261
3890
|
}
|
|
@@ -3276,11 +3905,11 @@ function createPage({ web, cacheDir }) {
|
|
|
3276
3905
|
if (typeof f === "string" && SAFE_PATH.test(f))
|
|
3277
3906
|
await download(f);
|
|
3278
3907
|
if (old !== version) {
|
|
3279
|
-
const all = (await
|
|
3280
|
-
const dated = await Promise.all(all.map(async (d) => ({ d, t: (await
|
|
3908
|
+
const all = (await fsp5.readdir(root).catch(() => [])).filter((d) => VERSION_ID.test(d));
|
|
3909
|
+
const dated = await Promise.all(all.map(async (d) => ({ d, t: (await fsp5.stat(path16.join(root, d))).mtimeMs })));
|
|
3281
3910
|
for (const { d } of dated.sort((a, b) => b.t - a.t).slice(2))
|
|
3282
3911
|
if (d !== version)
|
|
3283
|
-
await
|
|
3912
|
+
await fsp5.rm(path16.join(root, d), { recursive: true, force: true });
|
|
3284
3913
|
}
|
|
3285
3914
|
return { version };
|
|
3286
3915
|
}
|
|
@@ -3297,8 +3926,8 @@ function createPage({ web, cacheDir }) {
|
|
|
3297
3926
|
return res.writeHead(404), res.end(), true;
|
|
3298
3927
|
try {
|
|
3299
3928
|
const f = await download(rel);
|
|
3300
|
-
res.writeHead(200, { "content-type": TYPES[
|
|
3301
|
-
|
|
3929
|
+
res.writeHead(200, { "content-type": TYPES[path16.extname(f)] || "application/octet-stream", "cache-control": "no-store" });
|
|
3930
|
+
fs20.createReadStream(f).pipe(res);
|
|
3302
3931
|
} catch (e) {
|
|
3303
3932
|
res.writeHead(e.status === 404 ? 404 : 502);
|
|
3304
3933
|
res.end();
|
|
@@ -3314,9 +3943,9 @@ function createPage({ web, cacheDir }) {
|
|
|
3314
3943
|
};
|
|
3315
3944
|
}
|
|
3316
3945
|
|
|
3317
|
-
// src/render/relay.ts
|
|
3318
|
-
import
|
|
3319
|
-
var sha = (b) =>
|
|
3946
|
+
// packages/hypeframe/src/render/relay.ts
|
|
3947
|
+
import crypto8 from "node:crypto";
|
|
3948
|
+
var sha = (b) => crypto8.createHash("sha256").update(b).digest("hex");
|
|
3320
3949
|
var sleep2 = (ms) => new Promise((ok) => setTimeout(ok, ms));
|
|
3321
3950
|
async function runRelayJob(j, o) {
|
|
3322
3951
|
const step = o.onStep ?? (() => {
|
|
@@ -3385,7 +4014,7 @@ async function runRelayJob(j, o) {
|
|
|
3385
4014
|
return fail(`The finished video could not be read (${r.status}).`);
|
|
3386
4015
|
const type = r.headers.get("content-type") === "video/webm" ? "video/webm" : "video/mp4";
|
|
3387
4016
|
const size = Math.max(1, o.resultPartMb ?? 32) * 1048576;
|
|
3388
|
-
const total =
|
|
4017
|
+
const total = crypto8.createHash("sha256");
|
|
3389
4018
|
let sent = 0;
|
|
3390
4019
|
let n = 0;
|
|
3391
4020
|
let buf = [];
|
|
@@ -3431,20 +4060,20 @@ async function runRelayJob(j, o) {
|
|
|
3431
4060
|
}
|
|
3432
4061
|
}
|
|
3433
4062
|
|
|
3434
|
-
// src/render/service.ts
|
|
3435
|
-
import
|
|
3436
|
-
import
|
|
3437
|
-
import
|
|
4063
|
+
// packages/hypeframe/src/render/service.ts
|
|
4064
|
+
import crypto9 from "node:crypto";
|
|
4065
|
+
import fs21 from "node:fs";
|
|
4066
|
+
import fsp6 from "node:fs/promises";
|
|
3438
4067
|
import http2 from "node:http";
|
|
3439
|
-
import
|
|
3440
|
-
import
|
|
4068
|
+
import path17 from "node:path";
|
|
4069
|
+
import yauzl2 from "yauzl";
|
|
3441
4070
|
var ACTIVE = new Set(["unggah", "antre", "jalan"]);
|
|
3442
|
-
var safeEqual = (a, b) => a.length === b.length &&
|
|
4071
|
+
var safeEqual = (a, b) => a.length === b.length && crypto9.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
3443
4072
|
var BAD_ENTRY = /relative path|absolute path|invalid characters/i;
|
|
3444
4073
|
function listZip(f) {
|
|
3445
4074
|
return new Promise((ok, fail) => {
|
|
3446
4075
|
const refuse = (e) => fail(BAD_ENTRY.test(e.message) ? new Error(EngineError.BadPackage) : e);
|
|
3447
|
-
|
|
4076
|
+
yauzl2.open(f, { lazyEntries: true }, (e, zip) => {
|
|
3448
4077
|
if (e || !zip)
|
|
3449
4078
|
return refuse(e ?? new Error("zip"));
|
|
3450
4079
|
const entries = [];
|
|
@@ -3457,20 +4086,20 @@ function listZip(f) {
|
|
|
3457
4086
|
}
|
|
3458
4087
|
function extractZip(f, to) {
|
|
3459
4088
|
return new Promise((ok, fail) => {
|
|
3460
|
-
|
|
4089
|
+
yauzl2.open(f, { lazyEntries: true }, (e, zip) => {
|
|
3461
4090
|
if (e || !zip)
|
|
3462
4091
|
return fail(e ?? new Error("zip"));
|
|
3463
4092
|
zip.on("entry", (en) => {
|
|
3464
4093
|
if (en.fileName.endsWith("/"))
|
|
3465
4094
|
return zip.readEntry();
|
|
3466
|
-
const target =
|
|
3467
|
-
if (!target.startsWith(to +
|
|
4095
|
+
const target = path17.join(to, en.fileName);
|
|
4096
|
+
if (!target.startsWith(to + path17.sep))
|
|
3468
4097
|
return fail(new Error(EngineError.BadPackage));
|
|
3469
|
-
|
|
4098
|
+
fs21.mkdirSync(path17.dirname(target), { recursive: true });
|
|
3470
4099
|
zip.openReadStream(en, (e2, s) => {
|
|
3471
4100
|
if (e2 || !s)
|
|
3472
4101
|
return fail(e2 ?? new Error("zip"));
|
|
3473
|
-
const out =
|
|
4102
|
+
const out = fs21.createWriteStream(target);
|
|
3474
4103
|
s.pipe(out);
|
|
3475
4104
|
out.on("finish", () => zip.readEntry());
|
|
3476
4105
|
out.on("error", fail);
|
|
@@ -3485,13 +4114,13 @@ function extractZip(f, to) {
|
|
|
3485
4114
|
function saveBody2(req, to, max) {
|
|
3486
4115
|
return new Promise((ok, fail) => {
|
|
3487
4116
|
let n = 0;
|
|
3488
|
-
const out =
|
|
4117
|
+
const out = fs21.createWriteStream(to);
|
|
3489
4118
|
req.on("data", (d) => {
|
|
3490
4119
|
n += d.length;
|
|
3491
4120
|
if (n > max) {
|
|
3492
4121
|
req.destroy();
|
|
3493
4122
|
out.destroy();
|
|
3494
|
-
|
|
4123
|
+
fs21.rm(to, { force: true }, () => fail(new Error("terlalu besar")));
|
|
3495
4124
|
}
|
|
3496
4125
|
});
|
|
3497
4126
|
req.pipe(out);
|
|
@@ -3519,9 +4148,9 @@ async function createRenderService(o) {
|
|
|
3519
4148
|
return;
|
|
3520
4149
|
} } = o;
|
|
3521
4150
|
const origins = new Set([].concat(o.origin || []));
|
|
3522
|
-
const sign = (kind, body) =>
|
|
3523
|
-
const dir = (job) =>
|
|
3524
|
-
await
|
|
4151
|
+
const sign = (kind, body) => crypto9.createHmac("sha256", key).update(`${kind}.${body}`).digest("base64url");
|
|
4152
|
+
const dir = (job) => path17.join(folder, job);
|
|
4153
|
+
await fsp6.mkdir(folder, { recursive: true });
|
|
3525
4154
|
function readTicket(req) {
|
|
3526
4155
|
const tk = String(req.headers.authorization || "").replace(/^Bearer\s+/i, "");
|
|
3527
4156
|
const [v, body, sig] = tk.split(".");
|
|
@@ -3542,7 +4171,7 @@ async function createRenderService(o) {
|
|
|
3542
4171
|
const jobs = new Map;
|
|
3543
4172
|
const queue = [];
|
|
3544
4173
|
let current = null;
|
|
3545
|
-
const persist = (t) =>
|
|
4174
|
+
const persist = (t) => fsp6.writeFile(path17.join(dir(t.job), "status.json"), JSON.stringify(t)).catch(() => {
|
|
3546
4175
|
return;
|
|
3547
4176
|
});
|
|
3548
4177
|
const update = (t, patch) => (Object.assign(t, patch, { diperbarui: Date.now() }), void persist(t));
|
|
@@ -3561,19 +4190,19 @@ async function createRenderService(o) {
|
|
|
3561
4190
|
});
|
|
3562
4191
|
async function clearFiles(t, all = false) {
|
|
3563
4192
|
for (const n of all ? ["."] : ["paket", "paket.zip", "profil", "mentah.mp4", "mentah.webm"])
|
|
3564
|
-
await
|
|
4193
|
+
await fsp6.rm(path17.join(dir(t.job), n), { recursive: true, force: true }).catch(() => {
|
|
3565
4194
|
return;
|
|
3566
4195
|
});
|
|
3567
4196
|
if (!all) {
|
|
3568
|
-
for (const f of await
|
|
4197
|
+
for (const f of await fsp6.readdir(dir(t.job)).catch(() => []))
|
|
3569
4198
|
if (/^p\d+$/.test(f))
|
|
3570
|
-
await
|
|
4199
|
+
await fsp6.rm(path17.join(dir(t.job), f), { force: true });
|
|
3571
4200
|
}
|
|
3572
4201
|
}
|
|
3573
4202
|
async function openPackage(t) {
|
|
3574
4203
|
const d = dir(t.job);
|
|
3575
4204
|
const main = t.tiket.jenis === "klip" ? "klip.json" : "proyek.json";
|
|
3576
|
-
const entries = await listZip(
|
|
4205
|
+
const entries = await listZip(path17.join(d, "paket.zip"));
|
|
3577
4206
|
const names = entries.map((x) => x.name).filter((n) => !n.endsWith("/"));
|
|
3578
4207
|
if (names.some((n) => n.startsWith("/") || n.includes("..") || n.includes("\\") || n !== main && !/^aset\/[\w-]+$/.test(n)))
|
|
3579
4208
|
throw new Error(EngineError.BadPackage);
|
|
@@ -3581,10 +4210,10 @@ async function createRenderService(o) {
|
|
|
3581
4210
|
throw new Error(`Paket tidak berisi ${main}.`);
|
|
3582
4211
|
if (entries.reduce((a, x) => a + x.size, 0) > maxUnzippedMb * 1048576)
|
|
3583
4212
|
throw new Error("Isi paket terlalu besar.");
|
|
3584
|
-
await extractZip(
|
|
3585
|
-
await
|
|
3586
|
-
const j = JSON.parse(await
|
|
3587
|
-
const has = (id) => /^[\w-]+$/.test(id) &&
|
|
4213
|
+
await extractZip(path17.join(d, "paket.zip"), path17.join(d, "paket"));
|
|
4214
|
+
await fsp6.rm(path17.join(d, "paket.zip"), { force: true });
|
|
4215
|
+
const j = JSON.parse(await fsp6.readFile(path17.join(d, "paket", main), "utf8"));
|
|
4216
|
+
const has = (id) => /^[\w-]+$/.test(id) && fs21.existsSync(path17.join(d, "paket", "aset", id));
|
|
3588
4217
|
if (main === "klip.json") {
|
|
3589
4218
|
const k = j.klip || {};
|
|
3590
4219
|
const seconds = Number(k.durationInFrames) / Number(k.fps);
|
|
@@ -3632,7 +4261,7 @@ async function createRenderService(o) {
|
|
|
3632
4261
|
job: t.job,
|
|
3633
4262
|
kind: t.tiket.jenis,
|
|
3634
4263
|
dir: dir(t.job),
|
|
3635
|
-
packageDir:
|
|
4264
|
+
packageDir: path17.join(dir(t.job), "paket"),
|
|
3636
4265
|
transparent: !!t.transparan,
|
|
3637
4266
|
persen: t.persen,
|
|
3638
4267
|
width: t.tiket.w,
|
|
@@ -3649,10 +4278,10 @@ async function createRenderService(o) {
|
|
|
3649
4278
|
const h = await renderer(task, { progress, signal: cancel.signal });
|
|
3650
4279
|
if (cancel.signal.aborted)
|
|
3651
4280
|
throw new Error("Dibatalkan.");
|
|
3652
|
-
const size = (await
|
|
4281
|
+
const size = (await fsp6.stat(h.file)).size;
|
|
3653
4282
|
if (size < 200)
|
|
3654
4283
|
throw new Error(EngineError.EmptyResult);
|
|
3655
|
-
update(t, { status: "selesai", persen: 100, tahap: "", selesaiPada: Date.now(), hasilUkuran: size, hasilBerkas:
|
|
4284
|
+
update(t, { status: "selesai", persen: 100, tahap: "", selesaiPada: Date.now(), hasilUkuran: size, hasilBerkas: path17.basename(h.file), hasilJenis: h.type });
|
|
3656
4285
|
onJob("done", t);
|
|
3657
4286
|
} catch (e) {
|
|
3658
4287
|
if (t.status !== "batal") {
|
|
@@ -3681,7 +4310,7 @@ async function createRenderService(o) {
|
|
|
3681
4310
|
}
|
|
3682
4311
|
const json = (req, res, code, body) => (res.writeHead(code, { ...cors(req), "content-type": "application/json", "cache-control": "no-store" }), res.end(JSON.stringify(body)));
|
|
3683
4312
|
async function sendFile(req, res, f, type, name) {
|
|
3684
|
-
const st = await
|
|
4313
|
+
const st = await fsp6.stat(f);
|
|
3685
4314
|
const range = /^bytes=(\d+)-(\d*)$/.exec(String(req.headers.range || ""));
|
|
3686
4315
|
const h = { ...cors(req), "content-type": type, "accept-ranges": "bytes", "cache-control": "no-store", "content-disposition": `attachment; filename="${name}"` };
|
|
3687
4316
|
if (range) {
|
|
@@ -3690,10 +4319,10 @@ async function createRenderService(o) {
|
|
|
3690
4319
|
if (a > z)
|
|
3691
4320
|
return res.writeHead(416, { ...h, "content-range": `bytes */${st.size}` }), res.end();
|
|
3692
4321
|
res.writeHead(206, { ...h, "content-length": z - a + 1, "content-range": `bytes ${a}-${z}/${st.size}` });
|
|
3693
|
-
return void
|
|
4322
|
+
return void fs21.createReadStream(f, { start: a, end: z }).pipe(res);
|
|
3694
4323
|
}
|
|
3695
4324
|
res.writeHead(200, { ...h, "content-length": st.size });
|
|
3696
|
-
|
|
4325
|
+
fs21.createReadStream(f).pipe(res);
|
|
3697
4326
|
}
|
|
3698
4327
|
const ROUTE = /^\/tugas(?:\/(r_[a-f0-9]{16})(\/potongan\/(\d{1,4})|\/mulai|\/hasil)?)?$/;
|
|
3699
4328
|
const server = http2.createServer(async (req, res) => {
|
|
@@ -3720,7 +4349,7 @@ async function createRenderService(o) {
|
|
|
3720
4349
|
return json(req, res, 200, summary(t));
|
|
3721
4350
|
if (queue.length >= maxQueue)
|
|
3722
4351
|
return json(req, res, 503, { galat: EngineError.QueueFull });
|
|
3723
|
-
await
|
|
4352
|
+
await fsp6.mkdir(dir(job), { recursive: true });
|
|
3724
4353
|
t = { job, tiket: ticket, status: "unggah", dibuat: Date.now(), diperbarui: Date.now(), terunggah: 0 };
|
|
3725
4354
|
jobs.set(job, t);
|
|
3726
4355
|
persist(t);
|
|
@@ -3732,15 +4361,15 @@ async function createRenderService(o) {
|
|
|
3732
4361
|
if (t.status !== "unggah")
|
|
3733
4362
|
return json(req, res, 409, { galat: "Unggahan sudah ditutup." });
|
|
3734
4363
|
const n = Number(m[3]);
|
|
3735
|
-
const f =
|
|
3736
|
-
const before =
|
|
4364
|
+
const f = path17.join(dir(job), `p${n}`);
|
|
4365
|
+
const before = fs21.existsSync(f) ? (await fsp6.stat(f)).size : 0;
|
|
3737
4366
|
const room = Number(ticket.maksMb) * 1048576 - (t.terunggah - before);
|
|
3738
4367
|
const size = await saveBody2(req, f, Math.min(partMb * 1048576 + 1024, room));
|
|
3739
4368
|
const expected = String(req.headers["x-sha256"] || "").toLowerCase();
|
|
3740
4369
|
if (expected) {
|
|
3741
|
-
const digest =
|
|
4370
|
+
const digest = crypto9.createHash("sha256").update(await fsp6.readFile(f)).digest("hex");
|
|
3742
4371
|
if (digest !== expected) {
|
|
3743
|
-
await
|
|
4372
|
+
await fsp6.rm(f, { force: true });
|
|
3744
4373
|
update(t, { terunggah: t.terunggah - before });
|
|
3745
4374
|
return json(req, res, 400, { galat: "Potongan rusak di jalan. Kirim ulang." });
|
|
3746
4375
|
}
|
|
@@ -3755,24 +4384,24 @@ async function createRenderService(o) {
|
|
|
3755
4384
|
const count = Number(b.jumlah);
|
|
3756
4385
|
if (!(count > 0 && count < 1e4))
|
|
3757
4386
|
return json(req, res, 400, { galat: "Jumlah potongan tidak valid." });
|
|
3758
|
-
const zip =
|
|
3759
|
-
const out =
|
|
3760
|
-
const hash =
|
|
4387
|
+
const zip = path17.join(dir(job), "paket.zip");
|
|
4388
|
+
const out = fs21.createWriteStream(zip);
|
|
4389
|
+
const hash = crypto9.createHash("sha256");
|
|
3761
4390
|
let total = 0;
|
|
3762
4391
|
for (let i = 0;i < count; i++) {
|
|
3763
|
-
const f =
|
|
3764
|
-
if (!
|
|
4392
|
+
const f = path17.join(dir(job), `p${i}`);
|
|
4393
|
+
if (!fs21.existsSync(f))
|
|
3765
4394
|
return out.destroy(), json(req, res, 400, { galat: `Potongan ${i + 1} belum terunggah.` });
|
|
3766
|
-
const part = await
|
|
4395
|
+
const part = await fsp6.readFile(f);
|
|
3767
4396
|
hash.update(part);
|
|
3768
4397
|
total += part.length;
|
|
3769
4398
|
await new Promise((ok) => out.write(part) ? ok() : out.once("drain", ok));
|
|
3770
|
-
await
|
|
4399
|
+
await fsp6.rm(f, { force: true });
|
|
3771
4400
|
}
|
|
3772
4401
|
await new Promise((ok) => out.end(ok));
|
|
3773
4402
|
const digest = hash.digest("hex");
|
|
3774
4403
|
if (total !== Number(b.ukuran) || b.sha256 && digest !== String(b.sha256).toLowerCase()) {
|
|
3775
|
-
await
|
|
4404
|
+
await fsp6.rm(zip, { force: true });
|
|
3776
4405
|
update(t, { terunggah: 0 });
|
|
3777
4406
|
return json(req, res, 400, { galat: "Unggahan rusak di jalan. Coba render lagi." });
|
|
3778
4407
|
}
|
|
@@ -3791,8 +4420,8 @@ async function createRenderService(o) {
|
|
|
3791
4420
|
return json(req, res, 200, summary(t));
|
|
3792
4421
|
}
|
|
3793
4422
|
if (m[2] === "/hasil" && (req.method === "GET" || req.method === "HEAD")) {
|
|
3794
|
-
const f = t.hasilBerkas ?
|
|
3795
|
-
if (t.status !== "selesai" || !f || !
|
|
4423
|
+
const f = t.hasilBerkas ? path17.join(dir(job), t.hasilBerkas) : "";
|
|
4424
|
+
if (t.status !== "selesai" || !f || !fs21.existsSync(f))
|
|
3796
4425
|
return json(req, res, 409, { galat: "Video belum jadi." });
|
|
3797
4426
|
const webm = t.hasilJenis === "video/webm";
|
|
3798
4427
|
return sendFile(req, res, f, webm ? "video/webm" : "video/mp4", `hypeframe-${job}.${webm ? "webm" : "mp4"}`);
|
|
@@ -3819,16 +4448,16 @@ async function createRenderService(o) {
|
|
|
3819
4448
|
json(req, res, 500, { galat: EngineError.ServiceError });
|
|
3820
4449
|
}
|
|
3821
4450
|
});
|
|
3822
|
-
for (const job of await
|
|
4451
|
+
for (const job of await fsp6.readdir(folder).catch(() => [])) {
|
|
3823
4452
|
if (!JOB_ID.test(job))
|
|
3824
4453
|
continue;
|
|
3825
4454
|
try {
|
|
3826
|
-
const t = JSON.parse(await
|
|
4455
|
+
const t = JSON.parse(await fsp6.readFile(path17.join(dir(job), "status.json"), "utf8"));
|
|
3827
4456
|
if (t.status === "jalan" || t.status === "antre")
|
|
3828
4457
|
update(t, { status: "gagal", galat: EngineError.Restarted });
|
|
3829
4458
|
jobs.set(job, t);
|
|
3830
4459
|
} catch {
|
|
3831
|
-
await
|
|
4460
|
+
await fsp6.rm(dir(job), { recursive: true, force: true });
|
|
3832
4461
|
}
|
|
3833
4462
|
}
|
|
3834
4463
|
const sweep = setInterval(async () => {
|
|
@@ -3857,7 +4486,7 @@ async function createRenderService(o) {
|
|
|
3857
4486
|
};
|
|
3858
4487
|
}
|
|
3859
4488
|
|
|
3860
|
-
// src/ui/banner.ts
|
|
4489
|
+
// packages/hypeframe/src/ui/banner.ts
|
|
3861
4490
|
function banner() {
|
|
3862
4491
|
const mark = color.brand("◆");
|
|
3863
4492
|
return `
|
|
@@ -3866,7 +4495,7 @@ function banner() {
|
|
|
3866
4495
|
`;
|
|
3867
4496
|
}
|
|
3868
4497
|
|
|
3869
|
-
// src/util/format.ts
|
|
4498
|
+
// packages/hypeframe/src/util/format.ts
|
|
3870
4499
|
function bytes2(n) {
|
|
3871
4500
|
if (!(n > 0))
|
|
3872
4501
|
return "0 B";
|
|
@@ -3903,8 +4532,8 @@ function table(rows, indent = " ") {
|
|
|
3903
4532
|
`);
|
|
3904
4533
|
}
|
|
3905
4534
|
|
|
3906
|
-
// src/util/open.ts
|
|
3907
|
-
import { spawn as
|
|
4535
|
+
// packages/hypeframe/src/util/open.ts
|
|
4536
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
3908
4537
|
var PAIRING_LINK = new RegExp(`^https?://[A-Za-z0-9.-]+(:\\d+)?/sambung\\?kode=${PAIRING_CODE.source.slice(1, -1)}$`);
|
|
3909
4538
|
var WEB_ORIGIN = /^https?:\/\/[A-Za-z0-9.-]+(:\d+)?\/?$/;
|
|
3910
4539
|
function openCommand(target, platform, url) {
|
|
@@ -3918,7 +4547,7 @@ function openCommand(target, platform, url) {
|
|
|
3918
4547
|
}
|
|
3919
4548
|
function launch(target, url) {
|
|
3920
4549
|
const [cmd, args] = openCommand(target, isAndroid() ? "android" : process.platform, url);
|
|
3921
|
-
const p =
|
|
4550
|
+
const p = spawn5(cmd, args, { stdio: "ignore", detached: true });
|
|
3922
4551
|
p.on("error", () => {
|
|
3923
4552
|
return;
|
|
3924
4553
|
});
|
|
@@ -3940,7 +4569,7 @@ function openOnPhone(url) {
|
|
|
3940
4569
|
return true;
|
|
3941
4570
|
}
|
|
3942
4571
|
|
|
3943
|
-
// src/cli/commands/start.ts
|
|
4572
|
+
// packages/hypeframe/src/cli/commands/start.ts
|
|
3944
4573
|
var preview = (s) => {
|
|
3945
4574
|
const one = s.replace(/\s+/g, " ").trim();
|
|
3946
4575
|
return one.length > 80 ? `${one.slice(0, 79)}…` : one;
|
|
@@ -3974,6 +4603,10 @@ function logAgentEvent(e) {
|
|
|
3974
4603
|
return log.warn(t("agentLog.stopped", { agent: a, code: String(e.code) }));
|
|
3975
4604
|
case "account":
|
|
3976
4605
|
return log.info(t("agentLog.account", { agent: a }));
|
|
4606
|
+
case "terminal":
|
|
4607
|
+
return log.info(t("agentLog.terminal", { agent: a }));
|
|
4608
|
+
case "terminalClosed":
|
|
4609
|
+
return log.detail(t("agentLog.terminalClosed", { agent: e.agent }));
|
|
3977
4610
|
}
|
|
3978
4611
|
}
|
|
3979
4612
|
async function pairDevice(s, noBrowser = false) {
|
|
@@ -4022,7 +4655,7 @@ async function start(args, { fromMenu = false } = {}) {
|
|
|
4022
4655
|
let conn = null;
|
|
4023
4656
|
let servicePort = 0;
|
|
4024
4657
|
const agents = createAgentService({
|
|
4025
|
-
conn: { news: (k, b) => conn?.news(k, b), request: (ke, kind, body, ms) => conn?.request(ke, kind, body, ms) ?? Promise.resolve({ ok: false, error: "terputus" }) },
|
|
4658
|
+
conn: { news: (k, b) => conn?.news(k, b), request: (ke, kind, body, ms) => conn?.request(ke, kind, body, ms) ?? Promise.resolve({ ok: false, error: "terputus" }), tty: (ke, b) => conn?.tty(ke, b) },
|
|
4026
4659
|
port: () => servicePort,
|
|
4027
4660
|
bridge: bridgeLaunch(),
|
|
4028
4661
|
onToolError: (e) => log.warn(t(e === "tab" ? "agent.toolNoTab" : "agent.toolNoAnswer")),
|
|
@@ -4033,8 +4666,8 @@ async function start(args, { fromMenu = false } = {}) {
|
|
|
4033
4666
|
log.info(t("linux.openUrl", { url }));
|
|
4034
4667
|
openOnPhone(url);
|
|
4035
4668
|
});
|
|
4036
|
-
const capabilities = { render: false, chrome: null, transparan: false, agen: agents.capabilities() };
|
|
4037
|
-
const key =
|
|
4669
|
+
const capabilities = { render: false, chrome: null, transparan: false, agen: agents.capabilities(), terminal: ptySupported() };
|
|
4670
|
+
const key = crypto10.randomBytes(32).toString("base64url");
|
|
4038
4671
|
const cache = cacheDir();
|
|
4039
4672
|
const page = createPage({ web: s.web, cacheDir: cache });
|
|
4040
4673
|
let runner = null;
|
|
@@ -4098,6 +4731,7 @@ async function start(args, { fromMenu = false } = {}) {
|
|
|
4098
4731
|
});
|
|
4099
4732
|
const engineConn = new Connection({ gateway: s.gateway, token: account.token, info: { versi: VERSION, os: osName(), nama: s.name, kemampuan: capabilities, portLokal: service.port }, handler });
|
|
4100
4733
|
conn = engineConn;
|
|
4734
|
+
engineConn.on("tty", (m) => agents.tty(String(m.dari ?? ""), m));
|
|
4101
4735
|
setInterval(() => {
|
|
4102
4736
|
agents.checkAccounts();
|
|
4103
4737
|
const now = agents.capabilities();
|
|
@@ -4178,13 +4812,33 @@ async function start(args, { fromMenu = false } = {}) {
|
|
|
4178
4812
|
runner = createJobRunner({ chrome, ffmpeg, page, gpu: s.gpu, transparent: info.transparent, note: (m) => log.detail(m) });
|
|
4179
4813
|
runner.setPort(service.port);
|
|
4180
4814
|
Object.assign(capabilities, { render: true, chrome: info.version, transparan: info.transparent });
|
|
4815
|
+
delete capabilities.renderGalat;
|
|
4816
|
+
delete capabilities.renderSaran;
|
|
4181
4817
|
engineConn.setInfo({ kemampuan: capabilities });
|
|
4182
4818
|
engineConn.news("status", { kemampuan: capabilities });
|
|
4183
4819
|
log.ok(t("render.ready", { chrome: info.version, extra: info.transparent ? "" : t("render.noAlpha") }));
|
|
4184
4820
|
} catch (e) {
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4821
|
+
const message = e.message;
|
|
4822
|
+
renderNote = message.slice(0, 120);
|
|
4823
|
+
log.warn(t("render.notYet", { reason: message }));
|
|
4824
|
+
const help = renderHelp(message, { android: isAndroid(), miniReady: linuxChromiumReady() });
|
|
4825
|
+
Object.assign(capabilities, help);
|
|
4826
|
+
engineConn.setInfo({ kemampuan: capabilities });
|
|
4827
|
+
engineConn.news("status", { kemampuan: capabilities });
|
|
4828
|
+
if (help.renderSaran === "hypeframe chromium") {
|
|
4829
|
+
log.info(t("render.tryChromiumMini"));
|
|
4830
|
+
const watch = setInterval(() => {
|
|
4831
|
+
if (!linuxChromiumReady())
|
|
4832
|
+
return;
|
|
4833
|
+
clearInterval(watch);
|
|
4834
|
+
clearTimeout(later);
|
|
4835
|
+
prepareRender();
|
|
4836
|
+
}, 15000);
|
|
4837
|
+
watch.unref();
|
|
4838
|
+
const later = setTimeout(() => (clearInterval(watch), void prepareRender()), 10 * 60000);
|
|
4839
|
+
later.unref();
|
|
4840
|
+
} else
|
|
4841
|
+
setTimeout(prepareRender, 10 * 60000).unref();
|
|
4188
4842
|
}
|
|
4189
4843
|
}
|
|
4190
4844
|
prepareRender();
|
|
@@ -4205,7 +4859,7 @@ async function start(args, { fromMenu = false } = {}) {
|
|
|
4205
4859
|
});
|
|
4206
4860
|
}
|
|
4207
4861
|
|
|
4208
|
-
// src/cli/commands/account.ts
|
|
4862
|
+
// packages/hypeframe/src/cli/commands/account.ts
|
|
4209
4863
|
async function login(args) {
|
|
4210
4864
|
const s = resolveSettings(args.flags);
|
|
4211
4865
|
const a = readAccount();
|
|
@@ -4221,25 +4875,25 @@ function logout() {
|
|
|
4221
4875
|
log.ok(t("logout.done"));
|
|
4222
4876
|
}
|
|
4223
4877
|
|
|
4224
|
-
// src/cli/commands/autostart.ts
|
|
4225
|
-
import { spawnSync as
|
|
4226
|
-
import
|
|
4227
|
-
import
|
|
4228
|
-
import
|
|
4878
|
+
// packages/hypeframe/src/cli/commands/autostart.ts
|
|
4879
|
+
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
4880
|
+
import fs22 from "node:fs";
|
|
4881
|
+
import os4 from "node:os";
|
|
4882
|
+
import path18 from "node:path";
|
|
4229
4883
|
function entryFile() {
|
|
4230
|
-
const home =
|
|
4884
|
+
const home = os4.homedir();
|
|
4231
4885
|
if (process.platform === "win32")
|
|
4232
|
-
return
|
|
4886
|
+
return path18.join(process.env.APPDATA || path18.join(home, "AppData", "Roaming"), "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "HypeFrame.cmd");
|
|
4233
4887
|
if (process.platform === "darwin")
|
|
4234
|
-
return
|
|
4888
|
+
return path18.join(home, "Library", "LaunchAgents", "com.hypeframe.engine.plist");
|
|
4235
4889
|
if (hasSystemd())
|
|
4236
|
-
return
|
|
4237
|
-
return
|
|
4890
|
+
return path18.join(home, ".config", "systemd", "user", "hypeframe.service");
|
|
4891
|
+
return path18.join(home, ".config", "autostart", "hypeframe.desktop");
|
|
4238
4892
|
}
|
|
4239
4893
|
function hasSystemd() {
|
|
4240
|
-
return process.platform === "linux" &&
|
|
4894
|
+
return process.platform === "linux" && spawnSync4("systemctl", ["--user", "--version"], { stdio: "ignore" }).status === 0;
|
|
4241
4895
|
}
|
|
4242
|
-
var autostartEnabled = () =>
|
|
4896
|
+
var autostartEnabled = () => fs22.existsSync(entryFile());
|
|
4243
4897
|
var xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
4244
4898
|
function autostart(mode) {
|
|
4245
4899
|
const file = entryFile();
|
|
@@ -4250,8 +4904,8 @@ function autostart(mode) {
|
|
|
4250
4904
|
}
|
|
4251
4905
|
if (mode === "off") {
|
|
4252
4906
|
if (process.platform === "linux" && file.endsWith(".service"))
|
|
4253
|
-
|
|
4254
|
-
|
|
4907
|
+
spawnSync4("systemctl", ["--user", "disable", "hypeframe.service"], { stdio: "ignore" });
|
|
4908
|
+
fs22.rmSync(file, { force: true });
|
|
4255
4909
|
log.ok(t("autostart.off"));
|
|
4256
4910
|
return;
|
|
4257
4911
|
}
|
|
@@ -4266,14 +4920,14 @@ function autostart(mode) {
|
|
|
4266
4920
|
return;
|
|
4267
4921
|
}
|
|
4268
4922
|
const quoted = cmd.map((c) => `"${c}"`).join(" ");
|
|
4269
|
-
|
|
4923
|
+
fs22.mkdirSync(path18.dirname(file), { recursive: true });
|
|
4270
4924
|
if (process.platform === "win32") {
|
|
4271
|
-
|
|
4925
|
+
fs22.writeFileSync(file, `@echo off\r
|
|
4272
4926
|
start "HypeFrame" /min ${quoted} start --no-browser\r
|
|
4273
4927
|
`);
|
|
4274
4928
|
} else if (process.platform === "darwin") {
|
|
4275
|
-
const out =
|
|
4276
|
-
|
|
4929
|
+
const out = path18.join(logDir(), "autostart.log");
|
|
4930
|
+
fs22.writeFileSync(file, `<?xml version="1.0" encoding="UTF-8"?>
|
|
4277
4931
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
4278
4932
|
<plist version="1.0"><dict>
|
|
4279
4933
|
<key>Label</key><string>com.hypeframe.engine</string>
|
|
@@ -4284,7 +4938,7 @@ start "HypeFrame" /min ${quoted} start --no-browser\r
|
|
|
4284
4938
|
</dict></plist>
|
|
4285
4939
|
`);
|
|
4286
4940
|
} else if (file.endsWith(".service")) {
|
|
4287
|
-
|
|
4941
|
+
fs22.writeFileSync(file, `[Unit]
|
|
4288
4942
|
Description=HypeFrame engine
|
|
4289
4943
|
After=network-online.target
|
|
4290
4944
|
|
|
@@ -4296,10 +4950,10 @@ RestartSec=60
|
|
|
4296
4950
|
[Install]
|
|
4297
4951
|
WantedBy=default.target
|
|
4298
4952
|
`);
|
|
4299
|
-
|
|
4300
|
-
|
|
4953
|
+
spawnSync4("systemctl", ["--user", "daemon-reload"], { stdio: "ignore" });
|
|
4954
|
+
spawnSync4("systemctl", ["--user", "enable", "hypeframe.service"], { stdio: "ignore" });
|
|
4301
4955
|
} else {
|
|
4302
|
-
|
|
4956
|
+
fs22.writeFileSync(file, `[Desktop Entry]
|
|
4303
4957
|
Type=Application
|
|
4304
4958
|
Name=HypeFrame engine
|
|
4305
4959
|
Exec=${quoted} start --no-browser
|
|
@@ -4311,7 +4965,7 @@ X-GNOME-Autostart-enabled=true
|
|
|
4311
4965
|
log.detail(file);
|
|
4312
4966
|
}
|
|
4313
4967
|
|
|
4314
|
-
// src/cli/commands/bench.ts
|
|
4968
|
+
// packages/hypeframe/src/cli/commands/bench.ts
|
|
4315
4969
|
import http3 from "node:http";
|
|
4316
4970
|
import puppeteer3 from "puppeteer-core";
|
|
4317
4971
|
var FRAMES = 150;
|
|
@@ -4409,247 +5063,8 @@ async function bench(args) {
|
|
|
4409
5063
|
`);
|
|
4410
5064
|
}
|
|
4411
5065
|
|
|
4412
|
-
// src/cli/commands/agent.ts
|
|
5066
|
+
// packages/hypeframe/src/cli/commands/agent.ts
|
|
4413
5067
|
import * as p from "@clack/prompts";
|
|
4414
|
-
|
|
4415
|
-
// src/agent/install.ts
|
|
4416
|
-
import fs21 from "node:fs";
|
|
4417
|
-
import fsp5 from "node:fs/promises";
|
|
4418
|
-
import path17 from "node:path";
|
|
4419
|
-
import yauzl2 from "yauzl";
|
|
4420
|
-
function unzip(file, to) {
|
|
4421
|
-
return new Promise((ok, fail) => {
|
|
4422
|
-
yauzl2.open(file, { lazyEntries: true }, (e, zip) => {
|
|
4423
|
-
if (e || !zip)
|
|
4424
|
-
return fail(e ?? new Error("zip"));
|
|
4425
|
-
zip.on("entry", (en) => {
|
|
4426
|
-
const target = path17.join(to, en.fileName);
|
|
4427
|
-
if (!target.startsWith(to + path17.sep))
|
|
4428
|
-
return fail(new Error("archive path outside the agent folder"));
|
|
4429
|
-
if (en.fileName.endsWith("/"))
|
|
4430
|
-
return fs21.mkdirSync(target, { recursive: true }), zip.readEntry();
|
|
4431
|
-
fs21.mkdirSync(path17.dirname(target), { recursive: true });
|
|
4432
|
-
zip.openReadStream(en, (e2, s) => {
|
|
4433
|
-
if (e2 || !s)
|
|
4434
|
-
return fail(e2 ?? new Error("zip"));
|
|
4435
|
-
const out = fs21.createWriteStream(target);
|
|
4436
|
-
s.pipe(out);
|
|
4437
|
-
out.on("finish", () => zip.readEntry());
|
|
4438
|
-
out.on("error", fail);
|
|
4439
|
-
});
|
|
4440
|
-
});
|
|
4441
|
-
zip.on("end", () => ok());
|
|
4442
|
-
zip.on("error", fail);
|
|
4443
|
-
zip.readEntry();
|
|
4444
|
-
});
|
|
4445
|
-
});
|
|
4446
|
-
}
|
|
4447
|
-
async function untarGz(file, to) {
|
|
4448
|
-
const { gunzipSync } = await import("node:zlib");
|
|
4449
|
-
const data = gunzipSync(await fsp5.readFile(file));
|
|
4450
|
-
const root = path17.resolve(to);
|
|
4451
|
-
const str = (b) => b.toString("utf8").replace(/\0[\s\S]*$/, "");
|
|
4452
|
-
const octal = (b) => Number.parseInt(str(b).trim() || "0", 8) || 0;
|
|
4453
|
-
let off = 0;
|
|
4454
|
-
let longName = null;
|
|
4455
|
-
while (off + 512 <= data.length) {
|
|
4456
|
-
const h = data.subarray(off, off + 512);
|
|
4457
|
-
if (h.every((x) => x === 0))
|
|
4458
|
-
break;
|
|
4459
|
-
const size = octal(h.subarray(124, 136));
|
|
4460
|
-
const type = String.fromCharCode(h[156] || 48);
|
|
4461
|
-
const body = data.subarray(off + 512, off + 512 + size);
|
|
4462
|
-
off += 512 + Math.ceil(size / 512) * 512;
|
|
4463
|
-
const prefix = str(h.subarray(345, 500));
|
|
4464
|
-
let name = longName ?? (prefix ? `${prefix}/${str(h.subarray(0, 100))}` : str(h.subarray(0, 100)));
|
|
4465
|
-
longName = null;
|
|
4466
|
-
if (type === "x") {
|
|
4467
|
-
const m = body.toString("utf8").match(/(?:^|\n)\d+ path=([^\n]*)\n/);
|
|
4468
|
-
if (m)
|
|
4469
|
-
longName = m[1];
|
|
4470
|
-
continue;
|
|
4471
|
-
}
|
|
4472
|
-
if (type === "L") {
|
|
4473
|
-
longName = str(body);
|
|
4474
|
-
continue;
|
|
4475
|
-
}
|
|
4476
|
-
if (type === "g")
|
|
4477
|
-
continue;
|
|
4478
|
-
name = name.replace(/^\.\//, "");
|
|
4479
|
-
if (!name)
|
|
4480
|
-
continue;
|
|
4481
|
-
const target = path17.resolve(root, name);
|
|
4482
|
-
if (target !== root && !target.startsWith(root + path17.sep))
|
|
4483
|
-
throw new Error("archive path outside the agent folder");
|
|
4484
|
-
if (type === "5") {
|
|
4485
|
-
await fsp5.mkdir(target, { recursive: true });
|
|
4486
|
-
continue;
|
|
4487
|
-
}
|
|
4488
|
-
if (type !== "0" && type !== "7")
|
|
4489
|
-
continue;
|
|
4490
|
-
await fsp5.mkdir(path17.dirname(target), { recursive: true });
|
|
4491
|
-
await fsp5.writeFile(target, body, { mode: octal(h.subarray(100, 108)) & 73 ? 493 : 420 });
|
|
4492
|
-
}
|
|
4493
|
-
}
|
|
4494
|
-
function npxRunner(pkg, extra = []) {
|
|
4495
|
-
if (isStandalone())
|
|
4496
|
-
return { cmd: process.execPath, args: ["x", pkg, ...extra], env: { BUN_BE_BUN: "1" } };
|
|
4497
|
-
const npxCli = path17.join(path17.dirname(process.execPath), process.platform === "win32" ? "" : "..", process.platform === "win32" ? "node_modules" : "lib/node_modules", "npm", "bin", "npx-cli.js");
|
|
4498
|
-
if (!fs21.existsSync(npxCli))
|
|
4499
|
-
throw new Error("npx was not found next to Node.js");
|
|
4500
|
-
return { cmd: process.execPath, args: [npxCli, "-y", pkg, ...extra], env: {} };
|
|
4501
|
-
}
|
|
4502
|
-
function ownCopy(a) {
|
|
4503
|
-
const bin = a.distribution.binary?.[platformKey()];
|
|
4504
|
-
if (bin) {
|
|
4505
|
-
const cmd = onPath(path17.basename(bin.cmd).replace(/\.exe$/i, ""));
|
|
4506
|
-
return cmd ? { cmd, args: bin.args ?? [], env: bin.env ?? {} } : null;
|
|
4507
|
-
}
|
|
4508
|
-
const npx = a.distribution.npx;
|
|
4509
|
-
if (npx) {
|
|
4510
|
-
const name = npx.package.replace(/(?!^)@[^@/]*$/, "").split("/").pop() ?? "";
|
|
4511
|
-
const cmd = onPath(name);
|
|
4512
|
-
return cmd ? { cmd, args: npx.args ?? [], env: npx.env ?? {} } : null;
|
|
4513
|
-
}
|
|
4514
|
-
return null;
|
|
4515
|
-
}
|
|
4516
|
-
async function unpackBinary(id, version, bin, progress) {
|
|
4517
|
-
if (!/^[0-9a-f]{64}$/i.test(bin.sha256 || ""))
|
|
4518
|
-
throw new Error(`Agent ${id}: the registry gives no sha256; not installed`);
|
|
4519
|
-
const dir = path17.join(agentDir(), id, version);
|
|
4520
|
-
const tmp = `${dir}.tmp`;
|
|
4521
|
-
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
4522
|
-
await fsp5.mkdir(tmp, { recursive: true });
|
|
4523
|
-
try {
|
|
4524
|
-
const name = path17.basename(new URL(bin.archive).pathname);
|
|
4525
|
-
const cmdRel = bin.cmd.replace(/^\.\//, "");
|
|
4526
|
-
if (/\.zip$/i.test(name)) {
|
|
4527
|
-
const file = path17.join(tmp, ".download.zip");
|
|
4528
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
4529
|
-
await unzip(file, tmp);
|
|
4530
|
-
await fsp5.rm(file, { force: true });
|
|
4531
|
-
} else if (/\.(tar\.gz|tgz)$/i.test(name)) {
|
|
4532
|
-
const file = path17.join(tmp, ".download.tar.gz");
|
|
4533
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), file, progress);
|
|
4534
|
-
await untarGz(file, tmp);
|
|
4535
|
-
await fsp5.rm(file, { force: true });
|
|
4536
|
-
} else if (/\.gz$/i.test(name)) {
|
|
4537
|
-
await downloadVerified(bin.archive, bin.sha256.toLowerCase(), path17.join(tmp, cmdRel), progress, true);
|
|
4538
|
-
} else
|
|
4539
|
-
throw new Error(`Agent ${id}: unsupported archive ${name}`);
|
|
4540
|
-
const cmd = path17.join(tmp, cmdRel);
|
|
4541
|
-
if (!fs21.existsSync(cmd))
|
|
4542
|
-
throw new Error(`Agent ${id}: ${bin.cmd} is not in the download`);
|
|
4543
|
-
if (process.platform !== "win32")
|
|
4544
|
-
await fsp5.chmod(cmd, 493);
|
|
4545
|
-
await fsp5.rm(dir, { recursive: true, force: true });
|
|
4546
|
-
await fsp5.rename(tmp, dir);
|
|
4547
|
-
return { cmd: path17.join(dir, cmdRel), args: bin.args ?? [], env: bin.env ?? {} };
|
|
4548
|
-
} catch (e) {
|
|
4549
|
-
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
4550
|
-
throw e;
|
|
4551
|
-
}
|
|
4552
|
-
}
|
|
4553
|
-
var codexAcpRelease = () => process.env.HYPEFRAME_CODEX_ACP_RELEASE || "https://api.github.com/repos/zed-industries/codex-acp/releases/latest";
|
|
4554
|
-
async function codexAcpBuild(arch) {
|
|
4555
|
-
const j = await (await fetch(codexAcpRelease(), { headers: { accept: "application/vnd.github+json", "user-agent": "hypeframe" }, signal: AbortSignal.timeout(20000) })).json();
|
|
4556
|
-
const triple = arch === "x64" ? "x86_64" : "aarch64";
|
|
4557
|
-
const asset = (j.assets ?? []).find((x) => new RegExp(`${triple}-unknown-linux-musl\\.tar\\.gz$`).test(String(x.name)));
|
|
4558
|
-
const sha256 = /^sha256:([0-9a-f]{64})$/i.exec(String(asset?.digest ?? ""))?.[1];
|
|
4559
|
-
const url = String(asset?.browser_download_url ?? "");
|
|
4560
|
-
if (!asset || !sha256 || !url)
|
|
4561
|
-
throw new Error("codex-acp: no checked Linux build for this phone");
|
|
4562
|
-
if (!process.env.HYPEFRAME_CODEX_ACP_RELEASE && !url.startsWith("https://github.com/"))
|
|
4563
|
-
throw new Error("codex-acp: unexpected download address");
|
|
4564
|
-
return { url, sha256: sha256.toLowerCase(), version: String(j.tag_name ?? "latest").replace(/^v/, "") };
|
|
4565
|
-
}
|
|
4566
|
-
var findFile = (dir, name) => {
|
|
4567
|
-
for (const n of fs21.readdirSync(dir)) {
|
|
4568
|
-
const f = path17.join(dir, n);
|
|
4569
|
-
const st = fs21.lstatSync(f);
|
|
4570
|
-
if (st.isFile() && n === name)
|
|
4571
|
-
return f;
|
|
4572
|
-
if (st.isDirectory()) {
|
|
4573
|
-
const inner = findFile(f, name);
|
|
4574
|
-
if (inner)
|
|
4575
|
-
return inner;
|
|
4576
|
-
}
|
|
4577
|
-
}
|
|
4578
|
-
return null;
|
|
4579
|
-
};
|
|
4580
|
-
async function installInLinux(a, id, progress, steps, arch) {
|
|
4581
|
-
steps.prepare();
|
|
4582
|
-
if (id === "antigravity-acp") {
|
|
4583
|
-
if (!steps.run("(test -x /root/.local/bin/agy || curl -fsSL https://antigravity.google/cli/install.sh | bash) && test -x /root/.local/bin/agy"))
|
|
4584
|
-
throw new Error("Antigravity: Google's installer did not finish in the Linux mini, or agy is not at /root/.local/bin/agy");
|
|
4585
|
-
return { launch: { cmd: "/root/.local/bin/agy", args: ["acp"], env: {}, linux: true }, version: a.version };
|
|
4586
|
-
}
|
|
4587
|
-
if (id === "codex-acp") {
|
|
4588
|
-
const b = await codexAcpBuild(arch);
|
|
4589
|
-
const dir = path17.join(agentDir(), id, b.version);
|
|
4590
|
-
const tmp = `${dir}.tmp`;
|
|
4591
|
-
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
4592
|
-
await fsp5.mkdir(tmp, { recursive: true });
|
|
4593
|
-
try {
|
|
4594
|
-
const file = path17.join(tmp, ".download.tar.gz");
|
|
4595
|
-
await downloadVerified(b.url, b.sha256, file, progress);
|
|
4596
|
-
await untarGz(file, tmp);
|
|
4597
|
-
await fsp5.rm(file, { force: true });
|
|
4598
|
-
const found = findFile(tmp, "codex-acp");
|
|
4599
|
-
if (!found)
|
|
4600
|
-
throw new Error("codex-acp: the program is not in the download");
|
|
4601
|
-
const rel = path17.relative(tmp, found);
|
|
4602
|
-
await fsp5.chmod(found, 493);
|
|
4603
|
-
await fsp5.rm(dir, { recursive: true, force: true });
|
|
4604
|
-
await fsp5.rename(tmp, dir);
|
|
4605
|
-
return { launch: { cmd: path17.join(dir, rel), args: [], env: {}, linux: true }, version: b.version };
|
|
4606
|
-
} catch (e) {
|
|
4607
|
-
await fsp5.rm(tmp, { recursive: true, force: true });
|
|
4608
|
-
throw e;
|
|
4609
|
-
}
|
|
4610
|
-
}
|
|
4611
|
-
const bin = a.distribution.binary?.[`linux-${arch === "x64" ? "x86_64" : "aarch64"}`];
|
|
4612
|
-
if (!bin)
|
|
4613
|
-
throw new Error(`Agent ${id} has no Linux build to run on this phone`);
|
|
4614
|
-
return { launch: { ...await unpackBinary(id, a.version, bin, progress), linux: true }, version: a.version };
|
|
4615
|
-
}
|
|
4616
|
-
async function installAgent(id, progress = () => {
|
|
4617
|
-
return;
|
|
4618
|
-
}, opts = {}) {
|
|
4619
|
-
const a = (await fetchRegistry()).find((x) => x.id === id);
|
|
4620
|
-
if (!a)
|
|
4621
|
-
throw new Error(`Agent ${id} is not in the registry`);
|
|
4622
|
-
const local = a.distribution.local;
|
|
4623
|
-
if (!isSupported(id) && !local)
|
|
4624
|
-
throw new Error(`Agent ${id} is not supported`);
|
|
4625
|
-
if (!local && (opts.android ?? isAndroid())) {
|
|
4626
|
-
const steps = opts.linux ?? { prepare: () => prepareLinux(opts.say), run: runInLinux };
|
|
4627
|
-
const r = await installInLinux(a, id, progress, steps, opts.arch ?? process.arch);
|
|
4628
|
-
const installed = { id, name: a.name, version: r.version, launch: r.launch };
|
|
4629
|
-
writeInstalled(installed);
|
|
4630
|
-
return installed;
|
|
4631
|
-
}
|
|
4632
|
-
let launch;
|
|
4633
|
-
const bin = a.distribution.binary?.[platformKey()];
|
|
4634
|
-
const own = local || opts.download ? null : ownCopy(a);
|
|
4635
|
-
if (local) {
|
|
4636
|
-
launch = { cmd: local.cmd, args: local.args ?? [], env: {} };
|
|
4637
|
-
} else if (own) {
|
|
4638
|
-
launch = own;
|
|
4639
|
-
} else if (bin) {
|
|
4640
|
-
launch = await unpackBinary(id, a.version, bin, progress);
|
|
4641
|
-
} else if (a.distribution.npx) {
|
|
4642
|
-
launch = { ...npxRunner(a.distribution.npx.package, a.distribution.npx.args), env: { ...a.distribution.npx.env ?? {} } };
|
|
4643
|
-
if (isStandalone())
|
|
4644
|
-
launch.env.BUN_BE_BUN = "1";
|
|
4645
|
-
} else
|
|
4646
|
-
throw new Error(`Agent ${id} has no download for ${platformKey()}`);
|
|
4647
|
-
const installed = { id, name: a.name, version: a.version, launch, ...own ? { own: true } : {} };
|
|
4648
|
-
writeInstalled(installed);
|
|
4649
|
-
return installed;
|
|
4650
|
-
}
|
|
4651
|
-
|
|
4652
|
-
// src/cli/commands/agent.ts
|
|
4653
5068
|
var NAMES = { "antigravity-acp": "Antigravity", "codex-acp": "Codex", opencode: "OpenCode" };
|
|
4654
5069
|
var agentName = (id) => NAMES[id] ?? readInstalled().find((a) => a.id === id)?.name ?? id;
|
|
4655
5070
|
var ALIASES = { codex: "codex-acp", antigravity: "antigravity-acp", agy: "antigravity-acp", gemini: "antigravity-acp", opencode: "opencode" };
|
|
@@ -4855,7 +5270,7 @@ async function agentMenu() {
|
|
|
4855
5270
|
}
|
|
4856
5271
|
}
|
|
4857
5272
|
|
|
4858
|
-
// src/cli/commands/config.ts
|
|
5273
|
+
// packages/hypeframe/src/cli/commands/config.ts
|
|
4859
5274
|
import * as p2 from "@clack/prompts";
|
|
4860
5275
|
function print() {
|
|
4861
5276
|
const s = resolveSettings();
|
|
@@ -4921,10 +5336,10 @@ async function config(args) {
|
|
|
4921
5336
|
log.detail(t("config.restart"));
|
|
4922
5337
|
}
|
|
4923
5338
|
|
|
4924
|
-
// src/cli/commands/doctor.ts
|
|
4925
|
-
import { spawnSync as
|
|
4926
|
-
import
|
|
4927
|
-
import
|
|
5339
|
+
// packages/hypeframe/src/cli/commands/doctor.ts
|
|
5340
|
+
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
5341
|
+
import fs23 from "node:fs";
|
|
5342
|
+
import path19 from "node:path";
|
|
4928
5343
|
var mark = { ok: color.ok(icon.ok), warn: color.warn(icon.warn), error: color.error(icon.error) };
|
|
4929
5344
|
async function reach(url) {
|
|
4930
5345
|
const t0 = Date.now();
|
|
@@ -4953,10 +5368,10 @@ async function doctor(args) {
|
|
|
4953
5368
|
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")}` : ""}` });
|
|
4954
5369
|
}
|
|
4955
5370
|
try {
|
|
4956
|
-
const probe =
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
const st =
|
|
5371
|
+
const probe = path19.join(dataDir(), `.probe-${process.pid}`);
|
|
5372
|
+
fs23.writeFileSync(probe, "x");
|
|
5373
|
+
fs23.rmSync(probe);
|
|
5374
|
+
const st = fs23.statfsSync(dataDir());
|
|
4960
5375
|
const free = st.bavail * st.bsize;
|
|
4961
5376
|
show({ label: t("doctor.disk"), result: free > 2 * 1024 ** 3 ? "ok" : "warn", detail: `${dataDir()} ${color.muted(icon.dot)} ${t("doctor.free", { size: bytes2(free) })}` });
|
|
4962
5377
|
} catch (e) {
|
|
@@ -4967,7 +5382,7 @@ async function doctor(args) {
|
|
|
4967
5382
|
const canDownload = !!FFMPEG_PINNED[`${process.platform}-${process.arch}`];
|
|
4968
5383
|
show({ label: "ffmpeg", result: canDownload ? "warn" : "error", detail: canDownload ? t("doctor.ffmpegLater") : t("doctor.noFfmpeg") });
|
|
4969
5384
|
} else {
|
|
4970
|
-
const r =
|
|
5385
|
+
const r = spawnSync5(ff, ["-hide_banner", "-version"], { encoding: "utf8", timeout: 15000 });
|
|
4971
5386
|
const v = /ffmpeg version (\S+)/.exec(r.stdout || "")?.[1];
|
|
4972
5387
|
show({ label: "ffmpeg", result: v ? "ok" : "error", detail: v || t("doctor.noFfmpeg") });
|
|
4973
5388
|
}
|
|
@@ -5002,22 +5417,22 @@ async function doctor(args) {
|
|
|
5002
5417
|
return checks;
|
|
5003
5418
|
}
|
|
5004
5419
|
|
|
5005
|
-
// src/cli/commands/history.ts
|
|
5006
|
-
import
|
|
5007
|
-
import
|
|
5420
|
+
// packages/hypeframe/src/cli/commands/history.ts
|
|
5421
|
+
import fs24 from "node:fs";
|
|
5422
|
+
import path20 from "node:path";
|
|
5008
5423
|
function readHistory2(hours = 24) {
|
|
5009
5424
|
const root = renderDir();
|
|
5010
5425
|
const since = Date.now() - hours * 3600000;
|
|
5011
5426
|
const out = [];
|
|
5012
|
-
for (const name of
|
|
5427
|
+
for (const name of fs24.readdirSync(root)) {
|
|
5013
5428
|
if (!JOB_ID.test(name))
|
|
5014
5429
|
continue;
|
|
5015
5430
|
try {
|
|
5016
|
-
const j = JSON.parse(
|
|
5431
|
+
const j = JSON.parse(fs24.readFileSync(path20.join(root, name, "status.json"), "utf8"));
|
|
5017
5432
|
if ((j.diperbarui || j.dibuat) < since)
|
|
5018
5433
|
continue;
|
|
5019
|
-
const f = j.hasilBerkas ?
|
|
5020
|
-
out.push({ job: j, file: f &&
|
|
5434
|
+
const f = j.hasilBerkas ? path20.join(root, name, j.hasilBerkas) : null;
|
|
5435
|
+
out.push({ job: j, file: f && fs24.existsSync(f) ? f : null });
|
|
5021
5436
|
} catch {}
|
|
5022
5437
|
}
|
|
5023
5438
|
return out.sort((a, b) => (b.job.diperbarui || 0) - (a.job.diperbarui || 0));
|
|
@@ -5042,32 +5457,32 @@ function history() {
|
|
|
5042
5457
|
return items;
|
|
5043
5458
|
}
|
|
5044
5459
|
|
|
5045
|
-
// src/cli/commands/maintenance.ts
|
|
5046
|
-
import { spawnSync as
|
|
5047
|
-
import
|
|
5048
|
-
import
|
|
5049
|
-
import
|
|
5460
|
+
// packages/hypeframe/src/cli/commands/maintenance.ts
|
|
5461
|
+
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
5462
|
+
import fs25 from "node:fs";
|
|
5463
|
+
import os5 from "node:os";
|
|
5464
|
+
import path21 from "node:path";
|
|
5050
5465
|
async function clean() {
|
|
5051
5466
|
if (runningPid()) {
|
|
5052
5467
|
log.warn(t("clean.running"));
|
|
5053
5468
|
return;
|
|
5054
5469
|
}
|
|
5055
|
-
const targets = [
|
|
5056
|
-
for (const job of
|
|
5470
|
+
const targets = [path21.join(cacheDir(), "chrome"), path21.join(cacheDir(), "halaman"), path21.join(logDir(), "hypeframe.log.1")];
|
|
5471
|
+
for (const job of fs25.readdirSync(renderDir())) {
|
|
5057
5472
|
if (!JOB_ID.test(job))
|
|
5058
5473
|
continue;
|
|
5059
5474
|
try {
|
|
5060
|
-
const s = JSON.parse(
|
|
5475
|
+
const s = JSON.parse(fs25.readFileSync(path21.join(renderDir(), job, "status.json"), "utf8")).status;
|
|
5061
5476
|
if (s === "gagal" || s === "batal" || s === "unggah")
|
|
5062
|
-
targets.push(
|
|
5477
|
+
targets.push(path21.join(renderDir(), job));
|
|
5063
5478
|
} catch {
|
|
5064
|
-
targets.push(
|
|
5479
|
+
targets.push(path21.join(renderDir(), job));
|
|
5065
5480
|
}
|
|
5066
5481
|
}
|
|
5067
5482
|
let freed = 0;
|
|
5068
5483
|
for (const p of targets) {
|
|
5069
5484
|
freed += await sizeOf(p);
|
|
5070
|
-
|
|
5485
|
+
fs25.rmSync(p, { recursive: true, force: true });
|
|
5071
5486
|
}
|
|
5072
5487
|
log.ok(t("clean.done", { size: bytes2(freed) }));
|
|
5073
5488
|
}
|
|
@@ -5076,7 +5491,7 @@ function report() {
|
|
|
5076
5491
|
const a = readAccount();
|
|
5077
5492
|
let recent = "";
|
|
5078
5493
|
try {
|
|
5079
|
-
recent =
|
|
5494
|
+
recent = fs25.readFileSync(path21.join(logDir(), "hypeframe.log"), "utf8").split(`
|
|
5080
5495
|
`).slice(-400).join(`
|
|
5081
5496
|
`);
|
|
5082
5497
|
} catch {
|
|
@@ -5085,7 +5500,7 @@ function report() {
|
|
|
5085
5500
|
const lines = [
|
|
5086
5501
|
`hypeframe ${VERSION}`,
|
|
5087
5502
|
`created ${new Date().toISOString()}`,
|
|
5088
|
-
`${runtimeLabel()} · ${process.platform} ${
|
|
5503
|
+
`${runtimeLabel()} · ${process.platform} ${os5.release()} ${process.arch} · ${os5.cpus()[0]?.model ?? "?"} ×${os5.cpus().length} · ${bytes2(os5.totalmem())} RAM`,
|
|
5089
5504
|
`gateway ${s.gateway}`,
|
|
5090
5505
|
`web ${s.web}`,
|
|
5091
5506
|
`gpu ${s.gpu}`,
|
|
@@ -5097,8 +5512,8 @@ function report() {
|
|
|
5097
5512
|
recent
|
|
5098
5513
|
];
|
|
5099
5514
|
const stamp = new Date().toISOString().slice(0, 19).replace(/[-:T]/g, "");
|
|
5100
|
-
const file =
|
|
5101
|
-
|
|
5515
|
+
const file = path21.join(dataDir(), `laporan-${stamp}.txt`);
|
|
5516
|
+
fs25.writeFileSync(file, mask(lines.join(`
|
|
5102
5517
|
`)), { mode: 384 });
|
|
5103
5518
|
log.ok(t("report.done", { file }));
|
|
5104
5519
|
log.detail(t("report.hint"));
|
|
@@ -5119,7 +5534,7 @@ function update() {
|
|
|
5119
5534
|
}
|
|
5120
5535
|
log.info(t("update.running"));
|
|
5121
5536
|
const [cmd, args, extra] = updateCommand({ standalone: isStandalone(), android: isAndroid(), windows: process.platform === "win32" });
|
|
5122
|
-
const r =
|
|
5537
|
+
const r = spawnSync6(cmd, args, { stdio: "inherit", ...extra });
|
|
5123
5538
|
if (r.status === 0)
|
|
5124
5539
|
log.ok(t("update.done"));
|
|
5125
5540
|
else
|
|
@@ -5133,14 +5548,14 @@ function openWeb(args) {
|
|
|
5133
5548
|
log.warn(t("pair.badWeb"));
|
|
5134
5549
|
}
|
|
5135
5550
|
|
|
5136
|
-
// src/cli/commands/status.ts
|
|
5137
|
-
import
|
|
5138
|
-
import
|
|
5551
|
+
// packages/hypeframe/src/cli/commands/status.ts
|
|
5552
|
+
import fs26 from "node:fs";
|
|
5553
|
+
import path22 from "node:path";
|
|
5139
5554
|
function statusRows(args) {
|
|
5140
5555
|
const s = resolveSettings(args?.flags);
|
|
5141
5556
|
const a = readAccount();
|
|
5142
5557
|
const pid = runningPid();
|
|
5143
|
-
const chrome = findChrome() ||
|
|
5558
|
+
const chrome = findChrome() || fs26.existsSync(path22.join(cacheDir(), "chrome"));
|
|
5144
5559
|
const recent = readHistory2();
|
|
5145
5560
|
const k = (key) => color.muted(t(key));
|
|
5146
5561
|
return [
|
|
@@ -5158,7 +5573,7 @@ function status(args) {
|
|
|
5158
5573
|
console.log("");
|
|
5159
5574
|
}
|
|
5160
5575
|
|
|
5161
|
-
// src/cli/menu.ts
|
|
5576
|
+
// packages/hypeframe/src/cli/menu.ts
|
|
5162
5577
|
import * as p3 from "@clack/prompts";
|
|
5163
5578
|
function mainChoices(s) {
|
|
5164
5579
|
return [
|
|
@@ -5352,7 +5767,7 @@ async function menu(args) {
|
|
|
5352
5767
|
}
|
|
5353
5768
|
}
|
|
5354
5769
|
|
|
5355
|
-
// src/index.ts
|
|
5770
|
+
// packages/hypeframe/src/index.ts
|
|
5356
5771
|
function help() {
|
|
5357
5772
|
const rows = [
|
|
5358
5773
|
["start", t("help.start")],
|