forersi 0.0.1__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. forersi/__init__.py +169 -0
  2. forersi/__main__.py +110 -0
  3. forersi/agent_runtimes/__init__.py +126 -0
  4. forersi/agent_runtimes/antigravity/__init__.py +23 -0
  5. forersi/agent_runtimes/antigravity/acp.py +107 -0
  6. forersi/agent_runtimes/antigravity/agy_launch.py +126 -0
  7. forersi/agent_runtimes/antigravity/ephemeral.py +369 -0
  8. forersi/agent_runtimes/antigravity/headless.py +304 -0
  9. forersi/agent_runtimes/antigravity/native_status.py +362 -0
  10. forersi/agent_runtimes/antigravity/runtime.py +1869 -0
  11. forersi/agent_runtimes/antigravity/turn_events.py +90 -0
  12. forersi/agent_runtimes/antigravity/usage.py +388 -0
  13. forersi/agent_runtimes/authentication.py +136 -0
  14. forersi/agent_runtimes/base_runtime.py +1217 -0
  15. forersi/agent_runtimes/claude_code/__init__.py +23 -0
  16. forersi/agent_runtimes/claude_code/context_window.py +235 -0
  17. forersi/agent_runtimes/claude_code/record_file.py +99 -0
  18. forersi/agent_runtimes/claude_code/runtime.py +1156 -0
  19. forersi/agent_runtimes/claude_code/turn_events/.claude-plugin/plugin.json +1 -0
  20. forersi/agent_runtimes/claude_code/turn_events/hooks/hooks.json +1 -0
  21. forersi/agent_runtimes/claude_code/turn_events/hooks/input_stream.py +26 -0
  22. forersi/agent_runtimes/claude_code/turn_events/hooks/register.js +158 -0
  23. forersi/agent_runtimes/claude_code/usage.py +237 -0
  24. forersi/agent_runtimes/codex/__init__.py +23 -0
  25. forersi/agent_runtimes/codex/app_server.py +733 -0
  26. forersi/agent_runtimes/codex/runtime.py +856 -0
  27. forersi/agent_runtimes/codex/threads.py +262 -0
  28. forersi/agent_runtimes/codex/usage.py +278 -0
  29. forersi/agent_runtimes/context_window.py +191 -0
  30. forersi/agent_runtimes/ephemeral.py +201 -0
  31. forersi/agent_runtimes/installation.py +187 -0
  32. forersi/agent_runtimes/pane_activation.py +281 -0
  33. forersi/agent_runtimes/pi/__init__.py +23 -0
  34. forersi/agent_runtimes/pi/context_window.ts +97 -0
  35. forersi/agent_runtimes/pi/ipc.ts +308 -0
  36. forersi/agent_runtimes/pi/login.ts +126 -0
  37. forersi/agent_runtimes/pi/runtime.py +871 -0
  38. forersi/agent_runtimes/pi/tool_mcp.ts +68 -0
  39. forersi/agent_runtimes/pi/usage.py +188 -0
  40. forersi/agent_runtimes/pricing.py +507 -0
  41. forersi/agent_runtimes/saved_transcript.py +372 -0
  42. forersi/agent_runtimes/tool_mcp.py +347 -0
  43. forersi/agent_runtimes/tool_stdio.py +140 -0
  44. forersi/agent_runtimes/usage.py +511 -0
  45. forersi/agent_runtimes/usage_store.py +477 -0
  46. forersi/agent_runtimes/windows_job.py +114 -0
  47. forersi/cli/__init__.py +4 -0
  48. forersi/cli/parser.py +105 -0
  49. forersi/cli/validation.py +128 -0
  50. forersi/config.py +210 -0
  51. forersi/logging.py +75 -0
  52. forersi/main.py +140 -0
  53. forersi/reporting/__init__.py +299 -0
  54. forersi/reporting/chart_layout.py +1660 -0
  55. forersi/reporting/frontier_brief.py +682 -0
  56. forersi/reporting/progress_charts.py +1308 -0
  57. forersi/reporting/task_report.py +677 -0
  58. forersi/reporting/templates/task_report.md.j2 +148 -0
  59. forersi/rsi_workflows/__init__.py +214 -0
  60. forersi/rsi_workflows/default/__init__.py +9 -0
  61. forersi/rsi_workflows/default/agents/__init__.py +4 -0
  62. forersi/rsi_workflows/default/agents/checker/__init__.py +8 -0
  63. forersi/rsi_workflows/default/agents/checker/agent.py +484 -0
  64. forersi/rsi_workflows/default/agents/checker/tools.py +235 -0
  65. forersi/rsi_workflows/default/agents/coordinator/__init__.py +8 -0
  66. forersi/rsi_workflows/default/agents/coordinator/agent.py +129 -0
  67. forersi/rsi_workflows/default/agents/coordinator/tools.py +288 -0
  68. forersi/rsi_workflows/default/agents/experimenter/__init__.py +8 -0
  69. forersi/rsi_workflows/default/agents/experimenter/agent.py +416 -0
  70. forersi/rsi_workflows/default/agents/experimenter/tools.py +189 -0
  71. forersi/rsi_workflows/default/agents/explorer/__init__.py +8 -0
  72. forersi/rsi_workflows/default/agents/explorer/agent.py +347 -0
  73. forersi/rsi_workflows/default/agents/explorer/tools.py +546 -0
  74. forersi/rsi_workflows/default/agents/watchdog/__init__.py +4 -0
  75. forersi/rsi_workflows/default/agents/watchdog/agent.py +132 -0
  76. forersi/rsi_workflows/default/agents/watchdog/tools.py +56 -0
  77. forersi/rsi_workflows/default/checkpoint.py +253 -0
  78. forersi/rsi_workflows/default/knowledge_base/knowledge/index.md +6 -0
  79. forersi/rsi_workflows/default/knowledge_base/meta-knowledge/attribution/bottleneck-and-ceiling-attribution.md +40 -0
  80. forersi/rsi_workflows/default/knowledge_base/meta-knowledge/convergence/frontier-advancement-and-orthogonal-synthesis.md +40 -0
  81. forersi/rsi_workflows/default/knowledge_base/meta-knowledge/evaluation/staged-screening-and-proxy-fidelity.md +40 -0
  82. forersi/rsi_workflows/default/knowledge_base/meta-knowledge/index.md +26 -0
  83. forersi/rsi_workflows/default/knowledge_base/meta-knowledge/learning/distilling-verified-mechanisms-and-process-lessons.md +36 -0
  84. forersi/rsi_workflows/default/knowledge_base/meta-knowledge/research/upstream-code-issue-and-literature-search.md +54 -0
  85. forersi/rsi_workflows/default/prompts/checker/check_direction.j2 +62 -0
  86. forersi/rsi_workflows/default/prompts/checker/check_exploration.j2 +38 -0
  87. forersi/rsi_workflows/default/prompts/checker/check_finish.j2 +30 -0
  88. forersi/rsi_workflows/default/prompts/checker/check_progress.j2 +35 -0
  89. forersi/rsi_workflows/default/prompts/checker/check_reference_adoption.j2 +15 -0
  90. forersi/rsi_workflows/default/prompts/checker/system.j2 +14 -0
  91. forersi/rsi_workflows/default/prompts/common/system.j2 +23 -0
  92. forersi/rsi_workflows/default/prompts/common/user.j2 +9 -0
  93. forersi/rsi_workflows/default/prompts/coordinator/parse_task.j2 +6 -0
  94. forersi/rsi_workflows/default/prompts/coordinator/system.j2 +15 -0
  95. forersi/rsi_workflows/default/prompts/experimenter/check_experiments.j2 +26 -0
  96. forersi/rsi_workflows/default/prompts/experimenter/run_experiment.j2 +64 -0
  97. forersi/rsi_workflows/default/prompts/experimenter/study_framework.j2 +16 -0
  98. forersi/rsi_workflows/default/prompts/experimenter/system.j2 +12 -0
  99. forersi/rsi_workflows/default/prompts/explorer/conclude_exploration.j2 +40 -0
  100. forersi/rsi_workflows/default/prompts/explorer/exploration.j2 +45 -0
  101. forersi/rsi_workflows/default/prompts/explorer/prepare_baseline.j2 +20 -0
  102. forersi/rsi_workflows/default/prompts/explorer/select_direction.j2 +50 -0
  103. forersi/rsi_workflows/default/prompts/explorer/study_framework.j2 +12 -0
  104. forersi/rsi_workflows/default/prompts/explorer/system.j2 +11 -0
  105. forersi/rsi_workflows/default/prompts/watchdog/review.j2 +40 -0
  106. forersi/rsi_workflows/default/prompts/watchdog/system.j2 +8 -0
  107. forersi/rsi_workflows/default/reference_adoption.py +649 -0
  108. forersi/rsi_workflows/default/subflows/__init__.py +4 -0
  109. forersi/rsi_workflows/default/subflows/baseline_lifecycle.py +390 -0
  110. forersi/rsi_workflows/default/subflows/checker_pool.py +528 -0
  111. forersi/rsi_workflows/default/subflows/experiment_leases.py +717 -0
  112. forersi/rsi_workflows/default/subflows/experiment_recovery.py +566 -0
  113. forersi/rsi_workflows/default/subflows/experiment_subflow.py +1823 -0
  114. forersi/rsi_workflows/default/subflows/experiment_tracking.py +448 -0
  115. forersi/rsi_workflows/default/subflows/exploration_subflow.py +1969 -0
  116. forersi/rsi_workflows/default/subflows/watchdog_subflow.py +221 -0
  117. forersi/rsi_workflows/default/workflow.py +1259 -0
  118. forersi/rsi_workflows/default/workspaces.py +635 -0
  119. forersi/rsi_workflows/inference/__init__.py +29 -0
  120. forersi/rsi_workflows/inference/knowledge_base/knowledge/attention-state/hybrid-prefix-checkpoints.md +47 -0
  121. forersi/rsi_workflows/inference/knowledge_base/knowledge/attention-state/indexer-head-routing.md +53 -0
  122. forersi/rsi_workflows/inference/knowledge_base/knowledge/attention-state/kda-prefill-chunking.md +53 -0
  123. forersi/rsi_workflows/inference/knowledge_base/knowledge/attention-state/mla-layout-matching.md +53 -0
  124. forersi/rsi_workflows/inference/knowledge_base/knowledge/attention-state/softmax-pipeline-overlap.md +53 -0
  125. forersi/rsi_workflows/inference/knowledge_base/knowledge/attention-state/state-write-replay.md +54 -0
  126. forersi/rsi_workflows/inference/knowledge_base/knowledge/autoscaling-placement/cache-local-placement.md +49 -0
  127. forersi/rsi_workflows/inference/knowledge_base/knowledge/autoscaling-placement/generation-drain-handoff.md +52 -0
  128. forersi/rsi_workflows/inference/knowledge_base/knowledge/autoscaling-placement/slo-capacity-curves.md +50 -0
  129. forersi/rsi_workflows/inference/knowledge_base/knowledge/autoscaling-placement/startup-aware-scaling.md +54 -0
  130. forersi/rsi_workflows/inference/knowledge_base/knowledge/autoscaling-placement/token-pressure-scaling.md +47 -0
  131. forersi/rsi_workflows/inference/knowledge_base/knowledge/compiler-runtime/compile-cost-specialization.md +56 -0
  132. forersi/rsi_workflows/inference/knowledge_base/knowledge/compiler-runtime/custom-op-fusion.md +56 -0
  133. forersi/rsi_workflows/inference/knowledge_base/knowledge/compiler-runtime/graph-lifetime-pooling.md +56 -0
  134. forersi/rsi_workflows/inference/knowledge_base/knowledge/compiler-runtime/launch-graph-buckets.md +57 -0
  135. forersi/rsi_workflows/inference/knowledge_base/knowledge/disaggregated-serving/cost-aware-stage-placement.md +59 -0
  136. forersi/rsi_workflows/inference/knowledge_base/knowledge/disaggregated-serving/expert-batching-afd.md +60 -0
  137. forersi/rsi_workflows/inference/knowledge_base/knowledge/disaggregated-serving/kv-transfer-profiling.md +58 -0
  138. forersi/rsi_workflows/inference/knowledge_base/knowledge/disaggregated-serving/pipeline-capacity-balance.md +55 -0
  139. forersi/rsi_workflows/inference/knowledge_base/knowledge/disaggregated-serving/prefill-decode-separation.md +60 -0
  140. forersi/rsi_workflows/inference/knowledge_base/knowledge/engine-scheduling/decode-prefill-budget.md +51 -0
  141. forersi/rsi_workflows/inference/knowledge_base/knowledge/engine-scheduling/kv-pressure-admission.md +49 -0
  142. forersi/rsi_workflows/inference/knowledge_base/knowledge/engine-scheduling/moe-layered-prefill.md +47 -0
  143. forersi/rsi_workflows/inference/knowledge_base/knowledge/engine-scheduling/slo-decode-cadence.md +47 -0
  144. forersi/rsi_workflows/inference/knowledge_base/knowledge/engine-scheduling/token-fairness-counters.md +51 -0
  145. forersi/rsi_workflows/inference/knowledge_base/knowledge/engine-scheduling/workload-locked-kv-prefill-chunking-and-speculation.md +38 -0
  146. forersi/rsi_workflows/inference/knowledge_base/knowledge/heterogeneous-hardware/backend-graph-replay.md +51 -0
  147. forersi/rsi_workflows/inference/knowledge_base/knowledge/heterogeneous-hardware/cdna-gemm-tiling.md +55 -0
  148. forersi/rsi_workflows/inference/knowledge_base/knowledge/heterogeneous-hardware/collective-compute-overlap.md +54 -0
  149. forersi/rsi_workflows/inference/knowledge_base/knowledge/heterogeneous-hardware/cpu-gpu-offload.md +48 -0
  150. forersi/rsi_workflows/inference/knowledge_base/knowledge/heterogeneous-hardware/metax-int8-fusion.md +62 -0
  151. forersi/rsi_workflows/inference/knowledge_base/knowledge/host-streaming/host-device-overlap.md +57 -0
  152. forersi/rsi_workflows/inference/knowledge_base/knowledge/host-streaming/rank-numa-placement.md +49 -0
  153. forersi/rsi_workflows/inference/knowledge_base/knowledge/host-streaming/stream-backpressure-cancellation.md +56 -0
  154. forersi/rsi_workflows/inference/knowledge_base/knowledge/host-streaming/text-incremental-decoding.md +59 -0
  155. forersi/rsi_workflows/inference/knowledge_base/knowledge/index.md +152 -0
  156. forersi/rsi_workflows/inference/knowledge_base/knowledge/kernel-design/gemm-persistent-tiles.md +57 -0
  157. forersi/rsi_workflows/inference/knowledge_base/knowledge/kernel-design/intermediate-traffic-fusion.md +56 -0
  158. forersi/rsi_workflows/inference/knowledge_base/knowledge/kernel-design/sampling-radix-selection.md +52 -0
  159. forersi/rsi_workflows/inference/knowledge_base/knowledge/kernel-design/shape-locked-fusion-hybrid-layers-and-cuda-graphs.md +40 -0
  160. forersi/rsi_workflows/inference/knowledge_base/knowledge/kernel-design/warp-pipeline-overlap.md +53 -0
  161. forersi/rsi_workflows/inference/knowledge_base/knowledge/kv-cache/document-kv-recompute.md +53 -0
  162. forersi/rsi_workflows/inference/knowledge_base/knowledge/kv-cache/kv-compression-formats.md +58 -0
  163. forersi/rsi_workflows/inference/knowledge_base/knowledge/kv-cache/kv-query-page-selection.md +55 -0
  164. forersi/rsi_workflows/inference/knowledge_base/knowledge/kv-cache/kv-tiered-prefetch.md +57 -0
  165. forersi/rsi_workflows/inference/knowledge_base/knowledge/kv-cache/kv-transfer-layouts.md +50 -0
  166. forersi/rsi_workflows/inference/knowledge_base/knowledge/measurement-simulation/divergence-prefix-comparison.md +53 -0
  167. forersi/rsi_workflows/inference/knowledge_base/knowledge/measurement-simulation/latency-critical-paths.md +57 -0
  168. forersi/rsi_workflows/inference/knowledge_base/knowledge/measurement-simulation/queueing-arrival-clocks.md +63 -0
  169. forersi/rsi_workflows/inference/knowledge_base/knowledge/measurement-simulation/roofline-hardware-bounds.md +44 -0
  170. forersi/rsi_workflows/inference/knowledge_base/knowledge/measurement-simulation/simulation-replay-calibration.md +61 -0
  171. forersi/rsi_workflows/inference/knowledge_base/knowledge/measurement-simulation/slo-request-attribution.md +60 -0
  172. forersi/rsi_workflows/inference/knowledge_base/knowledge/model-loading-storage/loading-io-pipeline.md +52 -0
  173. forersi/rsi_workflows/inference/knowledge_base/knowledge/model-loading-storage/recovery-state-reuse.md +49 -0
  174. forersi/rsi_workflows/inference/knowledge_base/knowledge/model-loading-storage/startup-sharded-checkpoints.md +52 -0
  175. forersi/rsi_workflows/inference/knowledge_base/knowledge/model-loading-storage/weight-peer-loading.md +51 -0
  176. forersi/rsi_workflows/inference/knowledge_base/knowledge/moe-execution/batch-replica-assignment.md +54 -0
  177. forersi/rsi_workflows/inference/knowledge_base/knowledge/moe-execution/expert-window-rebalancing.md +46 -0
  178. forersi/rsi_workflows/inference/knowledge_base/knowledge/moe-execution/moe-gather-fusion.md +52 -0
  179. forersi/rsi_workflows/inference/knowledge_base/knowledge/moe-execution/moe-quantized-layouts.md +46 -0
  180. forersi/rsi_workflows/inference/knowledge_base/knowledge/moe-execution/small-batch-megakernels.md +46 -0
  181. forersi/rsi_workflows/inference/knowledge_base/knowledge/multi-model-adapters/adapter-deadline-scheduling.md +56 -0
  182. forersi/rsi_workflows/inference/knowledge_base/knowledge/multi-model-adapters/adapter-residency-dispatch.md +56 -0
  183. forersi/rsi_workflows/inference/knowledge_base/knowledge/multi-model-adapters/lora-tiles-split-k.md +58 -0
  184. forersi/rsi_workflows/inference/knowledge_base/knowledge/multi-model-adapters/model-memory-ballooning.md +57 -0
  185. forersi/rsi_workflows/inference/knowledge_base/knowledge/multimodal-generation/diffusion-feature-cache.md +58 -0
  186. forersi/rsi_workflows/inference/knowledge_base/knowledge/multimodal-generation/encoder-ttft-microbatching.md +57 -0
  187. forersi/rsi_workflows/inference/knowledge_base/knowledge/multimodal-generation/few-step-distillation.md +57 -0
  188. forersi/rsi_workflows/inference/knowledge_base/knowledge/multimodal-generation/media-chunk-decoding.md +55 -0
  189. forersi/rsi_workflows/inference/knowledge_base/knowledge/multimodal-generation/multimodal-shape-batching.md +57 -0
  190. forersi/rsi_workflows/inference/knowledge_base/knowledge/multimodal-generation/visual-prefill-reuse.md +57 -0
  191. forersi/rsi_workflows/inference/knowledge_base/knowledge/parallelism-communication/context-query-kv-sharding.md +57 -0
  192. forersi/rsi_workflows/inference/knowledge_base/knowledge/parallelism-communication/expert-topology-placement.md +52 -0
  193. forersi/rsi_workflows/inference/knowledge_base/knowledge/parallelism-communication/moe-dispatch-overlap.md +50 -0
  194. forersi/rsi_workflows/inference/knowledge_base/knowledge/parallelism-communication/pipeline-microbatch-balance.md +50 -0
  195. forersi/rsi_workflows/inference/knowledge_base/knowledge/parallelism-communication/topology-aware-collectives-and-host-streaming.md +38 -0
  196. forersi/rsi_workflows/inference/knowledge_base/knowledge/parallelism-communication/tp-collective-selection.md +50 -0
  197. forersi/rsi_workflows/inference/knowledge_base/knowledge/quantization/error-aware-block-scales.md +51 -0
  198. forersi/rsi_workflows/inference/knowledge_base/knowledge/quantization/low-bit-kernel-layouts.md +45 -0
  199. forersi/rsi_workflows/inference/knowledge_base/knowledge/quantization/mixed-precision-allocation.md +53 -0
  200. forersi/rsi_workflows/inference/knowledge_base/knowledge/quantization/outlier-rotation.md +47 -0
  201. forersi/rsi_workflows/inference/knowledge_base/knowledge/quantization/quality-rounding-scales.md +48 -0
  202. forersi/rsi_workflows/inference/knowledge_base/knowledge/routing-admission/deadline-aware-admission.md +53 -0
  203. forersi/rsi_workflows/inference/knowledge_base/knowledge/routing-admission/latency-predictive-routing.md +51 -0
  204. forersi/rsi_workflows/inference/knowledge_base/knowledge/routing-admission/tenant-fair-dispatch.md +49 -0
  205. forersi/rsi_workflows/inference/knowledge_base/knowledge/routing-admission/ttft-cache-queue-balance.md +50 -0
  206. forersi/rsi_workflows/inference/knowledge_base/knowledge/speculative-decoding/adaptive-verify-budget.md +50 -0
  207. forersi/rsi_workflows/inference/knowledge_base/knowledge/speculative-decoding/correction-fused-sampling.md +51 -0
  208. forersi/rsi_workflows/inference/knowledge_base/knowledge/speculative-decoding/draft-joint-selection.md +45 -0
  209. forersi/rsi_workflows/inference/knowledge_base/knowledge/speculative-decoding/draft-rollout-training.md +45 -0
  210. forersi/rsi_workflows/inference/knowledge_base/knowledge/speculative-decoding/parallel-block-drafting.md +47 -0
  211. forersi/rsi_workflows/inference/knowledge_base/knowledge/speculative-decoding/suffix-reuse-drafting.md +45 -0
  212. forersi/rsi_workflows/inference/knowledge_base/knowledge/speculative-decoding/tree-confidence-budget.md +47 -0
  213. forersi/rsi_workflows/inference/knowledge_base/meta-knowledge/architecture/cross-layer-serving-and-disaggregation-design.md +43 -0
  214. forersi/rsi_workflows/inference/knowledge_base/meta-knowledge/evaluation/steady-state-attribution-warm-reuse-and-anti-gaming.md +36 -0
  215. forersi/rsi_workflows/inference/knowledge_base/meta-knowledge/index.md +22 -0
  216. forersi/rsi_workflows/inference/knowledge_base/meta-knowledge/research/inference-ecosystem-profiler-and-trace-sources.md +51 -0
  217. forersi/rsi_workflows/inference/knowledge_base/meta-knowledge/specialization/bespoke-codesign-for-model-chip-and-cluster-state.md +45 -0
  218. forersi/rsi_workflows/inference/prompts/checker/check_direction.j2 +12 -0
  219. forersi/rsi_workflows/inference/prompts/checker/check_exploration.j2 +7 -0
  220. forersi/rsi_workflows/inference/prompts/checker/system.j2 +11 -0
  221. forersi/rsi_workflows/inference/prompts/common/system.j2 +9 -0
  222. forersi/rsi_workflows/inference/prompts/coordinator/system.j2 +11 -0
  223. forersi/rsi_workflows/inference/prompts/experimenter/check_experiments.j2 +8 -0
  224. forersi/rsi_workflows/inference/prompts/experimenter/run_experiment.j2 +9 -0
  225. forersi/rsi_workflows/inference/prompts/experimenter/study_framework.j2 +8 -0
  226. forersi/rsi_workflows/inference/prompts/experimenter/system.j2 +9 -0
  227. forersi/rsi_workflows/inference/prompts/explorer/conclude_exploration.j2 +7 -0
  228. forersi/rsi_workflows/inference/prompts/explorer/exploration.j2 +14 -0
  229. forersi/rsi_workflows/inference/prompts/explorer/prepare_baseline.j2 +8 -0
  230. forersi/rsi_workflows/inference/prompts/explorer/select_direction.j2 +14 -0
  231. forersi/rsi_workflows/inference/prompts/explorer/study_framework.j2 +8 -0
  232. forersi/rsi_workflows/inference/prompts/explorer/system.j2 +9 -0
  233. forersi/rsi_workflows/inference/prompts/watchdog/review.j2 +11 -0
  234. forersi/rsi_workflows/inference/workflow.py +70 -0
  235. forersi/rsi_workflows/meta/__init__.py +10 -0
  236. forersi/rsi_workflows/meta/agents.py +318 -0
  237. forersi/rsi_workflows/meta/prompts/architect/bootstrap.j2 +39 -0
  238. forersi/rsi_workflows/meta/prompts/architect/evolve.j2 +32 -0
  239. forersi/rsi_workflows/meta/prompts/architect/system.j2 +20 -0
  240. forersi/rsi_workflows/meta/prompts/checker/check_evolution.j2 +29 -0
  241. forersi/rsi_workflows/meta/prompts/checker/system.j2 +17 -0
  242. forersi/rsi_workflows/meta/subflow.py +622 -0
  243. forersi/rsi_workflows/meta/workflow.py +531 -0
  244. forersi/sessions/__init__.py +69 -0
  245. forersi/sessions/host.py +570 -0
  246. forersi/sessions/manager.py +249 -0
  247. forersi/ui/__init__.py +4 -0
  248. forersi/ui/tui/__init__.py +4 -0
  249. forersi/ui/tui/tui_runner.py +177 -0
  250. forersi/ui/tui/work_progress/__init__.py +4 -0
  251. forersi/ui/tui/work_progress/agent_team_graph.py +1378 -0
  252. forersi/ui/tui/work_progress/app.py +1613 -0
  253. forersi/ui/tui/work_progress/brand_logo.py +257 -0
  254. forersi/ui/tui/work_progress/cost_tab.py +354 -0
  255. forersi/ui/tui/work_progress/detail_widgets.py +407 -0
  256. forersi/ui/tui/work_progress/details.py +813 -0
  257. forersi/ui/tui/work_progress/exploration_graph.py +2240 -0
  258. forersi/ui/tui/work_progress/i18n.py +298 -0
  259. forersi/ui/tui/work_progress/node_tabs.py +715 -0
  260. forersi/ui/tui/work_progress/overview_tab.py +641 -0
  261. forersi/ui/tui/work_progress/work_progress_runner.py +103 -0
  262. forersi/ui/tui/work_progress/work_progress_runtime.py +108 -0
  263. forersi/ui/tui/work_progress/workflow_tab.py +363 -0
  264. forersi/utils/__init__.py +4 -0
  265. forersi/utils/paths.py +149 -0
  266. forersi/utils/process.py +11 -0
  267. forersi/utils/prompt_renderer.py +65 -0
  268. forersi/utils/terminal.py +377 -0
  269. forersi/utils/text.py +11 -0
  270. forersi/workflow_runtimes/__init__.py +226 -0
  271. forersi/workflow_runtimes/agent_scheduler.py +668 -0
  272. forersi/workflow_runtimes/base_agent.py +1053 -0
  273. forersi/workflow_runtimes/base_workflow.py +794 -0
  274. forersi/workflow_runtimes/ephemeral_subagent.py +199 -0
  275. forersi/workflow_runtimes/experiment_report.py +295 -0
  276. forersi/workflow_runtimes/exploration_pool.py +1792 -0
  277. forersi/workflow_runtimes/knowledge_base.py +909 -0
  278. forersi/workflow_runtimes/meta_workflow_store.py +1017 -0
  279. forersi/workflow_runtimes/run_state.py +31 -0
  280. forersi/workflow_runtimes/shared_docs.py +153 -0
  281. forersi/workflow_runtimes/task.py +585 -0
  282. forersi/workflow_runtimes/templates/knowledge_base/knowledge.md +35 -0
  283. forersi/workflow_runtimes/templates/knowledge_base/knowledge_zh.md +35 -0
  284. forersi/workflow_runtimes/templates/knowledge_base/meta-knowledge.md +30 -0
  285. forersi/workflow_runtimes/templates/knowledge_base/meta-knowledge_zh.md +30 -0
  286. forersi/workflow_runtimes/trajectory_digest.py +560 -0
  287. forersi/workflow_runtimes/types.py +19 -0
  288. forersi/workflow_runtimes/watchdog_reports.py +108 -0
  289. forersi/workflow_runtimes/workflow_runner.py +884 -0
  290. forersi/workflow_runtimes/workgroup.py +211 -0
  291. forersi/workflow_runtimes/workspace_provisioning.py +345 -0
  292. forersi-0.0.1.data/data/libexec/forersi/agy_launch.py +126 -0
  293. forersi-0.0.1.data/data/libexec/forersi/context_window.ts +97 -0
  294. forersi-0.0.1.data/data/libexec/forersi/forersi-terminal.exe +0 -0
  295. forersi-0.0.1.data/data/libexec/forersi/herdr-agent-state.ts +261 -0
  296. forersi-0.0.1.data/data/libexec/forersi/ipc.ts +308 -0
  297. forersi-0.0.1.data/data/libexec/forersi/login.ts +126 -0
  298. forersi-0.0.1.data/data/libexec/forersi/native_status.py +362 -0
  299. forersi-0.0.1.data/data/libexec/forersi/tool_mcp.ts +68 -0
  300. forersi-0.0.1.data/data/libexec/forersi/tool_stdio.py +140 -0
  301. forersi-0.0.1.data/data/libexec/forersi/turn_events.py +90 -0
  302. forersi-0.0.1.dist-info/METADATA +280 -0
  303. forersi-0.0.1.dist-info/RECORD +310 -0
  304. forersi-0.0.1.dist-info/WHEEL +5 -0
  305. forersi-0.0.1.dist-info/entry_points.txt +10 -0
  306. forersi-0.0.1.dist-info/licenses/LICENSE +201 -0
  307. forersi-0.0.1.dist-info/licenses/terminal/LICENSE +201 -0
  308. forersi-0.0.1.dist-info/licenses/terminal/vendor/libghostty-vt/LICENSE +21 -0
  309. forersi-0.0.1.dist-info/licenses/terminal/vendor/portable-pty/LICENSE.md +21 -0
  310. forersi-0.0.1.dist-info/top_level.txt +1 -0
forersi/__init__.py ADDED
@@ -0,0 +1,169 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: Copyright contributors to the ForeRSI project
3
+
4
+ """ForeRSI: an open-source framework for recursive self-improvement with agent teams.
5
+
6
+ Custom workflows subclass `BaseWorkflow` and `BaseAgent`, register role tools with
7
+ `register_agent_tool`, and run through the `forersi` CLI via `--workflow`.
8
+ Imports are resolved lazily so CLI startup only loads modules needed for the active command.
9
+ """
10
+
11
+ from pkgutil import resolve_name
12
+ from typing import TYPE_CHECKING
13
+
14
+ if TYPE_CHECKING:
15
+ from forersi.agent_runtimes.pricing import ModelPricing, PricingTier
16
+ from forersi.agent_runtimes.tool_mcp import AgentTool, register_agent_tool
17
+ from forersi.agent_runtimes.usage import (
18
+ MemberUsage,
19
+ SessionUsageSummary,
20
+ TokenUsage,
21
+ collect_session_usage,
22
+ )
23
+ from forersi.config import (
24
+ AgentConfig,
25
+ AgentHarness,
26
+ ReasoningEffort,
27
+ WorkflowConfig,
28
+ )
29
+ from forersi.rsi_workflows.default.workflow import DefaultWorkflow
30
+ from forersi.rsi_workflows.inference.workflow import InferenceWorkflow
31
+ from forersi.rsi_workflows.meta.agents import MetaArchitectAgent, MetaCheckerAgent
32
+ from forersi.rsi_workflows.meta.workflow import (
33
+ MetaDefaultWorkflow,
34
+ MetaInferenceWorkflow,
35
+ build_meta_workflow_class,
36
+ )
37
+ from forersi.workflow_runtimes.agent_scheduler import (
38
+ AgentAllocation,
39
+ AgentScheduler,
40
+ Quota,
41
+ )
42
+ from forersi.workflow_runtimes.base_agent import (
43
+ AgentState,
44
+ BaseAgent,
45
+ ExpectedToolCalls,
46
+ InboxMessage,
47
+ )
48
+ from forersi.workflow_runtimes.base_workflow import BaseWorkflow, SharedCache
49
+ from forersi.workflow_runtimes.exploration_pool import query_explorations
50
+ from forersi.workflow_runtimes.knowledge_base import (
51
+ KnowledgeBase,
52
+ KnowledgeEntry,
53
+ KnowledgeKind,
54
+ knowledge_template_path,
55
+ record_knowledge_entry,
56
+ validate_knowledge_markdown,
57
+ validate_knowledge_tree,
58
+ )
59
+ from forersi.workflow_runtimes.meta_workflow_store import MetaWorkflowStore
60
+ from forersi.workflow_runtimes.run_state import WorkflowState
61
+ from forersi.workflow_runtimes.trajectory_digest import (
62
+ build_trajectory_digest,
63
+ inspect_session_trajectories,
64
+ )
65
+ from forersi.workflow_runtimes.workgroup import Workgroup, Workgroups
66
+
67
+ LAZY_EXPORTS = {
68
+ "AgentAllocation": "forersi.workflow_runtimes.agent_scheduler:AgentAllocation",
69
+ "AgentConfig": "forersi.config:AgentConfig",
70
+ "AgentHarness": "forersi.config:AgentHarness",
71
+ "AgentScheduler": "forersi.workflow_runtimes.agent_scheduler:AgentScheduler",
72
+ "AgentState": "forersi.workflow_runtimes.base_agent:AgentState",
73
+ "AgentTool": "forersi.agent_runtimes.tool_mcp:AgentTool",
74
+ "BaseAgent": "forersi.workflow_runtimes.base_agent:BaseAgent",
75
+ "BaseWorkflow": "forersi.workflow_runtimes.base_workflow:BaseWorkflow",
76
+ "DefaultWorkflow": "forersi.rsi_workflows.default.workflow:DefaultWorkflow",
77
+ "ExpectedToolCalls": "forersi.workflow_runtimes.base_agent:ExpectedToolCalls",
78
+ "InboxMessage": "forersi.workflow_runtimes.base_agent:InboxMessage",
79
+ "InferenceWorkflow": "forersi.rsi_workflows.inference.workflow:InferenceWorkflow",
80
+ "KnowledgeBase": "forersi.workflow_runtimes.knowledge_base:KnowledgeBase",
81
+ "KnowledgeEntry": "forersi.workflow_runtimes.knowledge_base:KnowledgeEntry",
82
+ "KnowledgeKind": "forersi.workflow_runtimes.knowledge_base:KnowledgeKind",
83
+ "MemberUsage": "forersi.agent_runtimes.usage:MemberUsage",
84
+ "MetaArchitectAgent": "forersi.rsi_workflows.meta.agents:MetaArchitectAgent",
85
+ "MetaCheckerAgent": "forersi.rsi_workflows.meta.agents:MetaCheckerAgent",
86
+ "MetaDefaultWorkflow": "forersi.rsi_workflows.meta.workflow:MetaDefaultWorkflow",
87
+ "MetaInferenceWorkflow": "forersi.rsi_workflows.meta.workflow:MetaInferenceWorkflow",
88
+ "MetaWorkflowStore": "forersi.workflow_runtimes.meta_workflow_store:MetaWorkflowStore",
89
+ "ModelPricing": "forersi.agent_runtimes.pricing:ModelPricing",
90
+ "PricingTier": "forersi.agent_runtimes.pricing:PricingTier",
91
+ "Quota": "forersi.workflow_runtimes.agent_scheduler:Quota",
92
+ "ReasoningEffort": "forersi.config:ReasoningEffort",
93
+ "SessionUsageSummary": "forersi.agent_runtimes.usage:SessionUsageSummary",
94
+ "SharedCache": "forersi.workflow_runtimes.base_workflow:SharedCache",
95
+ "TokenUsage": "forersi.agent_runtimes.usage:TokenUsage",
96
+ "Workgroup": "forersi.workflow_runtimes.workgroup:Workgroup",
97
+ "Workgroups": "forersi.workflow_runtimes.workgroup:Workgroups",
98
+ "WorkflowConfig": "forersi.config:WorkflowConfig",
99
+ "WorkflowState": "forersi.workflow_runtimes.run_state:WorkflowState",
100
+ "build_meta_workflow_class": "forersi.rsi_workflows.meta.workflow:build_meta_workflow_class",
101
+ "build_trajectory_digest": "forersi.workflow_runtimes.trajectory_digest:build_trajectory_digest",
102
+ "collect_session_usage": "forersi.agent_runtimes.usage:collect_session_usage",
103
+ "inspect_session_trajectories": "forersi.workflow_runtimes.trajectory_digest:inspect_session_trajectories",
104
+ "knowledge_template_path": "forersi.workflow_runtimes.knowledge_base:knowledge_template_path",
105
+ "query_explorations": "forersi.workflow_runtimes.exploration_pool:query_explorations",
106
+ "record_knowledge_entry": "forersi.workflow_runtimes.knowledge_base:record_knowledge_entry",
107
+ "register_agent_tool": "forersi.agent_runtimes.tool_mcp:register_agent_tool",
108
+ "validate_knowledge_markdown": "forersi.workflow_runtimes.knowledge_base:validate_knowledge_markdown",
109
+ "validate_knowledge_tree": "forersi.workflow_runtimes.knowledge_base:validate_knowledge_tree",
110
+ }
111
+
112
+ __all__ = [
113
+ "AgentAllocation",
114
+ "AgentConfig",
115
+ "AgentHarness",
116
+ "AgentScheduler",
117
+ "AgentState",
118
+ "AgentTool",
119
+ "BaseAgent",
120
+ "BaseWorkflow",
121
+ "DefaultWorkflow",
122
+ "ExpectedToolCalls",
123
+ "InboxMessage",
124
+ "InferenceWorkflow",
125
+ "KnowledgeBase",
126
+ "KnowledgeEntry",
127
+ "KnowledgeKind",
128
+ "MemberUsage",
129
+ "MetaArchitectAgent",
130
+ "MetaCheckerAgent",
131
+ "MetaDefaultWorkflow",
132
+ "MetaInferenceWorkflow",
133
+ "MetaWorkflowStore",
134
+ "ModelPricing",
135
+ "PricingTier",
136
+ "Quota",
137
+ "ReasoningEffort",
138
+ "SessionUsageSummary",
139
+ "SharedCache",
140
+ "TokenUsage",
141
+ "WorkflowConfig",
142
+ "WorkflowState",
143
+ "Workgroup",
144
+ "Workgroups",
145
+ "build_meta_workflow_class",
146
+ "build_trajectory_digest",
147
+ "collect_session_usage",
148
+ "inspect_session_trajectories",
149
+ "knowledge_template_path",
150
+ "query_explorations",
151
+ "record_knowledge_entry",
152
+ "register_agent_tool",
153
+ "validate_knowledge_markdown",
154
+ "validate_knowledge_tree",
155
+ ]
156
+
157
+
158
+ def __getattr__(name: str) -> object:
159
+ """Resolve public framework symbols on first access."""
160
+ target = LAZY_EXPORTS.get(name)
161
+ if target is None:
162
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
163
+ value = resolve_name(target)
164
+ globals()[name] = value
165
+ return value
166
+
167
+
168
+ def __dir__() -> list[str]:
169
+ return sorted([*globals(), *LAZY_EXPORTS])
forersi/__main__.py ADDED
@@ -0,0 +1,110 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: Copyright contributors to the ForeRSI project
3
+
4
+ """Process entry point installing signal handlers around the async application loop."""
5
+
6
+ import asyncio
7
+ import signal
8
+ import sys
9
+ from collections.abc import Awaitable, Callable
10
+ from subprocess import CalledProcessError
11
+ from types import FrameType
12
+ from typing import cast
13
+
14
+
15
+ def cli() -> int:
16
+ """Console script entry point (`forersi`) returning a POSIX-compatible exit code.
17
+
18
+ Execution flow:
19
+ cli() --> asyncio.run(run_with_shutdown_signals(main))
20
+ +-- normal return --> exit status (0 or 128 + signum)
21
+ +-- CalledProcessError --> forward subprocess output to stderr, preserve code
22
+ +-- KeyboardInterrupt --> exit status 130
23
+ """
24
+ configure_utf8_stdio()
25
+ from forersi.main import main
26
+
27
+ exit_code: int | None = None
28
+ try:
29
+ return asyncio.run(run_with_shutdown_signals(main))
30
+ except* CalledProcessError as errors:
31
+ exit_code = command_exit_status(errors)
32
+ except* KeyboardInterrupt:
33
+ if exit_code is None:
34
+ exit_code = 130
35
+ assert exit_code is not None
36
+ return exit_code
37
+
38
+
39
+ async def run_with_shutdown_signals(application: Callable[[], Awaitable[None]]) -> int:
40
+ """Run `application()` and convert termination signals into cooperative task cancellation.
41
+
42
+ Called by both the foreground `cli()` launcher and the detached `forersi.sessions.host`
43
+ supervisor. Only the first termination signal cancels the root task so asynchronous
44
+ `finally` cleanup blocks can run to completion even if repeated window-close signals arrive.
45
+ """
46
+ configure_utf8_stdio()
47
+ loop = asyncio.get_running_loop()
48
+ task = cast(asyncio.Task[int], asyncio.current_task())
49
+ shutdown_signal: int | None = None
50
+
51
+ def cancel_application(signum: int) -> None:
52
+ nonlocal shutdown_signal
53
+ if shutdown_signal is None:
54
+ shutdown_signal = signum
55
+ if not task.cancelling():
56
+ task.cancel()
57
+
58
+ def request_shutdown(signum: int, _frame: FrameType | None) -> None:
59
+ loop.call_soon_threadsafe(cancel_application, signum)
60
+
61
+ termination_signals = [signal.SIGINT, signal.SIGTERM]
62
+ if hasattr(signal, "SIGHUP"):
63
+ termination_signals.append(signal.SIGHUP)
64
+ if hasattr(signal, "SIGBREAK"):
65
+ termination_signals.append(signal.SIGBREAK)
66
+
67
+ previous_handlers = {}
68
+ try:
69
+ for signum in termination_signals:
70
+ previous_handlers[signum] = signal.signal(signum, request_shutdown)
71
+ try:
72
+ await application()
73
+ except asyncio.CancelledError:
74
+ if shutdown_signal is None:
75
+ raise
76
+ finally:
77
+ for signum, handler in previous_handlers.items():
78
+ signal.signal(signum, handler)
79
+
80
+ if shutdown_signal is not None:
81
+ task.uncancel()
82
+ return 128 + shutdown_signal
83
+ return 0
84
+
85
+
86
+ def command_exit_status(
87
+ error: CalledProcessError | BaseExceptionGroup[CalledProcessError],
88
+ ) -> int:
89
+ """Forward captured subprocess diagnostics to stderr and compute the process exit code."""
90
+ if isinstance(error, BaseExceptionGroup):
91
+ statuses = [command_exit_status(child) for child in error.exceptions]
92
+ return statuses[0] if len(statuses) == 1 else 1
93
+
94
+ if error.stderr:
95
+ print(error.stderr, end="", file=sys.stderr)
96
+ elif error.stdout:
97
+ print(error.stdout, end="", file=sys.stderr)
98
+ return error.returncode if error.returncode >= 0 else 128 - error.returncode
99
+
100
+
101
+ def configure_utf8_stdio() -> None:
102
+ """Reconfigure standard text streams to UTF-8 so piped Windows CLI I/O avoids legacy codepages."""
103
+ for stream in (sys.stdin, sys.stdout, sys.stderr):
104
+ reconfigure = getattr(stream, "reconfigure", None)
105
+ if callable(reconfigure):
106
+ reconfigure(encoding="utf-8", errors="replace")
107
+
108
+
109
+ if __name__ == "__main__":
110
+ raise SystemExit(cli())
@@ -0,0 +1,126 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: Copyright contributors to the ForeRSI project
3
+
4
+ """Lazy backend resolution and factory entry points for native agent CLI runtimes."""
5
+
6
+ from __future__ import annotations
7
+
8
+ from collections.abc import Sequence
9
+ from pathlib import Path
10
+ from pkgutil import resolve_name
11
+ from typing import TYPE_CHECKING
12
+
13
+ from forersi.config import AgentConfig, CanonicalHarness, WorkflowConfig
14
+
15
+ if TYPE_CHECKING:
16
+ from forersi.agent_runtimes.base_runtime import AgentRuntime
17
+ from forersi.agent_runtimes.tool_mcp import AgentTool, ToolMcpHost
18
+
19
+ AGENT_ENTRY_POINTS: dict[CanonicalHarness, str] = {
20
+ "pi": "forersi.agent_runtimes.pi:PiAgentRuntime",
21
+ "codex": "forersi.agent_runtimes.codex:CodexAgentRuntime",
22
+ "claude": "forersi.agent_runtimes.claude_code:ClaudeCodeAgentRuntime",
23
+ "antigravity": "forersi.agent_runtimes.antigravity:AntigravityAgentRuntime",
24
+ }
25
+
26
+ HARNESS_STORAGE_DIRS: dict[CanonicalHarness, str] = {
27
+ "pi": "pi",
28
+ "codex": "codex",
29
+ "claude": "claude",
30
+ "antigravity": "agy",
31
+ }
32
+
33
+ LAZY_RUNTIME_EXPORTS: dict[str, str] = {
34
+ "AgentRuntime": "forersi.agent_runtimes.base_runtime:AgentRuntime",
35
+ "AgentTool": "forersi.agent_runtimes.tool_mcp:AgentTool",
36
+ "ToolMcpHost": "forersi.agent_runtimes.tool_mcp:ToolMcpHost",
37
+ }
38
+
39
+ __all__ = [
40
+ "AGENT_ENTRY_POINTS",
41
+ "HARNESS_STORAGE_DIRS",
42
+ "AgentRuntime",
43
+ "AgentTool",
44
+ "ToolMcpHost",
45
+ "canonical_harness_name",
46
+ "create_agent_runtime",
47
+ "find_saved_member_harnesses",
48
+ "get_agent_runtime_class",
49
+ ]
50
+
51
+
52
+ def canonical_harness_name(harness_name: str) -> CanonicalHarness:
53
+ """Normalize `harness_name` (`"agy"` -> `"antigravity"`) and validate against registered backends."""
54
+ canonical = "antigravity" if harness_name == "agy" else harness_name
55
+ if canonical not in AGENT_ENTRY_POINTS:
56
+ available = ", ".join(AGENT_ENTRY_POINTS)
57
+ raise ValueError(f"Unknown harness {harness_name!r}. Available harnesses: {available}.")
58
+ return canonical # type: ignore[return-value]
59
+
60
+
61
+ def create_agent_runtime(
62
+ agent_config: AgentConfig,
63
+ workflow_directory: Path,
64
+ *,
65
+ workgroup_name: str,
66
+ agent_name: str,
67
+ tool_mcp_host: ToolMcpHost,
68
+ tools: Sequence[AgentTool],
69
+ ) -> AgentRuntime:
70
+ """Construct the configured native runtime for one workflow agent without starting its pane.
71
+
72
+ Called by `BaseAgent.__init__` when assembling a workflow member. Resolves only the selected
73
+ backend module so unused CLI SDKs and transports are not imported, binds the member's
74
+ identity and MCP tools, and defers subprocess/pane allocation to `AgentRuntime.start()`.
75
+ """
76
+ runtime_class = get_agent_runtime_class(agent_config.harness)
77
+ return runtime_class(
78
+ agent_config,
79
+ workflow_directory,
80
+ workgroup_name=workgroup_name,
81
+ agent_name=agent_name,
82
+ tool_mcp_host=tool_mcp_host,
83
+ tools=tools,
84
+ )
85
+
86
+
87
+ def get_agent_runtime_class(harness_name: str) -> type[AgentRuntime]:
88
+ """Import and return the `AgentRuntime` subclass registered for `harness_name`.
89
+
90
+ Called by `create_agent_runtime`, pre-session installation and authentication checks in
91
+ `sessions.host`, and storage teardown in `WorkflowRunner`. Accepts `"agy"` as an alias for
92
+ `"antigravity"` to match the terminal's canonical agent kind.
93
+ """
94
+ canonical_name = canonical_harness_name(harness_name)
95
+ return resolve_name(AGENT_ENTRY_POINTS[canonical_name])
96
+
97
+
98
+ def find_saved_member_harnesses(
99
+ workflow_directory: Path, workgroup_name: str, agent_name: str,
100
+ ) -> tuple[CanonicalHarness, ...]:
101
+ """Return canonical harness names holding a saved conversation for `(workgroup_name, agent_name)`, newest first."""
102
+ harnesses_root = (
103
+ workflow_directory / WorkflowConfig.RUNTIME_DIR_NAME / WorkflowConfig.HARNESSES_DIR_NAME
104
+ )
105
+ if not harnesses_root.is_dir():
106
+ return ()
107
+ found: list[tuple[float, CanonicalHarness]] = []
108
+ for harness_key, storage_dir in HARNESS_STORAGE_DIRS.items():
109
+ if not (harnesses_root / storage_dir).is_dir():
110
+ continue
111
+ runtime_class = get_agent_runtime_class(harness_key)
112
+ if runtime_class.has_saved_member(workflow_directory, workgroup_name, agent_name):
113
+ mtime = runtime_class.saved_member_mtime(workflow_directory, workgroup_name, agent_name)
114
+ found.append((mtime, harness_key))
115
+ found.sort(key=lambda item: item[0], reverse=True)
116
+ return tuple(harness_key for _, harness_key in found)
117
+
118
+
119
+ def __getattr__(name: str) -> object:
120
+ """Lazily resolve `AgentRuntime`, `AgentTool`, and `ToolMcpHost` on first attribute access."""
121
+ target = LAZY_RUNTIME_EXPORTS.get(name)
122
+ if target is None:
123
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
124
+ resolved = resolve_name(target)
125
+ globals()[name] = resolved
126
+ return resolved
@@ -0,0 +1,23 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: Copyright contributors to the ForeRSI project
3
+
4
+ """Antigravity CLI (`agy`) runtime adapter."""
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import TYPE_CHECKING
9
+
10
+ if TYPE_CHECKING:
11
+ from .runtime import AntigravityAgentRuntime
12
+
13
+ __all__ = ["AntigravityAgentRuntime"]
14
+
15
+
16
+ def __getattr__(name: str) -> object:
17
+ """Lazily import `AntigravityAgentRuntime` so `antigravity.usage` avoids loading runtime plumbing."""
18
+ if name == "AntigravityAgentRuntime":
19
+ from .runtime import AntigravityAgentRuntime
20
+
21
+ globals()[name] = AntigravityAgentRuntime
22
+ return AntigravityAgentRuntime
23
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -0,0 +1,107 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: Copyright contributors to the ForeRSI project
3
+
4
+ """Antigravity authentication probe and transcript label formatting helpers."""
5
+
6
+ import asyncio
7
+ import re
8
+ from collections.abc import Mapping
9
+ from importlib.metadata import version
10
+ from pathlib import Path
11
+ from typing import cast
12
+
13
+ from forersi.utils.process import BACKGROUND_PROCESS_FLAGS
14
+
15
+ __all__ = [
16
+ "check_auth_method",
17
+ "extract_user_request",
18
+ "format_tool_label",
19
+ ]
20
+
21
+ USER_REQUEST_OPEN = "<USER_REQUEST>"
22
+ USER_REQUEST_CLOSE = "</USER_REQUEST>"
23
+ MCP_TOOL_PREFIX_PATTERN = re.compile(
24
+ r"^(?:mcp__.+?__|mcp_(?:frsi_[0-9a-f]+|[^_]+)_)"
25
+ )
26
+
27
+
28
+ async def check_auth_method(
29
+ executable: Path,
30
+ environment: Mapping[str, str],
31
+ *,
32
+ method_id: str,
33
+ ) -> bool:
34
+ """Probe whether `agy acp` accepts `authenticate(method_id=...)` within 20 seconds.
35
+
36
+ Called by `AntigravityAgentRuntime.ensure_authenticated()` and `can_open_standby()` for
37
+ `AGY_ADC_AUTH=true` (`agent-platform`) and `GEMINI_API_KEY` (`gemini-api-key`) modes.
38
+
39
+ Auth probe flow:
40
+ strip `ANTIGRAVITY_*` env --> spawn `agy acp --stdio --process-per-session`
41
+ --> `connection.initialize` --> `connection.authenticate(method_id)` --> True | False
42
+ """
43
+ from acp import PROTOCOL_VERSION, Client, RequestError, schema, spawn_agent_process
44
+
45
+ clean_env = {
46
+ key: value
47
+ for key, value in environment.items()
48
+ if not key.startswith("ANTIGRAVITY_")
49
+ }
50
+ process = spawn_agent_process(
51
+ cast(Client, AuthProbeClient()),
52
+ str(executable),
53
+ "acp",
54
+ "--stdio",
55
+ "--process-per-session",
56
+ env=clean_env,
57
+ cwd=Path.cwd(),
58
+ transport_kwargs={
59
+ "stderr": asyncio.subprocess.DEVNULL,
60
+ "creationflags": BACKGROUND_PROCESS_FLAGS,
61
+ },
62
+ )
63
+ try:
64
+ async with asyncio.timeout(20), process as (connection, _):
65
+ await connection.initialize(
66
+ protocol_version=PROTOCOL_VERSION,
67
+ client_info=schema.Implementation(
68
+ name="forersi", version=version("forersi")
69
+ ),
70
+ )
71
+ await connection.authenticate(method_id=method_id)
72
+ return True
73
+ except (OSError, RequestError, TimeoutError, RuntimeError):
74
+ return False
75
+
76
+
77
+ def extract_user_request(content: str) -> str:
78
+ """Extract the inner prompt from `<USER_REQUEST>...</USER_REQUEST>`, or strip `content`."""
79
+ start = content.find(USER_REQUEST_OPEN)
80
+ if start != -1:
81
+ inner_start = start + len(USER_REQUEST_OPEN)
82
+ end = content.find(USER_REQUEST_CLOSE, inner_start)
83
+ if end != -1:
84
+ return content[inner_start:end].strip()
85
+ return content.strip()
86
+
87
+
88
+ def format_tool_label(raw_name: str, *, mcp_server_name: str | None = None) -> str:
89
+ """Strip MCP server namespace prefixes (`mcp_<server>_`, `<server>:`) from `raw_name`."""
90
+ cleaned = raw_name.strip()
91
+ if mcp_server_name:
92
+ for prefix in (
93
+ f"mcp_{mcp_server_name}_",
94
+ f"mcp__{mcp_server_name}__",
95
+ f"{mcp_server_name}:",
96
+ f"{mcp_server_name}/",
97
+ ):
98
+ if cleaned.startswith(prefix):
99
+ return cleaned.removeprefix(prefix)
100
+ return MCP_TOOL_PREFIX_PATTERN.sub("", cleaned)
101
+
102
+
103
+ class AuthProbeClient:
104
+ """No-op ACP `Client` receiver used strictly during `check_auth_method` handshakes."""
105
+
106
+ async def session_update(self, *_args: object, **_kwargs: object) -> None:
107
+ """Ignore telemetry notifications during auth probes."""
@@ -0,0 +1,126 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: Copyright contributors to the ForeRSI project
3
+
4
+ """Replay-safe stdlib launcher starting or resuming a native `agy` TUI conversation."""
5
+
6
+ import os
7
+ import signal
8
+ import subprocess
9
+ import sys
10
+ from pathlib import Path
11
+ from uuid import UUID
12
+
13
+
14
+ def main() -> None:
15
+ """Prepend `--conversation <uuid>` when `<member>.id` exists, then run native `agy`.
16
+
17
+ Invoked inside Antigravity terminal panes via
18
+ `python -I -S agy_launch.py <member.id|""> <agy_executable> <options...>`.
19
+
20
+ Launch flow:
21
+ read `<member>.id` (if valid UUID) --> build `agy` argv
22
+ +-- Windows (`nt`) --> prepend `FORERSI_AGY_RUNNER_DIR` to `PATH`, ignore `SIGINT`,
23
+ | & `subprocess.call(argv)`
24
+ +-- macOS (`darwin`) --> enable `CLOCAL` on PTY slave & `run_without_controlling_tty`
25
+ | (`setsid` without `TIOCSCTTY` so neither `open("/dev/tty")`
26
+ | nor `open(ttyname(0))` blocks in XNU `ttyopen` while
27
+ | `agy_launch.py` holds `fg_pgid` and forwards PTY signals)
28
+ +-- Other POSIX --> `os.execv(executable, argv)`
29
+ """
30
+ id_path_arg, executable, *options = sys.argv[1:]
31
+ conversation_args = read_conversation_args(Path(id_path_arg)) if id_path_arg else []
32
+ argv = [executable, *conversation_args, *options]
33
+ if os.name == "nt":
34
+ runner_dir = os.environ.get("FORERSI_AGY_RUNNER_DIR") or str(Path(__file__).resolve().parent)
35
+ current_path = os.environ.get("PATH", "")
36
+ existing_entries = {
37
+ os.path.normcase(entry) for entry in current_path.split(os.pathsep) if entry
38
+ }
39
+ if os.path.normcase(runner_dir) not in existing_entries:
40
+ os.environ["PATH"] = (
41
+ f"{runner_dir}{os.pathsep}{current_path}" if current_path else runner_dir
42
+ )
43
+ signal.signal(signal.SIGINT, lambda *_: None)
44
+ sys.exit(subprocess.call(argv))
45
+ if sys.platform == "darwin":
46
+ sys.exit(run_without_controlling_tty(argv))
47
+ os.execv(executable, argv)
48
+
49
+
50
+ def run_without_controlling_tty(argv: list[str]) -> int:
51
+ """Run `argv` in a detached POSIX session sharing a `CLOCAL` PTY slave without `TIOCSCTTY`.
52
+
53
+ On macOS, `antigravity` opens `/dev/tty` (falling back to `ttyname(0)`) during TUI startup
54
+ before entering raw mode. Enabling `termios.CLOCAL` on inherited `stdin` (`fd 0`) prevents
55
+ XNU's `ttyopen` from sleeping on `!TS_CARR_ON`, while `start_new_session=True` without
56
+ `TIOCSCTTY` clears `P_CONTROLT` so `/dev/tty` returns `ENXIO` immediately without touching
57
+ wedged host ctty locks. This wrapper stays in the pane's foreground process group and
58
+ forwards PTY lifecycle and resize signals to the child process group.
59
+ """
60
+ import termios
61
+
62
+ try:
63
+ attrs = termios.tcgetattr(0)
64
+ if not (attrs[2] & termios.CLOCAL):
65
+ attrs[2] |= termios.CLOCAL
66
+ termios.tcsetattr(0, termios.TCSANOW, attrs)
67
+ except (OSError, termios.error):
68
+ pass
69
+
70
+ child_env = {key: value for key, value in os.environ.items() if key != "HERDR_AGENT"}
71
+ proc: subprocess.Popen[bytes] | None = None
72
+ pending_signals: list[int] = []
73
+
74
+ def forward_signal(signum: int, frame: object) -> None:
75
+ del frame
76
+ if proc is None:
77
+ pending_signals.append(signum)
78
+ return
79
+ try:
80
+ os.killpg(proc.pid, signum)
81
+ except ProcessLookupError:
82
+ pass
83
+
84
+ for sig in (
85
+ signal.SIGHUP,
86
+ signal.SIGINT,
87
+ signal.SIGTERM,
88
+ signal.SIGQUIT,
89
+ signal.SIGWINCH,
90
+ ):
91
+ signal.signal(sig, forward_signal)
92
+
93
+ proc = subprocess.Popen(argv, env=child_env, start_new_session=True)
94
+ try:
95
+ for queued_sig in pending_signals:
96
+ try:
97
+ os.killpg(proc.pid, queued_sig)
98
+ except ProcessLookupError:
99
+ pass
100
+ pending_signals.clear()
101
+ while True:
102
+ try:
103
+ return proc.wait()
104
+ except InterruptedError:
105
+ continue
106
+ finally:
107
+ if proc.poll() is None:
108
+ try:
109
+ os.killpg(proc.pid, signal.SIGTERM)
110
+ except ProcessLookupError:
111
+ pass
112
+
113
+
114
+ def read_conversation_args(id_file: Path) -> list[str]:
115
+ """Return `['--conversation', '<uuid>']` if `id_file` holds a valid UUID, else `[]`."""
116
+ if not id_file.is_file():
117
+ return []
118
+ try:
119
+ conversation_id = str(UUID(id_file.read_text(encoding="utf-8").strip()))
120
+ except (OSError, ValueError):
121
+ return []
122
+ return ["--conversation", conversation_id]
123
+
124
+
125
+ if __name__ == "__main__":
126
+ main()