ChatTask 0.1.1__tar.gz → 0.1.3__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 (37) hide show
  1. {chattask-0.1.1/src/ChatTask.egg-info → chattask-0.1.3}/PKG-INFO +1 -1
  2. {chattask-0.1.1 → chattask-0.1.3/src/ChatTask.egg-info}/PKG-INFO +1 -1
  3. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/__init__.py +1 -1
  4. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/agent_tasks.py +8 -3
  5. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/broker.py +36 -10
  6. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/codex_tasks.py +82 -58
  7. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/package_publication.py +154 -40
  8. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/package_service.py +106 -2
  9. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/web.py +13 -1
  10. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/web_static/app.js +32 -6
  11. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/web_static/index.html +2 -0
  12. {chattask-0.1.1 → chattask-0.1.3}/tests/test_version.py +1 -1
  13. {chattask-0.1.1 → chattask-0.1.3}/LICENSE +0 -0
  14. {chattask-0.1.1 → chattask-0.1.3}/README.md +0 -0
  15. {chattask-0.1.1 → chattask-0.1.3}/pyproject.toml +0 -0
  16. {chattask-0.1.1 → chattask-0.1.3}/setup.cfg +0 -0
  17. {chattask-0.1.1 → chattask-0.1.3}/src/ChatTask.egg-info/SOURCES.txt +0 -0
  18. {chattask-0.1.1 → chattask-0.1.3}/src/ChatTask.egg-info/dependency_links.txt +0 -0
  19. {chattask-0.1.1 → chattask-0.1.3}/src/ChatTask.egg-info/entry_points.txt +0 -0
  20. {chattask-0.1.1 → chattask-0.1.3}/src/ChatTask.egg-info/requires.txt +0 -0
  21. {chattask-0.1.1 → chattask-0.1.3}/src/ChatTask.egg-info/top_level.txt +0 -0
  22. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/auth.py +0 -0
  23. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/cli.py +0 -0
  24. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/config.py +0 -0
  25. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/executor.py +0 -0
  26. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/package_plan.py +0 -0
  27. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/package_template.py +0 -0
  28. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/package_validation.py +0 -0
  29. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/release.py +0 -0
  30. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/service.py +0 -0
  31. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/settings.py +0 -0
  32. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/source.py +0 -0
  33. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/tool_client.py +0 -0
  34. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/web_static/style.css +0 -0
  35. {chattask-0.1.1 → chattask-0.1.3}/src/chattask/workflow.py +0 -0
  36. {chattask-0.1.1 → chattask-0.1.3}/tests/test_cli.py +0 -0
  37. {chattask-0.1.1 → chattask-0.1.3}/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.1
3
+ Version: 0.1.3
4
4
  Summary: ChatTask: a ChatArch Python package.
5
5
  Author-email: ChatArch <rex@chatarch.org>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ChatTask
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: ChatTask: a ChatArch Python package.
5
5
  Author-email: ChatArch <rex@chatarch.org>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  """ChatTask: explicit task execution, sessions and an optional browser adapter."""
2
2
 
3
- __version__ = "0.1.1"
3
+ __version__ = "0.1.3"
4
4
  __all__ = ["__version__", "TaskService", "TaskSettings", "create_app", "state_paths", "WorkflowService", "TaskStore"]
5
5
 
6
6
 
@@ -37,10 +37,15 @@ class AgentTaskService:
37
37
  return await self._create(owner,body,None)
38
38
 
39
39
  async def create_internal(self,owner,body,capability):
40
- if not isinstance(capability,dict) or capability.get('mode') not in ('prepare','publish') or not isinstance(capability.get('plan'),dict):
40
+ if not isinstance(capability,dict) or capability.get('mode') not in ('prepare','publish','verify') or not isinstance(capability.get('plan'),dict):
41
41
  raise ValueError('invalid internal capability')
42
42
  if capability['mode']=='prepare' and set(capability)!={'mode','plan'} or capability['mode']=='publish' and (set(capability)!={'mode','plan','spec','plan_sha256'} or not isinstance(capability['spec'],dict) or not isinstance(capability['plan_sha256'],str) or not re.fullmatch('[0-9a-f]{64}',capability['plan_sha256'])):
43
43
  raise ValueError('invalid internal capability')
44
+ if capability['mode']=='verify' and (set(capability)!={'mode','plan','spec','plan_sha256','source_task_id'} or
45
+ not isinstance(capability['spec'],dict) or not isinstance(capability['plan_sha256'],str) or
46
+ not re.fullmatch('[0-9a-f]{64}',capability['plan_sha256']) or
47
+ not isinstance(capability['source_task_id'],str) or not re.fullmatch('[a-f0-9]{32}',capability['source_task_id'])):
48
+ raise ValueError('invalid internal verify capability')
44
49
  return await self._create(owner,body,capability)
45
50
 
46
51
  async def _create(self,owner,body,capability):
@@ -67,7 +72,7 @@ class AgentTaskService:
67
72
  task={'id':ident,'owner':owner,'engine':'codex','template_id':'codex-task','template_revision':1,
68
73
  'request_id':request_id,'request_fingerprint':digest,'instructions':instructions,
69
74
  'image_profile':image,'status':'queued','created_at':now(),'updated_at':now(),
70
- 'steps':[{'kind':kind,'status':'pending'} for kind in ['prepare','codex','collect']],
75
+ 'steps':[{'kind':kind,'status':'pending'} for kind in (['sandbox','trusted_validation'] if capability and capability['mode']=='verify' else ['prepare','codex','collect'])],
71
76
  'result':None,'artifacts':[],'cleanup':None,'input_task_id':input_task_id,'capability':capability}
72
77
  self.store.put('runs',ident,task)
73
78
  self.tasks[ident]=asyncio.create_task(self._execute(ident))
@@ -96,7 +101,7 @@ class AgentTaskService:
96
101
  for item in result.get('artifacts',[]):
97
102
  clean={k:v for k,v in item.items() if k!='data'}
98
103
  self.store.put_artifact(ident,item['name'],item['data']);current['artifacts'].append(clean)
99
- for key in ['sandbox_id','runtime','codex_session_id','cleanup','error','diagnostic']:
104
+ for key in ['sandbox_id','runtime','codex_session_id','cleanup','credential_closure','error','diagnostic']:
100
105
  if key in result:current[key]=result[key]
101
106
  current['result']=result.get('final')
102
107
  cancelled=current['status']=='cancel_requested'
@@ -67,7 +67,7 @@ class GatewayClient:
67
67
  def create(self,request_id,mode,plan):
68
68
  if not isinstance(request_id,str) or not re.fullmatch(r'[a-f0-9]{32}',request_id):
69
69
  raise ValueError('task ID required')
70
- if mode not in ('generic','prepare','publish') or (mode=='generic') != (plan is None):
70
+ if mode not in ('generic','prepare','publish','verify') or (mode=='generic') != (plan is None):
71
71
  raise ValueError('invalid gateway session mode/policy')
72
72
  payload=json.dumps({'request_id':request_id,'mode':mode,'plan':plan},sort_keys=True,separators=(',',':')).encode()
73
73
  request=urllib.request.Request(self.origin+'/control/sessions',data=payload,method='POST',
@@ -100,18 +100,23 @@ class GatewayClient:
100
100
  ident=value['id']
101
101
  if ident!=request_id:
102
102
  raise ValueError()
103
- model=_https(value['model_base_url'])
104
103
  expected=self.origin+'/sessions/'+ident
105
- if value['model_base_url']!=expected+'/v1' or model!=expected+'/v1':
106
- raise ValueError()
107
104
  tool=value['tool_base_url']
108
- if mode=='generic':
109
- if tool or value['tool_access_token']:
105
+ if mode=='verify':
106
+ if value['model_base_url'] or value['model_access_token'] or tool!=expected or not isinstance(value['tool_access_token'],str) or not value['tool_access_token']:
107
+ raise ValueError()
108
+ model=''
109
+ else:
110
+ model=_https(value['model_base_url'])
111
+ if value['model_base_url']!=expected+'/v1' or model!=expected+'/v1':
112
+ raise ValueError()
113
+ if mode=='generic':
114
+ if tool or value['tool_access_token']:
115
+ raise ValueError()
116
+ elif tool!=expected or not value['tool_access_token']:
117
+ raise ValueError()
118
+ if not value['model_access_token'] or not isinstance(value['model_access_token'],str):
110
119
  raise ValueError()
111
- elif tool!=expected or not value['tool_access_token']:
112
- raise ValueError()
113
- if not value['model_access_token'] or not isinstance(value['model_access_token'],str):
114
- raise ValueError()
115
120
  raw_expiry=value['expires_at']
116
121
  expires=(datetime.fromtimestamp(raw_expiry,timezone.utc) if isinstance(raw_expiry,(int,float)) and not isinstance(raw_expiry,bool)
117
122
  else datetime.fromisoformat(raw_expiry.replace('Z','+00:00')))
@@ -120,3 +125,24 @@ class GatewayClient:
120
125
  return GatewaySession(ident,model,value['model_access_token'],tool,value['tool_access_token'],value['expires_at'])
121
126
  except (KeyError,TypeError,ValueError,OverflowError,AttributeError):
122
127
  raise GatewayUnknown('invalid gateway session response; retry same task ID') from None
128
+
129
+ def close(self,request_id):
130
+ if not isinstance(request_id,str) or not re.fullmatch(r'[a-f0-9]{32}',request_id):
131
+ raise ValueError('task ID required')
132
+ request=urllib.request.Request(self.origin+'/control/sessions/'+request_id+'/close',
133
+ data=b'',method='POST',headers={'Authorization':'Bearer '+self._token,
134
+ 'Content-Type':'application/json','Accept':'application/json'})
135
+ try:
136
+ with self._open(request,timeout=8) as response:
137
+ if response.status!=200 or int(response.headers.get('content-length','0'))>4096:
138
+ raise GatewayUnknown('gateway lease closure outcome unknown')
139
+ raw=response.read(4097)
140
+ if len(raw)>4096 or json.loads(raw)!={'closed':True}:
141
+ raise GatewayUnknown('gateway lease closure outcome unknown')
142
+ return {'closed':True}
143
+ except urllib.error.HTTPError as exc:
144
+ if 400<=exc.code<500:
145
+ raise RuntimeError('gateway lease closure denied') from None
146
+ raise GatewayUnknown('gateway lease closure outcome unknown') from None
147
+ except (urllib.error.URLError,TimeoutError,OSError,ValueError,TypeError):
148
+ raise GatewayUnknown('gateway lease closure outcome unknown') from None
@@ -79,7 +79,7 @@ class CodexTaskExecutor:
79
79
  self.gateway=gateway;self.hosts=hosts or {};self.postprocessors={}
80
80
 
81
81
  def register_postprocessor(self,mode,handler,max_seconds):
82
- if mode not in ('prepare','publish') or not 1<=max_seconds<=900:
82
+ if mode not in ('prepare','publish','verify') or not 1<=max_seconds<=900:
83
83
  raise ValueError('invalid trusted postprocessor')
84
84
  selected=(handler,max_seconds)
85
85
  if mode in self.postprocessors and self.postprocessors[mode]!=selected:
@@ -88,25 +88,35 @@ class CodexTaskExecutor:
88
88
 
89
89
  async def execute(self,task,update,cancelled):
90
90
  runtime=self.runtime
91
- if self.gateway:
92
- capability=task.get('capability') or {}
93
- mode=capability.get('mode','generic')
94
- plan=capability.get('plan')
95
- session=await asyncio.to_thread(self.gateway.create,task['id'],mode,plan)
96
- runtime=replace(runtime,base_url=session.model_base_url,access_token=session.model_access_token,
97
- tool_base_url=session.tool_base_url,tool_access_token=session.tool_access_token)
98
- mode=(task.get('capability') or {}).get('mode','generic')
91
+ lease=None
92
+ capability=task.get('capability') or {}
93
+ mode=capability.get('mode','generic')
99
94
  hook=self.postprocessors.get(mode)
100
- service=TaskService(replace(self.task_service.settings,image=self.images[task['image_profile']]),docker_client=self.task_service.docker)
95
+ if mode=='verify' and (not self.gateway or not hook or not isinstance(task.get('_input_archive'),bytes)):
96
+ raise ValueError('read-only verification requires gateway, trusted hook and approved input')
97
+ service=None
101
98
  sandbox=cfg=None;outcome={'ok':False,'artifacts':[],'cleanup':{'container_absent':True,'not_created':True}}
102
99
  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)
103
104
  try:
105
+ if lease is not None:
106
+ if mode=='verify':
107
+ runtime=replace(runtime,tool_base_url=lease.tool_base_url,tool_access_token=lease.tool_access_token)
108
+ else:
109
+ runtime=replace(runtime,base_url=lease.model_base_url,access_token=lease.model_access_token,
110
+ 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)
104
112
  await update({'index':0,'status':'running'})
105
- sandbox,cfg,details=await service.create(ttl_seconds=runtime.seconds+(hook[1] if hook else 0)+120)
113
+ sandbox,cfg,details=await service.create(ttl_seconds=(120 if mode=='verify' else runtime.seconds)+(hook[1] if hook else 0)+120)
106
114
  outcome.update(sandbox_id=sandbox.id,runtime=details,cleanup={'container_absent':False})
107
115
  async def command(argv,seconds=30,cwd='/workspace'):
116
+ env=runtime.guest_env()
117
+ if mode=='verify':env.pop('CHATTASK_CODEX_API_KEY',None)
108
118
  output=await asyncio.wait_for(sandbox.commands.run(shlex.join(argv),opts=RunCommandOpts(
109
- timeout=timedelta(seconds=seconds),working_directory=cwd,envs=runtime.guest_env())),seconds+10)
119
+ timeout=timedelta(seconds=seconds),working_directory=cwd,envs=env)),seconds+10)
110
120
  receipt=service.output(output)
111
121
  for key in ['stdout','stderr','error']:
112
122
  if isinstance(receipt.get(key),str):receipt[key]=runtime.redact(receipt[key])
@@ -119,56 +129,59 @@ class CodexTaskExecutor:
119
129
  if runtime.ca_certificate:
120
130
  await sandbox.files.write_file('/workspace/public-ca.pem',runtime.ca_certificate,mode=644)
121
131
  await command(['python','-c','from pathlib import Path; system=Path("/etc/ssl/certs/ca-certificates.crt"); ca=Path("/workspace/public-ca.pem").read_bytes(); original=system.read_bytes(); assert original; system.open("ab").write(b"\\n"+ca); Path("/workspace/task-ca.pem").write_bytes(system.read_bytes())'])
122
- await command(['codex','--version'])
132
+ if mode!='verify':await command(['codex','--version'])
123
133
  if task.get('_input_archive') is not None:
124
134
  await command(['mkdir','-p','/workspace/input'])
125
135
  await sandbox.files.write_file('/workspace/input/previous-result.tar.gz',task['_input_archive'],mode=600)
126
136
  await sandbox.files.write_file('/workspace/task_tools.py',TOOL_CLIENT,mode=600)
127
137
  await sandbox.files.write_file('/workspace/collect_results.py',COLLECTOR,mode=600)
128
- prompt=(
129
- 'You execute a user task inside an owned container. Work under /workspace/work. '
130
- 'Put all deliverables under /workspace/result. Write /workspace/agent-started.txt with your cwd immediately. '
131
- 'Never print or copy environment secrets, credentials or authentication files into deliverables. '
132
- 'If a task tool service is configured, discover its /tools/catalog with '
133
- '`python /workspace/task_tools.py /tools/catalog`, then call exact listed routes with an optional JSON argument. '
134
- 'Use those services for privileged external operations; do not request or recover upstream credentials. '
135
- 'An HTTP or tool error is not success; report required approval/blocked operations honestly. '
136
- 'Only perform the external actions explicitly described in the user task. '
137
- 'This image supplies infrastructure; do not install unrelated infrastructure or alter the host. '
138
- 'On completion give a factual final summary with completed results and any blocker. '
139
- 'Use shell login=false if supported. If this task selects previous results, they are available as /workspace/input/previous-result.tar.gz.\n\nUSER TASK:\n'+task['instructions'])
140
- await sandbox.files.write_file('/workspace/task-prompt.txt',prompt,mode=600)
141
138
  await update({'index':0,'status':'passed','receipt':{'image_profile':task['image_profile'],'runtime':details}})
142
- await update({'index':1,'status':'running'})
143
- argv=['codex','--disable','unbounded_connection_retries','-c','model_provider="task"',
144
- '-c','model_providers.task.name="Task gateway"','-c','model_providers.task.wire_api="responses"',
145
- '-c','model_providers.task.env_key="CHATTASK_CODEX_API_KEY"',
146
- '-c','model_providers.task.base_url='+json.dumps(runtime.base_url),
147
- '-c','model_providers.task.request_max_retries=1','-c','model_providers.task.stream_max_retries=1',
148
- '-c','model_reasoning_effort="xhigh"','exec','--skip-git-repo-check','--sandbox','danger-full-access',
149
- '--model',runtime.model,'--cd','/workspace/work','--json','--output-last-message','/workspace/agent-final.md','-']
150
- shell=shlex.join(argv)+' < /workspace/task-prompt.txt > /workspace/agent-events.jsonl 2> /workspace/agent-stderr.txt'
151
- await command(['sh','-c',shell],seconds=runtime.seconds)
152
- events=runtime.redact(await sandbox.files.read_file('/workspace/agent-events.jsonl'))
153
- session=None;completed=False;failed=False
154
- for line in events.splitlines():
155
- try:
156
- event=json.loads(line)
157
- if event.get('type')=='thread.started':session=event.get('thread_id')
158
- if event.get('type')=='turn.completed':completed=True
159
- if event.get('type')=='turn.failed':failed=True
160
- except ValueError:pass
161
- outcome['codex_session_id']=session
162
- # Preserve the native transcript even if action/readiness verification fails.
163
- self._artifact(outcome,'codex.events.jsonl',events.encode()[:1024*1024])
164
- final=runtime.redact(await sandbox.files.read_file('/workspace/agent-final.md'))
165
- marker=await sandbox.files.read_file('/workspace/agent-started.txt')
166
- 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')
167
- if cancelled():raise RuntimeError('task cancellation requested')
168
- outcome['final']=final[:16000]
169
- self._artifact(outcome,'result.md',final.encode()[:1000000])
170
- await update({'index':1,'status':'passed','receipt':{'session_id':session,'startup_marker':marker[:200],'native_turn_completed':True}})
171
- await update({'index':2,'status':'running'})
139
+ if mode!='verify':
140
+ prompt=(
141
+ 'You execute a user task inside an owned container. Work under /workspace/work. '
142
+ 'Put all deliverables under /workspace/result. Write /workspace/agent-started.txt with your cwd immediately. '
143
+ 'Never print or copy environment secrets, credentials or authentication files into deliverables. '
144
+ 'If a task tool service is configured, discover its /tools/catalog with '
145
+ '`python /workspace/task_tools.py /tools/catalog`, then call exact listed routes with an optional JSON argument. '
146
+ 'Use those services for privileged external operations; do not request or recover upstream credentials. '
147
+ 'An HTTP or tool error is not success; report required approval/blocked operations honestly. '
148
+ 'Only perform the external actions explicitly described in the user task. '
149
+ 'This image supplies infrastructure; do not install unrelated infrastructure or alter the host. '
150
+ 'On completion give a factual final summary with completed results and any blocker. '
151
+ 'Use shell login=false if supported. If this task selects previous results, they are available as /workspace/input/previous-result.tar.gz.\n\nUSER TASK:\n'+task['instructions'])
152
+ await sandbox.files.write_file('/workspace/task-prompt.txt',prompt,mode=600)
153
+ await update({'index':1,'status':'running'})
154
+ argv=['codex','--disable','unbounded_connection_retries','-c','model_provider="task"',
155
+ '-c','model_providers.task.name="Task gateway"','-c','model_providers.task.wire_api="responses"',
156
+ '-c','model_providers.task.env_key="CHATTASK_CODEX_API_KEY"',
157
+ '-c','model_providers.task.base_url='+json.dumps(runtime.base_url),
158
+ '-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','-']
161
+ shell=shlex.join(argv)+' < /workspace/task-prompt.txt > /workspace/agent-events.jsonl 2> /workspace/agent-stderr.txt'
162
+ await command(['sh','-c',shell],seconds=runtime.seconds)
163
+ events=runtime.redact(await sandbox.files.read_file('/workspace/agent-events.jsonl'))
164
+ session=None;completed=False;failed=False
165
+ for line in events.splitlines():
166
+ try:
167
+ event=json.loads(line)
168
+ if event.get('type')=='thread.started':session=event.get('thread_id')
169
+ if event.get('type')=='turn.completed':completed=True
170
+ if event.get('type')=='turn.failed':failed=True
171
+ except ValueError:pass
172
+ outcome['codex_session_id']=session
173
+ # Preserve the native transcript even if action/readiness verification fails.
174
+ self._artifact(outcome,'codex.events.jsonl',events.encode()[:1024*1024])
175
+ final=runtime.redact(await sandbox.files.read_file('/workspace/agent-final.md'))
176
+ marker=await sandbox.files.read_file('/workspace/agent-started.txt')
177
+ 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')
178
+ if cancelled():raise RuntimeError('task cancellation requested')
179
+ outcome['final']=final[:16000]
180
+ self._artifact(outcome,'result.md',final.encode()[:1000000])
181
+ await update({'index':1,'status':'passed','receipt':{'session_id':session,'startup_marker':marker[:200],'native_turn_completed':True}})
182
+ await update({'index':2,'status':'running'})
183
+ else:
184
+ await update({'index':1,'status':'running'})
172
185
  if hook:
173
186
  await hook[0](sandbox,command,task,outcome,self._artifact,runtime)
174
187
  collection=await command(['python','/workspace/collect_results.py'])
@@ -183,11 +196,13 @@ class CodexTaskExecutor:
183
196
  body=archive.extractfile(member).read()
184
197
  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')
185
198
  self._artifact(outcome,'result.tar.gz',data)
186
- await update({'index':2,'status':'passed','receipt':json.loads(collection['stdout'])})
199
+ await update({'index':1 if mode=='verify' else 2,'status':'passed','receipt':json.loads(collection['stdout'])})
200
+ if mode=='verify':
201
+ outcome['final']='Read-only trusted publication verification passed.'
187
202
  outcome['ok']=True
188
203
  except Exception as exc:
189
204
  outcome['error']=runtime.redact(str(exc))[:1800]
190
- if sandbox is not None:
205
+ if sandbox is not None and mode!='verify':
191
206
  if not any(a['name']=='codex.events.jsonl' for a in outcome['artifacts']):
192
207
  try:
193
208
  partial=runtime.redact(await sandbox.files.read_file('/workspace/agent-events.jsonl'))
@@ -202,6 +217,15 @@ class CodexTaskExecutor:
202
217
  outcome['cleanup']={'requested':True,'container_absent':not any(c.name=='sandbox-'+sandbox.id for c in service.docker.containers.list(all=True))}
203
218
  except Exception:outcome['cleanup']={'requested':True,'container_absent':False}
204
219
  if not outcome['cleanup']['container_absent']:outcome['ok']=False
220
+ if lease is not None:
221
+ try:
222
+ closed=await asyncio.to_thread(self.gateway.close,task['id'])
223
+ if closed!={'closed':True}:raise ValueError('lease closure unconfirmed')
224
+ outcome['credential_closure']={'closed':True}
225
+ except Exception as exc:
226
+ outcome['credential_closure']={'closed':False,'error':type(exc).__name__}
227
+ outcome.setdefault('error','gateway lease closure unconfirmed')
228
+ outcome['ok']=False
205
229
  return outcome
206
230
 
207
231
  @staticmethod
@@ -5,13 +5,16 @@ import hashlib
5
5
  import io
6
6
  import json
7
7
  import os
8
+ import socket
9
+ import ssl
10
+ import urllib.error
8
11
  from pathlib import Path
9
12
  import re
10
13
  import subprocess
11
14
  import sys
12
15
  import tarfile
13
16
  import urllib.request
14
- from urllib.parse import quote, urlsplit
17
+ from urllib.parse import urlsplit
15
18
 
16
19
  HEX40=re.compile(r'[0-9a-f]{40}\Z')
17
20
  HEX64=re.compile(r'[0-9a-f]{64}\Z')
@@ -53,7 +56,7 @@ def verify_publication_receipts(policy,status,registry):
53
56
  kinds=set();files=[]
54
57
  for entry in urls:
55
58
  name=entry['filename'];digest=entry['digests']['sha256']
56
- if not isinstance(name,str) or not name.startswith(re.sub(r'[-_.]+','_',policy['project']).lower()+'-'+policy['version']) and not name.lower().startswith(policy['project'].lower()+'-'+policy['version']):
59
+ if not _safe_filename(name) or not name.startswith(re.sub(r'[-_.]+','_',policy['project']).lower()+'-'+policy['version']) and not name.lower().startswith(policy['project'].lower()+'-'+policy['version']):
57
60
  raise ValueError('PyPI filename target mismatch')
58
61
  if not isinstance(digest,str) or not HEX64.fullmatch(digest):
59
62
  raise ValueError('PyPI file digest missing')
@@ -69,37 +72,132 @@ def verify_publication_receipts(policy,status,registry):
69
72
  except (KeyError,TypeError,AttributeError) as exc:
70
73
  raise ValueError('publication receipt incomplete') from None
71
74
 
75
+ def _read_only(request,limit,phase,*,timeout=12):
76
+ # Two bounded attempts; only transport failures are retried.
77
+ host=urlsplit(request.full_url).hostname or 'unknown'
78
+ for attempt in range(2):
79
+ try:
80
+ with urllib.request.urlopen(request,timeout=timeout) as response:
81
+ length=response.headers.get('content-length','0')
82
+ if response.status!=200 or not str(length).isdigit() or int(length)>limit:
83
+ raise ValueError(phase+' readback rejected by '+host)
84
+ final=urlsplit(response.geturl())
85
+ original=urlsplit(request.full_url)
86
+ if final.scheme!='https' or final.hostname!=original.hostname:
87
+ raise ValueError(phase+' readback target changed at '+host)
88
+ data=response.read(limit+1)
89
+ if len(data)>limit:
90
+ raise ValueError(phase+' readback too large at '+host)
91
+ return data
92
+ except urllib.error.HTTPError as exc:
93
+ raise ValueError(phase+' HTTP '+str(exc.code)+' at '+host) from None
94
+ except urllib.error.URLError as exc:
95
+ reason=exc.reason
96
+ if isinstance(reason,ssl.SSLError):
97
+ raise ValueError(phase+' TLS verification failed at '+host) from None
98
+ if not isinstance(reason,(TimeoutError,ConnectionError,socket.gaierror,OSError)):
99
+ raise ValueError(phase+' network rejected at '+host) from None
100
+ if attempt:raise ValueError(phase+' network unavailable after 2 attempts at '+host) from None
101
+ except ssl.SSLError:
102
+ raise ValueError(phase+' TLS verification failed at '+host) from None
103
+ except (TimeoutError,ConnectionError,socket.gaierror,OSError):
104
+ if attempt:raise ValueError(phase+' network unavailable after 2 attempts at '+host) from None
105
+
72
106
  def _bounded_get(url,limit):
73
107
  request=urllib.request.Request(url,headers={'Accept':'application/json'})
74
- with urllib.request.urlopen(request,timeout=25) as response:
75
- if response.status!=200 or int(response.headers.get('content-length','0'))>limit:
76
- raise ValueError('publication readback failed')
77
- final=urlsplit(response.geturl())
78
- original=urlsplit(url)
79
- if final.scheme!='https' or final.hostname!=original.hostname:
80
- raise ValueError('publication readback redirect rejected')
81
- data=response.read(limit+1)
82
- if len(data)>limit:
83
- raise ValueError('publication readback too large')
84
- return data
85
-
86
- def _guest_tool(route):
108
+ return _read_only(request,limit,'public registry')
109
+
110
+ def _scoped_request(route,accept):
87
111
  base=os.environ['CHATTASK_TOOL_BASE_URL'];token=os.environ['CHATTASK_TOOL_ACCESS_TOKEN']
88
- if not base.startswith('https://') or not route.startswith('/'):
112
+ if not base.startswith('https://') or not route.startswith('/') or not token:
89
113
  raise ValueError('scoped tool missing')
90
- request=urllib.request.Request(base+route,headers={'Authorization':'Bearer '+token,'Accept':'application/json'})
91
- with urllib.request.urlopen(request,timeout=25) as response:
92
- if response.status!=200:
93
- raise ValueError('scoped status failed')
94
- data=response.read(500001)
95
- if len(data)>500000:
96
- raise ValueError('scoped status too large')
97
- return json.loads(data)
114
+ return urllib.request.Request(base+route,headers={'Authorization':'Bearer '+token,'Accept':accept})
115
+
116
+ def _guest_tool(route,*,limit=500000,timeout=60):
117
+ return json.loads(_read_only(_scoped_request(route,'application/json'),limit,'scoped readback',timeout=timeout))
118
+
119
+ def _guest_bytes(digest):
120
+ if not isinstance(digest,str) or not HEX64.fullmatch(digest):
121
+ raise ValueError('PyPI file digest missing')
122
+ request=_scoped_request('/pypi/api/artifacts/'+digest,'application/octet-stream')
123
+ return _read_only(request,10*1024*1024,'scoped artifact',timeout=12)
124
+
125
+ def _release_json(mode):
126
+ return _guest_tool('/pypi/api/release',limit=1000000,timeout=12)
127
+
128
+ def _placeholder_json(mode):
129
+ return _guest_tool('/pypi/api/placeholder',limit=1000000,timeout=12) if mode=='new' else None
130
+
131
+ def _safe_filename(name):
132
+ return isinstance(name,str) and bool(re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9._+-]{0,254}',name)) and name not in ('.','..') and Path(name).name==name
133
+
134
+ def _fetch_artifact(item,published):
135
+ name=item['filename'];digest=item['sha256']
136
+ if not _safe_filename(name) or not isinstance(digest,str) or not HEX64.fullmatch(digest):
137
+ raise ValueError('PyPI filename or digest rejected')
138
+ parsed=urlsplit(item.get('url',''))
139
+ if parsed.scheme!='https' or parsed.hostname!='files.pythonhosted.org' or parsed.username or parsed.password or parsed.fragment:
140
+ raise ValueError('PyPI file URL rejected')
141
+ data=_guest_bytes(digest)
142
+ if hashlib.sha256(data).hexdigest()!=digest:
143
+ raise ValueError('PyPI file bytes mismatch')
144
+ published.mkdir(exist_ok=True)
145
+ destination=published/name
146
+ destination.write_bytes(data)
147
+ return destination
148
+
149
+ def _dependency_provenance(digest):
150
+ return {'source':'pinned-wheelhouse','sha256':digest} if digest else {'source':'public-index','sha256':None}
151
+
152
+ def _stage_wheelhouse(blob,expected,destination):
153
+ if not isinstance(blob,bytes) or not blob or len(blob)>32*1024*1024 or not isinstance(expected,str) or not HEX64.fullmatch(expected) or hashlib.sha256(blob).hexdigest()!=expected:
154
+ raise ValueError('public dependency archive digest or size mismatch')
155
+ wheels=[];seen=set();total=0
156
+ with tarfile.open(fileobj=io.BytesIO(blob),mode='r:gz') as archive:
157
+ members=archive.getmembers()
158
+ if len(members)>5000:
159
+ raise ValueError('public dependency archive member count exceeded')
160
+ for member in members:
161
+ name=member.name.rstrip('/') if member.isdir() else member.name
162
+ parts=name.split('/')
163
+ if not name or name.startswith('/') or any(part in ('','.','..') for part in parts) or '\\' in name or parts[0]!='deps':
164
+ raise ValueError('public dependency archive path rejected')
165
+ if name in seen:
166
+ raise ValueError('public dependency archive duplicate member')
167
+ seen.add(name)
168
+ if not (member.isfile() or member.isdir()) or member.size<0:
169
+ raise ValueError('public dependency archive member rejected')
170
+ total+=member.size
171
+ if total>128*1024*1024:
172
+ raise ValueError('public dependency archive expanded size exceeded')
173
+ if parts[:2]==['deps','wheelhouse'] and member.isfile():
174
+ if len(parts)!=3 or not _safe_filename(parts[2]) or not parts[2].endswith('.whl') or member.size>32*1024*1024:
175
+ raise ValueError('public dependency wheelhouse member rejected')
176
+ wheels.append(member)
177
+ if not wheels:
178
+ raise ValueError('public dependency wheelhouse empty')
179
+ destination.mkdir()
180
+ for member in wheels:
181
+ data=archive.extractfile(member).read(member.size+1)
182
+ if len(data)!=member.size:
183
+ raise ValueError('public dependency wheelhouse member truncated')
184
+ (destination/member.name.split('/')[-1]).write_bytes(data)
185
+ return _dependency_provenance(expected)
186
+
187
+ def _install_argv(venv,wheel,wheelhouse):
188
+ base=[venv+'/bin/python','-m','pip','install','--no-input']
189
+ if wheelhouse is not None:
190
+ return base+['--no-index','--find-links',str(wheelhouse),str(wheel)]
191
+ return base+['--index-url','https://pypi.org/simple',str(wheel)]
98
192
 
99
193
  def _run(argv,seconds,log,expected=None):
100
194
  allowed=('PATH','HOME','SSL_CERT_FILE','REQUESTS_CA_BUNDLE','CODEX_CA_CERTIFICATE')
101
195
  env={key:os.environ[key] for key in allowed if key in os.environ}
102
- env.update(PIP_CONFIG_FILE='/dev/null',PIP_DISABLE_PIP_VERSION_CHECK='1',PIP_INDEX_URL='https://pypi.org/simple',PYTHONNOUSERSITE='1')
196
+ env.update(PIP_CONFIG_FILE='/dev/null',PIP_DISABLE_PIP_VERSION_CHECK='1',PYTHONNOUSERSITE='1')
197
+ if '--no-index' in argv:
198
+ env['PIP_NO_INDEX']='1'
199
+ else:
200
+ env['PIP_INDEX_URL']='https://pypi.org/simple'
103
201
  result=subprocess.run(argv,capture_output=True,text=True,timeout=seconds,env=env,cwd='/workspace')
104
202
  output=(result.stdout+'\n'+result.stderr)[-50000:]
105
203
  with log.open('a') as stream:
@@ -129,34 +227,42 @@ def guest_main():
129
227
  if plan.get('spec')!=spec:
130
228
  raise ValueError('approved spec mismatch')
131
229
  status=_guest_tool('/github/api/status')
132
- registry=json.loads(_bounded_get('https://pypi.org/pypi/'+quote(policy['project'],safe='')+'/'+quote(policy['version'],safe='')+'/json',1000000))
230
+ registry=_release_json(policy['mode'])
133
231
  receipt=verify_publication_receipts(policy,status,registry)
134
232
  if policy['mode']=='new':
135
- placeholder=json.loads(_bounded_get('https://pypi.org/pypi/'+quote(policy['project'],safe='')+'/0.0.1/json',1000000))
233
+ placeholder=_placeholder_json(policy['mode'])
136
234
  found={entry['filename']:entry['digests']['sha256'] for entry in placeholder.get('urls',[])}
137
235
  if placeholder.get('info',{}).get('version')!='0.0.1' or found!=policy['artifact_digests']:
138
236
  raise ValueError('0.0.1 registration placeholder readback mismatch')
139
- file_digests={}
237
+ published=Path('/workspace/published')
238
+ file_digests={};wheel=None
140
239
  for item in receipt['files']:
141
- url=item['url'];parsed=urlsplit(url)
142
- if parsed.scheme!='https' or parsed.hostname!='files.pythonhosted.org' or parsed.username or parsed.password or parsed.fragment:
143
- raise ValueError('PyPI file URL rejected')
144
- data=_bounded_get(url,10*1024*1024)
145
- if hashlib.sha256(data).hexdigest()!=item['sha256']:
146
- raise ValueError('PyPI file bytes mismatch')
240
+ target=_fetch_artifact(item,published)
147
241
  file_digests[item['filename']]=item['sha256']
242
+ if item['filename'].endswith('.whl'):
243
+ wheel=target
244
+ if wheel is None:
245
+ raise ValueError('PyPI wheel missing')
246
+ dependency_sha=context.get('public_dependencies_sha256')
247
+ wheelhouse=None
248
+ if dependency_sha is not None:
249
+ dependencies=Path('/workspace/public-deps.tar.gz').read_bytes()
250
+ dependency_source=_stage_wheelhouse(dependencies,dependency_sha,Path('/workspace/verification-deps'))
251
+ wheelhouse=Path('/workspace/verification-deps')
252
+ else:
253
+ dependency_source=_dependency_provenance(None)
148
254
  root=Path('/workspace/result');root.mkdir(exist_ok=True)
149
255
  log=root/'publication-install.log'
150
256
  venv='/workspace/publication-venv'
151
257
  _run([sys.executable,'-m','venv',venv],45,log)
152
- pip_hash=_run([venv+'/bin/python','-m','pip','install','--no-input','--index-url','https://pypi.org/simple',
153
- policy['project']+'=='+policy['version']],180,log)
258
+ pip_hash=_run(_install_argv(venv,wheel,wheelhouse),180,log)
154
259
  _run([venv+'/bin/python','-m','pip','check'],30,log)
155
260
  cli=spec['cli']
156
261
  version_hash=_run([venv+'/bin/'+cli,'--version'],30,log,expected=policy['version'])
157
262
  tree_hash=_run([venv+'/bin/'+cli,'--tree'],30,log)
158
263
  receipt.update(plan_sha256=expected,pypi_file_digests=file_digests,
159
- clean_install_sha256=pip_hash,cli_version_sha256=version_hash,cli_tree_sha256=tree_hash)
264
+ clean_install_sha256=pip_hash,cli_version_sha256=version_hash,cli_tree_sha256=tree_hash,
265
+ dependency_source=dependency_source)
160
266
  (root/'trusted-publication.json').write_text(json.dumps(receipt,sort_keys=True,separators=(',',':')))
161
267
  print(json.dumps({'plan_sha256':expected,'tag':receipt['tag'],'merged_sha':receipt['merged_sha']}))
162
268
 
@@ -167,7 +273,7 @@ async def prepare_postprocess(sandbox,command,task,outcome,artifact,runtime):
167
273
  attestation=await sandbox.files.read_file('/workspace/trusted-validation.json')
168
274
  artifact(outcome,'trusted-validation.json',runtime.redact(attestation).encode())
169
275
 
170
- async def publish_postprocess(sandbox,command,task,outcome,artifact,runtime):
276
+ async def publish_postprocess(sandbox,command,task,outcome,artifact,runtime,*,public_dependencies=None):
171
277
  from .package_plan import verify_plan
172
278
  capability=task['capability']
173
279
  archive=task.get('_input_archive')
@@ -178,12 +284,20 @@ async def publish_postprocess(sandbox,command,task,outcome,artifact,runtime):
178
284
  raise ValueError('approved publication manifest changed')
179
285
  await sandbox.files.write_file('/workspace/package_publication.py',Path(__file__).read_bytes(),mode=600)
180
286
  context={'policy':capability['plan'],'spec':capability['spec'],'plan_sha256':capability['plan_sha256']}
287
+ if public_dependencies is not None:
288
+ if not isinstance(public_dependencies,bytes) or not public_dependencies or len(public_dependencies)>32*1024*1024:
289
+ raise ValueError('public dependency archive size rejected')
290
+ context['public_dependencies_sha256']=hashlib.sha256(public_dependencies).hexdigest()
291
+ await sandbox.files.write_file('/workspace/public-deps.tar.gz',public_dependencies,mode=600)
181
292
  await sandbox.files.write_file('/workspace/publication-policy.json',json.dumps(context,sort_keys=True),mode=600)
182
293
  try:
183
- await command(['python','/workspace/package_publication.py','--guest'],seconds=450)
294
+ await command(['python','/workspace/package_publication.py','--guest'],seconds=470)
184
295
  raw=await sandbox.files.read_file('/workspace/result/trusted-publication.json')
185
296
  receipt=json.loads(raw)
186
- if receipt.get('plan_sha256')!=capability['plan_sha256'] or receipt.get('repository')!=capability['plan']['repository'] or receipt.get('version')!=capability['plan']['version']:
297
+ if (receipt.get('plan_sha256')!=capability['plan_sha256'] or
298
+ receipt.get('repository')!=capability['plan']['repository'] or
299
+ receipt.get('version')!=capability['plan']['version'] or
300
+ receipt.get('dependency_source')!=_dependency_provenance(context.get('public_dependencies_sha256'))):
187
301
  raise ValueError('trusted publication receipt mismatch')
188
302
  artifact(outcome,'trusted-publication.json',runtime.redact(raw).encode())
189
303
  finally:
@@ -1,5 +1,7 @@
1
1
  """Owner-bound durable package drafts over the generic task engine."""
2
2
  from __future__ import annotations
3
+ import asyncio
4
+ from functools import partial
3
5
  import hashlib
4
6
  import json
5
7
  import re
@@ -18,7 +20,7 @@ def _task_request(prefix,owner,draft,revision,request_id):
18
20
  return prefix+'-'+_digest([owner,draft,revision,request_id])[:56]
19
21
 
20
22
  class PackageService:
21
- def __init__(self,store,tasks,*,broker_required=False):
23
+ def __init__(self,store,tasks,*,broker_required=False,public_dependencies: bytes | None=None):
22
24
  self.store=store
23
25
  self.tasks=tasks
24
26
  self.broker_required=broker_required
@@ -26,7 +28,8 @@ class PackageService:
26
28
  if executor is not None and hasattr(executor,'register_postprocessor'):
27
29
  from .package_publication import prepare_postprocess,publish_postprocess
28
30
  executor.register_postprocessor('prepare',prepare_postprocess,600)
29
- executor.register_postprocessor('publish',publish_postprocess,480)
31
+ executor.register_postprocessor('publish',partial(publish_postprocess,public_dependencies=public_dependencies),500)
32
+ executor.register_postprocessor('verify',partial(publish_postprocess,public_dependencies=public_dependencies),500)
30
33
 
31
34
  def _owned(self,owner,ident):
32
35
  if not isinstance(ident,str) or not DRAFT_ID.fullmatch(ident):
@@ -99,6 +102,23 @@ class PackageService:
99
102
  task=self.tasks.get(owner,draft['publish_task_id'])
100
103
  verified=task['status']=='completed' and any(item.get('name')=='trusted-publication.json' for item in task.get('artifacts',[]))
101
104
  draft={**draft,'publish_status':task['status'],'publish_result':task.get('result'),'publish_error':task.get('error'),'publish_verified':verified}
105
+ if draft.get('verification_task_id'):
106
+ task=self.tasks.get(owner,draft['verification_task_id'])
107
+ rechecked=False
108
+ if task['status']=='completed' and draft.get('preview'):
109
+ entry=next((item for item in task.get('artifacts',[]) if item.get('name')=='trusted-publication.json'),None)
110
+ if entry and entry.get('size',0)<=50000:
111
+ try:
112
+ raw=self.store.artifact(task['id'],'trusted-publication.json')
113
+ receipt=json.loads(raw)
114
+ rechecked=(len(raw)==entry['size'] and hashlib.sha256(raw).hexdigest()==entry['sha256'] and
115
+ receipt.get('plan_sha256')==draft['preview']['plan_sha256'] and
116
+ receipt.get('repository')==draft['preview']['policy']['repository'] and
117
+ receipt.get('version')==draft['preview']['policy']['version'])
118
+ except (ValueError,KeyError,OSError,TypeError):
119
+ pass
120
+ draft={**draft,'verification_status':task['status'],'verification_error':task.get('error'),
121
+ 'publish_verified':draft.get('publish_verified',False) or rechecked}
102
122
  return self._public(draft)
103
123
 
104
124
  async def create(self,owner,body):
@@ -237,3 +257,87 @@ class PackageService:
237
257
  fresh['publish_task_id']=task['id'];fresh['updated_at']=now()
238
258
  self.store.put('package_drafts',ident,fresh)
239
259
  return self.get(owner,ident)
260
+
261
+ async def recheck(self,owner,ident,body):
262
+ """Create an explicit read-only task against an immutable approved publication."""
263
+ if self.broker_required and not getattr(getattr(self.tasks,'executor',None),'gateway',None):
264
+ raise ValueError('package verification requires configured task gateway')
265
+ _request(body,('request_id','revision'))
266
+ draft=self._owned(owner,ident)
267
+ if body['revision']!=draft['revision']:
268
+ raise ValueError('stale draft revision')
269
+ if not draft.get('preview') and draft.get('prepare_task_id'):
270
+ self.get(owner,ident)
271
+ draft=self._owned(owner,ident)
272
+ preview=draft.get('preview');approval=draft.get('approval')
273
+ if not draft.get('confirm_request_id') or not draft.get('publish_task_id') or not preview or not approval:
274
+ raise ValueError('submitted, approved preflight and publish task required')
275
+ if (preview.get('revision')!=draft['revision'] or preview.get('spec_fingerprint')!=draft['fingerprint'] or
276
+ preview.get('task_id')!=draft.get('prepare_task_id') or approval.get('owner')!=owner or
277
+ approval.get('revision')!=draft['revision'] or approval.get('preview_sha256')!=preview.get('preview_sha256') or
278
+ approval.get('confirmation')!=preview.get('confirmation')):
279
+ raise ValueError('approved preview changed')
280
+ publish=self.tasks.get(owner,draft['publish_task_id'])
281
+ if publish['status'] not in ('completed','blocked','interrupted','cancelled'):
282
+ raise ValueError('original publish task is not terminal')
283
+ prep=self.tasks.get(owner,draft['prepare_task_id'])
284
+ artifact=next((a for a in prep.get('artifacts',[]) if a.get('name')=='result.tar.gz'),None)
285
+ att=next((a for a in prep.get('artifacts',[]) if a.get('name')=='trusted-validation.json'),None)
286
+ if prep['status']!='completed' or not artifact or not att or att.get('size',0)>50000:
287
+ raise ValueError('completed verified preparation required')
288
+ data=self.store.artifact(prep['id'],'result.tar.gz')
289
+ if len(data)!=artifact['size'] or hashlib.sha256(data).hexdigest()!=artifact['sha256']:
290
+ raise ValueError('preparation archive changed')
291
+ checked=verify_plan(data,draft['spec'])
292
+ if (checked['archive_sha256']!=preview['archive_sha256'] or checked['plan_sha256']!=preview['plan_sha256'] or
293
+ checked['policy']!=preview['policy'] or checked['source_manifests']!=preview['source_manifests']):
294
+ raise ValueError('approved plan changed')
295
+ att_bytes=self.store.artifact(prep['id'],'trusted-validation.json')
296
+ if len(att_bytes)!=att['size'] or hashlib.sha256(att_bytes).hexdigest()!=att['sha256']:
297
+ raise ValueError('preparation validation changed')
298
+ evidence=json.loads(att_bytes)
299
+ if (evidence.get('plan_sha256')!=checked['plan_sha256'] or
300
+ trusted_checks(evidence.get('checks'))!=checked['validation'] or
301
+ set(evidence.get('branches',{}))!=set(checked['source_manifests'])):
302
+ raise ValueError('preparation validation does not bind approved plan')
303
+ images=self.tasks.images() if callable(self.tasks.images) else self.tasks.images
304
+ names=[x['id'] for x in images] if isinstance(images,list) else list(images)
305
+ if prep.get('image_profile') not in names:
306
+ raise ValueError('original image profile is unavailable')
307
+ digest=_digest(body)
308
+ with self.store.locked():
309
+ fresh=self._owned(owner,ident)
310
+ self._check_other_request(owner,body['request_id'],ident)
311
+ old=fresh['operations'].get(body['request_id'])
312
+ if old and (old['kind']!='recheck' or old['fingerprint']!=digest):
313
+ raise ValueError('request_id input conflict')
314
+ if fresh.get('confirm_request_id')==body['request_id']:
315
+ raise ValueError('request_id already used for confirmation')
316
+ if fresh['revision']!=draft['revision'] or fresh.get('preview')!=preview or fresh.get('approval')!=approval:
317
+ raise ValueError('approved preview changed')
318
+ previous=fresh.get('verification_task_id')
319
+ if fresh.get('verification_request_id') and fresh['verification_request_id']!=body['request_id']:
320
+ if not previous or self.tasks.get(owner,previous)['status'] not in ('completed','blocked','interrupted','cancelled'):
321
+ raise ValueError('verification already running')
322
+ fresh['verification_request_id']=body['request_id']
323
+ fresh['verification_task_id']=previous if old else None
324
+ fresh['operations'][body['request_id']]={'kind':'recheck','fingerprint':digest}
325
+ fresh['updated_at']=now()
326
+ self.store.put('package_drafts',ident,fresh)
327
+ gateway=getattr(getattr(self.tasks,'executor',None),'gateway',None)
328
+ if not gateway or not callable(getattr(gateway,'close',None)):
329
+ raise ValueError('trusted gateway lease closure is required')
330
+ closed=await asyncio.to_thread(gateway.close,draft['publish_task_id'])
331
+ if closed!={'closed':True}:
332
+ raise ValueError('original publish lease closure unconfirmed')
333
+ task=await self.tasks.create_internal(owner,{'request_id':_task_request('pkgverify',owner,ident,draft['revision'],body['request_id']),
334
+ 'instructions':'Read-only trusted publication verification of the approved preparation archive.',
335
+ 'image_profile':prep['image_profile'],'input_task_id':prep['id']},
336
+ {'mode':'verify','plan':preview['policy'],'spec':draft['spec'],'plan_sha256':preview['plan_sha256'],
337
+ 'source_task_id':draft['publish_task_id']})
338
+ with self.store.locked():
339
+ fresh=self._owned(owner,ident)
340
+ if fresh.get('verification_request_id')==body['request_id'] and fresh['revision']==draft['revision']:
341
+ fresh['verification_task_id']=task['id'];fresh['updated_at']=now()
342
+ self.store.put('package_drafts',ident,fresh)
343
+ return self.get(owner,ident)
@@ -40,7 +40,10 @@ def create_app(settings: TaskSettings | None=None, *, service: TaskService | Non
40
40
  agent_tasks = agent_tasks if agent_tasks is not None else AgentTaskService(workflow.store, configured_executor(settings, service))
41
41
  from .package_service import PackageService
42
42
  from .package_template import form_schema, intent_prefill
43
- packages = PackageService(workflow.store, agent_tasks, broker_required=True)
43
+ public_dependencies=getattr(getattr(workflow,'executor',None),'dependency_archive',None)
44
+ if public_dependencies is None:
45
+ public_dependencies=load_guest_dependencies(settings)
46
+ packages = PackageService(workflow.store, agent_tasks, broker_required=True,public_dependencies=public_dependencies)
44
47
  @asynccontextmanager
45
48
  async def lifespan(app: FastAPI):
46
49
  await workflow.recover()
@@ -271,6 +274,15 @@ def create_app(settings: TaskSettings | None=None, *, service: TaskService | Non
271
274
  except ValueError as exc:
272
275
  raise HTTPException(409, detail=str(exc))
273
276
 
277
+ @app.post('/api/package/drafts/{draft_id}/recheck')
278
+ async def package_recheck(request: Request, draft_id: str, body: dict):
279
+ try:
280
+ return await packages.recheck(await owner(request), draft_id, body)
281
+ except (KeyError, FileNotFoundError):
282
+ raise HTTPException(404, detail='draft not found')
283
+ except ValueError as exc:
284
+ raise HTTPException(409, detail=str(exc))
285
+
274
286
  @app.get('/api/templates')
275
287
  async def templates():
276
288
  return {'templates': workflow.templates()}
@@ -522,7 +522,7 @@ function clearPackageState() {
522
522
  for (const id of ['package-link','package-progress','package-preview','package-state']) $(id).textContent = '';
523
523
  $('package-intent').value = ''; $('package-confirm-text').checked = false;
524
524
  $('package-confirm-box').hidden = true;
525
- for (const id of ['package-save','package-prepare','package-confirm','package-prefill','package-retry-confirm']) $(id).disabled = true;
525
+ for (const id of ['package-save','package-prepare','package-confirm','package-prefill','package-retry-confirm','package-recheck']) $(id).disabled = true;
526
526
  }
527
527
  function suggestPackageFields() {
528
528
  const value = $('pkg-package_name')?.value || '';
@@ -555,7 +555,7 @@ function packageFields() {
555
555
  return spec;
556
556
  }
557
557
  function packageDirty() {
558
- return !!packageDraft && JSON.stringify(packageFields()) !== JSON.stringify(packageDraft.spec);
558
+ return !!packageDraft && Object.entries(packageFields()).some(([key,value]) => value !== packageDraft.spec[key]);
559
559
  }
560
560
  function packageControls() {
561
561
  const hasDraft = !!packageDraft;
@@ -570,6 +570,10 @@ function packageControls() {
570
570
  !packageDraft.preview || submitted || !$('package-confirm-text').checked;
571
571
  $('package-retry-confirm').disabled = !authenticated || packageBusy || !hasDraft ||
572
572
  packageDraft.publish_error !== 'GatewayUnknown';
573
+ $('package-recheck').disabled = !authenticated || packageBusy || !hasDraft || dirty || !packageSchema?.available ||
574
+ !submitted || !['completed','blocked','interrupted','cancelled'].includes(packageDraft.publish_status) ||
575
+ ['queued','running','cancel_requested'].includes(packageDraft.verification_status) ||
576
+ !!packageDraft.publish_verified || !!(packagePending && packagePending.kind !== 'recheck');
573
577
  }
574
578
  function packagePendingSet(value) {
575
579
  packagePending = value;
@@ -608,10 +612,13 @@ function renderPackage(draft) {
608
612
  const dirty = packageDirty();
609
613
  const prep = draft.prepare_task_id ? '预检任务 ' + draft.prepare_task_id + ' · ' + (draft.prepare_status || '可刷新') : '尚未预检';
610
614
  const pub = draft.publish_task_id ? ';发布任务 ' + draft.publish_task_id + ' · ' + (draft.publish_status || '可刷新') : '';
611
- show('package-progress', prep + pub + (dirty ? ';参数有未保存修改' : ''));
615
+ const verification = draft.verification_task_id ? ';只读核验任务 ' + draft.verification_task_id + ' · ' + (draft.verification_status || '可刷新') : '';
616
+ show('package-progress', prep + pub + verification + (dirty ? ';参数有未保存修改' : ''));
612
617
  const preview = draft.preview;
613
618
  $('package-confirm-box').hidden = !preview || !!draft.publish_task_id || dirty;
614
619
  $('package-retry-confirm').hidden = draft.publish_error !== 'GatewayUnknown';
620
+ $('package-recheck').hidden = !draft.publish_task_id || !['completed','blocked','interrupted','cancelled'].includes(draft.publish_status);
621
+ $('package-recheck-note').hidden = $('package-recheck').hidden;
615
622
  $('package-confirm-target').textContent = preview ? preview.policy.repository + ' · ' + preview.policy.tag : '';
616
623
  if (preview) {
617
624
  $('package-preview').textContent = JSON.stringify({
@@ -624,11 +631,11 @@ function renderPackage(draft) {
624
631
  } else $('package-preview').textContent = draft.prepare_task_id ?
625
632
  '预检任务正在执行或结果尚未验证。刷新后查看精确目标与产物摘要。' : '请先保存草稿并运行预检。';
626
633
  $('package-artifacts').replaceChildren();
627
- for (const id of [draft.prepare_task_id, draft.publish_task_id]) {
634
+ for (const id of [draft.prepare_task_id, draft.publish_task_id, draft.verification_task_id]) {
628
635
  if (!id) continue;
629
636
  const a = document.createElement('a');
630
637
  a.href = '/api/agent/tasks/' + id;
631
- a.textContent = (id === draft.prepare_task_id ? '预检' : '发布') + '任务状态 · ' + id;
638
+ a.textContent = (id === draft.prepare_task_id ? '预检' : id === draft.publish_task_id ? '发布' : '只读核验') + '任务状态 · ' + id;
632
639
  a.target = '_blank'; a.rel = 'noopener';
633
640
  $('package-artifacts').append(a);
634
641
  const download = document.createElement('a');
@@ -638,7 +645,11 @@ function renderPackage(draft) {
638
645
  }
639
646
  if (draft.prepare_error) show('package-state', '预检验证受阻:' + draft.prepare_error, true);
640
647
  if (draft.publish_task_id) {
641
- if (draft.publish_error || ['blocked','interrupted','cancelled'].includes(draft.publish_status)) {
648
+ if (draft.verification_status === 'completed' && draft.publish_verified)
649
+ show('package-state','重新核验通过;原执行记录保留。原发布任务:' + draft.publish_status + (draft.publish_error ? '(' + draft.publish_error + ')' : '') + '。');
650
+ else if (draft.verification_status && ['blocked','interrupted','cancelled'].includes(draft.verification_status))
651
+ show('package-state','只读重新核验受阻:' + (draft.verification_error || draft.verification_status) + '。原发布任务仍为 ' + draft.publish_status + '。',true);
652
+ else if (draft.publish_error || ['blocked','interrupted','cancelled'].includes(draft.publish_status)) {
642
653
  show('package-state','发布核验未完成:' + (draft.publish_error || draft.publish_status) + '。模型摘要不能作为发布成功的依据。',true);
643
654
  } else if (draft.publish_verified) show('package-state','发布完成,外部回执和干净安装核验已通过。');
644
655
  else show('package-state','发布状态:' + draft.publish_status + ';仍需完整外部核验。');
@@ -650,6 +661,8 @@ function renderPackage(draft) {
650
661
  packagePoll = setTimeout(() => loadPackage(draft.id), 2500);
651
662
  if (draft.publish_task_id && ['queued','running','cancel_requested'].includes(draft.publish_status))
652
663
  packagePoll = setTimeout(() => loadPackage(draft.id), 2500);
664
+ if (draft.verification_task_id && ['queued','running','cancel_requested'].includes(draft.verification_status))
665
+ packagePoll = setTimeout(() => loadPackage(draft.id), 2500);
653
666
  }
654
667
  async function loadPackage(id) {
655
668
  if (!id) {
@@ -778,3 +791,16 @@ $('package-retry-confirm').addEventListener('click', async () => {
778
791
  } catch (error) { show('package-state', '同一任务重试未确认:' + error.message, true); }
779
792
  finally { packageBusy = false; packageControls(); }
780
793
  });
794
+
795
+ $('package-recheck').addEventListener('click', async () => {
796
+ if (!packageDraft || packageBusy || packageDirty()) return;
797
+ packageBusy = true; packageControls();
798
+ try {
799
+ const body = {request_id:crypto.randomUUID(),revision:packageDraft.revision};
800
+ const draft = await packageMutation('recheck','/api/package/drafts/' + packageDraft.id + '/recheck','POST',body);
801
+ renderPackage(draft);
802
+ show('package-state','只读核验已提交;不会再次发布、创建 PR 或标签。原执行记录保留。');
803
+ } catch (error) {
804
+ show('package-state','只读核验结果未确认:' + error.message + '。重试此按钮会使用同一请求 ID。',true);
805
+ } finally { packageBusy = false; packageControls(); }
806
+ });
@@ -79,6 +79,8 @@
79
79
  <label for="package-confirm-text"><input id="package-confirm-text" type="checkbox"> 我已核对目标和权限,授权按此快照发布</label>
80
80
  <button id="package-confirm" class="primary-action" type="button" disabled>确认并提交发布</button>
81
81
  </div>
82
+ <button id="package-recheck" class="secondary-action" type="button" hidden>只读重新核验</button>
83
+ <p id="package-recheck-note" class="meta-note" hidden>只读取已发布结果;不会再次发布、创建 PR 或标签。原执行记录和错误保留。</p>
82
84
  <button id="package-retry-confirm" class="secondary-action" type="button" hidden>重试同一网关会话</button>
83
85
  <button id="package-refresh" class="secondary-action" type="button">刷新状态</button>
84
86
  </section>
@@ -2,4 +2,4 @@ from chattask import __version__
2
2
 
3
3
 
4
4
  def test_version_present():
5
- assert __version__ == "0.1.1"
5
+ assert __version__ == "0.1.3"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes