@usevalt/cli 0.7.0 → 0.7.2
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/index.js +41 -106
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
-
}) : x)(function(x) {
|
|
5
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
2
|
|
|
9
3
|
// src/index.ts
|
|
10
4
|
import { Command as Command16 } from "commander";
|
|
@@ -254,7 +248,7 @@ function getEndpoint2() {
|
|
|
254
248
|
return process.env.VALT_ENDPOINT ?? "https://usevalt.com";
|
|
255
249
|
}
|
|
256
250
|
function sleep(ms) {
|
|
257
|
-
return new Promise((
|
|
251
|
+
return new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
258
252
|
}
|
|
259
253
|
async function openBrowser(url) {
|
|
260
254
|
try {
|
|
@@ -509,13 +503,13 @@ var doctorCommand = new Command5("doctor").description("Check Valt configuration
|
|
|
509
503
|
"UserPromptSubmit",
|
|
510
504
|
"SessionEnd"
|
|
511
505
|
];
|
|
512
|
-
const
|
|
506
|
+
const settingsPath = `${process.env["HOME"] ?? "~"}/.claude/settings.json`;
|
|
513
507
|
try {
|
|
514
508
|
const { existsSync: exists, readFileSync: read } = await import("fs");
|
|
515
|
-
if (exists(
|
|
516
|
-
const
|
|
517
|
-
const
|
|
518
|
-
const registeredHooks =
|
|
509
|
+
if (exists(settingsPath)) {
|
|
510
|
+
const settingsContent = read(settingsPath, "utf-8");
|
|
511
|
+
const settingsConfig = JSON.parse(settingsContent);
|
|
512
|
+
const registeredHooks = settingsConfig.hooks ?? {};
|
|
519
513
|
const presentHooks = EXPECTED_HOOKS.filter((name) => {
|
|
520
514
|
const hookEntries = registeredHooks[name];
|
|
521
515
|
return Array.isArray(hookEntries) && JSON.stringify(hookEntries).includes("valt");
|
|
@@ -1082,11 +1076,11 @@ async function readStdin() {
|
|
|
1082
1076
|
if (process.stdin.isTTY) return {};
|
|
1083
1077
|
try {
|
|
1084
1078
|
const chunks = [];
|
|
1085
|
-
const data = await new Promise((
|
|
1079
|
+
const data = await new Promise((resolve3) => {
|
|
1086
1080
|
process.stdin.setEncoding("utf-8");
|
|
1087
1081
|
process.stdin.on("data", (chunk) => chunks.push(String(chunk)));
|
|
1088
|
-
process.stdin.on("end", () =>
|
|
1089
|
-
setTimeout(() =>
|
|
1082
|
+
process.stdin.on("end", () => resolve3(chunks.join("")));
|
|
1083
|
+
setTimeout(() => resolve3(chunks.join("")), 500);
|
|
1090
1084
|
});
|
|
1091
1085
|
return data.trim() ? JSON.parse(data) : {};
|
|
1092
1086
|
} catch {
|
|
@@ -1214,28 +1208,33 @@ function classifyToolCall(toolName, toolInput) {
|
|
|
1214
1208
|
return { eventType: "tool.call" };
|
|
1215
1209
|
}
|
|
1216
1210
|
}
|
|
1217
|
-
function isTestCommand(command) {
|
|
1218
|
-
const testPatterns = [
|
|
1219
|
-
/\b(jest|vitest|mocha|ava)\b/,
|
|
1220
|
-
/\bpnpm\s+(test|t)\b/,
|
|
1221
|
-
/\bnpm\s+(test|t)\b/,
|
|
1222
|
-
/\bnpx\s+(jest|vitest)\b/,
|
|
1223
|
-
/\bpytest\b/,
|
|
1224
|
-
/\bpython\s+-m\s+pytest\b/,
|
|
1225
|
-
/\bcargo\s+test\b/,
|
|
1226
|
-
/\bgo\s+test\b/,
|
|
1227
|
-
/\bmake\s+test\b/
|
|
1228
|
-
];
|
|
1229
|
-
return testPatterns.some((p) => p.test(command));
|
|
1230
|
-
}
|
|
1231
1211
|
function parseTestResults(stdout) {
|
|
1232
|
-
const
|
|
1233
|
-
if (
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1212
|
+
const vitestFailFirst = stdout.match(/Tests\s+(\d+)\s+failed\s*\|\s*(\d+)\s+passed\s+\((\d+)\)/i);
|
|
1213
|
+
if (vitestFailFirst) {
|
|
1214
|
+
return {
|
|
1215
|
+
testsRun: parseInt(vitestFailFirst[3], 10),
|
|
1216
|
+
testsPassed: parseInt(vitestFailFirst[2], 10),
|
|
1217
|
+
testsFailed: parseInt(vitestFailFirst[1], 10),
|
|
1218
|
+
framework: "vitest"
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
const vitestAllPassed = stdout.match(/Tests\s+(\d+)\s+passed\s+\((\d+)\)/i);
|
|
1222
|
+
if (vitestAllPassed) {
|
|
1223
|
+
return {
|
|
1224
|
+
testsRun: parseInt(vitestAllPassed[2], 10),
|
|
1225
|
+
testsPassed: parseInt(vitestAllPassed[1], 10),
|
|
1226
|
+
testsFailed: 0,
|
|
1227
|
+
framework: "vitest"
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1230
|
+
const vitestAllFailed = stdout.match(/Tests\s+(\d+)\s+failed\s+\((\d+)\)/i);
|
|
1231
|
+
if (vitestAllFailed) {
|
|
1232
|
+
return {
|
|
1233
|
+
testsRun: parseInt(vitestAllFailed[2], 10),
|
|
1234
|
+
testsPassed: 0,
|
|
1235
|
+
testsFailed: parseInt(vitestAllFailed[1], 10),
|
|
1236
|
+
framework: "vitest"
|
|
1237
|
+
};
|
|
1239
1238
|
}
|
|
1240
1239
|
const jestMatch = stdout.match(/Tests:\s+(?:(\d+)\s+failed,\s+)?(\d+)\s+passed,\s+(\d+)\s+total/i);
|
|
1241
1240
|
if (jestMatch) {
|
|
@@ -1452,16 +1451,6 @@ var toolCallCommand = new Command13("tool-call").description("Hook: called on ea
|
|
|
1452
1451
|
...command ? { command } : {}
|
|
1453
1452
|
}
|
|
1454
1453
|
});
|
|
1455
|
-
if (eventType === "command.execute" && command && isTestCommand(command)) {
|
|
1456
|
-
events.push({
|
|
1457
|
-
event_id: crypto.randomUUID(),
|
|
1458
|
-
session_id: session.sessionId,
|
|
1459
|
-
event_type: "test.run",
|
|
1460
|
-
timestamp,
|
|
1461
|
-
tool: "claude-code",
|
|
1462
|
-
metadata: { command, source: "pre-tool-detect" }
|
|
1463
|
-
});
|
|
1464
|
-
}
|
|
1465
1454
|
}
|
|
1466
1455
|
await sendEvents(session.endpoint, session.apiKey, events);
|
|
1467
1456
|
} catch {
|
|
@@ -1924,66 +1913,12 @@ function removeHooks() {
|
|
|
1924
1913
|
|
|
1925
1914
|
// src/commands/start.ts
|
|
1926
1915
|
import { Command as Command15 } from "commander";
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
}],
|
|
1934
|
-
PreToolCall: [{
|
|
1935
|
-
matcher: ".*",
|
|
1936
|
-
hooks: [{ type: "command", command: "echo '{}' | npx @usevalt/cli hook tool-call" }]
|
|
1937
|
-
}],
|
|
1938
|
-
Stop: [{
|
|
1939
|
-
hooks: [{ type: "command", command: "npx @usevalt/cli hook session-end" }]
|
|
1940
|
-
}]
|
|
1941
|
-
};
|
|
1942
|
-
var startCommand = new Command15("start").description("Configure Valt for Claude Code in the current project").action(() => {
|
|
1943
|
-
try {
|
|
1944
|
-
const apiKey = getApiKey();
|
|
1945
|
-
if (!apiKey) {
|
|
1946
|
-
error("No API key found. Set VALT_API_KEY or run `valt login` first.");
|
|
1947
|
-
process.exit(1);
|
|
1948
|
-
}
|
|
1949
|
-
const claudeDir = resolve3(process.cwd(), ".claude");
|
|
1950
|
-
if (!existsSync5(claudeDir)) {
|
|
1951
|
-
warn("No .claude/ directory found. This command is designed for Claude Code projects.");
|
|
1952
|
-
info("Creating .claude/ directory...");
|
|
1953
|
-
const { mkdirSync: mkdirSync3 } = __require("fs");
|
|
1954
|
-
mkdirSync3(claudeDir, { recursive: true });
|
|
1955
|
-
}
|
|
1956
|
-
const hooksFile = resolve3(process.cwd(), HOOKS_PATH);
|
|
1957
|
-
let existingHooks = {};
|
|
1958
|
-
if (existsSync5(hooksFile)) {
|
|
1959
|
-
try {
|
|
1960
|
-
existingHooks = JSON.parse(readFileSync5(hooksFile, "utf-8"));
|
|
1961
|
-
info("Found existing hooks.json -- merging Valt hooks.");
|
|
1962
|
-
} catch {
|
|
1963
|
-
warn("Existing hooks.json is not valid JSON. Creating a new one.");
|
|
1964
|
-
existingHooks = {};
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
1967
|
-
const hooks = existingHooks.hooks ?? {};
|
|
1968
|
-
for (const [event, valtEntries] of Object.entries(VALT_HOOKS)) {
|
|
1969
|
-
const existing = hooks[event];
|
|
1970
|
-
const hasValt = existing?.some(
|
|
1971
|
-
(entry) => entry.hooks?.some((h) => h.command?.includes("@usevalt/cli"))
|
|
1972
|
-
);
|
|
1973
|
-
if (hasValt) {
|
|
1974
|
-
continue;
|
|
1975
|
-
}
|
|
1976
|
-
hooks[event] = [...existing ?? [], ...valtEntries];
|
|
1977
|
-
}
|
|
1978
|
-
const merged = { ...existingHooks, hooks };
|
|
1979
|
-
writeFileSync5(hooksFile, JSON.stringify(merged, null, 2) + "\n", "utf-8");
|
|
1980
|
-
success("Valt is configured.");
|
|
1981
|
-
info(`Hooks written to ${bold(HOOKS_PATH)}`);
|
|
1982
|
-
info("Start a Claude Code session and your work will be tracked automatically.");
|
|
1983
|
-
} catch (err) {
|
|
1984
|
-
error(`Failed to configure: ${err instanceof Error ? err.message : String(err)}`);
|
|
1985
|
-
process.exit(1);
|
|
1986
|
-
}
|
|
1916
|
+
var startCommand = new Command15("start").description("Configure Valt for Claude Code (deprecated \u2014 use `valt setup`)").action(() => {
|
|
1917
|
+
warn("`valt start` is deprecated. Use `valt setup` instead.");
|
|
1918
|
+
info("Run: valt setup");
|
|
1919
|
+
info("");
|
|
1920
|
+
info("This configures hooks in ~/.claude/settings.json where Claude Code reads them.");
|
|
1921
|
+
process.exit(0);
|
|
1987
1922
|
});
|
|
1988
1923
|
|
|
1989
1924
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usevalt/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Valt CLI — trust layer for AI-assisted development",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"tsup": "^8.4.0",
|
|
40
40
|
"typescript": "^5.7.0",
|
|
41
41
|
"vitest": "^3.2.0",
|
|
42
|
-
"@usevalt/
|
|
43
|
-
"@usevalt/
|
|
42
|
+
"@usevalt/eslint-config": "0.0.0",
|
|
43
|
+
"@usevalt/typescript-config": "0.0.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsup",
|