-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
606 lines (525 loc) · 16.7 KB
/
Copy pathCMakeLists.txt
File metadata and controls
606 lines (525 loc) · 16.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
# @file CMakeLists.txt
# @author Gaspard Kirira
#
# Copyright 2026, Gaspard Kirira. All rights reserved.
# https://github.com/vixcpp/vix
# Use of this source code is governed by a MIT license
# that can be found in the License file.
#
# ====================================================================
# Vix.cpp - AI Agent Module
# ====================================================================
# Purpose:
# Local-first AI agent module for Vix.cpp.
# Provides a controlled agent runtime capable of:
# - preparing and scanning a local workspace
# - building model requests
# - using local model providers such as Ollama
# - exposing safe tools such as file reading and command execution
# - returning structured results and errors
#
# The module is designed to be local-first, explicit, and safe by
# default. It does not require a cloud model provider. The first
# provider is Ollama, accessed through local process execution.
#
# Public Targets:
# - vix_ai_agent : The actual library target
# - vix::ai_agent : Namespaced alias for consumers
#
# Public Dependencies:
# - vix::error
# - vix::json
# - vix::fs
# - vix::path
# - vix::process
# - vix::env
# - vix::time
# - vix::crypto
# - vix::log
# - vix::cache
#
# Installation/Export:
# - Umbrella build exports into: VixTargets
# - Standalone build exports into: vix_ai_agentTargets
# ====================================================================
cmake_minimum_required(VERSION 3.20)
project(vix_ai_agent
VERSION 0.1.0
DESCRIPTION "Local-first AI agent module for Vix.cpp"
LANGUAGES CXX
)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# --------------------------------------------------------------------
# Global settings
# --------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# --------------------------------------------------------------------
# Options
# --------------------------------------------------------------------
option(VIX_AI_AGENT_BUILD_TESTS "Build vix ai agent tests" OFF)
option(VIX_AI_AGENT_BUILD_EXAMPLES "Build vix ai agent examples" OFF)
option(VIX_AI_AGENT_FETCH_ERROR "Auto-fetch vix::error if missing" ON)
option(VIX_AI_AGENT_FETCH_JSON "Auto-fetch vix::json if missing" ON)
option(VIX_AI_AGENT_FETCH_FS "Auto-fetch vix::fs if missing" ON)
option(VIX_AI_AGENT_FETCH_PATH "Auto-fetch vix::path if missing" ON)
option(VIX_AI_AGENT_FETCH_PROCESS "Auto-fetch vix::process if missing" ON)
option(VIX_AI_AGENT_FETCH_NET "Auto-fetch vix::net if missing" ON)
option(VIX_AI_AGENT_FETCH_ENV "Auto-fetch vix::env if missing" ON)
option(VIX_AI_AGENT_FETCH_TIME "Auto-fetch vix::time if missing" ON)
option(VIX_AI_AGENT_FETCH_CRYPTO "Auto-fetch vix::crypto if missing" ON)
option(VIX_AI_AGENT_FETCH_LOG "Auto-fetch vix::log if missing" ON)
option(VIX_AI_AGENT_FETCH_CACHE "Auto-fetch vix::cache if missing" ON)
option(VIX_AI_AGENT_FETCH_IO "Auto-fetch vix::io if missing for examples" ON)
# --------------------------------------------------------------------
# Export set selection
# --------------------------------------------------------------------
if(DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
set(VIX_AI_AGENT_EXPORT_SET VixTargets)
else()
set(VIX_AI_AGENT_EXPORT_SET vix_ai_agentTargets)
endif()
# --------------------------------------------------------------------
# Umbrella build policy
# --------------------------------------------------------------------
# When building inside the Vix umbrella, dependencies are managed by the
# umbrella project. The AI agent module must not FetchContent nor add
# sibling subdirectories in umbrella mode.
# --------------------------------------------------------------------
if(DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
set(VIX_AI_AGENT_FETCH_ERROR OFF CACHE BOOL "Auto-fetch vix::error if missing" FORCE)
set(VIX_AI_AGENT_FETCH_JSON OFF CACHE BOOL "Auto-fetch vix::json if missing" FORCE)
set(VIX_AI_AGENT_FETCH_FS OFF CACHE BOOL "Auto-fetch vix::fs if missing" FORCE)
set(VIX_AI_AGENT_FETCH_PATH OFF CACHE BOOL "Auto-fetch vix::path if missing" FORCE)
set(VIX_AI_AGENT_FETCH_PROCESS OFF CACHE BOOL "Auto-fetch vix::process if missing" FORCE)
set(VIX_AI_AGENT_FETCH_NET OFF CACHE BOOL "Auto-fetch vix::net if missing" FORCE)
set(VIX_AI_AGENT_FETCH_ENV OFF CACHE BOOL "Auto-fetch vix::env if missing" FORCE)
set(VIX_AI_AGENT_FETCH_TIME OFF CACHE BOOL "Auto-fetch vix::time if missing" FORCE)
set(VIX_AI_AGENT_FETCH_CRYPTO OFF CACHE BOOL "Auto-fetch vix::crypto if missing" FORCE)
set(VIX_AI_AGENT_FETCH_LOG OFF CACHE BOOL "Auto-fetch vix::log if missing" FORCE)
set(VIX_AI_AGENT_FETCH_CACHE OFF CACHE BOOL "Auto-fetch vix::cache if missing" FORCE)
set(VIX_AI_AGENT_FETCH_IO OFF CACHE BOOL "Auto-fetch vix::io if missing for examples" FORCE)
endif()
# --------------------------------------------------------------------
# Dependency helper
# --------------------------------------------------------------------
function(vix_ai_agent_require_dependency target package_name sibling_dir fetch_option repo_url git_tag)
if(TARGET ${target})
return()
endif()
if(DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
message(FATAL_ERROR "[ai_agent] Umbrella build: ${target} must be provided before ai_agent.")
endif()
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../${sibling_dir}/CMakeLists.txt")
message(STATUS "[ai_agent] Adding ${sibling_dir} from sibling: ../${sibling_dir}")
add_subdirectory(
"${CMAKE_CURRENT_LIST_DIR}/../${sibling_dir}"
"${CMAKE_CURRENT_BINARY_DIR}/deps/${sibling_dir}"
EXCLUDE_FROM_ALL
)
else()
find_package(${package_name} CONFIG QUIET)
endif()
if(TARGET ${target})
return()
endif()
if(${fetch_option})
include(FetchContent)
message(STATUS "[ai_agent] Fetching ${target} via FetchContent")
FetchContent_Declare(${package_name}
GIT_REPOSITORY ${repo_url}
GIT_TAG ${git_tag}
)
FetchContent_MakeAvailable(${package_name})
endif()
if(NOT TARGET ${target})
message(FATAL_ERROR
"[ai_agent] ${target} not found. Install ${package_name}, provide the target, "
"add sibling module, or enable ${fetch_option}=ON."
)
endif()
endfunction()
function(vix_ai_agent_require_io_for_examples)
if(TARGET vix::io)
return()
endif()
if(DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
message(FATAL_ERROR "[ai_agent/examples] Umbrella build: vix::io must be provided before ai_agent examples.")
endif()
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../io/CMakeLists.txt")
message(STATUS "[ai_agent/examples] Adding io from sibling: ../io")
add_subdirectory(
"${CMAKE_CURRENT_LIST_DIR}/../io"
"${CMAKE_CURRENT_BINARY_DIR}/deps/io"
EXCLUDE_FROM_ALL
)
else()
find_package(vix_io CONFIG QUIET)
endif()
if(TARGET vix::io)
return()
endif()
if(VIX_AI_AGENT_FETCH_IO)
include(FetchContent)
message(STATUS "[ai_agent/examples] Fetching vix::io via FetchContent")
FetchContent_Declare(vix_io
GIT_REPOSITORY https://github.com/vixcpp/io.git
GIT_TAG v0.1.0
)
FetchContent_MakeAvailable(vix_io)
endif()
if(NOT TARGET vix::io)
message(FATAL_ERROR
"[ai_agent/examples] vix::io not found. Examples include <vix/print.hpp>, "
"so they require vix::io."
)
endif()
endfunction()
# --------------------------------------------------------------------
# Nested dependency policy
# --------------------------------------------------------------------
if(NOT TARGET vix::utils)
set(VIX_CRYPTO_FETCH_UTILS OFF CACHE BOOL "Auto-fetch vix::utils if missing" FORCE)
endif()
vix_ai_agent_require_dependency(
vix::error
vix_error
error
VIX_AI_AGENT_FETCH_ERROR
https://github.com/vixcpp/error.git
v0.1.0
)
vix_ai_agent_require_dependency(
vix::json
vix_json
json
VIX_AI_AGENT_FETCH_JSON
https://github.com/vixcpp/json.git
v0.1.0
)
vix_ai_agent_require_dependency(
vix::fs
vix_fs
fs
VIX_AI_AGENT_FETCH_FS
https://github.com/vixcpp/fs.git
v0.1.0
)
vix_ai_agent_require_dependency(
vix::path
vix_path
path
VIX_AI_AGENT_FETCH_PATH
https://github.com/vixcpp/path.git
v0.1.0
)
vix_ai_agent_require_dependency(
vix::process
vix_process
process
VIX_AI_AGENT_FETCH_PROCESS
https://github.com/vixcpp/process.git
v0.1.0
)
vix_ai_agent_require_dependency(
vix::net
vix_net
net
VIX_AI_AGENT_FETCH_NET
https://github.com/vixcpp/net.git
v0.1.0
)
vix_ai_agent_require_dependency(
vix::env
vix_env
env
VIX_AI_AGENT_FETCH_ENV
https://github.com/vixcpp/env.git
v0.1.0
)
vix_ai_agent_require_dependency(
vix::time
vix_time
time
VIX_AI_AGENT_FETCH_TIME
https://github.com/vixcpp/time.git
v0.1.0
)
vix_ai_agent_require_dependency(
vix::crypto
vix_crypto
crypto
VIX_AI_AGENT_FETCH_CRYPTO
https://github.com/vixcpp/crypto.git
v0.1.0
)
vix_ai_agent_require_dependency(
vix::log
vix_log
log
VIX_AI_AGENT_FETCH_LOG
https://github.com/vixcpp/log.git
v0.1.0
)
vix_ai_agent_require_dependency(
vix::cache
vix_cache
cache
VIX_AI_AGENT_FETCH_CACHE
https://github.com/vixcpp/cache.git
v0.1.0
)
# --------------------------------------------------------------------
# Sources
# --------------------------------------------------------------------
set(VIX_AI_AGENT_SOURCES
src/Agent.cpp
src/AgentConfigLoader.cpp
src/AgentError.cpp
src/AgentRunTimer.cpp
src/AgentWorkspace.cpp
src/crypto/AgentFingerprint.cpp
src/crypto/AgentId.cpp
src/workspace/FileScanPolicy.cpp
src/workspace/FileReader.cpp
src/workspace/ProjectScanner.cpp
src/ai/Agent.cpp
src/tools/ToolRegistry.cpp
src/tools/FileReadTool.cpp
src/tools/CommandTool.cpp
src/model/OllamaProvider.cpp
src/AgentConfigValidator.cpp
src/AgentRunStore.cpp
)
# --------------------------------------------------------------------
# Library target
# --------------------------------------------------------------------
add_library(vix_ai_agent STATIC
${VIX_AI_AGENT_SOURCES}
)
add_library(vix::ai_agent ALIAS vix_ai_agent)
target_compile_features(vix_ai_agent
PUBLIC
cxx_std_20
)
target_include_directories(vix_ai_agent
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(vix_ai_agent
PUBLIC
vix::error
vix::json
vix::fs
vix::path
vix::process
vix::net
vix::env
vix::time
vix::crypto
vix::log
vix::cache
)
set_target_properties(vix_ai_agent
PROPERTIES
OUTPUT_NAME vix_ai_agent
VERSION ${PROJECT_VERSION}
SOVERSION 0
EXPORT_NAME ai_agent
)
# --------------------------------------------------------------------
# Warnings
# --------------------------------------------------------------------
if(MSVC)
target_compile_options(vix_ai_agent PRIVATE /W4)
else()
target_compile_options(vix_ai_agent PRIVATE
-Wall
-Wextra
-Wpedantic
)
endif()
# --------------------------------------------------------------------
# Sanitizers
# --------------------------------------------------------------------
if(VIX_ENABLE_SANITIZERS AND NOT MSVC)
target_compile_options(vix_ai_agent PRIVATE
-fno-omit-frame-pointer
-fsanitize=address,undefined
)
target_link_options(vix_ai_agent PRIVATE
-fsanitize=address,undefined
)
endif()
# --------------------------------------------------------------------
# Install target and standalone package config
# --------------------------------------------------------------------
if(VIX_AI_AGENT_ENABLE_INSTALL)
install(TARGETS vix_ai_agent
EXPORT ${VIX_AI_AGENT_EXPORT_SET}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
if(NOT (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD))
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.h"
)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/vix_ai_agentConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/vix_ai_agentConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/vix_ai_agent"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/vix_ai_agentConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/vix_ai_agentConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/vix_ai_agentConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/vix_ai_agent"
)
install(EXPORT vix_ai_agentTargets
FILE vix_ai_agentTargets.cmake
NAMESPACE vix::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/vix_ai_agent"
)
endif()
endif()
# --------------------------------------------------------------------
# Examples
# --------------------------------------------------------------------
if(VIX_AI_AGENT_BUILD_EXAMPLES AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples")
vix_ai_agent_require_io_for_examples()
add_executable(vix_ai_agent_basic_agent
examples/basic_agent.cpp
)
target_link_libraries(vix_ai_agent_basic_agent
PRIVATE
vix::ai_agent
vix::io
)
add_executable(vix_ai_agent_scan_project
examples/scan_project.cpp
)
target_link_libraries(vix_ai_agent_scan_project
PRIVATE
vix::ai_agent
vix::io
)
add_executable(vix_ai_agent_ollama_agent
examples/ollama_agent.cpp
)
target_link_libraries(vix_ai_agent_ollama_agent
PRIVATE
vix::ai_agent
vix::io
)
add_executable(vix_ai_agent_with_cache
examples/agent_with_cache.cpp
)
target_link_libraries(vix_ai_agent_with_cache
PRIVATE
vix::ai_agent
vix::io
)
add_executable(vix_ai_agent_with_command_tool
examples/agent_with_command_tool.cpp
)
target_link_libraries(vix_ai_agent_with_command_tool
PRIVATE
vix::ai_agent
vix::io
)
add_executable(vix_ai_agent_custom_provider
examples/custom_provider.cpp
)
target_link_libraries(vix_ai_agent_custom_provider
PRIVATE
vix::ai_agent
vix::io
)
add_executable(vix_ai_agent_public_api
examples/public_api.cpp
)
target_link_libraries(vix_ai_agent_public_api
PRIVATE
vix::ai_agent
vix::io
)
endif()
# --------------------------------------------------------------------
# Tests
# --------------------------------------------------------------------
if(VIX_AI_AGENT_BUILD_TESTS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
include(CTest)
enable_testing()
add_executable(vix_ai_agent_tests
tests/AgentConfigTest.cpp
tests/AgentWorkspaceTest.cpp
tests/ProjectScannerTest.cpp
tests/ToolRegistryTest.cpp
tests/AgentRunTest.cpp
tests/FileScanPolicyTest.cpp
tests/FileReaderTest.cpp
tests/CommandToolTest.cpp
tests/AgentRunStoreTest.cpp
tests/AgentCacheTest.cpp
tests/AgentPublicApiTest.cpp
)
target_compile_features(vix_ai_agent_tests
PRIVATE
cxx_std_20
)
target_link_libraries(vix_ai_agent_tests
PRIVATE
vix::ai_agent
)
if(VIX_ENABLE_SANITIZERS AND NOT MSVC)
target_compile_options(vix_ai_agent_tests
PRIVATE
-fno-omit-frame-pointer
-fsanitize=address,undefined
)
target_link_options(vix_ai_agent_tests
PRIVATE
-fsanitize=address,undefined
)
endif()
add_test(
NAME vix_ai_agent_tests
COMMAND vix_ai_agent_tests
)
endif()
# --------------------------------------------------------------------
# Summary
# --------------------------------------------------------------------
message(STATUS "------------------------------------------------------")
message(STATUS "vix::ai_agent configured (${PROJECT_VERSION})")
message(STATUS "Mode: STATIC")
message(STATUS "Export set: ${VIX_AI_AGENT_EXPORT_SET}")
message(STATUS "Error target: vix::error")
message(STATUS "Json target: vix::json")
message(STATUS "Fs target: vix::fs")
message(STATUS "Path target: vix::path")
message(STATUS "Process target: vix::process")
message(STATUS "Net target: vix::net")
message(STATUS "Env target: vix::env")
message(STATUS "Time target: vix::time")
message(STATUS "Crypto target: vix::crypto")
message(STATUS "Log target: vix::log")
message(STATUS "Cache target: vix::cache")
message(STATUS "Install/export: ${VIX_AI_AGENT_ENABLE_INSTALL}")
message(STATUS "Include dir: ${CMAKE_CURRENT_SOURCE_DIR}/include")
message(STATUS "Build tests: ${VIX_AI_AGENT_BUILD_TESTS}")
message(STATUS "Build examples: ${VIX_AI_AGENT_BUILD_EXAMPLES}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "------------------------------------------------------")