@phren/cli 0.3.0 → 0.3.1
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/dist/bridge/agent-hooks.d.ts +15 -6
- package/dist/bridge/agent-hooks.js +55 -24
- package/dist/bridge/claude-question-dialog.d.ts +65 -0
- package/dist/bridge/claude-question-dialog.js +210 -0
- package/dist/bridge/command.js +92 -2
- package/dist/bridge/computers.d.ts +5 -0
- package/dist/bridge/computers.js +10 -4
- package/dist/bridge/conductor-group.d.ts +23 -0
- package/dist/bridge/conductor-group.js +25 -0
- package/dist/bridge/hand-off.js +5 -1
- package/dist/bridge/herdr.d.ts +7 -0
- package/dist/bridge/herdr.js +53 -2
- package/dist/bridge/link.d.ts +48 -0
- package/dist/bridge/link.js +136 -0
- package/dist/bridge/memory-store.d.ts +23 -0
- package/dist/bridge/memory-store.js +152 -0
- package/dist/bridge/pair.d.ts +46 -0
- package/dist/bridge/pair.js +240 -0
- package/dist/bridge/peers.d.ts +9 -0
- package/dist/bridge/peers.js +25 -2
- package/dist/bridge/server-launch.d.ts +9 -0
- package/dist/bridge/server-launch.js +34 -11
- package/dist/bridge/server-pane-routes.js +38 -7
- package/dist/bridge/server-routes.d.ts +1 -0
- package/dist/bridge/server-routes.js +11 -3
- package/dist/bridge/server-stream.js +4 -1
- package/dist/bridge/speech-key.d.ts +33 -0
- package/dist/bridge/speech-key.js +106 -0
- package/dist/bridge/speech-transcribe.js +1 -1
- package/dist/bridge/speech.d.ts +1 -3
- package/dist/bridge/speech.js +2 -16
- package/dist/bridge-hook.mjs +1198 -492
- package/dist/cli-handlers.js +6 -0
- package/dist/cli-registry.js +14 -2
- package/dist/content/learning.js +1 -1
- package/dist/data/tasks.d.ts +26 -0
- package/dist/data/tasks.js +72 -1
- package/dist/entrypoint.js +7 -0
- package/dist/governance/rbac.d.ts +1 -1
- package/dist/governance/rbac.js +1 -0
- package/dist/init/init-walkthrough.d.ts +10 -0
- package/dist/init/init-walkthrough.js +24 -1
- package/dist/init/init.d.ts +5 -0
- package/dist/init/init.js +54 -32
- package/dist/link/doctor.js +10 -0
- package/dist/mcp/profile.js +2 -1
- package/dist/modules/config.d.ts +7 -0
- package/dist/modules/config.js +17 -0
- package/dist/modules/registry.js +5 -4
- package/dist/sync/task-claim.d.ts +22 -0
- package/dist/sync/task-claim.js +45 -0
- package/dist/tools/dispatch.js +2 -2
- package/dist/tools/tasks.js +40 -1
- package/package.json +2 -1
- package/starter/global/skills/conductor/SKILL.md +41 -9
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { mkdir, readFile, stat } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { homeDir } from "../home-paths.js";
|
|
4
|
+
import { atomic, bridgeRoot } from "./protocol.js";
|
|
5
|
+
/** The ElevenLabs key for spoken replies and Scribe dictation. It is machine
|
|
6
|
+
* config, like apns.json: it lives in the Hook's own directory, mode 600, and
|
|
7
|
+
* never in the synced store. ELEVENLABS_API_KEY, ElevenLabs' own convention
|
|
8
|
+
* that its SDKs and MCP server read, wins when set. The Hook runs as a service
|
|
9
|
+
* that doesn't see shell env, so the file is the durable source. */
|
|
10
|
+
export const SPEECH_KEY_ENV = "ELEVENLABS_API_KEY";
|
|
11
|
+
export function speechKeyFile() {
|
|
12
|
+
return path.join(bridgeRoot(), "elevenlabs.json");
|
|
13
|
+
}
|
|
14
|
+
/** Where the key lived before phren kept its own: the mina trailer config. It
|
|
15
|
+
* is read once to migrate and never written or deleted. */
|
|
16
|
+
export function legacySpeechKeyFile(env = process.env) {
|
|
17
|
+
return path.join(homeDir(env), ".config", "mina-trailer.json");
|
|
18
|
+
}
|
|
19
|
+
function clean(value) {
|
|
20
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
21
|
+
}
|
|
22
|
+
/** The stored key. A file other users can read is refused, as apns.json is. */
|
|
23
|
+
async function readStored(file) {
|
|
24
|
+
let info;
|
|
25
|
+
try {
|
|
26
|
+
info = await stat(file);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return { state: "missing" };
|
|
30
|
+
}
|
|
31
|
+
if (!info.isFile())
|
|
32
|
+
return { state: "invalid" };
|
|
33
|
+
if (process.platform !== "win32" && ((info.mode & 0o077) !== 0 || (process.getuid && info.uid !== process.getuid())))
|
|
34
|
+
return { state: "unsafe" };
|
|
35
|
+
try {
|
|
36
|
+
const key = clean(JSON.parse(await readFile(file, "utf8")).apiKey);
|
|
37
|
+
return key ? { state: "ok", key } : { state: "invalid" };
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return { state: "invalid" };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function readLegacy(file) {
|
|
44
|
+
try {
|
|
45
|
+
return clean(JSON.parse(await readFile(file, "utf8")).elevenlabs_api_key);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export async function writeSpeechKey(key, file = speechKeyFile()) {
|
|
52
|
+
const value = clean(key);
|
|
53
|
+
if (!value)
|
|
54
|
+
throw new Error("The ElevenLabs key is empty.");
|
|
55
|
+
await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
56
|
+
await atomic(file, JSON.stringify({ apiKey: value }) + "\n", 0o600);
|
|
57
|
+
}
|
|
58
|
+
/** ELEVENLABS_API_KEY, else the stored key. When nothing is stored yet and the
|
|
59
|
+
* mina trailer config has a key, it is copied here once and read from here
|
|
60
|
+
* after. */
|
|
61
|
+
export async function resolveSpeechKey(paths = {}) {
|
|
62
|
+
const env = paths.env ?? process.env;
|
|
63
|
+
const fromEnv = clean(env[SPEECH_KEY_ENV]);
|
|
64
|
+
if (fromEnv)
|
|
65
|
+
return { key: fromEnv, source: "environment" };
|
|
66
|
+
const file = paths.file ?? speechKeyFile();
|
|
67
|
+
const stored = await readStored(file);
|
|
68
|
+
if (stored.state === "ok")
|
|
69
|
+
return { key: stored.key, source: "file" };
|
|
70
|
+
if (stored.state !== "missing")
|
|
71
|
+
return undefined;
|
|
72
|
+
const legacy = await readLegacy(paths.legacy ?? legacySpeechKeyFile(env));
|
|
73
|
+
if (!legacy)
|
|
74
|
+
return undefined;
|
|
75
|
+
try {
|
|
76
|
+
await writeSpeechKey(legacy, file);
|
|
77
|
+
}
|
|
78
|
+
catch { /* use it this once; the next call tries again */ }
|
|
79
|
+
return { key: legacy, source: "file" };
|
|
80
|
+
}
|
|
81
|
+
export async function readSpeechKey() {
|
|
82
|
+
return (await resolveSpeechKey())?.key;
|
|
83
|
+
}
|
|
84
|
+
/** Whether this computer has a key, for doctor. Never the key itself, and it
|
|
85
|
+
* doesn't migrate: a read-only check. */
|
|
86
|
+
export async function speechKeyStatus(paths = {}) {
|
|
87
|
+
const env = paths.env ?? process.env;
|
|
88
|
+
const file = paths.file ?? speechKeyFile();
|
|
89
|
+
const stored = await readStored(file);
|
|
90
|
+
const setup = "run `phren bridge speech-key set` and paste the key";
|
|
91
|
+
if (clean(env[SPEECH_KEY_ENV])) {
|
|
92
|
+
return stored.state === "ok"
|
|
93
|
+
? { configured: true, detail: `${SPEECH_KEY_ENV} is set and a key is stored in ${file}` }
|
|
94
|
+
: { configured: true, detail: `${SPEECH_KEY_ENV} is set in this shell; the Hook service doesn't see shell env, so ${setup} to store it` };
|
|
95
|
+
}
|
|
96
|
+
switch (stored.state) {
|
|
97
|
+
case "ok": return { configured: true, detail: `stored in ${file}` };
|
|
98
|
+
case "unsafe": return { configured: false, problem: true, detail: `${file} is readable by other users; run chmod 600 on it` };
|
|
99
|
+
case "invalid": return { configured: false, problem: true, detail: `${file} has no apiKey; ${setup}` };
|
|
100
|
+
}
|
|
101
|
+
const legacy = paths.legacy ?? legacySpeechKeyFile(env);
|
|
102
|
+
if (await readLegacy(legacy)) {
|
|
103
|
+
return { configured: true, detail: `not stored yet; the Hook copies it from ${legacy} on first use` };
|
|
104
|
+
}
|
|
105
|
+
return { configured: false, detail: `no ElevenLabs key, so spoken replies and Scribe dictation are off; ${setup}` };
|
|
106
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebSocket } from "ws";
|
|
2
|
-
import { readSpeechKey } from "./speech.js";
|
|
2
|
+
import { readSpeechKey } from "./speech-key.js";
|
|
3
3
|
/** Dictation through ElevenLabs Scribe v2 Realtime, for the phone's opt-in
|
|
4
4
|
* Scribe input. The phone streams 16 kHz mono PCM as binary frames; this
|
|
5
5
|
* computer forwards it to ElevenLabs with its own key, which never leaves
|
package/dist/bridge/speech.d.ts
CHANGED
|
@@ -17,12 +17,10 @@ export declare const speechRequest: z.ZodObject<{
|
|
|
17
17
|
}, z.core.$strip>;
|
|
18
18
|
export interface SpeechOptions {
|
|
19
19
|
fetch?: typeof fetch;
|
|
20
|
-
/** Resolves the ElevenLabs key; defaults to
|
|
20
|
+
/** Resolves the ElevenLabs key; defaults to ELEVENLABS_API_KEY, then the stored key (speech-key.ts). */
|
|
21
21
|
key?: () => Promise<string | undefined>;
|
|
22
22
|
voice?: string;
|
|
23
23
|
}
|
|
24
|
-
export declare function speechKeyFile(env?: NodeJS.ProcessEnv): string;
|
|
25
|
-
export declare function readSpeechKey(file?: string): Promise<string | undefined>;
|
|
26
24
|
/** A fixed message per ElevenLabs failure: its own response text is never
|
|
27
25
|
* passed on. */
|
|
28
26
|
export declare function speechError(upstream: Response): Promise<BridgeError>;
|
package/dist/bridge/speech.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { once } from "node:events";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
2
|
import { z } from "zod";
|
|
5
|
-
import { homeDir } from "../home-paths.js";
|
|
6
3
|
import { BridgeError } from "./protocol.js";
|
|
4
|
+
import { readSpeechKey } from "./speech-key.js";
|
|
7
5
|
/** Spoken replies for the phone's talk mode. The phone sends a sentence; the
|
|
8
6
|
* Hook voices it with ElevenLabs and streams the audio back. The API key is
|
|
9
7
|
* read on this computer, used only in the request to ElevenLabs, and never
|
|
@@ -18,18 +16,6 @@ export const SPEECH_MODEL = "eleven_flash_v2_5";
|
|
|
18
16
|
export const DEFAULT_SPEECH_VOICE = "SAz9YHcvj6GT2YYXdXww";
|
|
19
17
|
const MAX_TEXT = 2_000;
|
|
20
18
|
export const speechRequest = z.object({ text: z.string().trim().min(1).max(MAX_TEXT) });
|
|
21
|
-
export function speechKeyFile(env = process.env) {
|
|
22
|
-
return path.join(homeDir(env), ".config", "mina-trailer.json");
|
|
23
|
-
}
|
|
24
|
-
export async function readSpeechKey(file = speechKeyFile()) {
|
|
25
|
-
try {
|
|
26
|
-
const key = JSON.parse(await readFile(file, "utf8")).elevenlabs_api_key;
|
|
27
|
-
return typeof key === "string" && key.trim() ? key.trim() : undefined;
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
19
|
/** A fixed message per ElevenLabs failure: its own response text is never
|
|
34
20
|
* passed on. */
|
|
35
21
|
export async function speechError(upstream) {
|
|
@@ -52,7 +38,7 @@ export async function speechError(upstream) {
|
|
|
52
38
|
}
|
|
53
39
|
/** Starts ElevenLabs' streaming synthesis and returns its audio body. */
|
|
54
40
|
export async function synthesizeSpeech(text, signal, options = {}) {
|
|
55
|
-
const key = await (options.key ??
|
|
41
|
+
const key = await (options.key ?? readSpeechKey)();
|
|
56
42
|
if (!key)
|
|
57
43
|
throw new BridgeError(503, "Spoken replies aren't set up on this computer: it has no ElevenLabs key.", { code: "speech-unconfigured" });
|
|
58
44
|
const voice = options.voice ?? process.env.PHREN_SPEECH_VOICE ?? DEFAULT_SPEECH_VOICE;
|