MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / inspect

Function inspect

packages/opencode-atomic-hooks/src/index.ts:16–56  ·  view source on GitHub ↗
(value: unknown, maxStringLen = 500, maxDepth = 6)

Source from the content-addressed store, hash-verified

14
15// DEBUG: Safe deep-inspect that handles circular refs + truncates big strings
16function inspect(value: unknown, maxStringLen = 500, maxDepth = 6): string {
17 const seen = new WeakSet();
18 function walk(v: unknown, depth: number): unknown {
19 if (depth > maxDepth) return "[max depth]";
20 if (v === null || v === undefined) return v;
21 if (typeof v === "string")
22 return v.length > maxStringLen
23 ? v.substring(0, maxStringLen) + `...[${v.length} chars]`
24 : v;
25 if (typeof v === "number" || typeof v === "boolean") return v;
26 if (typeof v === "function") return `[function ${v.name || "anonymous"}]`;
27 if (typeof v === "symbol") return v.toString();
28 if (typeof v === "bigint") return v.toString();
29 if (v instanceof Date) return v.toISOString();
30 if (v instanceof RegExp) return v.toString();
31 if (v instanceof Error)
32 return { name: v.name, message: v.message, stack: v.stack };
33 if (typeof v === "object") {
34 if (seen.has(v as object)) return "[circular]";
35 seen.add(v as object);
36 if (Array.isArray(v))
37 return v.length > 50
38 ? [
39 ...v.slice(0, 50).map((x) => walk(x, depth + 1)),
40 `...[${v.length} items]`,
41 ]
42 : v.map((x) => walk(x, depth + 1));
43 const out: Record<string, unknown> = {};
44 for (const key of Object.keys(v as Record<string, unknown>)) {
45 out[key] = walk((v as Record<string, unknown>)[key], depth + 1);
46 }
47 return out;
48 }
49 return String(v);
50 }
51 try {
52 return JSON.stringify(walk(value, 0), null, 2);
53 } catch {
54 return `[inspect error: ${typeof value}]`;
55 }
56}
57
58export const AtomicHooksPlugin: Plugin = async ({ $, directory }) => {
59 const ATOMIC = "atomic";

Callers 1

debugFunction · 0.85

Calls 1

walkFunction · 0.85

Tested by

no test coverage detected