Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
1810 lines (1652 loc) · 73.7 KB
/
Copy pathflake.nix
File metadata and controls
1810 lines (1652 loc) · 73.7 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
description = "CyDo - Multi-agent orchestration with Claude Code";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
screenshot-fixtures = {
url = "git+file:docs/tools/screenshots/fixtures";
flake = false;
};
};
outputs = { self, nixpkgs, screenshot-fixtures }:
let
# Clean, full-history Git flakes count all ancestors. Dirty Git
# trees, Git fetches with shallow=1, and path or GitHub tarball
# flakes omit revCount and produce an unversioned build.
# Nix errors when forcing revCount for an implicit clean shallow checkout.
releaseVersion = if self ? revCount then "0.0.${toString self.revCount}" else null;
version = "0.0.0";
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ];
pkgsFor = system: import nixpkgs {
inherit system;
overlays = [(final: prev: {
# Claude Code stopped shipping the JS bundle on npm; recent versions
# publish per-platform native binaries instead. Package those
# directly — the linux-x64 binary is byte-identical to what the
# official installer deploys.
claude-code =
let
version = "2.1.330";
claudeSrc = {
x86_64-linux = {
platform = "linux-x64";
hash = "sha256-1YqoO6AhDXXzD/r+z9AIdGbJyJsGksW8A5Bi9PLybM4=";
};
aarch64-linux = {
platform = "linux-arm64";
hash = "sha256-OeDdcmREsi1qTaOEFoSgVUXoILR0ODWFa93NELxCxEs=";
};
}.${system} or (throw "Claude Code: unsupported system ${system}");
in final.stdenv.mkDerivation {
pname = "claude-code";
inherit version;
src = final.fetchzip {
url = "https://registry.npmjs.org/@anthropic-ai/claude-code-${claudeSrc.platform}/-/claude-code-${claudeSrc.platform}-${version}.tgz";
inherit (claudeSrc) hash;
};
nativeBuildInputs = [ final.patchelf ];
# The Bun-compiled binary carries its JS bundle as trailer data
# past the ELF image; stripping or autoPatchelf's section
# rewriting corrupts it, leaving the bare Bun runtime. Only the
# interpreter may be patched.
dontStrip = true;
installPhase = ''
runHook preInstall
install -Dm755 claude $out/bin/claude
patchelf --set-interpreter ${final.stdenv.cc.bintools.dynamicLinker} $out/bin/claude
runHook postInstall
'';
};
})];
config = {
allowUnfree = true;
};
};
lib = nixpkgs.lib;
playwrightForE2e = pkgs: pkgs.playwright-test.overrideAttrs (old: {
postInstall = (old.postInstall or "") + ''
substituteInPlace "$out/bin/playwright" \
--replace-fail " $out/lib/node_modules/@playwright/test/cli.js " \
" --max-semi-space-size=1 $out/lib/node_modules/@playwright/test/cli.js "
'';
});
playwrightCore = pkgs: "${playwrightForE2e pkgs}/lib/node_modules/playwright-core";
# Keys and dependency paths are relative to tests/.
e2eSpecInputs = {
"harness-ui/resume.spec.ts" = [ "codex-steer-relay.mjs" ];
"harness-ui/heic-photo.spec.ts" = [ "data/colors.heic" ];
"harness-ui/ask-answer.spec.ts" = [ "harness-ui/ask-answer-helpers.ts" ];
"ui/ask-answer.spec.ts" = [ "harness-ui/ask-answer-helpers.ts" ];
"harness-ui/export-html.spec.ts" = [ "ui/export-cdn-fixtures.ts" ];
"ui/export-cdn-fixtures.spec.ts" = [ "ui/export-cdn-fixtures.ts" ];
"ui/export-html.spec.ts" = [
"ui/export-cdn-fixtures.ts"
"harness-ui/semantic-shell-helpers.ts"
];
"ui/shell-parser-assets.spec.ts" = [ "ui/export-cdn-fixtures.ts" ];
"ui/discover.spec.ts" = [ "ui/discover-helpers.ts" ];
"harness-ui/image-paste.spec.ts" = [ "harness-ui/image-paste-helpers.ts" ];
"ui/image-paste.spec.ts" = [ "harness-ui/image-paste-helpers.ts" ];
"harness-ui/semantic-shell.spec.ts" = [ "harness-ui/semantic-shell-helpers.ts" ];
"ui/semantic-shell.spec.ts" = [ "harness-ui/semantic-shell-helpers.ts" ];
};
backendSrc = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./source
./tests/data/colors.heic
./dub.sdl
./scripts/generate-version.sh
./dub.selections.json
];
};
frontendSrc = lib.fileset.toSource {
root = ./web;
fileset = lib.fileset.unions [
./web/src
./web/public
./web/scripts
./web/index.html
./web/export.html
./web/package.json
./web/package-lock.json
./web/tsconfig.json
./web/tsconfig.tests.json
./web/vite.config.ts
./web/vite.export.config.ts
./web/vitest.config.ts
./web/eslint.config.mjs
./web/.prettierignore
./web/.stylelintrc.json
];
};
screenshotSrc = lib.cleanSourceWith {
src = ./docs/tools/screenshots;
filter = _path: _type: true;
};
mockApiSrc = lib.cleanSourceWith {
src = ./tests/mock-api;
filter = _path: _type: true;
};
# The browser fixtures exercise staging in their private /tmp. The
# image-jail check exercises these arguments with real Bubblewrap.
fakeHelperJail = ''
runHelperJail() (
set -e
local staged=()
trap 'rm -f -- "''${staged[@]}"' EXIT
while [[ $# -gt 0 ]]; do
case "$1" in
--)
shift
if [[ $# -gt 0 ]]; then
env -i "$@"
return
fi
break
;;
--file)
staged+=("$3")
cat <&"$2" > "$3"
shift 3
;;
--symlink)
ln -s -- "$2" "$3"
staged+=("$3")
shift 3
;;
--chdir) cd -- "$2"; shift 2 ;;
--ro-bind) shift 3 ;;
--size|--tmpfs|--proc|--remount-ro) shift 2 ;;
--unshare-user|--unshare-ipc|--unshare-pid|--unshare-net|--unshare-uts|--unshare-cgroup|--disable-userns|--die-with-parent|--new-session|--clearenv)
shift ;;
*) echo "Unsupported helper jail option: $1" >&2; return 1 ;;
esac
done
echo "Missing helper jail command" >&2
return 1
)
for option in "$@"; do
case "$option" in
--) break ;;
--disable-userns) runHelperJail "$@"; exit ;;
esac
done
'';
# Wrap a buildPhase body so it executes with /tmp on tmpfs. The Nix
# sandbox chroot root sits on the host's btrfs filesystem (under
# /nix/store), and unredirected /tmp writes thrash that disk.
# Outer ns: --map-root-user to gain CAP_SYS_ADMIN for mounting.
# Inner ns: --map-user=1000 because some agent CLIs refuse to run
# as root.
runInTmpfsNs = pkgs: body: ''
${pkgs.util-linux}/bin/unshare --user --map-root-user --mount bash <<'OUTER_NS'
${pkgs.util-linux}/bin/mount -t tmpfs tmpfs /tmp || { echo "FATAL: tmpfs mount failed" >&2; exit 1; }
chmod 1777 /tmp
${pkgs.util-linux}/bin/unshare --user --map-user=1000 bash <<'INNER_NS'
${body}
INNER_NS
OUTER_NS
'';
in
{
packages = forAllSystems (system:
let
pkgs = pkgsFor system;
nodejs = pkgs.nodejs_22;
# Codex CLI — pre-built static binary from npm
codexVersion = "0.171.0";
codexSrc = {
x86_64-linux = {
url = "https://registry.npmjs.org/@openai/codex/-/codex-${codexVersion}-linux-x64.tgz";
hash = "sha256-4T1nr7BTPMYWC19BQOStB+Ks2Hrbqggbv2m4LpDPTlU=";
triple = "x86_64-unknown-linux-musl";
};
aarch64-linux = {
url = "https://registry.npmjs.org/@openai/codex/-/codex-${codexVersion}-linux-arm64.tgz";
hash = "sha256-Jq4neIx9lirmQyGrpGc/kYuZtAxGVSRpML+WL6W4GwE=";
triple = "aarch64-unknown-linux-musl";
};
}.${system} or (throw "Codex CLI: unsupported system ${system}");
codex-cli = pkgs.stdenv.mkDerivation {
pname = "codex-cli";
version = codexVersion;
src = pkgs.fetchurl {
inherit (codexSrc) url hash;
};
unpackPhase = ''
tar xzf $src
'';
installPhase = ''
mkdir -p $out/bin $out/libexec
cp -R package/vendor/${codexSrc.triple} $out/libexec/codex
ln -s ../libexec/codex/bin/codex $out/bin/codex
'';
meta.platforms = [ "x86_64-linux" "aarch64-linux" ];
};
# Copilot CLI — pre-built binary from GitHub releases
copilotVersion = "1.0.9";
copilotSrc = {
x86_64-linux = {
url = "https://github.com/github/copilot-cli/releases/download/v${copilotVersion}/copilot-linux-x64.tar.gz";
hash = "sha256-FwRLHgibSeqOuq142SRIuPbIw8YVHgSgmwuH41kvWD0=";
};
aarch64-linux = {
url = "https://github.com/github/copilot-cli/releases/download/v${copilotVersion}/copilot-linux-arm64.tar.gz";
hash = "sha256-YFaVWsztnMBG3xo4DSAPzlEAMTPLRCYUt34G8M7/yls=";
};
}.${system} or (throw "Copilot CLI: unsupported system ${system}");
copilot-cli = pkgs.stdenv.mkDerivation {
pname = "copilot-cli";
version = copilotVersion;
src = pkgs.fetchurl { inherit (copilotSrc) url hash; };
dontStrip = true;
dontPatchELF = true;
dontFixup = true;
unpackPhase = ''tar xzf $src'';
installPhase = ''
mkdir -p $out/bin $out/lib
install -m755 copilot $out/lib/copilot
INTERP=$(cat $NIX_CC/nix-support/dynamic-linker)
LIB_PATH="${pkgs.lib.makeLibraryPath [
pkgs.stdenv.cc.cc.lib
pkgs.glibc
]}"
cat > $out/bin/copilot <<EOF
#!/bin/sh
export COPILOT_RUN_APP=1
exec $INTERP --library-path $LIB_PATH $out/lib/copilot "\$@"
EOF
chmod +x $out/bin/copilot
'';
meta.platforms = [ "x86_64-linux" "aarch64-linux" ];
};
# Seed the native launcher cache once for all Copilot test cells.
copilot-extracted = pkgs.runCommand "copilot-extracted-${copilotVersion}" { } ''
export HOME="$TMPDIR/copilot-home"
mkdir -p "$HOME" "$out"
COPILOT_CACHE_HOME="$out" ${copilot-cli}/bin/copilot --no-auto-update --version
set -- "$out"/pkg/*/"${copilotVersion}"
if [ "$#" -ne 1 ] || [ ! -f "$1/.extraction-complete" ] || [ ! -f "$1/app.js" ]; then
echo "Copilot did not extract the expected ${copilotVersion} payload" >&2
exit 1
fi
'';
frontend = pkgs.buildNpmPackage {
pname = "cydo-frontend";
inherit version;
src = frontendSrc;
inherit nodejs;
npmDepsHash = "sha256-jciXG6JhFx0s6j4dO5K3AgkVbm987vPLNIVdEJeLHn8=";
buildPhase = ''
runHook preBuild
npm run build
npm run build:export
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/dist $out/dist-export
cp -r dist/. $out/dist/
cp -r dist-export/. $out/dist-export/
node scripts/third-party-notices.mjs "$out/notices.txt"
runHook postInstall
'';
postInstall = ''
for asset in manifest.json favicon.svg apple-touch-icon.png icon-192.png icon-512.png; do
test -f "$out/dist/$asset"
done
'';
};
exportCdnFixtures = pkgs.buildNpmPackage {
pname = "cydo-export-cdn-fixtures";
inherit version;
src = frontendSrc;
inherit nodejs;
npmDepsHash = "sha256-jciXG6JhFx0s6j4dO5K3AgkVbm987vPLNIVdEJeLHn8=";
dontNpmBuild = true;
installPhase = ''
runHook preInstall
fixtureRoot="$TMPDIR/export-cdn-fixtures"
mkdir -p "$fixtureRoot"
node scripts/export-cdn-manifest.mjs --fixture-root "$fixtureRoot"
node scripts/export-cdn-manifest.mjs --validate-fixture "$fixtureRoot"
mkdir -p "$out"
cp -a "$fixtureRoot/." "$out/"
runHook postInstall
'';
};
backendCommon = {
pname = "cydo";
inherit version;
src = backendSrc;
CYDO_SKIP_VERSION_GENERATION = "1";
dubLock = ./dub-lock.json;
dontStrip = true;
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.sqlite pkgs.openssl pkgs.zlib ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
install -Dm755 build/cydo $out/bin/
runHook postInstall
'';
meta = with pkgs.lib; {
description = "Multi-agent orchestration with Claude Code";
platforms = platforms.linux;
};
};
protocol-codegen = pkgs.buildDubPackage {
pname = "cydo-protocol-codegen";
inherit version;
src = backendSrc;
CYDO_SKIP_VERSION_GENERATION = "1";
dubLock = ./dub-lock.json;
dontStrip = true;
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.openssl pkgs.zlib ];
buildPhase = ''
runHook preBuild
dub build cydo:protocol-codegen --skip-registry=all
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
install -Dm755 build/cydo_protocol-codegen $out/bin/protocol-codegen
runHook postInstall
'';
};
backend = pkgs.buildDubPackage (backendCommon // {
dubBuildType = "release-debug";
});
backendStaticMusl = import ./packaging/static-musl.nix {
inherit pkgs backendCommon;
};
releaseTarball = import ./packaging/release {
inherit pkgs backendStaticMusl frontend;
inherit releaseVersion;
defs = ./defs;
};
backendDebug = pkgs.buildDubPackage (backendCommon // {
dubBuildType = "debug";
});
mkCydo = backendPkg: { releaseVersion ? null, defs ? ./defs }: pkgs.stdenv.mkDerivation {
pname = "cydo";
version = if releaseVersion == null then "unknown" else releaseVersion;
dontUnpack = true;
nativeBuildInputs = [ pkgs.makeWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin $out/share/cydo/web
install -Dm755 ${backendPkg}/bin/cydo $out/share/cydo/
ln -s ${frontend}/dist $out/share/cydo/web/dist
ln -s ${frontend}/dist-export $out/share/cydo/web/dist-export
ln -s ${defs} $out/share/cydo/defs
${lib.optionalString (releaseVersion != null) ''
printf '%s' ${releaseVersion} > $out/share/cydo/cydo-version.txt
''}
makeWrapper $out/share/cydo/cydo $out/bin/cydo \
--suffix PATH : ${lib.makeBinPath [ pkgs.bubblewrap pkgs.libheif.bin pkgs.libjpeg_turbo.bin ]}
runHook postInstall
'';
meta = with pkgs.lib; {
description = "Multi-agent orchestration with Claude Code";
platforms = platforms.linux;
mainProgram = "cydo";
};
};
testDefs = pkgs.runCommand "cydo-test-defs" {} ''
cp -r ${./defs} $out
chmod -R u+w $out
cp ${./tests/defs/task-types.yaml} $out/task-types.yaml
'';
cydo = mkCydo backend { inherit releaseVersion; };
cydoUnversioned = mkCydo backend { };
cydoDebug = mkCydo backendDebug { };
cydoTest = mkCydo backendDebug { defs = testDefs; };
fake-bwrap = pkgs.writeShellScript "bwrap" ''
${fakeHelperJail}
chdir=""
clearenv=0
clearenvKeys=()
clearenvValues=()
setenvAfterClearenv() {
local key="$1"
local value="$2"
local i
for i in "''${!clearenvKeys[@]}"; do
if [[ "''${clearenvKeys[$i]}" == "$key" ]]; then
clearenvValues[$i]="$key=$value"
return
fi
done
clearenvKeys+=("$key")
clearenvValues+=("$key=$value")
}
while [[ $# -gt 0 ]]; do
case "$1" in
--) shift; break ;;
--setenv)
if [[ "$clearenv" == 1 ]]; then
setenvAfterClearenv "$2" "$3"
else
export "$2=$3"
fi
shift 3
;;
--chdir) chdir="$2"; shift 2 ;;
--clearenv)
clearenv=1
clearenvKeys=()
clearenvValues=()
shift
;;
--bind|--ro-bind|--symlink|--dev|--proc|--tmpfs) shift 2 ;;
*) shift ;;
esac
done
[[ -n "$chdir" ]] && cd "$chdir"
if [[ "$clearenv" == 1 ]]; then
exec env -i "''${clearenvValues[@]}" "$@"
fi
exec "$@"
'';
screenshots = pkgs.stdenv.mkDerivation {
pname = "cydo-screenshots";
inherit version;
src = screenshotSrc;
fixtures = screenshot-fixtures;
cydo = cydoUnversioned;
nativeBuildInputs = with pkgs; [
playwright-test
nodejs_22
curl
claude-code
git
sqlite
websocat
];
FONTCONFIG_FILE = pkgs.makeFontsConf {
fontDirectories = with pkgs; [ roboto jetbrains-mono liberation_ttf ];
};
HOME = "/tmp/playwright-home";
CI = "1";
ANTHROPIC_BASE_URL = "http://127.0.0.1:9100";
ANTHROPIC_API_KEY = "test-key-mock";
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1";
DISABLE_TELEMETRY = "1";
DISABLE_AUTOUPDATER = "1";
CLAUDE_CONFIG_DIR = "/tmp/screenshot-claude-home";
CLAUDE_CODE_ENTRYPOINT = "";
CLAUDE_CODE_OAUTH_TOKEN = "";
CYDO_REAL_CLAUDE_BIN = "";
OPENAI_BASE_URL = "";
OPENAI_API_KEY = "";
CODEX_API_KEY = "";
CODEX_HOME = "";
COPILOT_HOME = "";
COPILOT_GITHUB_TOKEN = "";
GH_TOKEN = "";
GITHUB_TOKEN = "";
COPILOT_MODEL = "";
HTTPS_PROXY = "";
NODE_TLS_REJECT_UNAUTHORIZED = "";
MOCK_SUGGESTIONS = ''["investigate the write latency regression", "add rate limiting to the websocket handler", "run the full test suite"]'';
buildPhase = let
fake-bwrap-local = pkgs.writeShellScript "bwrap" ''
${fakeHelperJail}
chdir=""
clearenv=0
clearenvKeys=()
clearenvValues=()
setenvAfterClearenv() {
local key="$1"
local value="$2"
local i
for i in "''${!clearenvKeys[@]}"; do
if [[ "''${clearenvKeys[$i]}" == "$key" ]]; then
clearenvValues[$i]="$key=$value"
return
fi
done
clearenvKeys+=("$key")
clearenvValues+=("$key=$value")
}
while [[ $# -gt 0 ]]; do
case "$1" in
--) shift; break ;;
--setenv)
if [[ "$clearenv" == 1 ]]; then
setenvAfterClearenv "$2" "$3"
else
export "$2=$3"
fi
shift 3
;;
--chdir) chdir="$2"; shift 2 ;;
--clearenv)
clearenv=1
clearenvKeys=()
clearenvValues=()
shift
;;
--bind|--ro-bind|--symlink|--dev|--proc|--tmpfs) shift 2 ;;
*) shift ;;
esac
done
[[ -n "$chdir" ]] && cd "$chdir"
if [[ "$clearenv" == 1 ]]; then
exec env -i "''${clearenvValues[@]}" "$@"
fi
exec "$@"
'';
in runInTmpfsNs pkgs ''
mkdir -p /tmp/playwright-home
# ── Claude CLI config ──────────────────────────────────────
mkdir -p $CLAUDE_CONFIG_DIR
cat > $CLAUDE_CONFIG_DIR/settings.json <<'SETTINGS'
{"hasCompletedOnboarding":true,"theme":"dark","skipDangerousModePermissionPrompt":true,"autoUpdates":false}
SETTINGS
# ── Git workspaces ──────────────────────────────────────────
for ws in \
/tmp/ws/personal/dotfiles /tmp/ws/personal/k4webadmin \
/tmp/ws/open-source/cydo /tmp/ws/open-source/ae /tmp/ws/open-source/dunamis /tmp/ws/open-source/graphqld2 /tmp/ws/open-source/dfeed \
/tmp/ws/external/nixpkgs /tmp/ws/external/linux /tmp/ws/external/forgejo /tmp/ws/external/swayfx /tmp/ws/external/nix; do
mkdir -p $ws
cd $ws
${pkgs.git}/bin/git init -q
${pkgs.git}/bin/git config user.email "test@test"
${pkgs.git}/bin/git config user.name "Test"
echo "test" > README.md
${pkgs.git}/bin/git add . && ${pkgs.git}/bin/git commit -qm "init"
done
# ── JSONL fixtures ─────────────────────────────────────────
mkdir -p $CLAUDE_CONFIG_DIR/projects/-tmp-ws-open-source-cydo
cp $fixtures/sessions/-tmp-ws-cydo/*.jsonl $CLAUDE_CONFIG_DIR/projects/-tmp-ws-open-source-cydo/
# Reuse 1658's JSONL for the child-less conversation task (9060)
cp $fixtures/sessions/-tmp-ws-cydo/ee043871-4594-412d-ae25-c41bc3774a02.jsonl \
$CLAUDE_CONFIG_DIR/projects/-tmp-ws-open-source-cydo/f8a23c01-7b9e-4d12-b5a4-c2e7d3f16890.jsonl
chmod u+w $CLAUDE_CONFIG_DIR/projects/-tmp-ws-open-source-cydo/*.jsonl
mkdir -p $CLAUDE_CONFIG_DIR/projects/-tmp-ws-open-source-ae
cp $fixtures/sessions/-tmp-ws-ae/*.jsonl $CLAUDE_CONFIG_DIR/projects/-tmp-ws-open-source-ae/
# ── fake-bwrap ─────────────────────────────────────────────
mkdir -p /tmp/fake-bin
ln -sf ${fake-bwrap-local} /tmp/fake-bin/bwrap
export PATH="/tmp/fake-bin:$PATH"
# ── CyDo workspace config ─────────────────────────────────
mkdir -p /tmp/playwright-home/.config/cydo
cat ${./tests/lib/test-config-base.yaml} > /tmp/playwright-home/.config/cydo/config.yaml
cat >> /tmp/playwright-home/.config/cydo/config.yaml <<'CYDO_CFG'
default_agent: claude
workspaces:
personal:
root: /tmp/ws/personal
open-source:
root: /tmp/ws/open-source
external:
root: /tmp/ws/external
CYDO_CFG
# ── Mock API ───────────────────────────────────────────────
mkdir -p /tmp/mock-api
cp ${mockApiSrc}/server.mjs /tmp/mock-api/
cp ${mockApiSrc}/patterns.mjs /tmp/mock-api/
cp ${mockApiSrc}/loop-monitor.mjs /tmp/mock-api/
MOCK_API_PORT=9100 MOCK_SUGGESTIONS="$MOCK_SUGGESTIONS" MOCK_STALL_SYSTEM=1 ${pkgs.nodejs_22}/bin/node /tmp/mock-api/server.mjs &
MOCK_PID=$!
for i in $(seq 1 15); do
if curl -sf http://127.0.0.1:9100/api/hello >/dev/null 2>&1; then break; fi
sleep 1
done
# ── Phase 1: Start CyDo to create DB schema ───────────────
cd /tmp/ws/open-source/cydo
printf screenshot | "$cydo/bin/cydo" passwd
CYDO_LISTEN_PORT=3950 "$cydo/bin/cydo" &
CYDO_PID=$!
for i in $(seq 1 30); do
if curl -sf http://127.0.0.1:3950/auth/login >/dev/null 2>&1; then break; fi
sleep 1
done
kill $CYDO_PID
wait $CYDO_PID 2>/dev/null || true
sleep 1
# ── Phase 2: Seed database ─────────────────────────────────
${pkgs.sqlite}/bin/sqlite3 /tmp/playwright-home/.local/share/cydo/cydo.db < $fixtures/init.sql
# ── Phase 3: Restart CyDo with seeded data ────────────────
CYDO_LISTEN_PORT=3950 "$cydo/bin/cydo" &
CYDO_PID=$!
for i in $(seq 1 30); do
if curl -sf http://127.0.0.1:3950/auth/login >/dev/null 2>&1; then break; fi
sleep 1
done
# Give time for alive/waiting/active tasks to resume
sleep 5
curl -fsS -c /tmp/cydo-screenshot-cookies \
-H 'Origin: http://127.0.0.1:3950' --data 'password=screenshot' \
http://127.0.0.1:3950/auth/login
CYDO_SCREENSHOT_COOKIE=$(awk '$6 ~ /^cydo-session-/ { print $6 "=" $7 }' /tmp/cydo-screenshot-cookies)
test -n "$CYDO_SCREENSHOT_COOKIE"
# Send "stall session" to waiting chain tasks via WebSocket.
# This makes their claude processes call the mock API, which stalls,
# setting isProcessing=true — required for the "waiting" sidebar icon.
for tid in 1658 1676 1677 1700; do
nonce=$(${pkgs.util-linux}/bin/uuidgen --random)
printf '{"type":"message","tid":%s,"correlation_id":"%s","content":[{"type":"text","text":"stall session"}]}\n' "$tid" "$nonce"
done | ${pkgs.websocat}/bin/websocat -n -H "Cookie: $CYDO_SCREENSHOT_COOKIE" ws://127.0.0.1:3950/ws &
WSCAT_PID=$!
# Wait for the stall to take effect (API calls reach mock, isProcessing=true)
sleep 3
kill $WSCAT_PID 2>/dev/null || true
# ── Capture screenshots ────────────────────────────────────
mkdir -p /tmp/screenshots
export CYDO_PORT=3950
export SCREENSHOT_OUTPUT=/tmp/screenshots
cp -r $src /tmp/capture
chmod -R u+w /tmp/capture
cd /tmp/capture
playwright test capture.spec.ts || CAPTURE_RESULT=$?
# ── Cleanup ────────────────────────────────────────────────
kill $CYDO_PID 2>/dev/null || true
kill $MOCK_PID 2>/dev/null || true
wait $CYDO_PID 2>/dev/null || true
wait $MOCK_PID 2>/dev/null || true
if [ "''${CAPTURE_RESULT:-0}" != "0" ]; then
echo "Screenshot capture failed with exit code ''${CAPTURE_RESULT}"
exit 1
fi
# Copy screenshots out of the tmpfs before the namespace exits.
mkdir -p /build/screenshots-out
cp /tmp/screenshots/*.png /build/screenshots-out/
'';
installPhase = ''
mkdir -p $out/docs/screenshots
cp /build/screenshots-out/*.png $out/docs/screenshots/
'';
};
in
{
inherit frontend exportCdnFixtures backend backendDebug protocol-codegen codex-cli copilot-cli copilot-extracted cydo cydoDebug cydoTest fake-bwrap screenshots;
default = cydo;
} // lib.optionalAttrs (system == "x86_64-linux") {
inherit backendStaticMusl releaseTarball;
});
checks = forAllSystems (system:
let
pkgs = pkgsFor system;
cydoDebug = self.packages.${system}.cydoDebug;
cydoTest = self.packages.${system}.cydoTest;
backendDebug = self.packages.${system}.backendDebug;
codex = self.packages.${system}.codex-cli;
copilot = self.packages.${system}.copilot-cli;
# The test sandbox clears the environment before spawning Copilot.
copilotForTests = pkgs.writeShellScriptBin "copilot" ''
export COPILOT_CACHE_HOME=${self.packages.${system}.copilot-extracted}
exec ${copilot}/bin/copilot "$@"
'';
exportCdnFixtures = self.packages.${system}.exportCdnFixtures;
# Fake bwrap that strips sandbox flags and exec's the inner command.
# Keep the browser tests independent of agent sandbox setup.
fake-bwrap = pkgs.writeShellScript "bwrap" ''
${fakeHelperJail}
chdir=""
clearenv=0
clearenvKeys=()
clearenvValues=()
setenvAfterClearenv() {
local key="$1"
local value="$2"
local i
for i in "''${!clearenvKeys[@]}"; do
if [[ "''${clearenvKeys[$i]}" == "$key" ]]; then
clearenvValues[$i]="$key=$value"
return
fi
done
clearenvKeys+=("$key")
clearenvValues+=("$key=$value")
}
while [[ $# -gt 0 ]]; do
case "$1" in
--) shift; break ;;
--setenv)
if [[ "$clearenv" == 1 ]]; then
setenvAfterClearenv "$2" "$3"
else
export "$2=$3"
fi
shift 3
;;
--chdir) chdir="$2"; shift 2 ;;
--clearenv)
clearenv=1
clearenvKeys=()
clearenvValues=()
shift
;;
--symlink|--dev|--proc|--tmpfs) shift 2 ;;
--bind|--ro-bind)
if [ ! -e "$2" ]; then
echo "bwrap: Can't find source path $2: No such file or directory" >&2
exit 1
fi
shift 2
;;
*) shift ;;
esac
done
[[ -n "$chdir" ]] && cd "$chdir"
if [[ "$clearenv" == 1 ]]; then
exec env -i "''${clearenvValues[@]}" "$@"
fi
exec "$@"
'';
fail-claude = pkgs.writeShellScript "fail-claude" ''
echo "Error: simulated process failure for testing" >&2
exit 1
'';
in
let
cellSupport = [
./tests/claude-capture-wrapper.sh
./tests/defs/task-types.yaml
./tests/extra-fields-inject.mjs
./tests/extra-fields-wrapper.sh
./tests/lib/test-config-base.yaml
./tests/mock-api/certs/proxy.crt
./tests/mock-api/certs/proxy.key
./tests/mock-api/copilot-proxy.mjs
./tests/mock-api/loop-monitor.mjs
./tests/mock-api/patterns.mjs
./tests/mock-api/server.mjs
./tests/sandbox-init.py
./tests/suggestion-one-shot-fail-wrapper.sh
./tests/title-one-shot-env-wrapper.sh
./tests/title-switch-overlap-signal-wrapper.sh
];
playwrightSupport = [
./tests/harness-ui/fixtures.ts
./tests/lib/agent.ts
./tests/lib/backend.ts
./tests/lib/config.ts
./tests/lib/history.ts
./tests/playwright-fixtures.ts
./tests/playwright.config.ts
./tests/ui/fixtures.ts
];
specInputPath = file:
let path = ./tests + "/${file}";
in
assert lib.assertMsg (builtins.pathExists path)
"Missing integration spec input tests/${file}";
assert lib.assertMsg (builtins.readFileType path == "regular")
"Integration spec input tests/${file} must be a file";
path;
extraSpecPaths = lib.mapAttrs (spec: files:
assert lib.assertMsg (builtins.elem spec testFiles)
"Unknown integration spec tests/${spec} in e2eSpecInputs";
map specInputPath files
) e2eSpecInputs;
cellSources = lib.genAttrs testFiles (specFile: lib.fileset.toSource {
root = ./tests;
fileset = lib.fileset.unions (cellSupport
++ lib.optionals (kinds.${testFileKind specFile}.runner == "playwright") playwrightSupport
++ [ (specInputPath specFile) ] ++ (extraSpecPaths.${specFile} or []));
});
playwrightResultSources = lib.fileset.toSource {
root = ./web;
fileset = lib.fileset.unions [
./web/src/toolResultFields.ts
./web/src/toolIdentity.ts
];
};
playwrightFontConfig = pkgs.makeFontsConf {
fontDirectories = with pkgs; [ roboto jetbrains-mono liberation_ttf ];
};
mkCell = {
name,
specFile,
title,
line,
stem,
runner,
agentType,
kind,
claudeBin ? null,
extraNativeBuildInputs ? [],
profile ? false,
} @ cell:
let
testMatch = "${specFile}:${toString line}";
testRunner = {
playwright = {
inputs = [ (playwrightForE2e pkgs) ];
command = "playwright test ${lib.escapeShellArg testMatch} --project=${kind} --workers=1";
};
node = {
inputs = [];
command = "env CYDO_SHELL_PARSER_ASSETS=${self.packages.${system}.frontend}/dist/assets node --enable-source-maps ${lib.escapeShellArgs [ "${harnessBundle}/${lib.removeSuffix ".test.ts" specFile}.mjs" (builtins.baseNameOf stem) title ]}";
};
}.${runner};
in pkgs.stdenv.mkDerivation ({
pname = "cydo-${lib.optionalString profile "profile-"}integration-${name}";
inherit version;
src = cellSources.${specFile};
nativeBuildInputs = with pkgs; [
nodejs_22
curl
claude-code
codex
git
sqlite
] ++ lib.optional (kind == "ui" && stem == "auth") pkgs.which
++ testRunner.inputs ++ extraNativeBuildInputs;
CYDO_TEST_AGENT = agentType;
HOME = "/tmp/playwright-home";
CI = "1";
ANTHROPIC_BASE_URL = "http://127.0.0.1:9000";
ANTHROPIC_API_KEY = "test-key-mock";
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1";
CLAUDE_CODE_BASH_EDIT_DIFF = "1";
DISABLE_TELEMETRY = "1";
DISABLE_AUTOUPDATER = "1";
CLAUDE_CONFIG_DIR = "/tmp/claude-test-home";
OPENAI_BASE_URL = "http://127.0.0.1:9000/v1";
OPENAI_API_KEY = "test-key-mock";
CODEX_API_KEY = "";
CODEX_HOME = "/tmp/codex-test-home";
CLAUDE_CODE_ENTRYPOINT = "";
CLAUDE_CODE_OAUTH_TOKEN = "";
CYDO_REAL_CLAUDE_BIN = "";
COPILOT_HOME = "";
COPILOT_GITHUB_TOKEN = "";
GH_TOKEN = "";
GITHUB_TOKEN = "";
COPILOT_MODEL = "";
HTTPS_PROXY = "";
NODE_TLS_REJECT_UNAUTHORIZED = "";
# Fixed port env vars — fixtures inherit these
CYDO_LISTEN_PORT = "3940";
buildPhase = runInTmpfsNs pkgs ''
CELL_START=$EPOCHREALTIME
${lib.optionalString profile ''
${pkgs.python3}/bin/python3 ${./docs/tools/e2e-cell-memory.py} "$NIX_BUILD_TOP/memory.jsonl" &
MEMORY_PID=$!
''}
mkdir -p /tmp/playwright-home
mkdir -p $CLAUDE_CONFIG_DIR
cat > $CLAUDE_CONFIG_DIR/settings.json <<'SETTINGS'
{"hasCompletedOnboarding":true,"theme":"dark","skipDangerousModePermissionPrompt":true,"autoUpdates":false}
SETTINGS
mkdir -p $CODEX_HOME
cat > $CODEX_HOME/config.toml <<'CODEXCFG'
model = "codex-mini-latest"
model_provider = "cydo-mock"
approval_policy = "never"
sandbox_mode = "danger-full-access"
[model_providers.cydo-mock]
name = "CyDo mock OpenAI"
base_url = "http://127.0.0.1:9000/v1"
wire_api = "responses"
requires_openai_auth = false
supports_websockets = false
CODEXCFG
mkdir -p $CODEX_HOME/shell_snapshots
mkdir -p /tmp/cydo-test-workspace
mkdir -p /tmp/cydo-test-workspace/.claude
cd /tmp/cydo-test-workspace
${pkgs.git}/bin/git init -q
${pkgs.git}/bin/git config user.email "test@test"
${pkgs.git}/bin/git config user.name "Test"
echo "test" > README.md
${pkgs.git}/bin/git add . && ${pkgs.git}/bin/git commit -qm "init"