agentvibes 3.5.9 → 4.0.0
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/.agentvibes/bmad/bmad-voices-enabled.flag +0 -0
- package/.agentvibes/bmad/bmad-voices.md +69 -0
- package/.claude/config/audio-effects.cfg +1 -1
- package/.claude/config/background-music-position.txt +1 -27
- package/.claude/github-star-reminder.txt +1 -1
- package/.claude/hooks/audio-processor.sh +32 -17
- package/.claude/hooks/bmad-speak-enhanced.sh +5 -5
- package/.claude/hooks/bmad-speak.sh +4 -4
- package/.claude/hooks/bmad-voice-manager.sh +8 -8
- package/.claude/hooks/clawdbot-receiver-SECURE.sh +23 -25
- package/.claude/hooks/clawdbot-receiver.sh +28 -4
- package/.claude/hooks/language-manager.sh +1 -1
- package/.claude/hooks/path-resolver.sh +60 -0
- package/.claude/hooks/play-tts-agentvibes-receiver-for-voiceless-connections.sh +90 -0
- package/.claude/hooks/play-tts-piper.sh +82 -24
- package/.claude/hooks/play-tts-ssh-remote.sh +13 -15
- package/.claude/hooks/play-tts.sh +16 -5
- package/.claude/hooks/session-start-tts.sh +26 -56
- package/.claude/hooks/soprano-gradio-synth.py +1 -1
- package/.claude/hooks/verbosity-manager.sh +10 -4
- package/.claude/settings.json +1 -1
- package/CLAUDE.md +129 -104
- package/README.md +418 -10
- package/RELEASE_NOTES.md +60 -1036
- package/bin/agentvibes-voice-browser.js +1827 -0
- package/bin/agentvibes.js +100 -0
- package/mcp-server/server.py +67 -3
- package/package.json +11 -2
- package/src/console/app.js +806 -0
- package/src/console/audio-env.js +123 -0
- package/src/console/brand-colors.js +13 -0
- package/src/console/footer-config.js +42 -0
- package/src/console/modals/.gitkeep +0 -0
- package/src/console/modals/modal-overlay.js +247 -0
- package/src/console/navigation.js +60 -0
- package/src/console/tabs/.gitkeep +0 -0
- package/src/console/tabs/agents-tab.js +369 -0
- package/src/console/tabs/help-tab.js +261 -0
- package/src/console/tabs/install-tab.js +990 -0
- package/src/console/tabs/music-tab.js +997 -0
- package/src/console/tabs/placeholder-tab.js +45 -0
- package/src/console/tabs/readme-tab.js +267 -0
- package/src/console/tabs/settings-tab.js +3949 -0
- package/src/console/tabs/voices-tab.js +1574 -0
- package/src/installer/music-file-input.js +304 -0
- package/src/installer.js +1353 -676
- package/src/services/.gitkeep +0 -0
- package/src/services/agent-voice-store.js +163 -0
- package/src/services/config-service.js +240 -0
- package/src/services/navigation-service.js +123 -0
- package/src/services/provider-service.js +132 -0
- package/src/services/verbosity-service.js +157 -0
- package/src/utils/audio-duration-validator.js +298 -0
- package/src/utils/audio-format-validator.js +277 -0
- package/src/utils/dependency-checker.js +3 -3
- package/src/utils/file-ownership-verifier.js +358 -0
- package/src/utils/music-file-validator.js +275 -0
- package/src/utils/preview-list-prompt.js +136 -0
- package/src/utils/provider-validator.js +144 -132
- package/src/utils/secure-music-storage.js +412 -0
- package/templates/agentvibes-receiver.sh +11 -7
- package/voice-assignments.json +8245 -0
- package/.claude/config/background-music-volume.txt +0 -1
- package/.claude/config/background-music.cfg +0 -1
- package/.claude/config/background-music.txt +0 -1
- package/.claude/config/tts-speech-rate.txt +0 -1
- package/.claude/config/tts-verbosity.txt +0 -1
- package/.claude/hooks/bmad-party-manager.sh +0 -225
- package/.claude/hooks/stop.sh +0 -38
- package/.claude/piper-voices-dir.txt +0 -1
- package/.mcp.json +0 -34
|
File without changes
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentVibes Agent Voice Store
|
|
3
|
+
* Epic 11: Stories 11.1, 11.3, 11.5
|
|
4
|
+
*
|
|
5
|
+
* Manages global BMAD agent voice assignments at ~/.agentvibes/bmad-voice-map.json.
|
|
6
|
+
* All path operations use path.resolve() to prevent traversal.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import os from 'node:os';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Single-voice provider detection (story 11.3)
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Known providers that only have one voice (limits party mode usefulness).
|
|
18
|
+
*/
|
|
19
|
+
const SINGLE_VOICE_PROVIDERS = Object.freeze(new Set(['soprano']));
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns true if the given provider only has one voice.
|
|
23
|
+
* @param {string} provider
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
*/
|
|
26
|
+
export function isSingleVoiceProvider(provider) {
|
|
27
|
+
return SINGLE_VOICE_PROVIDERS.has(provider?.toLowerCase());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// BMAD agent scanner (story 11.5)
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Scan for BMAD agents in the project root.
|
|
35
|
+
* Looks in `_bmad/bmm/agents/` then `.bmad/agents/`.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} projectRoot
|
|
38
|
+
* @returns {{ id: string, displayName: string }[]}
|
|
39
|
+
*/
|
|
40
|
+
export function scanBmadAgents(projectRoot) {
|
|
41
|
+
const safeRoot = path.resolve(projectRoot ?? process.cwd());
|
|
42
|
+
const candidateDirs = [
|
|
43
|
+
path.resolve(safeRoot, '_bmad', 'bmm', 'agents'),
|
|
44
|
+
path.resolve(safeRoot, '.bmad', 'agents'),
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
for (const dir of candidateDirs) {
|
|
48
|
+
if (!fs.existsSync(dir)) continue;
|
|
49
|
+
try {
|
|
50
|
+
const files = fs.readdirSync(dir);
|
|
51
|
+
return files
|
|
52
|
+
.filter(f => f.endsWith('.md') && !f.includes('.backup') && !f.includes('.bak'))
|
|
53
|
+
.map(f => {
|
|
54
|
+
const id = f.replace(/\.md$/, '');
|
|
55
|
+
const displayName = id
|
|
56
|
+
.split('-')
|
|
57
|
+
.map(w => w.charAt(0).toUpperCase() + w.slice(1))
|
|
58
|
+
.join(' ');
|
|
59
|
+
return { id, displayName };
|
|
60
|
+
})
|
|
61
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
62
|
+
} catch {
|
|
63
|
+
// Directory not readable — skip
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// AgentVoiceStore class (story 11.1)
|
|
71
|
+
|
|
72
|
+
export class AgentVoiceStore {
|
|
73
|
+
/**
|
|
74
|
+
* @param {object} [opts]
|
|
75
|
+
* @param {string} [opts.homeDir] - User home dir. Defaults to os.homedir().
|
|
76
|
+
*/
|
|
77
|
+
constructor(opts = {}) {
|
|
78
|
+
this._homeDir = path.resolve(opts.homeDir ?? os.homedir());
|
|
79
|
+
this._filePath = path.resolve(this._homeDir, '.agentvibes', 'bmad-voice-map.json');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Read the full voice map.
|
|
84
|
+
* @returns {{ voiceMap: object, partyMode: boolean }}
|
|
85
|
+
*/
|
|
86
|
+
_readStore() {
|
|
87
|
+
if (!fs.existsSync(this._filePath)) {
|
|
88
|
+
return { voiceMap: {}, partyMode: false };
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const raw = fs.readFileSync(this._filePath, 'utf8');
|
|
92
|
+
const data = JSON.parse(raw);
|
|
93
|
+
return {
|
|
94
|
+
voiceMap: data.voiceMap ?? {},
|
|
95
|
+
partyMode: data.partyMode ?? false,
|
|
96
|
+
};
|
|
97
|
+
} catch {
|
|
98
|
+
return { voiceMap: {}, partyMode: false };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Atomically write store data.
|
|
104
|
+
* @param {{ voiceMap: object, partyMode: boolean }} data
|
|
105
|
+
*/
|
|
106
|
+
_writeStore(data) {
|
|
107
|
+
const dir = path.dirname(this._filePath);
|
|
108
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
109
|
+
const tmpPath = `${this._filePath}.tmp`;
|
|
110
|
+
fs.writeFileSync(tmpPath, JSON.stringify(data, null, 2), { encoding: 'utf8', mode: 0o600 });
|
|
111
|
+
fs.renameSync(tmpPath, this._filePath);
|
|
112
|
+
fs.chmodSync(this._filePath, 0o600);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Get the agent → voice ID map.
|
|
117
|
+
* @returns {object}
|
|
118
|
+
*/
|
|
119
|
+
getVoiceMap() {
|
|
120
|
+
return this._readStore().voiceMap;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Assign a voice to an agent.
|
|
125
|
+
* @param {string} agentId
|
|
126
|
+
* @param {string} voiceId
|
|
127
|
+
*/
|
|
128
|
+
setVoice(agentId, voiceId) {
|
|
129
|
+
const store = this._readStore();
|
|
130
|
+
store.voiceMap[agentId] = voiceId;
|
|
131
|
+
this._writeStore(store);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Remove an agent's voice assignment (reset to default).
|
|
136
|
+
* @param {string} agentId
|
|
137
|
+
*/
|
|
138
|
+
resetVoice(agentId) {
|
|
139
|
+
const store = this._readStore();
|
|
140
|
+
delete store.voiceMap[agentId];
|
|
141
|
+
this._writeStore(store);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Get party mode state.
|
|
146
|
+
* @returns {boolean}
|
|
147
|
+
*/
|
|
148
|
+
getPartyMode() {
|
|
149
|
+
return this._readStore().partyMode;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Set party mode state.
|
|
154
|
+
* @param {boolean} enabled
|
|
155
|
+
*/
|
|
156
|
+
setPartyMode(enabled) {
|
|
157
|
+
const store = this._readStore();
|
|
158
|
+
store.partyMode = Boolean(enabled);
|
|
159
|
+
this._writeStore(store);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export default AgentVoiceStore;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentVibes Config Service
|
|
3
|
+
* Story 6.5: Command Routing & Entry Points (isInstalled, isBmadDetected stubs)
|
|
4
|
+
* Story 7.1: Provider & Voice Settings Group (full read/write implementation)
|
|
5
|
+
*
|
|
6
|
+
* Provides config hierarchy: global (~/.agentvibes/config.json)
|
|
7
|
+
* + project-level overrides (<projectRoot>/.agentvibes/config.json).
|
|
8
|
+
* All path operations use path.resolve() to prevent traversal.
|
|
9
|
+
* Config writes are atomic (write .tmp → rename) with chmod 600.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import os from 'node:os';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
|
|
16
|
+
export class ConfigService {
|
|
17
|
+
/**
|
|
18
|
+
* @param {object} [opts]
|
|
19
|
+
* @param {string} [opts.projectRoot] - Project root for hook/config detection. Defaults to process.cwd().
|
|
20
|
+
* @param {string} [opts.homeDir] - User home dir for global config. Defaults to os.homedir().
|
|
21
|
+
*/
|
|
22
|
+
constructor(opts = {}) {
|
|
23
|
+
// path.resolve() on all roots prevents path-traversal at the source
|
|
24
|
+
this._projectRoot = path.resolve(opts.projectRoot ?? process.cwd());
|
|
25
|
+
this._homeDir = path.resolve(opts.homeDir ?? os.homedir());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Returns the resolved project root path. */
|
|
29
|
+
getProjectRoot() {
|
|
30
|
+
return this._projectRoot;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Detection (story 6.5)
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns true if AgentVibes hooks are installed in this project.
|
|
38
|
+
* Detection: .claude/hooks/play-tts.sh exists in projectRoot.
|
|
39
|
+
*/
|
|
40
|
+
isInstalled() {
|
|
41
|
+
const hooksFile = path.resolve(this._projectRoot, '.claude', 'hooks', 'play-tts.sh');
|
|
42
|
+
return fs.existsSync(hooksFile);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns true if BMAD framework is detected.
|
|
47
|
+
* Checks: _bmad/ or .bmad/ in projectRoot, OR global voice map.
|
|
48
|
+
*/
|
|
49
|
+
isBmadDetected() {
|
|
50
|
+
const checks = [
|
|
51
|
+
path.resolve(this._projectRoot, '_bmad'),
|
|
52
|
+
path.resolve(this._projectRoot, '.bmad'),
|
|
53
|
+
path.resolve(this._homeDir, '.agentvibes', 'bmad-voice-map.json'),
|
|
54
|
+
];
|
|
55
|
+
return checks.some(p => fs.existsSync(p));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// Read (story 7.1)
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Returns global config (~/.agentvibes/config.json).
|
|
63
|
+
* Returns {} if file does not exist.
|
|
64
|
+
*/
|
|
65
|
+
getGlobalConfig() {
|
|
66
|
+
const filePath = path.resolve(this._homeDir, '.agentvibes', 'config.json');
|
|
67
|
+
return this._readConfigFile(filePath) ?? {};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Returns project config (<projectRoot>/.agentvibes/config.json) or null if not present.
|
|
72
|
+
*/
|
|
73
|
+
getProjectConfig() {
|
|
74
|
+
const dir = path.resolve(this._projectRoot, '.agentvibes');
|
|
75
|
+
if (!fs.existsSync(dir)) return null;
|
|
76
|
+
const filePath = path.resolve(dir, 'config.json');
|
|
77
|
+
return this._readConfigFile(filePath);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns merged config: global + project overrides.
|
|
82
|
+
* Project config keys win on conflict (deep merge for nested objects).
|
|
83
|
+
*/
|
|
84
|
+
getConfig() {
|
|
85
|
+
const global = this.getGlobalConfig();
|
|
86
|
+
const project = this.getProjectConfig();
|
|
87
|
+
return this._deepMerge(global, project);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns config schema version from merged config.
|
|
92
|
+
*/
|
|
93
|
+
getVersion() {
|
|
94
|
+
return this.getConfig().version ?? '1.0';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
// Path helpers
|
|
99
|
+
|
|
100
|
+
/** Returns the resolved global config file path. */
|
|
101
|
+
getGlobalConfigPath() {
|
|
102
|
+
return path.resolve(this._homeDir, '.agentvibes', 'config.json');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Returns the resolved local project config file path (regardless of whether it exists). */
|
|
106
|
+
getLocalConfigPath() {
|
|
107
|
+
return path.resolve(this._projectRoot, '.agentvibes', 'config.json');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Returns true if a local project config file exists. */
|
|
111
|
+
hasLocalConfig() {
|
|
112
|
+
return fs.existsSync(this.getLocalConfigPath());
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ---------------------------------------------------------------------------
|
|
116
|
+
// Bulk save
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Overwrites the ENTIRE global config with the given object.
|
|
120
|
+
* Atomic write (tmp → rename). Creates dir if needed. chmod 600.
|
|
121
|
+
* @param {object} data
|
|
122
|
+
*/
|
|
123
|
+
saveAllToGlobal(data) {
|
|
124
|
+
this._writeConfigAtomic(this.getGlobalConfigPath(), data);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Overwrites the ENTIRE local project config with the given object.
|
|
129
|
+
* Atomic write (tmp → rename). Creates dir if needed. chmod 600.
|
|
130
|
+
* @param {object} data
|
|
131
|
+
*/
|
|
132
|
+
saveAllToLocal(data) {
|
|
133
|
+
this._writeConfigAtomic(this.getLocalConfigPath(), data);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
// Write (story 7.1)
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Writes a key to project config if <projectRoot>/.agentvibes/ exists,
|
|
141
|
+
* otherwise writes to global config. Atomic write (tmp → rename). chmod 600.
|
|
142
|
+
* @param {string} key
|
|
143
|
+
* @param {*} value
|
|
144
|
+
*/
|
|
145
|
+
set(key, value) {
|
|
146
|
+
const projDir = path.resolve(this._projectRoot, '.agentvibes');
|
|
147
|
+
if (fs.existsSync(projDir)) {
|
|
148
|
+
const filePath = path.resolve(projDir, 'config.json');
|
|
149
|
+
const current = this._readConfigFile(filePath) ?? {};
|
|
150
|
+
current[key] = value;
|
|
151
|
+
this._writeConfigAtomic(filePath, current);
|
|
152
|
+
} else {
|
|
153
|
+
this.setGlobal(key, value);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Always writes a key to global config (~/.agentvibes/config.json).
|
|
159
|
+
* Atomic write (tmp → rename). chmod 600. Creates dir if needed.
|
|
160
|
+
* @param {string} key
|
|
161
|
+
* @param {*} value
|
|
162
|
+
*/
|
|
163
|
+
setGlobal(key, value) {
|
|
164
|
+
const filePath = path.resolve(this._homeDir, '.agentvibes', 'config.json');
|
|
165
|
+
const current = this._readConfigFile(filePath) ?? {};
|
|
166
|
+
current[key] = value;
|
|
167
|
+
this._writeConfigAtomic(filePath, current);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ---------------------------------------------------------------------------
|
|
171
|
+
// Private helpers
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Read and parse a JSON config file.
|
|
175
|
+
* Returns null if the file does not exist or is not a regular file.
|
|
176
|
+
* @param {string} filePath
|
|
177
|
+
* @returns {object|null}
|
|
178
|
+
*/
|
|
179
|
+
_readConfigFile(filePath) {
|
|
180
|
+
if (!fs.existsSync(filePath)) return null;
|
|
181
|
+
try {
|
|
182
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
183
|
+
return JSON.parse(raw);
|
|
184
|
+
} catch {
|
|
185
|
+
// Corrupt or unreadable — treat as missing
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Deep-merge two plain objects. Values from `override` win on conflict.
|
|
192
|
+
* Arrays are replaced (not merged). null override → returns copy of base.
|
|
193
|
+
* @param {object} base
|
|
194
|
+
* @param {object|null} override
|
|
195
|
+
* @returns {object}
|
|
196
|
+
*/
|
|
197
|
+
_deepMerge(base, override) {
|
|
198
|
+
if (!override || typeof override !== 'object') return { ...base };
|
|
199
|
+
const result = { ...base };
|
|
200
|
+
for (const [k, v] of Object.entries(override)) {
|
|
201
|
+
if (
|
|
202
|
+
v !== null &&
|
|
203
|
+
typeof v === 'object' &&
|
|
204
|
+
!Array.isArray(v) &&
|
|
205
|
+
typeof result[k] === 'object' &&
|
|
206
|
+
result[k] !== null &&
|
|
207
|
+
!Array.isArray(result[k])
|
|
208
|
+
) {
|
|
209
|
+
result[k] = this._deepMerge(result[k], v);
|
|
210
|
+
} else {
|
|
211
|
+
result[k] = v;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Atomically write data as JSON to filePath.
|
|
219
|
+
* Writes to {filePath}.tmp then renames — safe against partial reads.
|
|
220
|
+
* Creates parent directory if needed. Sets file permissions to 0o600.
|
|
221
|
+
* @param {string} filePath
|
|
222
|
+
* @param {object} data
|
|
223
|
+
*/
|
|
224
|
+
_writeConfigAtomic(filePath, data) {
|
|
225
|
+
const dir = path.dirname(filePath);
|
|
226
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
227
|
+
|
|
228
|
+
const tmpPath = `${filePath}.tmp`;
|
|
229
|
+
const json = JSON.stringify(data, null, 2);
|
|
230
|
+
|
|
231
|
+
// Write to tmp, then atomic rename
|
|
232
|
+
fs.writeFileSync(tmpPath, json, { encoding: 'utf8', mode: 0o600 });
|
|
233
|
+
fs.renameSync(tmpPath, filePath);
|
|
234
|
+
|
|
235
|
+
// Ensure correct permissions on final file
|
|
236
|
+
fs.chmodSync(filePath, 0o600);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export default ConfigService;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentVibes TUI Console — Navigation Service
|
|
3
|
+
* Story 6.2: Tab Bar & Global Keyboard Navigation
|
|
4
|
+
*
|
|
5
|
+
* Manages tab state, cycling, modal overlay state, and focus stack.
|
|
6
|
+
* Used by navigation.js (key bindings) and app.js (wiring).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Ordered list of all tab IDs — used for cycling and validation */
|
|
10
|
+
export const TAB_ORDER = ['install', 'settings', 'voices', 'music', 'readme', 'help'];
|
|
11
|
+
|
|
12
|
+
export class NavigationService {
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} [initialTab='settings'] - Tab to activate on launch
|
|
15
|
+
*/
|
|
16
|
+
constructor(initialTab = 'settings') {
|
|
17
|
+
this._activeTab = TAB_ORDER.includes(initialTab) ? initialTab : 'settings';
|
|
18
|
+
this._switchCallbacks = [];
|
|
19
|
+
this._focusStack = [];
|
|
20
|
+
this._modalOpen = false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Tab navigation
|
|
25
|
+
|
|
26
|
+
/** Returns the currently active tab ID */
|
|
27
|
+
getActiveTab() {
|
|
28
|
+
return this._activeTab;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Switch to the given tab.
|
|
33
|
+
* Ignores invalid tab IDs. Fires all registered onSwitch callbacks.
|
|
34
|
+
* @param {string} tabId
|
|
35
|
+
*/
|
|
36
|
+
switchTab(tabId) {
|
|
37
|
+
if (!TAB_ORDER.includes(tabId)) return;
|
|
38
|
+
if (tabId === this._activeTab) return; // no-op: already on this tab
|
|
39
|
+
this._activeTab = tabId;
|
|
40
|
+
this._switchCallbacks.forEach(cb => cb(tabId));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Activate a tab unconditionally, bypassing the same-tab no-op guard.
|
|
45
|
+
* Used for initial UI setup: the constructor pre-sets _activeTab but
|
|
46
|
+
* onSwitch callbacks must still fire to render the initial state.
|
|
47
|
+
* @param {string} tabId
|
|
48
|
+
*/
|
|
49
|
+
forceActivate(tabId) {
|
|
50
|
+
if (!TAB_ORDER.includes(tabId)) return;
|
|
51
|
+
this._activeTab = tabId;
|
|
52
|
+
this._switchCallbacks.forEach(cb => cb(tabId));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Cycle to the next tab in TAB_ORDER, wrapping from last back to first.
|
|
57
|
+
*/
|
|
58
|
+
cycleTab() {
|
|
59
|
+
const idx = TAB_ORDER.indexOf(this._activeTab);
|
|
60
|
+
const nextIdx = (idx + 1) % TAB_ORDER.length;
|
|
61
|
+
this.switchTab(TAB_ORDER[nextIdx]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Cycle to the previous tab in TAB_ORDER, wrapping from first back to last.
|
|
66
|
+
*/
|
|
67
|
+
cycleTabPrev() {
|
|
68
|
+
const idx = TAB_ORDER.indexOf(this._activeTab);
|
|
69
|
+
const prevIdx = (idx - 1 + TAB_ORDER.length) % TAB_ORDER.length;
|
|
70
|
+
this.switchTab(TAB_ORDER[prevIdx]);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Register a callback fired whenever the active tab changes.
|
|
75
|
+
* @param {(tabId: string) => void} callback
|
|
76
|
+
*/
|
|
77
|
+
onSwitch(callback) {
|
|
78
|
+
this._switchCallbacks.push(callback);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
// Modal state (story 6.4 will expand this)
|
|
83
|
+
|
|
84
|
+
/** Returns true if a modal is currently open */
|
|
85
|
+
isModalOpen() {
|
|
86
|
+
return this._modalOpen;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Open a modal. Sets modal-open state and calls the factory fn if provided.
|
|
91
|
+
* @param {Function|null} fn - Optional factory/callback invoked immediately
|
|
92
|
+
*/
|
|
93
|
+
openModal(fn) {
|
|
94
|
+
this._modalOpen = true;
|
|
95
|
+
fn?.();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Close the current modal, restoring modal-closed state */
|
|
99
|
+
closeModal() {
|
|
100
|
+
this._modalOpen = false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Focus stack (story 7.6 will use this for button-level focus)
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Push a Blessed element onto the focus stack
|
|
109
|
+
* @param {object} element - Blessed widget
|
|
110
|
+
*/
|
|
111
|
+
pushFocus(element) {
|
|
112
|
+
this._focusStack.push(element);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Pop the last element from the focus stack.
|
|
117
|
+
* Returns undefined if the stack is empty.
|
|
118
|
+
* @returns {object|undefined}
|
|
119
|
+
*/
|
|
120
|
+
popFocus() {
|
|
121
|
+
return this._focusStack.pop();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentVibes Provider Service
|
|
3
|
+
* Story 7.1: Provider & Voice Settings Group
|
|
4
|
+
*
|
|
5
|
+
* Detects installed TTS providers, reads/writes active provider and voice
|
|
6
|
+
* through ConfigService. Gracefully degrades when detection fails.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { execFileSync } from 'node:child_process';
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
|
|
14
|
+
export class ProviderService {
|
|
15
|
+
/**
|
|
16
|
+
* @param {import('./config-service.js').ConfigService} configService
|
|
17
|
+
*/
|
|
18
|
+
constructor(configService) {
|
|
19
|
+
this._config = configService;
|
|
20
|
+
this._installedProviders = null; // cached after first detection
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Provider
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns the currently active TTS provider from config.
|
|
28
|
+
* Defaults to 'piper' if not configured.
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
31
|
+
getActiveProvider() {
|
|
32
|
+
return this._config.getConfig().provider ?? 'piper';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Sets the active TTS provider in config AND syncs to .claude/tts-provider.txt
|
|
37
|
+
* so the shell hooks (play-tts.sh → provider-manager.sh) pick up the change.
|
|
38
|
+
* @param {string} provider
|
|
39
|
+
*/
|
|
40
|
+
setActiveProvider(provider) {
|
|
41
|
+
this._config.set('provider', provider);
|
|
42
|
+
this._syncProviderFile(provider);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Write provider to .claude/tts-provider.txt so shell hooks stay in sync.
|
|
47
|
+
* Writes to projectRoot/.claude/tts-provider.txt if .claude/ exists there,
|
|
48
|
+
* otherwise falls back to ~/.claude/tts-provider.txt.
|
|
49
|
+
* @param {string} provider
|
|
50
|
+
*/
|
|
51
|
+
_syncProviderFile(provider) {
|
|
52
|
+
try {
|
|
53
|
+
const projectClaudeDir = path.resolve(this._config.getProjectRoot(), '.claude');
|
|
54
|
+
const targetDir = fs.existsSync(projectClaudeDir)
|
|
55
|
+
? projectClaudeDir
|
|
56
|
+
: path.resolve(os.homedir(), '.claude');
|
|
57
|
+
const targetFile = path.resolve(targetDir, 'tts-provider.txt');
|
|
58
|
+
// Verify resolved path stays within targetDir (path traversal guard)
|
|
59
|
+
if (!targetFile.startsWith(targetDir + path.sep) && targetFile !== targetDir) return;
|
|
60
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
61
|
+
fs.writeFileSync(targetFile, provider, 'utf8');
|
|
62
|
+
} catch {
|
|
63
|
+
// Non-fatal — config.json is the authoritative source
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Returns an array of installed/available TTS providers.
|
|
69
|
+
* Detection uses `which` binary check. Always returns at least ['piper']
|
|
70
|
+
* as graceful degradation (piper is the primary supported provider).
|
|
71
|
+
* @returns {string[]}
|
|
72
|
+
*/
|
|
73
|
+
getInstalledProviders() {
|
|
74
|
+
if (this._installedProviders) return this._installedProviders;
|
|
75
|
+
|
|
76
|
+
const providers = [];
|
|
77
|
+
|
|
78
|
+
if (this._isAvailable('piper')) providers.push('piper');
|
|
79
|
+
if (this._isAvailable('soprano')) providers.push('soprano');
|
|
80
|
+
|
|
81
|
+
// macOS Say (darwin only)
|
|
82
|
+
if (process.platform === 'darwin' && this._isAvailable('say')) {
|
|
83
|
+
providers.push('macos');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Graceful degradation: always return at least piper
|
|
87
|
+
if (providers.length === 0) providers.push('piper');
|
|
88
|
+
|
|
89
|
+
this._installedProviders = providers;
|
|
90
|
+
return providers;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
// Voice
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Returns the currently active voice ID from config.
|
|
98
|
+
* Defaults to 'en_US-amy-medium' if not configured.
|
|
99
|
+
* @returns {string}
|
|
100
|
+
*/
|
|
101
|
+
getActiveVoiceId() {
|
|
102
|
+
return this._config.getConfig().voice ?? 'en_US-amy-medium';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Sets the active voice ID in config.
|
|
107
|
+
* @param {string} voiceId
|
|
108
|
+
*/
|
|
109
|
+
setActiveVoice(voiceId) {
|
|
110
|
+
this._config.set('voice', voiceId);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
// Private
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Check if a binary is available in PATH using `which`.
|
|
118
|
+
* Binary names are all hardcoded (not user input) — safe from injection.
|
|
119
|
+
* @param {string} binary - hardcoded binary name ('piper', 'soprano', 'say')
|
|
120
|
+
* @returns {boolean}
|
|
121
|
+
*/
|
|
122
|
+
_isAvailable(binary) {
|
|
123
|
+
try {
|
|
124
|
+
execFileSync('which', [binary], { stdio: 'ignore', timeout: 2000 });
|
|
125
|
+
return true;
|
|
126
|
+
} catch {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export default ProviderService;
|