text
stringlengths
3
8.33k
repo
stringclasses
52 values
path
stringlengths
6
141
language
stringclasses
35 values
sha
stringlengths
64
64
chunk_index
int32
0
273
n_tokens
int32
1
896
export { getKnowledgeBlockForScan } from "./injector"; export * from "./store"; export * from "./types";
clawguard
lib/knowledge/index.ts
TypeScript
2aaed55b9c31266b164f6a43fe7268ba3f841737bd1276d0e2df67c29f8f93ff
0
29
import type { ClawGuardConfig } from "@/lib/config/schemas"; import { formatKnowledgeForPrompt, listKnowledgeOrg } from "./store"; export async function getKnowledgeBlockForScan( owner: string, config: ClawGuardConfig, ): Promise<string> { if (!config.learnings.enabled || !config.learnings.allowOrgInheritance) {...
clawguard
lib/knowledge/injector.ts
TypeScript
46353b1af6650be4fd75349967a1263c38f4dc2f1a9af901cafa2915fbc8440b
0
124
import { redis } from "@/lib/redis"; import type { KnowledgeEntry } from "./types"; import { KnowledgeEntrySchema } from "./types"; function orgKey(owner: string): string { return `knowledge:org:${owner}`; } async function readList(key: string): Promise<KnowledgeEntry[]> { const raw = await redis.get<unknown>(key...
clawguard
lib/knowledge/store.ts
TypeScript
aaea2e855b80c9d07d3c55cac4e14682afc3c3980eeae4c6a3ebe609bef4f21b
0
478
import { z } from "zod"; export const KnowledgeCategorySchema = z.enum(["pattern", "anti-pattern", "adr"]); export type KnowledgeCategory = z.infer<typeof KnowledgeCategorySchema>; export const KnowledgeEntrySchema = z.object({ id: z.string(), category: KnowledgeCategorySchema, title: z.string(), body: z.stri...
clawguard
lib/knowledge/types.ts
TypeScript
7e51fe245b1e184b9fa5a86036671a5cf90860fe01a140f1d500436145ec6d5b
0
143
import { gateway } from "@ai-sdk/gateway"; import { generateObject } from "ai"; import { z } from "zod"; import type { LearningAction } from "./types"; const ExtractSchema = z.object({ pattern: z.string(), context: z.string(), action: z.enum(["prefer", "suppress", "escalate"]), }); const MODEL = process.env.CLA...
clawguard
lib/learnings/extractor.ts
TypeScript
7ec9f36ed5c344618ea1da02464d738c3fec24c5d33a18d49d4e1641c6b0898d
0
382
export * from "./extractor"; export { getLearningsBlockForScan } from "./injector"; export * from "./store"; export * from "./types";
clawguard
lib/learnings/index.ts
TypeScript
32c44ee3344eecaedcb2ca9e487471ef221bfe34fae75fa9614b840934626067
0
38
import type { ClawGuardConfig } from "@/lib/config/schemas"; import { formatLearningsForPrompt, listLearningsOrg, listLearningsRepo } from "./store"; export async function getLearningsBlockForScan( owner: string, repo: string, config: ClawGuardConfig, ): Promise<string> { if (!config.learnings.enabled) return ...
clawguard
lib/learnings/injector.ts
TypeScript
7c2f46ec2e3b8bc6105d80b1d8917dbde03a7d2cb922b9dd3001c8f5011ff500
0
148
import { redis } from "@/lib/redis"; import type { Learning } from "./types"; import { LearningSchema } from "./types"; function repoKey(owner: string, repo: string): string { return `learnings:${owner}/${repo}`; } function orgKey(owner: string): string { return `learnings:org:${owner}`; } async function readLis...
clawguard
lib/learnings/store.ts
TypeScript
3830e467bbdc34111f66371964310cc8fc663386a2cd382bba630e614747e2dd
0
735
import { z } from "zod"; export const LearningActionSchema = z.enum(["prefer", "suppress", "escalate"]); export type LearningAction = z.infer<typeof LearningActionSchema>; export const LearningSchema = z.object({ id: z.string(), pattern: z.string(), context: z.string(), action: LearningActionSchema, sourceP...
clawguard
lib/learnings/types.ts
TypeScript
25280a4835aabcb8ca6141937f0d3718d9ef7c31cc95590c1fed7de4f26b4856
0
186
/** * OSV API client (https://google.github.io/osv.dev/) */ export interface OsvPackageQuery { name: string; version: string; ecosystem: string; } export interface OsvVulnSummary { id: string; summary?: string; modified?: string; /** Severity strings when present in OSV */ severity?: Array<{ type?: ...
clawguard
lib/osv/client.ts
TypeScript
1b2269fe40acff91c21e49eff1110853fb377636ec7ba88f5701fb7b10e49fe2
0
272
import { gateway } from "@ai-sdk/gateway"; import { embed, embedMany } from "ai"; export interface CodeChunk { fileId: number; filePath: string; startLine: number; endLine: number; content: string; } const CHUNK_SIZE = 50; // lines per chunk const CHUNK_OVERLAP = 10; // overlap between chunks export functi...
clawguard
lib/rag/embedder.ts
TypeScript
c39bd29689036f1dc4699be0b818be464d8f2dd55a1ca9d40db9f6fb2338368c
0
437
import type { CodeChunk } from "./embedder"; export interface IndexEntry { chunk: CodeChunk; embedding: Float32Array; } export interface SearchHit { chunk: CodeChunk; score: number; } /** Dimensions used for coarse dot-product pre-ranking (ANN-style pruning). */ const COARSE_DIM = 64; const CANDIDATE_MULTIPL...
clawguard
lib/rag/index.ts
TypeScript
4f5ebff30d32c1d72a28b373003f51d35ac225223638e0c05be7317b827fe7cd
0
728
import type { Sandbox } from "@vercel/sandbox"; import { logAudit } from "@/lib/logger"; import type { CodeChunk } from "./embedder"; import { chunkFileContent, embedChunks, embedQuery } from "./embedder"; import { type SearchHit, VectorIndex } from "./index"; const SKIP_EXTENSIONS = new Set([ ".png", ".jpg", "....
clawguard
lib/rag/retriever.ts
TypeScript
2db96d1ed385e0e7c0820cb3a106d10d0afec963c6d6ab229f9ba6689df00e43
0
665
import { z } from "zod"; import { ToolError } from "@/lib/errors"; import type { SandboxToolDefinition } from "@/lib/tools/types"; import { retrieveContext } from "./retriever"; const SemanticSearchInputSchema = z.object({ query: z.string().min(1).max(2000), topK: z.number().int().min(1).max(50).default(10), }); ...
clawguard
lib/rag/tool.ts
TypeScript
78484a1d47091754daa7c72419fea4b7fe89ce183dd6ad9aa056e7bfa3dcbfb7
0
401
import type { FindingCategory } from "@/lib/analysis/types"; export function categoryLabel(c: FindingCategory): string { switch (c) { case "security": return "Security"; case "quality": return "Quality"; case "architecture": return "Architecture"; case "testing": return "Tests...
clawguard
lib/report/category-labels.ts
TypeScript
c5bfaf48d5f54cea47eb6f74684a704ad6e4b156a23a9de539d02cf42e28f6e2
0
99
export { injectSkills } from "./injector"; export { loadAllSkills, loadSkillById, loadSkillsForAgent } from "./loader"; export type { SkillDefinition, SkillDomain } from "./types";
clawguard
lib/skills/index.ts
TypeScript
cfe28409e8b6badd9610a1966bd6f2fc5f1ba0f4dfda6e3480c7546dc76fd9c3
0
40
import { loadSkillsForAgent } from "@/lib/skills/loader"; const MAX_SKILL_TOKENS_ESTIMATE = 12_000; const AVG_CHARS_PER_TOKEN = 4; export function injectSkills( baseInstructions: string, agentName: string, requestedSkillIds?: string[], ): string { let skills = loadSkillsForAgent(agentName); if (requestedSk...
clawguard
lib/skills/injector.ts
TypeScript
f85eaca25158b3cadc44117a70a33cf2589f0131a1cb1650d39b8259c4987f9e
0
219
import { apiSecurity } from "@/lib/skills/definitions/api-security"; import { architecturePatterns } from "@/lib/skills/definitions/architecture-patterns"; import { codeQuality } from "@/lib/skills/definitions/code-quality"; import { codeSmellsCatalog } from "@/lib/skills/definitions/code-smells-catalog"; import { cvss...
clawguard
lib/skills/loader.ts
TypeScript
66ccaba19ffb34f2f83a3da4f5b12785b9141610b5d51d721117a63722bf2170
0
501
export interface SkillDefinition { id: string; name: string; domain: SkillDomain; /** Agent names this skill applies to, or "*" for all */ applicableTo: string[]; priority: number; /** The instruction content injected into agent prompts */ content: string; } export type SkillDomain = | "security" |...
clawguard
lib/skills/types.ts
TypeScript
406b7438b6744a1138a158ce896d75458efa506161f97498b63701e1aaee0dd4
0
136
import type { SkillDefinition } from "@/lib/skills/types"; export const apiSecurity: SkillDefinition = { id: "api-security", name: "API & Route Handler Security", domain: "api", applicableTo: ["api-security"], priority: 1, content: `Review HTTP APIs (REST, GraphQL, RPC) as a single auth and validation surf...
clawguard
lib/skills/definitions/api-security.ts
TypeScript
e5e30858b008b6842e46c66aba52eefc7f90365f6c790742e2604e80b4f08f82
0
418
import type { SkillDefinition } from "@/lib/skills/types"; export const architecturePatterns: SkillDefinition = { id: "architecture-patterns", name: "Architecture patterns and anti-patterns", domain: "architecture", applicableTo: ["architecture", "*"], priority: 2, content: `Good: clear module boundaries, ...
clawguard
lib/skills/definitions/architecture-patterns.ts
TypeScript
56bf375d3578af90307136b24f40e7ffe7f661e49a5624f6e06133ba8b3adf2c
0
124
import type { SkillDefinition } from "@/lib/skills/types"; export const codeQuality: SkillDefinition = { id: "code-quality", name: "Code Quality for Security", domain: "code-quality", applicableTo: ["security-scan", "*"], priority: 2, content: `Treat code-quality issues as security signals when they hide f...
clawguard
lib/skills/definitions/code-quality.ts
TypeScript
692948501e05b345467eec4a3dfd8fc1e1134e06e9150fff17020458a9792ebe
0
376
import type { SkillDefinition } from "@/lib/skills/types"; export const codeSmellsCatalog: SkillDefinition = { id: "code-smells", name: "Code smells catalogue", domain: "code-quality", applicableTo: ["code-quality", "*"], priority: 2, content: `Smells: long method, large class, feature envy, data clumps, p...
clawguard
lib/skills/definitions/code-smells-catalog.ts
TypeScript
78f751224c0f47605851f9c25dad0865c61293783bd0efc7e22cb6808f31061b
0
127
import type { SkillDefinition } from "@/lib/skills/types"; export const cvssScoring: SkillDefinition = { id: "cvss-scoring", name: "CVSS v3.1 scoring", domain: "cvss", applicableTo: ["security-scan", "dependency-audit", "*"], priority: 3, content: `CVSS v3.1 base score combines Attack Vector (N/A/L/P), Att...
clawguard
lib/skills/definitions/cvss-scoring.ts
TypeScript
c293413ea5d7821572da1acf251e0b36125693b81d6e28461c19327f9e9b6844
0
165
import type { SkillDefinition } from "@/lib/skills/types"; export const dependencyAudit: SkillDefinition = { id: "dependency-audit", name: "Dependency & Supply-Chain Audit", domain: "dependency", applicableTo: ["dependency-audit"], priority: 1, content: `Prioritize exploitable dependency risk over raw vers...
clawguard
lib/skills/definitions/dependency-audit.ts
TypeScript
fe5e9fdf2b048e0fd9f5ce0861cc07aa8e0f572f555e9ad056e0989b44269acc
0
361
import type { SkillDefinition } from "@/lib/skills/types"; export const gitDiffReading: SkillDefinition = { id: "git-diff-reading", name: "Reading unified diffs", domain: "diff-reading", applicableTo: ["pr-summary", "code-quality", "*"], priority: 2, content: `Unified diff: lines with leading + are additio...
clawguard
lib/skills/definitions/git-diff-reading.ts
TypeScript
7e12615ce0157cf634c40dea75aacbf53b07045b5fccc057c96f01a169af4d5a
0
150
import type { SkillDefinition } from "@/lib/skills/types"; export const infrastructureReview: SkillDefinition = { id: "infrastructure-review", name: "Infrastructure & CI/CD Security", domain: "infrastructure", applicableTo: ["infrastructure-review"], priority: 1, content: `Dockerfiles: Prefer non-root \`US...
clawguard
lib/skills/definitions/infrastructure-review.ts
TypeScript
115b69dbe14da67370708928af1f1d8566cc07988544428e9a4de6ceb079e71c
0
380
import type { SkillDefinition } from "@/lib/skills/types"; export const orchestration: SkillDefinition = { id: "orchestration", name: "Multi-Agent Orchestration", domain: "orchestration", applicableTo: ["orchestrator"], priority: 1, content: `Decompose the security review into parallel workstreams after sh...
clawguard
lib/skills/definitions/orchestration.ts
TypeScript
f5ce176d069cf32d982e34369df17ed1b97c7a50e34b1f00181c64733974b79b
0
280
import type { SkillDefinition } from "@/lib/skills/types"; export const owaspWebSecurity: SkillDefinition = { id: "owasp-web-security", name: "OWASP Web Security (Top 10 2021)", domain: "security", applicableTo: ["security-scan", "api-security", "*"], priority: 1, content: `Use OWASP Top 10 2021 as the pri...
clawguard
lib/skills/definitions/owasp-web-security.ts
TypeScript
917ec871897e1dd917d175ae960d02042bfc579982a6601942c9ebada9c5b3d5
0
472
import type { SkillDefinition } from "@/lib/skills/types"; export const pentestMethodology: SkillDefinition = { id: "pentest-methodology", name: "Pentest Methodology (Evidence-Driven)", domain: "pentest", applicableTo: ["pentest"], priority: 1, content: `Operate in explicit rounds; each round must produce ...
clawguard
lib/skills/definitions/pentest-methodology.ts
TypeScript
37fd819ec5affa0063f206e18c7bd7ed5929c06a3e8b1c1757deb14229f6c4e8
0
375
import type { SkillDefinition } from "@/lib/skills/types"; export const performancePatterns: SkillDefinition = { id: "performance-patterns", name: "Performance patterns", domain: "performance", applicableTo: ["performance", "*"], priority: 2, content: `Watch for N+1 queries, missing pagination, unbounded l...
clawguard
lib/skills/definitions/performance-patterns.ts
TypeScript
7802ed1b8213f516c733194648737179d920eb716d2c6f66f1d3cd4b3ce22c5b
0
120
import type { SkillDefinition } from "@/lib/skills/types"; export const prReviewTone: SkillDefinition = { id: "pr-review-tone", name: "PR review tone", domain: "review-tone", applicableTo: ["documentation", "learnings", "pr-summary", "*"], priority: 1, content: `Review comments must be constructive and spe...
clawguard
lib/skills/definitions/pr-review-tone.ts
TypeScript
407ad005ada59eb7fbee38a376a5c9524756cc9d04a6cd9a8b9b946d5f0e15e0
0
137
import type { SkillDefinition } from "@/lib/skills/types"; export const reporting: SkillDefinition = { id: "reporting", name: "Security Report Structure", domain: "reporting", applicableTo: ["*"], priority: 10, content: `Every confirmed finding MUST include: severity (CRITICAL/HIGH/MEDIUM/LOW); concise typ...
clawguard
lib/skills/definitions/reporting.ts
TypeScript
7a37820f2dd5682888ce7dddfb9e54e13266eb7be2fbce2a01f4b8fdcb0f2020
0
327
import type { SkillDefinition } from "@/lib/skills/types"; export const secretScanning: SkillDefinition = { id: "secret-scanning", name: "Secret Scanning & Entropy Heuristics", domain: "secrets", applicableTo: ["secret-scanner"], priority: 1, content: `Detect high-entropy strings and provider-shaped tokens...
clawguard
lib/skills/definitions/secret-scanning.ts
TypeScript
d38265395788f3764858dd6d765e2b83ac301ab25f45fc4307b2477651515674
0
597
import type { SkillDefinition } from "@/lib/skills/types"; export const secureCodePatterns: SkillDefinition = { id: "secure-code-patterns", name: "Secure coding patterns", domain: "security", applicableTo: ["security-scan", "api-security", "*"], priority: 2, content: `Prefer parameterized queries/ORM bindi...
clawguard
lib/skills/definitions/secure-code-patterns.ts
TypeScript
12172c8159a39dd3a0099beceee25be1ce73978d30aef304e0ddddacfc3c9ad5
0
134
import type { SkillDefinition } from "@/lib/skills/types"; export const testWriting: SkillDefinition = { id: "test-writing", name: "Meaningful tests", domain: "testing", applicableTo: ["test-coverage", "*"], priority: 2, content: `Tests should follow arrange–act–assert, cover edge cases and error paths, us...
clawguard
lib/skills/definitions/test-writing.ts
TypeScript
d8847307c34ab06cf8fb2f28d529d8704751449a37954c61421624632e33885d
0
117
import type { Sandbox } from "@vercel/sandbox"; import { tool } from "ai"; import { z } from "zod"; import type { AgentContext } from "@/lib/agents/types"; import { parseUnifiedDiff } from "@/lib/analysis/parse-diff"; import { appendLearningRepo, listLearningsOrg, listLearningsRepo } from "@/lib/learnings"; import type...
clawguard
lib/tools/agent-tools.ts
TypeScript
650755e3d623982bbe9f0bfb22ee0fb027b7eb14af9f721e0f516a2070ed2647
0
896
"Scan a unified diff for high-entropy strings and known secret patterns (AWS, GitHub, Stripe, etc.).", inputSchema: z.object({ diff: z.string(), }), execute: async ({ diff }) => { const hits = scanDiffForSecrets(diff); return { ok: true as const, hits, count: hits.length }; }, }); ...
clawguard
lib/tools/agent-tools.ts
TypeScript
d102a50e0379a607cc7dfef6d190c23373f0f5d9b174f6f2b27b68c6a0758502
1
896
repo; if (!owner || !repo) { return { ok: false, error: "owner/repo not set on agent context" }; } const row = await appendLearningRepo(owner, repo, { pattern, context: ctxText, action: action as LearningAction, confidence, }); return { ok: true as c...
clawguard
lib/tools/agent-tools.ts
TypeScript
1e1f0d8aa4e54574806be2c77e41f79f25a651f587d2ce6e85eceb8ea9a7360b
2
112
import { z } from "zod"; import { ToolError } from "@/lib/errors"; import type { SandboxToolDefinition } from "./types"; const BLOCKED_PATTERNS = [ /rm\s+(-[rfRF]+\s+)?\/(?!tmp)/, /mkfs\./, /dd\s+.*of=\/dev/, />\s*\/dev\/sd/, /shutdown|reboot|halt|poweroff/, ]; const NETWORK_COMMANDS = /\b(curl|wget|nc|ncat...
clawguard
lib/tools/bash.ts
TypeScript
7705a540ee9e243915d69407d2663554629c7d6bbc1a2c3af7602ddb9b6aa1a6
0
483
import path from "node:path"; export interface ModuleNode { file: string; imports: string[]; importedBy: string[]; } export interface DepGraphResult { nodes: ModuleNode[]; circularChains: string[][]; fanOut: Record<string, number>; } function normalizeImport(fromFile: string, spec: string): string { if...
clawguard
lib/tools/dep-graph.ts
TypeScript
29ab2339252fa38beefdf1b072a90c4313a019d9a9c2fe25da76d79cc4a66603
0
896
"]+)['"]\s*\)/g; let m: RegExpExecArray | null; m = importRe.exec(source); while (m !== null) { if (m[1]) specs.add(m[1]); m = importRe.exec(source); } m = dynImportRe.exec(source); while (m !== null) { if (m[1]) specs.add(m[1]); m = dynImportRe.exec(source); } m = requireRe.exec(source)...
clawguard
lib/tools/dep-graph.ts
TypeScript
512bee57799673abd70a5c976506fe414e3d942af55bfba26f926a5eb383b108
1
167
import { z } from "zod"; import { ToolError } from "@/lib/errors"; import type { SandboxToolDefinition } from "./types"; const MAX_FILE_SIZE = 512_000; const FileReadInputSchema = z.object({ path: z.string().min(1).max(1000), startLine: z.number().int().min(1).optional(), endLine: z.number().int().min(1).option...
clawguard
lib/tools/file-read.ts
TypeScript
813bbbd1f795de516456013a2b6f3e45516c1e347999a2fb88cae14a75e7db25
0
510
import { z } from "zod"; import { ToolError } from "@/lib/errors"; import type { SandboxToolDefinition } from "./types"; const FileSearchInputSchema = z.object({ pattern: z.string().min(1).max(2000), fileGlob: z.string().optional(), maxResults: z.number().int().min(1).max(500).default(50), caseSensitive: z.boo...
clawguard
lib/tools/file-search.ts
TypeScript
f4b2ae79eba889ad4fdef98c43845c44b42bc914f5717559951e3c0a0dfd426e
0
819
import { z } from "zod"; import { ToolError } from "@/lib/errors"; import { registerRepoSearchOverlay } from "@/lib/tools/search/overlay"; import type { SandboxToolDefinition } from "./types"; const FileWriteInputSchema = z.object({ path: z.string().min(1).max(1000), content: z.string(), }); export const fileWrit...
clawguard
lib/tools/file-write.ts
TypeScript
37430891ef70cf861947ce697338379ef799650cedd662a44ade3169e7f050e5
0
442
import type { DepGraphResult } from "./dep-graph"; export type DiagramKind = "dependency" | "sequence"; export function mermaidDependencyGraph(graph: DepGraphResult, title?: string): string { const lines: string[] = ["graph LR"]; if (title) { lines.push(` title["${title.replace(/"/g, "'")}"]`); } const s...
clawguard
lib/tools/generate-diagram.ts
TypeScript
4936403160900ed43de7dd5faab087c73f826a5128e1282b8ea3bd980d299b75
0
510
export { semanticSearchTool } from "@/lib/rag/tool"; export { bashTool } from "./bash"; export { fileReadTool } from "./file-read"; export { fileSearchTool } from "./file-search"; export { fileWriteTool } from "./file-write"; export { getToolRegistry, ToolRegistry } from "./registry"; export { buildSearchIndex, ext...
clawguard
lib/tools/index.ts
TypeScript
3af3803dcb7da73e804702e4bb5e052bd08e4c7e458e904a6614d3f67f32442b
0
166
import type { Sandbox } from "@vercel/sandbox"; import { ToolError } from "@/lib/errors"; import { semanticSearchTool } from "@/lib/rag/tool"; import { bashCommandUsesNetwork, bashTool } from "./bash"; import { fileReadTool } from "./file-read"; import { fileSearchTool } from "./file-search"; import { fileWriteTool } ...
clawguard
lib/tools/registry.ts
TypeScript
3861ef7161d2cbccbbbf2f72834d554664afe5f3b9ea4013fbd903371ca3f31c
0
887
/** * Entropy + pattern-based secret hints for diffs (no ML). */ const HIGH_ENTROPY_MIN_LEN = 24; const BASE64_RE = /^[A-Za-z0-9+/=/_-]{24,}$/; const PATTERNS: Array<{ id: string; re: RegExp; label: string }> = [ { id: "aws_access", re: /AKIA[0-9A-Z]{16}/, label: "Possible AWS access key id" }, { id: "stripe_li...
clawguard
lib/tools/secret-scan-lib.ts
TypeScript
2198511e30c8eb586e348c3c56d27b561906d37f807989be1f9e4c0728fad983
0
772
import type { Sandbox } from "@vercel/sandbox"; import type { z } from "zod"; export interface ToolResult { success: boolean; output: string; error?: string; durationMs: number; metadata?: Record<string, unknown>; } export interface SandboxToolDefinition<TInput = unknown> { name: string; description: st...
clawguard
lib/tools/types.ts
TypeScript
8ef3aba5e2cb7b53ecb3703e7f9e7193957de11fccadab1b0f0f0aaca9d17e8a
0
164
import type { Sandbox } from "@vercel/sandbox"; export interface SearchIndex { fileMap: Map<number, string>; postings: Map<number, Set<number>>; totalFiles: number; } /** Common character pairs in English + typical source — low weight (rare boundaries). */ const COMMON_PAIR_WEIGHTS: ReadonlyMap<string, number> ...
clawguard
lib/tools/search/ngram-index.ts
TypeScript
7faecc01d8f2dbf95221cd40dbb3a1e220b7f54b47fd5f2e92fbc69d239e0485
0
896
[j] >= weights[i]) { isLocalMax = false; break; } } if (isLocalMax && i - start >= 2) { const end = i + 2 > text.length ? text.length : i + 2; ngrams.push(text.slice(start, end)); start = i; } } if (start < text.length) { const final = text.slice(start); ...
clawguard
lib/tools/search/ngram-index.ts
TypeScript
60ae7cc75e5e5d0d6557ffca0df8afbf6e1d8d79bac0132baec32b54089b2594
1
896
= buf.toString("utf-8"); const id = fileId++; fileMap.set(id, cleanPath); const ngrams = extractSparseNgrams(text); for (const ng of ngrams) { const h = hashNgram(ng); let set = postings.get(h); if (!set) { set = new Set(); postings.set(h, set); ...
clawguard
lib/tools/search/ngram-index.ts
TypeScript
665f6f695bedd8ed6b2c8bdd2ea4baeaf6a85742140be1c0d93eccb7c1dc64f7
2
115
/** In-memory overlay of file path → latest UTF-8 content (e.g. after `file_write`) for repo_search. */ const overlayBySandbox = new Map<string, Map<string, string>>(); export function registerRepoSearchOverlay(sandboxKey: string, path: string, content: string): void { if (!sandboxKey) return; let m = overlayBySan...
clawguard
lib/tools/search/overlay.ts
TypeScript
5683b26302c8479530478c7e5a24aafa24add54e5fde11fc42ba2caea7bd5afb
0
145
import type { Sandbox } from "@vercel/sandbox"; import micromatch from "micromatch"; import type { SearchIndex } from "./ngram-index"; import { extractCoveringNgrams, hashNgram } from "./ngram-index"; export interface SearchMatch { file: string; line: number; content: string; } export interface SearchResult { ...
clawguard
lib/tools/search/query.ts
TypeScript
8b0404c524702a91fa33b0f406147fad9029842dff4e3a9a69545405a06b0952
0
896
options?.useRegex ?? false; const isLiteral = !useRegex && !/[.*+?^${}()|[\]\\]/.test(pattern); let candidateSet: Set<number> | null = null; let indexUsed = false; let reportingCandidates = index.totalFiles; let narrowedPaths: string[] | undefined; if (isLiteral && caseSensitive) { candidateSet = get...
clawguard
lib/tools/search/query.ts
TypeScript
99d703c7277a3b1dcb6e4de69e01cec03ed5f090e1b5e37daf853af1000845c9
1
678
import type { Sandbox } from "@vercel/sandbox"; import { z } from "zod"; import { ToolError } from "@/lib/errors"; import type { SandboxToolDefinition } from "@/lib/tools/types"; import type { SearchIndex } from "./ngram-index"; import { buildSearchIndex } from "./ngram-index"; import { getRepoSearchOverlay } from "./o...
clawguard
lib/tools/search/tool.ts
TypeScript
0545ead451b6d3671d8fb0c9cc3869b9f254ccd887870b74c97b427d2c2c930d
0
569
import type { StoredPrediction } from "./predictions"; /** * Heuristic: does an issue text reference a prior finding fingerprint? * Returns confidence 0–1 for metrics / auto-learning. */ export function correlateIssueToPrediction( issueTitle: string, issueBody: string, prediction: StoredPrediction, ): number ...
clawguard
lib/tracking/correlator.ts
TypeScript
cb5430d8a48596ca1bda873504dee8644ed81a2ca2091d8e03f3399b99661412
0
220
export * from "./correlator"; export * from "./metrics"; export * from "./predictions";
clawguard
lib/tracking/index.ts
TypeScript
e29fd34eb29b8fad759558032e71041ec7a8c8c027277ee45a22b4cb6356067d
0
27
import { redis } from "@/lib/redis"; const METRICS_PREFIX = "tracking:metrics:"; export interface TrackingMetrics { truePositives: number; falsePositives: number; misses: number; lastUpdated: string; } export async function recordTruePositive(owner: string, repo: string): Promise<void> { const key = `${MET...
clawguard
lib/tracking/metrics.ts
TypeScript
82247517d1b6275205602e8e75bd2519c0f2e13e7899b2dbb2a6ea4ea0c5c37a
0
434
import type { Finding } from "@/lib/analysis/types"; import { redis } from "@/lib/redis"; export interface StoredPrediction { headSha: string; recordedAt: string; fingerprints: Array<{ type: string; file: string; line: number; severity: string; }>; } export async function storeAuditPredictions...
clawguard
lib/tracking/predictions.ts
TypeScript
3bcd2ec86c59d84a6b319902868d30756756106cfbe03db52341271b5f191ba8
0
259
import path from "node:path"; import * as TreeSitter from "web-tree-sitter"; type Language = TreeSitter.Language; type Node = TreeSitter.Node; let parserInit: Promise<void> | undefined; let parserInstance: TreeSitter.Parser | undefined; function getRepoRoot(): string { return process.cwd(); } function wasmPath(fi...
clawguard
lib/tree-sitter/analyze.ts
TypeScript
b15253c5727eecd31df6cc6f4636962c4b95b8406007081ef8aa460cf1517362
0
896
if (op && op.text === "&&") complexity += 1; if (op && op.text === "||") complexity += 1; } for (let i = 0; i < n.childCount; i++) { const c = n.child(i); if (c) walk(c); } } walk(node); return complexity; } function paramCount(node: Node): number { const params = node.childForFie...
clawguard
lib/tree-sitter/analyze.ts
TypeScript
3cfaf24f49932755931d9f08d2a5471d74d4de51de9d3fbef26193d891ca163c
1
896
} else if (node.type === "method_definition") { visitFunctionLike(node, "method"); } else if (node.type === "arrow_function") { visitFunctionLike(node, "arrow_function"); } for (let i = 0; i < node.childCount; i++) { const c = node.child(i); if (c) walk(c); } } walk(root); ...
clawguard
lib/tree-sitter/analyze.ts
TypeScript
d8bbc08e9cfbeab8a2e2bdcd7f48f6dd6b5ee7031ab42162626effd730b1dd8f
2
130
{ "name": "ClawGuard", "short_name": "ClawGuard", "description": "AI-powered security agent for GitHub pull requests", "start_url": "/", "display": "standalone", "background_color": "#09090b", "theme_color": "#09090b", "icons": [ { "src": "/logo.svg", "type": "image/svg+xml", "size...
clawguard
public/site.webmanifest
Web Manifest
699148f7b92c1545ea288037b225474f49029f1c744e4150a40cf2641e085b57
0
116
/** * Seeds Redis with one fake audit so the report page and dashboard showcase * full UI (findings, phases, threat model, PR summary, verdict, team patterns). * * Uses the same credentials as the Next.js app: * KV_REST_API_URL + KV_REST_API_TOKEN (Vercel KV), or * UPSTASH_REDIS_REST_URL + UPSTASH_REDIS_REST_...
clawguard
scripts/seed-demo-audit.ts
TypeScript
9c4c5a823bd32c743e2c922bb301022754d01b085e685c7c99a29c5696925d9e
0
402
import { createClient } from "v0-sdk"; const v0ApiKey = process.env.V0_API_KEY; if (!v0ApiKey) { console.error("V0_API_KEY not set. Skipping v0 generation."); console.error("All components are built manually — v0 is optional."); process.exit(0); } const prompts: Record<string, string> = { "score-gauge": "...
clawguard
scripts/v0-generate.ts
TypeScript
f8b3cedc6104f03fa27e3dd13b9e88f59a5b81969243ce37788df844cc9646b8
0
801
import { readFileSync } from "node:fs"; import { resolve } from "node:path"; import { describe, expect, it } from "vitest"; const botSource = readFileSync(resolve(__dirname, "../lib/bot.ts"), "utf-8"); const chatAdaptersSource = readFileSync(resolve(__dirname, "../lib/chat-adapters.ts"), "utf-8"); const auditRunnerSou...
clawguard
tests/bot.test.ts
TypeScript
7d2a1ddf4d7d3e1d6f4435d88b9e096463c6fb7c01c44291b2edf4f322223005
0
896
}); describe("Intent Detection (D-03)", () => { it("exports detectIntent function", () => { expect(botSource).toContain("export function detectIntent"); }); it("detects fix-all intent from @clawguard fix all", () => { expect(botSource).toContain('"fix-all"'); expect(botSource).toContain("fix all"); ...
clawguard
tests/bot.test.ts
TypeScript
65b293ff1dba703bee1aabd7edccf1fd588a91da34090767785a8c5a81f3e952
1
896
routing", () => { expect(botSource).toContain("detectIntent("); }); it("routes fix-all intent to fix flow", () => { expect(botSource).toMatch(/intent\.type\s*===\s*"fix-all"/); }); it("routes re-audit intent to runAuditAndPost", () => { expect(botSource).toMatch(/intent\.type\s*===\s*"re-audit"/);...
clawguard
tests/bot.test.ts
TypeScript
1eaba557714be199d1b34877f33398053e59b5444d89e0326c54c729bc434c46
2
188
import { describe, expect, it } from "vitest"; import { buildGithubMentionFallbackPattern, collectBotMentionHandles, commentBodyMentionsBot, } from "@/lib/github-mention-pattern"; describe("github-mention-pattern", () => { it("adds clawguardbot when primary is clawguard", () => { const h = collectBotMentio...
clawguard
tests/github-mention-pattern.test.ts
TypeScript
8dec526bce2b8c790c87de3234e80c48f7ab236b97a9bf38de99b4e76be57bac
0
288
import { describe, expect, it } from "vitest"; import { isAuditStorageKey } from "@/lib/redis-queries"; describe("isAuditStorageKey", () => { it("accepts audit JSON keys", () => { expect(isAuditStorageKey("abdulbb/webgoat-honeypot/pr/6")).toBe(true); expect(isAuditStorageKey("Julian-AT/clawguard/pr/1")).toBe...
clawguard
tests/redis-queries.test.ts
TypeScript
cd3f431202e4f08fdb64b3280fe9fdf80c5a121c94f3159548afd66a14055df8
0
195
import { beforeEach, describe, expect, it, vi } from "vitest"; // Use vi.hoisted to declare mocks that are accessible in vi.mock factories const { mockSet, mockGet } = vi.hoisted(() => ({ mockSet: vi.fn().mockResolvedValue("OK"), mockGet: vi.fn().mockResolvedValue(null), })); vi.mock("@upstash/redis", () => ({ ...
clawguard
tests/redis.test.ts
TypeScript
fd7a531d2e70e6ef4f2d9983211ca913d513e795b4da7a021a1cc980e84e6dd1
0
817
import { beforeEach, describe, expect, it, vi } from "vitest"; import type { AuditResult } from "../lib/analysis/types"; // Use vi.hoisted for mock variables used in vi.mock factories const { mockRunSecurityPipeline } = vi.hoisted(() => { const mockAuditResult: AuditResult = { summary: "Clean bill of health", ...
clawguard
tests/review.test.ts
TypeScript
523299d30ee065bfe7b04bc5c730b6e0205c50adb568ddaa8f3f71956eb5b2a4
0
724
import { beforeEach, describe, expect, it, vi } from "vitest"; const { mockAfter, mockWebhookHandler, mockRedisSet, mockRedisGet } = vi.hoisted(() => ({ mockAfter: vi.fn((fn: () => void) => fn()), mockWebhookHandler: vi.fn().mockResolvedValue(new Response("OK", { status: 200 })), mockRedisSet: vi.fn().mockResolv...
clawguard
tests/webhook-handler.test.ts
TypeScript
a34852ab86746d4de71397bc810c50361546d4cb3db078eee3ef811c5ed41d9a
0
896
action: "created" }), }); const response1 = await POST(request1); expect(response1.status).toBe(200); expect(mockWebhookHandler).toHaveBeenCalledTimes(1); mockWebhookHandler.mockClear(); mockRedisSet.mockResolvedValueOnce(null); const request2 = new Request("http://localhost/api/webhooks/...
clawguard
tests/webhook-handler.test.ts
TypeScript
8d069240d449c89a43ae80904cbd45fc01f3d2b2fdb61a861573696d8c621936
1
198
import { beforeEach, describe, expect, it, vi } from "vitest"; const mockOrchestratorRun = vi.hoisted(() => vi.fn().mockResolvedValue({ findings: [ { severity: "HIGH" as const, type: "xss", file: "src/api.ts", line: 1, cweId: "CWE-79", owaspCategory: "A03:202...
clawguard
tests/analysis/pipeline.test.ts
TypeScript
3e6dddcd4c6f6a3dd07685568a3d84a0b1d195cd74824d7e44d98caadde92a80
0
896
: 10, requireValidation: true, }, thresholds: { blockMerge: "CRITICAL", requestChanges: "HIGH", commentOnly: "MEDIUM", }, ignorePaths: [], report: { generateInteractiveReport: true, frameworks: ["OWASP"], }, model: { provi...
clawguard
tests/analysis/pipeline.test.ts
TypeScript
f84cdf5ec87035e5ff7cad901cfa86c86b1db8dd1a6ace59cd9cf1d50cbc06f2
1
896
, }); mockStop.mockResolvedValue(undefined); mockSandboxCreate.mockResolvedValue({ runCommand: mockRunCommand, stop: mockStop, }); mockRunReconnaissance.mockResolvedValue(defaultRecon); mockRunChangeAnalysis.mockResolvedValue({ narrative: "Summary narrative", sequenceDiag...
clawguard
tests/analysis/pipeline.test.ts
TypeScript
34814d5eadcc6c736315948978c92c6b3b31de73da331858370adffb11d29f0f
2
770
import { describe, expect, it } from "vitest"; import { calculateScore, countBySeverity, GRADE_THRESHOLDS, getGrade, } from "@/lib/analysis/scoring"; import type { Finding } from "@/lib/analysis/types"; import { SEVERITY_DEDUCTIONS } from "@/lib/constants"; function makeFinding(overrides: Partial<Finding> = {}...
clawguard
tests/analysis/scoring.test.ts
TypeScript
115dc775eb4704ac4b6c8a2fb910b2c2600c1a71389ad5a9ba662081c4a2746a
0
896
(90)).toBe("A"); }); it("returns grade B for score 80-89", () => { expect(getGrade(89)).toBe("B"); expect(getGrade(80)).toBe("B"); }); it("returns grade C for score 70-79", () => { expect(getGrade(79)).toBe("C"); expect(getGrade(70)).toBe("C"); }); it("returns grade D ...
clawguard
tests/analysis/scoring.test.ts
TypeScript
333661af4ef3eec51ea03b65cb4b12ebd3a5b53526d76470965eeaf9cb370c1b
1
394
import { describe, expect, it } from "vitest"; import type { Finding } from "@/lib/analysis/types"; import { AuditResultSchema, ConfidenceSchema, FindingSchema, normalizeAuditResultInput, PhaseResultSchema, parseAuditResult, SeveritySchema, } from "@/lib/analysis/types"; function makeFinding(overrides: P...
clawguard
tests/analysis/types.test.ts
TypeScript
39dcb42d8180f0e65be014e7358d007d07342e6092607238f895e6ccdd978b2d
0
896
result.success).toBe(true); }); it("includes confidence field (D-08)", () => { const finding = makeFinding({ confidence: "MEDIUM" }); const result = FindingSchema.safeParse(finding); expect(result.success).toBe(true); if (result.success) { expect(result.data.confidence).toBe("ME...
clawguard
tests/analysis/types.test.ts
TypeScript
b193667651a8f060a988ca4ceb6afcf7bbd0b25d83015dc548d2decc25da1a96
1
896
findings: [] }], findings: [makeFinding()], }); expect(AuditResultSchema.safeParse(raw).success).toBe(true); }); it("parseAuditResult tolerates legacy Redis finding shape (partial fields, string compliance)", () => { const legacyFinding = { severity: "HIGH", type: "xss...
clawguard
tests/analysis/types.test.ts
TypeScript
3012d8c4c324ce50db494e072e6ddc303b83551bb19e546b45573f47323f21dc
2
338
import { readFileSync } from "node:fs"; import { resolve } from "node:path"; import { describe, expect, it } from "vitest"; import { SEVERITY_ORDER } from "@/lib/cards/summary-card"; const cardSource = readFileSync(resolve(__dirname, "../../lib/cards/summary-card.tsx"), "utf-8"); describe("Summary Card Builder", () =...
clawguard
tests/cards/summary-card.test.ts
TypeScript
d56545e95361dc69f67d0205d2d2a2b76371a4cbe306ea22474113a1e7313b83
0
896
; }); it("calculates fixable count from CRITICAL+HIGH findings", () => { expect(cardSource).toContain("fixableCount"); expect(cardSource).toMatch(/CRITICAL.*HIGH|HIGH.*CRITICAL/); }); it("buildSummaryMarkdown uses NOTE block and report link", () => { expect(cardSource).toContain("> [...
clawguard
tests/cards/summary-card.test.ts
TypeScript
b389bbff5846783072f686b9426d059c895f072297e897934bb6a8df8d3d2e0b
1
127
import { createElement } from "react"; import { renderToString } from "react-dom/server"; import { describe, expect, it } from "vitest"; import { ReportShell } from "@/components/report/report-shell"; describe("ReportShell (SSR smoke)", () => { it("includes repo and PR in header", () => { const html = renderToSt...
clawguard
tests/components/report-shell.ssr.test.ts
TypeScript
2e231d18028ac6a9bf2f2bdc931c9b416d65ce01e0ba904a2846087c0cba813e
0
182
import { readFileSync } from "node:fs"; import { resolve } from "node:path"; import { describe, expect, it } from "vitest"; const source = readFileSync(resolve(__dirname, "../../lib/fix/apply.ts"), "utf-8"); describe("Fix Apply Module", () => { it("exports applyStoredFix as an async function", () => { expect(so...
clawguard
tests/fix/apply.test.ts
TypeScript
0b5999c7f444aafd4ae4f19851eca43fea00345e0c1882e39d0235c38056bf03
0
622
import { readFileSync } from "node:fs"; import { resolve } from "node:path"; import { describe, expect, it } from "vitest"; const source = readFileSync(resolve(__dirname, "../../lib/fix/commit.ts"), "utf-8"); describe("Fix Commit Module", () => { it("exports commitFixToGitHub as an async function", () => { expe...
clawguard
tests/fix/commit.test.ts
TypeScript
ce5d04ea9a351903d8094e062ca379fc012f5ac720ed9193b7b4f07c626d2027
0
670
import { readFileSync } from "node:fs"; import { resolve } from "node:path"; import { describe, expect, it } from "vitest"; const indexSource = readFileSync(resolve(__dirname, "../../lib/fix/index.ts"), "utf-8"); describe("fixFinding orchestration", () => { it("exports fixFinding function", () => { expect(index...
clawguard
tests/fix/index.test.ts
TypeScript
8ed54ac49fadc9bf9af41553a85e8c41d0e8e48cabec0a26da3244f3547b9404
0
896
results\.some|status.*===.*"fixed"/); }); it("throws error when no audit results found", () => { expect(indexSource).toContain("No audit results found"); }); it("sorts fixable findings by SEVERITY_ORDER (CRITICAL first)", () => { expect(indexSource).toContain("SEVERITY_ORDER"); }); });
clawguard
tests/fix/index.test.ts
TypeScript
f8e5c557bb2964a8206afe47fbf41ec4ffa2da3b15882b7bf9c18bac78b8d769
1
94
import { readFileSync } from "node:fs"; import { resolve } from "node:path"; import { describe, expect, it } from "vitest"; const source = readFileSync(resolve(__dirname, "../../lib/fix/validate.ts"), "utf-8"); describe("Fix Validate Module", () => { it("exports runValidation as an async function", () => { expe...
clawguard
tests/fix/validate.test.ts
TypeScript
f6d58591e9649e99db864991f1912412f72d5ab8f4c37badc16a38018406346f
0
706
import { describe, expect, it } from "vitest"; import { postProcessAudit } from "@/lib/analysis/post-process"; import { parseChangedFilesFromDiff } from "@/lib/analysis/recon"; import type { Finding, ThreatModel } from "@/lib/analysis/types"; import { DEFAULT_CLAWGUARD_CONFIG } from "@/lib/config/defaults"; describe("...
clawguard
tests/golden/golden-pipeline.test.ts
TypeScript
ae577a0d1ed70ce2121e76d720441b94f3c8ab07963e30b17ff37f33cf0c575e
0
528
declare module "micromatch" { const micromatch: { isMatch: (input: string, pattern: string, options?: { dot?: boolean }) => boolean; }; export default micromatch; }
clawguard
types/micromatch.d.ts
TypeScript
cd13c8eec199cadaa5e093c48decf0ae485be5c7794a668ac11eeda0a19acc57
0
42
import type { DefaultSession } from "next-auth"; declare module "next-auth" { interface Session { user?: DefaultSession["user"] & { id?: string; }; } }
clawguard
types/next-auth.d.ts
TypeScript
9cbb8d573eae71d5bfda24e518abc5bc96709d0d3685b3e39ecb3c1103c6d395
0
43
# dependencies node_modules/ # env — but keep the example .env .env.* !.env.example # python venv + bench artifacts .venv/ __pycache__/ *.pyc # data (allow committed manifests) data/* !data/corpus.json !data/adapter-tools.fallback.json !data/adapter-tools.json # iOS builds ios/**/build/ ios/**/DerivedData/ ios/**/*...
codex-hackathon
.gitignore
Git Ignore
38978141229a7d6d2160a48f9874ddd4d69093ca57e9e1a3590b363e262be468
0
191
# MLX Repository Instructions ## Product identity - The product is named **MLX**. - The only intended user-facing executable is `mlx`. - The default local state directory is `~/.mlx`, overridable with `MLX_HOME`. - Do not introduce or preserve the product names `Forgeprint`, `forgeprint`, or `codex` in user-facing pr...
codex-hackathon
AGENTS.md
Markdown
c3bebb7a3cbaf475c8909dbde886a5db553cedfa2d4b7342d26a0f01c5e91c36
0
896
Hugging Face `datasets`, `pyarrow`, `polars`, `duckdb`, and `huggingface_hub`. - Operational state: SQLite with migrations, WAL mode, foreign keys, leased jobs, heartbeats, retries, and recovery. - Canonical analytical data: Parquet/Arrow, queryable through DuckDB. - Content-addressed blobs: SHA-256 objects under `MLX_...
codex-hackathon
AGENTS.md
Markdown
8c29f358d2abecedcb3237944591495d583438802a9cf7d383ff8dedffd53771
1
339
{ "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", "organizeImports": { "enabled": true }, "linter": { "enabled": true, "rules": { "recommended": true, "suspicious": { "noExplicitAny": "off" }, "style": { "noNonNullAssertion": "warn" } } }, "formatter": { "enabled": tru...
codex-hackathon
biome.json
JSON
a65a8efdf7c8d9ad8840e411538000ee17cd8c4069653809a4001bbd2eb2fec1
0
228
# CLAUDE.md — Project Instructions for Claude Code > Offline Specialist-LLM Pipeline — CLI tool for producing narrow product expert models. ## Project Overview CLI-driven pipeline that discovers a product corpus, designs dynamic tools, generates training data, fine-tunes a local Gemma model via MLX, and deploys the ...
codex-hackathon
CLAUDE.md
Markdown
287a0988098c44415aca07a687b53d5f4a27e1681fc0e719d79b85ac5950ffef
0
675