- opencode--time-ago now returns nil for missing timestamps
- add opencode--format-time-ago helper for safe formatting
- handle :null (JSON null) in session summary fields
- check for nil directory before file-exists-p in Branch column
- filter out projects with nil worktree
fix nil and :null handling in API responses #2
avph/opencode.el:fix-nil-handling into main - opencode--time-ago now returns nil for missing timestamps - add opencode--format-time-ago helper for safe formatting - handle :null (JSON null) in session summary fields - check for nil directory before file-exists-p in Branch column - filter out projects with nil worktree
Looks good but is it needed to handle these cases? AFAIK in emacs default-directory will always be set. for the API responses I haven't run into these cases, and looking at packages/sdk/js/src/gen/types.gen.ts worktree in the project API response, and directory in the session API response are guaranteed to be present. summary is optional in the session info, but if it's present then files, deletions, and additions are guaranteed to be present, and if it's not present the existing (null .files) check will handle it
Hi thanks for reviewing. I've used opencode for a long time and I think there is legacy data in the sessions as well as edge cases.
-
Older sessions (pre-0.13.x) don't have a directory field at all. From my /session response:
((id . "ses_7a07d100fffejXf8epJhA47flz") (version . "0.3.58")
(title . "Adding mbox size handling across mailbox implementations")
(time (created . 1753949073392) (updated . 1753953708805)))
No directory field - calling (file-exists-p nil) throws wrong-type-argument stringp nil. -
Some sessions have summary present but with JSON null values that json-parse-buffer returns as :null:
(summary (additions . :null) (deletions . :null) (files . 1078))
Since :null is truthy in Emacs Lisp, (or :null 0) returns :null, not 0, causing (format "%d" :null) to fail. -
Some sessions/projects lack time.updated, causing (/ nil 1000) to fail in opencode--time-ago.
Ah, yea I just started using opencode about a month ago, but I also use it in a temporary sandbox as described in the security section of the readme, so I don't store old session history.
I just factored out a opencode--json-falsy utility function cause I'm pretty OCD about repeating code, and we do the null or :null checks twice already and I assume might need to add in other spots later.
No due date set.
No dependencies set.
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?