Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
295 lines (285 loc) · 17.2 KB
/
Copy pathbuild.zig
File metadata and controls
295 lines (285 loc) · 17.2 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lean_release = optimize == .fast or optimize == .small;
// `--version` string: stamped from `git describe` at build time so every
// binary says which commit built it; `-Dversion=X.Y.Z` overrides (the
// release workflow passes the tag).
const version = b.option([]const u8, "version", "version string for --version") orelse blk: {
var code: u8 = 0;
const raw = b.runAllowFail(
&.{ "git", "-C", ".", "describe", "--tags", "--always", "--dirty" },
&code,
.ignore,
) catch break :blk "0.1.0-dev";
const described = std.mem.trim(u8, raw, " \r\n");
if (described.len == 0) break :blk "0.1.0-dev";
// No tags yet → describe is a bare commit hash (no dot); make it
// read as a version.
break :blk if (std.mem.indexOfScalar(u8, described, '.') != null)
described
else
b.fmt("0.1.0-dev+{s}", .{described});
};
// Baked-in default OTLP telemetry endpoint: the harness phones
// usage/evolution telemetry here unless the user overrides with
// OTEL_EXPORTER_OTLP_ENDPOINT or opts out (--no-telemetry /
// GRAFF_NO_TELEMETRY). Hardcoded as the default so every build — release,
// source-install, and dev — carries it; `-Dtelemetry-endpoint=""` disables
// it at build time. The harness-telemetry worker recomputes the HMAC and
// rejects unsigned rows, so this must match the deployed collector.
const telemetry_endpoint = b.option(
[]const u8,
"telemetry-endpoint",
"default OTLP endpoint baked into builds (pass \"\" to disable; default = the deployed collector)",
) orelse "https://harness-telemetry.rachpradhan.workers.dev";
const opts = b.addOptions();
opts.addOption([]const u8, "version", version);
opts.addOption([]const u8, "telemetry_endpoint", telemetry_endpoint);
const exe = b.addExecutable(.{
.name = "graff",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.strip = lean_release,
// Linux cross-builds (x86_64-linux for in-container evals) must say
// libc explicitly; macOS resolves it implicitly and never notices.
.link_libc = true,
}),
});
exe.root_module.addOptions("build_options", opts);
const accord_dep = b.dependency("accord", .{ .target = target, .optimize = optimize });
const accord_mod = accord_dep.module("accord");
exe.root_module.addImport("accord", accord_mod);
const http_zig_dep = b.dependency("http_zig", .{ .target = target, .optimize = optimize });
const http_zig_mod = http_zig_dep.module("http_zig");
exe.root_module.addImport("http_zig", http_zig_mod);
// Shared model-ranking module used by the line-REPL picker.
const models_rank_mod = b.createModule(.{
.root_source_file = b.path("src/models_rank.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("models_rank", models_rank_mod);
// Shared nearest-command speller for the REPL/ACP catalog.
const slash_suggest_mod = b.createModule(.{
.root_source_file = b.path("src/slash_suggest.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("slash_suggest", slash_suggest_mod);
const install_graff = b.addInstallArtifact(exe, .{});
b.getInstallStep().dependOn(&install_graff.step);
const graff_step = b.step("graff", "Build and install only the release CLI");
graff_step.dependOn(&install_graff.step);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(&install_graff.step);
const run_step = b.step("run", "Run the harness");
run_step.dependOn(&run_cmd.step);
// `zig build test` — unit tests live in src/main.zig `test "..." {}` blocks.
// `-Dtest-filter="<text>"` (repeatable) narrows the run to the tests whose
// name contains that text. scripts/eval-tier1.sh uses it to prove the named
// goal/loop/todo invariants still run — a test whose module fell out of the
// test root exists in the source but never executes.
const test_filters = b.option(
[]const []const u8,
"test-filter",
"Only run tests whose name contains this text (repeatable)",
) orelse &[_][]const u8{};
const unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true, // workspace_switch reaches std.c.getcwd (#721); same as the exe
}),
.filters = test_filters,
});
unit_tests.root_module.addOptions("build_options", opts);
unit_tests.root_module.addImport("accord", accord_mod);
unit_tests.root_module.addImport("http_zig", http_zig_mod);
unit_tests.root_module.addImport("models_rank", models_rank_mod);
unit_tests.root_module.addImport("slash_suggest", slash_suggest_mod);
// spec/ fixtures live outside src/; importing them here makes @embedFile
// legal and rebuilds the suite when the exported semantics change.
exe.root_module.addAnonymousImport("ui_theme", .{ .root_source_file = b.path("src/ui_theme.css") });
unit_tests.root_module.addAnonymousImport("ui_theme", .{ .root_source_file = b.path("src/ui_theme.css") });
unit_tests.root_module.addAnonymousImport("spec_tool_catalog", .{ .root_source_file = b.path("spec/kernels/tool_catalog.json") });
unit_tests.root_module.addAnonymousImport("spec_transport", .{ .root_source_file = b.path("spec/kernels/transport.json") });
unit_tests.root_module.addAnonymousImport("spec_providers", .{ .root_source_file = b.path("spec/kernels/providers.json") });
unit_tests.root_module.addAnonymousImport("spec_goal_loop", .{ .root_source_file = b.path("spec/kernels/goal_loop.json") });
unit_tests.root_module.addAnonymousImport("spec_path_confine", .{ .root_source_file = b.path("spec/kernels/path_confine.json") });
unit_tests.root_module.addAnonymousImport("spec_shape", .{ .root_source_file = b.path("spec/kernels/shape.json") });
unit_tests.root_module.addAnonymousImport("spec_score", .{ .root_source_file = b.path("spec/kernels/score.json") });
unit_tests.root_module.addAnonymousImport("spec_bash_policy", .{ .root_source_file = b.path("spec/kernels/bash_policy.json") });
unit_tests.root_module.addAnonymousImport("spec_structured_output", .{ .root_source_file = b.path("spec/kernels/structured_output.json") });
unit_tests.root_module.addAnonymousImport("spec_prompt_cache", .{ .root_source_file = b.path("spec/kernels/prompt_cache.json") });
unit_tests.root_module.addAnonymousImport("spec_prompt_prefix", .{ .root_source_file = b.path("spec/kernels/prompt_prefix.json") });
unit_tests.root_module.addAnonymousImport("spec_prompt_stable", .{ .root_source_file = b.path("spec/kernels/prompt_stable.json") });
const run_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit and subprocess integration tests");
test_step.dependOn(&run_tests.step);
// Reachability only needs the binary. Running the suite here as well made
// pre-push spend its 600s budget before the tests check started.
const test_bin = b.step("test-bin", "Compile unit tests without running them");
test_bin.dependOn(&unit_tests.step);
// The working loop: the unit binary alone, without the integration
// scripts `test` adds below. `-Dtest-filter` narrows it to named tests.
const unit_step = b.step("unit", "Run only the unit tests (-Dtest-filter narrows them)");
unit_step.dependOn(&run_tests.step);
const acp_preauth_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-preauth.py" });
acp_preauth_test.addArtifactArg(exe);
test_step.dependOn(&acp_preauth_test.step);
const acp_goal_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-goal.py" });
acp_goal_test.addArtifactArg(exe);
test_step.dependOn(&acp_goal_test.step);
const acp_startup_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-startup.py" });
acp_startup_test.addArtifactArg(exe);
test_step.dependOn(&acp_startup_test.step);
const acp_harness_room_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-harness-room.py" });
acp_harness_room_test.addArtifactArg(exe);
test_step.dependOn(&acp_harness_room_test.step);
const usage_trace_test = b.addSystemCommand(&.{ "python3", "scripts/test-usage-trace.py" });
usage_trace_test.addArtifactArg(exe);
test_step.dependOn(&usage_trace_test.step);
const acp_view_meta_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-view-meta.py" });
acp_view_meta_test.addArtifactArg(exe);
test_step.dependOn(&acp_view_meta_test.step);
const acp_ask_user_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-ask-user.py" });
acp_ask_user_test.addArtifactArg(exe);
test_step.dependOn(&acp_ask_user_test.step);
const mcp_client_spec_test = b.addSystemCommand(&.{ "python3", "scripts/test-mcp-client-spec.py" });
mcp_client_spec_test.addArtifactArg(exe);
test_step.dependOn(&mcp_client_spec_test.step);
const mcp_shared_test = b.addSystemCommand(&.{ "python3", "scripts/test-mcp-shared.py" });
mcp_shared_test.addArtifactArg(exe);
test_step.dependOn(&mcp_shared_test.step);
const mcp_lazy_test = b.addSystemCommand(&.{ "python3", "scripts/test-mcp-lazy.py" });
mcp_lazy_test.addArtifactArg(exe);
test_step.dependOn(&mcp_lazy_test.step);
const mcp_async_test = b.addSystemCommand(&.{ "python3", "scripts/test-mcp-async-start.py" });
mcp_async_test.addArtifactArg(exe);
test_step.dependOn(&mcp_async_test.step);
const mcp_add_test = b.addSystemCommand(&.{ "python3", "scripts/test-mcp-add.py" });
mcp_add_test.addArtifactArg(exe);
test_step.dependOn(&mcp_add_test.step);
const acp_v2_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-v2.py" });
acp_v2_test.addArtifactArg(exe);
test_step.dependOn(&acp_v2_test.step);
const acp_effort_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-effort-config.py" });
acp_effort_test.addArtifactArg(exe);
test_step.dependOn(&acp_effort_test.step);
const acp_agent_wait_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-agent-output-wait.py" });
acp_agent_wait_test.addArtifactArg(exe);
test_step.dependOn(&acp_agent_wait_test.step);
const acp_child_update_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-subagent-update.py" });
acp_child_update_test.addArtifactArg(exe);
test_step.dependOn(&acp_child_update_test.step);
const acp_background_child_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-background-subagent.py" });
acp_background_child_test.addArtifactArg(exe);
test_step.dependOn(&acp_background_child_test.step);
const repl_background_wait_test = b.addSystemCommand(&.{ "python3", "scripts/test-repl-background-wait.py" });
repl_background_wait_test.addArtifactArg(exe);
test_step.dependOn(&repl_background_wait_test.step);
const shell_wait_todo_test = b.addSystemCommand(&.{ "python3", "scripts/test-shell-wait-and-todo-reply.py" });
shell_wait_todo_test.addArtifactArg(exe);
test_step.dependOn(&shell_wait_todo_test.step);
const workflow_isolation_test = b.addSystemCommand(&.{ "python3", "scripts/test-workflow-isolation.py" });
workflow_isolation_test.addArtifactArg(exe);
test_step.dependOn(&workflow_isolation_test.step);
const workspace_lifecycle_test = b.addSystemCommand(&.{ "python3", "scripts/test-workspace-lifecycle.py" });
workspace_lifecycle_test.addArtifactArg(exe);
test_step.dependOn(&workspace_lifecycle_test.step);
const acp_workspace_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-workspace.py" });
acp_workspace_test.addArtifactArg(exe);
test_step.dependOn(&acp_workspace_test.step);
const acp_images_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-images.py" });
acp_images_test.addArtifactArg(exe);
test_step.dependOn(&acp_images_test.step);
const acp_slash_typo_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-slash-typo.py" });
acp_slash_typo_test.addArtifactArg(exe);
test_step.dependOn(&acp_slash_typo_test.step);
const acp_compaction_test = b.addSystemCommand(&.{ "python3", "scripts/test-acp-compaction.py" });
acp_compaction_test.addArtifactArg(exe);
test_step.dependOn(&acp_compaction_test.step);
const run_tool_budget_test = b.addSystemCommand(&.{ "python3", "scripts/test-run-tool-budget.py" });
run_tool_budget_test.addArtifactArg(exe);
test_step.dependOn(&run_tool_budget_test.step);
const subagent_resume_test = b.addSystemCommand(&.{ "python3", "scripts/test-subagent-resume.py" });
subagent_resume_test.addArtifactArg(exe);
test_step.dependOn(&subagent_resume_test.step);
const learn_formal_test = b.addSystemCommand(&.{ "python3", "tests/learn_formal_e2e.py", "--graff" });
learn_formal_test.addArtifactArg(exe);
test_step.dependOn(&learn_formal_test.step);
test_step.dependOn(&b.addSystemCommand(&.{ "python3", "graff-evals/test_measurement.py" }).step);
test_step.dependOn(&b.addSystemCommand(&.{ "python3", "scripts/test-eval-cache-affinity.py" }).step);
// Learning kit: the adapter/suite files `graff learn init` materializes
// into a workspace so zero-configuration learning needs no repo checkout.
// Embedded by name (src/learn_assets.zig `@embedFile`s these imports).
for ([_]struct { import: []const u8, path: []const u8 }{
.{ .import = "mcp_installer", .path = "scripts/install-mcp.py" },
.{ .import = "learn_kit_mutator", .path = "examples/learn_graff_mutator.py" },
.{ .import = "learn_kit_evaluator", .path = "examples/learn_graff_evaluator.py" },
.{ .import = "learn_kit_case", .path = "examples/learn_graff_case.py" },
.{ .import = "learn_kit_behavior", .path = "examples/learn_behavior_metrics.py" },
.{ .import = "learn_kit_suites", .path = "examples/learn_graff_suites.py" },
.{ .import = "learn_kit_generate", .path = "examples/learn_generate_suites.py" },
.{ .import = "learn_kit_scorer", .path = "scripts/score_run.py" },
}) |asset| {
exe.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
unit_tests.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
}
// Bundled skills: SKILL.md playbooks compiled into every binary (embedded
// by name in src/skill_docs.zig), so a fresh install already knows how to
// author more skills and how to change this workspace's MCP servers.
for ([_]struct { import: []const u8, path: []const u8 }{
.{ .import = "skill_doc_creator", .path = "assets/skills/skill-creator.md" },
.{ .import = "skill_doc_mcp_config", .path = "assets/skills/mcp-config.md" },
.{ .import = "skill_doc_mcp", .path = "assets/skills/mcp.md" },
.{ .import = "skill_doc_jspace", .path = "assets/skills/jspace.md" },
.{ .import = "skill_doc_workspace", .path = "assets/skills/workspace.md" },
}) |asset| {
exe.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
unit_tests.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
}
const external_tui_test = b.addSystemCommand(&.{ "python3", "scripts/test-external-tui.py" });
external_tui_test.addArtifactArg(exe);
test_step.dependOn(&external_tui_test.step);
// In-process ACP (fx-shaped embed). Off the default install so the
// tagged CLI cut does not grow a .so / .wasm. `zig build libgraff`
// and `zig build -Dwasm-surface=core`.
const libgraff = b.addLibrary(.{
.linkage = .dynamic,
.name = "graff",
.root_module = b.createModule(.{
.root_source_file = b.path("src/libgraff.zig"),
.target = target,
.optimize = optimize,
.strip = lean_release,
}),
});
const libgraff_step = b.step("libgraff", "Build the in-process ACP shared library");
libgraff_step.dependOn(&b.addInstallArtifact(libgraff, .{}).step);
_ = b.option([]const u8, "wasm-surface", "wasm surface: core (use `zig build wasm-core`)");
// Pinned ReleaseSmall regardless of the global optimize: the wasm surface
// ships in @codegraff/sdk for JS hosts, so size is the axis that matters
// (vercel-labs/fx pins it the same way). -Doptimize still overrides.
const wasm = b.addExecutable(.{
.name = "graff-core",
.root_module = b.createModule(.{
.root_source_file = b.path("src/wasm_core_main.zig"),
.target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
}),
.optimize = if (optimize == .debug) .small else optimize,
.strip = true,
}),
});
wasm.entry = .disabled;
wasm.rdynamic = true;
const wasm_step = b.step("wasm-core", "Build graff-core.wasm (in-process ACP)");
wasm_step.dependOn(&b.addInstallArtifact(wasm, .{}).step);
}