Skip to content

moped CLI: open new files, and fix --wait on current macOS - #104

Merged
RobertoMachorro merged 3 commits into
masterfrom
claude/moped-nonexistent-file-084f7b
Oct 4, 2026
Merged

RobertoMachorro merged 3 commits into
masterfrom
claude/moped-nonexistent-file-084f7b

Conversation

@RobertoMachorro

@RobertoMachorro RobertoMachorro commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

Two moped CLI changes. Both rely on extended attributes on the opened files, the only channel the script and the sandboxed app both have.

moped <file> on a file that doesn't exist yet

Previously this stopped with "The file … does not exist." Now the script creates the file empty, exclusively (noclobber, so an existing file is never claimed), and opens it, and ⌘S saves straight to it. The sandboxed app can't create the file itself, because it may only write where it was handed a file. The script tags the new file with net.machorro.roberto.Moped.placeholder. If that file is still empty when its window closes, or when Moped quits, Moped deletes it, so changing your mind leaves nothing behind. Files that already existed are never deleted.

moped --wait failing with "Operation not permitted"

--wait kept its session file in Moped's sandbox container. Current macOS no longer lets other apps create files there, so touch failed under set -e and git commit aborted with "there was a problem with the editor".

--wait now tags each file with its own net.machorro.roberto.Moped.wait.<uuid>, so concurrent waits on one file stay independent:

  • The script sets the tag to pending before calling open.
  • Moped changes it to open when the window shows the file. For a file that's already open, the document's file watcher (now also listening for .attrib) sees the new tag. Moped removes the tag when the window closes, Moped quits, or the document moves away on Save As.
  • The script polls until every tag is gone. A tag still pending after about 10 s means Moped refused the file (binary, too large), so the script stops waiting for it.

This removes the container session file, the osascript distributed notification, the 1 s startup sleep and the repost. Because the tag is in place before Moped launches, the cold-launch race is gone. WaitManager.swift and the interim PlaceholderFiles.swift are replaced by CLIFileTags.swift. FileWatcher doesn't watch .attrib, so tag changes don't trigger the "changed on disk" prompt.

Behavior changes:

  • --wait can't wait for a file you can't write to. It prints moped: cannot wait for … and skips that file.
  • --wait on a path whose folder doesn't exist now returns at once with open's error, instead of after about 10 s.

Test plan

  • swiftlint --strict, swift test --package-path MopedEditor (229 tests), ./scripts/check_localized_strings.sh
  • Real Debug build, driven through a copy of the script that uses open -a to target that build:
    • New file closed untouched: deleted. New file typed into and closed: kept with its text. New file with Moped quit: deleted. ⌘S on a new file: saves in place, no Save panel. Existing file: untouched.
    • --wait, cold launch: tag went pending then open, returned on close.
    • --wait on an already-open file plus a new file: waits for both.
    • --wait on an already-open file while Moped is frontmost and the window is already key: still waits.
    • Two --wait on one file: terminating one leaves the other waiting.
    • --wait new.txt, then Save As: returns, and the empty new.txt is removed.
    • --wait on a binary file: released after about 12 s with no tag left.
    • --wait and quitting Moped: returned.
    • SIGTERM: tags cleaned up.
    • git commit with GIT_EDITOR='moped --wait': commit created with the typed message.
  • Not tested: a real Ctrl-C (SIGINT) in an interactive terminal. SIGTERM runs the same trap, but a background job in the test shell ignores SIGINT.
  • Not tested: an installed Release build, i.e. /usr/local/bin/moped resolving via open -b. The new cases are in manual-checklist.md.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings October 4, 2026 20:34
@RobertoMachorro RobertoMachorro self-assigned this Oct 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Save As handling and shared wait attributes can leave callers hanging or release independent sessions prematurely.

Review effort: Balanced
Findings: 1 High severity · 3 Medium severity

Open (4)
What changed in this PR

Updates the moped CLI to create new files and replace sandbox-dependent wait sessions with extended-attribute coordination.

Changes:

  • Creates and conditionally removes placeholder files.
  • Tracks --wait state through file attributes.
  • Updates documentation and manual verification steps.
File Description
Moped/​WaitManager.swift Removes the previous session manager.
Moped/​Resources/​moped Implements placeholder creation and attribute-based waiting.
Moped/​MopedApp.swift Marks displayed CLI documents as open.
Moped/​CLIFileTags.swift Manages wait and placeholder attributes.
Moped/​AppDelegate.swift Starts the new attribute manager.
Moped.xcodeproj/​project.pbxproj Replaces the source file in the target.
manual-checklist.md Adds CLI verification scenarios.
DOCUMENTATION.md Documents new-file and wait behavior.
CHANGELOG.md Records both user-facing changes.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Moped/Resources/moped Resolved
Comment thread Moped/CLIFileTags.swift Resolved
Comment thread Moped/MopedApp.swift Resolved
Comment thread Moped/Resources/moped Resolved
- Create placeholder files with noclobber, so a file appearing between
  the existence check and creation is never tagged and later deleted.
- Detect `moped --wait` on an already-open file through the document's
  file watcher (now also listening for .attrib), instead of relying on a
  key-window change that never comes when the window is already key.
- Release wait and placeholder tags on the URL a document leaves on
  Save As.
- Give each `moped --wait` its own tag (wait.<uuid>), so concurrent waits
  on one file no longer release each other.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RobertoMachorro
RobertoMachorro merged commit 48a8c50 into master Oct 4, 2026
1 check passed
@RobertoMachorro
RobertoMachorro deleted the claude/moped-nonexistent-file-084f7b branch October 4, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants