diff --git a/agent.py b/agent.py index fcca3ef..51af514 100644 --- a/agent.py +++ b/agent.py @@ -702,12 +702,16 @@ async def _write_workspace_text(ctx: RunContext[NoAuth], path: str, text: str, m if len(data) > MAX_TEXT_BYTES * 4: raise ValueError("artifact exceeds bounded text size") ws = ctx.workspace - if hasattr(ws, "write_bytes"): - ws.write_bytes(clean, data) # type: ignore[attr-defined] + if hasattr(ws, "is_writable_output") and ws.is_writable_output(clean): # type: ignore[attr-defined] + if hasattr(ws, "write_bytes"): + ws.write_bytes(clean, data) # type: ignore[attr-defined] + else: + view = await ws.open_view(purpose=f"write {clean}", hints=[clean], max_files=1, mode=WorkspaceMode.READ_WRITE_OVERLAY, reason="Persist integration engineering output under outputs/integrations") + await view.write(clean, data) else: - view = await ws.open_view(purpose=f"write {clean}", hints=[clean], max_files=1, mode=WorkspaceMode.READ_WRITE_OVERLAY, reason="Persist integration engineering output under outputs/integrations") - await view.write(clean, data) - ref = await ctx.write_artifact(clean.split("/")[-1], data, mime_type) + raise PermissionError("workspace grant does not allow writes under outputs/integrations") + artifact_name = clean.replace("/", "__") + ref = await ctx.write_artifact(artifact_name, data, mime_type) await ctx.emit_artifact(ref) return ArtifactRecord(path=clean, sha256=hashlib.sha256(data).hexdigest(), size_bytes=len(data), mime_type=mime_type)