pub struct NbClient { /* private fields */ }Expand description
Client for invoking nb commands.
Implementations§
Source§impl NbClient
impl NbClient
Sourcepub fn new(config: &Config) -> Result<Self>
pub fn new(config: &Config) -> Result<Self>
Creates a new nb client.
Uses the notebook from config if set, otherwise falls back to a
Git-derived notebook name. Does NOT read NB_MCP_NOTEBOOK —
that is an MCP-server-specific env var resolved by the server.
Sourcepub async fn transaction(
&self,
notebook: Option<&str>,
) -> Result<Transaction, NbError>
pub async fn transaction( &self, notebook: Option<&str>, ) -> Result<Transaction, NbError>
Begin a collect-then-commit Transaction for notebook.
Construction performs no durable I/O and does not acquire the gate.
Sourcepub fn gate_timeout(&self) -> Duration
pub fn gate_timeout(&self) -> Duration
Process-shared gate queue timeout configured on this client.
Source§impl NbClient
impl NbClient
Sourcepub async fn show_notebook_status(
&self,
notebook: Option<&str>,
) -> Result<String, NbError>
pub async fn show_notebook_status( &self, notebook: Option<&str>, ) -> Result<String, NbError>
Returns status information about the resolved notebook.
When the only notebook dirt is harmless .index
reconciliation (see git::status_is_index_only), an
explanatory note is appended; the raw nb output is
otherwise returned verbatim. The dirt classification runs
BEFORE any nb subprocess in this call: nb fires
fire-and-forget background checkpoints that could otherwise
commit the very dirt being described between the check and
the read. Root resolution prefers NB_DIR and never shells
out when it is set; if the root cannot be resolved, the
verbatim output is returned.
Sourcepub async fn list_notebooks(&self) -> Result<String, NbError>
pub async fn list_notebooks(&self) -> Result<String, NbError>
Lists available notebooks.
Sourcepub async fn show_notebook_path(
&self,
notebook: Option<&str>,
) -> Result<PathBuf, NbError>
pub async fn show_notebook_path( &self, notebook: Option<&str>, ) -> Result<PathBuf, NbError>
Returns the path for a notebook.
Sourcepub async fn show_note(
&self,
id: &str,
notebook: Option<&str>,
) -> Result<ShowNote, NbError>
pub async fn show_note( &self, id: &str, notebook: Option<&str>, ) -> Result<ShowNote, NbError>
Shows a note as a structured ShowNote (gate-held).
Sourcepub async fn read_note_source_bytes(
&self,
target: NoteTarget,
notebook: Option<&str>,
) -> Result<Vec<u8>, NbError>
pub async fn read_note_source_bytes( &self, target: NoteTarget, notebook: Option<&str>, ) -> Result<Vec<u8>, NbError>
Raw-bytes escape hatch: full file bytes without UTF-8 validation.
This is the only public read that returns Vec<u8>; every other
structured read is text-only and returns NonUtf8 on invalid UTF-8.
Sourcepub async fn show_note_lines(
&self,
target: NoteTarget,
offset: Option<u32>,
limit: Option<u32>,
notebook: Option<&str>,
) -> Result<ShowNoteLines, NbError>
pub async fn show_note_lines( &self, target: NoteTarget, offset: Option<u32>, limit: Option<u32>, notebook: Option<&str>, ) -> Result<ShowNoteLines, NbError>
Enumerate body lines for a contiguous-body note.
Sourcepub async fn search_note_lines(
&self,
target: NoteTarget,
pattern: &str,
notebook: Option<&str>,
) -> Result<SearchNoteLines, NbError>
pub async fn search_note_lines( &self, target: NoteTarget, pattern: &str, notebook: Option<&str>, ) -> Result<SearchNoteLines, NbError>
Search body line texts for a pattern (contiguous body only).
Source§impl NbClient
impl NbClient
Sourcepub async fn add_note(
&self,
title: Option<&str>,
content: &str,
tags: &[String],
folder: Option<&str>,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn add_note( &self, title: Option<&str>, content: &str, tags: &[String], folder: Option<&str>, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Creates a new note (one-shot transaction; nb-mangled filename).
Sourcepub async fn delete_note(
&self,
id: &str,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn delete_note( &self, id: &str, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Deletes a note (one-shot transaction).
Sourcepub async fn delete_folder(
&self,
id: &str,
recursive: bool,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn delete_folder( &self, id: &str, recursive: bool, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Deletes a folder (one-shot transaction).
recursive = false refuses non-empty folders, listing their
contents; recursive = true removes the whole subtree. There
is no force flag: deletion is explicit by call.
Sourcepub async fn move_note(
&self,
id: &str,
destination: &str,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn move_note( &self, id: &str, destination: &str, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Moves or renames a note (one-shot transaction).
Sourcepub async fn add_todo(
&self,
title: &str,
description: Option<&str>,
tasks: &[String],
tags: &[String],
folder: Option<&str>,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn add_todo( &self, title: &str, description: Option<&str>, tasks: &[String], tags: &[String], folder: Option<&str>, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Creates a todo item (one-shot transaction; nb-mangled filename).
Sourcepub async fn mark_task_done(
&self,
id: &str,
task_number: Option<u32>,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn mark_task_done( &self, id: &str, task_number: Option<u32>, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Marks a todo as done (one-shot transaction).
Sourcepub async fn unmark_task_done(
&self,
id: &str,
task_number: Option<u32>,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn unmark_task_done( &self, id: &str, task_number: Option<u32>, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Marks a todo as not done (one-shot transaction).
Sourcepub async fn replace_note_body(
&self,
target: NoteTarget,
new_body: &str,
fingerprint: Fingerprint,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn replace_note_body( &self, target: NoteTarget, new_body: &str, fingerprint: Fingerprint, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Replace contiguous body text (one-shot).
Sourcepub async fn edit_note_substring(
&self,
target: NoteTarget,
pattern: &str,
replacement: &str,
occurrence: Occurrence,
expected_count: u32,
fingerprint: Option<Fingerprint>,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn edit_note_substring( &self, target: NoteTarget, pattern: &str, replacement: &str, occurrence: Occurrence, expected_count: u32, fingerprint: Option<Fingerprint>, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Substring edit on contiguous body (one-shot).
Sourcepub async fn edit_note_lines(
&self,
target: NoteTarget,
edits: Vec<LineEdit>,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn edit_note_lines( &self, target: NoteTarget, edits: Vec<LineEdit>, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Line-oriented body edit batch (one-shot).
Sourcepub async fn retitle_note(
&self,
target: NoteTarget,
title: &str,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn retitle_note( &self, target: NoteTarget, title: &str, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Retitle a note without changing path (one-shot).
Add/remove tags (one-shot).
Sourcepub async fn list_tasks(
&self,
folder: Option<&str>,
status: Option<TaskStatus>,
recursive: bool,
notebook: Option<&str>,
) -> Result<String, NbError>
pub async fn list_tasks( &self, folder: Option<&str>, status: Option<TaskStatus>, recursive: bool, notebook: Option<&str>, ) -> Result<String, NbError>
Lists checklist items within todos.
Invokes nb todos tasks per scope. The method enumerates
the checklist items within todos (and recursively into
subfolders when recursive = true), filtered by
status if provided. An empty scope returns the empty
signal (0 open tasks.) rather than an error. A future
list_todos method for the todo container listing
(invoking nb todos) is tracked at
nb-api:todos/api/5 (deferred to 0.5.0).
Sourcepub async fn add_bookmark(
&self,
url: &str,
title: Option<&str>,
tags: &[String],
comment: Option<&str>,
folder: Option<&str>,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn add_bookmark( &self, url: &str, title: Option<&str>, tags: &[String], comment: Option<&str>, folder: Option<&str>, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Creates a bookmark (one-shot transaction; nb-mangled filename).
Sourcepub async fn list_folders(
&self,
parent: Option<&str>,
notebook: Option<&str>,
) -> Result<String, NbError>
pub async fn list_folders( &self, parent: Option<&str>, notebook: Option<&str>, ) -> Result<String, NbError>
Lists folders in a notebook.
Sourcepub async fn add_folder(
&self,
path: &str,
notebook: Option<&str>,
) -> Result<CommitOutcome, NbError>
pub async fn add_folder( &self, path: &str, notebook: Option<&str>, ) -> Result<CommitOutcome, NbError>
Creates a folder (one-shot transaction).
Sourcepub async fn import_note(
&self,
source: &str,
folder: Option<&str>,
filename: Option<&str>,
convert: bool,
notebook: Option<&str>,
) -> Result<String, NbError>
pub async fn import_note( &self, source: &str, folder: Option<&str>, filename: Option<&str>, convert: bool, notebook: Option<&str>, ) -> Result<String, NbError>
Imports a file or URL into the notebook as a note.
One-shot only under the process-shared notebook gate. Not a
Transaction plan op in 0.3.0.
NOTE (0.4.3, evaluated): nb import accepts no --wait
flag — an unknown flag would be misparsed as an import
path — and a standalone nb git checkpoint --wait cannot
join the import’s already-backgrounded checkpoint job, so
there is no --wait containment for the import race window.
Containment waits on 0.5.0 (native import with proper
locking); meanwhile the commit guard absorbs index-only
droppings and note-content leftovers still refuse loudly.