Repository navigation
fix: ISSUE-004 front matter init for new .md, txt stays plain (#5) - #12
Conversation
Reviewer's GuideData structuresUpdate document persistence so Markdown files serialize front matter when present, plain-text targets write only the body, and extension detection is case-insensitive.
APIMake document-opening methods return errors and add Markdown-path detection so callers can handle failed opens and initialize new Markdown documents.
Change navigation methods to return command outcomes and reject attempts to replace modified buffers.
Add deferred undo snapshots and commit them only when editing operations mutate the buffer.
Uses of the APICentralize command results and apply them consistently to user-visible status and quit state.
Route navigation keypresses through the new outcome handling and commit edits performed by the visual-edit path.
Refactor command dispatch to guard buffer replacement, report failures, and separate safe database, directory, and external-command operations.
ImplementationExtract shared database-note loading and sorted Markdown/text file collection helpers.
Open the initial document through fallible loaders and surface loading errors instead of silently swallowing them.
Save explicit targets before database persistence, initialize front matter for Markdown targets, and preserve existing-path save behavior.
ConfigurationAdd repository-local takt ignore configuration.
DocumentationDocument per-document undo/redo behavior and explain that commands which replace a modified buffer are rejected.
TestsTest deferred undo history, edit-session grouping, redo preservation, and the history limit.
Add coverage for command outcomes, unsaved-buffer guards, safe source switching, and Markdown-versus-plain-text save behavior.
Verify that documents with front matter save as plain text when the destination is a text file.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Hey - I've found 9 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/doc.rs" line_range="81" />
<code_context>
+ let content = if markdown {
+ self.to_string_content()
+ } else {
+ self.body.clone()
+ };
+ self.write(path_ref, content)
</code_context>
<issue_to_address>
**Saving text files deletes their headers**
When a `.txt` file begins with a block that `parse_markdown_or_plain` recognizes as front matter and is saved, `Document::load_from_file` parses the block regardless of extension, removing it from `body`, and `save_to` writes only `body` for non-Markdown paths. The saved text file loses its original header.
Make loading extension-aware so non-Markdown files remain whole plain-text bodies.
</issue_to_address>
### Comment 2
<location path="src/app.rs" line_range="1054" />
<code_context>
- if !crate::config::validate_path(&path) {
- self.status_message = Some(format!("Invalid path: {}", p));
- } else {
- self.source = Source::Db(path.clone());
- self.refresh_notes();
- if !self.notes.is_empty() {
</code_context>
<issue_to_address>
**Failed switches leave sources inconsistent**
When the new source list loads but opening its first file or note fails, `switch_to_db` and `switch_to_dir` replace the active source and list before opening the first item succeeds. The open returns an error while the old document and buffer remain, so the failed switch still changes state and leaves them paired with the new source.
Stage the new source, list, and opened document, and update the active app state only after opening succeeds.
Also at `src/app.rs:1091-1100`.
</issue_to_address>
### Comment 3
<location path="src/app.rs" line_range="373" />
<code_context>
- let _ = self.doc.save_to(&path_buf);
+ if let Some(path) = &explicit_target {
+ // 明示された `.md` 保存先は新規作成として front matter を補完する。
+ if is_markdown(path) {
+ self.doc.ensure_front_matter();
}
</code_context>
<issue_to_address>
**Overwriting plain Markdown adds metadata**
When an existing front-matter-free `.md` file is saved to via an explicit target, `save_current_file` calls `ensure_front_matter` for every explicit Markdown target, then writes the metadata into the existing file. The file no longer remains plain text.
Only call `ensure_front_matter` for an explicit Markdown target that is being newly created.
</issue_to_address>
### Comment 4
<location path="src/app.rs" line_range="389" />
<code_context>
- self.doc.ensure_front_matter();
+ let now = chrono::Utc::now().timestamp_millis();
+ let name = format!("{}.md", now);
+ self.doc.save_to(self.root_dir.join(name))?;
}
- self.doc.save_to(&path_buf)?;
</code_context>
<issue_to_address>
**Fallback Markdown saves lack metadata**
When the initial listed file fails to open and the user saves the pathless document, `save_current_file` writes the generated `.md` path without calling `ensure_front_matter`, so the saved note lacks its ID, title, and timestamp.
Call `ensure_front_matter` before saving the generated Markdown path.
Also at `src/app.rs:390`.
</issue_to_address>
### Comment 5
<location path="src/app.rs" line_range="196-197" />
<code_context>
+ } else {
+ self.open_file_at_index(0)
+ };
+ if let Err(e) = opened {
+ self.status_message = Some(format!("Error: {e}"));
}
}
</code_context>
<issue_to_address>
**Startup loses failed filename**
When the initially listed file disappears or becomes unreadable between list collection and opening, `open_file_at_index` returns an error before assigning the selected path to `doc`, and `open_initial` only records the error; the app remains usable with `Document::new_empty()` and no path, so a later save creates a timestamp-named file instead of retrying the selected file.
Retain the failed target path for retry, or return the open error from initialization instead of leaving a pathless editable document.
</issue_to_address>
### Comment 6
<location path="src/app.rs" line_range="346" />
<code_context>
- let ext = full_path.extension().and_then(|e| e.to_str()).unwrap_or("");
- if ext == "md" {
+ if is_markdown(&full_path) {
doc.ensure_front_matter();
}
self.buffer = TextBuffer::new();
</code_context>
<issue_to_address>
**New notes can share IDs**
When two new `.md` files are opened in the same millisecond, `ensure_front_matter()` assigns the generated ID to each new Markdown file; if two files are opened in the same millisecond, both IDs are identical, so importing them into the ID-keyed notes table causes one note to overwrite the other.
Generate IDs with an independent random component or check for collisions before assigning them.
</issue_to_address>
### Comment 7
<location path="src/buffer.rs" line_range="388" />
<code_context>
// --- Insert & editing operations ---
pub fn insert_char(&mut self, c: char) {
+ self.commit_edit();
let line = &mut self.lines[self.cursor.row];
let mut chars: Vec<char> = line.chars().collect();
</code_context>
<issue_to_address>
**Deleting an empty line clears redo**
When the buffer is a single empty line and redo history exists, `delete_line` commits the pending snapshot before checking whether deleting the sole empty line changes any text, so `dd` on that line clears the redo stack despite being a no-op.
Only commit the pending snapshot when `delete_line` actually changes the buffer.
</issue_to_address>
### Comment 8
<location path="src/app.rs" line_range="345-346" />
<code_context>
doc.path = Some(full_path.clone());
- let ext = full_path.extension().and_then(|e| e.to_str()).unwrap_or("");
- if ext == "md" {
+ if is_markdown(&full_path) {
doc.ensure_front_matter();
}
self.buffer = TextBuffer::new();
</code_context>
<issue_to_address>
**New `.txt` files lack metadata**
The issue asks for appropriate metadata initialization for new files, and specifically raises newly created `.txt` files. This branch initializes front matter only when the path is Markdown, leaving new `.txt` files without metadata or an opt-in path.
</issue_to_address>
### Comment 9
<location path="src/app.rs" line_range="1418" />
<code_context>
+ Source::Dir(_) => unreachable!("db app"),
+ };
+
+ app.execute_command(&format!("db {}", db_path.display()));
+
+ assert!(status(&app).starts_with("db -> "), "{}", status(&app));
</code_context>
<issue_to_address>
**Database switch test uses preloaded state**
When the test invokes `:db` with the database already loaded by `App::new`, `test_db_switch_loads_notes` switches to the same database that `app_in_db` already loaded, so a `switch_to_db` implementation that leaves `notes` and `buffer` untouched still passes the assertions at lines 1421–1422.
Switch to a second database with distinct seeded notes, or clear/change the current notes and buffer before switching, then assert the target database’s distinct contents are loaded.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 9 findings to address first, and saving a document with front matter to a .txt path now writes only the body, so an existing target can lose its metadata when overwritten. Reverting the change would not restore content already written to disk.
Blocking findings: src/doc.rs:81, src/app.rs:1054, src/app.rs:373, src/app.rs:389, src/app.rs:197, and 4 more
| let content = if markdown { | ||
| self.to_string_content() | ||
| } else { | ||
| self.body.clone() |
There was a problem hiding this comment.
🟡 Medium · Saving text files deletes their headers
When a .txt file begins with a block that parse_markdown_or_plain recognizes as front matter and is saved, Document::load_from_file parses the block regardless of extension, removing it from body, and save_to writes only body for non-Markdown paths. The saved text file loses its original header.
Make loading extension-aware so non-Markdown files remain whole plain-text bodies.
Prompt for AI agents
In `src/doc.rs` at line 81:
**Saving text files deletes their headers**
When a `.txt` file begins with a block that `parse_markdown_or_plain` recognizes as front matter and is saved, `Document::load_from_file` parses the block regardless of extension, removing it from `body`, and `save_to` writes only `body` for non-Markdown paths. The saved text file loses its original header.
Make loading extension-aware so non-Markdown files remain whole plain-text bodies.| _ => { | ||
| self.status_message = Some(format!("Unknown command: {}", cmd)); | ||
| }; | ||
| self.source = Source::Db(path.clone()); |
There was a problem hiding this comment.
🟡 Medium · Failed switches leave sources inconsistent
When the new source list loads but opening its first file or note fails, switch_to_db and switch_to_dir replace the active source and list before opening the first item succeeds. The open returns an error while the old document and buffer remain, so the failed switch still changes state and leaves them paired with the new source.
Stage the new source, list, and opened document, and update the active app state only after opening succeeds.
Also at src/app.rs:1091-1100.
Prompt for AI agents
In `src/app.rs` at line 1054:
**Failed switches leave sources inconsistent**
When the new source list loads but opening its first file or note fails, `switch_to_db` and `switch_to_dir` replace the active source and list before opening the first item succeeds. The open returns an error while the old document and buffer remain, so the failed switch still changes state and leaves them paired with the new source.
Stage the new source, list, and opened document, and update the active app state only after opening succeeds.
Also at `src/app.rs:1091-1100`.| let _ = self.doc.save_to(&path_buf); | ||
| if let Some(path) = &explicit_target { | ||
| // 明示された `.md` 保存先は新規作成として front matter を補完する。 | ||
| if is_markdown(path) { |
There was a problem hiding this comment.
🟡 Medium · Overwriting plain Markdown adds metadata
When an existing front-matter-free .md file is saved to via an explicit target, save_current_file calls ensure_front_matter for every explicit Markdown target, then writes the metadata into the existing file. The file no longer remains plain text.
Only call ensure_front_matter for an explicit Markdown target that is being newly created.
Prompt for AI agents
In `src/app.rs` at line 373:
**Overwriting plain Markdown adds metadata**
When an existing front-matter-free `.md` file is saved to via an explicit target, `save_current_file` calls `ensure_front_matter` for every explicit Markdown target, then writes the metadata into the existing file. The file no longer remains plain text.
Only call `ensure_front_matter` for an explicit Markdown target that is being newly created.| self.doc.ensure_front_matter(); | ||
| let now = chrono::Utc::now().timestamp_millis(); | ||
| let name = format!("{}.md", now); | ||
| self.doc.save_to(self.root_dir.join(name))?; |
There was a problem hiding this comment.
🟡 Medium · Fallback Markdown saves lack metadata
When the initial listed file fails to open and the user saves the pathless document, save_current_file writes the generated .md path without calling ensure_front_matter, so the saved note lacks its ID, title, and timestamp.
Call ensure_front_matter before saving the generated Markdown path.
Also at src/app.rs:390.
Prompt for AI agents
In `src/app.rs` at line 389:
**Fallback Markdown saves lack metadata**
When the initial listed file fails to open and the user saves the pathless document, `save_current_file` writes the generated `.md` path without calling `ensure_front_matter`, so the saved note lacks its ID, title, and timestamp.
Call `ensure_front_matter` before saving the generated Markdown path.
Also at `src/app.rs:390`.| if let Err(e) = opened { | ||
| self.status_message = Some(format!("Error: {e}")); |
There was a problem hiding this comment.
🟡 Medium · Startup loses failed filename
When the initially listed file disappears or becomes unreadable between list collection and opening, open_file_at_index returns an error before assigning the selected path to doc, and open_initial only records the error; the app remains usable with Document::new_empty() and no path, so a later save creates a timestamp-named file instead of retrying the selected file.
Retain the failed target path for retry, or return the open error from initialization instead of leaving a pathless editable document.
Prompt for AI agents
In `src/app.rs` at lines 196-197:
**Startup loses failed filename**
When the initially listed file disappears or becomes unreadable between list collection and opening, `open_file_at_index` returns an error before assigning the selected path to `doc`, and `open_initial` only records the error; the app remains usable with `Document::new_empty()` and no path, so a later save creates a timestamp-named file instead of retrying the selected file.
Retain the failed target path for retry, or return the open error from initialization instead of leaving a pathless editable document.| let ext = full_path.extension().and_then(|e| e.to_str()).unwrap_or(""); | ||
| if ext == "md" { | ||
| if is_markdown(&full_path) { | ||
| doc.ensure_front_matter(); |
There was a problem hiding this comment.
🟡 Medium · New notes can share IDs
When two new .md files are opened in the same millisecond, ensure_front_matter() assigns the generated ID to each new Markdown file; if two files are opened in the same millisecond, both IDs are identical, so importing them into the ID-keyed notes table causes one note to overwrite the other.
Generate IDs with an independent random component or check for collisions before assigning them.
Prompt for AI agents
In `src/app.rs` at line 346:
**New notes can share IDs**
When two new `.md` files are opened in the same millisecond, `ensure_front_matter()` assigns the generated ID to each new Markdown file; if two files are opened in the same millisecond, both IDs are identical, so importing them into the ID-keyed notes table causes one note to overwrite the other.
Generate IDs with an independent random component or check for collisions before assigning them.| } | ||
|
|
||
| pub fn delete_line(&mut self) -> String { | ||
| self.commit_edit(); |
There was a problem hiding this comment.
🟡 Medium · Deleting an empty line clears redo
When the buffer is a single empty line and redo history exists, delete_line commits the pending snapshot before checking whether deleting the sole empty line changes any text, so dd on that line clears the redo stack despite being a no-op.
Only commit the pending snapshot when delete_line actually changes the buffer.
Prompt for AI agents
In `src/buffer.rs` at line 388:
**Deleting an empty line clears redo**
When the buffer is a single empty line and redo history exists, `delete_line` commits the pending snapshot before checking whether deleting the sole empty line changes any text, so `dd` on that line clears the redo stack despite being a no-op.
Only commit the pending snapshot when `delete_line` actually changes the buffer.| Source::Dir(_) => unreachable!("db app"), | ||
| }; | ||
|
|
||
| app.execute_command(&format!("db {}", db_path.display())); |
There was a problem hiding this comment.
🟡 Medium · Database switch test uses preloaded state
When the test invokes :db with the database already loaded by App::new, test_db_switch_loads_notes switches to the same database that app_in_db already loaded, so a switch_to_db implementation that leaves notes and buffer untouched still passes the assertions at lines 1421–1422.
Switch to a second database with distinct seeded notes, or clear/change the current notes and buffer before switching, then assert the target database’s distinct contents are loaded.
Prompt for AI agents
In `src/app.rs` at line 1418:
**Database switch test uses preloaded state**
When the test invokes `:db` with the database already loaded by `App::new`, `test_db_switch_loads_notes` switches to the same database that `app_in_db` already loaded, so a `switch_to_db` implementation that leaves `notes` and `buffer` untouched still passes the assertions at lines 1421–1422.
Switch to a second database with distinct seeded notes, or clear/change the current notes and buffer before switching, then assert the target database’s distinct contents are loaded.…estore reload semantics)
| if is_markdown(&full_path) { | ||
| doc.ensure_front_matter(); | ||
| } |
There was a problem hiding this comment.
🟠 High · Initialize text-file metadata
The issue asks for appropriate metadata initialization for all new files. This path initializes front matter only for Markdown, leaving newly created .txt files without metadata.
Prompt for AI agents
In `src/app.rs` at lines 345-347:
**Initialize text-file metadata**
The issue asks for appropriate metadata initialization for all new files. This path initializes front matter only for Markdown, leaving newly created `.txt` files without metadata.From #5:
Ensure all new files get appropriate metadata initialization.
ISSUE-004: Missing Front Matter on New Text Files (#5)
takt simple-mini(ernie free)で実装 → coding-review 7/20 まで進行した時点でセッション中断。WIP を回収して PR 化(CI で検証)。
内容
:e <new .md>で新規作成時に front matter を初期化(従来は未初期化だった)Document::new_empty()の failed-first-open 経路など)仕様確認(design decision)
.txtは素テキストのまま(front matter を自動付与しない)— issue ISSUE-004: Missing Front Matter on New Text Files #5 の design decision コメントどおり.mdのみ front matter 初期化補足
winapifamily.h無し)。CI の判定を正とする.takt/runs/のログCloses #5
Summary by Sourcery
Preserve plain-text semantics while initializing front matter for new Markdown documents and harden document commands and editing history.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests:
Chores: