ChatTask 0.1.3__tar.gz → 0.1.6__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.
Files changed (45) hide show
  1. {chattask-0.1.3/src/ChatTask.egg-info → chattask-0.1.6}/PKG-INFO +16 -2
  2. {chattask-0.1.3 → chattask-0.1.6}/README.md +12 -1
  3. {chattask-0.1.3 → chattask-0.1.6}/pyproject.toml +3 -3
  4. {chattask-0.1.3 → chattask-0.1.6/src/ChatTask.egg-info}/PKG-INFO +16 -2
  5. {chattask-0.1.3 → chattask-0.1.6}/src/ChatTask.egg-info/SOURCES.txt +8 -0
  6. {chattask-0.1.3 → chattask-0.1.6}/src/ChatTask.egg-info/requires.txt +3 -0
  7. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/__init__.py +3 -3
  8. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/auth.py +5 -1
  9. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/cli.py +133 -0
  10. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/codex_tasks.py +136 -12
  11. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/config.py +9 -3
  12. chattask-0.1.6/src/chattask/durable.py +818 -0
  13. chattask-0.1.6/src/chattask/durable_archive.py +90 -0
  14. chattask-0.1.6/src/chattask/durable_research.py +67 -0
  15. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/executor.py +1 -2
  16. chattask-0.1.6/src/chattask/overleaf_native.mjs +279 -0
  17. chattask-0.1.6/src/chattask/research.py +631 -0
  18. chattask-0.1.6/src/chattask/research_compiler.py +161 -0
  19. chattask-0.1.6/src/chattask/research_discovery.py +76 -0
  20. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/service.py +47 -70
  21. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/settings.py +61 -7
  22. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/web.py +212 -10
  23. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/web_static/app.js +244 -0
  24. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/web_static/index.html +62 -0
  25. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/web_static/style.css +1 -0
  26. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/workflow.py +1 -1
  27. chattask-0.1.6/src/chattask/workspace_analysis.py +579 -0
  28. {chattask-0.1.3 → chattask-0.1.6}/tests/test_version.py +1 -1
  29. {chattask-0.1.3 → chattask-0.1.6}/LICENSE +0 -0
  30. {chattask-0.1.3 → chattask-0.1.6}/setup.cfg +0 -0
  31. {chattask-0.1.3 → chattask-0.1.6}/src/ChatTask.egg-info/dependency_links.txt +0 -0
  32. {chattask-0.1.3 → chattask-0.1.6}/src/ChatTask.egg-info/entry_points.txt +0 -0
  33. {chattask-0.1.3 → chattask-0.1.6}/src/ChatTask.egg-info/top_level.txt +0 -0
  34. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/agent_tasks.py +0 -0
  35. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/broker.py +0 -0
  36. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/package_plan.py +0 -0
  37. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/package_publication.py +0 -0
  38. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/package_service.py +0 -0
  39. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/package_template.py +0 -0
  40. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/package_validation.py +0 -0
  41. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/release.py +0 -0
  42. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/source.py +0 -0
  43. {chattask-0.1.3 → chattask-0.1.6}/src/chattask/tool_client.py +0 -0
  44. {chattask-0.1.3 → chattask-0.1.6}/tests/test_cli.py +0 -0
  45. {chattask-0.1.3 → chattask-0.1.6}/tests/test_docs_deployment.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ChatTask
3
- Version: 0.1.3
3
+ Version: 0.1.6
4
4
  Summary: ChatTask: a ChatArch Python package.
5
5
  Author-email: ChatArch <rex@chatarch.org>
6
6
  License-Expression: MIT
@@ -16,6 +16,7 @@ License-File: LICENSE
16
16
  Requires-Dist: click<9.0,>=8.0
17
17
  Requires-Dist: chatstyle<0.3.0,>=0.2.0
18
18
  Requires-Dist: chatenv<0.3.0,>=0.2.15
19
+ Requires-Dist: ChatSandbox<0.2.0,>=0.1.0
19
20
  Requires-Dist: opensandbox==1.1.0
20
21
  Requires-Dist: docker<8,>=7
21
22
  Requires-Dist: httpx<0.29,>=0.28
@@ -23,6 +24,8 @@ Requires-Dist: packaging<27,>=24
23
24
  Requires-Dist: tomli<3,>=2; python_version < "3.11"
24
25
  Provides-Extra: dev
25
26
  Requires-Dist: build; extra == "dev"
27
+ Requires-Dist: setuptools>=61.0; extra == "dev"
28
+ Requires-Dist: wheel; extra == "dev"
26
29
  Requires-Dist: pytest; extra == "dev"
27
30
  Requires-Dist: twine; extra == "dev"
28
31
  Provides-Extra: web
@@ -53,9 +56,20 @@ ChatTask 从 0.1.0 版本起提供可复用的任务模板、受信 Git 源码
53
56
 
54
57
  ChatTask 的主模型是 **任务 → Codex + Sandbox → 结果**。任务说明和所选镜像决定工作内容;发包只是示例,不是执行器的固定步骤。当前源码提供 `chattask run` 和受站点登录保护的 `/api/agent/tasks`,结果保存原生事件、产物摘要和 Sandbox 回收证据。镜像预装 infra,运行时 env 只注入服务端选择的模型/工具凭据;优先使用短期受限网关,不把原始 GitHub/PyPI 凭据交给 guest。参见[通用任务、Python 发包模板与网关边界](docs/tasks.md)。源码能力不等于 PyPI 或线上已更新。
55
58
 
59
+ ### 长期任务候选
60
+
61
+ “长期任务”视图和 `chattask task` 命令保存稳定 Task 与逐轮 Run;独立 `chattask worker --env-profile site --operator operator` 处理队列。每轮保存受限的工作区与原生 Codex 会话检查点,后续轮次在新 Sandbox 原生接续。暂停是排队前或本轮结束时的协作式操作。生产部署须单独核验真实镜像、网关、原服务和浏览器;详见[长期任务合约](docs/tasks.md#长期任务候选)。
62
+
63
+ 显式选择 `research` 时,可提交已核对来源记录,也可通过受限的 arXiv 摘要自动检索创建;后者只保存摘要,不代表读过论文全文。受信 worker 在本轮原生执行及清理通过后,将 `result/research/main.tex` 等文件发布到配置的原 Overleaf 工程并核对源码;PDF 由独立隔离容器使用原服务镜像和只读公共 TeX 工具链编译,PDF/源码回读归入本轮产物。未知外部写入或编译清理结果保持阻塞,需显式同操作核对。普通开发任务不依赖 Overleaf 配置。
64
+
56
65
  ## 从源码使用
57
66
 
67
+ ### Workspace 材料分析
68
+
69
+ 从 0.1.4 起,受信 Workspace 可创建资料快照、单独确认运行,并回读真实模型生成的摘要校验报告。Task 页面「材料分析」显示任务来源与 Run 历史。这是只读材料执行器,不调用工具或读取宿主文件,也不会把报告完成标成原建议完成;配置、认证与 HTTP 合约见[材料分析接入](docs/workspace.md)。
70
+
58
71
  ```bash
72
+ python -m pip install -e ./packages/chatsandbox
59
73
  python -m pip install -e '.[web,dev]'
60
74
  chattask --tree
61
75
  chattask paths --json-output
@@ -63,7 +77,7 @@ chattask repository register --id demo --path /srv/managed/demo --github-repo ow
63
77
  chattask serve --env-profile site --host 127.0.0.1 --port 8000
64
78
  ```
65
79
 
66
- 必须先配置已有 OpenSandbox 控制面、站点账号和既有 PyPI ChatEnv 命名连接 `task-tools`;配置详情见[快速接入](docs/index.md)。仓库路径只可通过服务器 CLI 登记,浏览器只能选择 ID。Web、Tool、Sandbox 和 ChatGH 的真实生产验收由部署方完成;源码测试使用标明的合成依赖。
80
+ 必须先配置原 OpenSandbox Docker 连接或显式的 ChatSandbox 命名 profile、站点账号和既有 PyPI ChatEnv 命名连接 `task-tools`;见[快速接入](docs/index.md)与[公共后端](docs/sandbox-backends.md)。同仓库 `packages/chatsandbox/` 是独立发行包,先从源码安装,公开发布需先于依赖它的新版 ChatTask。仓库路径只可通过服务器 CLI 登记,浏览器只能选择 ID。Web、Tool、Sandbox 和 ChatGH 的真实生产验收由部署方完成;源码测试使用标明的合成依赖。
67
81
 
68
82
  ## 边界
69
83
 
@@ -13,9 +13,20 @@ ChatTask 从 0.1.0 版本起提供可复用的任务模板、受信 Git 源码
13
13
 
14
14
  ChatTask 的主模型是 **任务 → Codex + Sandbox → 结果**。任务说明和所选镜像决定工作内容;发包只是示例,不是执行器的固定步骤。当前源码提供 `chattask run` 和受站点登录保护的 `/api/agent/tasks`,结果保存原生事件、产物摘要和 Sandbox 回收证据。镜像预装 infra,运行时 env 只注入服务端选择的模型/工具凭据;优先使用短期受限网关,不把原始 GitHub/PyPI 凭据交给 guest。参见[通用任务、Python 发包模板与网关边界](docs/tasks.md)。源码能力不等于 PyPI 或线上已更新。
15
15
 
16
+ ### 长期任务候选
17
+
18
+ “长期任务”视图和 `chattask task` 命令保存稳定 Task 与逐轮 Run;独立 `chattask worker --env-profile site --operator operator` 处理队列。每轮保存受限的工作区与原生 Codex 会话检查点,后续轮次在新 Sandbox 原生接续。暂停是排队前或本轮结束时的协作式操作。生产部署须单独核验真实镜像、网关、原服务和浏览器;详见[长期任务合约](docs/tasks.md#长期任务候选)。
19
+
20
+ 显式选择 `research` 时,可提交已核对来源记录,也可通过受限的 arXiv 摘要自动检索创建;后者只保存摘要,不代表读过论文全文。受信 worker 在本轮原生执行及清理通过后,将 `result/research/main.tex` 等文件发布到配置的原 Overleaf 工程并核对源码;PDF 由独立隔离容器使用原服务镜像和只读公共 TeX 工具链编译,PDF/源码回读归入本轮产物。未知外部写入或编译清理结果保持阻塞,需显式同操作核对。普通开发任务不依赖 Overleaf 配置。
21
+
16
22
  ## 从源码使用
17
23
 
24
+ ### Workspace 材料分析
25
+
26
+ 从 0.1.4 起,受信 Workspace 可创建资料快照、单独确认运行,并回读真实模型生成的摘要校验报告。Task 页面「材料分析」显示任务来源与 Run 历史。这是只读材料执行器,不调用工具或读取宿主文件,也不会把报告完成标成原建议完成;配置、认证与 HTTP 合约见[材料分析接入](docs/workspace.md)。
27
+
18
28
  ```bash
29
+ python -m pip install -e ./packages/chatsandbox
19
30
  python -m pip install -e '.[web,dev]'
20
31
  chattask --tree
21
32
  chattask paths --json-output
@@ -23,7 +34,7 @@ chattask repository register --id demo --path /srv/managed/demo --github-repo ow
23
34
  chattask serve --env-profile site --host 127.0.0.1 --port 8000
24
35
  ```
25
36
 
26
- 必须先配置已有 OpenSandbox 控制面、站点账号和既有 PyPI ChatEnv 命名连接 `task-tools`;配置详情见[快速接入](docs/index.md)。仓库路径只可通过服务器 CLI 登记,浏览器只能选择 ID。Web、Tool、Sandbox 和 ChatGH 的真实生产验收由部署方完成;源码测试使用标明的合成依赖。
37
+ 必须先配置原 OpenSandbox Docker 连接或显式的 ChatSandbox 命名 profile、站点账号和既有 PyPI ChatEnv 命名连接 `task-tools`;见[快速接入](docs/index.md)与[公共后端](docs/sandbox-backends.md)。同仓库 `packages/chatsandbox/` 是独立发行包,先从源码安装,公开发布需先于依赖它的新版 ChatTask。仓库路径只可通过服务器 CLI 登记,浏览器只能选择 ID。Web、Tool、Sandbox 和 ChatGH 的真实生产验收由部署方完成;源码测试使用标明的合成依赖。
27
38
 
28
39
  ## 边界
29
40
 
@@ -9,7 +9,7 @@ description = "ChatTask: a ChatArch Python package."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
11
11
  license = "MIT"
12
- dependencies = ["click>=8.0,<9.0", "chatstyle>=0.2.0,<0.3.0", "chatenv>=0.2.15,<0.3.0", "opensandbox==1.1.0", "docker>=7,<8", "httpx>=0.28,<0.29", "packaging>=24,<27", "tomli>=2,<3; python_version < '3.11'"]
12
+ dependencies = ["click>=8.0,<9.0", "chatstyle>=0.2.0,<0.3.0", "chatenv>=0.2.15,<0.3.0", "ChatSandbox>=0.1.0,<0.2.0", "opensandbox==1.1.0", "docker>=7,<8", "httpx>=0.28,<0.29", "packaging>=24,<27", "tomli>=2,<3; python_version < '3.11'"]
13
13
  authors = [{name = "ChatArch", email = "rex@chatarch.org"}]
14
14
  keywords = ["chattask", "chatarch", "cli"]
15
15
  classifiers = [
@@ -26,7 +26,7 @@ Documentation = "https://arch.gh.wzhecnu.cn/ChatTask/"
26
26
  chattask = "chattask.cli:main"
27
27
 
28
28
  [project.optional-dependencies]
29
- dev = ["build", "pytest", "twine"]
29
+ dev = ["build", "setuptools>=61.0", "wheel", "pytest", "twine"]
30
30
  web = ["fastapi>=0.133,<0.143", "uvicorn>=0.41,<0.55", "ChatLogin[web]>=0.2.0,<0.3.0", "ChatPyPI>=0.2.14,<0.3.0", "ChatGH>=0.2.14,<0.3.0"]
31
31
  docs = ["mkdocs>=1.6,<2.0", "mkdocs-material>=9.5,<9.7", "mkdocs-static-i18n>=1.2,<2.0", "mike>=2.0,<3.0"]
32
32
 
@@ -43,4 +43,4 @@ where = ["src"]
43
43
  include-package-data = true
44
44
 
45
45
  [tool.setuptools.package-data]
46
- chattask = ["web_static/*.html", "web_static/*.css", "web_static/*.js"]
46
+ chattask = ["web_static/*.html", "web_static/*.css", "web_static/*.js", "overleaf_native.mjs"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ChatTask
3
- Version: 0.1.3
3
+ Version: 0.1.6
4
4
  Summary: ChatTask: a ChatArch Python package.
5
5
  Author-email: ChatArch <rex@chatarch.org>
6
6
  License-Expression: MIT
@@ -16,6 +16,7 @@ License-File: LICENSE
16
16
  Requires-Dist: click<9.0,>=8.0
17
17
  Requires-Dist: chatstyle<0.3.0,>=0.2.0
18
18
  Requires-Dist: chatenv<0.3.0,>=0.2.15
19
+ Requires-Dist: ChatSandbox<0.2.0,>=0.1.0
19
20
  Requires-Dist: opensandbox==1.1.0
20
21
  Requires-Dist: docker<8,>=7
21
22
  Requires-Dist: httpx<0.29,>=0.28
@@ -23,6 +24,8 @@ Requires-Dist: packaging<27,>=24
23
24
  Requires-Dist: tomli<3,>=2; python_version < "3.11"
24
25
  Provides-Extra: dev
25
26
  Requires-Dist: build; extra == "dev"
27
+ Requires-Dist: setuptools>=61.0; extra == "dev"
28
+ Requires-Dist: wheel; extra == "dev"
26
29
  Requires-Dist: pytest; extra == "dev"
27
30
  Requires-Dist: twine; extra == "dev"
28
31
  Provides-Extra: web
@@ -53,9 +56,20 @@ ChatTask 从 0.1.0 版本起提供可复用的任务模板、受信 Git 源码
53
56
 
54
57
  ChatTask 的主模型是 **任务 → Codex + Sandbox → 结果**。任务说明和所选镜像决定工作内容;发包只是示例,不是执行器的固定步骤。当前源码提供 `chattask run` 和受站点登录保护的 `/api/agent/tasks`,结果保存原生事件、产物摘要和 Sandbox 回收证据。镜像预装 infra,运行时 env 只注入服务端选择的模型/工具凭据;优先使用短期受限网关,不把原始 GitHub/PyPI 凭据交给 guest。参见[通用任务、Python 发包模板与网关边界](docs/tasks.md)。源码能力不等于 PyPI 或线上已更新。
55
58
 
59
+ ### 长期任务候选
60
+
61
+ “长期任务”视图和 `chattask task` 命令保存稳定 Task 与逐轮 Run;独立 `chattask worker --env-profile site --operator operator` 处理队列。每轮保存受限的工作区与原生 Codex 会话检查点,后续轮次在新 Sandbox 原生接续。暂停是排队前或本轮结束时的协作式操作。生产部署须单独核验真实镜像、网关、原服务和浏览器;详见[长期任务合约](docs/tasks.md#长期任务候选)。
62
+
63
+ 显式选择 `research` 时,可提交已核对来源记录,也可通过受限的 arXiv 摘要自动检索创建;后者只保存摘要,不代表读过论文全文。受信 worker 在本轮原生执行及清理通过后,将 `result/research/main.tex` 等文件发布到配置的原 Overleaf 工程并核对源码;PDF 由独立隔离容器使用原服务镜像和只读公共 TeX 工具链编译,PDF/源码回读归入本轮产物。未知外部写入或编译清理结果保持阻塞,需显式同操作核对。普通开发任务不依赖 Overleaf 配置。
64
+
56
65
  ## 从源码使用
57
66
 
67
+ ### Workspace 材料分析
68
+
69
+ 从 0.1.4 起,受信 Workspace 可创建资料快照、单独确认运行,并回读真实模型生成的摘要校验报告。Task 页面「材料分析」显示任务来源与 Run 历史。这是只读材料执行器,不调用工具或读取宿主文件,也不会把报告完成标成原建议完成;配置、认证与 HTTP 合约见[材料分析接入](docs/workspace.md)。
70
+
58
71
  ```bash
72
+ python -m pip install -e ./packages/chatsandbox
59
73
  python -m pip install -e '.[web,dev]'
60
74
  chattask --tree
61
75
  chattask paths --json-output
@@ -63,7 +77,7 @@ chattask repository register --id demo --path /srv/managed/demo --github-repo ow
63
77
  chattask serve --env-profile site --host 127.0.0.1 --port 8000
64
78
  ```
65
79
 
66
- 必须先配置已有 OpenSandbox 控制面、站点账号和既有 PyPI ChatEnv 命名连接 `task-tools`;配置详情见[快速接入](docs/index.md)。仓库路径只可通过服务器 CLI 登记,浏览器只能选择 ID。Web、Tool、Sandbox 和 ChatGH 的真实生产验收由部署方完成;源码测试使用标明的合成依赖。
80
+ 必须先配置原 OpenSandbox Docker 连接或显式的 ChatSandbox 命名 profile、站点账号和既有 PyPI ChatEnv 命名连接 `task-tools`;见[快速接入](docs/index.md)与[公共后端](docs/sandbox-backends.md)。同仓库 `packages/chatsandbox/` 是独立发行包,先从源码安装,公开发布需先于依赖它的新版 ChatTask。仓库路径只可通过服务器 CLI 登记,浏览器只能选择 ID。Web、Tool、Sandbox 和 ChatGH 的真实生产验收由部署方完成;源码测试使用标明的合成依赖。
67
81
 
68
82
  ## 边界
69
83
 
@@ -14,19 +14,27 @@ src/chattask/broker.py
14
14
  src/chattask/cli.py
15
15
  src/chattask/codex_tasks.py
16
16
  src/chattask/config.py
17
+ src/chattask/durable.py
18
+ src/chattask/durable_archive.py
19
+ src/chattask/durable_research.py
17
20
  src/chattask/executor.py
21
+ src/chattask/overleaf_native.mjs
18
22
  src/chattask/package_plan.py
19
23
  src/chattask/package_publication.py
20
24
  src/chattask/package_service.py
21
25
  src/chattask/package_template.py
22
26
  src/chattask/package_validation.py
23
27
  src/chattask/release.py
28
+ src/chattask/research.py
29
+ src/chattask/research_compiler.py
30
+ src/chattask/research_discovery.py
24
31
  src/chattask/service.py
25
32
  src/chattask/settings.py
26
33
  src/chattask/source.py
27
34
  src/chattask/tool_client.py
28
35
  src/chattask/web.py
29
36
  src/chattask/workflow.py
37
+ src/chattask/workspace_analysis.py
30
38
  src/chattask/web_static/app.js
31
39
  src/chattask/web_static/index.html
32
40
  src/chattask/web_static/style.css
@@ -1,6 +1,7 @@
1
1
  click<9.0,>=8.0
2
2
  chatstyle<0.3.0,>=0.2.0
3
3
  chatenv<0.3.0,>=0.2.15
4
+ ChatSandbox<0.2.0,>=0.1.0
4
5
  opensandbox==1.1.0
5
6
  docker<8,>=7
6
7
  httpx<0.29,>=0.28
@@ -11,6 +12,8 @@ tomli<3,>=2
11
12
 
12
13
  [dev]
13
14
  build
15
+ setuptools>=61.0
16
+ wheel
14
17
  pytest
15
18
  twine
16
19
 
@@ -1,6 +1,6 @@
1
1
  """ChatTask: explicit task execution, sessions and an optional browser adapter."""
2
2
 
3
- __version__ = "0.1.3"
3
+ __version__ = "0.1.6"
4
4
  __all__ = ["__version__", "TaskService", "TaskSettings", "create_app", "state_paths", "WorkflowService", "TaskStore"]
5
5
 
6
6
 
@@ -17,9 +17,9 @@ def __getattr__(name):
17
17
  raise AttributeError(name)
18
18
 
19
19
 
20
- def create_app(settings=None, *, service=None, workflow=None, agent_tasks=None):
20
+ def create_app(settings=None, *, service=None, workflow=None, agent_tasks=None, analysis=None, auth_adapter=None, durable_tasks=None):
21
21
  from .web import create_app as factory
22
- return factory(settings, service=service, workflow=workflow, agent_tasks=agent_tasks)
22
+ return factory(settings, service=service, workflow=workflow, agent_tasks=agent_tasks, analysis=analysis, auth_adapter=auth_adapter, durable_tasks=durable_tasks)
23
23
 
24
24
 
25
25
  def state_paths(*, home=None):
@@ -1,4 +1,5 @@
1
1
  """Optional shared ChatLogin adapter; no second authentication protocol."""
2
+ import json
2
3
  from urllib.parse import urlsplit
3
4
  from chatlogin import PasswordBackend,Principal,SessionManager,MemorySessionStore,hash_password
4
5
  from chatlogin.fastapi import CookieSettings,FastAPIAuth
@@ -8,7 +9,10 @@ from chatlogin.ui import LoginUI
8
9
  def create_auth(settings):
9
10
  if not settings.username or not settings.password:
10
11
  raise ValueError('Web serving requires CHATTASK_LOGIN_USERNAME and CHATTASK_LOGIN_PASSWORD')
11
- backend=PasswordBackend({settings.username:(Principal('site-operator','站点管理员'),hash_password(settings.password))})
12
+ users={settings.username:(Principal('site-operator','站点管理员'),hash_password(settings.password))}
13
+ for entry in json.loads(settings.login_users_json or '[]'):
14
+ users[entry['username']]=(Principal(entry['principal_id'],entry['display_name']),hash_password(entry['password']))
15
+ backend=PasswordBackend(users)
12
16
  return FastAPIAuth(backend,SessionManager(MemorySessionStore(max_sessions=128),instance='chattask',ttl=86400),
13
17
  origin=settings.origin,cookie=CookieSettings(name='sandbox_site_session',secure=urlsplit(settings.origin).scheme=='https'),
14
18
  ui=LoginUI(title='Sandbox',subtitle='任务实验台 · 使用统一站点账号登录后,运行任务或继续一个环境。',
@@ -98,6 +98,139 @@ def run_command(instructions,instructions_file,image_profile,request_id,input_ta
98
98
  if result['status']!='completed':raise click.exceptions.Exit(1)
99
99
 
100
100
 
101
+ def _durable_service(env_profile):
102
+ from .settings import load_settings
103
+ from .durable import configured_service
104
+ return configured_service(load_settings(profile=env_profile))
105
+
106
+
107
+ def _durable_call(operation, env_profile, owner, *args):
108
+ import json
109
+ from .durable import DurableConflict
110
+ try:
111
+ result = getattr(_durable_service(env_profile), operation)(owner, *args)
112
+ except (KeyError, ValueError, OSError, DurableConflict) as exc:
113
+ raise click.ClickException(str(exc)) from exc
114
+ click.echo(json.dumps(result, ensure_ascii=False))
115
+
116
+
117
+ @main.group(name='task')
118
+ def task_group():
119
+ """Control private long-term Tasks; rounds execute in a separate worker."""
120
+
121
+
122
+ @task_group.command(name='create')
123
+ @click.argument('instructions')
124
+ @click.option('--image-profile', required=True)
125
+ @click.option('--workflow', type=click.Choice(['development','research']), default='development', show_default=True)
126
+ @click.option('--sources-file', type=click.Path(exists=True, dir_okay=False, path_type=str), help='JSON array of caller-verified research source records.')
127
+ @click.option('--request-id', required=True)
128
+ @click.option('--owner', required=True, help='Trusted local principal identity.')
129
+ @click.option('-e', '--env-profile', default=None)
130
+ def durable_create(instructions, image_profile, workflow, sources_file, request_id, owner, env_profile):
131
+ """Queue the first round of a long-term Task."""
132
+ import json
133
+ from pathlib import Path
134
+ body={'instructions': instructions, 'image_profile': image_profile, 'request_id': request_id, 'workflow': workflow}
135
+ if sources_file:
136
+ try:body['source_records']=json.loads(Path(sources_file).read_text(encoding='utf-8'))
137
+ except (OSError,ValueError) as exc:raise click.ClickException('invalid research sources JSON file') from exc
138
+ _durable_call('create', env_profile, owner, body)
139
+
140
+
141
+ @task_group.command(name='list')
142
+ @click.option('--owner', required=True)
143
+ @click.option('-e', '--env-profile', default=None)
144
+ def durable_list(owner, env_profile):
145
+ """List Tasks visible to a trusted local principal."""
146
+ _durable_call('list', env_profile, owner)
147
+
148
+
149
+ @task_group.command(name='show')
150
+ @click.argument('task_id')
151
+ @click.option('--owner', required=True)
152
+ @click.option('-e', '--env-profile', default=None)
153
+ def durable_show(task_id, owner, env_profile):
154
+ """Show a Task and its immutable round history."""
155
+ import json
156
+ try:
157
+ service = _durable_service(env_profile)
158
+ click.echo(json.dumps({'task': service.get(owner, task_id), 'runs': service.runs(owner, task_id)}, ensure_ascii=False))
159
+ except (KeyError, ValueError, OSError) as exc:
160
+ raise click.ClickException(str(exc)) from exc
161
+
162
+
163
+ @task_group.command(name='resume')
164
+ @click.argument('task_id')
165
+ @click.argument('instructions')
166
+ @click.option('--request-id', required=True)
167
+ @click.option('--acknowledge-unknown', is_flag=True, help='Confirm inspection of interrupted round and external side effects.')
168
+ @click.option('--sources-file', type=click.Path(exists=True, dir_okay=False, path_type=str), help='Optional new caller-verified research source records.')
169
+ @click.option('--owner', required=True)
170
+ @click.option('-e', '--env-profile', default=None)
171
+ def durable_resume(task_id, instructions, request_id, acknowledge_unknown, sources_file, owner, env_profile):
172
+ """Queue an explicit new native Codex round from a verified checkpoint."""
173
+ import json
174
+ from pathlib import Path
175
+ body={'request_id': request_id, 'instructions': instructions, 'acknowledge_unknown': acknowledge_unknown}
176
+ if sources_file:
177
+ try:body['source_records']=json.loads(Path(sources_file).read_text(encoding='utf-8'))
178
+ except (OSError,ValueError) as exc:raise click.ClickException('invalid research sources JSON file') from exc
179
+ _durable_call('resume', env_profile, owner, task_id, body)
180
+
181
+
182
+ @task_group.command(name='pause')
183
+ @click.argument('task_id')
184
+ @click.option('--request-id', required=True)
185
+ @click.option('--owner', required=True)
186
+ @click.option('-e', '--env-profile', default=None)
187
+ def durable_pause(task_id, request_id, owner, env_profile):
188
+ """Pause queued work now or request a cooperative end-of-round pause."""
189
+ _durable_call('pause', env_profile, owner, task_id, {'request_id': request_id})
190
+
191
+
192
+ @task_group.command(name='complete')
193
+ @click.argument('task_id')
194
+ @click.option('--request-id', required=True)
195
+ @click.option('--owner', required=True)
196
+ @click.option('-e', '--env-profile', default=None)
197
+ def durable_complete(task_id, request_id, owner, env_profile):
198
+ """Mark an inactive long-term Task complete; history remains available."""
199
+ _durable_call('complete', env_profile, owner, task_id, {'request_id': request_id})
200
+
201
+
202
+ @task_group.command(name='reconcile-research')
203
+ @click.argument('task_id')
204
+ @click.option('--request-id', required=True)
205
+ @click.option('--acknowledge-unknown', is_flag=True,
206
+ help='Confirm inspection of the original project before retrying the same operation identity.')
207
+ @click.option('--owner', required=True)
208
+ @click.option('-e', '--env-profile', default=None)
209
+ def durable_reconcile_research(task_id, request_id, acknowledge_unknown, owner, env_profile):
210
+ """Queue explicit same-round Research readback/reconciliation."""
211
+ _durable_call('reconcile_research', env_profile, owner, task_id,
212
+ {'request_id': request_id, 'acknowledge_unknown': acknowledge_unknown})
213
+
214
+
215
+ @main.command(name='worker')
216
+ @click.option('--once', is_flag=True, help='Claim at most one queued round, then exit.')
217
+ @click.option('--operator', required=True, help='Trusted local operator starting this single writer.')
218
+ @click.option('-e', '--env-profile', required=True, help='Named ChatEnv runtime configuration.')
219
+ def durable_worker(once, operator, env_profile):
220
+ """Run the independent durable queue executor under a process-held lock."""
221
+ import asyncio, json
222
+ from .settings import load_settings
223
+ from .durable import run_worker
224
+ if not operator.strip():
225
+ raise click.UsageError('nonempty --operator required')
226
+ try:
227
+ result = asyncio.run(run_worker(load_settings(profile=env_profile), once=once))
228
+ except (ValueError, OSError, RuntimeError) as exc:
229
+ raise click.ClickException(str(exc)) from exc
230
+ if once:
231
+ click.echo(json.dumps(result, ensure_ascii=False))
232
+
233
+
101
234
 
102
235
  @main.group(name='package')
103
236
  def package_group():
@@ -11,9 +11,9 @@ import json
11
11
  import re
12
12
  import shlex
13
13
  import tarfile
14
+ import uuid
14
15
  from urllib.parse import urlsplit
15
16
  from opensandbox.models.execd import RunCommandOpts
16
- from .service import TaskService
17
17
 
18
18
  @dataclass(frozen=True)
19
19
  class CodexRuntime:
@@ -73,6 +73,19 @@ with tarfile.open('/workspace/result.tar.gz','w:gz') as archive:
73
73
  print(json.dumps({'files':len(files),'bytes':total}))
74
74
  '''
75
75
 
76
+
77
+ def native_resume_argv(common, model, session_id, help_text, root_help):
78
+ """Build only the flags confirmed by the installed guest CLI help."""
79
+ try:
80
+ uuid.UUID(session_id)
81
+ except (ValueError, TypeError, AttributeError) as exc:
82
+ raise ValueError('invalid native Codex session id') from exc
83
+ if not all(flag in help_text for flag in ('SESSION_ID','--json','--output-last-message','--model','--skip-git-repo-check')) or not all(flag in root_help for flag in ('--cd','--sandbox')):
84
+ raise RuntimeError('guest Codex lacks required native resume flags')
85
+ return [*common,'--sandbox','danger-full-access','--cd','/workspace/work','exec','resume',
86
+ '--skip-git-repo-check','--model',model,'--json',
87
+ '--output-last-message','/workspace/agent-final.md',session_id,'-']
88
+
76
89
  class CodexTaskExecutor:
77
90
  def __init__(self,task_service,runtime:CodexRuntime,*,gateway=None,hosts=None):
78
91
  self.task_service=task_service;self.runtime=runtime;self.images=dict(runtime.images)
@@ -86,8 +99,50 @@ class CodexTaskExecutor:
86
99
  raise ValueError('conflicting trusted postprocessor')
87
100
  self.postprocessors[mode]=selected
88
101
 
102
+ async def execute_durable(self,task,run,checkpoint,save_checkpoint,progress):
103
+ """Internal-only invocation; public generic create cannot supply these fields."""
104
+ from .durable_archive import validate_checkpoint
105
+ if checkpoint is not None:
106
+ validate_checkpoint(checkpoint, expected=task['checkpoint'], session_id=run['session_id'])
107
+ instructions=run['instructions']
108
+ if run.get('workflow')=='research':
109
+ from .research import research_instructions
110
+ instructions=(research_instructions(task['goal'],run['source_records'],followup=run['number']>1)
111
+ +'\nPlace every result/research path under /workspace/result/research. '
112
+ 'Only the provided, caller-verified source records are available; do not claim autonomous discovery.\n'
113
+ +'CURRENT ROUND REQUEST:\n'+instructions)
114
+ invocation={'id':run['id'],'instructions':instructions,
115
+ 'image_profile':task['image_profile'],
116
+ '_durable':{'checkpoint':checkpoint,'session_id':run['session_id'],
117
+ 'save_checkpoint':save_checkpoint}}
118
+ return await self.execute(invocation,progress,lambda: False)
119
+
120
+ async def reconcile_durable(self,run):
121
+ """Allow a new writer only after exact owned-container absence and lease closure."""
122
+ sandbox_id, receipt = run.get('sandbox_id'), run.get('runtime_receipt')
123
+ if not run.get('phase') and (not sandbox_id or not isinstance(receipt,dict)):
124
+ return False
125
+ try:
126
+ finder=getattr(self.task_service,'find_run_sandboxes',None)
127
+ if finder is not None:
128
+ # Controller metadata catches a created Sandbox whose response/id was lost.
129
+ if await finder(run['id']):return False
130
+ elif not sandbox_id or not isinstance(receipt,dict):
131
+ return False
132
+ if sandbox_id:
133
+ if not self.task_service.verify_absent(sandbox_id):return False
134
+ if self.gateway:
135
+ closed=await asyncio.to_thread(self.gateway.close,run['id'])
136
+ if closed!={'closed':True}:
137
+ return False
138
+ return True
139
+ except Exception:
140
+ return False
141
+
89
142
  async def execute(self,task,update,cancelled):
90
143
  runtime=self.runtime
144
+ durable=task.get('_durable')
145
+ model_quiescent=False
91
146
  lease=None
92
147
  capability=task.get('capability') or {}
93
148
  mode=capability.get('mode','generic')
@@ -96,33 +151,64 @@ class CodexTaskExecutor:
96
151
  raise ValueError('read-only verification requires gateway, trusted hook and approved input')
97
152
  service=None
98
153
  sandbox=cfg=None;outcome={'ok':False,'artifacts':[],'cleanup':{'container_absent':True,'not_created':True}}
154
+ sandbox_create_attempted=False
99
155
  async with self.task_service.lock:
100
- if self.gateway:
101
- plan=capability.get('plan')
102
- if mode=='verify':plan={**plan,'verification_of':capability['source_task_id']}
103
- lease=await asyncio.to_thread(self.gateway.create,task['id'],mode,plan)
156
+ gateway_intent=False
104
157
  try:
158
+ if self.gateway:
159
+ if durable:
160
+ await update({'phase':'gateway_intent'})
161
+ gateway_intent=True
162
+ plan=capability.get('plan')
163
+ if mode=='verify':plan={**plan,'verification_of':capability['source_task_id']}
164
+ lease=await asyncio.to_thread(self.gateway.create,task['id'],mode,plan)
165
+ if durable:await update({'phase':'gateway_created'})
105
166
  if lease is not None:
106
167
  if mode=='verify':
107
168
  runtime=replace(runtime,tool_base_url=lease.tool_base_url,tool_access_token=lease.tool_access_token)
108
169
  else:
109
170
  runtime=replace(runtime,base_url=lease.model_base_url,access_token=lease.model_access_token,
110
171
  tool_base_url=lease.tool_base_url,tool_access_token=lease.tool_access_token)
111
- service=TaskService(replace(self.task_service.settings,image=self.images[task['image_profile']]),docker_client=self.task_service.docker)
172
+ service=self.task_service.for_image(self.images[task['image_profile']])
112
173
  await update({'index':0,'status':'running'})
113
- sandbox,cfg,details=await service.create(ttl_seconds=(120 if mode=='verify' else runtime.seconds)+(hook[1] if hook else 0)+120)
174
+ if durable:await update({'phase':'sandbox_intent'})
175
+ create_options={'ttl_seconds':(120 if mode=='verify' else runtime.seconds)+(hook[1] if hook else 0)+120}
176
+ if durable:create_options['durable_run_id']=task['id']
177
+ if durable:outcome['cleanup']={'container_absent':False,'creation_outcome_unknown':True}
178
+ sandbox_create_attempted=True
179
+ sandbox,cfg,details=await service.create(**create_options)
114
180
  outcome.update(sandbox_id=sandbox.id,runtime=details,cleanup={'container_absent':False})
115
- async def command(argv,seconds=30,cwd='/workspace'):
181
+ if durable:
182
+ await update({'phase':'sandbox_created','sandbox_id':sandbox.id,'runtime':details})
183
+ async def command(argv,seconds=30,cwd='/workspace',full_stdout_limit=None):
184
+ nonlocal model_quiescent
116
185
  env=runtime.guest_env()
117
186
  if mode=='verify':env.pop('CHATTASK_CODEX_API_KEY',None)
118
187
  output=await asyncio.wait_for(sandbox.commands.run(shlex.join(argv),opts=RunCommandOpts(
119
188
  timeout=timedelta(seconds=seconds),working_directory=cwd,envs=env)),seconds+10)
120
189
  receipt=service.output(output)
190
+ if argv[:2]==['sh','-c'] and 'codex' in argv[2]:
191
+ model_quiescent=True
121
192
  for key in ['stdout','stderr','error']:
122
193
  if isinstance(receipt.get(key),str):receipt[key]=runtime.redact(receipt[key])
123
194
  if receipt['exit_code']!=0 or receipt.get('error'):raise RuntimeError('guest command failed: '+(receipt.get('stderr') or receipt.get('stdout') or str(receipt.get('error')))[:1800])
195
+ if full_stdout_limit is not None:
196
+ # CLI help is a trusted guest probe. Ordinary receipts stay diagnostic-sized.
197
+ chunks=[];size=0
198
+ for log in output.logs.stdout:
199
+ piece=log.text
200
+ size+=len(piece.encode('utf-8'))+(1 if chunks else 0)
201
+ if size>full_stdout_limit:raise RuntimeError('guest Codex help exceeds 16 KiB')
202
+ chunks.append(piece)
203
+ receipt['stdout']=runtime.redact('\n'.join(chunks))
124
204
  return receipt
125
205
  await command(['mkdir','-p','/workspace/work','/workspace/result','/workspace/codex-home','/workspace/home'],cwd='/')
206
+ if durable and durable['checkpoint'] is not None:
207
+ from .durable_archive import validate_checkpoint
208
+ validate_checkpoint(durable['checkpoint'],session_id=durable['session_id'],
209
+ known_tokens=(runtime.access_token,runtime.tool_access_token))
210
+ await sandbox.files.write_file('/workspace/checkpoint.tar.gz',durable['checkpoint'],mode=600)
211
+ await command(['tar','-xzf','/workspace/checkpoint.tar.gz','-C','/workspace'])
126
212
  if self.hosts:
127
213
  lines=''.join(ip+' '+host+'\n' for host,ip in sorted(self.hosts.items()))
128
214
  await command(['python','-c','from pathlib import Path; p=Path("/etc/hosts"); p.open("a").write('+repr(lines)+')'])
@@ -156,10 +242,18 @@ class CodexTaskExecutor:
156
242
  '-c','model_providers.task.env_key="CHATTASK_CODEX_API_KEY"',
157
243
  '-c','model_providers.task.base_url='+json.dumps(runtime.base_url),
158
244
  '-c','model_providers.task.request_max_retries=1','-c','model_providers.task.stream_max_retries=1',
159
- '-c','model_reasoning_effort="xhigh"','exec','--skip-git-repo-check','--sandbox','danger-full-access',
160
- '--model',runtime.model,'--cd','/workspace/work','--json','--output-last-message','/workspace/agent-final.md','-']
245
+ '-c','model_reasoning_effort="xhigh"']
246
+ if durable and durable['session_id']:
247
+ help_text=(await command(['codex','exec','resume','--help'],full_stdout_limit=16*1024))['stdout']
248
+ root_help=(await command(['codex','--help'],full_stdout_limit=16*1024))['stdout']
249
+ argv=native_resume_argv(argv,runtime.model,durable['session_id'],help_text,root_help)
250
+ else:
251
+ argv+=['exec','--skip-git-repo-check','--sandbox','danger-full-access',
252
+ '--model',runtime.model,'--cd','/workspace/work','--json',
253
+ '--output-last-message','/workspace/agent-final.md','-']
161
254
  shell=shlex.join(argv)+' < /workspace/task-prompt.txt > /workspace/agent-events.jsonl 2> /workspace/agent-stderr.txt'
162
255
  await command(['sh','-c',shell],seconds=runtime.seconds)
256
+ model_quiescent=True
163
257
  events=runtime.redact(await sandbox.files.read_file('/workspace/agent-events.jsonl'))
164
258
  session=None;completed=False;failed=False
165
259
  for line in events.splitlines():
@@ -170,11 +264,14 @@ class CodexTaskExecutor:
170
264
  if event.get('type')=='turn.failed':failed=True
171
265
  except ValueError:pass
172
266
  outcome['codex_session_id']=session
267
+ if durable and durable['session_id'] and session!=durable['session_id']:
268
+ raise RuntimeError('native resumed thread id changed')
173
269
  # Preserve the native transcript even if action/readiness verification fails.
174
270
  self._artifact(outcome,'codex.events.jsonl',events.encode()[:1024*1024])
175
271
  final=runtime.redact(await sandbox.files.read_file('/workspace/agent-final.md'))
176
272
  marker=await sandbox.files.read_file('/workspace/agent-started.txt')
177
273
  if not session or not completed or failed or not marker.strip() or not final.strip():raise RuntimeError('Codex execution did not meet the native completion/write contract')
274
+ outcome['native_turn_completed']=True
178
275
  if cancelled():raise RuntimeError('task cancellation requested')
179
276
  outcome['final']=final[:16000]
180
277
  self._artifact(outcome,'result.md',final.encode()[:1000000])
@@ -197,11 +294,38 @@ class CodexTaskExecutor:
197
294
  if any(secret and (secret.encode() in body or base64.b64encode(secret.encode()) in body) for secret in (runtime.access_token,runtime.tool_access_token)):raise RuntimeError('task credential appeared in results')
198
295
  self._artifact(outcome,'result.tar.gz',data)
199
296
  await update({'index':1 if mode=='verify' else 2,'status':'passed','receipt':json.loads(collection['stdout'])})
297
+ if durable:
298
+ from .durable_archive import CAPTURE_SCRIPT,validate_checkpoint
299
+ await sandbox.files.write_file('/workspace/capture_checkpoint.py',CAPTURE_SCRIPT,mode=600)
300
+ await command(['python','/workspace/capture_checkpoint.py'])
301
+ checkpoint_data=await sandbox.files.read_bytes('/workspace/checkpoint.tar.gz')
302
+ validate_checkpoint(checkpoint_data,known_tokens=(runtime.access_token,runtime.tool_access_token),
303
+ session_id=outcome['codex_session_id'])
304
+ await durable['save_checkpoint'](checkpoint_data,outcome['codex_session_id'])
200
305
  if mode=='verify':
201
306
  outcome['final']='Read-only trusted publication verification passed.'
202
307
  outcome['ok']=True
203
308
  except Exception as exc:
204
309
  outcome['error']=runtime.redact(str(exc))[:1800]
310
+ if durable and not gateway_intent and lease is None and sandbox is None and not sandbox_create_attempted:
311
+ outcome['cleanup']={'not_created':True,'container_absent':True}
312
+ outcome['credential_closure']={'not_created':True}
313
+ if durable and model_quiescent and sandbox is not None and not outcome.get('codex_session_id'):
314
+ try:
315
+ partial=await sandbox.files.read_file('/workspace/agent-events.jsonl')
316
+ for line in partial.splitlines():
317
+ event=json.loads(line)
318
+ if event.get('type')=='thread.started':outcome['codex_session_id']=event.get('thread_id')
319
+ except Exception:pass
320
+ if durable and model_quiescent and sandbox is not None and outcome.get('codex_session_id') and not any(a['name']=='result.tar.gz' for a in outcome['artifacts']):
321
+ try:
322
+ from .durable_archive import CAPTURE_SCRIPT,validate_checkpoint
323
+ await sandbox.files.write_file('/workspace/capture_checkpoint.py',CAPTURE_SCRIPT,mode=600)
324
+ await command(['python','/workspace/capture_checkpoint.py'])
325
+ checkpoint_data=await sandbox.files.read_bytes('/workspace/checkpoint.tar.gz')
326
+ validate_checkpoint(checkpoint_data,known_tokens=(runtime.access_token,runtime.tool_access_token),session_id=outcome['codex_session_id'])
327
+ await durable['save_checkpoint'](checkpoint_data,outcome['codex_session_id'])
328
+ except Exception:pass
205
329
  if sandbox is not None and mode!='verify':
206
330
  if not any(a['name']=='codex.events.jsonl' for a in outcome['artifacts']):
207
331
  try:
@@ -214,10 +338,10 @@ class CodexTaskExecutor:
214
338
  if sandbox is not None:
215
339
  try:
216
340
  await service.dispose(sandbox,cfg)
217
- outcome['cleanup']={'requested':True,'container_absent':not any(c.name=='sandbox-'+sandbox.id for c in service.docker.containers.list(all=True))}
341
+ outcome['cleanup']={'requested':True,'container_absent':service.verify_absent(sandbox.id)}
218
342
  except Exception:outcome['cleanup']={'requested':True,'container_absent':False}
219
343
  if not outcome['cleanup']['container_absent']:outcome['ok']=False
220
- if lease is not None:
344
+ if lease is not None or gateway_intent:
221
345
  try:
222
346
  closed=await asyncio.to_thread(self.gateway.close,task['id'])
223
347
  if closed!={'closed':True}:raise ValueError('lease closure unconfirmed')