[OMEGA-331] Add delete-file skill with existence check and error handling - #289
[OMEGA-331] Add delete-file skill with existence check and error handling#289Aryam-21 wants to merge 3 commits into
Conversation
|
Nice addition — an explicit not-found branch instead of a silent failure is the right instinct. 1. The reason was that a static 2. The bare (= (exists-file $path)
(empty-to-bool (translatePredicate (exists_file $path))))That wrapper exists because 3. Minor: the repo now runs unit tests in CI ( Happy to help with the |
3bd2e3f to
56e79a5
Compare
|
That is a thorough rework — the directory case and the post- 1. >>> balance_parentheses('delete-file /tmp/out.txt')
'((Error UNKNOWN_SKILL_CALL "delete-file /tmp/out.txt"))'
>>> balance_parentheses('delete-file /tmp/out.txt\nsend done')
'((Error UNKNOWN_SKILL_CALL "delete-file /tmp/out.txt") (send "done"))'
>>> balance_parentheses('read-file /tmp/out.txt') # registered, for contrast
'((read-file "/tmp/out.txt"))'So every (Pre-#301 the same omission was milder but still wrong: 2. 3. Cosmetic: One thing that is my fault rather than yours: I suggested the |
9bfaece to
b8a956c
Compare
timur-ashkenov
left a comment
There was a problem hiding this comment.
@Aryam-21
Please rebase this branch onto the current main. It has diverged, and the changes overlap in src/helper.py and Autotests/run_mandatory, so the PR does not apply cleanly as-is.
|
|
||
| def delete_file(path): | ||
| path = str(path) | ||
| if not os.path.exists(path): |
There was a problem hiding this comment.
os.path.exists() returns False for dangling symlinks, so delete-file reports a missing file and leaves the symlink behind. I think its better to use os.path.lexists() here.
2282449 to
697a1b1
Compare
|
Checked this for OMEGA-331.
One gap for later: the Verdict: PASS |
697a1b1 to
ba93c91
Compare
|
Huge thanks for all the reviews! @TossSky, the edge-case and policy testing was seriously impressive thank you. I've noted the two missing tests and will pick them up in a follow-up PR. Happy to see this one land! |
|
Branch updated with main. All review feedback has been addressed, and this already has an approving review + a PASS from @TossSky's testing. Just needs the pending workflow run approved to get CI green — could a maintainer approve it when you get a chance? 🙏 |
Summary
Adds a
delete-fileskill that safely removes a file, matching theverified-result contract established by
write-file/append-file/write-file-b64in #243: no static success atom, no silent failures —every result is built from a read-back of the filesystem after the
operation.
Implementation
src/fileio.py— newdelete_file(path):caller — failures return an explicit string, matching
write_file'scontract
gone (guards against a race where something recreates it mid-call)
DELETE-VERIFIED file=<path> existed=trueon success, orDELETE-FAILED file=<path>: <reason>on failure (not found / is adirectory / OS error / still exists after removal)
src/skills.metta:delete-filenow calls(py-call (fileio.delete_file $path)),consistent with how
write-file/append-fileroute throughfileio.pyrather than raw Prolog predicatesgetStaticSkillsto reflect the newDELETE-VERIFIED/DELETE-FAILEDcontractAutotests/unit/test_fileio_verified_deletes.py— new unit tests,not a resolved/normalized variant, so the agent can match it back to
its request)
Review history
An earlier version used a raw
(translatePredicate (exists_file ...))guard with a static
DELETE-FILE-SUCCESSatom. Per review feedback,this was reworked to:
fileio.pywith read-back verification instead of astatic success atom (the agent otherwise can't distinguish an actual
deletion from a claimed one)
exists_fileguard, which yieldsEmptyrather thanFalsewhen used directly as anifcondition — a pitfall alreadyhit once during the [OMEGA-273][FIX] skills: file-write results are read back from disk (add write-file-b64) #243 rebase
This branch was also rebased/merged against
mainto pick up the #243file-I/O rework that landed after this branch was created.
Testing
python -m pytest Autotests/unit/test_fileio_verified_deletes.py -v— 4/4 passing
write-filecreated a file,delete-fileremoved it, confirmed viaan independent
lscheck outside the agentDELETE-FAILED ... file does not exist) via a real MeTTa-level call through the fullrun.mettabootstrap chain