friend-assistant 0.1.72 → 0.1.74
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 +22 -8
- package/dist/BUILD.json +2 -2
- package/dist/friend.mjs +362 -168
- package/dist/sandbox-child.mjs +318 -0
- package/dist/web/assets/{OrgParts-CKm9GiMe.js → OrgParts-Do6LghTp.js} +1 -1
- package/dist/web/assets/{index-Ds89qbOY.js → index-D-7sGBTA.js} +24 -24
- package/dist/web/assets/{jarvis-ui-P2GxXH_b.js → jarvis-ui-BAYSuxFl.js} +1 -1
- package/dist/web/assets/{jarvisTree-DL1hkJfL.js → jarvisTree-UR7AWNFs.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +4 -1
package/dist/friend.mjs
CHANGED
|
@@ -811,7 +811,7 @@ var TOOL_DEFS = [
|
|
|
811
811
|
},
|
|
812
812
|
{
|
|
813
813
|
name: "code.run",
|
|
814
|
-
description: "Run a program you wrote (python, node or shell)
|
|
814
|
+
description: "Run a program you wrote (python, node or shell) away from the owner's PC and get its output. It runs in a throwaway Docker container when Docker works, otherwise in the sandbox built into Friend (the result says which). Neither has a network or can see the owner's files, and the program is stopped after a time limit (default 10 s, at most 60 s). The built-in sandbox is smaller: python has the standard library only (no numpy or pandas), node is plain JavaScript (no require, no fetch; use readFile and console.log), and shell is an emulated bash with a fixed set of commands (no curl, git or compilers). Use it to calculate, process data you put in the code, test an idea or build a result. The owner approves every run. Print what you want to see to stdout.",
|
|
815
815
|
input: z5.object({
|
|
816
816
|
language: z5.enum(["python", "node", "shell"]),
|
|
817
817
|
code: z5.string().min(1).max(5e4),
|
|
@@ -4489,9 +4489,11 @@ ${r.text}` };
|
|
|
4489
4489
|
if (call.name === "code.run") {
|
|
4490
4490
|
const { language, code, timeoutSec } = args;
|
|
4491
4491
|
const r = await d.code.run({ language, code, timeoutSec });
|
|
4492
|
-
d.audit.log("agent", "tool.call", { tool: call.name, args: { language, chars: code.length }, tier, ok: r.ok });
|
|
4492
|
+
d.audit.log("agent", "tool.call", { tool: call.name, args: { language, chars: code.length }, tier, ok: r.ok, ...r.ok && r.runner ? { runner: r.runner } : {} });
|
|
4493
4493
|
if (!r.ok) return fail3(r.error);
|
|
4494
4494
|
const parts = [r.timedOut ? "Stopped: it ran past the time limit." : `exit code ${r.exitCode}`];
|
|
4495
|
+
if (r.fellBack) parts.push("(Docker was not available, so this ran in Friend's built-in sandbox, which is smaller: no real shell, and Python has the standard library only)");
|
|
4496
|
+
else if (r.runner === "sandbox") parts.push("(ran in Friend's built-in sandbox)");
|
|
4495
4497
|
if (r.stdout) parts.push(`--- stdout ---
|
|
4496
4498
|
${r.stdout}`);
|
|
4497
4499
|
if (r.stderr) parts.push(`--- stderr ---
|
|
@@ -5162,6 +5164,7 @@ function sanitizeChannels(raw) {
|
|
|
5162
5164
|
}
|
|
5163
5165
|
};
|
|
5164
5166
|
}
|
|
5167
|
+
var sanitizeCodeRunner = (v) => v === "sandbox" || v === "docker" ? v : "auto";
|
|
5165
5168
|
var DEFAULT_OPENAI = { url: "http://localhost:20128/v1", model: "auto", apiKey: null, vision: false };
|
|
5166
5169
|
var DEFAULT_CLAUDE_CODE = { model: "sonnet", command: "claude", fallback: "ollama", webSearch: true };
|
|
5167
5170
|
function sanitizeClaudeCode(raw) {
|
|
@@ -5350,6 +5353,7 @@ var defaults = (dataDir) => ({
|
|
|
5350
5353
|
look: { ...DEFAULT_LOOK },
|
|
5351
5354
|
ownerName: "",
|
|
5352
5355
|
approvals: "manual",
|
|
5356
|
+
codeRunner: "auto",
|
|
5353
5357
|
phoneApprovals: sanitizePhoneApprovals(void 0),
|
|
5354
5358
|
audit: sanitizeAudit(void 0),
|
|
5355
5359
|
channels: sanitizeChannels(DEFAULT_CHANNELS),
|
|
@@ -5428,6 +5432,7 @@ function loadConfig(dataDir = defaultDataDir()) {
|
|
|
5428
5432
|
look: sanitizeLook(stored.look),
|
|
5429
5433
|
ownerName: typeof stored.ownerName === "string" ? stored.ownerName.replace(/[\u0000-\u001f\u007f]/g, " ").trim().slice(0, 40) : "",
|
|
5430
5434
|
approvals: stored.approvals === "edits" || stored.approvals === "auto" ? stored.approvals : "manual",
|
|
5435
|
+
codeRunner: sanitizeCodeRunner(stored.codeRunner),
|
|
5431
5436
|
phoneApprovals: sanitizePhoneApprovals(stored.phoneApprovals),
|
|
5432
5437
|
audit: sanitizeAudit(stored.audit),
|
|
5433
5438
|
channels: sanitizeChannels(stored.channels),
|
|
@@ -8724,15 +8729,24 @@ var LockoutError = class extends Error {
|
|
|
8724
8729
|
}
|
|
8725
8730
|
retryAfterMs;
|
|
8726
8731
|
};
|
|
8732
|
+
var FORGET_AFTER_MS = 24 * 3600 * 1e3;
|
|
8727
8733
|
var RateLimiter = class {
|
|
8728
|
-
constructor(clock2, maxFails = 5, baseLockMs = 6e4) {
|
|
8734
|
+
constructor(clock2, maxFails = 5, baseLockMs = 6e4, store2) {
|
|
8729
8735
|
this.clock = clock2;
|
|
8730
8736
|
this.maxFails = maxFails;
|
|
8731
8737
|
this.baseLockMs = baseLockMs;
|
|
8738
|
+
this.store = store2;
|
|
8739
|
+
if (!store2) return;
|
|
8740
|
+
const now = clock2();
|
|
8741
|
+
for (const r of store2.load()) {
|
|
8742
|
+
if (now - r.updatedAt > FORGET_AFTER_MS) store2.remove(r.key);
|
|
8743
|
+
else this.entries.set(r.key, { fails: r.fails, lockedUntil: r.lockedUntil, updatedAt: r.updatedAt });
|
|
8744
|
+
}
|
|
8732
8745
|
}
|
|
8733
8746
|
clock;
|
|
8734
8747
|
maxFails;
|
|
8735
8748
|
baseLockMs;
|
|
8749
|
+
store;
|
|
8736
8750
|
entries = /* @__PURE__ */ new Map();
|
|
8737
8751
|
check(key2) {
|
|
8738
8752
|
const e = this.entries.get(key2);
|
|
@@ -8746,7 +8760,9 @@ var RateLimiter = class {
|
|
|
8746
8760
|
const over = e.fails - this.maxFails;
|
|
8747
8761
|
e.lockedUntil = this.clock() + Math.min(this.baseLockMs * 2 ** over, 36e5);
|
|
8748
8762
|
}
|
|
8763
|
+
e.updatedAt = this.clock();
|
|
8749
8764
|
this.entries.set(key2, e);
|
|
8765
|
+
this.store?.save(key2, { fails: e.fails, lockedUntil: e.lockedUntil, updatedAt: e.updatedAt });
|
|
8750
8766
|
}
|
|
8751
8767
|
/** Wrong tries left before the next lock. Once locked before, one wrong try is enough to lock again, for longer. */
|
|
8752
8768
|
triesLeft(key2) {
|
|
@@ -8761,6 +8777,7 @@ var RateLimiter = class {
|
|
|
8761
8777
|
}
|
|
8762
8778
|
reset(key2) {
|
|
8763
8779
|
this.entries.delete(key2);
|
|
8780
|
+
this.store?.remove(key2);
|
|
8764
8781
|
}
|
|
8765
8782
|
};
|
|
8766
8783
|
|
|
@@ -8768,6 +8785,20 @@ var RateLimiter = class {
|
|
|
8768
8785
|
var SESSION_TTL_MS = 7 * 24 * 3600 * 1e3;
|
|
8769
8786
|
var LOGIN_TRIES = 3;
|
|
8770
8787
|
var PAIR_TTL_MS = 5 * 60 * 1e3;
|
|
8788
|
+
function lockoutStore(db, scope) {
|
|
8789
|
+
const upsert = db.prepare("insert or replace into lockouts (scope, key, fails, locked_until, updated_at) values (?, ?, ?, ?, ?)");
|
|
8790
|
+
const del = db.prepare("delete from lockouts where scope = ? and key = ?");
|
|
8791
|
+
return {
|
|
8792
|
+
load: () => db.prepare("select key, fails, locked_until, updated_at from lockouts where scope = ?").all(scope).map((r) => ({
|
|
8793
|
+
key: r.key,
|
|
8794
|
+
fails: r.fails,
|
|
8795
|
+
lockedUntil: r.locked_until,
|
|
8796
|
+
updatedAt: r.updated_at
|
|
8797
|
+
})),
|
|
8798
|
+
save: (key2, e) => void upsert.run(scope, key2, e.fails, e.lockedUntil, e.updatedAt),
|
|
8799
|
+
remove: (key2) => void del.run(scope, key2)
|
|
8800
|
+
};
|
|
8801
|
+
}
|
|
8771
8802
|
var sha256 = (s) => createHash6("sha256").update(s).digest("hex");
|
|
8772
8803
|
var SCRYPT_N = 131072;
|
|
8773
8804
|
var LEGACY_N = 16384;
|
|
@@ -8805,8 +8836,9 @@ var Auth = class _Auth {
|
|
|
8805
8836
|
this.db = db;
|
|
8806
8837
|
this.audit = audit;
|
|
8807
8838
|
this.clock = clock2;
|
|
8808
|
-
|
|
8809
|
-
this.
|
|
8839
|
+
db.exec("create table if not exists lockouts (scope text not null, key text not null, fails integer not null, locked_until integer not null, updated_at integer not null, primary key (scope, key))");
|
|
8840
|
+
this.limiter = new RateLimiter(clock2, LOGIN_TRIES, 6e4, lockoutStore(db, "address"));
|
|
8841
|
+
this.accountLimiter = new RateLimiter(clock2, 20, 6e4, lockoutStore(db, "account"));
|
|
8810
8842
|
}
|
|
8811
8843
|
db;
|
|
8812
8844
|
audit;
|
|
@@ -8814,6 +8846,10 @@ var Auth = class _Auth {
|
|
|
8814
8846
|
limiter;
|
|
8815
8847
|
/** Account-wide limits, so rotating source addresses does not multiply the guesses. */
|
|
8816
8848
|
accountLimiter;
|
|
8849
|
+
/** A limiter whose counts are kept in the database (for example the pairing codes), so a restart does not reset it. */
|
|
8850
|
+
persistentLimiter(scope, maxFails = 5) {
|
|
8851
|
+
return new RateLimiter(this.clock, maxFails, 6e4, lockoutStore(this.db, scope));
|
|
8852
|
+
}
|
|
8817
8853
|
/** Where a sign-in stands for this address: the wrong tries left, and how long it is locked. Safe to show the visitor. */
|
|
8818
8854
|
loginState(ip) {
|
|
8819
8855
|
const key2 = `login:${ip}`;
|
|
@@ -13808,11 +13844,128 @@ ${url}`);
|
|
|
13808
13844
|
};
|
|
13809
13845
|
|
|
13810
13846
|
// ../server/src/codebox.ts
|
|
13811
|
-
import { spawn as
|
|
13847
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
13812
13848
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
13813
13849
|
import { chmodSync as chmodSync7, mkdtempSync as mkdtempSync2, rmSync as rmSync9, writeFileSync as writeFileSync11 } from "node:fs";
|
|
13814
13850
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
13815
|
-
import { join as
|
|
13851
|
+
import { join as join19 } from "node:path";
|
|
13852
|
+
|
|
13853
|
+
// ../server/src/sandbox/index.ts
|
|
13854
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
13855
|
+
import { existsSync as existsSync16, realpathSync } from "node:fs";
|
|
13856
|
+
import { createRequire } from "node:module";
|
|
13857
|
+
import { dirname as dirname5, join as join18, sep as sep3 } from "node:path";
|
|
13858
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13859
|
+
|
|
13860
|
+
// ../server/src/sandbox/types.ts
|
|
13861
|
+
var SandboxUnavailable = class extends Error {
|
|
13862
|
+
};
|
|
13863
|
+
var MAX_SANDBOX_OUTPUT = 4e4;
|
|
13864
|
+
var SANDBOX_MEMORY_MB = 512;
|
|
13865
|
+
|
|
13866
|
+
// ../server/src/sandbox/index.ts
|
|
13867
|
+
var RESULT_MARK = "\n@@friend-sandbox-result@@";
|
|
13868
|
+
function childFile() {
|
|
13869
|
+
const here2 = dirname5(fileURLToPath2(import.meta.url));
|
|
13870
|
+
for (const f of [join18(here2, "sandbox-child.mjs"), join18(here2, "..", "..", ".sandbox-dev", "child.mjs")]) if (existsSync16(f)) return f;
|
|
13871
|
+
throw new SandboxUnavailable("The built-in sandbox program is missing. Run `pnpm build` (from the source) or reinstall Friend.");
|
|
13872
|
+
}
|
|
13873
|
+
function engineFolders(child) {
|
|
13874
|
+
const found = /* @__PURE__ */ new Set();
|
|
13875
|
+
for (let dir = dirname5(child); ; dir = dirname5(dir)) {
|
|
13876
|
+
if (existsSync16(join18(dir, "node_modules", "quickjs-emscripten"))) found.add(join18(dir, "node_modules"));
|
|
13877
|
+
if (dirname5(dir) === dir) break;
|
|
13878
|
+
}
|
|
13879
|
+
try {
|
|
13880
|
+
const real3 = realpathSync(createRequire(import.meta.url).resolve("quickjs-emscripten/package.json"));
|
|
13881
|
+
const at = real3.indexOf(`${sep3}node_modules${sep3}`);
|
|
13882
|
+
found.add(at >= 0 ? real3.slice(0, at + `${sep3}node_modules`.length) : dirname5(real3));
|
|
13883
|
+
} catch {
|
|
13884
|
+
}
|
|
13885
|
+
return [...found];
|
|
13886
|
+
}
|
|
13887
|
+
function neutralEnvironment() {
|
|
13888
|
+
if (process.platform !== "win32") return {};
|
|
13889
|
+
const root = process.env.SystemRoot ?? "C:Windows";
|
|
13890
|
+
return {
|
|
13891
|
+
SystemRoot: root,
|
|
13892
|
+
WINDIR: root,
|
|
13893
|
+
PATH: `${root}system32`,
|
|
13894
|
+
SYSTEMDRIVE: "C:",
|
|
13895
|
+
USERPROFILE: "C:sandbox",
|
|
13896
|
+
HOMEDRIVE: "C:",
|
|
13897
|
+
HOMEPATH: "sandbox",
|
|
13898
|
+
USERNAME: "sandbox",
|
|
13899
|
+
USERDOMAIN: "SANDBOX",
|
|
13900
|
+
LOGONSERVER: "\\SANDBOX",
|
|
13901
|
+
COMPUTERNAME: "SANDBOX",
|
|
13902
|
+
TEMP: "C:sandbox mp",
|
|
13903
|
+
TMP: "C:sandbox mp",
|
|
13904
|
+
APPDATA: "C:sandboxappdata",
|
|
13905
|
+
LOCALAPPDATA: "C:sandboxappdata"
|
|
13906
|
+
};
|
|
13907
|
+
}
|
|
13908
|
+
function permissionFlag() {
|
|
13909
|
+
const flags = process.allowedNodeEnvironmentFlags;
|
|
13910
|
+
if (flags.has("--permission")) return "--permission";
|
|
13911
|
+
if (flags.has("--experimental-permission")) return "--experimental-permission";
|
|
13912
|
+
throw new SandboxUnavailable("The built-in sandbox needs Node.js 20 or newer with its permission feature. Update Node.js, or use Docker.");
|
|
13913
|
+
}
|
|
13914
|
+
async function runInSandbox(input) {
|
|
13915
|
+
const child = childFile();
|
|
13916
|
+
const args = [
|
|
13917
|
+
permissionFlag(),
|
|
13918
|
+
`--allow-fs-read=${dirname5(child)}`,
|
|
13919
|
+
...engineFolders(child).map((f) => `--allow-fs-read=${f}`),
|
|
13920
|
+
`--max-old-space-size=${SANDBOX_MEMORY_MB}`,
|
|
13921
|
+
"--no-warnings",
|
|
13922
|
+
child
|
|
13923
|
+
];
|
|
13924
|
+
return new Promise((resolve13, reject) => {
|
|
13925
|
+
let done = false;
|
|
13926
|
+
let out = "";
|
|
13927
|
+
let err = "";
|
|
13928
|
+
let timedOut = false;
|
|
13929
|
+
const p = spawn4(process.execPath, args, { env: neutralEnvironment(), windowsHide: true, stdio: ["pipe", "pipe", "pipe"] });
|
|
13930
|
+
const finish2 = (r) => {
|
|
13931
|
+
if (done) return;
|
|
13932
|
+
done = true;
|
|
13933
|
+
clearTimeout(timer);
|
|
13934
|
+
p.kill("SIGKILL");
|
|
13935
|
+
if (r instanceof Error) reject(r);
|
|
13936
|
+
else resolve13(r);
|
|
13937
|
+
};
|
|
13938
|
+
const timer = setTimeout(() => {
|
|
13939
|
+
timedOut = true;
|
|
13940
|
+
finish2({ code: null, stdout: "", stderr: "", timedOut: true, outOfMemory: false });
|
|
13941
|
+
}, input.timeoutMs + 3e3);
|
|
13942
|
+
const cap = MAX_SANDBOX_OUTPUT * 4;
|
|
13943
|
+
p.stdout.on("data", (d) => void (out.length < cap && (out += d)));
|
|
13944
|
+
p.stderr.on("data", (d) => void (err.length < cap && (err += d)));
|
|
13945
|
+
p.on("error", (e) => finish2(new SandboxUnavailable(`The built-in sandbox could not start: ${e.message}`)));
|
|
13946
|
+
p.on("close", () => {
|
|
13947
|
+
if (timedOut) return;
|
|
13948
|
+
const at = out.lastIndexOf(RESULT_MARK);
|
|
13949
|
+
if (at < 0) {
|
|
13950
|
+
const oom = /heap out of memory|allocation failed|Reached heap limit/i.test(err);
|
|
13951
|
+
finish2({ code: null, stdout: "", stderr: oom ? "" : "The program ended unexpectedly.\n", timedOut: false, outOfMemory: oom });
|
|
13952
|
+
return;
|
|
13953
|
+
}
|
|
13954
|
+
try {
|
|
13955
|
+
const m = JSON.parse(out.slice(at + RESULT_MARK.length));
|
|
13956
|
+
if ("unavailable" in m) finish2(new SandboxUnavailable(m.unavailable));
|
|
13957
|
+
else finish2({ ...m, stdout: String(m.stdout).slice(0, MAX_SANDBOX_OUTPUT), stderr: String(m.stderr).slice(0, MAX_SANDBOX_OUTPUT) });
|
|
13958
|
+
} catch {
|
|
13959
|
+
finish2({ code: null, stdout: "", stderr: "The program ended unexpectedly.\n", timedOut: false, outOfMemory: false });
|
|
13960
|
+
}
|
|
13961
|
+
});
|
|
13962
|
+
p.stdin.on("error", () => {
|
|
13963
|
+
});
|
|
13964
|
+
p.stdin.end(JSON.stringify(input));
|
|
13965
|
+
});
|
|
13966
|
+
}
|
|
13967
|
+
|
|
13968
|
+
// ../server/src/codebox.ts
|
|
13816
13969
|
var MAX_CODE_CHARS = 5e4;
|
|
13817
13970
|
var MAX_OUTPUT_CHARS = 2e4;
|
|
13818
13971
|
var MAX_EXTRA_FILES = 10;
|
|
@@ -13826,7 +13979,7 @@ var SETUP = {
|
|
|
13826
13979
|
};
|
|
13827
13980
|
var spawnDocker = (args, { timeoutMs }) => new Promise((resolve13, reject) => {
|
|
13828
13981
|
const name = args[args.indexOf("--name") + 1];
|
|
13829
|
-
const child =
|
|
13982
|
+
const child = spawn5("docker", args, { windowsHide: true });
|
|
13830
13983
|
const cap = MAX_OUTPUT_CHARS * 2;
|
|
13831
13984
|
let stdout = "";
|
|
13832
13985
|
let stderr = "";
|
|
@@ -13835,7 +13988,7 @@ var spawnDocker = (args, { timeoutMs }) => new Promise((resolve13, reject) => {
|
|
|
13835
13988
|
child.stderr.on("data", (d) => void (stderr.length < cap && (stderr += d)));
|
|
13836
13989
|
const remove = () => new Promise((done) => {
|
|
13837
13990
|
if (!name) return done();
|
|
13838
|
-
const rm =
|
|
13991
|
+
const rm = spawn5("docker", ["rm", "-f", name], { windowsHide: true, stdio: "ignore" });
|
|
13839
13992
|
rm.on("error", () => done());
|
|
13840
13993
|
rm.on("close", () => done());
|
|
13841
13994
|
});
|
|
@@ -13856,11 +14009,15 @@ var spawnDocker = (args, { timeoutMs }) => new Promise((resolve13, reject) => {
|
|
|
13856
14009
|
});
|
|
13857
14010
|
var clip6 = (s) => s.length > MAX_OUTPUT_CHARS ? `${s.slice(0, MAX_OUTPUT_CHARS)}
|
|
13858
14011
|
[output cut]` : s;
|
|
14012
|
+
var DOCKER_RETRY_MS = 6e4;
|
|
13859
14013
|
var CodeBox = class {
|
|
13860
|
-
constructor(docker = spawnDocker) {
|
|
14014
|
+
constructor(docker = spawnDocker, opts = {}) {
|
|
13861
14015
|
this.docker = docker;
|
|
14016
|
+
this.opts = opts;
|
|
13862
14017
|
}
|
|
13863
14018
|
docker;
|
|
14019
|
+
opts;
|
|
14020
|
+
dockerDownUntil = 0;
|
|
13864
14021
|
async run(input) {
|
|
13865
14022
|
if (!input.code.trim()) return { ok: false, error: "There is no code to run." };
|
|
13866
14023
|
if (input.code.length > MAX_CODE_CHARS) return { ok: false, error: `The code is too long (the limit is ${MAX_CODE_CHARS} characters).` };
|
|
@@ -13870,17 +14027,45 @@ var CodeBox = class {
|
|
|
13870
14027
|
return { ok: false, error: "That file name is not allowed in the sandbox." };
|
|
13871
14028
|
}
|
|
13872
14029
|
if (extra.reduce((sum, [, body]) => sum + body.length, 0) > MAX_EXTRA_FILE_CHARS) return { ok: false, error: "The sandbox files are too large." };
|
|
13873
|
-
const setup = SETUP[input.language];
|
|
13874
14030
|
const timeoutMs = input.timeoutSec && input.timeoutSec > 0 ? Math.min(input.timeoutSec * 1e3, MAX_TIMEOUT_MS) : DEFAULT_TIMEOUT_MS;
|
|
13875
|
-
const
|
|
14031
|
+
const mode = this.opts.mode?.() ?? "docker";
|
|
14032
|
+
if (mode === "sandbox") return this.inSandbox(input, timeoutMs);
|
|
14033
|
+
const now = this.opts.now ?? Date.now;
|
|
14034
|
+
if (mode === "auto" && now() < this.dockerDownUntil) return this.fallBack(await this.inSandbox(input, timeoutMs));
|
|
14035
|
+
const viaDocker = await this.inDocker(input, timeoutMs);
|
|
14036
|
+
if (viaDocker.unavailable && mode === "auto") {
|
|
14037
|
+
this.dockerDownUntil = now() + DOCKER_RETRY_MS;
|
|
14038
|
+
return this.fallBack(await this.inSandbox(input, timeoutMs));
|
|
14039
|
+
}
|
|
14040
|
+
return viaDocker.result;
|
|
14041
|
+
}
|
|
14042
|
+
/** Marks a run that went to the built-in sandbox only because Docker would not run it, so the owner and the model are told. */
|
|
14043
|
+
fallBack(r) {
|
|
14044
|
+
return r.ok ? { ...r, fellBack: true } : r;
|
|
14045
|
+
}
|
|
14046
|
+
async inSandbox(input, timeoutMs) {
|
|
14047
|
+
try {
|
|
14048
|
+
const r = await (this.opts.sandbox ?? runInSandbox)({ language: input.language, code: input.code, files: input.files ?? {}, timeoutMs });
|
|
14049
|
+
const memory = "The program ran out of memory (limit 512 MB)." + String.fromCharCode(10);
|
|
14050
|
+
const stderr = r.outOfMemory ? (r.stderr && !r.stderr.endsWith(String.fromCharCode(10)) ? r.stderr + String.fromCharCode(10) : r.stderr) + memory : r.stderr;
|
|
14051
|
+
return { ok: true, runner: "sandbox", exitCode: r.code, stdout: clip6(r.stdout), stderr: clip6(stderr), timedOut: r.timedOut };
|
|
14052
|
+
} catch (e) {
|
|
14053
|
+
if (e instanceof SandboxUnavailable) return { ok: false, error: e.message };
|
|
14054
|
+
return { ok: false, error: "The built-in sandbox could not run this." };
|
|
14055
|
+
}
|
|
14056
|
+
}
|
|
14057
|
+
async inDocker(input, timeoutMs) {
|
|
14058
|
+
const extra = Object.entries(input.files ?? {});
|
|
14059
|
+
const setup = SETUP[input.language];
|
|
14060
|
+
const dir = mkdtempSync2(join19(tmpdir2(), "friend-code-"));
|
|
13876
14061
|
try {
|
|
13877
|
-
const file =
|
|
14062
|
+
const file = join19(dir, setup.file);
|
|
13878
14063
|
writeFileSync11(file, input.code);
|
|
13879
14064
|
chmodSync7(dir, 493);
|
|
13880
14065
|
chmodSync7(file, 420);
|
|
13881
14066
|
for (const [name, body] of extra) {
|
|
13882
|
-
writeFileSync11(
|
|
13883
|
-
chmodSync7(
|
|
14067
|
+
writeFileSync11(join19(dir, name), body);
|
|
14068
|
+
chmodSync7(join19(dir, name), 420);
|
|
13884
14069
|
}
|
|
13885
14070
|
const args = [
|
|
13886
14071
|
"run",
|
|
@@ -13919,15 +14104,15 @@ var CodeBox = class {
|
|
|
13919
14104
|
r = await this.docker(args, { timeoutMs });
|
|
13920
14105
|
} catch (e) {
|
|
13921
14106
|
if (e.code === "ENOENT") {
|
|
13922
|
-
return { ok: false, error: "Docker is not available. Install Docker Desktop and start it to run code safely." };
|
|
14107
|
+
return { result: { ok: false, error: "Docker is not available. Install Docker Desktop and start it to run code safely." }, unavailable: true };
|
|
13923
14108
|
}
|
|
13924
|
-
return { ok: false, error: "Docker could not be started." };
|
|
14109
|
+
return { result: { ok: false, error: "Docker could not be started." }, unavailable: true };
|
|
13925
14110
|
}
|
|
13926
14111
|
if (r.code === 125 && !r.timedOut) {
|
|
13927
|
-
if (/daemon|pipe|socket/i.test(r.stderr)) return { ok: false, error: "Docker is not running. Start Docker Desktop and try again." };
|
|
13928
|
-
return { ok: false, error: "Docker could not start the container. The first run of each language needs an internet connection to download its image." };
|
|
14112
|
+
if (/daemon|pipe|socket/i.test(r.stderr)) return { result: { ok: false, error: "Docker is not running. Start Docker Desktop and try again." }, unavailable: true };
|
|
14113
|
+
return { result: { ok: false, error: "Docker could not start the container. The first run of each language needs an internet connection to download its image." }, unavailable: true };
|
|
13929
14114
|
}
|
|
13930
|
-
return { ok: true, exitCode: r.code, stdout: clip6(r.stdout), stderr: clip6(r.stderr), timedOut: r.timedOut };
|
|
14115
|
+
return { result: { ok: true, runner: "docker", exitCode: r.code, stdout: clip6(r.stdout), stderr: clip6(r.stderr), timedOut: r.timedOut }, unavailable: false };
|
|
13931
14116
|
} finally {
|
|
13932
14117
|
rmSync9(dir, { recursive: true, force: true });
|
|
13933
14118
|
}
|
|
@@ -14024,13 +14209,13 @@ var Memory = class {
|
|
|
14024
14209
|
};
|
|
14025
14210
|
|
|
14026
14211
|
// ../server/src/memory/import.ts
|
|
14027
|
-
import { existsSync as
|
|
14028
|
-
import { join as
|
|
14212
|
+
import { existsSync as existsSync17, writeFileSync as writeFileSync12 } from "node:fs";
|
|
14213
|
+
import { join as join20 } from "node:path";
|
|
14029
14214
|
var MARKER = ".imported-notes";
|
|
14030
14215
|
function importFlatNotes(memory, tree2) {
|
|
14031
14216
|
tree2.ensure();
|
|
14032
|
-
const marker =
|
|
14033
|
-
if (
|
|
14217
|
+
const marker = join20(tree2.root, MARKER);
|
|
14218
|
+
if (existsSync17(marker)) return 0;
|
|
14034
14219
|
let n2 = 0;
|
|
14035
14220
|
for (const m of [...memory.list()].reverse()) {
|
|
14036
14221
|
const name = inboxName(m.text, (x) => tree2.has(`inbox/${x}.md`));
|
|
@@ -14042,8 +14227,8 @@ function importFlatNotes(memory, tree2) {
|
|
|
14042
14227
|
}
|
|
14043
14228
|
|
|
14044
14229
|
// ../server/src/memory/keeper.ts
|
|
14045
|
-
import { existsSync as
|
|
14046
|
-
import { join as
|
|
14230
|
+
import { existsSync as existsSync18, readFileSync as readFileSync11, writeFileSync as writeFileSync13 } from "node:fs";
|
|
14231
|
+
import { join as join21 } from "node:path";
|
|
14047
14232
|
import { z as z11 } from "zod";
|
|
14048
14233
|
var SYSTEM3 = `You keep the long-term memory of a personal assistant for its owner. You are given the memory index, a few existing notes that may be related, and the latest conversation between the owner and the assistant. Decide what, if anything, is worth keeping for months, and return it as JSON.
|
|
14049
14234
|
|
|
@@ -14111,11 +14296,11 @@ var MemoryKeeper = class {
|
|
|
14111
14296
|
this.d.after?.();
|
|
14112
14297
|
}
|
|
14113
14298
|
cursorPath() {
|
|
14114
|
-
return
|
|
14299
|
+
return join21(this.d.tree.root, CURSOR_FILE);
|
|
14115
14300
|
}
|
|
14116
14301
|
readCursor() {
|
|
14117
14302
|
try {
|
|
14118
|
-
if (!
|
|
14303
|
+
if (!existsSync18(this.cursorPath())) return -1;
|
|
14119
14304
|
const n2 = Number(JSON.parse(readFileSync11(this.cursorPath(), "utf8")).lastId);
|
|
14120
14305
|
return Number.isInteger(n2) && n2 >= 0 ? n2 : -1;
|
|
14121
14306
|
} catch {
|
|
@@ -14409,7 +14594,7 @@ ${n2.body.trim().slice(0, NOTE_CHARS)}`).join("\n")}`,
|
|
|
14409
14594
|
};
|
|
14410
14595
|
|
|
14411
14596
|
// ../server/src/proactive/beat.ts
|
|
14412
|
-
import { existsSync as
|
|
14597
|
+
import { existsSync as existsSync19, readFileSync as readFileSync12, writeFileSync as writeFileSync14 } from "node:fs";
|
|
14413
14598
|
var LEVEL2 = { off: 0, low: 1, medium: 2, high: 3 };
|
|
14414
14599
|
var MAX_SAY = 400;
|
|
14415
14600
|
var OVERDUE_AFTER_MS = 2 * 36e5;
|
|
@@ -14452,7 +14637,7 @@ var ProactiveBeat = class {
|
|
|
14452
14637
|
}
|
|
14453
14638
|
load(day2) {
|
|
14454
14639
|
try {
|
|
14455
|
-
if (
|
|
14640
|
+
if (existsSync19(this.d.statePath)) {
|
|
14456
14641
|
const s = JSON.parse(readFileSync12(this.d.statePath, "utf8"));
|
|
14457
14642
|
if (s.day === day2) return { day: day2, sent: s.sent ?? 0, lastAt: s.lastAt ?? 0, fired: s.fired ?? {}, said: s.said ?? [] };
|
|
14458
14643
|
const week = this.now() - 7 * 864e5;
|
|
@@ -14608,13 +14793,13 @@ ${recent}` : "",
|
|
|
14608
14793
|
};
|
|
14609
14794
|
|
|
14610
14795
|
// ../server/src/app.ts
|
|
14611
|
-
import { dirname as
|
|
14612
|
-
import { fileURLToPath as
|
|
14796
|
+
import { dirname as dirname8, extname as extname3, resolve as resolve5 } from "node:path";
|
|
14797
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
14613
14798
|
|
|
14614
14799
|
// ../server/src/office/office.ts
|
|
14615
14800
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
14616
14801
|
import { mkdirSync as mkdirSync12, statSync as statSync3, writeFileSync as writeFileSync15 } from "node:fs";
|
|
14617
|
-
import { join as
|
|
14802
|
+
import { join as join22 } from "node:path";
|
|
14618
14803
|
|
|
14619
14804
|
// ../server/src/provider/claude-code/bridge.ts
|
|
14620
14805
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
@@ -14851,15 +15036,15 @@ function decideAction(call, ctx) {
|
|
|
14851
15036
|
}
|
|
14852
15037
|
|
|
14853
15038
|
// ../server/src/office/runner.ts
|
|
14854
|
-
import
|
|
15039
|
+
import spawn7 from "cross-spawn";
|
|
14855
15040
|
|
|
14856
15041
|
// ../server/src/provider/claude-code/process.ts
|
|
14857
|
-
import
|
|
15042
|
+
import spawn6 from "cross-spawn";
|
|
14858
15043
|
var MAX_STDERR = 8 * 1024;
|
|
14859
15044
|
var ClaudeProc = class {
|
|
14860
15045
|
constructor(opts, emit) {
|
|
14861
15046
|
this.emit = emit;
|
|
14862
|
-
this.child =
|
|
15047
|
+
this.child = spawn6(opts.command, opts.args, { cwd: opts.cwd, env: opts.env, stdio: ["pipe", "pipe", "pipe"], windowsHide: true });
|
|
14863
15048
|
this.exited = new Promise((resolve13) => {
|
|
14864
15049
|
let finished = false;
|
|
14865
15050
|
const finish2 = (code, notInstalled) => {
|
|
@@ -14973,7 +15158,7 @@ var WorkerProc = class {
|
|
|
14973
15158
|
const pid = this.proc.pid;
|
|
14974
15159
|
if (process.platform === "win32" && pid) {
|
|
14975
15160
|
try {
|
|
14976
|
-
|
|
15161
|
+
spawn7.sync("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true, timeout: 5e3 });
|
|
14977
15162
|
} catch {
|
|
14978
15163
|
}
|
|
14979
15164
|
}
|
|
@@ -15272,9 +15457,9 @@ var Office = class {
|
|
|
15272
15457
|
const cfg = this.d.config();
|
|
15273
15458
|
await run2.bridge.start();
|
|
15274
15459
|
if (run2.concluded) return;
|
|
15275
|
-
const dir =
|
|
15460
|
+
const dir = join22(this.d.dataDir, "office");
|
|
15276
15461
|
mkdirSync12(dir, { recursive: true });
|
|
15277
|
-
const mcp =
|
|
15462
|
+
const mcp = join22(dir, `${worker.id}.mcp.json`);
|
|
15278
15463
|
writeFileSync15(mcp, JSON.stringify({ mcpServers: { office: { type: "http", url: run2.bridge.url, headers: { Authorization: `Bearer ${run2.bridge.token}` } } } }));
|
|
15279
15464
|
const args = buildWorkerArgs({
|
|
15280
15465
|
model: worker.model.trim() || cfg.claudeCode.model,
|
|
@@ -15664,12 +15849,12 @@ var OfficeStore = class {
|
|
|
15664
15849
|
};
|
|
15665
15850
|
|
|
15666
15851
|
// ../server/src/app.ts
|
|
15667
|
-
import { join as
|
|
15852
|
+
import { join as join27 } from "node:path";
|
|
15668
15853
|
|
|
15669
15854
|
// ../server/src/db.ts
|
|
15670
15855
|
import Database from "better-sqlite3";
|
|
15671
15856
|
import { mkdirSync as mkdirSync13 } from "node:fs";
|
|
15672
|
-
import { join as
|
|
15857
|
+
import { join as join23 } from "node:path";
|
|
15673
15858
|
|
|
15674
15859
|
// ../server/src/migrations.ts
|
|
15675
15860
|
var MIGRATIONS = [
|
|
@@ -15965,7 +16150,7 @@ create trigger audit_no_delete before delete on audit_log begin select raise(abo
|
|
|
15965
16150
|
// ../server/src/db.ts
|
|
15966
16151
|
function openDb(dataDir) {
|
|
15967
16152
|
mkdirSync13(dataDir, { recursive: true });
|
|
15968
|
-
const db = new Database(
|
|
16153
|
+
const db = new Database(join23(dataDir, "friend.db"));
|
|
15969
16154
|
db.pragma("journal_mode = WAL");
|
|
15970
16155
|
db.pragma("foreign_keys = ON");
|
|
15971
16156
|
db.exec("create table if not exists schema_version (id integer primary key, applied_at integer not null)");
|
|
@@ -16790,7 +16975,7 @@ function registerAuditRoutes(d) {
|
|
|
16790
16975
|
// ../server/src/gateway.ts
|
|
16791
16976
|
import fastifyStatic from "@fastify/static";
|
|
16792
16977
|
import Fastify from "fastify";
|
|
16793
|
-
import { createReadStream as createReadStream2, existsSync as
|
|
16978
|
+
import { createReadStream as createReadStream2, existsSync as existsSync20, promises as fsp2 } from "node:fs";
|
|
16794
16979
|
import { isIP as isIP3 } from "node:net";
|
|
16795
16980
|
import { Readable } from "node:stream";
|
|
16796
16981
|
import { WebSocket as WebSocket2, WebSocketServer } from "ws";
|
|
@@ -17026,7 +17211,7 @@ function createGateway(deps) {
|
|
|
17026
17211
|
return reply.code(400).send({ error: e.message });
|
|
17027
17212
|
}
|
|
17028
17213
|
});
|
|
17029
|
-
const pairLimiter =
|
|
17214
|
+
const pairLimiter = auth.persistentLimiter("pair");
|
|
17030
17215
|
app.post("/api/pair", async (req, reply) => {
|
|
17031
17216
|
const body = z14.object({ code: z14.string().min(1).max(64), name: z14.string().min(1).max(64) }).safeParse(req.body);
|
|
17032
17217
|
if (!body.success) return reply.code(400).send({ error: "Invalid input" });
|
|
@@ -17923,7 +18108,7 @@ function createGateway(deps) {
|
|
|
17923
18108
|
deps.onLock?.();
|
|
17924
18109
|
return { ok: true };
|
|
17925
18110
|
});
|
|
17926
|
-
if (deps.webDir &&
|
|
18111
|
+
if (deps.webDir && existsSync20(deps.webDir)) {
|
|
17927
18112
|
app.register(fastifyStatic, { root: deps.webDir });
|
|
17928
18113
|
app.setNotFoundHandler((req, reply) => {
|
|
17929
18114
|
if (req.method === "GET" && !req.url.startsWith("/api")) return reply.sendFile("index.html");
|
|
@@ -18077,10 +18262,10 @@ Connection: close\r
|
|
|
18077
18262
|
}
|
|
18078
18263
|
|
|
18079
18264
|
// ../server/src/browser/hub.ts
|
|
18080
|
-
import { spawn as
|
|
18265
|
+
import { spawn as spawn8, spawnSync } from "node:child_process";
|
|
18081
18266
|
import { mkdirSync as mkdirSync14, mkdtempSync as mkdtempSync3, readdirSync as readdirSync6, readFileSync as readFileSync13, rmSync as rmSync10, statSync as statSync5 } from "node:fs";
|
|
18082
18267
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
18083
|
-
import { join as
|
|
18268
|
+
import { join as join24 } from "node:path";
|
|
18084
18269
|
|
|
18085
18270
|
// ../server/src/browser/cdp.ts
|
|
18086
18271
|
import { WebSocket as WebSocket3 } from "ws";
|
|
@@ -18150,11 +18335,11 @@ var Cdp = class _Cdp {
|
|
|
18150
18335
|
};
|
|
18151
18336
|
|
|
18152
18337
|
// ../server/src/browser/chrome.ts
|
|
18153
|
-
import { existsSync as
|
|
18338
|
+
import { existsSync as existsSync21, statSync as statSync4 } from "node:fs";
|
|
18154
18339
|
import { posix as posix3, win32 as win323 } from "node:path";
|
|
18155
18340
|
var fileThere = (p) => {
|
|
18156
18341
|
try {
|
|
18157
|
-
return
|
|
18342
|
+
return existsSync21(p) && statSync4(p).isFile();
|
|
18158
18343
|
} catch {
|
|
18159
18344
|
return false;
|
|
18160
18345
|
}
|
|
@@ -18165,15 +18350,15 @@ function findChrome(override = "", w = {}) {
|
|
|
18165
18350
|
const platform = w.platform ?? process.platform;
|
|
18166
18351
|
const env = w.env ?? process.env;
|
|
18167
18352
|
const isFile = w.isFile ?? fileThere;
|
|
18168
|
-
const
|
|
18353
|
+
const join37 = platform === "win32" ? win323.join : posix3.join;
|
|
18169
18354
|
if (override.trim()) return isFile(override.trim()) ? override.trim() : null;
|
|
18170
18355
|
if (platform === "win32") {
|
|
18171
18356
|
const roots = [env.PROGRAMFILES, env["PROGRAMFILES(X86)"], env.LOCALAPPDATA].filter((r) => !!r);
|
|
18172
|
-
for (const r of roots) for (const rel of ["Google/Chrome/Application/chrome.exe", "Chromium/Application/chrome.exe", "Microsoft/Edge/Application/msedge.exe"]) if (isFile(
|
|
18357
|
+
for (const r of roots) for (const rel of ["Google/Chrome/Application/chrome.exe", "Chromium/Application/chrome.exe", "Microsoft/Edge/Application/msedge.exe"]) if (isFile(join37(r, rel))) return join37(r, rel);
|
|
18173
18358
|
return null;
|
|
18174
18359
|
}
|
|
18175
18360
|
if (platform === "darwin") return MAC_PATHS.find(isFile) ?? null;
|
|
18176
|
-
for (const dir of (env.PATH ?? "").split(":").filter(Boolean)) for (const name of LINUX_NAMES) if (isFile(
|
|
18361
|
+
for (const dir of (env.PATH ?? "").split(":").filter(Boolean)) for (const name of LINUX_NAMES) if (isFile(join37(dir, name))) return join37(dir, name);
|
|
18177
18362
|
return null;
|
|
18178
18363
|
}
|
|
18179
18364
|
|
|
@@ -18200,7 +18385,7 @@ var BrowserHub = class {
|
|
|
18200
18385
|
try {
|
|
18201
18386
|
for (const name of readdirSync6(root)) {
|
|
18202
18387
|
if (!/^friend-browser-/.test(name)) continue;
|
|
18203
|
-
const dir =
|
|
18388
|
+
const dir = join24(root, name);
|
|
18204
18389
|
if (Date.now() - statSync5(dir).mtimeMs > 36e5) rmSync10(dir, { recursive: true, force: true });
|
|
18205
18390
|
}
|
|
18206
18391
|
} catch {
|
|
@@ -18265,8 +18450,8 @@ A picture of the page "${r.value.title || r.value.href}" (${r.value.href}). Text
|
|
|
18265
18450
|
try {
|
|
18266
18451
|
const root = this.o.tmpRoot ?? tmpdir3();
|
|
18267
18452
|
mkdirSync14(root, { recursive: true });
|
|
18268
|
-
profile = mkdtempSync3(
|
|
18269
|
-
child =
|
|
18453
|
+
profile = mkdtempSync3(join24(root, "friend-browser-"));
|
|
18454
|
+
child = spawn8(
|
|
18270
18455
|
chrome,
|
|
18271
18456
|
[
|
|
18272
18457
|
"--headless=new",
|
|
@@ -18379,7 +18564,7 @@ async function endpoint(profile, signal) {
|
|
|
18379
18564
|
for (; ; ) {
|
|
18380
18565
|
signal.throwIfAborted();
|
|
18381
18566
|
try {
|
|
18382
|
-
const [port, path3] = readFileSync13(
|
|
18567
|
+
const [port, path3] = readFileSync13(join24(profile, "DevToolsActivePort"), "utf8").split("\n");
|
|
18383
18568
|
if (port && path3) return `ws://127.0.0.1:${port.trim()}${path3.trim()}`;
|
|
18384
18569
|
} catch {
|
|
18385
18570
|
}
|
|
@@ -18621,8 +18806,8 @@ function startStatsFeed(opts) {
|
|
|
18621
18806
|
|
|
18622
18807
|
// ../server/src/provider/claude-code/provider.ts
|
|
18623
18808
|
import { createHash as createHash12 } from "node:crypto";
|
|
18624
|
-
import { chmodSync as chmodSync8, existsSync as
|
|
18625
|
-
import { join as
|
|
18809
|
+
import { chmodSync as chmodSync8, existsSync as existsSync22, mkdirSync as mkdirSync15, readdirSync as readdirSync7, readFileSync as readFileSync14, rmSync as rmSync11, writeFileSync as writeFileSync16 } from "node:fs";
|
|
18810
|
+
import { join as join25 } from "node:path";
|
|
18626
18811
|
|
|
18627
18812
|
// ../server/src/provider/claude-code/limits.ts
|
|
18628
18813
|
var LIMIT2 = /\b(?:hit|reached)\s+(?:your\s+|the\s+)?(?:[\w-]+\s+)?(?:usage\s+)?limit\b|\busage\s+limit\b|\b(?:\d+-hour|weekly|daily|monthly)\s+limit\s+reached\b|\bhit your (?:weekly|daily|monthly|usage|\d+-hour) limit\b/i;
|
|
@@ -18720,7 +18905,7 @@ var NOT_SIGNED_IN = /not logged in|please run \/login|invalid api key|authentica
|
|
|
18720
18905
|
var ClaudeCodeProvider = class {
|
|
18721
18906
|
constructor(opts) {
|
|
18722
18907
|
this.opts = opts;
|
|
18723
|
-
this.home =
|
|
18908
|
+
this.home = join25(opts.dataDir, "claude");
|
|
18724
18909
|
this.now = opts.now ?? Date.now;
|
|
18725
18910
|
this.bridge = new ToolBridge((call) => this.owner.inbox.push({ kind: "call", call }));
|
|
18726
18911
|
}
|
|
@@ -18976,7 +19161,7 @@ ${item.stderr}`;
|
|
|
18976
19161
|
"local",
|
|
18977
19162
|
"--system-prompt-file",
|
|
18978
19163
|
systemFile,
|
|
18979
|
-
...conv.guest ? ["--no-session-persistence"] : ["--mcp-config",
|
|
19164
|
+
...conv.guest ? ["--no-session-persistence"] : ["--mcp-config", join25(this.home, "mcp.json"), "--allowedTools", [...web ? ["WebSearch"] : [], ...req.tools.map((t) => `mcp__friend__${encodeToolName(t.name)}`)].join(","), ...resume ? ["--resume", resume] : []]
|
|
18980
19165
|
];
|
|
18981
19166
|
const proc = new ClaudeProc(
|
|
18982
19167
|
{
|
|
@@ -19005,11 +19190,11 @@ ${item.stderr}`;
|
|
|
19005
19190
|
if (!this.swept) {
|
|
19006
19191
|
this.swept = true;
|
|
19007
19192
|
try {
|
|
19008
|
-
for (const f of readdirSync7(this.home)) if (/^system-\d+\.txt$/.test(f)) rmSync11(
|
|
19193
|
+
for (const f of readdirSync7(this.home)) if (/^system-\d+\.txt$/.test(f)) rmSync11(join25(this.home, f), { force: true });
|
|
19009
19194
|
} catch {
|
|
19010
19195
|
}
|
|
19011
19196
|
}
|
|
19012
|
-
const file =
|
|
19197
|
+
const file = join25(this.home, `system-${++this.systemCount}.txt`);
|
|
19013
19198
|
writeFileSync16(file, text4);
|
|
19014
19199
|
try {
|
|
19015
19200
|
chmodSync8(file, 384);
|
|
@@ -19026,7 +19211,7 @@ ${item.stderr}`;
|
|
|
19026
19211
|
startBridge() {
|
|
19027
19212
|
this.bridgeReady ??= (async () => {
|
|
19028
19213
|
await this.bridge.start();
|
|
19029
|
-
const file =
|
|
19214
|
+
const file = join25(this.home, "mcp.json");
|
|
19030
19215
|
writeFileSync16(file, JSON.stringify({ mcpServers: { friend: { type: "http", url: this.bridge.url, headers: { Authorization: `Bearer ${this.bridge.token}` } } } }));
|
|
19031
19216
|
try {
|
|
19032
19217
|
chmodSync8(file, 384);
|
|
@@ -19036,10 +19221,10 @@ ${item.stderr}`;
|
|
|
19036
19221
|
return this.bridgeReady;
|
|
19037
19222
|
}
|
|
19038
19223
|
// ---- the session id, kept so a restart of Friend can pick the conversation up again ----
|
|
19039
|
-
sessionFile = () =>
|
|
19224
|
+
sessionFile = () => join25(this.home, "session-id");
|
|
19040
19225
|
readSession() {
|
|
19041
19226
|
try {
|
|
19042
|
-
return
|
|
19227
|
+
return existsSync22(this.sessionFile()) ? readFileSync14(this.sessionFile(), "utf8").trim() || null : null;
|
|
19043
19228
|
} catch {
|
|
19044
19229
|
return null;
|
|
19045
19230
|
}
|
|
@@ -19057,10 +19242,10 @@ ${item.stderr}`;
|
|
|
19057
19242
|
} catch {
|
|
19058
19243
|
}
|
|
19059
19244
|
}
|
|
19060
|
-
freshFile = () =>
|
|
19245
|
+
freshFile = () => join25(this.home, "fresh.json");
|
|
19061
19246
|
readFresh() {
|
|
19062
19247
|
try {
|
|
19063
|
-
if (!
|
|
19248
|
+
if (!existsSync22(this.freshFile())) return null;
|
|
19064
19249
|
const r = JSON.parse(readFileSync14(this.freshFile(), "utf8"));
|
|
19065
19250
|
return { seed: typeof r.seed === "string" && r.seed ? r.seed : null };
|
|
19066
19251
|
} catch {
|
|
@@ -19218,6 +19403,8 @@ var SettingsPatch = z15.object({
|
|
|
19218
19403
|
ownerName: z15.string().trim().max(40),
|
|
19219
19404
|
/** How much Friend asks before acting. Loosening it is a change that needs the PIN. */
|
|
19220
19405
|
approvals: z15.enum(["manual", "edits", "auto"]),
|
|
19406
|
+
/** Where the code the assistant writes runs. Changing it needs the PIN. */
|
|
19407
|
+
codeRunner: z15.enum(["auto", "sandbox", "docker"]),
|
|
19221
19408
|
/** The audit trail. Owner-only. */
|
|
19222
19409
|
audit: z15.object({
|
|
19223
19410
|
keepDays: z15.number().int().min(0).max(3650),
|
|
@@ -19418,6 +19605,7 @@ function settingsView(c) {
|
|
|
19418
19605
|
view: c.view,
|
|
19419
19606
|
ownerName: c.ownerName,
|
|
19420
19607
|
approvals: c.approvals,
|
|
19608
|
+
codeRunner: c.codeRunner,
|
|
19421
19609
|
phoneApprovals: { ...c.phoneApprovals },
|
|
19422
19610
|
audit: { ...c.audit },
|
|
19423
19611
|
channels: {
|
|
@@ -19651,6 +19839,7 @@ function applySettings(config, raw) {
|
|
|
19651
19839
|
if (launcher) config.hud.launcher = sanitizeHud({ launcher }).launcher;
|
|
19652
19840
|
}
|
|
19653
19841
|
if (p.approvals) config.approvals = p.approvals;
|
|
19842
|
+
if (p.codeRunner) config.codeRunner = p.codeRunner;
|
|
19654
19843
|
if (p.phoneApprovals) Object.assign(config.phoneApprovals, p.phoneApprovals);
|
|
19655
19844
|
if (p.audit) Object.assign(config.audit, p.audit);
|
|
19656
19845
|
if (p.channels) {
|
|
@@ -20073,10 +20262,10 @@ function dbWidgetStore(db) {
|
|
|
20073
20262
|
}
|
|
20074
20263
|
|
|
20075
20264
|
// ../server/src/tls.ts
|
|
20076
|
-
import { chmodSync as chmodSync9, existsSync as
|
|
20265
|
+
import { chmodSync as chmodSync9, existsSync as existsSync23, mkdirSync as mkdirSync16, readFileSync as readFileSync15, writeFileSync as writeFileSync17 } from "node:fs";
|
|
20077
20266
|
import { networkInterfaces } from "node:os";
|
|
20078
20267
|
import { isIP as isIP4 } from "node:net";
|
|
20079
|
-
import { join as
|
|
20268
|
+
import { join as join26 } from "node:path";
|
|
20080
20269
|
import { generate } from "selfsigned";
|
|
20081
20270
|
var DAYS = 825;
|
|
20082
20271
|
var RENEW_BEFORE_MS = 30 * 24 * 36e5;
|
|
@@ -20091,12 +20280,12 @@ function tlsHosts(extra = [], ifaces) {
|
|
|
20091
20280
|
return [.../* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", ...lanAddresses(ifaces), ...extra.map((h) => h.toLowerCase()).filter(Boolean)])];
|
|
20092
20281
|
}
|
|
20093
20282
|
async function ensureTlsCert(dataDir, extraHosts = [], ifaces, now = Date.now) {
|
|
20094
|
-
const dir =
|
|
20095
|
-
const keyFile =
|
|
20096
|
-
const certFile =
|
|
20097
|
-
const metaFile =
|
|
20283
|
+
const dir = join26(dataDir, "tls");
|
|
20284
|
+
const keyFile = join26(dir, "key.pem");
|
|
20285
|
+
const certFile = join26(dir, "cert.pem");
|
|
20286
|
+
const metaFile = join26(dir, "meta.json");
|
|
20098
20287
|
const hosts = tlsHosts(extraHosts, ifaces);
|
|
20099
|
-
if (
|
|
20288
|
+
if (existsSync23(keyFile) && existsSync23(certFile) && existsSync23(metaFile)) {
|
|
20100
20289
|
try {
|
|
20101
20290
|
const meta = JSON.parse(readFileSync15(metaFile, "utf8"));
|
|
20102
20291
|
const covered = hosts.every((h) => meta.hosts.includes(h));
|
|
@@ -20166,10 +20355,10 @@ var DuckController = class {
|
|
|
20166
20355
|
};
|
|
20167
20356
|
|
|
20168
20357
|
// ../server/src/system/autostart.ts
|
|
20169
|
-
import { spawn as
|
|
20170
|
-
import { existsSync as
|
|
20358
|
+
import { spawn as spawn9 } from "node:child_process";
|
|
20359
|
+
import { existsSync as existsSync24, mkdirSync as mkdirSync17, readFileSync as readFileSync16, rmSync as rmSync12, writeFileSync as writeFileSync18 } from "node:fs";
|
|
20171
20360
|
import { homedir as homedir4 } from "node:os";
|
|
20172
|
-
import { dirname as
|
|
20361
|
+
import { dirname as dirname6, posix as posix4, win32 as win324 } from "node:path";
|
|
20173
20362
|
var RUN_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
20174
20363
|
var NAME2 = "Friend";
|
|
20175
20364
|
var LABEL = "com.friend.assistant";
|
|
@@ -20344,7 +20533,7 @@ function realAutostartDeps(dataDir) {
|
|
|
20344
20533
|
uid: typeof process.getuid === "function" ? process.getuid() : 0,
|
|
20345
20534
|
path: process.env.PATH ?? "",
|
|
20346
20535
|
...process.env.XDG_CONFIG_HOME ? { configHome: process.env.XDG_CONFIG_HOME } : {},
|
|
20347
|
-
exists: (p) =>
|
|
20536
|
+
exists: (p) => existsSync24(p),
|
|
20348
20537
|
read: (p) => {
|
|
20349
20538
|
try {
|
|
20350
20539
|
return readFileSync16(p, "utf8");
|
|
@@ -20353,13 +20542,13 @@ function realAutostartDeps(dataDir) {
|
|
|
20353
20542
|
}
|
|
20354
20543
|
},
|
|
20355
20544
|
write: (p, text4) => {
|
|
20356
|
-
mkdirSync17(
|
|
20545
|
+
mkdirSync17(dirname6(p), { recursive: true });
|
|
20357
20546
|
writeFileSync18(p, text4);
|
|
20358
20547
|
},
|
|
20359
20548
|
remove: (p) => rmSync12(p, { force: true }),
|
|
20360
20549
|
run: (cmd, args) => new Promise((resolve13) => {
|
|
20361
20550
|
let out = "";
|
|
20362
|
-
const child =
|
|
20551
|
+
const child = spawn9(cmd, args, { stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
20363
20552
|
child.stdout?.on("data", (d) => out += d.toString());
|
|
20364
20553
|
child.stderr?.on("data", (d) => out += d.toString());
|
|
20365
20554
|
child.on("error", () => resolve13({ code: 127, stdout: out }));
|
|
@@ -20373,9 +20562,9 @@ function currentSelf() {
|
|
|
20373
20562
|
}
|
|
20374
20563
|
|
|
20375
20564
|
// ../server/src/system/npm.ts
|
|
20376
|
-
import { spawn as
|
|
20565
|
+
import { spawn as spawn10 } from "node:child_process";
|
|
20377
20566
|
var PACKAGE = "friend-assistant";
|
|
20378
|
-
var runningVersion = () => true ? "0.1.
|
|
20567
|
+
var runningVersion = () => true ? "0.1.74" : "development";
|
|
20379
20568
|
async function npmLatest(fetchFn = fetch, timeoutMs = 1e4) {
|
|
20380
20569
|
try {
|
|
20381
20570
|
const res = await fetchFn(`https://registry.npmjs.org/${PACKAGE}/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
|
|
@@ -20390,7 +20579,7 @@ var ps = (s) => `'${s.replace(/'/g, "''")}'`;
|
|
|
20390
20579
|
function spawnUpgrade(self, platform = process.platform) {
|
|
20391
20580
|
if (!self.node || !self.script) return false;
|
|
20392
20581
|
try {
|
|
20393
|
-
const child = platform === "win32" ?
|
|
20582
|
+
const child = platform === "win32" ? spawn10("powershell.exe", ["-NoProfile", "-NonInteractive", "-WindowStyle", "Hidden", "-Command", `Start-Process -WindowStyle Hidden -FilePath ${ps(self.node)} -ArgumentList ${ps(`"${self.script}"`)},'upgrade','--auto'`], { detached: true, stdio: "ignore", windowsHide: true }) : spawn10(self.node, [self.script, "upgrade", "--auto"], { detached: true, stdio: "ignore" });
|
|
20394
20583
|
child.on("error", () => {
|
|
20395
20584
|
});
|
|
20396
20585
|
child.unref();
|
|
@@ -20588,18 +20777,18 @@ var Challenges = class {
|
|
|
20588
20777
|
|
|
20589
20778
|
// ../server/src/voice/crypto.ts
|
|
20590
20779
|
import { createCipheriv as createCipheriv2, createDecipheriv as createDecipheriv2, randomBytes as randomBytes13 } from "node:crypto";
|
|
20591
|
-
import { chmodSync as chmodSync10, existsSync as
|
|
20592
|
-
import { dirname as
|
|
20780
|
+
import { chmodSync as chmodSync10, existsSync as existsSync25, mkdirSync as mkdirSync18, readFileSync as readFileSync17, writeFileSync as writeFileSync19 } from "node:fs";
|
|
20781
|
+
import { dirname as dirname7 } from "node:path";
|
|
20593
20782
|
var KEY_BYTES = 32;
|
|
20594
20783
|
var IV_BYTES = 12;
|
|
20595
20784
|
var TAG_BYTES = 16;
|
|
20596
20785
|
function loadOrCreateKey(path3) {
|
|
20597
|
-
if (
|
|
20786
|
+
if (existsSync25(path3)) {
|
|
20598
20787
|
const key3 = readFileSync17(path3);
|
|
20599
20788
|
if (key3.length !== KEY_BYTES) throw new Error(`invalid voice key file (expected ${KEY_BYTES} bytes): ${path3}`);
|
|
20600
20789
|
return key3;
|
|
20601
20790
|
}
|
|
20602
|
-
mkdirSync18(
|
|
20791
|
+
mkdirSync18(dirname7(path3), { recursive: true });
|
|
20603
20792
|
const key2 = randomBytes13(KEY_BYTES);
|
|
20604
20793
|
writeFileSync19(path3, key2, { mode: 384 });
|
|
20605
20794
|
try {
|
|
@@ -21239,17 +21428,17 @@ async function createApp(opts) {
|
|
|
21239
21428
|
void musicLibrary.scan().catch(() => {
|
|
21240
21429
|
});
|
|
21241
21430
|
const memory = new Memory(db);
|
|
21242
|
-
const memoryTree = new MemoryTree(
|
|
21431
|
+
const memoryTree = new MemoryTree(join27(opts.dataDir, "memory"));
|
|
21243
21432
|
if (config.memory.enabled) {
|
|
21244
21433
|
memoryTree.ensure();
|
|
21245
21434
|
importFlatNotes(memory, memoryTree);
|
|
21246
21435
|
memoryTree.repair();
|
|
21247
21436
|
}
|
|
21248
|
-
const soul = new Soul(memoryTree,
|
|
21437
|
+
const soul = new Soul(memoryTree, join27(opts.dataDir, "soul-history"));
|
|
21249
21438
|
soul.ensure();
|
|
21250
|
-
const browserHub = new BrowserHub({ config: () => config.browser, tmpRoot:
|
|
21439
|
+
const browserHub = new BrowserHub({ config: () => config.browser, tmpRoot: join27(opts.dataDir, "browser-profiles") });
|
|
21251
21440
|
const tasks = new Tasks(db);
|
|
21252
|
-
const plugins = new Plugins(db,
|
|
21441
|
+
const plugins = new Plugins(db, join27(opts.dataDir, "plugins"));
|
|
21253
21442
|
const hub = new McpHub(new ConnectorStore(opts.dataDir));
|
|
21254
21443
|
let listenPort = config.port;
|
|
21255
21444
|
const provisioner = opts.video?.provisioner ?? new Provisioner({ dataDir: opts.dataDir, onError: (name, why) => audit.log("system", "video.provision_failed", { name, why: why.slice(0, 200) }) });
|
|
@@ -21361,13 +21550,13 @@ async function createApp(opts) {
|
|
|
21361
21550
|
if (id2 === "audius") return changeAudiusConfig((s) => changeAudius(s, change));
|
|
21362
21551
|
if (id2 === "browser") {
|
|
21363
21552
|
const err2 = changeBrowserConfig((b) => changeBrowser(b, change, !!browserHub.status().chrome));
|
|
21364
|
-
if (!err2 && "install" in change && listCatalog(catalogDir).some((c) => c.id === BROWSER_SKILL)) plugins.install(
|
|
21553
|
+
if (!err2 && "install" in change && listCatalog(catalogDir).some((c) => c.id === BROWSER_SKILL)) plugins.install(join27(catalogDir, BROWSER_SKILL));
|
|
21365
21554
|
if (!err2 && "remove" in change) plugins.remove(BROWSER_SKILL);
|
|
21366
21555
|
return err2;
|
|
21367
21556
|
}
|
|
21368
21557
|
if (id2 === "tavily") {
|
|
21369
21558
|
const err2 = changeTavilyConfig((t) => changeTavily(t, change, !!config.web.tavilyKey));
|
|
21370
|
-
if (!err2 && "install" in change && listCatalog(catalogDir).some((c) => c.id === TAVILY_SKILL)) plugins.install(
|
|
21559
|
+
if (!err2 && "install" in change && listCatalog(catalogDir).some((c) => c.id === TAVILY_SKILL)) plugins.install(join27(catalogDir, TAVILY_SKILL));
|
|
21371
21560
|
if (!err2 && "remove" in change) plugins.remove(TAVILY_SKILL);
|
|
21372
21561
|
return err2;
|
|
21373
21562
|
}
|
|
@@ -21398,7 +21587,7 @@ async function createApp(opts) {
|
|
|
21398
21587
|
}
|
|
21399
21588
|
if (id2 !== "zerodha") return changeChannels((c) => changeIntegration(c, id2, change));
|
|
21400
21589
|
const err = changeBrokers((b) => changeBroker(b, id2, change, (gone) => brokerHub.forget(gone)));
|
|
21401
|
-
if (!err && "install" in change && listCatalog(catalogDir).some((c) => c.id === PORTFOLIO_SKILL)) plugins.install(
|
|
21590
|
+
if (!err && "install" in change && listCatalog(catalogDir).some((c) => c.id === PORTFOLIO_SKILL)) plugins.install(join27(catalogDir, PORTFOLIO_SKILL));
|
|
21402
21591
|
if (!err && "remove" in change) plugins.remove(PORTFOLIO_SKILL);
|
|
21403
21592
|
return err;
|
|
21404
21593
|
};
|
|
@@ -21414,7 +21603,7 @@ async function createApp(opts) {
|
|
|
21414
21603
|
},
|
|
21415
21604
|
install: (id2) => {
|
|
21416
21605
|
if (!listCatalog(catalogDir).some((c) => c.id === id2)) return { ok: false, error: "That plugin is not in the catalog." };
|
|
21417
|
-
return plugins.install(
|
|
21606
|
+
return plugins.install(join27(catalogDir, id2));
|
|
21418
21607
|
}
|
|
21419
21608
|
},
|
|
21420
21609
|
integrations: {
|
|
@@ -21708,7 +21897,7 @@ First check the work: read the whole report (office.report) and, when it changed
|
|
|
21708
21897
|
tasks,
|
|
21709
21898
|
plugins,
|
|
21710
21899
|
weather: weatherService,
|
|
21711
|
-
code: opts.codeBox ?? new CodeBox(),
|
|
21900
|
+
code: opts.codeBox ?? new CodeBox(void 0, { mode: () => config.codeRunner }),
|
|
21712
21901
|
camera: {
|
|
21713
21902
|
request: (emit, signal) => {
|
|
21714
21903
|
audit.log("agent", "camera.requested", {});
|
|
@@ -21813,7 +22002,7 @@ First check the work: read the whole report (office.report) and, when it changed
|
|
|
21813
22002
|
const voice2 = opts.voice;
|
|
21814
22003
|
const speaker = voice2 ? new Speaker(voice2, audit, () => config.voice.ttsVoice, () => ({ hindi: config.voice.hindiVoice || void 0, marathi: config.voice.marathiVoice || void 0 })) : null;
|
|
21815
22004
|
const voiceAvailable = () => !!voice2 && voice2.available();
|
|
21816
|
-
const voiceKey = voice2 ? loadOrCreateKey(
|
|
22005
|
+
const voiceKey = voice2 ? loadOrCreateKey(join27(opts.dataDir, "voice.key")) : null;
|
|
21817
22006
|
const voiceprint = voiceKey ? new Voiceprint(db, voiceKey) : null;
|
|
21818
22007
|
const enrollment = voiceprint ? new Enrollment(voiceprint, SPEAKER_MODEL) : null;
|
|
21819
22008
|
const household = voiceKey ? new Household(db, voiceKey) : null;
|
|
@@ -21898,7 +22087,7 @@ ${task.title}`) !== null,
|
|
|
21898
22087
|
}
|
|
21899
22088
|
},
|
|
21900
22089
|
audit,
|
|
21901
|
-
statePath:
|
|
22090
|
+
statePath: join27(opts.dataDir, "proactive.json")
|
|
21902
22091
|
});
|
|
21903
22092
|
async function requirePin(pin, ip) {
|
|
21904
22093
|
let ok2 = false;
|
|
@@ -21968,7 +22157,7 @@ ${task.title}`) !== null,
|
|
|
21968
22157
|
broadcast({ type: "voice.heard", text: held.text, trust: "owner" });
|
|
21969
22158
|
await runVoiceTurn(held.text, conn.ip, epoch);
|
|
21970
22159
|
}
|
|
21971
|
-
const here2 =
|
|
22160
|
+
const here2 = dirname8(fileURLToPath3(import.meta.url));
|
|
21972
22161
|
const catalogDir = opts.pluginCatalogDir ?? firstExistingDir([process.env.FRIEND_PLUGIN_CATALOG, resolve5(here2, "plugins"), resolve5(here2, "../../..", "plugins")]) ?? resolve5(here2, "plugins");
|
|
21973
22162
|
const pluginsApi = {
|
|
21974
22163
|
list: () => {
|
|
@@ -21989,7 +22178,7 @@ ${task.title}`) !== null,
|
|
|
21989
22178
|
if (!isPluginId(id2)) throw new HttpError(400, "That is not a plugin name.");
|
|
21990
22179
|
if (!listCatalog(catalogDir).some((c) => c.id === id2)) throw new HttpError(404, "That plugin is not in the catalog.");
|
|
21991
22180
|
await requirePin(pin, ip);
|
|
21992
|
-
const r = plugins.install(
|
|
22181
|
+
const r = plugins.install(join27(catalogDir, id2));
|
|
21993
22182
|
if (!r.ok) throw new HttpError(400, `That plugin cannot be installed: ${r.error}`);
|
|
21994
22183
|
audit.log("owner", "plugin.installed", { id: r.id, upgraded: r.upgraded, ip });
|
|
21995
22184
|
return { id: r.id, upgraded: r.upgraded };
|
|
@@ -22799,7 +22988,7 @@ ${url}`);
|
|
|
22799
22988
|
}
|
|
22800
22989
|
const prune = () => {
|
|
22801
22990
|
try {
|
|
22802
|
-
const r = pruneAudit(db, { keepDays: config.audit.keepDays, archive: config.audit.archive, dir:
|
|
22991
|
+
const r = pruneAudit(db, { keepDays: config.audit.keepDays, archive: config.audit.archive, dir: join27(opts.dataDir, "audit-archive"), now: Date.now() });
|
|
22803
22992
|
if (r.removed) audit.log("system", "audit.pruned", { removed: r.removed, archive: r.archivePath });
|
|
22804
22993
|
} catch (e) {
|
|
22805
22994
|
audit.log("system", "audit.prune_failed", { message: e.message.slice(0, 200) });
|
|
@@ -22893,7 +23082,7 @@ ${url}`);
|
|
|
22893
23082
|
}
|
|
22894
23083
|
|
|
22895
23084
|
// ../server/src/voice/sidecar.ts
|
|
22896
|
-
import { spawn as
|
|
23085
|
+
import { spawn as spawn11 } from "node:child_process";
|
|
22897
23086
|
import { createInterface } from "node:readline";
|
|
22898
23087
|
var SidecarProcess = class {
|
|
22899
23088
|
constructor(opts) {
|
|
@@ -22930,7 +23119,7 @@ var SidecarProcess = class {
|
|
|
22930
23119
|
settled = true;
|
|
22931
23120
|
reject(new Error(message));
|
|
22932
23121
|
};
|
|
22933
|
-
const child =
|
|
23122
|
+
const child = spawn11(this.opts.command, this.opts.args, {
|
|
22934
23123
|
cwd: this.opts.cwd,
|
|
22935
23124
|
env: { ...this.opts.env ?? process.env, FRIEND_VOICE_TOKEN: this.opts.token },
|
|
22936
23125
|
windowsHide: true,
|
|
@@ -23062,6 +23251,10 @@ var PARSERS = {
|
|
|
23062
23251
|
if (v !== "manual" && v !== "edits" && v !== "auto") throw new Error("approvals must be manual, edits or auto");
|
|
23063
23252
|
return v;
|
|
23064
23253
|
},
|
|
23254
|
+
codeRunner: (v) => {
|
|
23255
|
+
if (v !== "auto" && v !== "sandbox" && v !== "docker") throw new Error("codeRunner must be auto, sandbox or docker");
|
|
23256
|
+
return v;
|
|
23257
|
+
},
|
|
23065
23258
|
https: bool,
|
|
23066
23259
|
port: (v) => {
|
|
23067
23260
|
const n2 = Number(v);
|
|
@@ -23213,6 +23406,7 @@ var KEY_HELP = {
|
|
|
23213
23406
|
port: "the web port (easier: friend lan port N)",
|
|
23214
23407
|
https: "true serves a secure https:// address (Friend makes its own certificate), so a phone may use the microphone (easier: friend lan https on)",
|
|
23215
23408
|
publicUrl: "the address people use when Friend is behind your own domain, or empty",
|
|
23409
|
+
codeRunner: "where code the assistant writes runs: auto (Docker if it works, otherwise the built-in sandbox), sandbox (always the built-in one, nothing to install) or docker (always Docker)",
|
|
23216
23410
|
approvals: "how much Friend asks before acting: manual (asks every time), edits (file work and sandboxed code go ahead) or auto (everything goes ahead except risky commands, the camera and changes to connectors/plugins). Easier: Esc \u2192 Settings \u2192 Approvals",
|
|
23217
23411
|
ownerName: "your name, shown on the profile badge (the shield) in the corner of the screen; empty shows Owner",
|
|
23218
23412
|
roots: "folders Friend may read and write freely, separated by commas",
|
|
@@ -23306,11 +23500,11 @@ import { WebSocket as WebSocket4 } from "ws";
|
|
|
23306
23500
|
|
|
23307
23501
|
// ../agent-cli/src/tools/fs.ts
|
|
23308
23502
|
import { closeSync, mkdirSync as mkdirSync19, openSync, readSync, readdirSync as readdirSync8, statSync as statSync7, writeFileSync as writeFileSync20 } from "node:fs";
|
|
23309
|
-
import { dirname as
|
|
23503
|
+
import { dirname as dirname10, join as join28 } from "node:path";
|
|
23310
23504
|
|
|
23311
23505
|
// ../agent-cli/src/tools/roots.ts
|
|
23312
|
-
import { lstatSync as lstatSync3, realpathSync } from "node:fs";
|
|
23313
|
-
import { dirname as
|
|
23506
|
+
import { lstatSync as lstatSync3, realpathSync as realpathSync2 } from "node:fs";
|
|
23507
|
+
import { dirname as dirname9, isAbsolute as isAbsolute2, relative as relative3, resolve as resolve6, sep as sep4 } from "node:path";
|
|
23314
23508
|
var isWin = process.platform === "win32";
|
|
23315
23509
|
var norm = (p) => isWin ? p.toLowerCase() : p;
|
|
23316
23510
|
var exists = (p) => {
|
|
@@ -23326,14 +23520,14 @@ function realish(abs) {
|
|
|
23326
23520
|
let cur = abs;
|
|
23327
23521
|
const tail2 = [];
|
|
23328
23522
|
while (!exists(cur)) {
|
|
23329
|
-
const parent =
|
|
23523
|
+
const parent = dirname9(cur);
|
|
23330
23524
|
if (parent === cur) return abs;
|
|
23331
23525
|
tail2.unshift(cur.slice(parent.length).replace(/^[\\/]+/, ""));
|
|
23332
23526
|
cur = parent;
|
|
23333
23527
|
}
|
|
23334
23528
|
let real3;
|
|
23335
23529
|
try {
|
|
23336
|
-
real3 =
|
|
23530
|
+
real3 = realpathSync2.native(cur);
|
|
23337
23531
|
} catch {
|
|
23338
23532
|
return UNRESOLVABLE + abs;
|
|
23339
23533
|
}
|
|
@@ -23342,7 +23536,7 @@ function realish(abs) {
|
|
|
23342
23536
|
function within2(root, target) {
|
|
23343
23537
|
if (target.startsWith(UNRESOLVABLE)) return false;
|
|
23344
23538
|
const rel = relative3(norm(root), norm(target));
|
|
23345
|
-
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel) && !rel.split(
|
|
23539
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel) && !rel.split(sep4).includes("..");
|
|
23346
23540
|
}
|
|
23347
23541
|
function resolveInRoots(p, roots) {
|
|
23348
23542
|
const base = roots[0] ?? process.cwd();
|
|
@@ -23368,7 +23562,7 @@ function fsList(args, ctx) {
|
|
|
23368
23562
|
if (e.isDirectory()) return `[dir] ${e.name}`;
|
|
23369
23563
|
let size = 0;
|
|
23370
23564
|
try {
|
|
23371
|
-
size = statSync7(
|
|
23565
|
+
size = statSync7(join28(g.abs, e.name)).size;
|
|
23372
23566
|
} catch {
|
|
23373
23567
|
}
|
|
23374
23568
|
return `[file] ${e.name} (${size} bytes)`;
|
|
@@ -23409,7 +23603,7 @@ function fsWrite(args, ctx) {
|
|
|
23409
23603
|
if ("error" in g) return { ok: false, error: g.error };
|
|
23410
23604
|
if (Buffer.byteLength(args.content) > MAX_WRITE) return { ok: false, error: "Content too large (5 MB limit)" };
|
|
23411
23605
|
try {
|
|
23412
|
-
mkdirSync19(
|
|
23606
|
+
mkdirSync19(dirname10(g.abs), { recursive: true });
|
|
23413
23607
|
writeFileSync20(g.abs, args.content);
|
|
23414
23608
|
return { ok: true, output: `Wrote ${Buffer.byteLength(args.content)} bytes to ${g.abs}`, truncated: false };
|
|
23415
23609
|
} catch (e) {
|
|
@@ -23418,7 +23612,7 @@ function fsWrite(args, ctx) {
|
|
|
23418
23612
|
}
|
|
23419
23613
|
|
|
23420
23614
|
// ../agent-cli/src/tools/shell.ts
|
|
23421
|
-
import { spawn as
|
|
23615
|
+
import { spawn as spawn12, spawnSync as spawnSync2 } from "node:child_process";
|
|
23422
23616
|
function killTree2(child) {
|
|
23423
23617
|
if (!child.pid) return;
|
|
23424
23618
|
if (process.platform === "win32") {
|
|
@@ -23444,7 +23638,7 @@ function runCommand2(command, cwdArg, ctx, argv) {
|
|
|
23444
23638
|
const file = argv?.file ?? (win ? "powershell.exe" : "sh");
|
|
23445
23639
|
const args = argv?.args ?? (win ? ["-NoProfile", "-NonInteractive", "-Command", command] : ["-c", command]);
|
|
23446
23640
|
return new Promise((resolve13) => {
|
|
23447
|
-
const child =
|
|
23641
|
+
const child = spawn12(file, args, { cwd, windowsHide: true, detached: !win, stdio: ["ignore", "pipe", "pipe"] });
|
|
23448
23642
|
let out = "";
|
|
23449
23643
|
let truncated = false;
|
|
23450
23644
|
let timedOut = false;
|
|
@@ -23646,9 +23840,9 @@ function startDeviceNode(opts) {
|
|
|
23646
23840
|
|
|
23647
23841
|
// ../agent-cli/src/commands/start.ts
|
|
23648
23842
|
import { randomBytes as randomBytes14 } from "node:crypto";
|
|
23649
|
-
import { existsSync as
|
|
23650
|
-
import { dirname as
|
|
23651
|
-
import { fileURLToPath as
|
|
23843
|
+
import { existsSync as existsSync27, readFileSync as readFileSync19, writeFileSync as writeFileSync22 } from "node:fs";
|
|
23844
|
+
import { dirname as dirname12, join as join30, resolve as resolve8 } from "node:path";
|
|
23845
|
+
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
23652
23846
|
|
|
23653
23847
|
// ../agent-cli/src/commands/lan.ts
|
|
23654
23848
|
import { networkInterfaces as networkInterfaces2 } from "node:os";
|
|
@@ -23752,19 +23946,19 @@ async function lanCommand(args, io2, ifaces = networkInterfaces2) {
|
|
|
23752
23946
|
}
|
|
23753
23947
|
|
|
23754
23948
|
// ../agent-cli/src/commands/voice.ts
|
|
23755
|
-
import { spawn as
|
|
23756
|
-
import { existsSync as
|
|
23757
|
-
import { dirname as
|
|
23758
|
-
import { fileURLToPath as
|
|
23949
|
+
import { spawn as spawn13 } from "node:child_process";
|
|
23950
|
+
import { existsSync as existsSync26, mkdirSync as mkdirSync20, readFileSync as readFileSync18, writeFileSync as writeFileSync21 } from "node:fs";
|
|
23951
|
+
import { dirname as dirname11, join as join29, resolve as resolve7 } from "node:path";
|
|
23952
|
+
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
23759
23953
|
function voicePaths(dataDir) {
|
|
23760
|
-
const home =
|
|
23761
|
-
const venv =
|
|
23954
|
+
const home = join29(dataDir, "voice");
|
|
23955
|
+
const venv = join29(home, "venv");
|
|
23762
23956
|
return {
|
|
23763
23957
|
home,
|
|
23764
23958
|
venv,
|
|
23765
|
-
python: process.platform === "win32" ?
|
|
23766
|
-
models:
|
|
23767
|
-
marker:
|
|
23959
|
+
python: process.platform === "win32" ? join29(venv, "Scripts", "python.exe") : join29(venv, "bin", "python"),
|
|
23960
|
+
models: join29(home, "models"),
|
|
23961
|
+
marker: join29(home, "installed.json")
|
|
23768
23962
|
};
|
|
23769
23963
|
}
|
|
23770
23964
|
function readMarker(dataDir) {
|
|
@@ -23775,13 +23969,13 @@ function readMarker(dataDir) {
|
|
|
23775
23969
|
}
|
|
23776
23970
|
}
|
|
23777
23971
|
function findVoiceDir() {
|
|
23778
|
-
const here2 =
|
|
23972
|
+
const here2 = dirname11(fileURLToPath4(import.meta.url));
|
|
23779
23973
|
return firstExistingDir([process.env.FRIEND_VOICE_DIR, resolve7(here2, "voice"), resolve7(here2, "../../../voice")], "friend_voice") ?? resolve7(here2, "voice");
|
|
23780
23974
|
}
|
|
23781
23975
|
var QUIET_ENV = { ...process.env, HF_HUB_DISABLE_SYMLINKS_WARNING: "1", PYTHONUTF8: "1" };
|
|
23782
23976
|
var defaultRunner = (cmd, args, opts) => new Promise((res) => {
|
|
23783
23977
|
let stdout = "";
|
|
23784
|
-
const child =
|
|
23978
|
+
const child = spawn13(cmd, args, { cwd: opts?.cwd, env: QUIET_ENV, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
23785
23979
|
const feed = (d) => {
|
|
23786
23980
|
const s = d.toString();
|
|
23787
23981
|
stdout += s;
|
|
@@ -23867,7 +24061,7 @@ async function voiceSetupCommand(io2, deps = {}, args = []) {
|
|
|
23867
24061
|
return 1;
|
|
23868
24062
|
}
|
|
23869
24063
|
mkdirSync20(p.home, { recursive: true });
|
|
23870
|
-
if (!
|
|
24064
|
+
if (!existsSync26(p.python)) {
|
|
23871
24065
|
io2.out("1/3 Creating a private Python environment\u2026");
|
|
23872
24066
|
const r = await run2(py.cmd, [...py.args, "-m", "venv", p.venv], { onLine });
|
|
23873
24067
|
if (r.code !== 0) {
|
|
@@ -23917,7 +24111,7 @@ async function voiceStatusCommand(io2) {
|
|
|
23917
24111
|
io2.out("Voice engine: not installed. Run: friend voice setup");
|
|
23918
24112
|
return 0;
|
|
23919
24113
|
}
|
|
23920
|
-
if (!
|
|
24114
|
+
if (!existsSync26(marker.python)) {
|
|
23921
24115
|
io2.out("Voice engine: installed, but its Python is missing. Run: friend voice setup");
|
|
23922
24116
|
return 0;
|
|
23923
24117
|
}
|
|
@@ -23988,9 +24182,9 @@ async function voiceCommand(args, io2) {
|
|
|
23988
24182
|
|
|
23989
24183
|
// ../agent-cli/src/commands/start.ts
|
|
23990
24184
|
function findWebDir(explicit) {
|
|
23991
|
-
const here2 =
|
|
24185
|
+
const here2 = dirname12(fileURLToPath5(import.meta.url));
|
|
23992
24186
|
const candidates = [explicit, process.env.FRIEND_WEB_DIR, resolve8(here2, "../../../web/dist"), resolve8(here2, "web")];
|
|
23993
|
-
return candidates.find((c) => !!c &&
|
|
24187
|
+
return candidates.find((c) => !!c && existsSync27(join30(c, "index.html")));
|
|
23994
24188
|
}
|
|
23995
24189
|
async function startFriend(opts) {
|
|
23996
24190
|
const stored = loadConfig(opts.dataDir);
|
|
@@ -24026,8 +24220,8 @@ async function startFriend(opts) {
|
|
|
24026
24220
|
}
|
|
24027
24221
|
});
|
|
24028
24222
|
const { port } = await app.start();
|
|
24029
|
-
const tokenFile =
|
|
24030
|
-
let token =
|
|
24223
|
+
const tokenFile = join30(opts.dataDir, "local-device.token");
|
|
24224
|
+
let token = existsSync27(tokenFile) ? readFileSync19(tokenFile, "utf8").trim() : "";
|
|
24031
24225
|
if (!token || !app.auth.resolveDevice(token)) {
|
|
24032
24226
|
token = app.auth.redeemPairCode(app.auth.createPairCode(), "this-pc");
|
|
24033
24227
|
writeFileSync22(tokenFile, token, { mode: 384 });
|
|
@@ -24036,7 +24230,7 @@ async function startFriend(opts) {
|
|
|
24036
24230
|
url: `${app.config.https ? "wss" : "ws"}://127.0.0.1:${port}/device`,
|
|
24037
24231
|
token,
|
|
24038
24232
|
roots: app.config.roots,
|
|
24039
|
-
...app.config.https ? { ca: readFileSync19(
|
|
24233
|
+
...app.config.https ? { ca: readFileSync19(join30(opts.dataDir, "tls", "cert.pem"), "utf8") } : {}
|
|
24040
24234
|
// this PC trusts only its own Friend's certificate
|
|
24041
24235
|
});
|
|
24042
24236
|
const urls = urlsFor(app.config.bind, port, void 0, app.config.https);
|
|
@@ -24206,8 +24400,8 @@ async function devicesCommand(args, io2) {
|
|
|
24206
24400
|
}
|
|
24207
24401
|
|
|
24208
24402
|
// ../agent-cli/src/commands/memory.ts
|
|
24209
|
-
import { existsSync as
|
|
24210
|
-
import { join as
|
|
24403
|
+
import { existsSync as existsSync28 } from "node:fs";
|
|
24404
|
+
import { join as join31 } from "node:path";
|
|
24211
24405
|
var USAGE = "Usage: friend memory list | friend memory show <path> | friend memory forget <path or number> | friend memory clear";
|
|
24212
24406
|
async function memoryCommand(args, io2) {
|
|
24213
24407
|
const [sub, arg] = args;
|
|
@@ -24219,7 +24413,7 @@ async function memoryCommand(args, io2) {
|
|
|
24219
24413
|
try {
|
|
24220
24414
|
const memory = new Memory(db);
|
|
24221
24415
|
const audit = new Audit(db);
|
|
24222
|
-
const tree2 =
|
|
24416
|
+
const tree2 = existsSync28(join31(io2.dataDir, "memory", "INDEX.md")) ? new MemoryTree(join31(io2.dataDir, "memory")) : null;
|
|
24223
24417
|
if (sub === "show") {
|
|
24224
24418
|
if (!tree2 || !arg) {
|
|
24225
24419
|
io2.err(tree2 ? USAGE : "There is no memory tree yet.");
|
|
@@ -24298,12 +24492,12 @@ async function memoryCommand(args, io2) {
|
|
|
24298
24492
|
}
|
|
24299
24493
|
|
|
24300
24494
|
// ../agent-cli/src/commands/plugin.ts
|
|
24301
|
-
import { existsSync as
|
|
24302
|
-
import { dirname as
|
|
24303
|
-
import { fileURLToPath as
|
|
24495
|
+
import { existsSync as existsSync29, readdirSync as readdirSync9, statSync as statSync8 } from "node:fs";
|
|
24496
|
+
import { dirname as dirname13, join as join32, resolve as resolve10 } from "node:path";
|
|
24497
|
+
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
24304
24498
|
var USAGE2 = "Usage: friend plugin catalog | list | install <name|folder> [--yes] | enable <id> | disable <id> | remove <id>";
|
|
24305
24499
|
function defaultCatalog() {
|
|
24306
|
-
const here2 =
|
|
24500
|
+
const here2 = dirname13(fileURLToPath6(import.meta.url));
|
|
24307
24501
|
return firstExistingDir([process.env.FRIEND_PLUGIN_CATALOG, resolve10(here2, "plugins"), resolve10(here2, "../../../../plugins")]) ?? resolve10(here2, "plugins");
|
|
24308
24502
|
}
|
|
24309
24503
|
var count2 = (n2, word2) => `${n2} ${word2}${n2 === 1 ? "" : "s"}`;
|
|
@@ -24313,10 +24507,10 @@ async function pluginCommand(args, io2, deps = {}) {
|
|
|
24313
24507
|
const flags = rest.filter((a) => a.startsWith("--"));
|
|
24314
24508
|
const arg = rest.find((a) => !a.startsWith("--"));
|
|
24315
24509
|
if (sub === "catalog") {
|
|
24316
|
-
const dirs =
|
|
24510
|
+
const dirs = existsSync29(catalogDir) ? readdirSync9(catalogDir).filter((d) => statSync8(join32(catalogDir, d)).isDirectory()) : [];
|
|
24317
24511
|
if (dirs.length === 0) io2.out("The catalog is empty.");
|
|
24318
24512
|
for (const d of dirs.sort()) {
|
|
24319
|
-
const r = inspectPlugin(
|
|
24513
|
+
const r = inspectPlugin(join32(catalogDir, d));
|
|
24320
24514
|
if (!r.ok) {
|
|
24321
24515
|
io2.out(`${d} (invalid: ${r.error})`);
|
|
24322
24516
|
continue;
|
|
@@ -24332,7 +24526,7 @@ async function pluginCommand(args, io2, deps = {}) {
|
|
|
24332
24526
|
}
|
|
24333
24527
|
const db = openDb(io2.dataDir);
|
|
24334
24528
|
try {
|
|
24335
|
-
const plugins = new Plugins(db,
|
|
24529
|
+
const plugins = new Plugins(db, join32(io2.dataDir, "plugins"));
|
|
24336
24530
|
if (sub === "list") {
|
|
24337
24531
|
const all = plugins.list();
|
|
24338
24532
|
if (all.length === 0) io2.out("No plugins installed. See: friend plugin catalog");
|
|
@@ -24346,8 +24540,8 @@ async function pluginCommand(args, io2, deps = {}) {
|
|
|
24346
24540
|
io2.err(USAGE2);
|
|
24347
24541
|
return 1;
|
|
24348
24542
|
}
|
|
24349
|
-
const inCatalog = !/[\\/]/.test(arg) &&
|
|
24350
|
-
const source = inCatalog ?
|
|
24543
|
+
const inCatalog = !/[\\/]/.test(arg) && existsSync29(join32(catalogDir, arg));
|
|
24544
|
+
const source = inCatalog ? join32(catalogDir, arg) : existsSync29(resolve10(arg)) ? resolve10(arg) : null;
|
|
24351
24545
|
if (!source) {
|
|
24352
24546
|
io2.err(`"${arg}" is not in the catalog and there is no such folder. See: friend plugin catalog`);
|
|
24353
24547
|
return 1;
|
|
@@ -24364,7 +24558,7 @@ async function pluginCommand(args, io2, deps = {}) {
|
|
|
24364
24558
|
if (m.skills.length) io2.out(`Skills (${m.skills.length}): ${m.skills.map((s) => s.name).join(", ")}`);
|
|
24365
24559
|
if (m.tools.length) {
|
|
24366
24560
|
io2.out(`Tools (${m.tools.length}): ${m.tools.map((t) => t.name).join(", ")}`);
|
|
24367
|
-
io2.out(" Tools run in a Docker
|
|
24561
|
+
io2.out(" Tools run in a sandbox (Docker if you have it, otherwise the one built into Friend) with no network and no access to your files, and ask for your approval every time.");
|
|
24368
24562
|
}
|
|
24369
24563
|
io2.out(`Files: ${r.files}, ${Math.max(1, Math.round(r.bytes / 1024))} KB`);
|
|
24370
24564
|
if (!flags.includes("--yes")) {
|
|
@@ -24636,7 +24830,7 @@ async function checkPython(d) {
|
|
|
24636
24830
|
return { ...base, ok: true, detail: first2(v.stdout) || "Python 3.10 or newer" };
|
|
24637
24831
|
}
|
|
24638
24832
|
async function checkDocker(d) {
|
|
24639
|
-
const base = { id: "docker", label: "Docker", need: "optional", unlocks: "
|
|
24833
|
+
const base = { id: "docker", label: "Docker", need: "optional", unlocks: "a real container for scripts the built-in sandbox cannot run (the built-in sandbox needs nothing installed)" };
|
|
24640
24834
|
const v = await d.run("docker", ["--version"]);
|
|
24641
24835
|
if (v.code !== 0) return { ...base, ok: false, detail: "not installed" };
|
|
24642
24836
|
const info = await d.run("docker", ["info", "--format", "{{.ServerVersion}}"]);
|
|
@@ -24725,14 +24919,14 @@ function installPlan(id2, platform, have) {
|
|
|
24725
24919
|
}
|
|
24726
24920
|
|
|
24727
24921
|
// ../agent-cli/src/commands/onboard/state.ts
|
|
24728
|
-
import { existsSync as
|
|
24729
|
-
import { dirname as
|
|
24922
|
+
import { existsSync as existsSync30, mkdirSync as mkdirSync21, readFileSync as readFileSync20, renameSync as renameSync5, rmSync as rmSync13, writeFileSync as writeFileSync23 } from "node:fs";
|
|
24923
|
+
import { dirname as dirname14, join as join33 } from "node:path";
|
|
24730
24924
|
var FEATURES = ["claude-code", "claude-api", "ollama", "voice", "sandbox"];
|
|
24731
24925
|
var emptyState = () => ({ version: 1, done: {}, features: [], restart: [] });
|
|
24732
|
-
var statePath = (dataDir) =>
|
|
24926
|
+
var statePath = (dataDir) => join33(dataDir, "onboarding.json");
|
|
24733
24927
|
function loadState(dataDir) {
|
|
24734
24928
|
const f = statePath(dataDir);
|
|
24735
|
-
if (!
|
|
24929
|
+
if (!existsSync30(f)) return emptyState();
|
|
24736
24930
|
try {
|
|
24737
24931
|
const raw = JSON.parse(readFileSync20(f, "utf8"));
|
|
24738
24932
|
const done = raw.done && typeof raw.done === "object" ? Object.fromEntries(Object.entries(raw.done).filter(([, v]) => typeof v === "string")) : {};
|
|
@@ -24745,7 +24939,7 @@ function loadState(dataDir) {
|
|
|
24745
24939
|
}
|
|
24746
24940
|
function saveState(dataDir, state) {
|
|
24747
24941
|
const f = statePath(dataDir);
|
|
24748
|
-
mkdirSync21(
|
|
24942
|
+
mkdirSync21(dirname14(f), { recursive: true });
|
|
24749
24943
|
const tmp = `${f}.tmp`;
|
|
24750
24944
|
writeFileSync23(tmp, JSON.stringify(state, null, 2));
|
|
24751
24945
|
renameSync5(tmp, f);
|
|
@@ -24845,7 +25039,7 @@ function defaultOnboardDeps() {
|
|
|
24845
25039
|
ollamaSetup: (io2, args) => ollamaCommand(args, io2, { run: capture })
|
|
24846
25040
|
};
|
|
24847
25041
|
}
|
|
24848
|
-
var FEATURE_PREREQ = { "claude-code": "claude", ollama: "ollama", voice: "python"
|
|
25042
|
+
var FEATURE_PREREQ = { "claude-code": "claude", ollama: "ollama", voice: "python" };
|
|
24849
25043
|
var has = (c, f) => c.state.features.includes(f);
|
|
24850
25044
|
var save = (c) => saveState(c.io.dataDir, c.state);
|
|
24851
25045
|
async function welcome(c) {
|
|
@@ -24872,7 +25066,7 @@ async function features(c) {
|
|
|
24872
25066
|
{ key: "claude-api", label: "Claude, with an API key", hint: "pay per use" },
|
|
24873
25067
|
{ key: "ollama", label: "A model on this PC with Ollama", hint: "free and private, but slower" },
|
|
24874
25068
|
{ key: "voice", label: "Voice: talk to Friend and hear it", hint: "needs Python, about 250 MB" },
|
|
24875
|
-
{ key: "sandbox", label: "Safe code running and plugin tools", hint: "
|
|
25069
|
+
{ key: "sandbox", label: "Safe code running and plugin tools", hint: "built in, nothing to install (Docker is optional)" }
|
|
24876
25070
|
],
|
|
24877
25071
|
["claude-code", "voice"]
|
|
24878
25072
|
);
|
|
@@ -25358,7 +25552,7 @@ async function usageCommand(args, io2, log) {
|
|
|
25358
25552
|
|
|
25359
25553
|
// ../agent-cli/src/commands/audit.ts
|
|
25360
25554
|
import { writeFileSync as writeFileSync24 } from "node:fs";
|
|
25361
|
-
import { join as
|
|
25555
|
+
import { join as join34 } from "node:path";
|
|
25362
25556
|
var USAGE5 = [
|
|
25363
25557
|
"Usage: friend audit list [--since 2h|1d|7d] [--who owner|assistant|worker|system|outsider|<worker name>] [--group approvals|tools|workers|logins|messages|settings|system] [--result refused|failed|done] [--q text] [--limit N]",
|
|
25364
25558
|
" friend audit show <request-id>",
|
|
@@ -25463,7 +25657,7 @@ async function auditCommand(args, io2, deps = {}) {
|
|
|
25463
25657
|
afterwards = async (res2) => {
|
|
25464
25658
|
const raw = /filename="([^"]+)"/.exec(res2.headers.get("content-disposition") ?? "")?.[1] ?? `friend-audit.${f.query.format}`;
|
|
25465
25659
|
const name = (raw.split(/[\\/]/).pop() ?? "friend-audit").replace(/[^A-Za-z0-9._-]/g, "_") || "friend-audit";
|
|
25466
|
-
(deps.write ?? ((n2, b) => writeFileSync24(
|
|
25660
|
+
(deps.write ?? ((n2, b) => writeFileSync24(join34(process.cwd(), n2), b)))(name, await res2.text());
|
|
25467
25661
|
io2.out(`Saved ${name} in this folder. It contains private content: keep it safe.`);
|
|
25468
25662
|
return 0;
|
|
25469
25663
|
};
|
|
@@ -25490,10 +25684,10 @@ async function auditCommand(args, io2, deps = {}) {
|
|
|
25490
25684
|
}
|
|
25491
25685
|
|
|
25492
25686
|
// ../agent-cli/src/commands/daemon.ts
|
|
25493
|
-
import { spawn as
|
|
25494
|
-
import { closeSync as closeSync2, existsSync as
|
|
25687
|
+
import { spawn as spawn14, spawnSync as spawnSync3 } from "node:child_process";
|
|
25688
|
+
import { closeSync as closeSync2, existsSync as existsSync31, mkdirSync as mkdirSync23, openSync as openSync2, readFileSync as readFileSync21, renameSync as renameSync6, rmSync as rmSync14, statSync as statSync9, writeFileSync as writeFileSync25 } from "node:fs";
|
|
25495
25689
|
import { connect } from "node:net";
|
|
25496
|
-
import { join as
|
|
25690
|
+
import { join as join35 } from "node:path";
|
|
25497
25691
|
var USAGE6 = "Usage: friend daemon start | stop | restart | status";
|
|
25498
25692
|
var MAX_LOG_BYTES = 5 * 1024 * 1024;
|
|
25499
25693
|
var sleep2 = (ms2) => new Promise((r) => setTimeout(r, ms2));
|
|
@@ -25501,7 +25695,7 @@ var realDeps = {
|
|
|
25501
25695
|
launch(logFile) {
|
|
25502
25696
|
const fd = openSync2(logFile, "a");
|
|
25503
25697
|
try {
|
|
25504
|
-
const child =
|
|
25698
|
+
const child = spawn14(process.execPath, [process.argv[1], "start"], { detached: true, stdio: ["ignore", fd, fd], windowsHide: true, env: { ...process.env, FRIEND_DAEMON: "1" } });
|
|
25505
25699
|
child.unref();
|
|
25506
25700
|
return child.pid;
|
|
25507
25701
|
} finally {
|
|
@@ -25549,8 +25743,8 @@ var realDeps = {
|
|
|
25549
25743
|
},
|
|
25550
25744
|
now: Date.now
|
|
25551
25745
|
};
|
|
25552
|
-
var pidFile = (dataDir) =>
|
|
25553
|
-
var logFileOf = (dataDir) =>
|
|
25746
|
+
var pidFile = (dataDir) => join35(dataDir, "friend.pid");
|
|
25747
|
+
var logFileOf = (dataDir) => join35(dataDir, "friend.log");
|
|
25554
25748
|
function readPid(dataDir) {
|
|
25555
25749
|
try {
|
|
25556
25750
|
const r = JSON.parse(readFileSync21(pidFile(dataDir), "utf8"));
|
|
@@ -25587,7 +25781,7 @@ async function start(io2, deps) {
|
|
|
25587
25781
|
mkdirSync23(io2.dataDir, { recursive: true });
|
|
25588
25782
|
const log = logFileOf(io2.dataDir);
|
|
25589
25783
|
try {
|
|
25590
|
-
if (
|
|
25784
|
+
if (existsSync31(log) && statSync9(log).size > MAX_LOG_BYTES) renameSync6(log, `${log}.old`);
|
|
25591
25785
|
} catch {
|
|
25592
25786
|
}
|
|
25593
25787
|
const pid = deps.launch(log);
|
|
@@ -25661,10 +25855,10 @@ async function daemonCommand(args, io2, deps = realDeps) {
|
|
|
25661
25855
|
// ../agent-cli/src/commands/upgrade.ts
|
|
25662
25856
|
import crossSpawn5 from "cross-spawn";
|
|
25663
25857
|
import { appendFileSync } from "node:fs";
|
|
25664
|
-
import { join as
|
|
25858
|
+
import { join as join36 } from "node:path";
|
|
25665
25859
|
var PACKAGE2 = "friend-assistant";
|
|
25666
25860
|
var real2 = {
|
|
25667
|
-
current: () => true ? "0.1.
|
|
25861
|
+
current: () => true ? "0.1.74" : "development",
|
|
25668
25862
|
latest: () => new Promise((resolve13) => {
|
|
25669
25863
|
const child = crossSpawn5("npm", ["view", PACKAGE2, "version", "--prefer-online"], { stdio: ["ignore", "pipe", "ignore"] });
|
|
25670
25864
|
let out = "";
|
|
@@ -25702,7 +25896,7 @@ async function upgradeCommand(args, io0, deps = real2) {
|
|
|
25702
25896
|
io0.err("Usage: friend upgrade [--force] [--auto]");
|
|
25703
25897
|
return 1;
|
|
25704
25898
|
}
|
|
25705
|
-
const log = deps.log ?? ((line2) => appendFileSync(
|
|
25899
|
+
const log = deps.log ?? ((line2) => appendFileSync(join36(io0.dataDir, "update.log"), `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
25706
25900
|
`));
|
|
25707
25901
|
const io2 = auto ? {
|
|
25708
25902
|
...io0,
|
|
@@ -25982,7 +26176,7 @@ async function run(argv, io2) {
|
|
|
25982
26176
|
case "version":
|
|
25983
26177
|
case "--version":
|
|
25984
26178
|
case "-v":
|
|
25985
|
-
io2.out(true ? "0.1.
|
|
26179
|
+
io2.out(true ? "0.1.74" : "development");
|
|
25986
26180
|
return 0;
|
|
25987
26181
|
case "lan":
|
|
25988
26182
|
return await lanCommand(rest, io2);
|