Skip to content

Conversation

@ultmaster
Copy link
Contributor

Summary

  • dump pretty results to .result.txt for JS traces
  • add trace_artifact helper to Python API
  • support new artifact files in tests
  • infer latest trace prefix instead of tracking globals
  • use regex to locate latest trace prefix in python
  • ensure regex logic handles filenames with dots

Testing

  • npm run build-webview
  • npm run build-cli
  • npm run lint
  • npm test
  • python -m pytest python/tests

https://chatgpt.com/codex/tasks/task_e_68875447fe1c832e922bc6e3fcb1ee58

Copilot AI review requested due to automatic review settings July 29, 2025 06:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables enhanced tracing functionality by adding artifact support and pretty-printed result dumps. The main purpose is to improve debugging and inspection capabilities for POML executions by generating additional trace files with human-readable outputs.

Key changes include:

  • Adding trace_artifact function to Python API for creating custom trace files
  • Dumping pretty-printed results to .result.txt files in JavaScript traces
  • Implementing regex-based logic to find the latest trace prefix instead of tracking globals

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
python/poml/init.py Exports new trace_artifact function
python/poml/api.py Implements trace_artifact and _latest_trace_prefix helper functions
python/tests/test_basic.py Adds comprehensive tests for artifact functionality and prefix regex logic
packages/poml/util/trace.ts Adds support for dumping pretty-printed results to .result.txt files
packages/poml/index.ts Refactors output generation and passes pretty output to trace dump
packages/poml/tests/trace.test.tsx Tests that pretty-printed result text is properly dumped

if not (_trace_enabled and _trace_dir):
return None

pattern = re.compile(r"^(\d{4}.*?)(?:\.source)?\.poml$")
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern will incorrectly match files ending with '.source.poml' and treat them as valid trace files. The negative lookahead should be modified to properly exclude source files while still matching the main trace files.

Suggested change
pattern = re.compile(r"^(\d{4}.*?)(?:\.source)?\.poml$")
pattern = re.compile(r"^(\d{4}.*?)(?!\.source\.poml)\.poml$")

Copilot uses AI. Check for mistakes.
Comment on lines +74 to +75
if prefix_part.endswith(".source"):
continue
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check for '.source' suffix is redundant and potentially incorrect since the regex already handles this case. The logic should be consistent between the regex pattern and this manual check.

Suggested change
if prefix_part.endswith(".source"):
continue

Copilot uses AI. Check for mistakes.
Comment on lines +87 to +92
def trace_artifact(file_suffix: str, contents: str | bytes) -> Optional[Path]:
"""Write an additional artifact file for the most recent ``poml`` call."""
prefix = _latest_trace_prefix()
if prefix is None:
return None
suffix = file_suffix if file_suffix.startswith(".") else f".{file_suffix}"
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider extracting this suffix normalization logic into a helper function or using a more explicit conditional to improve readability and potential reuse.

Suggested change
def trace_artifact(file_suffix: str, contents: str | bytes) -> Optional[Path]:
"""Write an additional artifact file for the most recent ``poml`` call."""
prefix = _latest_trace_prefix()
if prefix is None:
return None
suffix = file_suffix if file_suffix.startswith(".") else f".{file_suffix}"
def _normalize_suffix(file_suffix: str) -> str:
"""Ensure the file suffix starts with a dot."""
return file_suffix if file_suffix.startswith(".") else f".{file_suffix}"
def trace_artifact(file_suffix: str, contents: str | bytes) -> Optional[Path]:
"""Write an additional artifact file for the most recent ``poml`` call."""
prefix = _latest_trace_prefix()
if prefix is None:
return None
suffix = _normalize_suffix(file_suffix)

Copilot uses AI. Check for mistakes.
@ultmaster ultmaster merged commit e599c71 into main Jul 29, 2025
3 checks passed
@ultmaster ultmaster deleted the codex/add-pretty-print-for-js-trace-output branch August 27, 2025 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants