hyntx 3.0.2 → 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/README.md +118 -963
- package/dist/cli.d.ts +1 -440
- package/dist/cli.js +5183 -6762
- package/dist/index.d.ts +696 -2
- package/dist/index.js +5392 -1
- package/package.json +17 -38
- package/dist/api/index.d.ts +0 -1083
- package/dist/api/index.js +0 -1
- package/dist/chunk-24U3LCZC.js +0 -3347
- package/dist/chunk-TLJ2AIHG.js +0 -389
- package/dist/shell-config-VEIMSP5W.js +0 -2
package/dist/chunk-TLJ2AIHG.js
DELETED
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { existsSync, readFileSync, mkdirSync, writeFileSync, chmodSync } from 'fs';
|
|
3
|
-
import { homedir } from 'os';
|
|
4
|
-
import { join, dirname } from 'path';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
|
|
7
|
-
// src/utils/logger-base.ts
|
|
8
|
-
var BaseLogger = class {
|
|
9
|
-
warnings = [];
|
|
10
|
-
verboseEnabled = false;
|
|
11
|
-
/**
|
|
12
|
-
* Enables or disables verbose (debug) mode.
|
|
13
|
-
*
|
|
14
|
-
* @param enabled - Whether to enable verbose mode
|
|
15
|
-
*/
|
|
16
|
-
setVerbose(enabled) {
|
|
17
|
-
this.verboseEnabled = enabled;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Returns whether verbose mode is enabled.
|
|
21
|
-
*
|
|
22
|
-
* @returns true if verbose mode is enabled
|
|
23
|
-
*/
|
|
24
|
-
isVerbose() {
|
|
25
|
-
return this.verboseEnabled;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Logs an error message to stderr.
|
|
29
|
-
*
|
|
30
|
-
* @param message - Error message
|
|
31
|
-
* @param context - Optional context (e.g., file name, operation)
|
|
32
|
-
*/
|
|
33
|
-
error(message, context) {
|
|
34
|
-
const prefix = context ? `[${context}] ` : "";
|
|
35
|
-
process.stderr.write(`ERROR: ${prefix}${message}
|
|
36
|
-
`);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Logs a warning message to stderr.
|
|
40
|
-
*
|
|
41
|
-
* @param message - Warning message
|
|
42
|
-
* @param context - Optional context (e.g., file name, operation)
|
|
43
|
-
*/
|
|
44
|
-
warn(message, context) {
|
|
45
|
-
const prefix = context ? `[${context}] ` : "";
|
|
46
|
-
process.stderr.write(`WARN: ${prefix}${message}
|
|
47
|
-
`);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Logs an info message to stderr.
|
|
51
|
-
*
|
|
52
|
-
* @param message - Info message
|
|
53
|
-
*/
|
|
54
|
-
info(message) {
|
|
55
|
-
process.stderr.write(`INFO: ${message}
|
|
56
|
-
`);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Logs a debug message to stderr (only when verbose mode is enabled).
|
|
60
|
-
*
|
|
61
|
-
* @param message - Debug message
|
|
62
|
-
* @param context - Optional context
|
|
63
|
-
*/
|
|
64
|
-
debug(message, context) {
|
|
65
|
-
if (this.verboseEnabled) {
|
|
66
|
-
const prefix = context ? `[${context}] ` : "";
|
|
67
|
-
process.stderr.write(`[DEBUG] ${prefix}${message}
|
|
68
|
-
`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Collects a warning for later reporting.
|
|
73
|
-
* Use this for non-fatal issues that should be displayed at the end of execution.
|
|
74
|
-
*
|
|
75
|
-
* @param message - Warning message
|
|
76
|
-
* @param context - Optional context (e.g., file name, operation)
|
|
77
|
-
*/
|
|
78
|
-
collectWarning(message, context) {
|
|
79
|
-
this.warnings.push({ message, context });
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Returns all collected warnings.
|
|
83
|
-
*
|
|
84
|
-
* @returns Array of collected warnings
|
|
85
|
-
*/
|
|
86
|
-
getWarnings() {
|
|
87
|
-
return [...this.warnings];
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Returns the number of collected warnings.
|
|
91
|
-
*
|
|
92
|
-
* @returns Warning count
|
|
93
|
-
*/
|
|
94
|
-
getWarningCount() {
|
|
95
|
-
return this.warnings.length;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Clears all collected warnings.
|
|
99
|
-
*/
|
|
100
|
-
clearWarnings() {
|
|
101
|
-
this.warnings = [];
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Reports all collected warnings to stderr and clears them.
|
|
105
|
-
* Does nothing if there are no warnings.
|
|
106
|
-
*/
|
|
107
|
-
reportWarnings() {
|
|
108
|
-
if (this.warnings.length === 0) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
process.stderr.write(`
|
|
112
|
-
\u26A0\uFE0F ${String(this.warnings.length)} warning(s):
|
|
113
|
-
`);
|
|
114
|
-
for (const warning of this.warnings) {
|
|
115
|
-
const prefix = warning.context ? `[${warning.context}] ` : "";
|
|
116
|
-
process.stderr.write(` - ${prefix}${warning.message}
|
|
117
|
-
`);
|
|
118
|
-
}
|
|
119
|
-
this.clearWarnings();
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Formats collected warnings as plain text (without ANSI colors).
|
|
123
|
-
* Useful for JSON output or testing.
|
|
124
|
-
*
|
|
125
|
-
* @returns Array of formatted warning strings
|
|
126
|
-
*/
|
|
127
|
-
formatWarnings() {
|
|
128
|
-
return this.warnings.map((w) => {
|
|
129
|
-
const prefix = w.context ? `[${w.context}] ` : "";
|
|
130
|
-
return `${prefix}${w.message}`;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
var logger = new BaseLogger();
|
|
135
|
-
|
|
136
|
-
// src/utils/logger.ts
|
|
137
|
-
var CliLogger = class extends BaseLogger {
|
|
138
|
-
/**
|
|
139
|
-
* Logs an error message to stderr with red coloring.
|
|
140
|
-
*
|
|
141
|
-
* @param message - Error message
|
|
142
|
-
* @param context - Optional context (e.g., file name, operation)
|
|
143
|
-
*/
|
|
144
|
-
error(message, context) {
|
|
145
|
-
const prefix = context ? `[${context}] ` : "";
|
|
146
|
-
process.stderr.write(chalk.red(`ERROR: ${prefix}${message}
|
|
147
|
-
`));
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Logs a warning message to stderr with yellow coloring.
|
|
151
|
-
*
|
|
152
|
-
* @param message - Warning message
|
|
153
|
-
* @param context - Optional context (e.g., file name, operation)
|
|
154
|
-
*/
|
|
155
|
-
warn(message, context) {
|
|
156
|
-
const prefix = context ? `[${context}] ` : "";
|
|
157
|
-
process.stderr.write(chalk.yellow(`WARN: ${prefix}${message}
|
|
158
|
-
`));
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Logs an info message to stderr with blue coloring.
|
|
162
|
-
*
|
|
163
|
-
* @param message - Info message
|
|
164
|
-
*/
|
|
165
|
-
info(message) {
|
|
166
|
-
process.stderr.write(chalk.blue(`INFO: ${message}
|
|
167
|
-
`));
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Logs a debug message to stderr with gray coloring (only when verbose mode is enabled).
|
|
171
|
-
*
|
|
172
|
-
* @param message - Debug message
|
|
173
|
-
* @param context - Optional context
|
|
174
|
-
*/
|
|
175
|
-
debug(message, context) {
|
|
176
|
-
if (this.isVerbose()) {
|
|
177
|
-
const prefix = context ? `[${context}] ` : "";
|
|
178
|
-
process.stderr.write(chalk.gray(`[DEBUG] ${prefix}${message}
|
|
179
|
-
`));
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Reports all collected warnings to stderr with yellow coloring and clears them.
|
|
184
|
-
* Does nothing if there are no warnings.
|
|
185
|
-
*/
|
|
186
|
-
reportWarnings() {
|
|
187
|
-
const warnings = this.getWarnings();
|
|
188
|
-
if (warnings.length === 0) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
process.stderr.write(
|
|
192
|
-
chalk.yellow(`
|
|
193
|
-
\u26A0\uFE0F ${String(warnings.length)} warning(s):
|
|
194
|
-
`)
|
|
195
|
-
);
|
|
196
|
-
for (const warning of warnings) {
|
|
197
|
-
const prefix = warning.context ? `[${warning.context}] ` : "";
|
|
198
|
-
process.stderr.write(chalk.yellow(` - ${prefix}${warning.message}
|
|
199
|
-
`));
|
|
200
|
-
}
|
|
201
|
-
this.clearWarnings();
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
var logger2 = new CliLogger();
|
|
205
|
-
|
|
206
|
-
// src/utils/shell-config.ts
|
|
207
|
-
var START_MARKER = "# >>> hyntx config >>>";
|
|
208
|
-
var END_MARKER = "# <<< hyntx config <<<";
|
|
209
|
-
function findMarkerPositions(content) {
|
|
210
|
-
const startIndex = content.indexOf(START_MARKER);
|
|
211
|
-
const endIndex = content.indexOf(END_MARKER);
|
|
212
|
-
if (startIndex === -1 && endIndex === -1) {
|
|
213
|
-
return { startIndex: -1, endIndex: -1, isValid: true };
|
|
214
|
-
}
|
|
215
|
-
if (startIndex !== -1 && endIndex === -1) {
|
|
216
|
-
return { startIndex, endIndex: -1, isValid: false, issue: "missing_end" };
|
|
217
|
-
}
|
|
218
|
-
if (startIndex === -1 && endIndex !== -1) {
|
|
219
|
-
return { startIndex: -1, endIndex, isValid: false, issue: "missing_start" };
|
|
220
|
-
}
|
|
221
|
-
if (startIndex > endIndex) {
|
|
222
|
-
return { startIndex, endIndex, isValid: false, issue: "wrong_order" };
|
|
223
|
-
}
|
|
224
|
-
return { startIndex, endIndex, isValid: true };
|
|
225
|
-
}
|
|
226
|
-
function removeMalformedMarkers(content, positions) {
|
|
227
|
-
let result = content;
|
|
228
|
-
if (positions.issue === "wrong_order") {
|
|
229
|
-
const startLineEnd = result.indexOf("\n", positions.startIndex);
|
|
230
|
-
const before = result.slice(0, positions.endIndex);
|
|
231
|
-
const after = result.slice(
|
|
232
|
-
startLineEnd !== -1 ? startLineEnd + 1 : result.length
|
|
233
|
-
);
|
|
234
|
-
result = before.trimEnd() + (after ? "\n" + after : "");
|
|
235
|
-
} else {
|
|
236
|
-
const markerIndex = positions.startIndex !== -1 ? positions.startIndex : positions.endIndex;
|
|
237
|
-
const marker = positions.startIndex !== -1 ? START_MARKER : END_MARKER;
|
|
238
|
-
const lineStart = result.lastIndexOf("\n", markerIndex - 1) + 1;
|
|
239
|
-
const lineEnd = result.indexOf("\n", markerIndex + marker.length);
|
|
240
|
-
result = result.slice(0, lineStart) + result.slice(lineEnd !== -1 ? lineEnd + 1 : result.length);
|
|
241
|
-
}
|
|
242
|
-
return result.trimEnd();
|
|
243
|
-
}
|
|
244
|
-
function detectShellConfigFile() {
|
|
245
|
-
const home = homedir();
|
|
246
|
-
const shell = process.env["SHELL"] ?? "";
|
|
247
|
-
if (shell.includes("zsh")) {
|
|
248
|
-
return {
|
|
249
|
-
shellType: "zsh",
|
|
250
|
-
configFile: join(home, ".zshrc")
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
if (shell.includes("bash")) {
|
|
254
|
-
return {
|
|
255
|
-
shellType: "bash",
|
|
256
|
-
configFile: join(home, ".bashrc")
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
if (shell.includes("fish")) {
|
|
260
|
-
return {
|
|
261
|
-
shellType: "fish",
|
|
262
|
-
configFile: join(home, ".config", "fish", "config.fish")
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
const defaultShell = process.platform === "darwin" ? "zsh" : "bash";
|
|
266
|
-
return {
|
|
267
|
-
shellType: defaultShell,
|
|
268
|
-
configFile: join(home, `.${defaultShell}rc`)
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
function generateEnvExports(config) {
|
|
272
|
-
const lines = [];
|
|
273
|
-
if (config.services.length > 0) {
|
|
274
|
-
lines.push(`export HYNTX_SERVICES=${config.services.join(",")}`);
|
|
275
|
-
}
|
|
276
|
-
if (config.reminder) {
|
|
277
|
-
lines.push(`export HYNTX_REMINDER=${config.reminder}`);
|
|
278
|
-
}
|
|
279
|
-
if (config.services.includes("ollama")) {
|
|
280
|
-
if (config.ollama.model) {
|
|
281
|
-
lines.push(`export HYNTX_OLLAMA_MODEL=${config.ollama.model}`);
|
|
282
|
-
}
|
|
283
|
-
if (config.ollama.host) {
|
|
284
|
-
lines.push(`export HYNTX_OLLAMA_HOST=${config.ollama.host}`);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
if (config.services.includes("anthropic") && config.anthropic.apiKey) {
|
|
288
|
-
lines.push(`export HYNTX_ANTHROPIC_MODEL=${config.anthropic.model}`);
|
|
289
|
-
lines.push(`export HYNTX_ANTHROPIC_KEY=${config.anthropic.apiKey}`);
|
|
290
|
-
}
|
|
291
|
-
if (config.services.includes("google") && config.google.apiKey) {
|
|
292
|
-
lines.push(`export HYNTX_GOOGLE_MODEL=${config.google.model}`);
|
|
293
|
-
lines.push(`export HYNTX_GOOGLE_KEY=${config.google.apiKey}`);
|
|
294
|
-
}
|
|
295
|
-
return lines;
|
|
296
|
-
}
|
|
297
|
-
function updateShellConfig(configFile, exports$1) {
|
|
298
|
-
const exportLines = exports$1.map((line) => ` ${line}`).join("\n");
|
|
299
|
-
const configBlock = `${START_MARKER}
|
|
300
|
-
${exportLines}
|
|
301
|
-
|
|
302
|
-
# Uncomment to enable periodic reminders:
|
|
303
|
-
# hyntx --check-reminder 2>/dev/null
|
|
304
|
-
${END_MARKER}
|
|
305
|
-
`;
|
|
306
|
-
try {
|
|
307
|
-
let content = "";
|
|
308
|
-
let action = "created";
|
|
309
|
-
if (existsSync(configFile)) {
|
|
310
|
-
content = readFileSync(configFile, "utf-8");
|
|
311
|
-
action = "updated";
|
|
312
|
-
}
|
|
313
|
-
const positions = findMarkerPositions(content);
|
|
314
|
-
if (positions.startIndex === -1 && positions.endIndex === -1) {
|
|
315
|
-
const separator = content && !content.endsWith("\n") ? "\n\n" : "\n";
|
|
316
|
-
content = `${content}${separator}${configBlock}`;
|
|
317
|
-
} else if (positions.isValid) {
|
|
318
|
-
const before = content.slice(0, positions.startIndex);
|
|
319
|
-
const after = content.slice(positions.endIndex + END_MARKER.length);
|
|
320
|
-
const beforeTrimmed = before.endsWith("\n") ? before.slice(0, -1) : before;
|
|
321
|
-
content = `${beforeTrimmed}
|
|
322
|
-
${configBlock}${after}`.trim() + "\n";
|
|
323
|
-
} else {
|
|
324
|
-
logger2.collectWarning(
|
|
325
|
-
`Found malformed Hyntx block in ${configFile} (${positions.issue ?? "unknown"}). Rebuilding configuration.`,
|
|
326
|
-
"shell-config"
|
|
327
|
-
);
|
|
328
|
-
const cleanedContent = removeMalformedMarkers(content, positions);
|
|
329
|
-
const separator = cleanedContent && !cleanedContent.endsWith("\n") ? "\n\n" : "\n";
|
|
330
|
-
content = `${cleanedContent}${separator}${configBlock}`;
|
|
331
|
-
}
|
|
332
|
-
try {
|
|
333
|
-
mkdirSync(dirname(configFile), { recursive: true });
|
|
334
|
-
} catch (error) {
|
|
335
|
-
if (error instanceof Error && !error.message.includes("EEXIST") && !error.code?.includes("EEXIST")) {
|
|
336
|
-
logger2.debug(
|
|
337
|
-
`Directory creation note: ${error.message}`,
|
|
338
|
-
"shell-config"
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
writeFileSync(configFile, content, "utf-8");
|
|
343
|
-
try {
|
|
344
|
-
chmodSync(configFile, 384);
|
|
345
|
-
} catch (error) {
|
|
346
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
347
|
-
logger2.collectWarning(
|
|
348
|
-
`Could not set restrictive permissions on ${configFile}: ${errorMessage}`,
|
|
349
|
-
"shell-config"
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
return {
|
|
353
|
-
success: true,
|
|
354
|
-
shellFile: configFile,
|
|
355
|
-
message: `Configuration ${action === "created" ? "saved to" : "updated in"} ${configFile}`,
|
|
356
|
-
action
|
|
357
|
-
};
|
|
358
|
-
} catch (error) {
|
|
359
|
-
return {
|
|
360
|
-
success: false,
|
|
361
|
-
shellFile: configFile,
|
|
362
|
-
message: `Failed to update ${configFile}: ${error instanceof Error ? error.message : String(error)}`,
|
|
363
|
-
action: "failed"
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
function saveConfigToShell(config) {
|
|
368
|
-
const { configFile } = detectShellConfigFile();
|
|
369
|
-
const exports$1 = generateEnvExports(config);
|
|
370
|
-
return updateShellConfig(configFile, exports$1);
|
|
371
|
-
}
|
|
372
|
-
function getManualInstructions(config) {
|
|
373
|
-
const { configFile } = detectShellConfigFile();
|
|
374
|
-
const exports$1 = generateEnvExports(config);
|
|
375
|
-
const instructions = [
|
|
376
|
-
`Add this to your ${configFile}:`,
|
|
377
|
-
"",
|
|
378
|
-
...exports$1.map((line) => ` ${line}`),
|
|
379
|
-
"",
|
|
380
|
-
"# Uncomment to enable periodic reminders:",
|
|
381
|
-
"# hyntx --check-reminder 2>/dev/null",
|
|
382
|
-
"",
|
|
383
|
-
`Then reload your shell:`,
|
|
384
|
-
` source ${configFile}`
|
|
385
|
-
];
|
|
386
|
-
return instructions.join("\n");
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
export { detectShellConfigFile, findMarkerPositions, generateEnvExports, getManualInstructions, logger, logger2, removeMalformedMarkers, saveConfigToShell, updateShellConfig };
|