voice-runtime 0.0.2 → 1.0.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/README.md +244 -9
- package/bin/voice-runtime.mjs +248 -0
- package/dist/index.cjs +18409 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +3976 -0
- package/dist/index.js +18212 -0
- package/dist/index.js.map +7 -0
- package/package.json +42 -8
- package/skills/tvic/SKILL.md +79 -0
- package/index.d.ts +0 -8
- package/index.js +0 -13
package/README.md
CHANGED
|
@@ -8,18 +8,136 @@
|
|
|
8
8
|
[TVIC](https://github.com/Kkartik14/TVIC), a provider-neutral runtime for realtime
|
|
9
9
|
voice agents with bring-your-own telephony, speech, model, and synthesis providers.
|
|
10
10
|
|
|
11
|
-
## Status
|
|
11
|
+
## Status
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
`voice-runtime@1.0.0` is the public Node.js entry point for the TVIC runtime. It
|
|
14
|
+
declares Node.js 20 or newer, ships both ESM and CommonJS entry points, and is
|
|
15
|
+
server-side only. The main CI compatibility matrix exercises Node 22, 24, and 26;
|
|
16
|
+
Node 20 remains the package engine floor.
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
Browser audio connects to a Node server through the browser-audio transport
|
|
19
|
+
adapter. Browser code does not import this package directly.
|
|
19
20
|
|
|
20
|
-
The
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
The stable managed API assembles the STT → LLM → TTS pipeline from a prompt and
|
|
22
|
+
provider configuration. The host application still owns its HTTP server,
|
|
23
|
+
webhook authentication, browser-session authentication, and domain tools.
|
|
24
|
+
|
|
25
|
+
If you are new to voice systems, read the [beginner guide on GitHub](https://github.com/Kkartik14/TVIC/blob/main/docs/start-here.md)
|
|
26
|
+
before using the lower-level examples. The [provider guide](https://github.com/Kkartik14/TVIC/blob/main/docs/providers.md)
|
|
27
|
+
explains credentials, model selection, and maturity labels.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npm install voice-runtime
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The package has no provider SDK lock-in. You may use the built-in adapters, pass
|
|
36
|
+
your own provider implementations, or mix both approaches.
|
|
37
|
+
|
|
38
|
+
## Optional AI agent guidance
|
|
39
|
+
|
|
40
|
+
To give Claude Code, Codex, or another compatible coding agent project-scoped
|
|
41
|
+
TVIC guidance, run this explicitly from your project directory:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
npx voice-runtime skills install
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The command asks for `y` before writing `.claude/skills/tvic/SKILL.md` for Claude
|
|
48
|
+
Code and `.agents/skills/tvic/SKILL.md` for Codex and OpenRouter-compatible
|
|
49
|
+
agents. It does not run automatically during `npm install`, write to a home
|
|
50
|
+
directory, or overwrite an existing skill without `--force`. Use
|
|
51
|
+
`npx voice-runtime skills install --yes` in automation. See the [AI agent skills
|
|
52
|
+
guide](https://github.com/Kkartik14/TVIC/blob/main/docs/agent-skills.md).
|
|
53
|
+
|
|
54
|
+
## Prompt-first agent
|
|
55
|
+
|
|
56
|
+
The prompt-first API assembles the STT → LLM → TTS pipeline. It still needs an
|
|
57
|
+
authenticated transport `CallHandle`; `npm install` does not create a public
|
|
58
|
+
audio endpoint or a phone call for your application.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { createVoiceAgent } from "voice-runtime";
|
|
62
|
+
|
|
63
|
+
const agent = createVoiceAgent({
|
|
64
|
+
prompt: "You schedule appointments for Dr. Kartik. Be concise and confirm the time.",
|
|
65
|
+
providers: {
|
|
66
|
+
telephony: { provider: "web-client-audio" },
|
|
67
|
+
stt: { provider: "deepgram", apiKey: process.env.DEEPGRAM_API_KEY },
|
|
68
|
+
llm: {
|
|
69
|
+
provider: "openai",
|
|
70
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
71
|
+
model: "gpt-4.1-mini",
|
|
72
|
+
},
|
|
73
|
+
tts: {
|
|
74
|
+
provider: "cartesia",
|
|
75
|
+
apiKey: process.env.CARTESIA_API_KEY,
|
|
76
|
+
voiceId: process.env.CARTESIA_VOICE_ID,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// `callHandle` comes from a verified transport connection or your own adapter.
|
|
82
|
+
const session = await agent.start({
|
|
83
|
+
callHandle,
|
|
84
|
+
channel: "web_audio",
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
for await (const event of session.run) {
|
|
88
|
+
if (event.kind === "transcript_delta") console.log("caller:", event.text);
|
|
89
|
+
if (event.kind === "error") console.error(event.error);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const result = await session.run;
|
|
93
|
+
console.log(result.turnsHandled);
|
|
94
|
+
await agent.stop();
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`agent.start()` returns `{ sessionId, run }`. The `run` value is both an async
|
|
98
|
+
event stream and an awaitable final result. The separate envelope is required by
|
|
99
|
+
JavaScript Promise assimilation rules; returning the Promise-like run directly
|
|
100
|
+
from an async `start()` method would make `await agent.start()` lose the session
|
|
101
|
+
handle. Use `agent.run(options)` when you only need the final result.
|
|
102
|
+
|
|
103
|
+
TVIC does not receive media from a prompt alone. A verified transport adapter
|
|
104
|
+
must produce the `callHandle` passed to `start()`.
|
|
105
|
+
|
|
106
|
+
For a built-in Web Client Audio or Twilio adapter, use the factory form so the
|
|
107
|
+
adapter receives the session ID created by TVIC:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { createTwilioMediaStreamsProvider, createVoiceAgent } from "voice-runtime";
|
|
111
|
+
|
|
112
|
+
const telephony = createTwilioMediaStreamsProvider();
|
|
113
|
+
|
|
114
|
+
const session = await agent.start({
|
|
115
|
+
call: verifiedInboundCall,
|
|
116
|
+
channel: "phone",
|
|
117
|
+
callHandle: ({ sessionId, call }) => telephony.acceptWebSocket(socket, call.id, sessionId),
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The factory runs after the runtime session exists and receives
|
|
122
|
+
`{ sessionId, call, channel }`. The supplied call is required in this form, and
|
|
123
|
+
its ID must match the returned handle's `callId`. Replace the provider and
|
|
124
|
+
`channel` with `createWebClientAudioProvider()` and `"web_audio"` for browser
|
|
125
|
+
audio. A preconstructed custom `CallHandle` is also supported when the adapter
|
|
126
|
+
already knows how to correlate its events to the managed session.
|
|
127
|
+
|
|
128
|
+
`agent.stop()` is idempotent. If a session is still running, it cancels and
|
|
129
|
+
drains that session before closing the runtime and its stores.
|
|
130
|
+
|
|
131
|
+
Errors on `VoiceEvent` and `MediaEvent` payloads are JSON-safe
|
|
132
|
+
`NormalizedError` values. Check them with `isNormalizedError`; the
|
|
133
|
+
`isTvicError` marker is reserved for thrown `TvicThrowableError` wrappers and
|
|
134
|
+
is not present on plain event payloads.
|
|
135
|
+
|
|
136
|
+
TVIC-created error codes use lowercase, namespaced identifiers such as
|
|
137
|
+
`auth.invalid_key` and `provider.open_failed`. Custom calls to
|
|
138
|
+
`normalizedError()` and `normalizeUnknownError()` must use one or more
|
|
139
|
+
lowercase dot-separated segments; older persisted error records retain their
|
|
140
|
+
legacy codes during migration.
|
|
23
141
|
|
|
24
142
|
## What TVIC does
|
|
25
143
|
|
|
@@ -31,6 +149,123 @@ Recordings, traces, incident analysis, and dashboards are deliberately out of sc
|
|
|
31
149
|
Those belong to Earshot, a separate voice observability product that integrates
|
|
32
150
|
outside the realtime critical path.
|
|
33
151
|
|
|
152
|
+
## Providers, models, and credentials
|
|
153
|
+
|
|
154
|
+
Each stage is configured independently. Built-in options currently include:
|
|
155
|
+
|
|
156
|
+
- STT: Deepgram, Sarvam, ElevenLabs Scribe, AssemblyAI, and Soniox.
|
|
157
|
+
- LLM: OpenAI Responses.
|
|
158
|
+
- TTS: Cartesia and ElevenLabs.
|
|
159
|
+
- Transport: browser audio and inbound Twilio Media Streams.
|
|
160
|
+
|
|
161
|
+
Maturity is intentionally explicit: Web Client Audio and inbound Twilio Media
|
|
162
|
+
Streams are the stable transport paths in `1.0.0`. The paid STT, LLM,
|
|
163
|
+
and TTS adapters are currently `experimental`. Their deterministic protocol
|
|
164
|
+
coverage passes, but each still needs a credential-gated live-service check
|
|
165
|
+
before release notes can call it stable. The root export `PROVIDER_STABILITY`
|
|
166
|
+
contains the machine-readable labels.
|
|
167
|
+
|
|
168
|
+
Pass an explicit `apiKey` or use the documented environment variable. Explicit
|
|
169
|
+
credentials take precedence; missing credentials fail before a live session is
|
|
170
|
+
created.
|
|
171
|
+
|
|
172
|
+
| Provider | Environment variable |
|
|
173
|
+
| ---------- | -------------------- |
|
|
174
|
+
| Deepgram | `DEEPGRAM_API_KEY` |
|
|
175
|
+
| Sarvam | `SARVAM_API_KEY` |
|
|
176
|
+
| ElevenLabs | `ELEVENLABS_API_KEY` |
|
|
177
|
+
| AssemblyAI | `ASSEMBLYAI_API_KEY` |
|
|
178
|
+
| Soniox | `SONIOX_API_KEY` |
|
|
179
|
+
| OpenAI | `OPENAI_API_KEY` |
|
|
180
|
+
| Cartesia | `CARTESIA_API_KEY` |
|
|
181
|
+
|
|
182
|
+
STT, LLM, and TTS models are independent settings. TTS voice selection is also
|
|
183
|
+
independent. Built-in TTS can read `CARTESIA_VOICE_ID` or
|
|
184
|
+
`ELEVENLABS_VOICE_ID` for its voice. For complete provider-specific control,
|
|
185
|
+
pass a constructed provider instance instead of a built-in configuration object.
|
|
186
|
+
Built-in STT and OpenAI-compatible LLM configurations reject models outside the
|
|
187
|
+
dated TVIC catalog unless `allowUnknownModel: true` is explicitly set.
|
|
188
|
+
|
|
189
|
+
Tools are application-owned functions. Define their schema and executor once,
|
|
190
|
+
then include them in the agent:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
import { createVoiceAgent, defineTool } from "voice-runtime";
|
|
194
|
+
|
|
195
|
+
const bookAppointment = defineTool<{ date: string }, { booked: boolean }>({
|
|
196
|
+
id: "book_appointment",
|
|
197
|
+
name: "book_appointment",
|
|
198
|
+
description: "Books an appointment for a requested date.",
|
|
199
|
+
inputSchema: { type: "object", required: ["date"] },
|
|
200
|
+
outputSchema: { type: "object", required: ["booked"] },
|
|
201
|
+
async execute(input) {
|
|
202
|
+
// Call your application service here; TVIC does not own domain state.
|
|
203
|
+
return { booked: input.date.length > 0 };
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const providers = {
|
|
208
|
+
telephony: { provider: "web-client-audio" as const },
|
|
209
|
+
stt: { provider: "deepgram" as const, apiKey: process.env.DEEPGRAM_API_KEY },
|
|
210
|
+
llm: { provider: "openai" as const, apiKey: process.env.OPENAI_API_KEY },
|
|
211
|
+
tts: {
|
|
212
|
+
provider: "cartesia" as const,
|
|
213
|
+
apiKey: process.env.CARTESIA_API_KEY,
|
|
214
|
+
voiceId: process.env.CARTESIA_VOICE_ID,
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const agentWithTools = createVoiceAgent({
|
|
219
|
+
prompt: "Schedule appointments and use the booking tool when needed.",
|
|
220
|
+
tools: [bookAppointment],
|
|
221
|
+
providers,
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Tool execution receives a session/turn-scoped `AbortSignal`; authorization,
|
|
226
|
+
confirmation for irreversible actions, and domain-state writes remain the host
|
|
227
|
+
application's responsibility.
|
|
228
|
+
|
|
229
|
+
## Composable API
|
|
230
|
+
|
|
231
|
+
Advanced runtime, media, provider, normalized-error, and durable-adapter APIs
|
|
232
|
+
are exported from the package root. There are no advanced subpath imports in
|
|
233
|
+
1.0.0. This lets a developer start with `createVoiceAgent` and later own
|
|
234
|
+
the runtime/session/pipeline boundaries without changing package names.
|
|
235
|
+
|
|
236
|
+
The host remains responsible for creating authenticated transport connections,
|
|
237
|
+
owning HTTP/webhook lifecycle, and implementing application-domain tools. TVIC
|
|
238
|
+
does not automatically create public unauthenticated endpoints or choose a
|
|
239
|
+
provider fallback policy.
|
|
240
|
+
|
|
241
|
+
## Persistence adapters
|
|
242
|
+
|
|
243
|
+
The root also exposes the PostgreSQL and Redis durability building blocks. The
|
|
244
|
+
database drivers are intentionally injected, so install and configure `pg` and
|
|
245
|
+
`redis` in your application:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
import {
|
|
249
|
+
createPostgresMemory,
|
|
250
|
+
createPostgresRedisDurableRuntimeStore,
|
|
251
|
+
runPostgresMemoryMigrations,
|
|
252
|
+
runPostgresMigrations,
|
|
253
|
+
} from "voice-runtime";
|
|
254
|
+
|
|
255
|
+
await runPostgresMigrations(pgPool);
|
|
256
|
+
await runPostgresMemoryMigrations(memoryPool);
|
|
257
|
+
const memory = createPostgresMemory({ pool: memoryPool });
|
|
258
|
+
const durable = createPostgresRedisDurableRuntimeStore({
|
|
259
|
+
pool: pgPool,
|
|
260
|
+
redis: redisClient,
|
|
261
|
+
});
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
The migration SQL is bundled into the published package and can also be
|
|
265
|
+
inspected in the package's migration sources. Run each migration function once
|
|
266
|
+
at deploy time; repeated calls are idempotent. PostgreSQL is authoritative for
|
|
267
|
+
the composite store, while Redis is used for its cache/projection layer.
|
|
268
|
+
|
|
34
269
|
## License
|
|
35
270
|
|
|
36
271
|
[Apache-2.0](./LICENSE)
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import readline from "node:readline/promises";
|
|
7
|
+
|
|
8
|
+
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
9
|
+
const skillSource = path.join(packageRoot, "skills", "tvic", "SKILL.md");
|
|
10
|
+
|
|
11
|
+
const AGENT_TARGETS = Object.freeze({
|
|
12
|
+
claude: Object.freeze({
|
|
13
|
+
label: "Claude Code",
|
|
14
|
+
relativePath: path.join(".claude", "skills", "tvic", "SKILL.md"),
|
|
15
|
+
}),
|
|
16
|
+
codex: Object.freeze({
|
|
17
|
+
label: "Codex",
|
|
18
|
+
relativePath: path.join(".agents", "skills", "tvic", "SKILL.md"),
|
|
19
|
+
}),
|
|
20
|
+
openrouter: Object.freeze({
|
|
21
|
+
label: "OpenRouter-compatible agents",
|
|
22
|
+
relativePath: path.join(".agents", "skills", "tvic", "SKILL.md"),
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const DEFAULT_AGENTS = Object.freeze(["claude", "codex", "openrouter"]);
|
|
27
|
+
|
|
28
|
+
function printHelp() {
|
|
29
|
+
process.stdout.write("voice-runtime\n\n");
|
|
30
|
+
process.stdout.write("Install the optional TVIC guidance skill in the current project.\n\n");
|
|
31
|
+
process.stdout.write("Usage:\n");
|
|
32
|
+
process.stdout.write(" voice-runtime skills install [options]\n\n");
|
|
33
|
+
process.stdout.write("Options:\n");
|
|
34
|
+
process.stdout.write(" --agent <name> Target claude, codex, or openrouter. Repeatable.\n");
|
|
35
|
+
process.stdout.write(" --yes Confirm installation without a prompt.\n");
|
|
36
|
+
process.stdout.write(" --dry-run Show planned files without changing anything.\n");
|
|
37
|
+
process.stdout.write(" --force Replace an existing TVIC skill file.\n");
|
|
38
|
+
process.stdout.write(" --help Show this help.\n\n");
|
|
39
|
+
process.stdout.write("Project paths:\n");
|
|
40
|
+
process.stdout.write(" Claude Code: .claude/skills/tvic/SKILL.md\n");
|
|
41
|
+
process.stdout.write(" Codex/OpenRouter: .agents/skills/tvic/SKILL.md\n");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function parseArgs(args) {
|
|
45
|
+
const options = {
|
|
46
|
+
agents: [],
|
|
47
|
+
dryRun: false,
|
|
48
|
+
force: false,
|
|
49
|
+
help: false,
|
|
50
|
+
yes: false,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
54
|
+
const argument = args[index];
|
|
55
|
+
if (argument === "--help" || argument === "-h") {
|
|
56
|
+
options.help = true;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (argument === "--yes" || argument === "-y") {
|
|
60
|
+
options.yes = true;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (argument === "--dry-run") {
|
|
64
|
+
options.dryRun = true;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (argument === "--force" || argument === "-f") {
|
|
68
|
+
options.force = true;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (argument === "--agent") {
|
|
73
|
+
const value = args[index + 1];
|
|
74
|
+
if (!value) throw new Error("--agent requires a value");
|
|
75
|
+
options.agents.push(...value.split(","));
|
|
76
|
+
index += 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (argument.startsWith("--agent=")) {
|
|
81
|
+
options.agents.push(...argument.slice("--agent=".length).split(","));
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
throw new Error(`Unknown option: ${argument}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return options;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function selectedAgents(requestedAgents) {
|
|
92
|
+
const names = requestedAgents.length > 0 ? requestedAgents : DEFAULT_AGENTS;
|
|
93
|
+
const selected = new Set();
|
|
94
|
+
|
|
95
|
+
for (const requested of names) {
|
|
96
|
+
const name = requested.trim().toLowerCase();
|
|
97
|
+
if (name === "all") {
|
|
98
|
+
for (const agent of DEFAULT_AGENTS) selected.add(agent);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (!Object.hasOwn(AGENT_TARGETS, name)) {
|
|
102
|
+
throw new Error(`Unknown agent "${requested}". Choose claude, codex, or openrouter.`);
|
|
103
|
+
}
|
|
104
|
+
selected.add(name);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return [...selected];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function plannedFiles(agentNames, projectDirectory) {
|
|
111
|
+
const plans = new Map();
|
|
112
|
+
|
|
113
|
+
for (const agentName of agentNames) {
|
|
114
|
+
const target = AGENT_TARGETS[agentName];
|
|
115
|
+
const absolutePath = path.resolve(projectDirectory, target.relativePath);
|
|
116
|
+
const existing = plans.get(absolutePath);
|
|
117
|
+
if (existing) {
|
|
118
|
+
existing.agentNames.push(agentName);
|
|
119
|
+
} else {
|
|
120
|
+
plans.set(absolutePath, {
|
|
121
|
+
agentNames: [agentName],
|
|
122
|
+
absolutePath,
|
|
123
|
+
relativePath: path.relative(projectDirectory, absolutePath),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return [...plans.values()];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function inspectPlans(plans, source, force) {
|
|
132
|
+
const inspected = [];
|
|
133
|
+
|
|
134
|
+
for (const plan of plans) {
|
|
135
|
+
let current;
|
|
136
|
+
try {
|
|
137
|
+
current = await readFile(plan.absolutePath, "utf8");
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if (error?.code !== "ENOENT") throw error;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let action = "create";
|
|
143
|
+
if (current !== undefined) {
|
|
144
|
+
action = current === source ? "unchanged" : force ? "replace" : "conflict";
|
|
145
|
+
}
|
|
146
|
+
inspected.push({ ...plan, action });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return inspected;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function confirmInstallation(projectDirectory, plans) {
|
|
153
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
"No interactive terminal is available. Re-run with --yes to confirm installation.",
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const labels = [...new Set(plans.flatMap((plan) => plan.agentNames))]
|
|
160
|
+
.map((agentName) => AGENT_TARGETS[agentName].label)
|
|
161
|
+
.join(", ");
|
|
162
|
+
const prompt = `Install TVIC guidance for ${labels} in ${projectDirectory}? (y/N) `;
|
|
163
|
+
const terminal = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
164
|
+
try {
|
|
165
|
+
const answer = await terminal.question(prompt);
|
|
166
|
+
return answer.trim().toLowerCase() === "y";
|
|
167
|
+
} finally {
|
|
168
|
+
terminal.close();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function installPlans(plans, source) {
|
|
173
|
+
for (const plan of plans) {
|
|
174
|
+
if (plan.action === "unchanged") {
|
|
175
|
+
process.stdout.write(`Already installed: ${plan.relativePath}\n`);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
await mkdir(path.dirname(plan.absolutePath), { recursive: true });
|
|
179
|
+
await writeFile(plan.absolutePath, source, "utf8");
|
|
180
|
+
process.stdout.write(
|
|
181
|
+
`${plan.action === "replace" ? "Updated" : "Installed"}: ${plan.relativePath}\n`,
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function installSkills(options) {
|
|
187
|
+
const projectDirectory = process.cwd();
|
|
188
|
+
const agents = selectedAgents(options.agents);
|
|
189
|
+
const source = await readFile(skillSource, "utf8");
|
|
190
|
+
const plans = await inspectPlans(plannedFiles(agents, projectDirectory), source, options.force);
|
|
191
|
+
|
|
192
|
+
process.stdout.write(`Project: ${projectDirectory}\n`);
|
|
193
|
+
for (const plan of plans) {
|
|
194
|
+
const agentsForPath = [...new Set(plan.agentNames)]
|
|
195
|
+
.map((agentName) => AGENT_TARGETS[agentName].label)
|
|
196
|
+
.join(" and ");
|
|
197
|
+
process.stdout.write(` ${plan.relativePath} (${agentsForPath})\n`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (options.dryRun) {
|
|
201
|
+
process.stdout.write("Dry run: no files changed.\n");
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const conflicts = plans.filter((plan) => plan.action === "conflict");
|
|
206
|
+
if (conflicts.length > 0) {
|
|
207
|
+
throw new Error(
|
|
208
|
+
`Existing TVIC skill files differ: ${conflicts
|
|
209
|
+
.map((plan) => plan.relativePath)
|
|
210
|
+
.join(", ")}. Use --force to replace them.`,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (!options.yes && !(await confirmInstallation(projectDirectory, plans))) {
|
|
215
|
+
process.stdout.write("No files changed.\n");
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
await installPlans(plans, source);
|
|
220
|
+
process.stdout.write(
|
|
221
|
+
"TVIC agent guidance is ready. Restart the agent if it does not appear automatically.\n",
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function main() {
|
|
226
|
+
const [command, subcommand, ...args] = process.argv.slice(2);
|
|
227
|
+
if (command === "--help" || command === "-h" || !command) {
|
|
228
|
+
printHelp();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (command !== "skills" || subcommand !== "install") {
|
|
232
|
+
throw new Error("Use: voice-runtime skills install [options]");
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const options = parseArgs(args);
|
|
236
|
+
if (options.help) {
|
|
237
|
+
printHelp();
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
await installSkills(options);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
main().catch((error) => {
|
|
244
|
+
process.stderr.write(
|
|
245
|
+
`voice-runtime: ${error instanceof Error ? error.message : String(error)}\n`,
|
|
246
|
+
);
|
|
247
|
+
process.exitCode = 1;
|
|
248
|
+
});
|