feat(examples): add invoice PDF generator skill and actor example #188
No reviewers
Labels
No labels
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Blocks
#187 Add examples/ invoice PDF generator skill and actor demonstrating gated script execution
cleveragents/cleveractors-core
Reference
cleveragents/cleveractors-core!188
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/m1-invoice-pdf-skill-example"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds a second, independent
examples/demonstration alongside thecalculator app (issue #148): an "invoice clerk" LLM agent that extracts
plain text/numeric fields from a user's request and runs a bundled skill
script through the
execute: truegate (ADR-2034 D-10) to produce a realPDF invoice -- a genuine use of gated script execution, not just
instructions-only skill usage like the existing
programming-patternsskill.
examples/packages/invoice-pdf-generator.yaml: askill-type package(
safe_mode: false) bundling one script,scripts/generate_invoice.py,with a full
SKILL.md-equivalentinstructionsfield documenting theCLI. The script takes only plain text/numeric flags, computes
subtotal/tax/total, and hand-builds a valid, single-page, ASCII-only PDF
from the standard library -- no third-party PDF dependency.
examples/packages/invoice-agent.yaml: atype: llmagent(
skills: ["local:invoice-pdf-generator.yaml"],safe_mode: false,allow_shell: true) whose system prompt never drafts the PDF itself --it only extracts field values and dispatches the skill tool.
examples/packages/invoice-actor.yaml: wires the agent into asingle-node route with
context.global.unsafe: true.examples/test_app.py: setsCLEVERACTORS_PROJECT_ROOTto its ownlaunch directory so the bundled script -- which runs inside an
ephemeral, auto-deleted execution workspace -- can still write the PDF
under an
invoices/folder at the project base path instead of losingit when the workspace is torn down.
examples/README.md/.gitignore/CHANGELOG.mdupdated to match.Closes #187
Test plan
nox -s lint-- greennox -s typecheck-- 0 errors, 0 warningsnox -s security_scan/nox -s dead_code-- greennox -s unit_tests-- green (160 features, 3360 scenarios, 0 failed; this change touches onlyexamples/, notfeatures/)ruff check/pyrightdirectly on the bundled script content before embedding -- cleanfileconfirms "PDF document, version 1.4, 1 page(s)"), every validation/error path (missing item, malformed item, non-ASCII input, path-traversal filename), default-filename derivationcleveractors.agents.skill_schema.SkillValidatorLocalPackageStore/PackageContentResolverand built a realExecutorviacleveractors.runtime.create_executor, matching the issue #148 precedentexecute: truepath driven directly through the realAgentFactory/ToolAgent._skill_toolproduction code (no live LLM needed for this check) -- confirmed the double-safety gate opens/closes correctly, the script runs in its real ephemeral workspace, and the PDF lands ininvoices/outside that workspaceUnsafeConfigurationErrorbefore any agent/script runs when the host is not started with--unsafePR Review: !188 (Ticket #187)
Verdict: Request Changes
The example is well-constructed and nearly everything verifies end-to-end: the skill YAML passes
SkillValidator, the actor resolves throughLocalPackageStoreand builds a realExecutorwithunsafe=True,execute()refuses withUnsafeConfigurationErroron a safe host before anything runs,CLEVERACTORS_PROJECT_ROOTpropagates throughcreate_subprocess_exec(noenvoverride), the PDF lands at$CLEVERACTORS_PROJECT_ROOT/invoices/as a validPDF document, version 1.4, 1 page(s), the ephemeral workspace is cleaned up, and path-traversal/malformed-item/missing-item paths all reject cleanly. However, the embedded script violates an explicit acceptance criterion on two input fields, verified by execution.Critical Issues
None.
Major Issues
examples/packages/invoice-pdf-generator.yaml(embedded script,main()) —--due-dateand--currencyare never ASCII-validated, so non-ASCII values crash with a rawUnicodeEncodeErrortraceback (exit code 1) inside_render_pdf_document'scontent_stream.encode('ascii')instead of the cleanerror: .../ exit-2 path every other text field uses. Verified by execution:--due-date "Frühjahr 2027"→UnicodeEncodeError ... position 182, rc=1;--currency "EURO €"→UnicodeEncodeError ... position 844, rc=1. This breaks three things at once:instructionsfield, which promises: "Every text value must be ASCII-only; the script rejects anything else with a clearerror: ... must contain only ASCII charactersmessage (exit code 2)" — documented behavior the script does not implement, and the LLM agent relays these instructions to users.Recommendation: in
main()'s try block, add a guarded_require_ascii("--due-date", args.due_date)(skip when empty, like--seller-address) and_require_ascii("--currency", args.currency).Minor Issues
_build_content_stream/ summary line — one-cent display inconsistency: tax and total are rounded independently from float math, so the printed figures don't sum. Verified with the README's own example numbers: subtotal=1749.00, tax=148.67 (raw 148.66500000000002), but total prints 1897.66 — i.e., 1749.00 + 148.67 = 1897.67 ≠ 1897.66 on a customer-facing invoice. Recommendation: round tax to 2dp first, then compute total = subtotal + rounded tax so the printed rows are internally consistent.Nits
output_path.write_bytes(...)silently overwrites an existing invoice with the same derived/explicit filename — regeneratingINV-1001destroys the previousINV-1001.pdfwith no warning.nox -s lint/typecheck/ coverage — correctness rests on one-time manual validation, and future edits to the YAML ship unvalidated. Acceptable per the #148 precedent and the ticket's manual-validation subtasks, but worth remembering if this script grows./invoices/in.gitignoreis root-anchored, but output lands wherevertest_app.pywas launched; launching from a subdirectory leaves unignored artifacts (README does document launch-from-root behavior).Summary
Verified working end-to-end: skill schema validation, actor→agent→skill resolution, real
Executorbuild, the double-safety gate (UnsafeConfigurationErroron a safe host, before any agent/script runs), env-var propagation into the script subprocess, valid single-page PDF output at the project base path, workspace cleanup, and clean rejection of path-traversal, malformed-item, and missing-item inputs. The safe-mode blocklist does not interfere with realistic item descriptions ("Alarm system", "Dell laptop") because the agent runs withsafe_mode: false— checked and cleared. Commit hygiene is fine (single atomic commit, first line matches the issue Metadata exactly, no merge commits, branch matches Metadata). The one blocking gap is the missing ASCII validation on--due-date/--currency, which contradicts both the ticket AC and the skill's own documented contract; with that fixed (plus ideally the rounding nit), this is a solid, genuinely useful demonstration of the ADR-2034 D-10 gate. The unchecked live-LLM test-plan item is treated as deferred per the documented provider caveat, same as the calculator example.72bf9794cf6ae28258bd@hurui200320 Thanks for the thorough execution-verified review. I checked each point against issue #187's AC, the skill's own
instructionsfield,docs/index.md§4.4.8, anddocs/adr/ADR-2034-skill-package-support.md(D-9/D-10) before touching anything. Here's what changed and what didn't, with justification for each.Major Issues
--due-date/--currencynot ASCII-validated — fixed.Confirmed your finding:
main()validated--invoice-number,--invoice-date,--seller-name,--customer-name, and conditionally--seller-address/--customer-address/--notes, but never--due-dateor--currency. That's a genuine gap against issue #187's AC ("non-ASCII input is rejected with a clear error") and the skill's own CLI reference table, which documents ASCII-only validation for every text field including these two — so there was no spec conflict to weigh, just a missed call site.Added
if args.due_date: _require_ascii("--due-date", args.due_date)and_require_ascii("--currency", args.currency)(unconditional, since--currencyalways has a value via its"USD"default) to the same validation block, before any PDF construction begins.Re-verified by execution:
--due-date "Frühjahr 2027"→error: --due-date must contain only ASCII characters: ..., exit 2--currency "EURO €"→error: --currency must contain only ASCII characters: ..., exit 2Both now take the same clean-error/exit-2 path as every other field; no more raw
UnicodeEncodeErrortraceback.Minor Issues
Tax/total rounding inconsistency — fixed.
Agreed this is a real display bug, not a style preference — a customer-facing invoice whose line items don't sum is a correctness defect. Changed
tax_amount = subtotal * (args.tax_rate / 100.0)totax_amount = round(subtotal * (args.tax_rate / 100.0), 2), computed beforetotal = subtotal + tax_amount, exactly as you recommended.Re-verified with your own numbers: subtotal=1749.00, tax=148.67 (rounded from 148.665), total now prints 1897.67 (1749.00 + 148.67), consistent. I also updated the stale
1897.66in the skill's documented example output (instructionsfield) to match — that example is now accurate again.Nits — left as-is
nox -s lint/typecheck/coverage. You already called this acceptable per the #148 precedent — confirmed:noxfile.py'slint,typecheck,security_scan,dead_code, andunit_tests/coverage_reportsessions all scope explicitly tosrc,features,benchmarks,utils—examples/is out of scope for every one of them. No action needed; verification of this fix was done the same way the original PR's test plan did it, by extracting and running the embedded script standalone (regression-checked missing-item, malformed-item, and path-traversal-filename paths too — all still reject cleanly)..gitignoreentry vs. launch-from-subdirectory. Already documented as a known, accepted limitation (README documents launch-from-root). No change.On the "independent PRs" note
I looked for this across the PR's reviews, issue/PR comments, and timeline and didn't find any comment to that effect on PR #188 — nothing here suggested splitting this into multiple PRs, so there's nothing to address or ignore on that front.
Verification summary
examples/packages/invoice-pdf-generator.yamlonly (embedded script + documented example output).examples/, so there is no coverage delta to report for this change.feat(examples): add invoice PDF generator skill and actor example) rather than adding a new one, per this project's one-issue-one-commit convention, and force-pushed to sync this PR branch.Ready for re-review.
PR Review: !188 (Ticket #187) - Re-review of fix pass
Verdict: Approve
Re-review of the force-pushed fix commit (
6ae2825, amending the single atomic commit per the one-issue-one-commit convention). Both blocking findings from the previous review are fixed and re-verified by execution, and the previously flagged nits were dispositioned by the author (deferred/accepted) and are removed from this review. All ticket #187 acceptance criteria hold against the latest commit.Critical Issues
None.
Major Issues
None. Both previously reported majors are resolved and re-verified:
--due-date/--currencyASCII validation - fixed. Re-verified by execution, both standalone and through the real production gate:--due-date "Frühjahr 2027"and--currency "EURO €"now take the cleanerror: ... must contain only ASCII characters/ exit-2 path (no rawUnicodeEncodeError, no file written), standalone and via the realToolAgent._skill_toolexecute: truepath (the failure surfaces as the properExecutionErrorenvelope with the exit-2 stderr text).total = subtotal + tax_amount. Re-verified through the real gate with the README's own example numbers: subtotal=1749.00, tax=148.67, total=1897.67 - internally consistent, and the documented example output in the skill'sinstructionsfield was updated to match.Minor Issues
examples/packages/invoice-pdf-generator.yaml(embedded script,_parse_item/main) - NaN/infnumeric values bypass every numeric validation:float("nan")satisfies neitherquantity <= 0norunit_price < 0(both comparisons are False for NaN), and--tax-rate nan/1e400(->inf) passes thetax_rate < 0check. Verified by execution:--item "Widget:nan:10.00",--item "Widget:1:nan", and--tax-rate naneach produce a written PDF and exit 0 withsubtotal=nan ... total=nan(orinf) in both the summary line and the rendered PDF - contradicting the skill's own documented contract ("Quantity must be positive; unit price must be non-negative") in the same spirit as the previously fixed ASCII gap, though with no crash and no security impact (garbage-in/garbage-out on a customer-facing document). Recommendation: guard the numeric parses withmath.isfinite()(reject non-finite quantity/unit_price/tax_rate with the standardInvoiceArgumentError/ exit-2 path). Fine to address in a follow-up given this is an example; not blocking.Nits
examples/packages/invoice-agent.yaml(header comment) - claims the package is anagent-type local package with prefixpkg_agt_(§3.2), butLocalPackageStore's key-heuristic type detection (_TYPE_DETECTORSinsrc/cleveractors/registry/local_store.py) matches none of its top-level keys (type/config) and falls back toPackageType.TEMPLATE, assigningpkg_tpl_54165e.... Functionally harmless (ADR-2037 D-3 uses the resolved dict as-is; dispatch works - verified end-to-end), and the identical claim/comment exists verbatim in the mergedcalculator-app-builder.yamlthis PR mirrors, so it is an inherited pattern rather than a regression. Optional docs touch-up, ideally across both examples in one follow-up.Removed from review (author disposition)
Per the review-response thread, the following previously flagged nits are dropped as decided: the silent overwrite of an existing invoice with the same derived filename (deferred to a follow-up issue by the author - out of scope for this fix pass), the embedded script being invisible to
nox -s lint/typecheck/coverage (confirmed acceptable: all nox sessions scope tosrc/features/benchmarks/utils, same as the #148 precedent), and the root-anchored/invoices/.gitignoreentry vs. launch-from-subdirectory (documented, accepted limitation).Verification performed (local, no CI reliance)
SkillValidator(safe_mode: False, exactly one resourcescripts/generate_invoice.py).LocalPackageStoreand builds a realExecutorwithunsafe=True; with the host not in unsafe mode,Executor.execute()refuses withUnsafeConfigurationErrorbefore any agent/script runs (real production code).execute: truedriven through the realToolAgent._skill_tool(skills loaded via the dispatch-timeSkillLoader, double-safety gate open:_unsafe_mode: true+ skillsafe_mode: false+allow_shell: true): script runs in the ephemeral workspace, PDF lands under$CLEVERACTORS_PROJECT_ROOT/invoices/,INVOICE_SUMMARYconsistent; non-ASCII--due-datethrough the same path rejects cleanly.--output-filename, non-ASCII item description, and default-filename derivation all behave as documented (fileconfirms a valid 1-page PDF 1.4 on success).examples/is excluded from every quality-gate session, so the reported green runs (160 features / 3360 scenarios) and unchanged coverage remain authoritative for this change.ISSUES CLOSED: #187present, branch name matches the ticket Metadata, rebased ondevelop(no merge commits).Summary
A well-constructed, genuinely end-to-end example of the ADR-2034 D-10 gated script-execution path, and a responsive fix pass: both blocking findings were addressed exactly as recommended and re-verified by execution, with the skill's documented example output corrected in the same commit. The single remaining finding (NaN/
infslipping past numeric validation) is a low-severity input-validation gap consistent with example-grade hardening and is fine to track as a follow-up. No spec-compliance, correctness, security, or test-coverage concerns remain. Approving.