-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
executable file
·80 lines (71 loc) · 2.34 KB
/
index.ts
File metadata and controls
executable file
·80 lines (71 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bun
import { show } from "./src/commands/show";
import { sessions } from "./src/commands/sessions";
import type { ParsedArgs, ShowOptions, SessionsOptions } from "./src/types";
function parseArgs(argv: string[]): ParsedArgs {
const args = argv.slice(2); // skip bun and script path
const command = args[0] || "help";
const positional: string[] = [];
const flags: Record<string, string | boolean> = {};
for (let i = 1; i < args.length; i++) {
const arg = args[i];
if (arg.startsWith("--no-")) {
flags[arg.slice(2)] = true; // "no-tools" → true
} else if (arg.startsWith("--")) {
const key = arg.slice(2);
const next = args[i + 1];
if (next && !next.startsWith("--")) {
flags[key] = next;
i++;
} else {
flags[key] = true;
}
} else {
positional.push(arg);
}
}
return { command, positional, flags };
}
const USAGE = `Usage:
claude-query show <sessionId> View a session conversation
--type user|assistant Filter by message type
--no-tools Hide tool_use/tool_result blocks
--no-system Hide system messages
--compact Truncate long tool results
claude-query sessions List recent sessions
--project <name> Filter by project name
--limit <n> Max results (default 20)`;
async function main() {
const parsed = parseArgs(Bun.argv);
switch (parsed.command) {
case "show": {
const sessionId = parsed.positional[0];
if (!sessionId) {
console.error("Error: session ID required\n\n" + USAGE);
process.exit(1);
}
const options: ShowOptions = {
type: parsed.flags.type as ShowOptions["type"],
noTools: !!parsed.flags["no-tools"],
noSystem: !!parsed.flags["no-system"],
compact: !!parsed.flags.compact,
};
console.log(await show(sessionId, options));
break;
}
case "sessions": {
const options: SessionsOptions = {
project: parsed.flags.project as string | undefined,
limit: Number(parsed.flags.limit) || 20,
};
console.log(await sessions(options));
break;
}
default:
console.log(USAGE);
}
}
main().catch((err) => {
console.error(`Error: ${err.message}`);
process.exit(1);
});