friend-assistant 0.1.71 → 0.1.72
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 +1 -0
- package/dist/BUILD.json +2 -2
- package/dist/friend.mjs +469 -374
- package/package.json +1 -1
package/dist/friend.mjs
CHANGED
|
@@ -89,7 +89,7 @@ function jarvisProblem(props) {
|
|
|
89
89
|
const ui = props && typeof props === "object" ? props.ui : void 0;
|
|
90
90
|
if (!ui || typeof ui !== "object") return 'A jarvis object needs ui: a tree like {c: "JStatCard", p: {...}, kids: [...]}, where c is the component name.';
|
|
91
91
|
let count3 = 0;
|
|
92
|
-
const
|
|
92
|
+
const walk3 = (n2, depth) => {
|
|
93
93
|
if (typeof n2 === "string") return n2.length > JARVIS_LIMITS.text ? "A text is too long." : null;
|
|
94
94
|
if (!n2 || typeof n2 !== "object" || typeof n2.c !== "string") return "Every node needs c, the component name.";
|
|
95
95
|
if (depth > JARVIS_LIMITS.depth) return `The tree is too deep (at most ${JARVIS_LIMITS.depth} levels).`;
|
|
@@ -108,19 +108,19 @@ function jarvisProblem(props) {
|
|
|
108
108
|
const parts = node.slots[slot];
|
|
109
109
|
if (!Array.isArray(parts)) return `${node.c}: the slot ${slot} must be a list.`;
|
|
110
110
|
for (const part of parts) {
|
|
111
|
-
const r =
|
|
111
|
+
const r = walk3(part, depth + 1);
|
|
112
112
|
if (r) return r;
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
if (node.kids !== void 0 && !Array.isArray(node.kids)) return `${node.c}: kids must be a list.`;
|
|
116
116
|
if (node.kids && !def.kids && node.kids.some((k) => typeof k !== "string")) return `${node.c} cannot contain other components.`;
|
|
117
117
|
for (const k of node.kids ?? []) {
|
|
118
|
-
const r =
|
|
118
|
+
const r = walk3(k, depth + 1);
|
|
119
119
|
if (r) return r;
|
|
120
120
|
}
|
|
121
121
|
return null;
|
|
122
122
|
};
|
|
123
|
-
return
|
|
123
|
+
return walk3(ui, 1);
|
|
124
124
|
}
|
|
125
125
|
function jarvisObjectProblem(type, props) {
|
|
126
126
|
return jarvisProblem({ ui: jarvisTreeOf(type, props) });
|
|
@@ -2400,14 +2400,14 @@ var MemoryTree = class {
|
|
|
2400
2400
|
/** Counts every note (not index files). */
|
|
2401
2401
|
count() {
|
|
2402
2402
|
let n2 = 0;
|
|
2403
|
-
const
|
|
2403
|
+
const walk3 = (dir) => {
|
|
2404
2404
|
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
2405
2405
|
if (e.isSymbolicLink()) continue;
|
|
2406
|
-
if (e.isDirectory())
|
|
2406
|
+
if (e.isDirectory()) walk3(join(dir, e.name));
|
|
2407
2407
|
else if (e.isFile() && e.name.endsWith(".md") && e.name !== INDEX_FILE) n2++;
|
|
2408
2408
|
}
|
|
2409
2409
|
};
|
|
2410
|
-
if (existsSync(this.root))
|
|
2410
|
+
if (existsSync(this.root)) walk3(this.root);
|
|
2411
2411
|
return n2;
|
|
2412
2412
|
}
|
|
2413
2413
|
/** A note's text, or a folder's index. An empty path is the root. */
|
|
@@ -2499,18 +2499,18 @@ var MemoryTree = class {
|
|
|
2499
2499
|
/** Every note (path, title, summary, related), reading the files. For tidying, and for the notes' links. */
|
|
2500
2500
|
notes() {
|
|
2501
2501
|
const out = [];
|
|
2502
|
-
const
|
|
2502
|
+
const walk3 = (dir, parts) => {
|
|
2503
2503
|
if (!existsSync(dir)) return;
|
|
2504
2504
|
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
2505
2505
|
if (e.isSymbolicLink()) continue;
|
|
2506
|
-
if (e.isDirectory())
|
|
2506
|
+
if (e.isDirectory()) walk3(join(dir, e.name), [...parts, e.name]);
|
|
2507
2507
|
else if (e.isFile() && e.name.endsWith(".md") && e.name !== INDEX_FILE) {
|
|
2508
2508
|
const n2 = parseNote(readFileSync(join(dir, e.name), "utf8"), humanize(e.name));
|
|
2509
2509
|
out.push({ path: [...parts, e.name].join("/"), title: n2.title, summary: n2.summary, related: n2.related, body: n2.body });
|
|
2510
2510
|
}
|
|
2511
2511
|
}
|
|
2512
2512
|
};
|
|
2513
|
-
|
|
2513
|
+
walk3(this.root, []);
|
|
2514
2514
|
return out;
|
|
2515
2515
|
}
|
|
2516
2516
|
/** After a note or folder moved or was deleted, notes that pointed at it follow it (or drop the pointer). */
|
|
@@ -2542,14 +2542,14 @@ var MemoryTree = class {
|
|
|
2542
2542
|
}
|
|
2543
2543
|
countUnder(parts) {
|
|
2544
2544
|
let n2 = 0;
|
|
2545
|
-
const
|
|
2545
|
+
const walk3 = (dir) => {
|
|
2546
2546
|
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
2547
2547
|
if (e.isSymbolicLink()) continue;
|
|
2548
|
-
if (e.isDirectory())
|
|
2548
|
+
if (e.isDirectory()) walk3(join(dir, e.name));
|
|
2549
2549
|
else if (e.name.endsWith(".md") && e.name !== INDEX_FILE) n2++;
|
|
2550
2550
|
}
|
|
2551
2551
|
};
|
|
2552
|
-
|
|
2552
|
+
walk3(this.abs(parts));
|
|
2553
2553
|
return n2;
|
|
2554
2554
|
}
|
|
2555
2555
|
/** Moves a note to another folder or name; both indexes follow. A folder moves with everything in it. */
|
|
@@ -2590,11 +2590,11 @@ var MemoryTree = class {
|
|
|
2590
2590
|
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
2591
2591
|
if (words.length === 0) return [];
|
|
2592
2592
|
const hits = [];
|
|
2593
|
-
const
|
|
2593
|
+
const walk3 = (dir, parts) => {
|
|
2594
2594
|
if (!existsSync(dir)) return;
|
|
2595
2595
|
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
2596
2596
|
if (e.isSymbolicLink()) continue;
|
|
2597
|
-
if (e.isDirectory())
|
|
2597
|
+
if (e.isDirectory()) walk3(join(dir, e.name), [...parts, e.name]);
|
|
2598
2598
|
else if (e.isFile() && e.name.endsWith(".md") && e.name !== INDEX_FILE) {
|
|
2599
2599
|
const note = parseNote(readFileSync(join(dir, e.name), "utf8"), humanize(e.name));
|
|
2600
2600
|
const head = `${note.title} ${note.summary}`.toLowerCase();
|
|
@@ -2604,21 +2604,21 @@ var MemoryTree = class {
|
|
|
2604
2604
|
}
|
|
2605
2605
|
}
|
|
2606
2606
|
};
|
|
2607
|
-
|
|
2607
|
+
walk3(this.root, []);
|
|
2608
2608
|
return hits.sort((a, b) => b.score - a.score || a.path.localeCompare(b.path)).slice(0, limit).map(({ score: _s, ...f }) => f);
|
|
2609
2609
|
}
|
|
2610
2610
|
/** Every folder and note, walking down from the root by the indexes, with how deep each is. */
|
|
2611
2611
|
outline() {
|
|
2612
2612
|
const out = [];
|
|
2613
|
-
const
|
|
2613
|
+
const walk3 = (folder) => {
|
|
2614
2614
|
if (!existsSync(this.abs([...folder, INDEX_FILE]))) return;
|
|
2615
2615
|
for (const e of this.readIndexOf(folder).entries) {
|
|
2616
2616
|
const path3 = [...folder, e.target.replace(/\/$/, "")].join("/");
|
|
2617
2617
|
out.push({ path: e.kind === "folder" ? `${path3}/` : path3, kind: e.kind, title: e.title, summary: e.summary, depth: folder.length });
|
|
2618
|
-
if (e.kind === "folder" && folder.length < MAX_DEPTH)
|
|
2618
|
+
if (e.kind === "folder" && folder.length < MAX_DEPTH) walk3([...folder, e.target.replace(/\/$/, "")]);
|
|
2619
2619
|
}
|
|
2620
2620
|
};
|
|
2621
|
-
|
|
2621
|
+
walk3([]);
|
|
2622
2622
|
return out;
|
|
2623
2623
|
}
|
|
2624
2624
|
/** Deletes every note and folder and starts the root index again. Returns how many notes there were. */
|
|
@@ -2632,7 +2632,7 @@ var MemoryTree = class {
|
|
|
2632
2632
|
check() {
|
|
2633
2633
|
this.ensure();
|
|
2634
2634
|
const problems = [];
|
|
2635
|
-
const
|
|
2635
|
+
const walk3 = (folder) => {
|
|
2636
2636
|
const dir = this.abs(folder);
|
|
2637
2637
|
const hasIndex = existsSync(join(dir, INDEX_FILE));
|
|
2638
2638
|
if (!hasIndex) problems.push({ kind: "no-index", path: folder.join("/") });
|
|
@@ -2643,7 +2643,7 @@ var MemoryTree = class {
|
|
|
2643
2643
|
if (e.isDirectory()) {
|
|
2644
2644
|
seen.add(`${e.name}/`);
|
|
2645
2645
|
if (!listed.some((l) => l.target === `${e.name}/`)) problems.push({ kind: "unlisted-folder", path: [...folder, e.name].join("/") });
|
|
2646
|
-
|
|
2646
|
+
walk3([...folder, e.name]);
|
|
2647
2647
|
} else if (e.isFile() && e.name.endsWith(".md") && e.name !== INDEX_FILE) {
|
|
2648
2648
|
const key2 = e.name;
|
|
2649
2649
|
seen.add(key2);
|
|
@@ -2652,7 +2652,7 @@ var MemoryTree = class {
|
|
|
2652
2652
|
}
|
|
2653
2653
|
for (const l of listed) if (!seen.has(l.target)) problems.push({ kind: "dead-link", path: [...folder, l.target].join("/") });
|
|
2654
2654
|
};
|
|
2655
|
-
|
|
2655
|
+
walk3([]);
|
|
2656
2656
|
for (const n2 of this.notes()) for (const r of n2.related) if (!this.noteExists(r)) problems.push({ kind: "dead-related", path: `${n2.path} -> ${r}` });
|
|
2657
2657
|
return problems;
|
|
2658
2658
|
}
|
|
@@ -3074,14 +3074,14 @@ function regionUse(objects) {
|
|
|
3074
3074
|
return { used: used2, free: REGION_NAMES.filter((n2) => !used2.has(n2)) };
|
|
3075
3075
|
}
|
|
3076
3076
|
function describeScreen(scene, presence, entries, now, panels = [], screen = null, view, accent) {
|
|
3077
|
-
const
|
|
3077
|
+
const open3 = panels.length ? `; the owner has open: ${panels.map((p) => PANEL_TEXT[p]).join(", ")}, so keep clear of them` : "";
|
|
3078
3078
|
const known = [screen ? describeDevice(screen) : "", view ? `view=${view}` : "", accent ? `accent=${accent}` : ""].filter(Boolean);
|
|
3079
3079
|
const device = known.length ? `${known.join("; ")}; ` : "";
|
|
3080
3080
|
const phone = screen?.kind === "phone";
|
|
3081
3081
|
const taken = panelObjects(panels);
|
|
3082
3082
|
if (entries.length === 0) {
|
|
3083
3083
|
const { free: free2 } = regionUse(taken);
|
|
3084
|
-
return `${device}scene=${scene}; presence=${presence}; the stage is empty${
|
|
3084
|
+
return `${device}scene=${scene}; presence=${presence}; the stage is empty${open3}${phone ? "" : `; free regions: ${free2.join(", ") || "none"}`}`;
|
|
3085
3085
|
}
|
|
3086
3086
|
const items = entries.map(({ object: o, expiresAt }) => {
|
|
3087
3087
|
const where = typeof o.placement === "string" ? o.placement : "custom box";
|
|
@@ -3089,7 +3089,7 @@ function describeScreen(scene, presence, entries, now, panels = [], screen = nul
|
|
|
3089
3089
|
return `${o.id} (${o.type}, ${o.layer === "overlay" ? "overlay on top" : phone ? "stacked" : where}, ${life})`;
|
|
3090
3090
|
});
|
|
3091
3091
|
const { free } = regionUse([...entries.map((e) => e.object).filter((o) => o.layer !== "overlay"), ...taken]);
|
|
3092
|
-
return `${device}scene=${scene}; presence=${presence}; on screen: ${items.join("; ")}${
|
|
3092
|
+
return `${device}scene=${scene}; presence=${presence}; on screen: ${items.join("; ")}${open3}${phone ? "" : `; free regions: ${free.join(", ") || "none, replace something first"}`}`;
|
|
3093
3093
|
}
|
|
3094
3094
|
var LAYOUT_GUIDE = `Screen layout (follow this when you decide where things go)
|
|
3095
3095
|
- Always on screen, never yours to cover or move: the voice presence (middle of the screen; a small round shape in the bottom-left corner during "focus" and "multi" scenes), the live captions at the bottom, a status line in the bottom-left, a small clock in the bottom-right, and the owner's notices along the top edge. Use the middle of the screen for what the owner asked to see.
|
|
@@ -3348,8 +3348,8 @@ var StageState = class {
|
|
|
3348
3348
|
return this.locked;
|
|
3349
3349
|
}
|
|
3350
3350
|
/** The side panels the owner has open right now; objects are kept out of their way. */
|
|
3351
|
-
setPanels(
|
|
3352
|
-
this.panels = ["chat", "tasks"].filter((p) =>
|
|
3351
|
+
setPanels(open3) {
|
|
3352
|
+
this.panels = ["chat", "tasks"].filter((p) => open3.includes(p));
|
|
3353
3353
|
}
|
|
3354
3354
|
openPanels() {
|
|
3355
3355
|
return [...this.panels];
|
|
@@ -4201,8 +4201,8 @@ var Agent = class {
|
|
|
4201
4201
|
return { ok: true, text: `Added task #${r.id}${describe({ dueAt: due, repeat: repeat ?? null })}.` };
|
|
4202
4202
|
}
|
|
4203
4203
|
if (name === "task.list") {
|
|
4204
|
-
const
|
|
4205
|
-
return { ok: true, text:
|
|
4204
|
+
const open3 = tasks.list();
|
|
4205
|
+
return { ok: true, text: open3.length ? open3.map((t) => `#${t.id} ${t.title}${describe(t)}`).join("\n") : "No open tasks." };
|
|
4206
4206
|
}
|
|
4207
4207
|
if (name === "task.done") {
|
|
4208
4208
|
const id2 = Number(args.id);
|
|
@@ -4734,7 +4734,7 @@ ${lines.join("\n")}`, isError: false };
|
|
|
4734
4734
|
};
|
|
4735
4735
|
|
|
4736
4736
|
// ../server/src/admin.ts
|
|
4737
|
-
import { join as
|
|
4737
|
+
import { join as join7 } from "node:path";
|
|
4738
4738
|
|
|
4739
4739
|
// ../server/src/author.ts
|
|
4740
4740
|
import { mkdirSync as mkdirSync3, mkdtempSync, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
@@ -4786,9 +4786,100 @@ function authorPlugin(plugins, scratchRoot, spec) {
|
|
|
4786
4786
|
|
|
4787
4787
|
// ../server/src/config.ts
|
|
4788
4788
|
import { createHash as createHash2 } from "node:crypto";
|
|
4789
|
-
import { chmodSync, existsSync as
|
|
4789
|
+
import { chmodSync as chmodSync2, existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
4790
4790
|
import { homedir } from "node:os";
|
|
4791
|
-
import { join as
|
|
4791
|
+
import { join as join5, posix as posix2, win32 as win322 } from "node:path";
|
|
4792
|
+
|
|
4793
|
+
// ../server/src/secretBox.ts
|
|
4794
|
+
import { createCipheriv, createDecipheriv, randomBytes, scryptSync } from "node:crypto";
|
|
4795
|
+
import { chmodSync, existsSync as existsSync3, mkdirSync as mkdirSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
4796
|
+
import { join as join4 } from "node:path";
|
|
4797
|
+
var PREFIX = "enc:v1:";
|
|
4798
|
+
var SECRET_NAME = /(token|secret|password|passphrase|key|sid)$/i;
|
|
4799
|
+
var keyCache = /* @__PURE__ */ new Map();
|
|
4800
|
+
function masterKey(dataDir) {
|
|
4801
|
+
const pass = process.env.FRIEND_SECRET_KEY;
|
|
4802
|
+
const id2 = pass ? `p:${pass}` : `f:${dataDir}`;
|
|
4803
|
+
const hit = keyCache.get(id2);
|
|
4804
|
+
if (hit) return hit;
|
|
4805
|
+
let key2;
|
|
4806
|
+
if (pass) key2 = scryptSync(pass, "friend-secret-box-v1", 32);
|
|
4807
|
+
else {
|
|
4808
|
+
const file = join4(dataDir, "secret.key");
|
|
4809
|
+
if (existsSync3(file)) key2 = Buffer.from(readFileSync3(file, "utf8").trim(), "hex");
|
|
4810
|
+
else {
|
|
4811
|
+
key2 = randomBytes(32);
|
|
4812
|
+
mkdirSync4(dataDir, { recursive: true });
|
|
4813
|
+
writeFileSync4(file, key2.toString("hex"), { mode: 384 });
|
|
4814
|
+
try {
|
|
4815
|
+
chmodSync(file, 384);
|
|
4816
|
+
} catch {
|
|
4817
|
+
}
|
|
4818
|
+
}
|
|
4819
|
+
if (key2.length !== 32) throw new Error(`${file} is damaged (it must hold a 32-byte key). Restore it from a backup.`);
|
|
4820
|
+
}
|
|
4821
|
+
keyCache.set(id2, key2);
|
|
4822
|
+
return key2;
|
|
4823
|
+
}
|
|
4824
|
+
function seal(text4, key2) {
|
|
4825
|
+
const iv = randomBytes(12);
|
|
4826
|
+
const c = createCipheriv("aes-256-gcm", key2, iv);
|
|
4827
|
+
const data2 = Buffer.concat([c.update(text4, "utf8"), c.final()]);
|
|
4828
|
+
return PREFIX + [iv, c.getAuthTag(), data2].map((b) => b.toString("base64url")).join(".");
|
|
4829
|
+
}
|
|
4830
|
+
function open(text4, key2) {
|
|
4831
|
+
try {
|
|
4832
|
+
const [iv, tag, data2] = text4.slice(PREFIX.length).split(".").map((s) => Buffer.from(s, "base64url"));
|
|
4833
|
+
if (!iv || !tag || !data2 || iv.length !== 12 || tag.length !== 16) return null;
|
|
4834
|
+
const d = createDecipheriv("aes-256-gcm", key2, iv);
|
|
4835
|
+
d.setAuthTag(tag);
|
|
4836
|
+
return Buffer.concat([d.update(data2), d.final()]).toString("utf8");
|
|
4837
|
+
} catch {
|
|
4838
|
+
return null;
|
|
4839
|
+
}
|
|
4840
|
+
}
|
|
4841
|
+
function walk(v, path3, visit) {
|
|
4842
|
+
if (Array.isArray(v)) v.forEach((x, i) => walk(x, `${path3}[${i}]`, visit));
|
|
4843
|
+
else if (v && typeof v === "object") {
|
|
4844
|
+
const o = v;
|
|
4845
|
+
for (const k of Object.keys(o)) {
|
|
4846
|
+
const p = path3 ? `${path3}.${k}` : k;
|
|
4847
|
+
visit(o, k, p);
|
|
4848
|
+
walk(o[k], p, visit);
|
|
4849
|
+
}
|
|
4850
|
+
}
|
|
4851
|
+
}
|
|
4852
|
+
function sealSecrets(value, dataDir) {
|
|
4853
|
+
const copy = JSON.parse(JSON.stringify(value));
|
|
4854
|
+
let changed = false;
|
|
4855
|
+
walk(copy, "", (o, k) => {
|
|
4856
|
+
const s = o[k];
|
|
4857
|
+
if (typeof s === "string" && s !== "" && !s.startsWith(PREFIX) && SECRET_NAME.test(k)) {
|
|
4858
|
+
o[k] = seal(s, masterKey(dataDir));
|
|
4859
|
+
changed = true;
|
|
4860
|
+
}
|
|
4861
|
+
});
|
|
4862
|
+
return { value: copy, changed };
|
|
4863
|
+
}
|
|
4864
|
+
function unsealSecrets(value, dataDir) {
|
|
4865
|
+
const copy = JSON.parse(JSON.stringify(value));
|
|
4866
|
+
const lost = [];
|
|
4867
|
+
walk(copy, "", (o, k, p) => {
|
|
4868
|
+
const s = o[k];
|
|
4869
|
+
if (typeof s !== "string" || !s.startsWith(PREFIX)) return;
|
|
4870
|
+
let plain6 = null;
|
|
4871
|
+
try {
|
|
4872
|
+
plain6 = open(s, masterKey(dataDir));
|
|
4873
|
+
} catch {
|
|
4874
|
+
plain6 = null;
|
|
4875
|
+
}
|
|
4876
|
+
if (plain6 === null) lost.push(p);
|
|
4877
|
+
o[k] = plain6 ?? "";
|
|
4878
|
+
});
|
|
4879
|
+
return { value: copy, lost };
|
|
4880
|
+
}
|
|
4881
|
+
|
|
4882
|
+
// ../server/src/config.ts
|
|
4792
4883
|
var BROWSER_LIMITS = { timeoutSec: { min: 5, max: 60, def: 20 }, maxChars: { min: 1e3, max: 3e4, def: 12e3 } };
|
|
4793
4884
|
var chromePathOk = (v) => v === "" || v.length <= 300 && !/[\u0000-\u001f"<>|*?]/.test(v) && !v.startsWith("-");
|
|
4794
4885
|
function sanitizeBrowser(raw) {
|
|
@@ -5231,7 +5322,7 @@ var DEFAULT_DESTRUCTIVE_PATTERNS = [
|
|
|
5231
5322
|
String.raw`\b(iex|invoke-expression)\b`
|
|
5232
5323
|
];
|
|
5233
5324
|
function defaultDataDir() {
|
|
5234
|
-
return process.env.FRIEND_HOME ??
|
|
5325
|
+
return process.env.FRIEND_HOME ?? join5(homedir(), ".friend");
|
|
5235
5326
|
}
|
|
5236
5327
|
var defaults = (dataDir) => ({
|
|
5237
5328
|
bind: "127.0.0.1",
|
|
@@ -5274,46 +5365,50 @@ var defaults = (dataDir) => ({
|
|
|
5274
5365
|
dataDir
|
|
5275
5366
|
});
|
|
5276
5367
|
function configPath(dataDir) {
|
|
5277
|
-
return
|
|
5368
|
+
return join5(dataDir, "config.json");
|
|
5278
5369
|
}
|
|
5279
5370
|
var trackHash = false;
|
|
5280
5371
|
function trackConfigHash(on = true) {
|
|
5281
5372
|
trackHash = on;
|
|
5282
5373
|
}
|
|
5283
|
-
var hashFile = (dataDir) =>
|
|
5284
|
-
var fingerprint = (dataDir) => createHash2("sha256").update(
|
|
5374
|
+
var hashFile = (dataDir) => join5(dataDir, "config.hash");
|
|
5375
|
+
var fingerprint = (dataDir) => createHash2("sha256").update(readFileSync4(configPath(dataDir))).digest("hex");
|
|
5285
5376
|
function checkConfigFile(dataDir) {
|
|
5286
5377
|
const to = fingerprint(dataDir);
|
|
5287
5378
|
let from = null;
|
|
5288
5379
|
try {
|
|
5289
|
-
from =
|
|
5380
|
+
from = readFileSync4(hashFile(dataDir), "utf8").trim();
|
|
5290
5381
|
} catch {
|
|
5291
5382
|
from = null;
|
|
5292
5383
|
}
|
|
5293
|
-
|
|
5384
|
+
writeFileSync5(hashFile(dataDir), to);
|
|
5294
5385
|
if (from === null) return { state: "baseline", to };
|
|
5295
5386
|
return from === to ? { state: "same", to } : { state: "changed", from, to };
|
|
5296
5387
|
}
|
|
5297
5388
|
function saveConfig(cfg) {
|
|
5298
5389
|
const { dataDir, ...rest } = cfg;
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
if (trackHash)
|
|
5390
|
+
mkdirSync5(dataDir, { recursive: true });
|
|
5391
|
+
writeFileSync5(configPath(dataDir), JSON.stringify(sealSecrets(rest, dataDir).value, null, 2));
|
|
5392
|
+
if (trackHash) writeFileSync5(hashFile(dataDir), fingerprint(dataDir));
|
|
5302
5393
|
try {
|
|
5303
|
-
|
|
5394
|
+
chmodSync2(configPath(dataDir), 384);
|
|
5304
5395
|
} catch {
|
|
5305
5396
|
}
|
|
5306
5397
|
}
|
|
5307
5398
|
function loadConfig(dataDir = defaultDataDir()) {
|
|
5308
|
-
|
|
5399
|
+
mkdirSync5(dataDir, { recursive: true });
|
|
5309
5400
|
const file = configPath(dataDir);
|
|
5310
5401
|
const base = defaults(dataDir);
|
|
5311
|
-
if (!
|
|
5402
|
+
if (!existsSync4(file)) {
|
|
5312
5403
|
const { dataDir: _d, ...rest } = base;
|
|
5313
5404
|
saveConfig({ ...rest, dataDir });
|
|
5314
5405
|
return base;
|
|
5315
5406
|
}
|
|
5316
|
-
const
|
|
5407
|
+
const raw = JSON.parse(readFileSync4(file, "utf8"));
|
|
5408
|
+
const opened = unsealSecrets(raw, dataDir);
|
|
5409
|
+
const stored = opened.value;
|
|
5410
|
+
if (opened.lost.length) console.warn(`[friend] These saved keys could not be decrypted (wrong or missing secret.key / FRIEND_SECRET_KEY) and were left empty: ${opened.lost.join(", ")}. Enter them again in Settings.`);
|
|
5411
|
+
else if (sealSecrets(raw, dataDir).changed) saveConfig({ ...stored, dataDir });
|
|
5317
5412
|
const destructivePatterns = [.../* @__PURE__ */ new Set([...base.destructivePatterns, ...stored.destructivePatterns ?? []])];
|
|
5318
5413
|
return {
|
|
5319
5414
|
...base,
|
|
@@ -5735,8 +5830,8 @@ function integrationSummary(views) {
|
|
|
5735
5830
|
|
|
5736
5831
|
// ../server/src/plugins.ts
|
|
5737
5832
|
import { randomUUID } from "node:crypto";
|
|
5738
|
-
import { cpSync, existsSync as
|
|
5739
|
-
import { join as
|
|
5833
|
+
import { cpSync, existsSync as existsSync5, lstatSync as lstatSync2, mkdirSync as mkdirSync6, readdirSync as readdirSync3, readFileSync as readFileSync5, renameSync as renameSync2, rmSync as rmSync4 } from "node:fs";
|
|
5834
|
+
import { join as join6, relative, resolve } from "node:path";
|
|
5740
5835
|
import { z as z9 } from "zod";
|
|
5741
5836
|
var MAX_SKILL_BYTES = 20 * 1024;
|
|
5742
5837
|
var MAX_TOOL_BYTES = 50 * 1024;
|
|
@@ -5779,13 +5874,13 @@ function safeRelative(file) {
|
|
|
5779
5874
|
function scan(dir) {
|
|
5780
5875
|
let files = 0;
|
|
5781
5876
|
let bytes2 = 0;
|
|
5782
|
-
const
|
|
5877
|
+
const walk3 = (d) => {
|
|
5783
5878
|
for (const entry of readdirSync3(d)) {
|
|
5784
|
-
const full =
|
|
5879
|
+
const full = join6(d, entry);
|
|
5785
5880
|
const st = lstatSync2(full);
|
|
5786
5881
|
if (st.isSymbolicLink()) return `The plugin contains a link (${entry}), which is not allowed.`;
|
|
5787
5882
|
if (st.isDirectory()) {
|
|
5788
|
-
const err2 =
|
|
5883
|
+
const err2 = walk3(full);
|
|
5789
5884
|
if (err2) return err2;
|
|
5790
5885
|
} else if (st.isFile()) {
|
|
5791
5886
|
files++;
|
|
@@ -5798,7 +5893,7 @@ function scan(dir) {
|
|
|
5798
5893
|
}
|
|
5799
5894
|
return null;
|
|
5800
5895
|
};
|
|
5801
|
-
const err =
|
|
5896
|
+
const err = walk3(dir);
|
|
5802
5897
|
return err ?? { files, bytes: bytes2 };
|
|
5803
5898
|
}
|
|
5804
5899
|
function readInside(dir, file, limit) {
|
|
@@ -5806,20 +5901,20 @@ function readInside(dir, file, limit) {
|
|
|
5806
5901
|
if (!parts) return { ok: false, error: `"${file}" must be a file inside the plugin folder.` };
|
|
5807
5902
|
const full = resolve(dir, ...parts);
|
|
5808
5903
|
if (relative(resolve(dir), full).startsWith("..")) return { ok: false, error: `"${file}" must be a file inside the plugin folder.` };
|
|
5809
|
-
if (!
|
|
5904
|
+
if (!existsSync5(full) || !lstatSync2(full).isFile()) return { ok: false, error: `The file "${file}" does not exist.` };
|
|
5810
5905
|
if (lstatSync2(full).size > limit) return { ok: false, error: `"${file}" is too large (limit ${limit / 1024} KB).` };
|
|
5811
|
-
return { ok: true, text:
|
|
5906
|
+
return { ok: true, text: readFileSync5(full, "utf8") };
|
|
5812
5907
|
}
|
|
5813
5908
|
function inspectPlugin(dir) {
|
|
5814
|
-
if (!
|
|
5909
|
+
if (!existsSync5(dir) || !lstatSync2(dir).isDirectory()) return { ok: false, error: "That plugin folder does not exist." };
|
|
5815
5910
|
const counted = scan(dir);
|
|
5816
5911
|
if (typeof counted === "string") return { ok: false, error: counted };
|
|
5817
|
-
const manifestPath =
|
|
5818
|
-
if (!
|
|
5912
|
+
const manifestPath = join6(dir, "plugin.json");
|
|
5913
|
+
if (!existsSync5(manifestPath)) return { ok: false, error: "plugin.json is missing." };
|
|
5819
5914
|
if (lstatSync2(manifestPath).size > MAX_MANIFEST_BYTES) return { ok: false, error: "plugin.json is too large." };
|
|
5820
5915
|
let raw;
|
|
5821
5916
|
try {
|
|
5822
|
-
raw = JSON.parse(
|
|
5917
|
+
raw = JSON.parse(readFileSync5(manifestPath, "utf8"));
|
|
5823
5918
|
} catch {
|
|
5824
5919
|
return { ok: false, error: "plugin.json is not valid JSON." };
|
|
5825
5920
|
}
|
|
@@ -5876,9 +5971,9 @@ function toolDef(m, t, code) {
|
|
|
5876
5971
|
}
|
|
5877
5972
|
var isPluginId = (id2) => id2.length >= 1 && id2.length <= 40 && NAME.test(id2);
|
|
5878
5973
|
function listCatalog(dir) {
|
|
5879
|
-
if (!
|
|
5880
|
-
return readdirSync3(dir).filter((d) => isPluginId(d) && lstatSync2(
|
|
5881
|
-
const r = inspectPlugin(
|
|
5974
|
+
if (!existsSync5(dir)) return [];
|
|
5975
|
+
return readdirSync3(dir).filter((d) => isPluginId(d) && lstatSync2(join6(dir, d)).isDirectory()).sort().map((id2) => {
|
|
5976
|
+
const r = inspectPlugin(join6(dir, id2));
|
|
5882
5977
|
if (!r.ok) return { id: id2, name: id2, version: "", description: "", tools: 0, skills: 0, error: r.error };
|
|
5883
5978
|
const m = r.manifest;
|
|
5884
5979
|
return { id: id2, name: m.name, version: m.version, description: m.description, tools: m.tools.length, skills: m.skills.length, error: null };
|
|
@@ -5901,12 +5996,12 @@ var Plugins = class {
|
|
|
5901
5996
|
const r = inspectPlugin(srcDir);
|
|
5902
5997
|
if (!r.ok) return r;
|
|
5903
5998
|
const id2 = r.manifest.id;
|
|
5904
|
-
|
|
5905
|
-
const staging =
|
|
5999
|
+
mkdirSync6(this.root, { recursive: true });
|
|
6000
|
+
const staging = join6(this.root, `.tmp-${randomUUID()}`);
|
|
5906
6001
|
try {
|
|
5907
6002
|
cpSync(srcDir, staging, { recursive: true, dereference: false });
|
|
5908
|
-
const dest =
|
|
5909
|
-
const upgraded =
|
|
6003
|
+
const dest = join6(this.root, id2);
|
|
6004
|
+
const upgraded = existsSync5(dest);
|
|
5910
6005
|
rmSync4(dest, { recursive: true, force: true });
|
|
5911
6006
|
renameSync2(staging, dest);
|
|
5912
6007
|
this.db.prepare("insert into plugins (id, enabled, installed_at) values (?, 1, ?) on conflict(id) do update set installed_at = excluded.installed_at").run(id2, this.clock());
|
|
@@ -5926,8 +6021,8 @@ var Plugins = class {
|
|
|
5926
6021
|
this.cache ??= /* @__PURE__ */ new Map();
|
|
5927
6022
|
let hit = this.cache.get(id2);
|
|
5928
6023
|
if (!hit) {
|
|
5929
|
-
const dir =
|
|
5930
|
-
hit =
|
|
6024
|
+
const dir = join6(this.root, id2);
|
|
6025
|
+
hit = existsSync5(dir) ? inspectPlugin(dir) : { ok: false, error: "The plugin files are missing." };
|
|
5931
6026
|
this.cache.set(id2, hit);
|
|
5932
6027
|
}
|
|
5933
6028
|
return hit;
|
|
@@ -5954,7 +6049,7 @@ var Plugins = class {
|
|
|
5954
6049
|
}
|
|
5955
6050
|
remove(id2) {
|
|
5956
6051
|
const had = this.db.prepare("delete from plugins where id = ?").run(id2).changes > 0;
|
|
5957
|
-
if (NAME.test(id2)) rmSync4(
|
|
6052
|
+
if (NAME.test(id2)) rmSync4(join6(this.root, id2), { recursive: true, force: true });
|
|
5958
6053
|
this.cache = null;
|
|
5959
6054
|
return had;
|
|
5960
6055
|
}
|
|
@@ -6087,7 +6182,7 @@ ${steps}
|
|
|
6087
6182
|
return list2.length ? list2.map((p) => `${p.id}: ${p.name} ${p.version}, ${p.enabled ? "on" : "off"}${p.error ? ` (cannot be used: ${p.error})` : ""}, ${p.skills.length} skills [${p.skills.map((s) => s.name).join(", ")}], ${p.tools.length} tools [${p.tools.map((t) => t.name).join(", ")}]`).join("\n") : "No plugins installed.";
|
|
6088
6183
|
}
|
|
6089
6184
|
case "plugins.create": {
|
|
6090
|
-
const r = authorPlugin(d.plugins,
|
|
6185
|
+
const r = authorPlugin(d.plugins, join7(d.dataDir, "drafts"), args);
|
|
6091
6186
|
if (!r.ok) throw new Error(`The plugin was not created: ${r.error}`);
|
|
6092
6187
|
d.audit("plugins.create", { id: r.id, upgraded: r.upgraded, skills: r.skills, tools: r.tools });
|
|
6093
6188
|
return `${r.upgraded ? "Updated" : "Created"} the plugin ${r.id} and switched it on: ${r.skills} skills, ${r.tools} tools. ${r.skills ? "Load a skill with skill.use. " : ""}${r.tools ? `Its tools are plugin.${r.id}.<tool> (each call asks the owner).` : ""}`.trim();
|
|
@@ -6120,10 +6215,10 @@ ${steps}
|
|
|
6120
6215
|
}
|
|
6121
6216
|
|
|
6122
6217
|
// ../server/src/assets.ts
|
|
6123
|
-
import { existsSync as
|
|
6124
|
-
import { join as
|
|
6218
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
6219
|
+
import { join as join8 } from "node:path";
|
|
6125
6220
|
function firstExistingDir(candidates, mustContain) {
|
|
6126
|
-
return candidates.find((c) => !!c &&
|
|
6221
|
+
return candidates.find((c) => !!c && existsSync6(mustContain ? join8(c, mustContain) : c));
|
|
6127
6222
|
}
|
|
6128
6223
|
|
|
6129
6224
|
// ../server/src/chatlog.ts
|
|
@@ -6158,8 +6253,8 @@ import crossSpawn from "cross-spawn";
|
|
|
6158
6253
|
import { createHash as createHash3 } from "node:crypto";
|
|
6159
6254
|
|
|
6160
6255
|
// ../server/src/connectors/store.ts
|
|
6161
|
-
import { chmodSync as
|
|
6162
|
-
import { dirname as dirname2, join as
|
|
6256
|
+
import { chmodSync as chmodSync3, existsSync as existsSync7, mkdirSync as mkdirSync7, readFileSync as readFileSync6, renameSync as renameSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
6257
|
+
import { dirname as dirname2, join as join9 } from "node:path";
|
|
6163
6258
|
import { z as z10 } from "zod";
|
|
6164
6259
|
var CONNECTOR_ID = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
6165
6260
|
var MAX_CONNECTORS = 20;
|
|
@@ -6197,14 +6292,14 @@ var ConnectorStore = class {
|
|
|
6197
6292
|
path;
|
|
6198
6293
|
items;
|
|
6199
6294
|
constructor(dataDir) {
|
|
6200
|
-
this.path =
|
|
6295
|
+
this.path = join9(dataDir, "connectors.json");
|
|
6201
6296
|
this.items = this.load();
|
|
6202
6297
|
}
|
|
6203
6298
|
load() {
|
|
6204
|
-
if (!
|
|
6299
|
+
if (!existsSync7(this.path)) return [];
|
|
6205
6300
|
let raw;
|
|
6206
6301
|
try {
|
|
6207
|
-
raw = JSON.parse(
|
|
6302
|
+
raw = JSON.parse(readFileSync6(this.path, "utf8"));
|
|
6208
6303
|
} catch {
|
|
6209
6304
|
return [];
|
|
6210
6305
|
}
|
|
@@ -6219,11 +6314,11 @@ var ConnectorStore = class {
|
|
|
6219
6314
|
return out.slice(0, MAX_CONNECTORS);
|
|
6220
6315
|
}
|
|
6221
6316
|
save() {
|
|
6222
|
-
|
|
6317
|
+
mkdirSync7(dirname2(this.path), { recursive: true });
|
|
6223
6318
|
const tmp = `${this.path}.tmp`;
|
|
6224
|
-
|
|
6319
|
+
writeFileSync6(tmp, JSON.stringify(this.items, null, 2));
|
|
6225
6320
|
try {
|
|
6226
|
-
|
|
6321
|
+
chmodSync3(tmp, 384);
|
|
6227
6322
|
} catch {
|
|
6228
6323
|
}
|
|
6229
6324
|
renameSync3(tmp, this.path);
|
|
@@ -6556,9 +6651,9 @@ var PRESETS = [
|
|
|
6556
6651
|
];
|
|
6557
6652
|
|
|
6558
6653
|
// ../server/src/connectors/quick.ts
|
|
6559
|
-
import { existsSync as
|
|
6654
|
+
import { existsSync as existsSync8 } from "node:fs";
|
|
6560
6655
|
import { homedir as homedir2 } from "node:os";
|
|
6561
|
-
import { join as
|
|
6656
|
+
import { join as join10 } from "node:path";
|
|
6562
6657
|
var find = (id2) => PRESETS.find((p) => p.id === id2 && p.quick);
|
|
6563
6658
|
var isQuickPreset = (id2) => !!find(id2);
|
|
6564
6659
|
function programFor(preset, bundled) {
|
|
@@ -6566,12 +6661,12 @@ function programFor(preset, bundled) {
|
|
|
6566
6661
|
}
|
|
6567
6662
|
var MANUAL_EXTENSION = "One step only you can do, because Chrome does not allow programs to install extensions silently: open chrome://extensions, turn on Developer mode (top right), click Load unpacked and choose the folder shown above. Then click the extension's icon and switch it on.";
|
|
6568
6663
|
function chromeFolder(home) {
|
|
6569
|
-
return
|
|
6664
|
+
return join10(home, ".chrome-control-mcp");
|
|
6570
6665
|
}
|
|
6571
6666
|
function chromeInstalled(home = homedir2()) {
|
|
6572
6667
|
const base = chromeFolder(home);
|
|
6573
|
-
const ext =
|
|
6574
|
-
const installed =
|
|
6668
|
+
const ext = join10(base, "extension");
|
|
6669
|
+
const installed = existsSync8(join10(base, "token")) && existsSync8(join10(ext, "manifest.json")) && existsSync8(join10(base, "native-host"));
|
|
6575
6670
|
return { installed, extensionFolder: installed ? ext : null };
|
|
6576
6671
|
}
|
|
6577
6672
|
function quickCheck(id2, deps = {}) {
|
|
@@ -6650,14 +6745,14 @@ async function quickConnect(id2, deps) {
|
|
|
6650
6745
|
}
|
|
6651
6746
|
|
|
6652
6747
|
// ../server/src/connectors/chromePlugin.ts
|
|
6653
|
-
import { existsSync as
|
|
6748
|
+
import { existsSync as existsSync9 } from "node:fs";
|
|
6654
6749
|
import { dirname as dirname3, resolve as resolve2 } from "node:path";
|
|
6655
6750
|
import { fileURLToPath } from "node:url";
|
|
6656
6751
|
var here = dirname3(fileURLToPath(import.meta.url));
|
|
6657
6752
|
var ID = "chrome";
|
|
6658
6753
|
function bundledChromeControl() {
|
|
6659
6754
|
const candidates = [process.env.FRIEND_CHROME_CONTROL, resolve2(here, "chrome-control/dist/index.js"), resolve2(here, "../../../chrome-control/dist/index.js")];
|
|
6660
|
-
for (const c of candidates) if (c &&
|
|
6755
|
+
for (const c of candidates) if (c && existsSync9(c)) return c;
|
|
6661
6756
|
return null;
|
|
6662
6757
|
}
|
|
6663
6758
|
var ChromePlugin = class {
|
|
@@ -6806,15 +6901,15 @@ var ChromePlugin = class {
|
|
|
6806
6901
|
};
|
|
6807
6902
|
|
|
6808
6903
|
// ../server/src/connectors/chromeRemote.ts
|
|
6809
|
-
import { existsSync as
|
|
6904
|
+
import { existsSync as existsSync10, readFileSync as readFileSync7 } from "node:fs";
|
|
6810
6905
|
import { createHash as createHash4, timingSafeEqual } from "node:crypto";
|
|
6811
6906
|
import { request } from "node:http";
|
|
6812
6907
|
import { homedir as homedir3 } from "node:os";
|
|
6813
|
-
import { dirname as dirname4, join as
|
|
6908
|
+
import { dirname as dirname4, join as join11, resolve as resolve3 } from "node:path";
|
|
6814
6909
|
import { WebSocket } from "ws";
|
|
6815
6910
|
function chromeToken(home = homedir3()) {
|
|
6816
6911
|
try {
|
|
6817
|
-
const t =
|
|
6912
|
+
const t = readFileSync7(join11(home, ".chrome-control-mcp", "token"), "utf8").trim();
|
|
6818
6913
|
return t || null;
|
|
6819
6914
|
} catch {
|
|
6820
6915
|
return null;
|
|
@@ -6831,7 +6926,7 @@ function keyFromRequest(headers, search) {
|
|
|
6831
6926
|
function bundledExtensionDir(bundledIndex) {
|
|
6832
6927
|
if (!bundledIndex) return null;
|
|
6833
6928
|
const dir = resolve3(dirname4(bundledIndex), "..", "extension");
|
|
6834
|
-
return
|
|
6929
|
+
return existsSync10(join11(dir, "manifest.json")) ? dir : null;
|
|
6835
6930
|
}
|
|
6836
6931
|
function chromeAddresses(origin) {
|
|
6837
6932
|
const url = new URL(origin);
|
|
@@ -6906,8 +7001,8 @@ function relayExtension(client, up) {
|
|
|
6906
7001
|
}
|
|
6907
7002
|
|
|
6908
7003
|
// ../server/src/zip.ts
|
|
6909
|
-
import { readdirSync as readdirSync4, readFileSync as
|
|
6910
|
-
import { join as
|
|
7004
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync8, statSync } from "node:fs";
|
|
7005
|
+
import { join as join12 } from "node:path";
|
|
6911
7006
|
import { deflateRawSync } from "node:zlib";
|
|
6912
7007
|
var TABLE = (() => {
|
|
6913
7008
|
const t = new Uint32Array(256);
|
|
@@ -6926,17 +7021,17 @@ function crc32(data2) {
|
|
|
6926
7021
|
var SKIP = /* @__PURE__ */ new Set(["node_modules", ".git"]);
|
|
6927
7022
|
var MAX_FILES2 = 500;
|
|
6928
7023
|
var MAX_BYTES = 2e7;
|
|
6929
|
-
function
|
|
7024
|
+
function walk2(dir, prefix, out) {
|
|
6930
7025
|
for (const e of readdirSync4(dir, { withFileTypes: true }).sort((a, b) => a.name < b.name ? -1 : 1)) {
|
|
6931
7026
|
if (SKIP.has(e.name)) continue;
|
|
6932
|
-
const path3 =
|
|
6933
|
-
if (e.isDirectory())
|
|
7027
|
+
const path3 = join12(dir, e.name);
|
|
7028
|
+
if (e.isDirectory()) walk2(path3, `${prefix}${e.name}/`, out);
|
|
6934
7029
|
else if (e.isFile()) out.push({ name: `${prefix}${e.name}`, path: path3 });
|
|
6935
7030
|
}
|
|
6936
7031
|
}
|
|
6937
7032
|
function zipDirectory(dir, folder) {
|
|
6938
7033
|
const files = [];
|
|
6939
|
-
|
|
7034
|
+
walk2(dir, `${folder}/`, files);
|
|
6940
7035
|
if (files.length > MAX_FILES2) throw new Error("That folder has too many files to zip.");
|
|
6941
7036
|
const parts = [];
|
|
6942
7037
|
const central = [];
|
|
@@ -6945,7 +7040,7 @@ function zipDirectory(dir, folder) {
|
|
|
6945
7040
|
const time = 0;
|
|
6946
7041
|
const date = 2020 - 1980 << 9 | 1 << 5 | 1;
|
|
6947
7042
|
for (const f of files) {
|
|
6948
|
-
const data2 =
|
|
7043
|
+
const data2 = readFileSync8(f.path);
|
|
6949
7044
|
total += data2.length;
|
|
6950
7045
|
if (total > MAX_BYTES || statSync(f.path).size > MAX_BYTES) throw new Error("That folder is too big to zip.");
|
|
6951
7046
|
const packed = deflateRawSync(data2);
|
|
@@ -6995,7 +7090,7 @@ function zipDirectory(dir, folder) {
|
|
|
6995
7090
|
|
|
6996
7091
|
// ../server/src/music/mpv.ts
|
|
6997
7092
|
import { spawn as nodeSpawn } from "node:child_process";
|
|
6998
|
-
import { existsSync as
|
|
7093
|
+
import { existsSync as existsSync11, rmSync as rmSync5 } from "node:fs";
|
|
6999
7094
|
import net from "node:net";
|
|
7000
7095
|
import { tmpdir } from "node:os";
|
|
7001
7096
|
import path from "node:path";
|
|
@@ -7048,7 +7143,7 @@ function places(platform, env) {
|
|
|
7048
7143
|
async function findMpv(d) {
|
|
7049
7144
|
const platform = d.platform ?? process.platform;
|
|
7050
7145
|
const env = d.env ?? process.env;
|
|
7051
|
-
const exists2 = d.exists ??
|
|
7146
|
+
const exists2 = d.exists ?? existsSync11;
|
|
7052
7147
|
const run2 = d.run ?? defaultRun;
|
|
7053
7148
|
const versionOf = async (p) => {
|
|
7054
7149
|
const r = await run2(p, ["--version"]);
|
|
@@ -7359,12 +7454,12 @@ async function openInBrowser(url, d = {}) {
|
|
|
7359
7454
|
|
|
7360
7455
|
// ../server/src/video/provision.ts
|
|
7361
7456
|
import { spawn as spawn2 } from "node:child_process";
|
|
7362
|
-
import { createHash as createHash5, randomBytes } from "node:crypto";
|
|
7363
|
-
import { chmodSync as
|
|
7364
|
-
import { open } from "node:fs/promises";
|
|
7457
|
+
import { createHash as createHash5, randomBytes as randomBytes2 } from "node:crypto";
|
|
7458
|
+
import { chmodSync as chmodSync4, createReadStream, createWriteStream, existsSync as existsSync12, mkdirSync as mkdirSync8, readdirSync as readdirSync5, renameSync as renameSync4, rmSync as rmSync6, copyFileSync, statSync as statSync2, utimesSync, writeFileSync as writeFileSync7 } from "node:fs";
|
|
7459
|
+
import { open as open2 } from "node:fs/promises";
|
|
7365
7460
|
import { createInflateRaw } from "node:zlib";
|
|
7366
7461
|
import { pipeline } from "node:stream/promises";
|
|
7367
|
-
import { join as
|
|
7462
|
+
import { join as join13 } from "node:path";
|
|
7368
7463
|
|
|
7369
7464
|
// ../server/src/video/resolve.ts
|
|
7370
7465
|
import { spawn } from "node:child_process";
|
|
@@ -7781,7 +7876,7 @@ var MAX_HOPS2 = 5;
|
|
|
7781
7876
|
var hostOk = (host2) => ALLOWED_HOSTS.some((h) => host2 === h || host2.endsWith(`.${h}`));
|
|
7782
7877
|
var zipExtract = async (archive, plan, dest) => {
|
|
7783
7878
|
const want = `/${(plan.inside ?? plan.file).replace(/\\/g, "/")}`;
|
|
7784
|
-
const fh = await
|
|
7879
|
+
const fh = await open2(archive, "r");
|
|
7785
7880
|
try {
|
|
7786
7881
|
const size = (await fh.stat()).size;
|
|
7787
7882
|
const tailLen = Math.min(size, 65557);
|
|
@@ -7823,8 +7918,8 @@ var zipExtract = async (archive, plan, dest) => {
|
|
|
7823
7918
|
}
|
|
7824
7919
|
};
|
|
7825
7920
|
var tarExtract = (archive, plan, dest) => new Promise((resolve13, reject) => {
|
|
7826
|
-
const tmp = `${dest}.extract-${
|
|
7827
|
-
|
|
7921
|
+
const tmp = `${dest}.extract-${randomBytes2(4).toString("hex")}`;
|
|
7922
|
+
mkdirSync8(tmp, { recursive: true });
|
|
7828
7923
|
const done = (err) => {
|
|
7829
7924
|
if (!err) {
|
|
7830
7925
|
try {
|
|
@@ -7849,17 +7944,17 @@ var tarExtract = (archive, plan, dest) => new Promise((resolve13, reject) => {
|
|
|
7849
7944
|
});
|
|
7850
7945
|
function findInside(root, inside) {
|
|
7851
7946
|
const want = `/${inside.replace(/\\/g, "/")}`;
|
|
7852
|
-
const
|
|
7947
|
+
const walk3 = (dir) => {
|
|
7853
7948
|
for (const e of readdirSync5(dir, { withFileTypes: true })) {
|
|
7854
|
-
const p =
|
|
7949
|
+
const p = join13(dir, e.name);
|
|
7855
7950
|
if (e.isDirectory()) {
|
|
7856
|
-
const r =
|
|
7951
|
+
const r = walk3(p);
|
|
7857
7952
|
if (r) return r;
|
|
7858
7953
|
} else if (`/${p.slice(root.length).replace(/\\/g, "/").replace(/^\//, "")}`.endsWith(want) || !inside.includes("/") && e.name === inside) return p;
|
|
7859
7954
|
}
|
|
7860
7955
|
return null;
|
|
7861
7956
|
};
|
|
7862
|
-
return
|
|
7957
|
+
return walk3(root);
|
|
7863
7958
|
}
|
|
7864
7959
|
function checksumFor(list2, name) {
|
|
7865
7960
|
const lines = list2.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
@@ -7894,20 +7989,20 @@ var Provisioner = class {
|
|
|
7894
7989
|
*/
|
|
7895
7990
|
async update() {
|
|
7896
7991
|
const file = managedPath(this.d.dataDir, "yt-dlp", this.platform);
|
|
7897
|
-
if (!
|
|
7898
|
-
const stamp =
|
|
7992
|
+
if (!existsSync12(file)) return;
|
|
7993
|
+
const stamp = join13(this.d.dataDir, "tools", ".yt-dlp-updated");
|
|
7899
7994
|
const now = (this.d.now ?? Date.now)();
|
|
7900
7995
|
const WEEK = 7 * 24 * 3600 * 1e3;
|
|
7901
|
-
if (
|
|
7996
|
+
if (existsSync12(stamp) && now - statSync2(stamp).mtimeMs < WEEK) return;
|
|
7902
7997
|
try {
|
|
7903
|
-
|
|
7998
|
+
writeFileSync7(stamp, "");
|
|
7904
7999
|
utimesSync(stamp, now / 1e3, now / 1e3);
|
|
7905
8000
|
await (this.d.run ?? ytRun)(file, ["-U"], { timeoutMs: 12e4, maxBytes: 1e5 });
|
|
7906
8001
|
} catch {
|
|
7907
8002
|
}
|
|
7908
8003
|
}
|
|
7909
8004
|
has(name) {
|
|
7910
|
-
return
|
|
8005
|
+
return existsSync12(managedPath(this.d.dataDir, name, this.platform));
|
|
7911
8006
|
}
|
|
7912
8007
|
async ensure(names) {
|
|
7913
8008
|
while (this.running) await this.running.catch(() => {
|
|
@@ -7938,9 +8033,9 @@ var Provisioner = class {
|
|
|
7938
8033
|
return { ok: false, error };
|
|
7939
8034
|
};
|
|
7940
8035
|
if (!plan) return fail3(`Friend cannot set up ${name} on this system by itself. Install it with your package manager, then press Check again.`);
|
|
7941
|
-
const tools =
|
|
7942
|
-
|
|
7943
|
-
const part =
|
|
8036
|
+
const tools = join13(this.d.dataDir, "tools");
|
|
8037
|
+
mkdirSync8(tools, { recursive: true });
|
|
8038
|
+
const part = join13(tools, `.download-${name}-${randomBytes2(4).toString("hex")}`);
|
|
7944
8039
|
const final = managedPath(this.d.dataDir, name, this.platform);
|
|
7945
8040
|
try {
|
|
7946
8041
|
this.set(name, { phase: "downloading", percent: null });
|
|
@@ -7969,7 +8064,7 @@ var Provisioner = class {
|
|
|
7969
8064
|
return fail3(`Friend could not unpack ${name}. Install it with your package manager, then press Check again.`);
|
|
7970
8065
|
}
|
|
7971
8066
|
}
|
|
7972
|
-
if (this.platform !== "win32")
|
|
8067
|
+
if (this.platform !== "win32") chmodSync4(final, 493);
|
|
7973
8068
|
this.set(name, { phase: "ready" });
|
|
7974
8069
|
return { ok: true };
|
|
7975
8070
|
} catch (e) {
|
|
@@ -8055,13 +8150,13 @@ var Provisioner = class {
|
|
|
8055
8150
|
out.destroy();
|
|
8056
8151
|
return { error: "failed", why: e.message };
|
|
8057
8152
|
}
|
|
8058
|
-
if (!
|
|
8153
|
+
if (!existsSync12(dest) || statSync2(dest).size === 0) return { error: "failed", why: "empty download" };
|
|
8059
8154
|
return { sha: hash.digest("hex") };
|
|
8060
8155
|
}
|
|
8061
8156
|
};
|
|
8062
8157
|
|
|
8063
8158
|
// ../server/src/video/hub.ts
|
|
8064
|
-
import { randomBytes as
|
|
8159
|
+
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
8065
8160
|
|
|
8066
8161
|
// ../server/src/video/stream.ts
|
|
8067
8162
|
import { spawn as nodeSpawn3 } from "node:child_process";
|
|
@@ -8130,7 +8225,7 @@ function startStream(ffmpeg, info, o, d = {}) {
|
|
|
8130
8225
|
|
|
8131
8226
|
// ../server/src/video/tools.ts
|
|
8132
8227
|
import { spawn as spawn3 } from "node:child_process";
|
|
8133
|
-
import { existsSync as
|
|
8228
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
8134
8229
|
import path2 from "node:path";
|
|
8135
8230
|
var INSTALL2 = {
|
|
8136
8231
|
"yt-dlp": {
|
|
@@ -8197,7 +8292,7 @@ var versionOfOutput = (name, out) => {
|
|
|
8197
8292
|
async function findHelper(name, d) {
|
|
8198
8293
|
const platform = d.platform ?? process.platform;
|
|
8199
8294
|
const env = d.env ?? process.env;
|
|
8200
|
-
const exists2 = d.exists ??
|
|
8295
|
+
const exists2 = d.exists ?? existsSync13;
|
|
8201
8296
|
const run2 = d.run ?? defaultRun2;
|
|
8202
8297
|
const isPath = (p) => /[\\/]/.test(p);
|
|
8203
8298
|
const tryOne = async (p) => {
|
|
@@ -8376,7 +8471,7 @@ var VideoHub = class {
|
|
|
8376
8471
|
const now = this.clock();
|
|
8377
8472
|
for (const [id3, t] of this.tokens) if (t.expires <= now) this.tokens.delete(id3);
|
|
8378
8473
|
while (this.tokens.size >= MAX_TOKENS) this.tokens.delete(this.tokens.keys().next().value);
|
|
8379
|
-
const id2 =
|
|
8474
|
+
const id2 = randomBytes3(16).toString("hex");
|
|
8380
8475
|
this.tokens.set(id2, { info, startSec, expires: now + TTL_MS });
|
|
8381
8476
|
return { id: CARD, props: { title: info.title, src: `/api/video/${id2}` } };
|
|
8382
8477
|
}
|
|
@@ -8459,7 +8554,7 @@ var VideoHub = class {
|
|
|
8459
8554
|
if (browserWindow) {
|
|
8460
8555
|
const show3 = this.issue(info, start2);
|
|
8461
8556
|
const id2 = /\/api\/video\/([0-9a-f]{32})$/.exec(show3.props.src)[1];
|
|
8462
|
-
const ticket =
|
|
8557
|
+
const ticket = randomBytes3(16).toString("hex");
|
|
8463
8558
|
this.tickets.set(ticket, { id: id2, expires: this.clock() + TICKET_MS });
|
|
8464
8559
|
const ok2 = await this.d.openBrowser(this.d.windowUrl(id2, ticket)).catch(() => false);
|
|
8465
8560
|
if (!ok2) return { ok: false, text: "Friend could not open a browser window on this PC." };
|
|
@@ -8598,9 +8693,9 @@ import { randomUUID as randomUUID2 } from "node:crypto";
|
|
|
8598
8693
|
|
|
8599
8694
|
// ../server/src/auditContext.ts
|
|
8600
8695
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8601
|
-
import { randomBytes as
|
|
8696
|
+
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
8602
8697
|
var store = new AsyncLocalStorage();
|
|
8603
|
-
var newRequestId = (prefix) => `${prefix}-${
|
|
8698
|
+
var newRequestId = (prefix) => `${prefix}-${randomBytes4(4).toString("hex")}`;
|
|
8604
8699
|
function runWithRequest(ctx, fn) {
|
|
8605
8700
|
const outer = store.getStore();
|
|
8606
8701
|
const next = {
|
|
@@ -8619,7 +8714,7 @@ function ensureRequest(prefix, fn) {
|
|
|
8619
8714
|
}
|
|
8620
8715
|
|
|
8621
8716
|
// ../server/src/auth.ts
|
|
8622
|
-
import { createHash as createHash6, randomBytes as
|
|
8717
|
+
import { createHash as createHash6, randomBytes as randomBytes5, scrypt, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
8623
8718
|
|
|
8624
8719
|
// ../server/src/ratelimit.ts
|
|
8625
8720
|
var LockoutError = class extends Error {
|
|
@@ -8683,7 +8778,7 @@ function scryptAsync(secret, salt, N) {
|
|
|
8683
8778
|
);
|
|
8684
8779
|
}
|
|
8685
8780
|
async function hashSecret(secret) {
|
|
8686
|
-
const salt =
|
|
8781
|
+
const salt = randomBytes5(16);
|
|
8687
8782
|
const key2 = await scryptAsync(secret, salt, cost);
|
|
8688
8783
|
return `scrypt2$${cost}$${salt.toString("hex")}$${key2.toString("hex")}`;
|
|
8689
8784
|
}
|
|
@@ -8760,7 +8855,7 @@ var Auth = class _Auth {
|
|
|
8760
8855
|
}
|
|
8761
8856
|
succeeded();
|
|
8762
8857
|
if (row2 && outdated(row2.h)) this.db.prepare("update owner set password_hash = ? where id = 1").run(await hashSecret(password));
|
|
8763
|
-
const token =
|
|
8858
|
+
const token = randomBytes5(32).toString("hex");
|
|
8764
8859
|
const expiresAt = this.clock() + SESSION_TTL_MS;
|
|
8765
8860
|
this.db.prepare("insert into sessions (token_hash, kind, expires_at, ip) values (?, 'web', ?, ?)").run(sha256(token), expiresAt, ip);
|
|
8766
8861
|
this.audit.log("owner", "login.ok", { ip });
|
|
@@ -8836,7 +8931,7 @@ var Auth = class _Auth {
|
|
|
8836
8931
|
this.audit.log("system", "secrets.reset", { password: input.newPassword !== void 0, pin: input.newPin !== void 0 });
|
|
8837
8932
|
}
|
|
8838
8933
|
createPairCode() {
|
|
8839
|
-
const code =
|
|
8934
|
+
const code = randomBytes5(5).toString("hex").toUpperCase();
|
|
8840
8935
|
this.db.prepare("insert into pair_codes (code_hash, expires_at) values (?, ?)").run(sha256(code), this.clock() + PAIR_TTL_MS);
|
|
8841
8936
|
return code;
|
|
8842
8937
|
}
|
|
@@ -8848,7 +8943,7 @@ var Auth = class _Auth {
|
|
|
8848
8943
|
this.audit.log("device", "pair.fail", { deviceName });
|
|
8849
8944
|
throw new Error("Invalid or expired pairing code");
|
|
8850
8945
|
}
|
|
8851
|
-
const token =
|
|
8946
|
+
const token = randomBytes5(32).toString("hex");
|
|
8852
8947
|
this.db.prepare("insert into devices (name, token_hash, last_seen) values (?, ?, ?)").run(deviceName, sha256(token), this.clock());
|
|
8853
8948
|
this.audit.log("device", "pair.ok", { deviceName });
|
|
8854
8949
|
return token;
|
|
@@ -9578,8 +9673,8 @@ var AuditQuery = class {
|
|
|
9578
9673
|
};
|
|
9579
9674
|
|
|
9580
9675
|
// ../server/src/auditRetention.ts
|
|
9581
|
-
import { mkdirSync as
|
|
9582
|
-
import { join as
|
|
9676
|
+
import { mkdirSync as mkdirSync9, writeFileSync as writeFileSync8 } from "node:fs";
|
|
9677
|
+
import { join as join14 } from "node:path";
|
|
9583
9678
|
import { gzipSync } from "node:zlib";
|
|
9584
9679
|
var DAY = 864e5;
|
|
9585
9680
|
var APPEND_ONLY = "create trigger audit_no_delete before delete on audit_log begin select raise(abort, 'audit_log is append-only'); end;";
|
|
@@ -9597,9 +9692,9 @@ function pruneAudit(db, o) {
|
|
|
9597
9692
|
let archivePath = null;
|
|
9598
9693
|
if (o.archive) {
|
|
9599
9694
|
const rows4 = db.prepare("select * from audit_log where id between ? and ? order by id").all(fromId, toId);
|
|
9600
|
-
|
|
9601
|
-
archivePath =
|
|
9602
|
-
|
|
9695
|
+
mkdirSync9(o.dir, { recursive: true });
|
|
9696
|
+
archivePath = join14(o.dir, `audit-${fromId}-${toId}.jsonl.gz`);
|
|
9697
|
+
writeFileSync8(archivePath, gzipSync(`${rows4.map((r) => JSON.stringify(r)).join("\n")}
|
|
9603
9698
|
`));
|
|
9604
9699
|
}
|
|
9605
9700
|
const audit = new Audit(db);
|
|
@@ -10085,8 +10180,8 @@ function detectSetups(symbol, s) {
|
|
|
10085
10180
|
if ((hi - last.c) / width <= NEAR && last.c <= hi) out.push({ symbol, kind: "orb-long", state: "near", at: null, ...plan(1, hi, mid), last: r2(last.c), rangeLow: r2(lo), rangeHigh: r2(hi), volumeRatio, score: 0 });
|
|
10086
10181
|
else if ((last.c - lo) / width <= NEAR && last.c >= lo) out.push({ symbol, kind: "orb-short", state: "near", at: null, ...plan(-1, lo, mid), last: r2(last.c), rangeLow: r2(lo), rangeHigh: r2(hi), volumeRatio, score: 0 });
|
|
10087
10182
|
}
|
|
10088
|
-
const
|
|
10089
|
-
if (last.c <=
|
|
10183
|
+
const open3 = day2[0].o;
|
|
10184
|
+
if (last.c <= open3 * (1 - BOUNCE_DROP) && last.c > last.o && last.v > avgVol) {
|
|
10090
10185
|
out.push({ symbol, kind: "bounce", state: "triggered", at: hhmm(last.t, s.offset), ...plan(1, last.c, last.l), last: r2(last.c), rangeLow: r2(lo), rangeHigh: r2(hi), volumeRatio, score: 0 });
|
|
10091
10186
|
}
|
|
10092
10187
|
for (const o of out) if (o.state === "triggered" && o.at && minutes(o.at) >= TOO_LATE_MINUTES) o.state = "late";
|
|
@@ -10324,7 +10419,7 @@ async function runMarketTool(name, args, d, signal) {
|
|
|
10324
10419
|
}
|
|
10325
10420
|
|
|
10326
10421
|
// ../server/src/media.ts
|
|
10327
|
-
import { randomBytes as
|
|
10422
|
+
import { randomBytes as randomBytes6 } from "node:crypto";
|
|
10328
10423
|
import { promises as fs } from "node:fs";
|
|
10329
10424
|
import { basename, extname, isAbsolute, relative as relative2, resolve as resolve4, sep } from "node:path";
|
|
10330
10425
|
var IMAGE = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp", bmp: "image/bmp", avif: "image/avif", svg: "image/svg+xml" };
|
|
@@ -10430,7 +10525,7 @@ var MediaStore = class {
|
|
|
10430
10525
|
this.db.prepare("update media set mime = ?, size = ?, created_at = ? where id = ?").run(mime, size, this.clock(), existing.id);
|
|
10431
10526
|
return existing.id;
|
|
10432
10527
|
}
|
|
10433
|
-
const id2 =
|
|
10528
|
+
const id2 = randomBytes6(16).toString("hex");
|
|
10434
10529
|
this.db.prepare("insert into media (id, path, mime, size, created_at) values (?, ?, ?, ?, ?)").run(id2, path3, mime, size, this.clock());
|
|
10435
10530
|
return id2;
|
|
10436
10531
|
}
|
|
@@ -10517,7 +10612,7 @@ var MediaStore = class {
|
|
|
10517
10612
|
|
|
10518
10613
|
// ../server/src/channels/hub.ts
|
|
10519
10614
|
import { promises as fsp } from "node:fs";
|
|
10520
|
-
import { createHmac, randomBytes as
|
|
10615
|
+
import { createHmac, randomBytes as randomBytes7, randomInt, timingSafeEqual as timingSafeEqual3 } from "node:crypto";
|
|
10521
10616
|
var CHANNEL_LABEL = { telegram: "Telegram", sms: "SMS", whatsapp: "WhatsApp" };
|
|
10522
10617
|
var VoiceMessageError = class extends Error {
|
|
10523
10618
|
};
|
|
@@ -10998,7 +11093,7 @@ ${reply}` : reply);
|
|
|
10998
11093
|
const now = this.now();
|
|
10999
11094
|
for (const [k, v] of this.outbox) if (v.expires <= now) this.outbox.delete(k);
|
|
11000
11095
|
while (this.outbox.size >= OUTBOX_MAX) this.outbox.delete(this.outbox.keys().next().value);
|
|
11001
|
-
const token =
|
|
11096
|
+
const token = randomBytes7(16).toString("hex");
|
|
11002
11097
|
this.outbox.set(token, { path: file.path, mime: file.mime, name: file.name, expires: now + OUTBOX_TTL_MS });
|
|
11003
11098
|
return token;
|
|
11004
11099
|
}
|
|
@@ -11852,9 +11947,9 @@ ${lines.join("\n")}${found.total > lines.length ? `
|
|
|
11852
11947
|
};
|
|
11853
11948
|
|
|
11854
11949
|
// ../server/src/music/oauth.ts
|
|
11855
|
-
import { createHash as createHash9, randomBytes as
|
|
11856
|
-
import { chmodSync as
|
|
11857
|
-
import { join as
|
|
11950
|
+
import { createHash as createHash9, randomBytes as randomBytes8 } from "node:crypto";
|
|
11951
|
+
import { chmodSync as chmodSync5, existsSync as existsSync14, mkdirSync as mkdirSync10, readFileSync as readFileSync9, rmSync as rmSync7, writeFileSync as writeFileSync9 } from "node:fs";
|
|
11952
|
+
import { join as join15 } from "node:path";
|
|
11858
11953
|
var STATE_TTL_MS = 10 * 6e4;
|
|
11859
11954
|
var MAX_STATES = 20;
|
|
11860
11955
|
var REFRESH_AHEAD_MS = 6e4;
|
|
@@ -11863,7 +11958,7 @@ var RefreshRejected = class extends Error {
|
|
|
11863
11958
|
};
|
|
11864
11959
|
var b64url = (b) => b.toString("base64url");
|
|
11865
11960
|
var challengeOf = (verifier) => b64url(createHash9("sha256").update(verifier).digest());
|
|
11866
|
-
function pkcePair(random =
|
|
11961
|
+
function pkcePair(random = randomBytes8) {
|
|
11867
11962
|
const verifier = b64url(random(48));
|
|
11868
11963
|
return { verifier, challenge: challengeOf(verifier) };
|
|
11869
11964
|
}
|
|
@@ -11874,7 +11969,7 @@ var OAuthStates = class {
|
|
|
11874
11969
|
clock;
|
|
11875
11970
|
pending = /* @__PURE__ */ new Map();
|
|
11876
11971
|
issue(source, verifier) {
|
|
11877
|
-
const state = b64url(
|
|
11972
|
+
const state = b64url(randomBytes8(24));
|
|
11878
11973
|
this.pending.set(state, { source, verifier, at: this.clock() });
|
|
11879
11974
|
while (this.pending.size > MAX_STATES) this.pending.delete(this.pending.keys().next().value);
|
|
11880
11975
|
return state;
|
|
@@ -11898,23 +11993,23 @@ var MusicTokens = class {
|
|
|
11898
11993
|
reconnect = /* @__PURE__ */ new Set();
|
|
11899
11994
|
generations = /* @__PURE__ */ new Map();
|
|
11900
11995
|
file(source) {
|
|
11901
|
-
return
|
|
11996
|
+
return join15(this.dir, `music-${source}.tokens.json`);
|
|
11902
11997
|
}
|
|
11903
11998
|
save(source, login) {
|
|
11904
|
-
|
|
11999
|
+
mkdirSync10(this.dir, { recursive: true });
|
|
11905
12000
|
const file = this.file(source);
|
|
11906
|
-
|
|
12001
|
+
writeFileSync9(file, JSON.stringify(login), { mode: 384 });
|
|
11907
12002
|
try {
|
|
11908
|
-
|
|
12003
|
+
chmodSync5(file, 384);
|
|
11909
12004
|
} catch {
|
|
11910
12005
|
}
|
|
11911
12006
|
this.reconnect.delete(source);
|
|
11912
12007
|
}
|
|
11913
12008
|
load(source) {
|
|
11914
12009
|
const file = this.file(source);
|
|
11915
|
-
if (!
|
|
12010
|
+
if (!existsSync14(file)) return null;
|
|
11916
12011
|
try {
|
|
11917
|
-
const j = JSON.parse(
|
|
12012
|
+
const j = JSON.parse(readFileSync9(file, "utf8"));
|
|
11918
12013
|
if (typeof j.accessToken !== "string" || typeof j.refreshToken !== "string" || typeof j.expiresAt !== "number" || typeof j.account !== "string") return null;
|
|
11919
12014
|
return { accessToken: j.accessToken, refreshToken: j.refreshToken, expiresAt: j.expiresAt, account: j.account, premium: typeof j.premium === "boolean" ? j.premium : null };
|
|
11920
12015
|
} catch {
|
|
@@ -11944,21 +12039,21 @@ var MusicSecrets = class {
|
|
|
11944
12039
|
}
|
|
11945
12040
|
dir;
|
|
11946
12041
|
file(source) {
|
|
11947
|
-
return
|
|
12042
|
+
return join15(this.dir, `music-${source}.secret.json`);
|
|
11948
12043
|
}
|
|
11949
12044
|
set(source, secret) {
|
|
11950
|
-
|
|
12045
|
+
mkdirSync10(this.dir, { recursive: true });
|
|
11951
12046
|
const file = this.file(source);
|
|
11952
|
-
|
|
12047
|
+
writeFileSync9(file, JSON.stringify({ secret }), { mode: 384 });
|
|
11953
12048
|
try {
|
|
11954
|
-
|
|
12049
|
+
chmodSync5(file, 384);
|
|
11955
12050
|
} catch {
|
|
11956
12051
|
}
|
|
11957
12052
|
}
|
|
11958
12053
|
/** For the service's own token call only. */
|
|
11959
12054
|
get(source) {
|
|
11960
12055
|
try {
|
|
11961
|
-
const j = JSON.parse(
|
|
12056
|
+
const j = JSON.parse(readFileSync9(this.file(source), "utf8"));
|
|
11962
12057
|
return typeof j.secret === "string" ? j.secret : "";
|
|
11963
12058
|
} catch {
|
|
11964
12059
|
return "";
|
|
@@ -12546,7 +12641,7 @@ var HostPlayer = class {
|
|
|
12546
12641
|
// ../server/src/music/library.ts
|
|
12547
12642
|
import { createHash as createHash10 } from "node:crypto";
|
|
12548
12643
|
import { lstat, readdir, readFile, realpath, stat } from "node:fs/promises";
|
|
12549
|
-
import { basename as basename2, extname as extname2, join as
|
|
12644
|
+
import { basename as basename2, extname as extname2, join as join16, sep as sep2 } from "node:path";
|
|
12550
12645
|
import { parseFile } from "music-metadata";
|
|
12551
12646
|
var MAX_PAGE = 500;
|
|
12552
12647
|
var MAX_COVER_BYTES = 3 * 1024 * 1024;
|
|
@@ -12601,7 +12696,7 @@ var MusicLibrary = class {
|
|
|
12601
12696
|
const depthLimit = this.o.scanDepth();
|
|
12602
12697
|
const found = [];
|
|
12603
12698
|
let truncated = false;
|
|
12604
|
-
const
|
|
12699
|
+
const walk3 = async (dir, rel, depth) => {
|
|
12605
12700
|
if (truncated) return;
|
|
12606
12701
|
let entries;
|
|
12607
12702
|
try {
|
|
@@ -12621,7 +12716,7 @@ var MusicLibrary = class {
|
|
|
12621
12716
|
if (e.name.startsWith(".") || e.isSymbolicLink()) continue;
|
|
12622
12717
|
const childRel = rel ? `${rel}${sep2}${e.name}` : e.name;
|
|
12623
12718
|
if (e.isDirectory()) {
|
|
12624
|
-
if (depth < depthLimit) await
|
|
12719
|
+
if (depth < depthLimit) await walk3(join16(dir, e.name), childRel, depth + 1);
|
|
12625
12720
|
} else if (e.isFile() && allowed.has(extname2(e.name).slice(1).toLowerCase())) {
|
|
12626
12721
|
if (found.length >= max) {
|
|
12627
12722
|
truncated = true;
|
|
@@ -12631,7 +12726,7 @@ var MusicLibrary = class {
|
|
|
12631
12726
|
}
|
|
12632
12727
|
}
|
|
12633
12728
|
};
|
|
12634
|
-
await
|
|
12729
|
+
await walk3(root, "", 0);
|
|
12635
12730
|
const tracks = new Array(found.length);
|
|
12636
12731
|
let next = 0;
|
|
12637
12732
|
const worker = async () => {
|
|
@@ -12653,7 +12748,7 @@ var MusicLibrary = class {
|
|
|
12653
12748
|
const name = basename2(rel);
|
|
12654
12749
|
const ext = extname2(name).slice(1).toLowerCase();
|
|
12655
12750
|
const stem = name.slice(0, name.length - extname2(name).length);
|
|
12656
|
-
const parent = rel.includes(sep2) ? basename2(
|
|
12751
|
+
const parent = rel.includes(sep2) ? basename2(join16(rel, "..")) : "";
|
|
12657
12752
|
let title2 = "";
|
|
12658
12753
|
let artist = "";
|
|
12659
12754
|
let album = "";
|
|
@@ -12661,7 +12756,7 @@ var MusicLibrary = class {
|
|
|
12661
12756
|
let durationSec = null;
|
|
12662
12757
|
let embedded = false;
|
|
12663
12758
|
try {
|
|
12664
|
-
const m = await parseFile(
|
|
12759
|
+
const m = await parseFile(join16(root, rel));
|
|
12665
12760
|
title2 = m.common.title?.trim() ?? "";
|
|
12666
12761
|
artist = (m.common.artist ?? m.common.albumartist ?? "").trim();
|
|
12667
12762
|
album = m.common.album?.trim() ?? "";
|
|
@@ -12704,7 +12799,7 @@ var MusicLibrary = class {
|
|
|
12704
12799
|
if (!t || !this.root) return null;
|
|
12705
12800
|
const allowed = this.o.extensions().map((e) => e.toLowerCase().replace(/^\./, ""));
|
|
12706
12801
|
if (!allowed.includes(t.ext)) return null;
|
|
12707
|
-
return this.inside(
|
|
12802
|
+
return this.inside(join16(this.root, t.rel));
|
|
12708
12803
|
}
|
|
12709
12804
|
async inside(path3) {
|
|
12710
12805
|
try {
|
|
@@ -12722,7 +12817,7 @@ var MusicLibrary = class {
|
|
|
12722
12817
|
const t = this.tracks.find((x) => x.id === id2);
|
|
12723
12818
|
if (!t || !this.root) return null;
|
|
12724
12819
|
if (t.coverFile) {
|
|
12725
|
-
const path3 = await this.inside(
|
|
12820
|
+
const path3 = await this.inside(join16(this.root, t.coverFile));
|
|
12726
12821
|
if (path3) {
|
|
12727
12822
|
try {
|
|
12728
12823
|
if ((await stat(path3)).size <= MAX_COVER_BYTES) return { mime: COVER_EXT[extname2(path3).slice(1).toLowerCase()], data: await readFile(path3) };
|
|
@@ -12731,7 +12826,7 @@ var MusicLibrary = class {
|
|
|
12731
12826
|
}
|
|
12732
12827
|
}
|
|
12733
12828
|
if (t.embedded) {
|
|
12734
|
-
const path3 = await this.inside(
|
|
12829
|
+
const path3 = await this.inside(join16(this.root, t.rel));
|
|
12735
12830
|
if (path3) {
|
|
12736
12831
|
try {
|
|
12737
12832
|
const pic = (await parseFile(path3)).common.picture?.[0];
|
|
@@ -13228,11 +13323,11 @@ function buildReport(input) {
|
|
|
13228
13323
|
out.push("");
|
|
13229
13324
|
if (!snap.positions.ok) out.push(missing("Positions", snap.positions));
|
|
13230
13325
|
else {
|
|
13231
|
-
const
|
|
13232
|
-
if (
|
|
13326
|
+
const open3 = snap.positions.data.filter((p) => p.quantity !== 0);
|
|
13327
|
+
if (open3.length === 0) out.push("No open positions.");
|
|
13233
13328
|
else {
|
|
13234
13329
|
out.push("Open positions:");
|
|
13235
|
-
for (const p of
|
|
13330
|
+
for (const p of open3) out.push(`- ${p.symbol} ${p.product} ${p.quantity}${p.quantity < 0 ? " (short)" : ""} @ ${fmt(p.avgPrice)}, P&L ${signed(p.pnl)}`);
|
|
13236
13331
|
}
|
|
13237
13332
|
}
|
|
13238
13333
|
}
|
|
@@ -13346,9 +13441,9 @@ var ReportSchedules = class {
|
|
|
13346
13441
|
};
|
|
13347
13442
|
|
|
13348
13443
|
// ../server/src/brokers/session.ts
|
|
13349
|
-
import { randomBytes as
|
|
13350
|
-
import { chmodSync as
|
|
13351
|
-
import { join as
|
|
13444
|
+
import { randomBytes as randomBytes9 } from "node:crypto";
|
|
13445
|
+
import { chmodSync as chmodSync6, existsSync as existsSync15, mkdirSync as mkdirSync11, readFileSync as readFileSync10, rmSync as rmSync8, writeFileSync as writeFileSync10 } from "node:fs";
|
|
13446
|
+
import { join as join17 } from "node:path";
|
|
13352
13447
|
var STATE_TTL_MS2 = 10 * 6e4;
|
|
13353
13448
|
var MAX_STATES2 = 20;
|
|
13354
13449
|
var BROKER_ID = /^[a-z0-9-]{1,40}$/;
|
|
@@ -13362,14 +13457,14 @@ var BrokerSessions = class {
|
|
|
13362
13457
|
states = /* @__PURE__ */ new Map();
|
|
13363
13458
|
file(broker) {
|
|
13364
13459
|
if (!BROKER_ID.test(broker)) throw new Error("That is not a broker id.");
|
|
13365
|
-
return
|
|
13460
|
+
return join17(this.dir, `broker-${broker}.session.json`);
|
|
13366
13461
|
}
|
|
13367
13462
|
save(broker, info) {
|
|
13368
13463
|
const file = this.file(broker);
|
|
13369
|
-
|
|
13370
|
-
|
|
13464
|
+
mkdirSync11(this.dir, { recursive: true });
|
|
13465
|
+
writeFileSync10(file, JSON.stringify({ accessToken: info.accessToken, expiresAt: info.expiresAt }), { mode: 384 });
|
|
13371
13466
|
try {
|
|
13372
|
-
|
|
13467
|
+
chmodSync6(file, 384);
|
|
13373
13468
|
} catch {
|
|
13374
13469
|
}
|
|
13375
13470
|
}
|
|
@@ -13377,9 +13472,9 @@ var BrokerSessions = class {
|
|
|
13377
13472
|
load(broker) {
|
|
13378
13473
|
if (!BROKER_ID.test(broker)) return null;
|
|
13379
13474
|
const file = this.file(broker);
|
|
13380
|
-
if (!
|
|
13475
|
+
if (!existsSync15(file)) return null;
|
|
13381
13476
|
try {
|
|
13382
|
-
const raw = JSON.parse(
|
|
13477
|
+
const raw = JSON.parse(readFileSync10(file, "utf8"));
|
|
13383
13478
|
if (typeof raw.accessToken !== "string" || typeof raw.expiresAt !== "number") return null;
|
|
13384
13479
|
if (raw.expiresAt <= this.clock()) {
|
|
13385
13480
|
this.clear(broker);
|
|
@@ -13396,7 +13491,7 @@ var BrokerSessions = class {
|
|
|
13396
13491
|
}
|
|
13397
13492
|
/** A fresh unguessable code for one login at `broker`. At most twenty wait at once; the oldest is dropped. */
|
|
13398
13493
|
newState(broker) {
|
|
13399
|
-
const state =
|
|
13494
|
+
const state = randomBytes9(24).toString("hex");
|
|
13400
13495
|
this.states.set(state, { broker, at: this.clock() });
|
|
13401
13496
|
while (this.states.size > MAX_STATES2) this.states.delete(this.states.keys().next().value);
|
|
13402
13497
|
return state;
|
|
@@ -13715,9 +13810,9 @@ ${url}`);
|
|
|
13715
13810
|
// ../server/src/codebox.ts
|
|
13716
13811
|
import { spawn as spawn4 } from "node:child_process";
|
|
13717
13812
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
13718
|
-
import { chmodSync as
|
|
13813
|
+
import { chmodSync as chmodSync7, mkdtempSync as mkdtempSync2, rmSync as rmSync9, writeFileSync as writeFileSync11 } from "node:fs";
|
|
13719
13814
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
13720
|
-
import { join as
|
|
13815
|
+
import { join as join18 } from "node:path";
|
|
13721
13816
|
var MAX_CODE_CHARS = 5e4;
|
|
13722
13817
|
var MAX_OUTPUT_CHARS = 2e4;
|
|
13723
13818
|
var MAX_EXTRA_FILES = 10;
|
|
@@ -13777,15 +13872,15 @@ var CodeBox = class {
|
|
|
13777
13872
|
if (extra.reduce((sum, [, body]) => sum + body.length, 0) > MAX_EXTRA_FILE_CHARS) return { ok: false, error: "The sandbox files are too large." };
|
|
13778
13873
|
const setup = SETUP[input.language];
|
|
13779
13874
|
const timeoutMs = input.timeoutSec && input.timeoutSec > 0 ? Math.min(input.timeoutSec * 1e3, MAX_TIMEOUT_MS) : DEFAULT_TIMEOUT_MS;
|
|
13780
|
-
const dir = mkdtempSync2(
|
|
13875
|
+
const dir = mkdtempSync2(join18(tmpdir2(), "friend-code-"));
|
|
13781
13876
|
try {
|
|
13782
|
-
const file =
|
|
13783
|
-
|
|
13784
|
-
|
|
13785
|
-
|
|
13877
|
+
const file = join18(dir, setup.file);
|
|
13878
|
+
writeFileSync11(file, input.code);
|
|
13879
|
+
chmodSync7(dir, 493);
|
|
13880
|
+
chmodSync7(file, 420);
|
|
13786
13881
|
for (const [name, body] of extra) {
|
|
13787
|
-
|
|
13788
|
-
|
|
13882
|
+
writeFileSync11(join18(dir, name), body);
|
|
13883
|
+
chmodSync7(join18(dir, name), 420);
|
|
13789
13884
|
}
|
|
13790
13885
|
const args = [
|
|
13791
13886
|
"run",
|
|
@@ -13929,26 +14024,26 @@ var Memory = class {
|
|
|
13929
14024
|
};
|
|
13930
14025
|
|
|
13931
14026
|
// ../server/src/memory/import.ts
|
|
13932
|
-
import { existsSync as
|
|
13933
|
-
import { join as
|
|
14027
|
+
import { existsSync as existsSync16, writeFileSync as writeFileSync12 } from "node:fs";
|
|
14028
|
+
import { join as join19 } from "node:path";
|
|
13934
14029
|
var MARKER = ".imported-notes";
|
|
13935
14030
|
function importFlatNotes(memory, tree2) {
|
|
13936
14031
|
tree2.ensure();
|
|
13937
|
-
const marker =
|
|
13938
|
-
if (
|
|
14032
|
+
const marker = join19(tree2.root, MARKER);
|
|
14033
|
+
if (existsSync16(marker)) return 0;
|
|
13939
14034
|
let n2 = 0;
|
|
13940
14035
|
for (const m of [...memory.list()].reverse()) {
|
|
13941
14036
|
const name = inboxName(m.text, (x) => tree2.has(`inbox/${x}.md`));
|
|
13942
14037
|
const r = tree2.write(`inbox/${name}.md`, m.text, { title: m.text.slice(0, 60), summary: m.text.slice(0, 120), source: "import", ...n2 === 0 ? { folderSummary: "quick notes not filed yet, and notes brought over from the older list" } : {} });
|
|
13943
14038
|
if (r.ok) n2++;
|
|
13944
14039
|
}
|
|
13945
|
-
|
|
14040
|
+
writeFileSync12(marker, (/* @__PURE__ */ new Date()).toISOString());
|
|
13946
14041
|
return n2;
|
|
13947
14042
|
}
|
|
13948
14043
|
|
|
13949
14044
|
// ../server/src/memory/keeper.ts
|
|
13950
|
-
import { existsSync as
|
|
13951
|
-
import { join as
|
|
14045
|
+
import { existsSync as existsSync17, readFileSync as readFileSync11, writeFileSync as writeFileSync13 } from "node:fs";
|
|
14046
|
+
import { join as join20 } from "node:path";
|
|
13952
14047
|
import { z as z11 } from "zod";
|
|
13953
14048
|
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.
|
|
13954
14049
|
|
|
@@ -14016,12 +14111,12 @@ var MemoryKeeper = class {
|
|
|
14016
14111
|
this.d.after?.();
|
|
14017
14112
|
}
|
|
14018
14113
|
cursorPath() {
|
|
14019
|
-
return
|
|
14114
|
+
return join20(this.d.tree.root, CURSOR_FILE);
|
|
14020
14115
|
}
|
|
14021
14116
|
readCursor() {
|
|
14022
14117
|
try {
|
|
14023
|
-
if (!
|
|
14024
|
-
const n2 = Number(JSON.parse(
|
|
14118
|
+
if (!existsSync17(this.cursorPath())) return -1;
|
|
14119
|
+
const n2 = Number(JSON.parse(readFileSync11(this.cursorPath(), "utf8")).lastId);
|
|
14025
14120
|
return Number.isInteger(n2) && n2 >= 0 ? n2 : -1;
|
|
14026
14121
|
} catch {
|
|
14027
14122
|
return -1;
|
|
@@ -14029,7 +14124,7 @@ var MemoryKeeper = class {
|
|
|
14029
14124
|
}
|
|
14030
14125
|
writeCursor(id2) {
|
|
14031
14126
|
this.d.tree.ensure();
|
|
14032
|
-
|
|
14127
|
+
writeFileSync13(this.cursorPath(), JSON.stringify({ lastId: id2 }));
|
|
14033
14128
|
}
|
|
14034
14129
|
window(after) {
|
|
14035
14130
|
const max = this.d.db.prepare("select max(id) m from messages").get().m ?? 0;
|
|
@@ -14314,7 +14409,7 @@ ${n2.body.trim().slice(0, NOTE_CHARS)}`).join("\n")}`,
|
|
|
14314
14409
|
};
|
|
14315
14410
|
|
|
14316
14411
|
// ../server/src/proactive/beat.ts
|
|
14317
|
-
import { existsSync as
|
|
14412
|
+
import { existsSync as existsSync18, readFileSync as readFileSync12, writeFileSync as writeFileSync14 } from "node:fs";
|
|
14318
14413
|
var LEVEL2 = { off: 0, low: 1, medium: 2, high: 3 };
|
|
14319
14414
|
var MAX_SAY = 400;
|
|
14320
14415
|
var OVERDUE_AFTER_MS = 2 * 36e5;
|
|
@@ -14357,8 +14452,8 @@ var ProactiveBeat = class {
|
|
|
14357
14452
|
}
|
|
14358
14453
|
load(day2) {
|
|
14359
14454
|
try {
|
|
14360
|
-
if (
|
|
14361
|
-
const s = JSON.parse(
|
|
14455
|
+
if (existsSync18(this.d.statePath)) {
|
|
14456
|
+
const s = JSON.parse(readFileSync12(this.d.statePath, "utf8"));
|
|
14362
14457
|
if (s.day === day2) return { day: day2, sent: s.sent ?? 0, lastAt: s.lastAt ?? 0, fired: s.fired ?? {}, said: s.said ?? [] };
|
|
14363
14458
|
const week = this.now() - 7 * 864e5;
|
|
14364
14459
|
return { day: day2, sent: 0, lastAt: s.lastAt ?? 0, fired: Object.fromEntries(Object.entries(s.fired ?? {}).filter(([, t]) => t > week)), said: [] };
|
|
@@ -14369,7 +14464,7 @@ var ProactiveBeat = class {
|
|
|
14369
14464
|
}
|
|
14370
14465
|
save(s) {
|
|
14371
14466
|
try {
|
|
14372
|
-
|
|
14467
|
+
writeFileSync14(this.d.statePath, JSON.stringify(s));
|
|
14373
14468
|
} catch {
|
|
14374
14469
|
}
|
|
14375
14470
|
}
|
|
@@ -14395,15 +14490,15 @@ var ProactiveBeat = class {
|
|
|
14395
14490
|
}
|
|
14396
14491
|
const here2 = this.d.screens() > 0 || c.phone && !!this.d.phoneReady?.();
|
|
14397
14492
|
if (lvl >= 2 && here2) {
|
|
14398
|
-
const
|
|
14399
|
-
const todays =
|
|
14493
|
+
const open3 = this.d.tasks.list();
|
|
14494
|
+
const todays = open3.filter((t) => t.dueAt !== null && dayKey2(new Date(t.dueAt)) === day2);
|
|
14400
14495
|
const office = this.d.officeLine?.() ?? null;
|
|
14401
14496
|
if (minute >= hm(c.morningAt) && minute < hm(c.morningAt) + 240) {
|
|
14402
14497
|
out.push({
|
|
14403
14498
|
key: `morning:${day2}`,
|
|
14404
14499
|
kind: "morning",
|
|
14405
14500
|
level: 2,
|
|
14406
|
-
facts: [`It is the morning of ${at.toDateString()}.`, todays.length ? `Due today: ${todays.map((t) => t.title).join("; ")}.` : "Nothing is due today.", `${
|
|
14501
|
+
facts: [`It is the morning of ${at.toDateString()}.`, todays.length ? `Due today: ${todays.map((t) => t.title).join("; ")}.` : "Nothing is due today.", `${open3.length} items are open on the task list.`, ...office ? [`Office: ${office}`] : []]
|
|
14407
14502
|
});
|
|
14408
14503
|
}
|
|
14409
14504
|
if (minute >= hm(c.eveningAt) && !within(minute, c.quietFrom, c.quietTo)) {
|
|
@@ -14518,14 +14613,14 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
|
14518
14613
|
|
|
14519
14614
|
// ../server/src/office/office.ts
|
|
14520
14615
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
14521
|
-
import { mkdirSync as
|
|
14522
|
-
import { join as
|
|
14616
|
+
import { mkdirSync as mkdirSync12, statSync as statSync3, writeFileSync as writeFileSync15 } from "node:fs";
|
|
14617
|
+
import { join as join21 } from "node:path";
|
|
14523
14618
|
|
|
14524
14619
|
// ../server/src/provider/claude-code/bridge.ts
|
|
14525
14620
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
14526
14621
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
14527
14622
|
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
14528
|
-
import { randomBytes as
|
|
14623
|
+
import { randomBytes as randomBytes10, timingSafeEqual as timingSafeEqual4 } from "node:crypto";
|
|
14529
14624
|
import { createServer } from "node:http";
|
|
14530
14625
|
var encodeToolName = (name) => name.replaceAll(".", "__");
|
|
14531
14626
|
var MAX_BODY_BYTES = 8 * 1024 * 1024;
|
|
@@ -14534,7 +14629,7 @@ var ToolBridge = class {
|
|
|
14534
14629
|
this.onCall = onCall;
|
|
14535
14630
|
}
|
|
14536
14631
|
onCall;
|
|
14537
|
-
token =
|
|
14632
|
+
token = randomBytes10(24).toString("hex");
|
|
14538
14633
|
tools = [];
|
|
14539
14634
|
http = null;
|
|
14540
14635
|
port = 0;
|
|
@@ -15177,10 +15272,10 @@ var Office = class {
|
|
|
15177
15272
|
const cfg = this.d.config();
|
|
15178
15273
|
await run2.bridge.start();
|
|
15179
15274
|
if (run2.concluded) return;
|
|
15180
|
-
const dir =
|
|
15181
|
-
|
|
15182
|
-
const mcp =
|
|
15183
|
-
|
|
15275
|
+
const dir = join21(this.d.dataDir, "office");
|
|
15276
|
+
mkdirSync12(dir, { recursive: true });
|
|
15277
|
+
const mcp = join21(dir, `${worker.id}.mcp.json`);
|
|
15278
|
+
writeFileSync15(mcp, JSON.stringify({ mcpServers: { office: { type: "http", url: run2.bridge.url, headers: { Authorization: `Bearer ${run2.bridge.token}` } } } }));
|
|
15184
15279
|
const args = buildWorkerArgs({
|
|
15185
15280
|
model: worker.model.trim() || cfg.claudeCode.model,
|
|
15186
15281
|
instructions: this.briefing(worker),
|
|
@@ -15439,7 +15534,7 @@ ${ticket.description}` : "", goal: project.goal, action: describeAction(tool, in
|
|
|
15439
15534
|
};
|
|
15440
15535
|
|
|
15441
15536
|
// ../server/src/office/store.ts
|
|
15442
|
-
import { randomBytes as
|
|
15537
|
+
import { randomBytes as randomBytes11 } from "node:crypto";
|
|
15443
15538
|
var MAX_EVENT_CHARS = 200;
|
|
15444
15539
|
var MAX_EVENTS_PER_WORKER = 500;
|
|
15445
15540
|
var toRequest = (r) => ({ id: r.id, workerId: r.worker_id, ticketId: r.ticket_id, tool: r.tool, summary: r.summary, danger: r.danger === 1, status: r.status, decision: r.decision, reason: r.reason, tries: r.tries, createdAt: r.created_at, decidedAt: r.decided_at });
|
|
@@ -15456,7 +15551,7 @@ var OfficeStore = class {
|
|
|
15456
15551
|
db;
|
|
15457
15552
|
now;
|
|
15458
15553
|
createWorker(w) {
|
|
15459
|
-
const id2 =
|
|
15554
|
+
const id2 = randomBytes11(4).toString("hex");
|
|
15460
15555
|
this.db.prepare("insert into office_workers (id, name, role_id, project_id, created_at, title, capabilities, instructions, model, permission, manager_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").run(id2, w.name, w.roleId, w.projectId, this.now(), w.title ?? "", w.capabilities ?? "", w.instructions ?? "", w.model ?? "", w.permission ?? "default", w.managerId ?? null);
|
|
15461
15556
|
return this.getWorker(id2);
|
|
15462
15557
|
}
|
|
@@ -15569,12 +15664,12 @@ var OfficeStore = class {
|
|
|
15569
15664
|
};
|
|
15570
15665
|
|
|
15571
15666
|
// ../server/src/app.ts
|
|
15572
|
-
import { join as
|
|
15667
|
+
import { join as join26 } from "node:path";
|
|
15573
15668
|
|
|
15574
15669
|
// ../server/src/db.ts
|
|
15575
15670
|
import Database from "better-sqlite3";
|
|
15576
|
-
import { mkdirSync as
|
|
15577
|
-
import { join as
|
|
15671
|
+
import { mkdirSync as mkdirSync13 } from "node:fs";
|
|
15672
|
+
import { join as join22 } from "node:path";
|
|
15578
15673
|
|
|
15579
15674
|
// ../server/src/migrations.ts
|
|
15580
15675
|
var MIGRATIONS = [
|
|
@@ -15869,8 +15964,8 @@ create trigger audit_no_delete before delete on audit_log begin select raise(abo
|
|
|
15869
15964
|
|
|
15870
15965
|
// ../server/src/db.ts
|
|
15871
15966
|
function openDb(dataDir) {
|
|
15872
|
-
|
|
15873
|
-
const db = new Database(
|
|
15967
|
+
mkdirSync13(dataDir, { recursive: true });
|
|
15968
|
+
const db = new Database(join22(dataDir, "friend.db"));
|
|
15874
15969
|
db.pragma("journal_mode = WAL");
|
|
15875
15970
|
db.pragma("foreign_keys = ON");
|
|
15876
15971
|
db.exec("create table if not exists schema_version (id integer primary key, applied_at integer not null)");
|
|
@@ -16199,17 +16294,17 @@ function scan2(html) {
|
|
|
16199
16294
|
}
|
|
16200
16295
|
return { title: title2, out: out.join("") };
|
|
16201
16296
|
}
|
|
16202
|
-
function firstRegion(s,
|
|
16203
|
-
const a = s.indexOf(
|
|
16297
|
+
function firstRegion(s, open3, close) {
|
|
16298
|
+
const a = s.indexOf(open3);
|
|
16204
16299
|
if (a < 0) return null;
|
|
16205
16300
|
const b = s.indexOf(close, a + 1);
|
|
16206
16301
|
return s.slice(a + 1, b < 0 ? s.length : b);
|
|
16207
16302
|
}
|
|
16208
|
-
function allRegions(s,
|
|
16303
|
+
function allRegions(s, open3, close) {
|
|
16209
16304
|
const parts = [];
|
|
16210
16305
|
let at = 0;
|
|
16211
16306
|
for (; ; ) {
|
|
16212
|
-
const a = s.indexOf(
|
|
16307
|
+
const a = s.indexOf(open3, at);
|
|
16213
16308
|
if (a < 0) break;
|
|
16214
16309
|
const b = s.indexOf(close, a + 1);
|
|
16215
16310
|
parts.push(s.slice(a + 1, b < 0 ? s.length : b));
|
|
@@ -16501,7 +16596,7 @@ var DeviceHub = class {
|
|
|
16501
16596
|
import fastifyCookie from "@fastify/cookie";
|
|
16502
16597
|
|
|
16503
16598
|
// ../server/src/auditApi.ts
|
|
16504
|
-
import { randomBytes as
|
|
16599
|
+
import { randomBytes as randomBytes12 } from "node:crypto";
|
|
16505
16600
|
import { z as z13 } from "zod";
|
|
16506
16601
|
|
|
16507
16602
|
// ../server/src/auditExport.ts
|
|
@@ -16550,7 +16645,7 @@ var UnlockStore = class {
|
|
|
16550
16645
|
issue(minutes3) {
|
|
16551
16646
|
const t = this.now();
|
|
16552
16647
|
for (const [k, v] of this.tokens) if (v < t) this.tokens.delete(k);
|
|
16553
|
-
const token =
|
|
16648
|
+
const token = randomBytes12(32).toString("hex");
|
|
16554
16649
|
const expiresAt = t + minutes3 * 6e4;
|
|
16555
16650
|
this.tokens.set(token, expiresAt);
|
|
16556
16651
|
return { token, expiresAt };
|
|
@@ -16687,15 +16782,15 @@ function registerAuditRoutes(d) {
|
|
|
16687
16782
|
app.get("/api/audit/status", { onRequest: guard2 }, async (req) => {
|
|
16688
16783
|
read("/api/audit/status", req);
|
|
16689
16784
|
const last = d.audit.last();
|
|
16690
|
-
const
|
|
16691
|
-
return { rows: d.query.counts({}).total, lastId: last?.id ?? null, lastSeal:
|
|
16785
|
+
const seal2 = d.query.lastSeal();
|
|
16786
|
+
return { rows: d.query.counts({}).total, lastId: last?.id ?? null, lastSeal: seal2 ? { at: seal2.ts, text: seal2.detail.seal ?? null } : null, keepDays: d.config().keepDays, workers: d.query.workers() };
|
|
16692
16787
|
});
|
|
16693
16788
|
}
|
|
16694
16789
|
|
|
16695
16790
|
// ../server/src/gateway.ts
|
|
16696
16791
|
import fastifyStatic from "@fastify/static";
|
|
16697
16792
|
import Fastify from "fastify";
|
|
16698
|
-
import { createReadStream as createReadStream2, existsSync as
|
|
16793
|
+
import { createReadStream as createReadStream2, existsSync as existsSync19, promises as fsp2 } from "node:fs";
|
|
16699
16794
|
import { isIP as isIP3 } from "node:net";
|
|
16700
16795
|
import { Readable } from "node:stream";
|
|
16701
16796
|
import { WebSocket as WebSocket2, WebSocketServer } from "ws";
|
|
@@ -17828,7 +17923,7 @@ function createGateway(deps) {
|
|
|
17828
17923
|
deps.onLock?.();
|
|
17829
17924
|
return { ok: true };
|
|
17830
17925
|
});
|
|
17831
|
-
if (deps.webDir &&
|
|
17926
|
+
if (deps.webDir && existsSync19(deps.webDir)) {
|
|
17832
17927
|
app.register(fastifyStatic, { root: deps.webDir });
|
|
17833
17928
|
app.setNotFoundHandler((req, reply) => {
|
|
17834
17929
|
if (req.method === "GET" && !req.url.startsWith("/api")) return reply.sendFile("index.html");
|
|
@@ -17983,9 +18078,9 @@ Connection: close\r
|
|
|
17983
18078
|
|
|
17984
18079
|
// ../server/src/browser/hub.ts
|
|
17985
18080
|
import { spawn as spawn7, spawnSync } from "node:child_process";
|
|
17986
|
-
import { mkdirSync as
|
|
18081
|
+
import { mkdirSync as mkdirSync14, mkdtempSync as mkdtempSync3, readdirSync as readdirSync6, readFileSync as readFileSync13, rmSync as rmSync10, statSync as statSync5 } from "node:fs";
|
|
17987
18082
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
17988
|
-
import { join as
|
|
18083
|
+
import { join as join23 } from "node:path";
|
|
17989
18084
|
|
|
17990
18085
|
// ../server/src/browser/cdp.ts
|
|
17991
18086
|
import { WebSocket as WebSocket3 } from "ws";
|
|
@@ -18055,11 +18150,11 @@ var Cdp = class _Cdp {
|
|
|
18055
18150
|
};
|
|
18056
18151
|
|
|
18057
18152
|
// ../server/src/browser/chrome.ts
|
|
18058
|
-
import { existsSync as
|
|
18153
|
+
import { existsSync as existsSync20, statSync as statSync4 } from "node:fs";
|
|
18059
18154
|
import { posix as posix3, win32 as win323 } from "node:path";
|
|
18060
18155
|
var fileThere = (p) => {
|
|
18061
18156
|
try {
|
|
18062
|
-
return
|
|
18157
|
+
return existsSync20(p) && statSync4(p).isFile();
|
|
18063
18158
|
} catch {
|
|
18064
18159
|
return false;
|
|
18065
18160
|
}
|
|
@@ -18070,15 +18165,15 @@ function findChrome(override = "", w = {}) {
|
|
|
18070
18165
|
const platform = w.platform ?? process.platform;
|
|
18071
18166
|
const env = w.env ?? process.env;
|
|
18072
18167
|
const isFile = w.isFile ?? fileThere;
|
|
18073
|
-
const
|
|
18168
|
+
const join36 = platform === "win32" ? win323.join : posix3.join;
|
|
18074
18169
|
if (override.trim()) return isFile(override.trim()) ? override.trim() : null;
|
|
18075
18170
|
if (platform === "win32") {
|
|
18076
18171
|
const roots = [env.PROGRAMFILES, env["PROGRAMFILES(X86)"], env.LOCALAPPDATA].filter((r) => !!r);
|
|
18077
|
-
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(
|
|
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(join36(r, rel))) return join36(r, rel);
|
|
18078
18173
|
return null;
|
|
18079
18174
|
}
|
|
18080
18175
|
if (platform === "darwin") return MAC_PATHS.find(isFile) ?? null;
|
|
18081
|
-
for (const dir of (env.PATH ?? "").split(":").filter(Boolean)) for (const name of LINUX_NAMES) if (isFile(
|
|
18176
|
+
for (const dir of (env.PATH ?? "").split(":").filter(Boolean)) for (const name of LINUX_NAMES) if (isFile(join36(dir, name))) return join36(dir, name);
|
|
18082
18177
|
return null;
|
|
18083
18178
|
}
|
|
18084
18179
|
|
|
@@ -18105,7 +18200,7 @@ var BrowserHub = class {
|
|
|
18105
18200
|
try {
|
|
18106
18201
|
for (const name of readdirSync6(root)) {
|
|
18107
18202
|
if (!/^friend-browser-/.test(name)) continue;
|
|
18108
|
-
const dir =
|
|
18203
|
+
const dir = join23(root, name);
|
|
18109
18204
|
if (Date.now() - statSync5(dir).mtimeMs > 36e5) rmSync10(dir, { recursive: true, force: true });
|
|
18110
18205
|
}
|
|
18111
18206
|
} catch {
|
|
@@ -18169,8 +18264,8 @@ A picture of the page "${r.value.title || r.value.href}" (${r.value.href}). Text
|
|
|
18169
18264
|
let cdp = null;
|
|
18170
18265
|
try {
|
|
18171
18266
|
const root = this.o.tmpRoot ?? tmpdir3();
|
|
18172
|
-
|
|
18173
|
-
profile = mkdtempSync3(
|
|
18267
|
+
mkdirSync14(root, { recursive: true });
|
|
18268
|
+
profile = mkdtempSync3(join23(root, "friend-browser-"));
|
|
18174
18269
|
child = spawn7(
|
|
18175
18270
|
chrome,
|
|
18176
18271
|
[
|
|
@@ -18284,7 +18379,7 @@ async function endpoint(profile, signal) {
|
|
|
18284
18379
|
for (; ; ) {
|
|
18285
18380
|
signal.throwIfAborted();
|
|
18286
18381
|
try {
|
|
18287
|
-
const [port, path3] =
|
|
18382
|
+
const [port, path3] = readFileSync13(join23(profile, "DevToolsActivePort"), "utf8").split("\n");
|
|
18288
18383
|
if (port && path3) return `ws://127.0.0.1:${port.trim()}${path3.trim()}`;
|
|
18289
18384
|
} catch {
|
|
18290
18385
|
}
|
|
@@ -18526,8 +18621,8 @@ function startStatsFeed(opts) {
|
|
|
18526
18621
|
|
|
18527
18622
|
// ../server/src/provider/claude-code/provider.ts
|
|
18528
18623
|
import { createHash as createHash12 } from "node:crypto";
|
|
18529
|
-
import { chmodSync as
|
|
18530
|
-
import { join as
|
|
18624
|
+
import { chmodSync as chmodSync8, existsSync as existsSync21, mkdirSync as mkdirSync15, readdirSync as readdirSync7, readFileSync as readFileSync14, rmSync as rmSync11, writeFileSync as writeFileSync16 } from "node:fs";
|
|
18625
|
+
import { join as join24 } from "node:path";
|
|
18531
18626
|
|
|
18532
18627
|
// ../server/src/provider/claude-code/limits.ts
|
|
18533
18628
|
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;
|
|
@@ -18625,7 +18720,7 @@ var NOT_SIGNED_IN = /not logged in|please run \/login|invalid api key|authentica
|
|
|
18625
18720
|
var ClaudeCodeProvider = class {
|
|
18626
18721
|
constructor(opts) {
|
|
18627
18722
|
this.opts = opts;
|
|
18628
|
-
this.home =
|
|
18723
|
+
this.home = join24(opts.dataDir, "claude");
|
|
18629
18724
|
this.now = opts.now ?? Date.now;
|
|
18630
18725
|
this.bridge = new ToolBridge((call) => this.owner.inbox.push({ kind: "call", call }));
|
|
18631
18726
|
}
|
|
@@ -18689,10 +18784,10 @@ var ClaudeCodeProvider = class {
|
|
|
18689
18784
|
conv.hasContext = false;
|
|
18690
18785
|
conv.systemKey = "";
|
|
18691
18786
|
this.forgetSession(conv);
|
|
18692
|
-
|
|
18787
|
+
mkdirSync15(this.home, { recursive: true });
|
|
18693
18788
|
this.fresh = { seed: seed?.trim() || null };
|
|
18694
18789
|
try {
|
|
18695
|
-
|
|
18790
|
+
writeFileSync16(this.freshFile(), JSON.stringify(this.fresh));
|
|
18696
18791
|
} catch {
|
|
18697
18792
|
}
|
|
18698
18793
|
}
|
|
@@ -18851,7 +18946,7 @@ ${item.stderr}`;
|
|
|
18851
18946
|
conv.proc = null;
|
|
18852
18947
|
}
|
|
18853
18948
|
conv.inbox.clear();
|
|
18854
|
-
|
|
18949
|
+
mkdirSync15(this.home, { recursive: true });
|
|
18855
18950
|
if (!conv.guest) {
|
|
18856
18951
|
conv.sessionId ??= this.readSession();
|
|
18857
18952
|
this.fresh = conv.sessionId ? null : this.readFresh();
|
|
@@ -18881,7 +18976,7 @@ ${item.stderr}`;
|
|
|
18881
18976
|
"local",
|
|
18882
18977
|
"--system-prompt-file",
|
|
18883
18978
|
systemFile,
|
|
18884
|
-
...conv.guest ? ["--no-session-persistence"] : ["--mcp-config",
|
|
18979
|
+
...conv.guest ? ["--no-session-persistence"] : ["--mcp-config", join24(this.home, "mcp.json"), "--allowedTools", [...web ? ["WebSearch"] : [], ...req.tools.map((t) => `mcp__friend__${encodeToolName(t.name)}`)].join(","), ...resume ? ["--resume", resume] : []]
|
|
18885
18980
|
];
|
|
18886
18981
|
const proc = new ClaudeProc(
|
|
18887
18982
|
{
|
|
@@ -18910,14 +19005,14 @@ ${item.stderr}`;
|
|
|
18910
19005
|
if (!this.swept) {
|
|
18911
19006
|
this.swept = true;
|
|
18912
19007
|
try {
|
|
18913
|
-
for (const f of readdirSync7(this.home)) if (/^system-\d+\.txt$/.test(f)) rmSync11(
|
|
19008
|
+
for (const f of readdirSync7(this.home)) if (/^system-\d+\.txt$/.test(f)) rmSync11(join24(this.home, f), { force: true });
|
|
18914
19009
|
} catch {
|
|
18915
19010
|
}
|
|
18916
19011
|
}
|
|
18917
|
-
const file =
|
|
18918
|
-
|
|
19012
|
+
const file = join24(this.home, `system-${++this.systemCount}.txt`);
|
|
19013
|
+
writeFileSync16(file, text4);
|
|
18919
19014
|
try {
|
|
18920
|
-
|
|
19015
|
+
chmodSync8(file, 384);
|
|
18921
19016
|
} catch {
|
|
18922
19017
|
}
|
|
18923
19018
|
return file;
|
|
@@ -18931,20 +19026,20 @@ ${item.stderr}`;
|
|
|
18931
19026
|
startBridge() {
|
|
18932
19027
|
this.bridgeReady ??= (async () => {
|
|
18933
19028
|
await this.bridge.start();
|
|
18934
|
-
const file =
|
|
18935
|
-
|
|
19029
|
+
const file = join24(this.home, "mcp.json");
|
|
19030
|
+
writeFileSync16(file, JSON.stringify({ mcpServers: { friend: { type: "http", url: this.bridge.url, headers: { Authorization: `Bearer ${this.bridge.token}` } } } }));
|
|
18936
19031
|
try {
|
|
18937
|
-
|
|
19032
|
+
chmodSync8(file, 384);
|
|
18938
19033
|
} catch {
|
|
18939
19034
|
}
|
|
18940
19035
|
})();
|
|
18941
19036
|
return this.bridgeReady;
|
|
18942
19037
|
}
|
|
18943
19038
|
// ---- the session id, kept so a restart of Friend can pick the conversation up again ----
|
|
18944
|
-
sessionFile = () =>
|
|
19039
|
+
sessionFile = () => join24(this.home, "session-id");
|
|
18945
19040
|
readSession() {
|
|
18946
19041
|
try {
|
|
18947
|
-
return
|
|
19042
|
+
return existsSync21(this.sessionFile()) ? readFileSync14(this.sessionFile(), "utf8").trim() || null : null;
|
|
18948
19043
|
} catch {
|
|
18949
19044
|
return null;
|
|
18950
19045
|
}
|
|
@@ -18958,15 +19053,15 @@ ${item.stderr}`;
|
|
|
18958
19053
|
} catch {
|
|
18959
19054
|
}
|
|
18960
19055
|
try {
|
|
18961
|
-
|
|
19056
|
+
writeFileSync16(this.sessionFile(), id2);
|
|
18962
19057
|
} catch {
|
|
18963
19058
|
}
|
|
18964
19059
|
}
|
|
18965
|
-
freshFile = () =>
|
|
19060
|
+
freshFile = () => join24(this.home, "fresh.json");
|
|
18966
19061
|
readFresh() {
|
|
18967
19062
|
try {
|
|
18968
|
-
if (!
|
|
18969
|
-
const r = JSON.parse(
|
|
19063
|
+
if (!existsSync21(this.freshFile())) return null;
|
|
19064
|
+
const r = JSON.parse(readFileSync14(this.freshFile(), "utf8"));
|
|
18970
19065
|
return { seed: typeof r.seed === "string" && r.seed ? r.seed : null };
|
|
18971
19066
|
} catch {
|
|
18972
19067
|
return null;
|
|
@@ -19978,10 +20073,10 @@ function dbWidgetStore(db) {
|
|
|
19978
20073
|
}
|
|
19979
20074
|
|
|
19980
20075
|
// ../server/src/tls.ts
|
|
19981
|
-
import { chmodSync as
|
|
20076
|
+
import { chmodSync as chmodSync9, existsSync as existsSync22, mkdirSync as mkdirSync16, readFileSync as readFileSync15, writeFileSync as writeFileSync17 } from "node:fs";
|
|
19982
20077
|
import { networkInterfaces } from "node:os";
|
|
19983
20078
|
import { isIP as isIP4 } from "node:net";
|
|
19984
|
-
import { join as
|
|
20079
|
+
import { join as join25 } from "node:path";
|
|
19985
20080
|
import { generate } from "selfsigned";
|
|
19986
20081
|
var DAYS = 825;
|
|
19987
20082
|
var RENEW_BEFORE_MS = 30 * 24 * 36e5;
|
|
@@ -19996,16 +20091,16 @@ function tlsHosts(extra = [], ifaces) {
|
|
|
19996
20091
|
return [.../* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", ...lanAddresses(ifaces), ...extra.map((h) => h.toLowerCase()).filter(Boolean)])];
|
|
19997
20092
|
}
|
|
19998
20093
|
async function ensureTlsCert(dataDir, extraHosts = [], ifaces, now = Date.now) {
|
|
19999
|
-
const dir =
|
|
20000
|
-
const keyFile =
|
|
20001
|
-
const certFile =
|
|
20002
|
-
const metaFile =
|
|
20094
|
+
const dir = join25(dataDir, "tls");
|
|
20095
|
+
const keyFile = join25(dir, "key.pem");
|
|
20096
|
+
const certFile = join25(dir, "cert.pem");
|
|
20097
|
+
const metaFile = join25(dir, "meta.json");
|
|
20003
20098
|
const hosts = tlsHosts(extraHosts, ifaces);
|
|
20004
|
-
if (
|
|
20099
|
+
if (existsSync22(keyFile) && existsSync22(certFile) && existsSync22(metaFile)) {
|
|
20005
20100
|
try {
|
|
20006
|
-
const meta = JSON.parse(
|
|
20101
|
+
const meta = JSON.parse(readFileSync15(metaFile, "utf8"));
|
|
20007
20102
|
const covered = hosts.every((h) => meta.hosts.includes(h));
|
|
20008
|
-
if (covered && meta.expires - now() > RENEW_BEFORE_MS) return { key:
|
|
20103
|
+
if (covered && meta.expires - now() > RENEW_BEFORE_MS) return { key: readFileSync15(keyFile, "utf8"), cert: readFileSync15(certFile, "utf8") };
|
|
20009
20104
|
} catch {
|
|
20010
20105
|
}
|
|
20011
20106
|
}
|
|
@@ -20023,12 +20118,12 @@ async function ensureTlsCert(dataDir, extraHosts = [], ifaces, now = Date.now) {
|
|
|
20023
20118
|
{ name: "subjectAltName", altNames }
|
|
20024
20119
|
]
|
|
20025
20120
|
});
|
|
20026
|
-
|
|
20027
|
-
|
|
20028
|
-
|
|
20029
|
-
|
|
20121
|
+
mkdirSync16(dir, { recursive: true });
|
|
20122
|
+
writeFileSync17(keyFile, pems.private);
|
|
20123
|
+
writeFileSync17(certFile, pems.cert);
|
|
20124
|
+
writeFileSync17(metaFile, JSON.stringify({ hosts, expires: now() + DAYS * 24 * 36e5 }));
|
|
20030
20125
|
try {
|
|
20031
|
-
|
|
20126
|
+
chmodSync9(keyFile, 384);
|
|
20032
20127
|
} catch {
|
|
20033
20128
|
}
|
|
20034
20129
|
return { key: pems.private, cert: pems.cert };
|
|
@@ -20072,7 +20167,7 @@ var DuckController = class {
|
|
|
20072
20167
|
|
|
20073
20168
|
// ../server/src/system/autostart.ts
|
|
20074
20169
|
import { spawn as spawn8 } from "node:child_process";
|
|
20075
|
-
import { existsSync as
|
|
20170
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync17, readFileSync as readFileSync16, rmSync as rmSync12, writeFileSync as writeFileSync18 } from "node:fs";
|
|
20076
20171
|
import { homedir as homedir4 } from "node:os";
|
|
20077
20172
|
import { dirname as dirname5, posix as posix4, win32 as win324 } from "node:path";
|
|
20078
20173
|
var RUN_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
@@ -20249,17 +20344,17 @@ function realAutostartDeps(dataDir) {
|
|
|
20249
20344
|
uid: typeof process.getuid === "function" ? process.getuid() : 0,
|
|
20250
20345
|
path: process.env.PATH ?? "",
|
|
20251
20346
|
...process.env.XDG_CONFIG_HOME ? { configHome: process.env.XDG_CONFIG_HOME } : {},
|
|
20252
|
-
exists: (p) =>
|
|
20347
|
+
exists: (p) => existsSync23(p),
|
|
20253
20348
|
read: (p) => {
|
|
20254
20349
|
try {
|
|
20255
|
-
return
|
|
20350
|
+
return readFileSync16(p, "utf8");
|
|
20256
20351
|
} catch {
|
|
20257
20352
|
return null;
|
|
20258
20353
|
}
|
|
20259
20354
|
},
|
|
20260
20355
|
write: (p, text4) => {
|
|
20261
|
-
|
|
20262
|
-
|
|
20356
|
+
mkdirSync17(dirname5(p), { recursive: true });
|
|
20357
|
+
writeFileSync18(p, text4);
|
|
20263
20358
|
},
|
|
20264
20359
|
remove: (p) => rmSync12(p, { force: true }),
|
|
20265
20360
|
run: (cmd, args) => new Promise((resolve13) => {
|
|
@@ -20280,7 +20375,7 @@ function currentSelf() {
|
|
|
20280
20375
|
// ../server/src/system/npm.ts
|
|
20281
20376
|
import { spawn as spawn9 } from "node:child_process";
|
|
20282
20377
|
var PACKAGE = "friend-assistant";
|
|
20283
|
-
var runningVersion = () => true ? "0.1.
|
|
20378
|
+
var runningVersion = () => true ? "0.1.72" : "development";
|
|
20284
20379
|
async function npmLatest(fetchFn = fetch, timeoutMs = 1e4) {
|
|
20285
20380
|
try {
|
|
20286
20381
|
const res = await fetchFn(`https://registry.npmjs.org/${PACKAGE}/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
|
|
@@ -20492,36 +20587,36 @@ var Challenges = class {
|
|
|
20492
20587
|
};
|
|
20493
20588
|
|
|
20494
20589
|
// ../server/src/voice/crypto.ts
|
|
20495
|
-
import { createCipheriv, createDecipheriv, randomBytes as
|
|
20496
|
-
import { chmodSync as
|
|
20590
|
+
import { createCipheriv as createCipheriv2, createDecipheriv as createDecipheriv2, randomBytes as randomBytes13 } from "node:crypto";
|
|
20591
|
+
import { chmodSync as chmodSync10, existsSync as existsSync24, mkdirSync as mkdirSync18, readFileSync as readFileSync17, writeFileSync as writeFileSync19 } from "node:fs";
|
|
20497
20592
|
import { dirname as dirname6 } from "node:path";
|
|
20498
20593
|
var KEY_BYTES = 32;
|
|
20499
20594
|
var IV_BYTES = 12;
|
|
20500
20595
|
var TAG_BYTES = 16;
|
|
20501
20596
|
function loadOrCreateKey(path3) {
|
|
20502
|
-
if (
|
|
20503
|
-
const key3 =
|
|
20597
|
+
if (existsSync24(path3)) {
|
|
20598
|
+
const key3 = readFileSync17(path3);
|
|
20504
20599
|
if (key3.length !== KEY_BYTES) throw new Error(`invalid voice key file (expected ${KEY_BYTES} bytes): ${path3}`);
|
|
20505
20600
|
return key3;
|
|
20506
20601
|
}
|
|
20507
|
-
|
|
20508
|
-
const key2 =
|
|
20509
|
-
|
|
20602
|
+
mkdirSync18(dirname6(path3), { recursive: true });
|
|
20603
|
+
const key2 = randomBytes13(KEY_BYTES);
|
|
20604
|
+
writeFileSync19(path3, key2, { mode: 384 });
|
|
20510
20605
|
try {
|
|
20511
|
-
|
|
20606
|
+
chmodSync10(path3, 384);
|
|
20512
20607
|
} catch {
|
|
20513
20608
|
}
|
|
20514
20609
|
return key2;
|
|
20515
20610
|
}
|
|
20516
20611
|
function encrypt(key2, plain6) {
|
|
20517
|
-
const iv =
|
|
20518
|
-
const cipher =
|
|
20612
|
+
const iv = randomBytes13(IV_BYTES);
|
|
20613
|
+
const cipher = createCipheriv2("aes-256-gcm", key2, iv);
|
|
20519
20614
|
const body = Buffer.concat([cipher.update(plain6), cipher.final()]);
|
|
20520
20615
|
return Buffer.concat([iv, cipher.getAuthTag(), body]);
|
|
20521
20616
|
}
|
|
20522
20617
|
function decrypt(key2, blob) {
|
|
20523
20618
|
if (blob.length < IV_BYTES + TAG_BYTES) throw new Error("encrypted data is too short");
|
|
20524
|
-
const decipher =
|
|
20619
|
+
const decipher = createDecipheriv2("aes-256-gcm", key2, blob.subarray(0, IV_BYTES));
|
|
20525
20620
|
decipher.setAuthTag(blob.subarray(IV_BYTES, IV_BYTES + TAG_BYTES));
|
|
20526
20621
|
return Buffer.concat([decipher.update(blob.subarray(IV_BYTES + TAG_BYTES)), decipher.final()]);
|
|
20527
20622
|
}
|
|
@@ -20909,9 +21004,9 @@ var Speaker = class {
|
|
|
20909
21004
|
if (alive()) this.active = false;
|
|
20910
21005
|
});
|
|
20911
21006
|
const take = (final) => {
|
|
20912
|
-
const
|
|
20913
|
-
if (
|
|
20914
|
-
const text4 =
|
|
21007
|
+
const open3 = fenceCount(pending) % 2 === 1;
|
|
21008
|
+
if (open3 && !final) return;
|
|
21009
|
+
const text4 = open3 ? pending.slice(0, pending.lastIndexOf("```")) : pending;
|
|
20915
21010
|
const cut = final ? text4.length : lastBoundary(text4);
|
|
20916
21011
|
if (cut === 0) return;
|
|
20917
21012
|
pending = final ? "" : text4.slice(cut);
|
|
@@ -21144,17 +21239,17 @@ async function createApp(opts) {
|
|
|
21144
21239
|
void musicLibrary.scan().catch(() => {
|
|
21145
21240
|
});
|
|
21146
21241
|
const memory = new Memory(db);
|
|
21147
|
-
const memoryTree = new MemoryTree(
|
|
21242
|
+
const memoryTree = new MemoryTree(join26(opts.dataDir, "memory"));
|
|
21148
21243
|
if (config.memory.enabled) {
|
|
21149
21244
|
memoryTree.ensure();
|
|
21150
21245
|
importFlatNotes(memory, memoryTree);
|
|
21151
21246
|
memoryTree.repair();
|
|
21152
21247
|
}
|
|
21153
|
-
const soul = new Soul(memoryTree,
|
|
21248
|
+
const soul = new Soul(memoryTree, join26(opts.dataDir, "soul-history"));
|
|
21154
21249
|
soul.ensure();
|
|
21155
|
-
const browserHub = new BrowserHub({ config: () => config.browser, tmpRoot:
|
|
21250
|
+
const browserHub = new BrowserHub({ config: () => config.browser, tmpRoot: join26(opts.dataDir, "browser-profiles") });
|
|
21156
21251
|
const tasks = new Tasks(db);
|
|
21157
|
-
const plugins = new Plugins(db,
|
|
21252
|
+
const plugins = new Plugins(db, join26(opts.dataDir, "plugins"));
|
|
21158
21253
|
const hub = new McpHub(new ConnectorStore(opts.dataDir));
|
|
21159
21254
|
let listenPort = config.port;
|
|
21160
21255
|
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) }) });
|
|
@@ -21266,13 +21361,13 @@ async function createApp(opts) {
|
|
|
21266
21361
|
if (id2 === "audius") return changeAudiusConfig((s) => changeAudius(s, change));
|
|
21267
21362
|
if (id2 === "browser") {
|
|
21268
21363
|
const err2 = changeBrowserConfig((b) => changeBrowser(b, change, !!browserHub.status().chrome));
|
|
21269
|
-
if (!err2 && "install" in change && listCatalog(catalogDir).some((c) => c.id === BROWSER_SKILL)) plugins.install(
|
|
21364
|
+
if (!err2 && "install" in change && listCatalog(catalogDir).some((c) => c.id === BROWSER_SKILL)) plugins.install(join26(catalogDir, BROWSER_SKILL));
|
|
21270
21365
|
if (!err2 && "remove" in change) plugins.remove(BROWSER_SKILL);
|
|
21271
21366
|
return err2;
|
|
21272
21367
|
}
|
|
21273
21368
|
if (id2 === "tavily") {
|
|
21274
21369
|
const err2 = changeTavilyConfig((t) => changeTavily(t, change, !!config.web.tavilyKey));
|
|
21275
|
-
if (!err2 && "install" in change && listCatalog(catalogDir).some((c) => c.id === TAVILY_SKILL)) plugins.install(
|
|
21370
|
+
if (!err2 && "install" in change && listCatalog(catalogDir).some((c) => c.id === TAVILY_SKILL)) plugins.install(join26(catalogDir, TAVILY_SKILL));
|
|
21276
21371
|
if (!err2 && "remove" in change) plugins.remove(TAVILY_SKILL);
|
|
21277
21372
|
return err2;
|
|
21278
21373
|
}
|
|
@@ -21303,7 +21398,7 @@ async function createApp(opts) {
|
|
|
21303
21398
|
}
|
|
21304
21399
|
if (id2 !== "zerodha") return changeChannels((c) => changeIntegration(c, id2, change));
|
|
21305
21400
|
const err = changeBrokers((b) => changeBroker(b, id2, change, (gone) => brokerHub.forget(gone)));
|
|
21306
|
-
if (!err && "install" in change && listCatalog(catalogDir).some((c) => c.id === PORTFOLIO_SKILL)) plugins.install(
|
|
21401
|
+
if (!err && "install" in change && listCatalog(catalogDir).some((c) => c.id === PORTFOLIO_SKILL)) plugins.install(join26(catalogDir, PORTFOLIO_SKILL));
|
|
21307
21402
|
if (!err && "remove" in change) plugins.remove(PORTFOLIO_SKILL);
|
|
21308
21403
|
return err;
|
|
21309
21404
|
};
|
|
@@ -21319,7 +21414,7 @@ async function createApp(opts) {
|
|
|
21319
21414
|
},
|
|
21320
21415
|
install: (id2) => {
|
|
21321
21416
|
if (!listCatalog(catalogDir).some((c) => c.id === id2)) return { ok: false, error: "That plugin is not in the catalog." };
|
|
21322
|
-
return plugins.install(
|
|
21417
|
+
return plugins.install(join26(catalogDir, id2));
|
|
21323
21418
|
}
|
|
21324
21419
|
},
|
|
21325
21420
|
integrations: {
|
|
@@ -21718,7 +21813,7 @@ First check the work: read the whole report (office.report) and, when it changed
|
|
|
21718
21813
|
const voice2 = opts.voice;
|
|
21719
21814
|
const speaker = voice2 ? new Speaker(voice2, audit, () => config.voice.ttsVoice, () => ({ hindi: config.voice.hindiVoice || void 0, marathi: config.voice.marathiVoice || void 0 })) : null;
|
|
21720
21815
|
const voiceAvailable = () => !!voice2 && voice2.available();
|
|
21721
|
-
const voiceKey = voice2 ? loadOrCreateKey(
|
|
21816
|
+
const voiceKey = voice2 ? loadOrCreateKey(join26(opts.dataDir, "voice.key")) : null;
|
|
21722
21817
|
const voiceprint = voiceKey ? new Voiceprint(db, voiceKey) : null;
|
|
21723
21818
|
const enrollment = voiceprint ? new Enrollment(voiceprint, SPEAKER_MODEL) : null;
|
|
21724
21819
|
const household = voiceKey ? new Household(db, voiceKey) : null;
|
|
@@ -21803,7 +21898,7 @@ ${task.title}`) !== null,
|
|
|
21803
21898
|
}
|
|
21804
21899
|
},
|
|
21805
21900
|
audit,
|
|
21806
|
-
statePath:
|
|
21901
|
+
statePath: join26(opts.dataDir, "proactive.json")
|
|
21807
21902
|
});
|
|
21808
21903
|
async function requirePin(pin, ip) {
|
|
21809
21904
|
let ok2 = false;
|
|
@@ -21894,7 +21989,7 @@ ${task.title}`) !== null,
|
|
|
21894
21989
|
if (!isPluginId(id2)) throw new HttpError(400, "That is not a plugin name.");
|
|
21895
21990
|
if (!listCatalog(catalogDir).some((c) => c.id === id2)) throw new HttpError(404, "That plugin is not in the catalog.");
|
|
21896
21991
|
await requirePin(pin, ip);
|
|
21897
|
-
const r = plugins.install(
|
|
21992
|
+
const r = plugins.install(join26(catalogDir, id2));
|
|
21898
21993
|
if (!r.ok) throw new HttpError(400, `That plugin cannot be installed: ${r.error}`);
|
|
21899
21994
|
audit.log("owner", "plugin.installed", { id: r.id, upgraded: r.upgraded, ip });
|
|
21900
21995
|
return { id: r.id, upgraded: r.upgraded };
|
|
@@ -22704,7 +22799,7 @@ ${url}`);
|
|
|
22704
22799
|
}
|
|
22705
22800
|
const prune = () => {
|
|
22706
22801
|
try {
|
|
22707
|
-
const r = pruneAudit(db, { keepDays: config.audit.keepDays, archive: config.audit.archive, dir:
|
|
22802
|
+
const r = pruneAudit(db, { keepDays: config.audit.keepDays, archive: config.audit.archive, dir: join26(opts.dataDir, "audit-archive"), now: Date.now() });
|
|
22708
22803
|
if (r.removed) audit.log("system", "audit.pruned", { removed: r.removed, archive: r.archivePath });
|
|
22709
22804
|
} catch (e) {
|
|
22710
22805
|
audit.log("system", "audit.prune_failed", { message: e.message.slice(0, 200) });
|
|
@@ -22714,7 +22809,7 @@ ${url}`);
|
|
|
22714
22809
|
pruneTimer = setInterval(prune, 24 * 36e5);
|
|
22715
22810
|
pruneTimer.unref?.();
|
|
22716
22811
|
let lastSealAttempt = null;
|
|
22717
|
-
const
|
|
22812
|
+
const seal2 = async () => {
|
|
22718
22813
|
try {
|
|
22719
22814
|
const lastSeal = new AuditQuery(db).lastSeal({ sent: true });
|
|
22720
22815
|
if (!sealDue(/* @__PURE__ */ new Date(), config.audit.sealAt, typeof lastSeal?.detail.date === "string" ? lastSeal.detail.date : null, lastSealAttempt)) return;
|
|
@@ -22723,7 +22818,7 @@ ${url}`);
|
|
|
22723
22818
|
} catch {
|
|
22724
22819
|
}
|
|
22725
22820
|
};
|
|
22726
|
-
sealTimer = setInterval(() => void
|
|
22821
|
+
sealTimer = setInterval(() => void seal2(), 6e4);
|
|
22727
22822
|
sealTimer.unref?.();
|
|
22728
22823
|
heartbeat.start();
|
|
22729
22824
|
proactive.start();
|
|
@@ -23210,8 +23305,8 @@ import { resolve as resolve9 } from "node:path";
|
|
|
23210
23305
|
import { WebSocket as WebSocket4 } from "ws";
|
|
23211
23306
|
|
|
23212
23307
|
// ../agent-cli/src/tools/fs.ts
|
|
23213
|
-
import { closeSync, mkdirSync as
|
|
23214
|
-
import { dirname as dirname9, join as
|
|
23308
|
+
import { closeSync, mkdirSync as mkdirSync19, openSync, readSync, readdirSync as readdirSync8, statSync as statSync7, writeFileSync as writeFileSync20 } from "node:fs";
|
|
23309
|
+
import { dirname as dirname9, join as join27 } from "node:path";
|
|
23215
23310
|
|
|
23216
23311
|
// ../agent-cli/src/tools/roots.ts
|
|
23217
23312
|
import { lstatSync as lstatSync3, realpathSync } from "node:fs";
|
|
@@ -23273,7 +23368,7 @@ function fsList(args, ctx) {
|
|
|
23273
23368
|
if (e.isDirectory()) return `[dir] ${e.name}`;
|
|
23274
23369
|
let size = 0;
|
|
23275
23370
|
try {
|
|
23276
|
-
size = statSync7(
|
|
23371
|
+
size = statSync7(join27(g.abs, e.name)).size;
|
|
23277
23372
|
} catch {
|
|
23278
23373
|
}
|
|
23279
23374
|
return `[file] ${e.name} (${size} bytes)`;
|
|
@@ -23314,8 +23409,8 @@ function fsWrite(args, ctx) {
|
|
|
23314
23409
|
if ("error" in g) return { ok: false, error: g.error };
|
|
23315
23410
|
if (Buffer.byteLength(args.content) > MAX_WRITE) return { ok: false, error: "Content too large (5 MB limit)" };
|
|
23316
23411
|
try {
|
|
23317
|
-
|
|
23318
|
-
|
|
23412
|
+
mkdirSync19(dirname9(g.abs), { recursive: true });
|
|
23413
|
+
writeFileSync20(g.abs, args.content);
|
|
23319
23414
|
return { ok: true, output: `Wrote ${Buffer.byteLength(args.content)} bytes to ${g.abs}`, truncated: false };
|
|
23320
23415
|
} catch (e) {
|
|
23321
23416
|
return { ok: false, error: e.message };
|
|
@@ -23550,9 +23645,9 @@ function startDeviceNode(opts) {
|
|
|
23550
23645
|
}
|
|
23551
23646
|
|
|
23552
23647
|
// ../agent-cli/src/commands/start.ts
|
|
23553
|
-
import { randomBytes as
|
|
23554
|
-
import { existsSync as
|
|
23555
|
-
import { dirname as dirname11, join as
|
|
23648
|
+
import { randomBytes as randomBytes14 } from "node:crypto";
|
|
23649
|
+
import { existsSync as existsSync26, readFileSync as readFileSync19, writeFileSync as writeFileSync22 } from "node:fs";
|
|
23650
|
+
import { dirname as dirname11, join as join29, resolve as resolve8 } from "node:path";
|
|
23556
23651
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
23557
23652
|
|
|
23558
23653
|
// ../agent-cli/src/commands/lan.ts
|
|
@@ -23658,23 +23753,23 @@ async function lanCommand(args, io2, ifaces = networkInterfaces2) {
|
|
|
23658
23753
|
|
|
23659
23754
|
// ../agent-cli/src/commands/voice.ts
|
|
23660
23755
|
import { spawn as spawn12 } from "node:child_process";
|
|
23661
|
-
import { existsSync as
|
|
23662
|
-
import { dirname as dirname10, join as
|
|
23756
|
+
import { existsSync as existsSync25, mkdirSync as mkdirSync20, readFileSync as readFileSync18, writeFileSync as writeFileSync21 } from "node:fs";
|
|
23757
|
+
import { dirname as dirname10, join as join28, resolve as resolve7 } from "node:path";
|
|
23663
23758
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
23664
23759
|
function voicePaths(dataDir) {
|
|
23665
|
-
const home =
|
|
23666
|
-
const venv =
|
|
23760
|
+
const home = join28(dataDir, "voice");
|
|
23761
|
+
const venv = join28(home, "venv");
|
|
23667
23762
|
return {
|
|
23668
23763
|
home,
|
|
23669
23764
|
venv,
|
|
23670
|
-
python: process.platform === "win32" ?
|
|
23671
|
-
models:
|
|
23672
|
-
marker:
|
|
23765
|
+
python: process.platform === "win32" ? join28(venv, "Scripts", "python.exe") : join28(venv, "bin", "python"),
|
|
23766
|
+
models: join28(home, "models"),
|
|
23767
|
+
marker: join28(home, "installed.json")
|
|
23673
23768
|
};
|
|
23674
23769
|
}
|
|
23675
23770
|
function readMarker(dataDir) {
|
|
23676
23771
|
try {
|
|
23677
|
-
return JSON.parse(
|
|
23772
|
+
return JSON.parse(readFileSync18(voicePaths(dataDir).marker, "utf8"));
|
|
23678
23773
|
} catch {
|
|
23679
23774
|
return null;
|
|
23680
23775
|
}
|
|
@@ -23771,8 +23866,8 @@ async function voiceSetupCommand(io2, deps = {}, args = []) {
|
|
|
23771
23866
|
io2.err("Python 3.10 or newer is required. Install it from https://www.python.org/downloads/ and run this again.");
|
|
23772
23867
|
return 1;
|
|
23773
23868
|
}
|
|
23774
|
-
|
|
23775
|
-
if (!
|
|
23869
|
+
mkdirSync20(p.home, { recursive: true });
|
|
23870
|
+
if (!existsSync25(p.python)) {
|
|
23776
23871
|
io2.out("1/3 Creating a private Python environment\u2026");
|
|
23777
23872
|
const r = await run2(py.cmd, [...py.args, "-m", "venv", p.venv], { onLine });
|
|
23778
23873
|
if (r.code !== 0) {
|
|
@@ -23806,7 +23901,7 @@ ${tail(dl.stdout)}`);
|
|
|
23806
23901
|
return 1;
|
|
23807
23902
|
}
|
|
23808
23903
|
const marker = { python: p.python, sttModel: cfg.voice.sttModel, ttsVoice: cfg.voice.ttsVoice, at: Date.now() };
|
|
23809
|
-
|
|
23904
|
+
writeFileSync21(p.marker, JSON.stringify(marker, null, 2));
|
|
23810
23905
|
io2.out("Voice is ready. Start Friend with `friend start`, then hold Space to talk.");
|
|
23811
23906
|
return 0;
|
|
23812
23907
|
}
|
|
@@ -23822,7 +23917,7 @@ async function voiceStatusCommand(io2) {
|
|
|
23822
23917
|
io2.out("Voice engine: not installed. Run: friend voice setup");
|
|
23823
23918
|
return 0;
|
|
23824
23919
|
}
|
|
23825
|
-
if (!
|
|
23920
|
+
if (!existsSync25(marker.python)) {
|
|
23826
23921
|
io2.out("Voice engine: installed, but its Python is missing. Run: friend voice setup");
|
|
23827
23922
|
return 0;
|
|
23828
23923
|
}
|
|
@@ -23895,12 +23990,12 @@ async function voiceCommand(args, io2) {
|
|
|
23895
23990
|
function findWebDir(explicit) {
|
|
23896
23991
|
const here2 = dirname11(fileURLToPath4(import.meta.url));
|
|
23897
23992
|
const candidates = [explicit, process.env.FRIEND_WEB_DIR, resolve8(here2, "../../../web/dist"), resolve8(here2, "web")];
|
|
23898
|
-
return candidates.find((c) => !!c &&
|
|
23993
|
+
return candidates.find((c) => !!c && existsSync26(join29(c, "index.html")));
|
|
23899
23994
|
}
|
|
23900
23995
|
async function startFriend(opts) {
|
|
23901
23996
|
const stored = loadConfig(opts.dataDir);
|
|
23902
23997
|
const marker = stored.voice.enabled ? readMarker(opts.dataDir) : null;
|
|
23903
|
-
const secret =
|
|
23998
|
+
const secret = randomBytes14(24).toString("hex");
|
|
23904
23999
|
const sidecar = marker ? new SidecarProcess({
|
|
23905
24000
|
command: marker.python,
|
|
23906
24001
|
args: [
|
|
@@ -23931,17 +24026,17 @@ async function startFriend(opts) {
|
|
|
23931
24026
|
}
|
|
23932
24027
|
});
|
|
23933
24028
|
const { port } = await app.start();
|
|
23934
|
-
const tokenFile =
|
|
23935
|
-
let token =
|
|
24029
|
+
const tokenFile = join29(opts.dataDir, "local-device.token");
|
|
24030
|
+
let token = existsSync26(tokenFile) ? readFileSync19(tokenFile, "utf8").trim() : "";
|
|
23936
24031
|
if (!token || !app.auth.resolveDevice(token)) {
|
|
23937
24032
|
token = app.auth.redeemPairCode(app.auth.createPairCode(), "this-pc");
|
|
23938
|
-
|
|
24033
|
+
writeFileSync22(tokenFile, token, { mode: 384 });
|
|
23939
24034
|
}
|
|
23940
24035
|
const node = startDeviceNode({
|
|
23941
24036
|
url: `${app.config.https ? "wss" : "ws"}://127.0.0.1:${port}/device`,
|
|
23942
24037
|
token,
|
|
23943
24038
|
roots: app.config.roots,
|
|
23944
|
-
...app.config.https ? { ca:
|
|
24039
|
+
...app.config.https ? { ca: readFileSync19(join29(opts.dataDir, "tls", "cert.pem"), "utf8") } : {}
|
|
23945
24040
|
// this PC trusts only its own Friend's certificate
|
|
23946
24041
|
});
|
|
23947
24042
|
const urls = urlsFor(app.config.bind, port, void 0, app.config.https);
|
|
@@ -24111,8 +24206,8 @@ async function devicesCommand(args, io2) {
|
|
|
24111
24206
|
}
|
|
24112
24207
|
|
|
24113
24208
|
// ../agent-cli/src/commands/memory.ts
|
|
24114
|
-
import { existsSync as
|
|
24115
|
-
import { join as
|
|
24209
|
+
import { existsSync as existsSync27 } from "node:fs";
|
|
24210
|
+
import { join as join30 } from "node:path";
|
|
24116
24211
|
var USAGE = "Usage: friend memory list | friend memory show <path> | friend memory forget <path or number> | friend memory clear";
|
|
24117
24212
|
async function memoryCommand(args, io2) {
|
|
24118
24213
|
const [sub, arg] = args;
|
|
@@ -24124,7 +24219,7 @@ async function memoryCommand(args, io2) {
|
|
|
24124
24219
|
try {
|
|
24125
24220
|
const memory = new Memory(db);
|
|
24126
24221
|
const audit = new Audit(db);
|
|
24127
|
-
const tree2 =
|
|
24222
|
+
const tree2 = existsSync27(join30(io2.dataDir, "memory", "INDEX.md")) ? new MemoryTree(join30(io2.dataDir, "memory")) : null;
|
|
24128
24223
|
if (sub === "show") {
|
|
24129
24224
|
if (!tree2 || !arg) {
|
|
24130
24225
|
io2.err(tree2 ? USAGE : "There is no memory tree yet.");
|
|
@@ -24203,8 +24298,8 @@ async function memoryCommand(args, io2) {
|
|
|
24203
24298
|
}
|
|
24204
24299
|
|
|
24205
24300
|
// ../agent-cli/src/commands/plugin.ts
|
|
24206
|
-
import { existsSync as
|
|
24207
|
-
import { dirname as dirname12, join as
|
|
24301
|
+
import { existsSync as existsSync28, readdirSync as readdirSync9, statSync as statSync8 } from "node:fs";
|
|
24302
|
+
import { dirname as dirname12, join as join31, resolve as resolve10 } from "node:path";
|
|
24208
24303
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
24209
24304
|
var USAGE2 = "Usage: friend plugin catalog | list | install <name|folder> [--yes] | enable <id> | disable <id> | remove <id>";
|
|
24210
24305
|
function defaultCatalog() {
|
|
@@ -24218,10 +24313,10 @@ async function pluginCommand(args, io2, deps = {}) {
|
|
|
24218
24313
|
const flags = rest.filter((a) => a.startsWith("--"));
|
|
24219
24314
|
const arg = rest.find((a) => !a.startsWith("--"));
|
|
24220
24315
|
if (sub === "catalog") {
|
|
24221
|
-
const dirs =
|
|
24316
|
+
const dirs = existsSync28(catalogDir) ? readdirSync9(catalogDir).filter((d) => statSync8(join31(catalogDir, d)).isDirectory()) : [];
|
|
24222
24317
|
if (dirs.length === 0) io2.out("The catalog is empty.");
|
|
24223
24318
|
for (const d of dirs.sort()) {
|
|
24224
|
-
const r = inspectPlugin(
|
|
24319
|
+
const r = inspectPlugin(join31(catalogDir, d));
|
|
24225
24320
|
if (!r.ok) {
|
|
24226
24321
|
io2.out(`${d} (invalid: ${r.error})`);
|
|
24227
24322
|
continue;
|
|
@@ -24237,7 +24332,7 @@ async function pluginCommand(args, io2, deps = {}) {
|
|
|
24237
24332
|
}
|
|
24238
24333
|
const db = openDb(io2.dataDir);
|
|
24239
24334
|
try {
|
|
24240
|
-
const plugins = new Plugins(db,
|
|
24335
|
+
const plugins = new Plugins(db, join31(io2.dataDir, "plugins"));
|
|
24241
24336
|
if (sub === "list") {
|
|
24242
24337
|
const all = plugins.list();
|
|
24243
24338
|
if (all.length === 0) io2.out("No plugins installed. See: friend plugin catalog");
|
|
@@ -24251,8 +24346,8 @@ async function pluginCommand(args, io2, deps = {}) {
|
|
|
24251
24346
|
io2.err(USAGE2);
|
|
24252
24347
|
return 1;
|
|
24253
24348
|
}
|
|
24254
|
-
const inCatalog = !/[\\/]/.test(arg) &&
|
|
24255
|
-
const source = inCatalog ?
|
|
24349
|
+
const inCatalog = !/[\\/]/.test(arg) && existsSync28(join31(catalogDir, arg));
|
|
24350
|
+
const source = inCatalog ? join31(catalogDir, arg) : existsSync28(resolve10(arg)) ? resolve10(arg) : null;
|
|
24256
24351
|
if (!source) {
|
|
24257
24352
|
io2.err(`"${arg}" is not in the catalog and there is no such folder. See: friend plugin catalog`);
|
|
24258
24353
|
return 1;
|
|
@@ -24307,7 +24402,7 @@ async function pluginCommand(args, io2, deps = {}) {
|
|
|
24307
24402
|
|
|
24308
24403
|
// ../agent-cli/src/commands/onboard/index.ts
|
|
24309
24404
|
import crossSpawn4 from "cross-spawn";
|
|
24310
|
-
import { mkdirSync as
|
|
24405
|
+
import { mkdirSync as mkdirSync22 } from "node:fs";
|
|
24311
24406
|
import { resolve as resolve11 } from "node:path";
|
|
24312
24407
|
|
|
24313
24408
|
// ../agent-cli/src/commands/ollama.ts
|
|
@@ -24630,16 +24725,16 @@ function installPlan(id2, platform, have) {
|
|
|
24630
24725
|
}
|
|
24631
24726
|
|
|
24632
24727
|
// ../agent-cli/src/commands/onboard/state.ts
|
|
24633
|
-
import { existsSync as
|
|
24634
|
-
import { dirname as dirname13, join as
|
|
24728
|
+
import { existsSync as existsSync29, mkdirSync as mkdirSync21, readFileSync as readFileSync20, renameSync as renameSync5, rmSync as rmSync13, writeFileSync as writeFileSync23 } from "node:fs";
|
|
24729
|
+
import { dirname as dirname13, join as join32 } from "node:path";
|
|
24635
24730
|
var FEATURES = ["claude-code", "claude-api", "ollama", "voice", "sandbox"];
|
|
24636
24731
|
var emptyState = () => ({ version: 1, done: {}, features: [], restart: [] });
|
|
24637
|
-
var statePath = (dataDir) =>
|
|
24732
|
+
var statePath = (dataDir) => join32(dataDir, "onboarding.json");
|
|
24638
24733
|
function loadState(dataDir) {
|
|
24639
24734
|
const f = statePath(dataDir);
|
|
24640
|
-
if (!
|
|
24735
|
+
if (!existsSync29(f)) return emptyState();
|
|
24641
24736
|
try {
|
|
24642
|
-
const raw = JSON.parse(
|
|
24737
|
+
const raw = JSON.parse(readFileSync20(f, "utf8"));
|
|
24643
24738
|
const done = raw.done && typeof raw.done === "object" ? Object.fromEntries(Object.entries(raw.done).filter(([, v]) => typeof v === "string")) : {};
|
|
24644
24739
|
const features2 = Array.isArray(raw.features) ? raw.features.filter((x) => FEATURES.includes(x)) : [];
|
|
24645
24740
|
const restart = Array.isArray(raw.restart) ? raw.restart.filter((x) => typeof x === "string") : [];
|
|
@@ -24650,9 +24745,9 @@ function loadState(dataDir) {
|
|
|
24650
24745
|
}
|
|
24651
24746
|
function saveState(dataDir, state) {
|
|
24652
24747
|
const f = statePath(dataDir);
|
|
24653
|
-
|
|
24748
|
+
mkdirSync21(dirname13(f), { recursive: true });
|
|
24654
24749
|
const tmp = `${f}.tmp`;
|
|
24655
|
-
|
|
24750
|
+
writeFileSync23(tmp, JSON.stringify(state, null, 2));
|
|
24656
24751
|
renameSync5(tmp, f);
|
|
24657
24752
|
}
|
|
24658
24753
|
function resetState(dataDir) {
|
|
@@ -25008,7 +25103,7 @@ async function workspace(c) {
|
|
|
25008
25103
|
const answer = await text3(c.ui, current ? "Workspace folder" : "Workspace folder (Enter to skip)", current ?? "");
|
|
25009
25104
|
if (answer) {
|
|
25010
25105
|
const abs = resolve11(answer);
|
|
25011
|
-
|
|
25106
|
+
mkdirSync22(abs, { recursive: true });
|
|
25012
25107
|
cfg.roots = [abs];
|
|
25013
25108
|
saveConfig(cfg);
|
|
25014
25109
|
io2.out(`Workspace: ${abs}`);
|
|
@@ -25262,8 +25357,8 @@ async function usageCommand(args, io2, log) {
|
|
|
25262
25357
|
}
|
|
25263
25358
|
|
|
25264
25359
|
// ../agent-cli/src/commands/audit.ts
|
|
25265
|
-
import { writeFileSync as
|
|
25266
|
-
import { join as
|
|
25360
|
+
import { writeFileSync as writeFileSync24 } from "node:fs";
|
|
25361
|
+
import { join as join33 } from "node:path";
|
|
25267
25362
|
var USAGE5 = [
|
|
25268
25363
|
"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]",
|
|
25269
25364
|
" friend audit show <request-id>",
|
|
@@ -25368,7 +25463,7 @@ async function auditCommand(args, io2, deps = {}) {
|
|
|
25368
25463
|
afterwards = async (res2) => {
|
|
25369
25464
|
const raw = /filename="([^"]+)"/.exec(res2.headers.get("content-disposition") ?? "")?.[1] ?? `friend-audit.${f.query.format}`;
|
|
25370
25465
|
const name = (raw.split(/[\\/]/).pop() ?? "friend-audit").replace(/[^A-Za-z0-9._-]/g, "_") || "friend-audit";
|
|
25371
|
-
(deps.write ?? ((n2, b) =>
|
|
25466
|
+
(deps.write ?? ((n2, b) => writeFileSync24(join33(process.cwd(), n2), b)))(name, await res2.text());
|
|
25372
25467
|
io2.out(`Saved ${name} in this folder. It contains private content: keep it safe.`);
|
|
25373
25468
|
return 0;
|
|
25374
25469
|
};
|
|
@@ -25396,9 +25491,9 @@ async function auditCommand(args, io2, deps = {}) {
|
|
|
25396
25491
|
|
|
25397
25492
|
// ../agent-cli/src/commands/daemon.ts
|
|
25398
25493
|
import { spawn as spawn13, spawnSync as spawnSync3 } from "node:child_process";
|
|
25399
|
-
import { closeSync as closeSync2, existsSync as
|
|
25494
|
+
import { closeSync as closeSync2, existsSync as existsSync30, mkdirSync as mkdirSync23, openSync as openSync2, readFileSync as readFileSync21, renameSync as renameSync6, rmSync as rmSync14, statSync as statSync9, writeFileSync as writeFileSync25 } from "node:fs";
|
|
25400
25495
|
import { connect } from "node:net";
|
|
25401
|
-
import { join as
|
|
25496
|
+
import { join as join34 } from "node:path";
|
|
25402
25497
|
var USAGE6 = "Usage: friend daemon start | stop | restart | status";
|
|
25403
25498
|
var MAX_LOG_BYTES = 5 * 1024 * 1024;
|
|
25404
25499
|
var sleep2 = (ms2) => new Promise((r) => setTimeout(r, ms2));
|
|
@@ -25454,11 +25549,11 @@ var realDeps = {
|
|
|
25454
25549
|
},
|
|
25455
25550
|
now: Date.now
|
|
25456
25551
|
};
|
|
25457
|
-
var pidFile = (dataDir) =>
|
|
25458
|
-
var logFileOf = (dataDir) =>
|
|
25552
|
+
var pidFile = (dataDir) => join34(dataDir, "friend.pid");
|
|
25553
|
+
var logFileOf = (dataDir) => join34(dataDir, "friend.log");
|
|
25459
25554
|
function readPid(dataDir) {
|
|
25460
25555
|
try {
|
|
25461
|
-
const r = JSON.parse(
|
|
25556
|
+
const r = JSON.parse(readFileSync21(pidFile(dataDir), "utf8"));
|
|
25462
25557
|
return Number.isInteger(r.pid) && r.pid > 0 ? r : null;
|
|
25463
25558
|
} catch {
|
|
25464
25559
|
return null;
|
|
@@ -25489,10 +25584,10 @@ async function start(io2, deps) {
|
|
|
25489
25584
|
io2.err(`Port ${cfg.port} is already in use. Friend may be running in a terminal (stop it with Ctrl+C), or another program uses that port (friend lan port N).`);
|
|
25490
25585
|
return 1;
|
|
25491
25586
|
}
|
|
25492
|
-
|
|
25587
|
+
mkdirSync23(io2.dataDir, { recursive: true });
|
|
25493
25588
|
const log = logFileOf(io2.dataDir);
|
|
25494
25589
|
try {
|
|
25495
|
-
if (
|
|
25590
|
+
if (existsSync30(log) && statSync9(log).size > MAX_LOG_BYTES) renameSync6(log, `${log}.old`);
|
|
25496
25591
|
} catch {
|
|
25497
25592
|
}
|
|
25498
25593
|
const pid = deps.launch(log);
|
|
@@ -25500,7 +25595,7 @@ async function start(io2, deps) {
|
|
|
25500
25595
|
io2.err("Could not start Friend in the background.");
|
|
25501
25596
|
return 1;
|
|
25502
25597
|
}
|
|
25503
|
-
|
|
25598
|
+
writeFileSync25(pidFile(io2.dataDir), JSON.stringify({ pid, startedAt: deps.now() }));
|
|
25504
25599
|
for (let i = 0; i < 60; i++) {
|
|
25505
25600
|
if (await deps.portOpen(cfg.port, 300)) {
|
|
25506
25601
|
io2.out(`Friend is running in the background (pid ${pid}) at ${urls.local}`);
|
|
@@ -25566,10 +25661,10 @@ async function daemonCommand(args, io2, deps = realDeps) {
|
|
|
25566
25661
|
// ../agent-cli/src/commands/upgrade.ts
|
|
25567
25662
|
import crossSpawn5 from "cross-spawn";
|
|
25568
25663
|
import { appendFileSync } from "node:fs";
|
|
25569
|
-
import { join as
|
|
25664
|
+
import { join as join35 } from "node:path";
|
|
25570
25665
|
var PACKAGE2 = "friend-assistant";
|
|
25571
25666
|
var real2 = {
|
|
25572
|
-
current: () => true ? "0.1.
|
|
25667
|
+
current: () => true ? "0.1.72" : "development",
|
|
25573
25668
|
latest: () => new Promise((resolve13) => {
|
|
25574
25669
|
const child = crossSpawn5("npm", ["view", PACKAGE2, "version", "--prefer-online"], { stdio: ["ignore", "pipe", "ignore"] });
|
|
25575
25670
|
let out = "";
|
|
@@ -25607,7 +25702,7 @@ async function upgradeCommand(args, io0, deps = real2) {
|
|
|
25607
25702
|
io0.err("Usage: friend upgrade [--force] [--auto]");
|
|
25608
25703
|
return 1;
|
|
25609
25704
|
}
|
|
25610
|
-
const log = deps.log ?? ((line2) => appendFileSync(
|
|
25705
|
+
const log = deps.log ?? ((line2) => appendFileSync(join35(io0.dataDir, "update.log"), `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
25611
25706
|
`));
|
|
25612
25707
|
const io2 = auto ? {
|
|
25613
25708
|
...io0,
|
|
@@ -25725,7 +25820,7 @@ async function claudeCommand(args, io2, deps = {}) {
|
|
|
25725
25820
|
}
|
|
25726
25821
|
|
|
25727
25822
|
// ../agent-cli/src/commands/setup.ts
|
|
25728
|
-
import { mkdirSync as
|
|
25823
|
+
import { mkdirSync as mkdirSync24 } from "node:fs";
|
|
25729
25824
|
import { resolve as resolve12 } from "node:path";
|
|
25730
25825
|
async function setupCommand3(io2) {
|
|
25731
25826
|
const db = openDb(io2.dataDir);
|
|
@@ -25751,7 +25846,7 @@ async function setupCommand3(io2) {
|
|
|
25751
25846
|
const cfg = loadConfig(io2.dataDir);
|
|
25752
25847
|
if (workspace2) {
|
|
25753
25848
|
const abs = resolve12(workspace2);
|
|
25754
|
-
|
|
25849
|
+
mkdirSync24(abs, { recursive: true });
|
|
25755
25850
|
cfg.roots = [abs];
|
|
25756
25851
|
}
|
|
25757
25852
|
if (apiKey) cfg.apiKey = apiKey;
|
|
@@ -25887,7 +25982,7 @@ async function run(argv, io2) {
|
|
|
25887
25982
|
case "version":
|
|
25888
25983
|
case "--version":
|
|
25889
25984
|
case "-v":
|
|
25890
|
-
io2.out(true ? "0.1.
|
|
25985
|
+
io2.out(true ? "0.1.72" : "development");
|
|
25891
25986
|
return 0;
|
|
25892
25987
|
case "lan":
|
|
25893
25988
|
return await lanCommand(rest, io2);
|