pyagy 0.7.1__tar.gz

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.
pyagy-0.7.1/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .pytest_cache/
4
+ build/
5
+ dist/
6
+ *.egg-info/
@@ -0,0 +1,110 @@
1
+ # pyagy 对齐说明
2
+
3
+ 本文档记录 `pyagy` 与官方 Antigravity CLI(**`agy 1.5.14`**,客户端指纹 `google-genai-sdk/1.79.1 gl-go/go1.28-20261102-RC01 cl/1012564305 +298f53e483 X:fieldtrack,boringcrypto,nogolistexportnewformat`)的对齐现状。
4
+
5
+ 对照基准通过同一个本地 HTTP Capture Server 抓取双端真实发出的 Gemini `streamGenerateContent` 请求、工具往返与多轮会话轨迹核验(验证日期:`2026-11-22`)。下文先列出当前**未对齐或仅形式对齐**的部分,再列出**已对齐**的部分。
6
+
7
+ ---
8
+
9
+ ## 一、未对齐与仅形式对齐部分
10
+
11
+ ### 1.1 纯形式对齐的禁用/占位工具(3 个)
12
+
13
+ 以下 3 个工具在 `pyagy/prompts/tool_declarations.json` 中完整保留了官方名称、描述与 `parametersJsonSchema`,模型侧看到的 14 个工具声明与官方完全一致,但本地仅注册为禁用/占位类,调用时直接返回错误:
14
+
15
+ | 工具名 | 实现位置 | 调用返回与说明 |
16
+ | --- | --- | --- |
17
+ | `ask_question` | `pyagy/tools/interaction_tools.py` (`AskQuestionPlaceholderTool`) | 固定返回 `Encountered error in tool execution: ask_question is disabled`;保留工具声明但不触发交互提问或弹窗。 |
18
+ | `run_workflow` | `pyagy/tools/interaction_tools.py` (`RunWorkflowPlaceholderTool`) | 固定返回 `Encountered error in tool execution: tool is not enabled in pyagy CLI mode`;未实现 Python 工作流脚本宿主与多智能体编排原语。 |
19
+ | `swarm` | `pyagy/tools/interaction_tools.py` (`SwarmPlaceholderTool`) | 固定返回 `Encountered error in tool execution: tool is not enabled in pyagy CLI mode`;未实现共享消息板、成员名册及集群协作生命周期。 |
20
+
21
+ ### 1.2 已实现工具中的局部形式对齐与行为差异(5 项)
22
+
23
+ 其余 11 个工具已实现主体执行逻辑,但以下参数或子能力目前仅在 Schema / 提示词层面对齐,运行时存在简化或忽略:
24
+
25
+ 1. **`edit_file` 的 `ArtifactMetadata` 参数未生效**
26
+ - `edit_file` 的 Schema 包含 `ArtifactMetadata`(`Summary`、`UserFacing`、`RequestFeedback`),但 `EditFileTool` 未读取该参数,传入时会被静默忽略(`write_file` 则会将其写入 `.system_generated/artifacts/<name>.metadata.json`)。
27
+ - 此外,CLI 与 `pycodex-ws` Web 前端目前均未消费 `UserFacing` 与 `RequestFeedback`(例如计划文档的交互确认按钮)。
28
+ 2. **`read_file` 仅对图片实现二进制多模态,未覆盖 PDF 与音视频**
29
+ - 工具描述声明可读取 `text, image, pdf, video, or audio file`。
30
+ - 实际 `ReadFileTool` 仅识别 `png / jpeg / gif / webp` 四类图片并封装为 Gemini `inlineData`;传入 PDF、音频或视频文件时不会转为多模态输入,而是按 `utf-8 (errors="replace")` 当作普通文本解码并按行截断。
31
+ 3. **`define_subagent` 的 `EnableMCPTools` 参数与子 Agent 原生生图工具**
32
+ - `EnableMCPTools` 仅保存在 `SubagentBlueprint` 中,`_resolve_subagent_prompt_and_tools` 组装子 Agent 工具集时未读取该字段(`pyagy` 当前未接入 MCP Server 工具)。
33
+ - 官方自定义子 Agent 与内置 `image-generator` 具备原生生图工具(如 `generate_image`);`pyagy` 未实现原生生图工具,`image-generator` 目前仅挂载 `read_file`、`write_file`、`run_command`、`send_message`、`schedule`、`manage_task`。
34
+ 4. **`search_web` 的检索通道与无 Grounding 降级行为**
35
+ - `SearchWebTool` 通过复用当前下游 Gemini 接口额外发起一条带 `tools: [{"googleSearch": {}}]` 的请求并提取 `groundingChunks` 引用。
36
+ - 若下游代理返回 HTTP `400` 或 `501`(不支持 Google Search Grounding),实现会静默回退为不带 `googleSearch` 的普通模型生成请求,此时回答仅依赖模型参数知识而非真实联网检索。
37
+ 5. **`research` 子 Agent 沙箱与 CLI 权限/模式开关**
38
+ - 遵循仓库整体不做 OS 沙箱强制和命令审批拦截的约定:`research` 子 Agent 的“无网络只读沙箱”仅由系统提示词与只读工具集约束,其 `run_command` 仍在宿主 `bash` 中直接执行。
39
+ - CLI 参数 `--mode`(`accept-edits` / `auto` / `plan`)与 `--dangerously-skip-permissions` 仅做命令行兼容解析,不触发独立的权限审批弹窗或 Plan 状态切换。
40
+
41
+ ### 1.3 旁路请求、HTTP 传输层与本地持久化差异
42
+
43
+ 1. **省略官方 `SAFETY_RATER` 旁路请求**
44
+ - 官方 `agy 1.5.14` 在模型返回 `run_command` 后、真正执行命令前,会额外向 `/v1beta/models/gemini-3.1-flash-lite-preview:streamGenerateContent?alt=sse` 发送一条无 `tools`、带 `X-Server-Timeout: 8` 且 `thinkingLevel: "MINIMAL"` 的安全评估请求(`You are a safety and security rater overseeing Jetski...`)。
45
+ - `pyagy` 不发送该旁路请求,直接执行工具调用。
46
+ 2. **JSON 原始字节转义与 HTTP 连接头**
47
+ - 双端请求体解析后的 JSON 结构、键顺序与字段值完全一致;但官方基于 Go `encoding/json.Encoder`,会将 `<`、`>`、`&` 转义为 `\u003c`、`\u003e`、`\u0026` 并在请求体末尾追加 `\n`,同时默认复用 HTTP/1.1 长连接。
48
+ - `pyagy` 使用 Python `json.dumps(..., ensure_ascii=False, separators=(",", ":"))` 直接输出原字符且无末尾换行;底层 `urllib.request` 会附带 `Connection: close`,HTTP Header 排列顺序与 Go 标准库略有不同。
49
+ 3. **本地会话存储格式与 `transcript.jsonl` 详略度**
50
+ - 官方使用内部 protobuf 会话文件,并在 `transcript.jsonl` / `transcript_full.jsonl` 的 `PLANNER_RESPONSE` 步骤中写入完整 `thinking`、`content` 与 `tool_calls` 字段。
51
+ - `pyagy` 使用 `.system_generated/pyagy_session.json` 保存完整历史与恢复元数据(含 `anchor_tokens` 与对应的 `anchor_history_len` 锚定边界;缺少 `anchor_history_len` 的旧版存档在恢复时自动定位至最后一条模型响应条目之后,确保尾部未采样消息计入增量估算);运行时实时追加的 `PLANNER_RESPONSE` 步骤目前仅记录 `step_index`、`created_at` 与 `model`(完整推理及工具记录保存在 `pyagy_session.json` 及 Web 模式的 Codex rollout 文件中)。
52
+
53
+ ### 1.4 `pycodex-ws` Web 模式下的显式上下文扩展
54
+
55
+ 当配置 `harness = "pyagy"` 从 `pycodex-ws` 启动 Web 会话时,为支持工作区功能会按 `ContextConfig` 动态注入两项额外上下文(纯 `pyagy` CLI 模式默认关闭,保持与官方 CLI 0 diff):
56
+
57
+ 1. **`contents[0]` 前置工作区上下文消息**:注入 `<environment_context>` 及(当 `enable_board=True` 时)实时 Canvas 画布路径说明,首条真实 `<USER_REQUEST>` 顺移至 `contents[1]`。
58
+ 2. **合并 Codex 技能目录**:当 `include_skills_instructions=True` 且提供 `codex_home` 时,`systemInstruction` 的 `<skills>` 会合并挂载 `~/.codex/skills` 下的技能条目。
59
+
60
+ ---
61
+
62
+ ## 二、已对齐部分
63
+
64
+ 在纯 CLI 默认模式下,将官方 `agy 1.5.14` 与 `pyagy` 同时指向同一个本地 Capture Server,多轮主 Agent 与子 Agent 请求解析后的 JSON 负载及关键协议头已实现逐字段一致(由 `packages/pyagy/tests/test_wire_parity.py` 回归覆盖)。
65
+
66
+ ### 2.1 Gemini Wire 请求结构与客户端指纹
67
+
68
+ - **端点路径**:统一发送 `POST /v1beta/models/{api_model}:streamGenerateContent?alt=sse`。
69
+ - **请求头对齐**:固定发送 `Content-Type: application/json`、`Accept-Encoding: gzip`、`x-goog-api-key`,并将 `User-agent` 与 `x-goog-api-client` 锁定为 `agy 1.5.14` 的 `google-genai-sdk/1.79.1 ...` 指纹(自动忽略 provider 配置中旧版本的同名 header 覆盖);支持响应流 gzip 解压。
70
+ - **顶层字段顺序**:固定按 `['contents', 'generationConfig', 'systemInstruction', 'tools']` 顺序序列化(显式指定 `tool_choice` 时追加 `toolConfig`)。
71
+
72
+ ### 2.2 模型目录与 `generationConfig` 映射
73
+
74
+ - **25 个官方模型**:完整对齐 `OFFICIAL_MODELS` 的 slug、人类可读显示名(如 `Gemini 4 Carbon (High)`)及底层 `api_model` 映射,支持 `model:route` 路由后缀原样透传。
75
+ - **推理配置分档**:
76
+ - Gemini 4(Neon / Carbon / Hydrogen / Argon)与 Gemini 3.8 / 3.7 / 3.6 Flash:`maxOutputTokens: 65536`,`thinkingConfig: {"includeThoughts": true, "thinkingLevel": "LOW|MEDIUM|HIGH|XHIGH"}`(仅 `neon` 与 `hydrogen` 保留 `XHIGH`,其余自动收敛至 `HIGH`)。
77
+ - `gemini-3.1-pro-high` / `gemini-3.1-pro-low`:映射至 `gemini-3.1-pro-preview`,`maxOutputTokens: 65535`,`thinkingConfig` 使用 `thinkingBudget`(`low -> 1024`,`high -> -1`)。
78
+ - 子 Agent 模型分档:`inherit` 继承父模型与显式 effort,`flash_lite -> gemini-3.6-flash-low`,`flash -> gemini-3.8-flash-high`,`pro -> gemini-4-carbon-high`。
79
+
80
+ ### 2.3 12 段式 `systemInstruction`、技能与规则发现
81
+
82
+ - **指令装配**:`systemInstruction` 外层固定 `role: "user"`,正文严格按静态前缀(`<identity>`、`<artifacts>`、`<conversation_transcript>`、`<guidelines>`、`<work_efficiently>`、`<communication_style>`、`<slash_commands>`、`<messaging>`、`<subagents>`)+ `<skills>` + `<user_rules>` + `<user_information>` 拼接。
83
+ - **技能发现与过滤**:默认挂载 5 个内置技能(`agy-customizations`、`antigravity-guide`、`run-workflow`、`swarm_monitor`、`swarm_pane`),并按优先级扫描 `~/.gemini/config/skills` 及所有工作区从 Git 仓库根到当前目录祖先链下的 `.agents/.agent/_agents/_agent/skills`,支持过滤 `disable-model-invocation: true` 并按技能名排序。
84
+ - **规则发现与多工作区**:沿 Git 仓库根到工作区目录的祖先链按序收集 `AGENTS.md` 与 `GEMINI.md`,使用 `<RULE[绝对路径]>` 标签包裹(不混入 `~/.codex/AGENTS.md`);支持 `--add-dir` 多工作区去重排序。
85
+
86
+ ### 2.4 多轮历史、Thought 签名与工具往返格式
87
+
88
+ - **用户消息锚定包装**:自动包裹 `<USER_REQUEST>` 与带本地时区秒级时间戳的 `<ADDITIONAL_METADATA>`;首轮或模型显示名发生变更时附加 `<USER_SETTINGS_CHANGE>`,未变更轮次不重复附加,历史轮次保持原时间戳不变。
89
+ - **流式思考与签名还原**:
90
+ - 纯文本回复:合并流式 `thought` 文本分片,并将 `thought` 与正文分片上的 `thoughtSignature`(含流末尾空文本签名分片)按字节拼接后置于最终正文 part。
91
+ - 工具调用回复:前置 `thought` 仅在自身携带签名时保留,无签名前置 `thought` 自动丢弃;保留各 `functionCall` 原生签名,若整轮无任何签名则在首个 `functionCall` 填充 `skip_thought_signature_validator`;每个 `functionCall` 固定键序 `['args', 'id', 'name']` 并对 `args` 递归按键名排序。
92
+ - **`functionResponse` 与系统消息拼接**:
93
+ - 工具返回外层固定 `role: "model"`,同一批次连续工具结果合并为一个 `contents` 条目,且绝不并入前一条 `functionCall` 模型消息。
94
+ - 成功结果写入 `response.output`,失败结果写入 `response.error`(自动补齐 `Encountered error in tool execution: ` 前缀);图片工具结果写入 `functionResponse.parts[].inlineData`,字段顺序保持 `['id', 'name', 'parts', 'response']`。
95
+ - 工具执行期间到达的一个或多个后台任务 / 子 Agent `<SYSTEM_MESSAGE>` 自动以 `\n\n` 追加到紧邻的最后一个 `functionResponse` 文本末尾。
96
+
97
+ ### 2.5 14 个工具声明与 11 个已实现工具核心行为
98
+
99
+ - **工具声明表**:全部 14 个工具的排列顺序、描述文本及 `parametersJsonSchema`(含 `$schema`、`additionalProperties`、`required` 等)与官方首轮请求完全一致。
100
+ - **文件读写编辑**:`read_file`(绝对路径校验、空文件提示、行号切片、`ByteOffset` 续读、单次 800 行 / 46080 字节上限、PNG/JPEG/GIF/WebP 图片多模态读取)、`write_file`(自动建父目录、默认防覆盖、`Overwrite`/`Append` 互斥校验、Artifact 元数据落盘)、`edit_file`(全量精确替换、替换次数及起始行与增删行数统计)。
101
+ - **命令执行与定时任务**:`run_command`(PTY 会话执行、`WaitMsBeforeAsync` 500~10000ms 同步等待或转后台任务、按 Gemini 4 / 3.x / 3.1 Pro 区分后台返回提示语、完成或取消后自动投递 `<SYSTEM_MESSAGE>`)、`manage_task`(`list` / `status` / `send_input` / `kill`)、`schedule`(单次倒计时支持 `TimerCondition` `never`/`any`/`<sender>` 来信早停,5 段式 Cron 支持抖动、`ExactTiming`、`IsDaemon` 与 `MaxIterations`)。`background_work_count` 包含所有仍能唤醒会话的后台命令和定时任务,打印模式只等待非守护任务。`background_work_snapshot` 省略原始命令行与提示词。
102
+ - **工具输出 10 KiB 中间截断与步骤文件落盘**:同步 `run_command`、后台 `run_command` 完成时的 `<SYSTEM_MESSAGE>` 结果正文,以及其余非 `read_file` 纯文本工具输出超过 `10,240` UTF-8 字节时,统一按官方格式保留首尾合法 UTF-8 切片与 `\n<truncated X of Y bytes from the middle of the output>\n` 标记,并将完整原始输出写入 `.system_generated/steps/<step_index>/output.txt`(同步与后台完成的 `run_command` 始终落盘步骤输出文件,`read_file` 保持独立的 800 行 / 46,080 字节限制)。
103
+ - **本地恢复扩展**:按会话保存待触发的 `schedule`。恢复时沿用任务 ID、下一次截止时间、取消条件及已触发次数。已过期的 cron 补发一次后按原表达式继续;已取消和完成的任务在关闭前即移除恢复记录。
104
+ - **子 Agent 与跨会话通信**:`define_subagent`(自定义蓝图与写/子 Agent 工具开关)、`invoke_subagent`(支持 `self` / `research` / `image-generator` 及自定义类型、`Workspace` 支持 `inherit` / `branch` 目录克隆 / `share` Git worktree 隔离、按类型构造专属系统提示词与 `<subagent_reminder>`)、`send_message`(父子及同级双向消息投递与唤醒、已主动汇报时抑制重复空闲通知)、`manage_subagents`(直属子 Agent 列表及递归终止清理派生工作区);运行中的直属子 Agent 同步通过 `AgySubagentWorkTracker` 纳入父会话 `background_work_count` 与 `background_work_snapshot`。
105
+
106
+ ### 2.6 上下文压缩、会话恢复与 CLI 模式
107
+
108
+ - **自动与手动压缩**:按模型阈值(Gemini 4 Neon/Carbon/Argon `512000`,其余官方模型 `256000`,支持环境变量 `AGY_CLI_AUTO_COMPACT_OVERRIDE` 整数或 `1%..100%` 覆盖)以 `promptTokenCount + candidatesTokenCount + thoughtsTokenCount` 锚点加尾部未采样增量估算在调用前自动触发压缩(对外 `usage.input_tokens` 按官方语义扣除 `cache_read_tokens`);支持 `/compact` 与 `/compact <follow-up>` 手动压缩(附加 `ON-DEMAND COMPACTION` 后缀),压缩请求自动切换模型对应的 `compaction_max_output_tokens`(`32768` 或 `16384`)。若普通请求或压缩请求本身遇到 `ContextLengthExceeded`,自动回退至超长 `<SYSTEM_MESSAGE>` / 工具结果截断与最旧工具结果裁剪以完成恢复。
109
+ - **`<CONTEXT_SUMMARY>` 与恢复**:压缩后历史替换为标准 `<CONTEXT_SUMMARY>`(包含最近 10 条用户请求或父 Agent 消息、按 ID 排序的已创建子 Agent 摘要块及日志路径说明),同时写入 `CHECKPOINT` 步骤;`--continue` / `--conversation` 跨进程恢复历史后在下一轮用户消息后自动附带重启提醒 `<SYSTEM_MESSAGE>`。
110
+ - **CLI 输入输出模式**:支持 `-p` 非交互打印、交互式 REPL(`/model`、`/effort`、`/compact`、`/status`)、`models` / `agents` 子命令,以及 `--input-format stream-json` 与 `--output-format text|json|stream-json` 流式事件输出。
pyagy-0.7.1/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 OpenAI
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
pyagy-0.7.1/PKG-INFO ADDED
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyagy
3
+ Version: 0.7.1
4
+ Summary: Antigravity CLI (agy 1.5.14) wire-compatible harness built on python-codex
5
+ License-File: LICENSE
6
+ Requires-Python: >=3.7
7
+ Requires-Dist: python-codex==0.7.1
8
+ Description-Content-Type: text/markdown
9
+
10
+ # pyagy
11
+
12
+ Antigravity CLI (`agy 1.5.14`) wire-compatible CLI harness built on top of `pycodex` and `responses_server`.
13
+
14
+ ## Quick Start
15
+
16
+ Start from [config_examples/pyagy.config.toml](../../config_examples/pyagy.config.toml) and save it as `~/.codex/pyagy.config.toml` (with `GEMINI_API_KEY` set in the environment or `~/.codex/.env`):
17
+
18
+ ```toml
19
+ model = "gemini-4-carbon-high"
20
+ model_provider = "gemini"
21
+ compat_api = "gemini"
22
+ harness = "pyagy"
23
+ model_reasoning_effort = "high"
24
+
25
+ [model_providers.gemini]
26
+ base_url = "https://api.example.invalid/v1beta"
27
+ env_key = "GEMINI_API_KEY"
28
+ ```
29
+
30
+ Run from the CLI against any profile with `compat_api = "gemini"`:
31
+
32
+ ```bash
33
+ env -u VIRTUAL_ENV PYTHONPATH=.:packages/pyagy \
34
+ uv run python -m pyagy --profile pyagy -p "Hello"
35
+ ```
36
+
37
+ ## Compaction & Multi-Agent Messaging
38
+
39
+ - **Context Compaction & Tool Output Truncation (`agy 1.5.14` wire parity)**:
40
+ - Pre-invocation auto-compaction triggers when estimated context tokens reach the model's threshold (`512000` for Gemini 4 Neon/Carbon/Argon, `256000` for Gemini 4 Hydrogen / 3.8 / 3.7 / 3.6 Flash / 3.1 Pro, or `AGY_CLI_AUTO_COMPACT_OVERRIDE` integer / `1..100%`), with automatic overflow fallback on `ContextLengthExceeded`.
41
+ - Sync and background `run_command` outputs (as well as other non-`read_file` plain-text tool outputs exceeding `10,240` UTF-8 bytes) apply exact middle truncation and persist full output under `.system_generated/steps/<step_index>/output.txt`.
42
+ - Manual `/compact` and `/compact <follow-up>` emit the on-demand compaction prompt (`maxOutputTokens` `32768` / `16384`), replace conversation history with `<CONTEXT_SUMMARY>`, and persist `CHECKPOINT` transcript steps across `--continue` / `--conversation`.
43
+ - **Subagent -> Root Messaging**:
44
+ - Subagents spawned via `invoke_subagent` receive the caller's `conversation_id` and can proactively send progress or questions back to root (or any live peer) via `send_message(Recipient=<root_id>, Message=...)`, in addition to automatic idle reporting.
45
+
46
+ ## Web Workspace (`pycodex-ws`) Profile Integration
47
+
48
+ Add `harness = "pyagy"` (default is `harness = "pycodex"`) to any Gemini profile (`compat_api = "gemini"`, such as `~/.codex/gemini-pool.config.toml`) to switch `pycodex-ws` Web sessions for that profile to the `pyagy` backend:
49
+
50
+ - **Optional Context Alignment**: When created from `pycodex-ws`, optional `ContextConfig` inputs (`extra_contextual_user_messages` such as Canvas board instructions when `enable_board=True` and `<external_call_context>`, `include_environment_context`, `developer_instructions`, `user_instructions`, `base_instructions_override`, and `codex_home/skills` when `include_skills_instructions=True`) are injected dynamically without altering pure CLI wire parity.
51
+ - **Disabled `ask_question` Runtime**: `ask_question` retains its official declaration in `tools` for 100% wire parity, and immediately returns `Encountered error in tool execution: ask_question is disabled` when called (without prompting).
52
+ - **Web UI Features**: Supports `/compact`, `/model`, `/effort`, `/cd`, live subagent tree (`/api/sessions/<id>/agents`), background task & subagent tracking (`idle: sleeping` status and `/api/sessions/<id>/background-work`), rollout tab persistence, and in-place Reload PyCodex.
53
+ - An idle session shows `idle: sleeping` while a background command or schedule can wake it, including daemon jobs. Print mode can exit with daemons still pending.
54
+ - Pending one-shot timers and cron jobs store their next deadline, prompt and progress under the conversation’s `.system_generated/tasks/`. Web rollout restore, `--continue` and `--conversation` rearm them. An overdue timer fires on resume. A cron delivers one overdue notification, then continues on its calendar with its remaining iteration budget. Timers created by older versions with only a task log need to be scheduled again. Shell processes end when the session closes.
55
+ - The workspace enables `preview_reasoning` for pyagy Web views and Feishu cards. Root and subagent previews show the full current reasoning text or summary, including paragraph breaks. The next assistant delta replaces it with the accumulated reply text. Recorded items retain their original roles for Gemini replay.
56
+
57
+ ## Verification
58
+
59
+ See [ALIGNMENT.md](ALIGNMENT.md) for the detailed alignment status (unaligned/placeholder items vs verified wire-compatible contracts) against official `agy 1.5.14`.
60
+
61
+ ```bash
62
+ env -u VIRTUAL_ENV PYTHONPATH=.:packages/pyagy \
63
+ uv run --dev pytest packages/pyagy/tests
64
+ ```
pyagy-0.7.1/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # pyagy
2
+
3
+ Antigravity CLI (`agy 1.5.14`) wire-compatible CLI harness built on top of `pycodex` and `responses_server`.
4
+
5
+ ## Quick Start
6
+
7
+ Start from [config_examples/pyagy.config.toml](../../config_examples/pyagy.config.toml) and save it as `~/.codex/pyagy.config.toml` (with `GEMINI_API_KEY` set in the environment or `~/.codex/.env`):
8
+
9
+ ```toml
10
+ model = "gemini-4-carbon-high"
11
+ model_provider = "gemini"
12
+ compat_api = "gemini"
13
+ harness = "pyagy"
14
+ model_reasoning_effort = "high"
15
+
16
+ [model_providers.gemini]
17
+ base_url = "https://api.example.invalid/v1beta"
18
+ env_key = "GEMINI_API_KEY"
19
+ ```
20
+
21
+ Run from the CLI against any profile with `compat_api = "gemini"`:
22
+
23
+ ```bash
24
+ env -u VIRTUAL_ENV PYTHONPATH=.:packages/pyagy \
25
+ uv run python -m pyagy --profile pyagy -p "Hello"
26
+ ```
27
+
28
+ ## Compaction & Multi-Agent Messaging
29
+
30
+ - **Context Compaction & Tool Output Truncation (`agy 1.5.14` wire parity)**:
31
+ - Pre-invocation auto-compaction triggers when estimated context tokens reach the model's threshold (`512000` for Gemini 4 Neon/Carbon/Argon, `256000` for Gemini 4 Hydrogen / 3.8 / 3.7 / 3.6 Flash / 3.1 Pro, or `AGY_CLI_AUTO_COMPACT_OVERRIDE` integer / `1..100%`), with automatic overflow fallback on `ContextLengthExceeded`.
32
+ - Sync and background `run_command` outputs (as well as other non-`read_file` plain-text tool outputs exceeding `10,240` UTF-8 bytes) apply exact middle truncation and persist full output under `.system_generated/steps/<step_index>/output.txt`.
33
+ - Manual `/compact` and `/compact <follow-up>` emit the on-demand compaction prompt (`maxOutputTokens` `32768` / `16384`), replace conversation history with `<CONTEXT_SUMMARY>`, and persist `CHECKPOINT` transcript steps across `--continue` / `--conversation`.
34
+ - **Subagent -> Root Messaging**:
35
+ - Subagents spawned via `invoke_subagent` receive the caller's `conversation_id` and can proactively send progress or questions back to root (or any live peer) via `send_message(Recipient=<root_id>, Message=...)`, in addition to automatic idle reporting.
36
+
37
+ ## Web Workspace (`pycodex-ws`) Profile Integration
38
+
39
+ Add `harness = "pyagy"` (default is `harness = "pycodex"`) to any Gemini profile (`compat_api = "gemini"`, such as `~/.codex/gemini-pool.config.toml`) to switch `pycodex-ws` Web sessions for that profile to the `pyagy` backend:
40
+
41
+ - **Optional Context Alignment**: When created from `pycodex-ws`, optional `ContextConfig` inputs (`extra_contextual_user_messages` such as Canvas board instructions when `enable_board=True` and `<external_call_context>`, `include_environment_context`, `developer_instructions`, `user_instructions`, `base_instructions_override`, and `codex_home/skills` when `include_skills_instructions=True`) are injected dynamically without altering pure CLI wire parity.
42
+ - **Disabled `ask_question` Runtime**: `ask_question` retains its official declaration in `tools` for 100% wire parity, and immediately returns `Encountered error in tool execution: ask_question is disabled` when called (without prompting).
43
+ - **Web UI Features**: Supports `/compact`, `/model`, `/effort`, `/cd`, live subagent tree (`/api/sessions/<id>/agents`), background task & subagent tracking (`idle: sleeping` status and `/api/sessions/<id>/background-work`), rollout tab persistence, and in-place Reload PyCodex.
44
+ - An idle session shows `idle: sleeping` while a background command or schedule can wake it, including daemon jobs. Print mode can exit with daemons still pending.
45
+ - Pending one-shot timers and cron jobs store their next deadline, prompt and progress under the conversation’s `.system_generated/tasks/`. Web rollout restore, `--continue` and `--conversation` rearm them. An overdue timer fires on resume. A cron delivers one overdue notification, then continues on its calendar with its remaining iteration budget. Timers created by older versions with only a task log need to be scheduled again. Shell processes end when the session closes.
46
+ - The workspace enables `preview_reasoning` for pyagy Web views and Feishu cards. Root and subagent previews show the full current reasoning text or summary, including paragraph breaks. The next assistant delta replaces it with the accumulated reply text. Recorded items retain their original roles for Gemini replay.
47
+
48
+ ## Verification
49
+
50
+ See [ALIGNMENT.md](ALIGNMENT.md) for the detailed alignment status (unaligned/placeholder items vs verified wire-compatible contracts) against official `agy 1.5.14`.
51
+
52
+ ```bash
53
+ env -u VIRTUAL_ENV PYTHONPATH=.:packages/pyagy \
54
+ uv run --dev pytest packages/pyagy/tests
55
+ ```
@@ -0,0 +1,8 @@
1
+ """Antigravity CLI (agy 1.5.14) wire-compatible mode built on pycodex."""
2
+
3
+ from pycodex.utils.compat import importlib_metadata
4
+
5
+ try:
6
+ __version__ = importlib_metadata.version("pyagy")
7
+ except importlib_metadata.PackageNotFoundError: # pragma: no cover - uninstalled checkout
8
+ __version__ = "0.7.1"
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(main())