forked from isboyjc/claude-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
executable file
·197 lines (192 loc) · 5.63 KB
/
build.ts
File metadata and controls
executable file
·197 lines (192 loc) · 5.63 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**
* Build script for Claude Code source reconstruction.
* Uses Bun's bundler with feature flag definitions and MACRO constants.
*/
const VERSION = '2.1.88'
const BUILD_TIME = new Date().toISOString()
// All feature flags - matching production external build defaults
const featureFlags: Record<string, boolean> = {
ABLATION_BASELINE: false,
AGENT_MEMORY_SNAPSHOT: false,
AGENT_TRIGGERS: false,
AGENT_TRIGGERS_REMOTE: false,
ALLOW_TEST_VERSIONS: false,
ANTI_DISTILLATION_CC: false,
AUTO_THEME: false,
AWAY_SUMMARY: false,
BASH_CLASSIFIER: false,
BG_SESSIONS: false,
BREAK_CACHE_COMMAND: false,
BRIDGE_MODE: false,
BUDDY: false,
BUILDING_CLAUDE_APPS: false,
BUILTIN_EXPLORE_PLAN_AGENTS: true,
BYOC_ENVIRONMENT_RUNNER: false,
CACHED_MICROCOMPACT: false,
CCR_AUTO_CONNECT: false,
CCR_MIRROR: false,
CCR_REMOTE_SETUP: false,
CHICAGO_MCP: false,
COMMIT_ATTRIBUTION: false,
COMPACTION_REMINDERS: true,
CONNECTOR_TEXT: false,
CONTEXT_COLLAPSE: false,
COORDINATOR_MODE: false,
COWORKER_TYPE_TELEMETRY: false,
DAEMON: false,
DIRECT_CONNECT: false,
DOWNLOAD_USER_SETTINGS: false,
DUMP_SYSTEM_PROMPT: false,
ENHANCED_TELEMETRY_BETA: false,
EXPERIMENTAL_SKILL_SEARCH: false,
EXTRACT_MEMORIES: false,
FILE_PERSISTENCE: false,
FORK_SUBAGENT: false,
HARD_FAIL: false,
HISTORY_PICKER: false,
HISTORY_SNIP: false,
HOOK_PROMPTS: false,
IS_LIBC_GLIBC: false,
IS_LIBC_MUSL: false,
KAIROS: false,
KAIROS_BRIEF: false,
KAIROS_CHANNELS: false,
KAIROS_DREAM: false,
KAIROS_GITHUB_WEBHOOKS: false,
KAIROS_PUSH_NOTIFICATION: false,
LODESTONE: false,
MCP_RICH_OUTPUT: false,
MCP_SKILLS: true,
MEMORY_SHAPE_TELEMETRY: false,
MESSAGE_ACTIONS: false,
MONITOR_TOOL: false,
NATIVE_CLIENT_ATTESTATION: false,
NATIVE_CLIPBOARD_IMAGE: false,
NEW_INIT: false,
OVERFLOW_TEST_TOOL: false,
PERFETTO_TRACING: false,
POWERSHELL_AUTO_MODE: false,
PROACTIVE: false,
PROMPT_CACHE_BREAK_DETECTION: false,
QUICK_SEARCH: false,
REACTIVE_COMPACT: false,
REVIEW_ARTIFACT: false,
RUN_SKILL_GENERATOR: false,
SELF_HOSTED_RUNNER: false,
SHOT_STATS: false,
SKILL_IMPROVEMENT: false,
SLOW_OPERATION_LOGGING: false,
SSH_REMOTE: false,
STREAMLINED_OUTPUT: false,
TEAMMEM: false,
TEMPLATES: false,
TERMINAL_PANEL: false,
TOKEN_BUDGET: true,
TORCH: false,
TRANSCRIPT_CLASSIFIER: false,
TREE_SITTER_BASH: false,
TREE_SITTER_BASH_SHADOW: false,
UDS_INBOX: false,
ULTRAPLAN: false,
ULTRATHINK: false,
UNATTENDED_RETRY: false,
UPLOAD_USER_SETTINGS: false,
VERIFICATION_AGENT: false,
VOICE_MODE: false,
WEB_BROWSER_TOOL: false,
WORKFLOW_SCRIPTS: false,
}
const result = await Bun.build({
entrypoints: ['./src/entrypoints/cli.tsx'],
outdir: './dist',
target: 'node',
format: 'esm',
sourcemap: 'linked',
minify: false,
define: {
// MACRO constants inlined at build time
'MACRO.VERSION': JSON.stringify(VERSION),
'MACRO.BUILD_TIME': JSON.stringify(BUILD_TIME),
'MACRO.ISSUES_EXPLAINER': JSON.stringify('report the issue at https://github.com/anthropics/claude-code/issues'),
'MACRO.FEEDBACK_CHANNEL': JSON.stringify('https://github.com/anthropics/claude-code/issues'),
'MACRO.PACKAGE_URL': JSON.stringify('https://www.npmjs.com/package/@anthropic-ai/claude-code'),
'MACRO.NATIVE_PACKAGE_URL': JSON.stringify('https://www.npmjs.com/package/@anthropic-ai/claude-code'),
'MACRO.VERSION_CHANGELOG': JSON.stringify(''),
// Bun global
'Bun.env.NODE_ENV': JSON.stringify('production'),
},
external: [
'*.node',
'sharp',
'@img/*',
'@anthropic-ai/bedrock-sdk',
'@anthropic-ai/vertex-sdk',
'@anthropic-ai/foundry-sdk',
],
plugins: [
{
name: 'bun-bundle-feature-shim',
setup(build) {
// Intercept bun:bundle imports and replace feature() with compile-time values
build.onResolve({ filter: /^bun:bundle$/ }, () => ({
path: 'bun:bundle',
namespace: 'bun-bundle-shim',
}))
build.onLoad({ filter: /.*/, namespace: 'bun-bundle-shim' }, () => {
const lines = Object.entries(featureFlags)
.map(([k, v]) => ` '${k}': ${v},`)
.join('\n')
return {
contents: `
const features = {\n${lines}\n};
export function feature(name) {
if (name in features) return features[name];
return false;
}
`,
loader: 'js',
}
})
},
},
{
name: 'text-file-loader',
setup(build) {
// Load .md and .txt files as strings
build.onLoad({ filter: /\.(md|txt)$/ }, async (args) => {
const fs = await import('fs/promises')
const contents = await fs.readFile(args.path, 'utf-8')
return {
contents: `export default ${JSON.stringify(contents)}`,
loader: 'js',
}
})
// Load .d.ts files as empty modules (they're type-only)
build.onLoad({ filter: /\.d\.ts$/ }, () => ({
contents: 'export {}',
loader: 'js',
}))
},
},
],
})
if (result.success) {
// Add shebang to output
const fs = await import('fs/promises')
const outFile = result.outputs[0]!.path
const content = await fs.readFile(outFile, 'utf-8')
if (!content.startsWith('#!/')) {
await fs.writeFile(outFile, `#!/usr/bin/env node\n${content}`)
}
await fs.chmod(outFile, 0o755)
console.log('✓ Build succeeded')
console.log(` Output: ${result.outputs.map(o => o.path).join(', ')}`)
const stat = await fs.stat(outFile)
console.log(` Size: ${(stat.size / 1024 / 1024).toFixed(1)}MB`)
} else {
console.error('✗ Build failed')
for (const log of result.logs) {
console.error(log)
}
process.exit(1)
}