const query = async () => {
const stream = api.stream()
for await (const chunk of stream) {
if (chunk.type === 'tool_use') {
await executeTool(chunk)
}
yield chunk.delta
}
}
export class QueryEngine {
private sessions: Map<string>
async compact(history) {
if (tokens > MAX_CONTEXT) {
return summarize(history)
}
}
}
const PERMISSIONS = [
'FileRead', 'FileWrite',
'Bash', 'Glob', 'Grep',
]
function checkSecurity(cmd) {
for (const rule of RULES) {
if (rule.match(cmd)) block()
}
}
interface Tool {
name: string
isConcurrencySafe: boolean
execute(input: unknown)
}
async function dispatch(calls) {
const reads = calls.filter(safe)
const writes = calls.filter(!safe)
await Promise.all(reads)
for (const w of writes) {
await w.execute()
}
}
// KAIROS daemon mode
class KairosDaemon {
private cron: CronScheduler
async autoDream() {
await consolidateMemory()
await mergeFindingss()
}
watch(repo: Repository) {
repo.on('pr', handle)
repo.on('issue', handle)
}
}
const FEATURE_FLAGS = {
KAIROS: false,
VOICE_MODE: false,
COORDINATOR: true,
BUDDY: true,
ANTI_DISTILL: true,
DAEMON: false,
BRIDGE: true,
TORCH: false,
}
// anti-distillation
if (feature('ANTI_DISTILL')) {
result.anti_distillation
= ['fake_tools']
}
// undercover mode
export function isUndercover() {
return isExternalRepo()
&& isAnthropicUser()
}
export async function main() {
const config = loadConfig()
const keys = await keychain()
await Promise.all([
growthbook.init(),
mcp.connect(servers),
registerTools(TOOLS),
])
const prompt = buildSystem({
identity: AGENT_IDENTITY,
tools: TOOL_SPECS,
memory: loadMemory(),
claudeMd: readClaudeMd(),
})
launchRepl(prompt, config)
}
// bashSecurity.ts
const CHECKS = 23
function validateCommand(cmd) {
// Check 1: $(command)
// Check 2: process substitution
// Check 7: zmodload bypass
// Check 12: unicode zero-width
// Check 19: IFS null byte
// Check 23: HackerOne report
if (dangerous(cmd)) {
telemetry.track(
'bash_security_triggered',
{ check: checkId }
)
return BLOCKED
}
}
// 512,664 lines total
// 1,884 .ts/.tsx files
// Runtime: Bun
class MemorySystem {
private index: MemoryIndex
async recall(query: string) {
const matches = semantic(
this.memories, query
)
return matches.slice(0, 5)
}
async age() {
for (const m of this.memories) {
if (isStale(m)) {
await this.archive(m)
}
}
}
}
// buddy/species.ts
const SPECIES = [
'duck', 'dragon', 'octopus',
'capybara', 'ghost', 'mushroom',
]
// coordinator prompt (300+ lines)
// Phase 1: Research
// Phase 2: Synthesis
// Phase 3: Implementation
// Phase 4: Verification
//
// "Do not rubber-stamp
// weak work"
//
// prompt cache strategy:
// static segments: cached
// dynamic segments: rebuilt
//
// cache_control: {
// type: 'ephemeral'
// }
//
// MAX_AUTOCOMPACT = 3
// saved 250k API calls/day
source leaked
51万行源码曝光
我扒完了Claude Code
的全部家底
512,664行 TypeScript · 1,884 文件 · 44 特性开关
$ npm pack @anthropic-ai/claude-code
→ claude-code-2.1.88.tgz
→ index.js.map 59.8MB
⚠ EXPOSED:
files: 1,884
lines: 512,664
flags: 44
tools: 40+
█ KAIROS █ ANTI_DISTILL
█ BUDDY █ UNDERCOVER