grokbox 0.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 +34 -0
- package/bin/grok-bot +2 -0
- package/package.json +34 -0
- package/skills/core.md +81 -0
- package/src/commands/agents.ts +110 -0
- package/src/commands/doctor.ts +50 -0
- package/src/commands/events.ts +123 -0
- package/src/commands/history.ts +65 -0
- package/src/commands/is.ts +23 -0
- package/src/commands/memory.ts +47 -0
- package/src/commands/roster.ts +11 -0
- package/src/commands/send.ts +72 -0
- package/src/deps.ts +49 -0
- package/src/errors.ts +132 -0
- package/src/gateway.ts +421 -0
- package/src/index.ts +6 -0
- package/src/opts.ts +52 -0
- package/src/output.ts +58 -0
- package/src/program.ts +213 -0
- package/src/redaction.ts +130 -0
- package/src/registry.ts +202 -0
- package/src/skills.ts +55 -0
- package/src/util.ts +59 -0
package/src/util.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { usage } from "./errors.ts";
|
|
2
|
+
|
|
3
|
+
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
4
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function parseInteger(
|
|
8
|
+
raw: unknown,
|
|
9
|
+
spec: { name: string; min: number; max: number; defaultValue?: number },
|
|
10
|
+
): number {
|
|
11
|
+
if (raw === undefined || raw === null || raw === "") {
|
|
12
|
+
if (spec.defaultValue !== undefined) return spec.defaultValue;
|
|
13
|
+
throw usage(`${spec.name} is required.`);
|
|
14
|
+
}
|
|
15
|
+
const n = typeof raw === "number" ? raw : Number.parseInt(String(raw), 10);
|
|
16
|
+
if (!Number.isInteger(n) || n < spec.min || n > spec.max) {
|
|
17
|
+
throw usage(`${spec.name} must be an integer between ${spec.min} and ${spec.max}.`);
|
|
18
|
+
}
|
|
19
|
+
return n;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function emptyToNull(value: unknown): string | null {
|
|
23
|
+
if (typeof value !== "string") return null;
|
|
24
|
+
return value.length === 0 ? null : value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function asBoolean(value: unknown): boolean {
|
|
28
|
+
return value === true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function asNumber(value: unknown, fallback = 0): number {
|
|
32
|
+
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function asString(value: unknown, fallback = ""): string {
|
|
36
|
+
return typeof value === "string" ? value : fallback;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function stripOneTrailingNewline(text: string): string {
|
|
40
|
+
if (text.endsWith("\r\n")) return text.slice(0, -2);
|
|
41
|
+
if (text.endsWith("\n")) return text.slice(0, -1);
|
|
42
|
+
return text;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const UUID_V4 =
|
|
46
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
47
|
+
|
|
48
|
+
export function assertUuidV4(value: string, name: string): string {
|
|
49
|
+
if (!UUID_V4.test(value)) throw usage(`${name} must be a UUID v4.`);
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function utf8Bytes(text: string): number {
|
|
54
|
+
return new TextEncoder().encode(text).byteLength;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function containsSensitiveLeak(haystack: string, secrets: string[]): boolean {
|
|
58
|
+
return secrets.some((secret) => secret.length > 0 && haystack.includes(secret));
|
|
59
|
+
}
|