The interface between coding agents and codebases is broken.

context-engine.app · 2026-08-04 · by Long Nguyen ·generic
Coding agents are given files and text tools, but code is a graph of symbols, contracts, dependencies, and usages. We need to fix the interface.

The interface between coding agents and codebases is broken.

Imagine being given a whiteboard and a large stack of paper with a project's source code printed on it, then being asked to implement a feature or fix a bug. You know little about the project. You have worked with some of its dependencies before, but the project uses newer versions. I doubt you would be very productive. Yet this is exactly how we ask AI coding agents to work.

You can add an index listing every word used on every page, but it will not make your job much easier; it will mostly make the stack taller. You can add more stacks containing the documentation for the project's dependencies, but there is no guarantee that it is complete or current. None of this will make you much more productive, because the problem is not the amount of paper. The problem is that paper is the wrong format for working with a codebase.

We fill an agent's context with raw text from files. Files are the storage format, but the codebase an agent needs to understand is a directed graph of symbols. Those symbols have structure, identities, and boundaries that are not defined by arbitrary line ranges. They have relationships to other symbols and contracts that are often defined in other files. All this information is encoded in the text, but only implicitly, so the agent has to reconstruct it. Dependency symbols are not external to this graph. They are an integral part of the codebase the agent must reason about, and the contracts of the exact versions in use matter.

Better tools cannot fix a broken interface. As long as they still operate on raw text, the problem is unfixable. We have to fix the interface itself.

Luckily, the legacy coding era left us deterministic tools built to work with code: language servers and Tree-sitter. Language servers resolve symbol identities, definitions, references, types, and APIs. Tree-sitter recovers the syntax and structure of code across many languages.

But these tools were designed as backends for IDE features used by humans. Simply exposing their native operations and output to an agent does not fix the interface. It can give the agent more tools to choose from, more output to process, and more decisions unrelated to the actual task. We should keep the underlying machinery, but redesign the interface above it for a different user: the coding agent. That interface should be organized around coding workflows, not around the tools that implement them.

That is why I built Context Engine. It was built from day one as a language-agnostic interface between agents and codebases, and it avoids language-specific heuristics almost completely. The only exceptions are JS/TS callbacks passed as function arguments and React hooks — hello ;)

It allows agents to navigate the semantic graph of even a huge codebase and selectively fetch the parts of symbols they need for the task, keeping the redundant noise out of context. It makes symbol contracts visible instead of forcing agents to spend their reasoning budget inferring them. Here are the workflows we have built Context Engine around.

01

Codebase Exploration

Filling an agent's context with the entire contents of a file when it only needs the API defined there is sheer barbarism. This is not just about wasting tokens. It is context pollution, and context pollution degrades reasoning performance.

Why include module-level and symbol documentation when it is unrelated to the question the agent is answering? Why make the agent read fat function bodies full of implementation details when it only needs a signature and annotations/decorators?

Context Engine's `outline`tool is built for exactly this workflow. Given a file, it returns data structures with their fields, interfaces, signatures, and the symbol hierarchy, while providing an interface for selectively fetching any hidden detail the agent needs. It strips away redundant information and provides a complete, pollution-free view of the file's structural API. Any hidden detail the agent needs remains selectively accessible through the returned handles.

Handles are another part of the interface. They identify symbols structurally rather than by their current file positions. Add several lines of comments above a symbol and its line number changes, but the symbol itself does not. Its handle remains valid.

An agent can pass that handle to `extract` to fetch selected parts of the symbol or to `show_usage` to find its usages without calling `outline`again. Handles survive body edits, comment changes, reformatting, line shifts, and moves that preserve the symbol hierarchy. A handle is invalidated only when the symbol's signature or hierarchy changes.

This means agents can continue using `outline` results throughout an editing session instead of rebuilding their view of the file after every change.

Finally, agents need an easy-to-use way to explore dependency APIs. Documentation is not the source of truth: it can be incomplete or outdated. The source code of the version your project actually uses is.

Instead of guessing an API or relying on training data, an agent can use `jump` on any symbol visible in the code and choose the view it needs — either the full implementation or the API only. Whether the symbol is defined in another package of a huge monorepo or in an external dependency, `jump` follows the codebase graph and returns exactly the requested information.

It does not matter whether the model was trained on the exact dependency version pinned by your project. The answer is one tool call away in the dependency's source code.

Real workflowHere is the animation of the exploration workflow on a real Tokio codebase (Rust):

...610 /// Attempts to send a value to all active [`Receiver`] handles, returning611 /// it back if it could not be sent.612 ///613 /// A successful send occurs when there is at least one active [`Receiver`]614 /// handle. An unsuccessful send would be one where all associated615 /// [`Receiver`] handles have already been dropped.616 ///617 /// # Return618 ///619 /// On success, the number of subscribed [`Receiver`] handles is returned.620 /// This does not mean that this number of receivers will see the message as621 /// a receiver may drop or lag (see lagging) before receiving622 /// the message.623 ///624 /// # Note625 ///626 /// A return value of `Ok` does not mean that the sent value will be627 /// observed by all or any of the active [`Receiver`] handles. [`Receiver`]628 /// handles may be dropped before receiving the sent message.629 ///630 /// A return value of `Err` does not mean that future calls to `send`631 /// will fail. New [`Receiver`] handles may be created by calling632 /// [`subscribe`].633 ///634 /// [`Receiver`]: crate::sync::broadcast::Receiver635 /// [`subscribe`]: crate::sync::broadcast::Sender::subscribe636 ///637 /// # Examples638 ///639 /// ```640 /// use tokio::sync::broadcast;641 ///642 /// # #[tokio::main(flavor = "current_thread")]643 /// # async fn main() {644 /// let (tx, mut rx1) = broadcast::channel(16);645 /// let mut rx2 = tx.subscribe();646 ///647 /// tokio::spawn(async move {648 /// assert_eq!(rx1.recv().await.unwrap(), 10);649 /// assert_eq!(rx1.recv().await.unwrap(), 20);650 /// });651 ///652 /// tokio::spawn(async move {653 /// assert_eq!(rx2.recv().await.unwrap(), 10);654 /// assert_eq!(rx2.recv().await.unwrap(), 20);655 /// });656 ///657 /// tx.send(10).unwrap();658 /// tx.send(20).unwrap();659 /// # }660 /// ```661 pub fn send(&self, value: T) -> Result<usize, SendError<T>> {662 let mut tail = self.shared.tail.lock();663664 if tail.rx_cnt == 0 {665 return Err(SendError(value));666 }667668 // Position to write into669 let pos = tail.pos;670 let rem = tail.rx_cnt;671 let idx = (pos & self.shared.mask as u64) as usize;672673 // Update the tail position674 tail.pos = tail.pos.wrapping_add(1);675676 // Get the slot677 let mut slot = self.shared.buffer[idx].lock();678679 // Track the position680 slot.pos = pos;681682 // Set remaining receivers683 slot.rem.with_mut(|v| *v = rem);684685 // Write the value686 slot.val = Some(value);687688 // Release the slot lock before notifying the receivers.689 drop(slot);690691 // Notify and release the mutex. This must happen after the slot lock is692 // released, otherwise the writer lock bit could be cleared while another693 // thread is in the critical section.694 self.shared.notify_rx(tail);695696 Ok(rem)697 }...

...

610 /// Attempts to send a value to all active \[\`Receiver\`\] handles, returning_611_ /// it back if it could not be sent.612 ///613 /// A successful send occurs when there is at least one active \[\`Receiver\`\]614 /// handle. An unsuccessful send would be one where all associated_615_ /// \[\`Receiver\`\] handles have already been dropped.616 ///617 /// # Return_618_ ///619 /// On success, the number of subscribed \[\`Receiver\`\] handles is returned.620 /// This does not mean that this number of receivers will see the message as_621_ /// a receiver may drop or lag (\see lagging\) before receiving_622_ /// the message.623 ///624 /// # Note_625_ ///626 /// A return value of \`Ok\` \\*does not\\ mean that the sent value will be_627_ /// observed by all or any of the active \[\`Receiver\`\] handles. \[\`Receiver\`\]628 /// handles may be dropped before receiving the sent message.629 ///630 /// A return value of \`Err\` \\does not\\* mean that future calls to \`send\`631 /// will fail. New \[\`Receiver\`\] handles may be created by calling_632_ /// \[\`subscribe\`\].633 ///634 /// \[\`Receiver\`\]: crate::sync::broadcast::Receiver_635_ /// \[\`subscribe\`\]: crate::sync::broadcast::Sender::subscribe_636_ ///637 /// # Examples_638_ ///639 /// \`\`\`640 /// use tokio::sync::broadcast;641 ///642 /// # #\[tokio::main(flavor = "current\thread")\]_643 /// # async fn main() {644 /// let (tx, mut rx1) = broadcast::channel(16);645 /// let mut rx2 = tx.subscribe();646 ///647 /// tokio::spawn(async move {648 /// assert\eq!(rx1.recv().await.unwrap(), 10);_649 /// assert\eq!(rx1.recv().await.unwrap(), 20);_650 /// });651 ///652 /// tokio::spawn(async move {653 /// assert\eq!(rx2.recv().await.unwrap(), 10);_654 /// assert\eq!(rx2.recv().await.unwrap(), 20);_655 /// });656 ///657 /// tx.send(10).unwrap();658 /// tx.send(20).unwrap();659 /// # }660 /// \`\`\`

saved: 57.7 KB -> 11.6 KB (80% fewer bytes)Use symbol handles to surgically read necessary ranges only; pass them to extract(handles=\[...\])Legend: full=docs+code, code=code only, docs=symbol docs, module-docs=file/module docs, imports=imports/directives/context; L means source line count\# tokio/src/sync/broadcast.rs (1797L)file scope: \["2000002f" full 1797L | module-docs 131L | imports 22L\]\- pub struct Sender<T> { ... } \["20000001" full 34L | code 3L | docs 31L\] \- shared: Arc<Shared<T>> \["20000000" full 1L | code 1L\]\- pub struct WeakSender<T> { ... } \["20000003" full 33L | code 3L | docs 30L\] \- shared: Arc<Shared<T>> \["20000002" full 1L | code 1L\]\- pub struct Receiver<T> { ... } \["20000006" full 43L | code 7L | docs 36L\] \- shared: Arc<Shared<T>> \["20000004" full 2L | code 1L | docs 1L\] \- next: u64 \["20000005" full 2L | code 1L | docs 1L\]\- pub mod error { ... } \["2000000o" full 103L | code 103L\] \- #\[derive(Debug)\] pub struct SendError<T>( ... ); \["20000007" full 10L | code 2L | docs 8L\] \- impl<T> fmt::Display for SendError<T> { ... } \["20000009" full 5L | code 5L\] \- fn fmt(&self, f: &mut fmt::Formatter<'\>) -> fmt::Result { ... } \["20000008" full 3L | code 3L\] \- impl<T: fmt::Debug> std::error::Error for SendError<T> { ... } \["2000000a" full 1L | code 1L\] \- #\[derive(Debug, PartialEq, Eq, Clone)\] pub enum RecvError { ... } \["2000000d" full 24L | code 20L | docs 4L\] \- Closed \["2000000b" full 3L | code 1L | docs 2L\] \- Lagged(u64) \["2000000c" full 13L | code 1L | docs 12L\] \- impl fmt::Display for RecvError { ... } \["2000000f" full 8L | code 8L\] \- fn fmt(&self, f: &mut fmt::Formatter<'\>) -> fmt::Result { ... } \["2000000e" full 6L | code 6L\] \- impl std::error::Error for RecvError { ... } \["2000000g" full 1L | code 1L\] \- #\[derive(Debug, PartialEq, Eq, Clone)\] pub enum TryRecvError { ... } \["2000000k" full 30L | code 26L | docs 4L\] \- Empty \["2000000h" full 5L | code 1L | docs 4L\] \- Closed \["2000000i" full 3L | code 1L | docs 2L\] \- Lagged(u64) \["2000000j" full 13L | code 1L | docs 12L\] \- impl fmt::Display for TryRecvError { ... } \["2000000m" full 9L | code 9L\] \- fn fmt(&self, f: &mut fmt::Formatter<'\_>) -> fmt::Result { ... } \["2000000l" full 7L | code 7L\] \- impl std::error::Error for TryRecvError { ... } \["2000000n" full 1L | code 1L\]\- struct Shared<T> { ... } \["2000000v" full 20L | code 19L | docs 1L\] \- buffer: Box<\[Mutex<Slot<T>>\]> \["2000000p" full 2L | code 1L | docs 1L\] \- mask: usize \["2000000q" full 2L | code 1L | docs 1L\] \- tail: Mutex<Tail> \["2000000r" full 2L | code 1L | docs 1L\] \- num\_tx: AtomicUsize \["2000000s" full 2L | code 1L | docs 1L\] \- num\_weak\_tx: AtomicUsize \["2000000t" full 2L | code 1L | docs 1L\] \- notify\_last\_rx\_drop: Notify \["2000000u" full 2L | code 1L | docs 1L\]\- struct Tail { ... } \["2000000A" full 14L | code 13L | docs 1L\] \- pos: u64 \["2000000w" full 2L | code 1L | docs 1L\] \- rx\_cnt: usize \["2000000x" full 2L | code 1L | docs 1L\] \- closed: bool \["2000000y" full 2L | code 1L | docs 1L\] \- waiters: LinkedList<Waiter> \["2000000z" full 2L | code 1L | docs 1L\]\- struct Slot<T> { ... } \["2000000E" full 19L | code 18L | docs 1L\] \- rem: AtomicUsize \["2000000B" full 7L | code 1L | docs 6L\] \- pos: u64 \["2000000C" full 2L | code 1L | docs 1L\] \- val: Option<T> \["2000000D" full 5L | code 1L | docs 4L\]\- struct Waiter { ... } \["2000000J" full 14L | code 13L | docs 1L\] \- queued: AtomicBool \["2000000F" full 2L | code 1L | docs 1L\] \- waker: Option<Waker> \["2000000G" full 2L | code 1L | docs 1L\] \- pointers: linked\_list::Pointers<Waiter> \["2000000H" full 2L | code 1L | docs 1L\] \- \_p: PhantomPinned \["2000000I" full 2L | code 1L | docs 1L\]\- impl Waiter { ... } \["2000000L" full 10L | code 10L\] \- fn new() -> Self { ... } \["2000000K" full 8L | code 8L\]\- struct RecvGuard<'a, T> { ... } \["2000000N" full 3L | code 3L\] \- slot: MutexGuard<'a, Slot<T>> \["2000000M" full 1L | code 1L\]\- struct Recv<'a, T> { ... } \["2000000Q" full 8L | code 7L | docs 1L\] \- receiver: &'a mut Receiver<T> \["2000000O" full 2L | code 1L | docs 1L\] \- waiter: WaiterCell \["2000000P" full 2L | code 1L | docs 1L\]\- struct WaiterCell( ... ); \["2000000R" full 3L | code 1L | docs 2L\]\- unsafe impl Send for WaiterCell { ... } \["2000000S" full 1L | code 1L\]\- unsafe impl Sync for WaiterCell { ... } \["2000000T" full 1L | code 1L\]\- const MAX\_RECEIVERS: usize = usize::MAX >> 2; \["2000000U" full 2L | code 1L | docs 1L\]\- #\[track\_caller\] pub fn channel<T: Clone>(capacity: usize) -> (Sender<T>, Receiver<T>) { ... } \["2000000V" full 67L | code 10L | docs 57L\]\- impl<T> Sender<T> { ... } \["20000019" full 402L | code 402L\] \- #\[track\_caller\] pub fn new(capacity: usize) -> Self { ... } \["2000000W" full 11L | code 5L | docs 6L\] \- #\[track\_caller\] unsafe fn new\_with\_receiver\_count(receiver\_count: usize, mut capacity: usize) -> Self { ... } \["2000000X" full 46L | code 35L | docs 11L\]

661 pub fn send(&self, value: T) -> Result<usize, SendError<T>> { \- pub fn send(&self, value: T) -> Result<usize, SendError<T>> { ... }\["2000000Y" full 88L | code 37L | docs 51L\]... }697

662 let mut tail = self.shared.tail.lock();663 664 if tail.rx\cnt == 0 {_665 return Err(SendError(value));666 }667 668 // Position to write into_669_ let pos = tail.pos;670 let rem = tail.rx\cnt;_671 let idx = (pos & self.shared.mask as u64) as usize;672 673 // Update the tail position_674_ tail.pos = tail.pos.wrapping\add(1);_675 676 // Get the slot_677_ let mut slot = self.shared.buffer\[idx\].lock();678 679 // Track the position_680_ slot.pos = pos;681 682 // Set remaining receivers_683_ slot.rem.with\mut(|v| \*v = rem);_684 685 // Write the value_686_ slot.val = Some(value);687 688 // Release the slot lock before notifying the receivers.689 drop(slot);690 691 // Notify and release the mutex. This must happen after the slot lock is_692_ // released, otherwise the writer lock bit could be cleared while another_693_ // thread is in the critical section.694 self.shared.notify\rx(tail);_695 696 Ok(rem)697 }

...

\- pub fn subscribe(&self) -> Receiver<T> { ... } \["2000000Z" full 27L | code 4L | docs 23L\] \- #\[must\use = "Downgrade creates a WeakSender without destroying the original non-weak sender."\] pub fn downgrade(&self) -> WeakSender<T> { ... } \["20000010" full 11L | code 7L | docs 4L\] \- pub fn len(&self) -> usize { ... } \["20000011" full 55L | code 18L | docs 37L\] \- pub fn is\_empty(&self) -> bool { ... } \["20000012" full 34L | code 6L | docs 28L\] \- pub fn receiver\_count(&self) -> usize { ... } \["20000013" full 40L | code 4L | docs 36L\] \- pub fn same\_channel(&self, other: &Self) -> bool { ... } \["20000014" full 22L | code 3L | docs 19L\] \- pub async fn closed(&self) { ... } \["20000015" full 40L | code 15L | docs 25L\] \- fn close\_channel(&self) { ... } \["20000016" full 6L | code 6L\] \- pub fn strong\_count(&self) -> usize { ... } \["20000017" full 4L | code 3L | docs 1L\] \- pub fn weak\_count(&self) -> usize { ... } \["20000018" full 4L | code 3L | docs 1L\]\- fn new\_receiver<T>(shared: Arc<Shared<T>>) -> Receiver<T> { ... } \["2000001a" full 20L | code 19L | docs 1L\]\- struct WaitersList<'a, T> { ... } \["2000001e" full 8L | code 5L | docs 3L\] \- list: GuardedLinkedList<Waiter> \["2000001b" full 1L | code 1L\] \- is\_empty: bool \["2000001c" full 1L | code 1L\] \- shared: &'a Shared<T> \["2000001d" full 1L | code 1L\]\- impl<'a, T> Drop for WaitersList<'a, T> { ... } \["2000001g" full 10L | code 10L\] \- fn drop(&mut self) { ... } \["2000001f" full 8L | code 8L\]\- impl<'a, T> WaitersList<'a, T> { ... } \["2000001j" full 27L | code 27L\] \- fn new( unguarded\_list: LinkedList<Waiter>, guard: Pin<&'a Waiter>, shared: &'a Shared<T>, ) -> Self { ... } \["2000001h" full 13L | code 13L\] \- fn pop\_back\_locked(&mut self, \_tail: &mut Tail) -> Option<NonNull<Waiter>> { ... } \["2000001i" full 11L | code 9L | docs 2L\]\- impl<T> Shared<T> { ... } \["2000001l" full 65L | code 65L\] \- fn notify\_rx<'a, 'b: 'a>(&'b self, mut tail: MutexGuard<'a, Tail>) { ... } \["2000001k" full 63L | code 63L\]\- impl<T> Clone for Sender<T> { ... } \["2000001n" full 8L | code 8L\] \- fn clone(&self) -> Sender<T> { ... } \["2000001m" full 6L | code 6L\]\- impl<T> Drop for Sender<T> { ... } \["2000001p" full 7L | code 7L\] \- fn drop(&mut self) { ... } \["2000001o" full 5L | code 5L\]\- impl<T> WeakSender<T> { ... } \["2000001t" full 40L | code 40L\] \- #\[must\_use\] pub fn upgrade(&self) -> Option<Sender<T>> { ... } \["2000001q" full 28L | code 24L | docs 4L\] \- pub fn strong\_count(&self) -> usize { ... } \["2000001r" full 4L | code 3L | docs 1L\] \- pub fn weak\_count(&self) -> usize { ... } \["2000001s" full 4L | code 3L | docs 1L\]\- impl<T> Clone for WeakSender<T> { ... } \["2000001v" full 8L | code 8L\] \- fn clone(&self) -> WeakSender<T> { ... } \["2000001u" full 6L | code 6L\]\- impl<T> Drop for WeakSender<T> { ... } \["2000001x" full 5L | code 5L\] \- fn drop(&mut self) { ... } \["2000001w" full 3L | code 3L\]\- impl<T> Receiver<T> { ... } \["2000001F" full 239L | code 239L\] \- pub fn len(&self) -> usize { ... } \["2000001y" full 41L | code 4L | docs 37L\] \- pub fn is\_empty(&self) -> bool { ... } \["2000001z" full 28L | code 3L | docs 25L\] \- pub fn same\_channel(&self, other: &Self) -> bool { ... } \["2000001A" full 22L | code 3L | docs 19L\] \- fn recv\_ref( &mut self, waiter: Option<(&UnsafeCell<Waiter>, &Waker)>, ) -> Result<RecvGuard<'\, T>, TryRecvError> { ... } \["2000001B" full 107L | code 106L | docs 1L\] \- pub fn sender\strong\_count(&self) -> usize { ... } \["2000001C" full 4L | code 3L | docs 1L\] \- pub fn sender\_weak\_count(&self) -> usize { ... } \["2000001D" full 4L | code 3L | docs 1L\] \- pub fn is\_closed(&self) -> bool { ... } \["2000001E" full 25L | code 4L | docs 21L\]\- impl<T: Clone> Receiver<T> { ... } \["2000001K" full 184L | code 184L\] \- pub fn resubscribe(&self) -> Self { ... } \["2000001G" full 27L | code 4L | docs 23L\] \- pub async fn recv(&mut self) -> Result<T, RecvError> { ... } \["2000001H" full 77L | code 3L | docs 74L\] \- pub fn try\_recv(&mut self) -> Result<T, TryRecvError> { ... } \["2000001I" full 46L | code 4L | docs 42L\] \- pub fn blocking\_recv(&mut self) -> Result<T, RecvError> { ... } \["2000001J" full 30L | code 3L | docs 27L\]\- impl<T> Drop for Receiver<T> { ... } \["2000001M" full 28L | code 28L\] \- fn drop(&mut self) { ... } \["2000001L" full 26L | code 26L\]\- impl<'a, T> Recv<'a, T> { ... } \["2000001P" full 25L | code 25L\] \- fn new(receiver: &'a mut Receiver<T>) -> Recv<'a, T> { ... } \["2000001N" full 11L | code 11L\] \- fn project(self: Pin<&mut Self>) -> (&mut Receiver<T>, &UnsafeCell<Waiter>) { ... } \["2000001O" full 11L | code 9L | docs 2L\]\- impl<'a, T> Future for Recv<'a, T> where T: Clone, { ... } \["2000001S" full 21L | code 21L\] \- type Output = Result<T, RecvError>; \["2000001Q" full 1L | code 1L\] \- fn poll(self: Pin<&mut Self>, cx: &mut Context<'\>) -> Poll<Result<T, RecvError>> { ... } \["2000001R" full 14L | code 14L\]\- impl<'a, T> Drop for Recv<'a, T> { ... } \["2000001U" full 39L | code 39L\] \- fn drop(&mut self) { ... } \["2000001T" full 37L | code 37L\]\- unsafe impl linked\list::Link for Waiter { ... } \["20000020" full 19L | code 16L | docs 3L\] \- type Handle = NonNull<Waiter>; \["2000001V" full 1L | code 1L\] \- type Target = Waiter; \["2000001W" full 1L | code 1L\] \- fn as\_raw(handle: &NonNull<Waiter>) -> NonNull<Waiter> { ... } \["2000001X" full 3L | code 3L\] \- unsafe fn from\_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> { ... } \["2000001Y" full 3L | code 3L\] \- unsafe fn pointers(target: NonNull<Waiter>) -> NonNull<linked\_list::Pointers<Waiter>> { ... } \["2000001Z" full 3L | code 3L\]\- impl<T> fmt::Debug for Sender<T> { ... } \["20000022" full 5L | code 5L\] \- fn fmt(&self, fmt: &mut fmt::Formatter<'\>) -> fmt::Result { ... } \["20000021" full 3L | code 3L\]\- impl<T> fmt::Debug for WeakSender<T> { ... } \["20000024" full 5L | code 5L\] \- fn fmt(&self, fmt: &mut fmt::Formatter<'\>) -> fmt::Result { ... } \["20000023" full 3L | code 3L\]\- impl<T> fmt::Debug for Receiver<T> { ... } \["20000026" full 5L | code 5L\] \- fn fmt(&self, fmt: &mut fmt::Formatter<'\>) -> fmt::Result { ... } \["20000025" full 3L | code 3L\]\- impl<'a, T> RecvGuard<'a, T> { ... } \["20000028" full 8L | code 8L\] \- fn clone\_value(&self) -> Option<T> where T: Clone, { ... } \["20000027" full 6L | code 6L\]\- impl<'a, T> Drop for RecvGuard<'a, T> { ... } \["2000002a" full 8L | code 8L\] \- fn drop(&mut self) { ... } \["20000029" full 6L | code 6L\]\- fn is\_unpin<T: Unpin>() { ... } \["2000002b" full 1L | code 1L\]\- #\[cfg(not(loom))\] #\[cfg(test)\] mod tests { ... } \["2000002e" full 37L | code 37L\] \- #\[test\] fn receiver\_count\_on\_sender\_constructor() { ... } \["2000002c" full 21L | code 21L\] \- #\[cfg(not(loom))\] #\[test\] fn receiver\_count\_on\_channel\_constructor() { ... } \["2000002d" full 9L | code 9L\]

saved: 57.7 KB -> 11.6 KB (80% fewer bytes)Use symbol handles to surgically read necessary ranges only; pass them to extract(handles=[...])Legend: full=docs+code, code=code only, docs=symbol docs, module-docs=file/module docs, imports=imports/directives/context; L means source line count# tokio/src/sync/broadcast.rs (1797L)file scope: ["2000002f" full 1797L | module-docs 131L | imports 22L]- pub struct Sender<T> { ... } ["20000001" full 34L | code 3L | docs 31L] - shared: Arc<Shared<T>> ["20000000" full 1L | code 1L]- pub struct WeakSender<T> { ... } ["20000003" full 33L | code 3L | docs 30L] - shared: Arc<Shared<T>> ["20000002" full 1L | code 1L]- pub struct Receiver<T> { ... } ["20000006" full 43L | code 7L | docs 36L] - shared: Arc<Shared<T>> ["20000004" full 2L | code 1L | docs 1L] - next: u64 ["20000005" full 2L | code 1L | docs 1L]- pub mod error { ... } ["2000000o" full 103L | code 103L] - #[derive(Debug)] pub struct SendError<T>( ... ); ["20000007" full 10L | code 2L | docs 8L] - impl<T> fmt::Display for SendError<T> { ... } ["20000009" full 5L | code 5L] - fn fmt(&self, f: &mut fmt::Formatter<'>) -> fmt::Result { ... } ["20000008" full 3L | code 3L] - impl<T: fmt::Debug> std::error::Error for SendError<T> { ... } ["2000000a" full 1L | code 1L] - #[derive(Debug, PartialEq, Eq, Clone)] pub enum RecvError { ... } ["2000000d" full 24L | code 20L | docs 4L] - Closed ["2000000b" full 3L | code 1L | docs 2L] - Lagged(u64) ["2000000c" full 13L | code 1L | docs 12L] - impl fmt::Display for RecvError { ... } ["2000000f" full 8L | code 8L] - fn fmt(&self, f: &mut fmt::Formatter<'>) -> fmt::Result { ... } ["2000000e" full 6L | code 6L] - impl std::error::Error for RecvError { ... } ["2000000g" full 1L | code 1L] - #[derive(Debug, PartialEq, Eq, Clone)] pub enum TryRecvError { ... } ["2000000k" full 30L | code 26L | docs 4L] - Empty ["2000000h" full 5L | code 1L | docs 4L] - Closed ["2000000i" full 3L | code 1L | docs 2L] - Lagged(u64) ["2000000j" full 13L | code 1L | docs 12L] - impl fmt::Display for TryRecvError { ... } ["2000000m" full 9L | code 9L] - fn fmt(&self, f: &mut fmt::Formatter<'>) -> fmt::Result { ... } ["2000000l" full 7L | code 7L] - impl std::error::Error for TryRecvError { ... } ["2000000n" full 1L | code 1L]- struct Shared<T> { ... } ["2000000v" full 20L | code 19L | docs 1L] - buffer: Box<[Mutex<Slot<T>>]> ["2000000p" full 2L | code 1L | docs 1L] - mask: usize ["2000000q" full 2L | code 1L | docs 1L] - tail: Mutex<Tail> ["2000000r" full 2L | code 1L | docs 1L] - num_tx: AtomicUsize ["2000000s" full 2L | code 1L | docs 1L] - num_weak_tx: AtomicUsize ["2000000t" full 2L | code 1L | docs 1L] - notify_last_rx_drop: Notify ["2000000u" full 2L | code 1L | docs 1L]- struct Tail { ... } ["2000000A" full 14L | code 13L | docs 1L] - pos: u64 ["2000000w" full 2L | code 1L | docs 1L] - rx_cnt: usize ["2000000x" full 2L | code 1L | docs 1L] - closed: bool ["2000000y" full 2L | code 1L | docs 1L] - waiters: LinkedList<Waiter> ["2000000z" full 2L | code 1L | docs 1L]- struct Slot<T> { ... } ["2000000E" full 19L | code 18L | docs 1L] - rem: AtomicUsize ["2000000B" full 7L | code 1L | docs 6L] - pos: u64 ["2000000C" full 2L | code 1L | docs 1L] - val: Option<T> ["2000000D" full 5L | code 1L | docs 4L]- struct Waiter { ... } ["2000000J" full 14L | code 13L | docs 1L] - queued: AtomicBool ["2000000F" full 2L | code 1L | docs 1L] - waker: Option<Waker> ["2000000G" full 2L | code 1L | docs 1L] - pointers: linked_list::Pointers<Waiter> ["2000000H" full 2L | code 1L | docs 1L] - _p: PhantomPinned ["2000000I" full 2L | code 1L | docs 1L]- impl Waiter { ... } ["2000000L" full 10L | code 10L] - fn new() -> Self { ... } ["2000000K" full 8L | code 8L]- struct RecvGuard<'a, T> { ... } ["2000000N" full 3L | code 3L] - slot: MutexGuard<'a, Slot<T>> ["2000000M" full 1L | code 1L]- struct Recv<'a, T> { ... } ["2000000Q" full 8L | code 7L | docs 1L] - receiver: &'a mut Receiver<T> ["2000000O" full 2L | code 1L | docs 1L] - waiter: WaiterCell ["2000000P" full 2L | code 1L | docs 1L]- struct WaiterCell( ... ); ["2000000R" full 3L | code 1L | docs 2L]- unsafe impl Send for WaiterCell { ... } ["2000000S" full 1L | code 1L]- unsafe impl Sync for WaiterCell { ... } ["2000000T" full 1L | code 1L]- const MAX_RECEIVERS: usize = usize::MAX >> 2; ["2000000U" full 2L | code 1L | docs 1L]- #[track_caller] pub fn channel<T: Clone>(capacity: usize) -> (Sender<T>, Receiver<T>) { ... } ["2000000V" full 67L | code 10L | docs 57L]- impl<T> Sender<T> { ... } ["20000019" full 402L | code 402L] - #[track_caller] pub fn new(capacity: usize) -> Self { ... } ["2000000W" full 11L | code 5L | docs 6L] - #[track_caller] unsafe fn new_with_receiver_count(receiver_count: usize, mut capacity: usize) -> Self { ... } ["2000000X" full 46L | code 35L | docs 11L] - pub fn send(&self, value: T) -> Result<usize, SendError<T>> { ... } ["2000000Y" full 88L | code 37L | docs 51L] - pub fn subscribe(&self) -> Receiver<T> { ... } ["2000000Z" full 27L | code 4L | docs 23L] - #[must_use = "Downgrade creates a WeakSender without destroying the original non-weak sender."] pub fn downgrade(&self) -> WeakSender<T> { ... } ["20000010" full 11L | code 7L | docs 4L] - pub fn len(&self) -> usize { ... } ["20000011" full 55L | code 18L | docs 37L] - pub fn is_empty(&self) -> bool { ... } ["20000012" full 34L | code 6L | docs 28L] - pub fn receiver_count(&self) -> usize { ... } ["20000013" full 40L | code 4L | docs 36L] - pub fn same_channel(&self, other: &Self) -> bool { ... } ["20000014" full 22L | code 3L | docs 19L] - pub async fn closed(&self) { ... } ["20000015" full 40L | code 15L | docs 25L] - fn close_channel(&self) { ... } ["20000016" full 6L | code 6L] - pub fn strong_count(&self) -> usize { ... } ["20000017" full 4L | code 3L | docs 1L] - pub fn weak_count(&self) -> usize { ... } ["20000018" full 4L | code 3L | docs 1L]- fn new_receiver<T>(shared: Arc<Shared<T>>) -> Receiver<T> { ... } ["2000001a" full 20L | code 19L | docs 1L]- struct WaitersList<'a, T> { ... } ["2000001e" full 8L | code 5L | docs 3L] - list: GuardedLinkedList<Waiter> ["2000001b" full 1L | code 1L] - is_empty: bool ["2000001c" full 1L | code 1L] - shared: &'a Shared<T> ["2000001d" full 1L | code 1L]- impl<'a, T> Drop for WaitersList<'a, T> { ... } ["2000001g" full 10L | code 10L] - fn drop(&mut self) { ... } ["2000001f" full 8L | code 8L]- impl<'a, T> WaitersList<'a, T> { ... } ["2000001j" full 27L | code 27L] - fn new( unguarded_list: LinkedList<Waiter>, guard: Pin<&'a Waiter>, shared: &'a Shared<T>, ) -> Self { ... } ["2000001h" full 13L | code 13L] - fn pop_back_locked(&mut self, _tail: &mut Tail) -> Option<NonNull<Waiter>> { ... } ["2000001i" full 11L | code 9L | docs 2L]- impl<T> Shared<T> { ... } ["2000001l" full 65L | code 65L] - fn notify_rx<'a, 'b: 'a>(&'b self, mut tail: MutexGuard<'a, Tail>) { ... } ["2000001k" full 63L | code 63L]- impl<T> Clone for Sender<T> { ... } ["2000001n" full 8L | code 8L] - fn clone(&self) -> Sender<T> { ... } ["2000001m" full 6L | code 6L]- impl<T> Drop for Sender<T> { ... } ["2000001p" full 7L | code 7L] - fn drop(&mut self) { ... } ["2000001o" full 5L | code 5L]- impl<T> WeakSender<T> { ... } ["2000001t" full 40L | code 40L] - #[must_use] pub fn upgrade(&self) -> Option<Sender<T>> { ... } ["2000001q" full 28L | code 24L | docs 4L] - pub fn strong_count(&self) -> usize { ... } ["2000001r" full 4L | code 3L | docs 1L] - pub fn weak_count(&self) -> usize { ... } ["2000001s" full 4L | code 3L | docs 1L]- impl<T> Clone for WeakSender<T> { ... } ["2000001v" full 8L | code 8L] - fn clone(&self) -> WeakSender<T> { ... } ["2000001u" full 6L | code 6L]- impl<T> Drop for WeakSender<T> { ... } ["2000001x" full 5L | code 5L] - fn drop(&mut self) { ... } ["2000001w" full 3L | code 3L]- impl<T> Receiver<T> { ... } ["2000001F" full 239L | code 239L] - pub fn len(&self) -> usize { ... } ["2000001y" full 41L | code 4L | docs 37L] - pub fn is_empty(&self) -> bool { ... } ["2000001z" full 28L | code 3L | docs 25L] - pub fn same_channel(&self, other: &Self) -> bool { ... } ["2000001A" full 22L | code 3L | docs 19L] - fn recv_ref( &mut self, waiter: Option<(&UnsafeCell<Waiter>, &Waker)>, ) -> Result<RecvGuard<', T>, TryRecvError> { ... } ["2000001B" full 107L | code 106L | docs 1L] - pub fn sender_strong_count(&self) -> usize { ... } ["2000001C" full 4L | code 3L | docs 1L] - pub fn sender_weak_count(&self) -> usize { ... } ["2000001D" full 4L | code 3L | docs 1L] - pub fn is_closed(&self) -> bool { ... } ["2000001E" full 25L | code 4L | docs 21L]- impl<T: Clone> Receiver<T> { ... } ["2000001K" full 184L | code 184L] - pub fn resubscribe(&self) -> Self { ... } ["2000001G" full 27L | code 4L | docs 23L] - pub async fn recv(&mut self) -> Result<T, RecvError> { ... } ["2000001H" full 77L | code 3L | docs 74L] - pub fn try_recv(&mut self) -> Result<T, TryRecvError> { ... } ["2000001I" full 46L | code 4L | docs 42L] - pub fn blocking_recv(&mut self) -> Result<T, RecvError> { ... } ["2000001J" full 30L | code 3L | docs 27L]- impl<T> Drop for Receiver<T> { ... } ["2000001M" full 28L | code 28L] - fn drop(&mut self) { ... } ["2000001L" full 26L | code 26L]- impl<'a, T> Recv<'a, T> { ... } ["2000001P" full 25L | code 25L] - fn new(receiver: &'a mut Receiver<T>) -> Recv<'a, T> { ... } ["2000001N" full 11L | code 11L] - fn project(self: Pin<&mut Self>) -> (&mut Receiver<T>, &UnsafeCell<Waiter>) { ... } ["2000001O" full 11L | code 9L | docs 2L]- impl<'a, T> Future for Recv<'a, T> where T: Clone, { ... } ["2000001S" full 21L | code 21L] - type Output = Result<T, RecvError>; ["2000001Q" full 1L | code 1L] - fn poll(self: Pin<&mut Self>, cx: &mut Context<'>) -> Poll<Result<T, RecvError>> { ... } ["2000001R" full 14L | code 14L]- impl<'a, T> Drop for Recv<'a, T> { ... } ["2000001U" full 39L | code 39L] - fn drop(&mut self) { ... } ["2000001T" full 37L | code 37L]- unsafe impl linked_list::Link for Waiter { ... } ["20000020" full 19L | code 16L | docs 3L] - type Handle = NonNull<Waiter>; ["2000001V" full 1L | code 1L] - type Target = Waiter; ["2000001W" full 1L | code 1L] - fn as_raw(handle: &NonNull<Waiter>) -> NonNull<Waiter> { ... } ["2000001X" full 3L | code 3L] - unsafe fn from_raw(ptr: NonNull<Waiter>) -> NonNull<Waiter> { ... } ["2000001Y" full 3L | code 3L] - unsafe fn pointers(target: NonNull<Waiter>) -> NonNull<linked_list::Pointers<Waiter>> { ... } ["2000001Z" full 3L | code 3L]- impl<T> fmt::Debug for Sender<T> { ... } ["20000022" full 5L | code 5L] - fn fmt(&self, fmt: &mut fmt::Formatter<'>) -> fmt::Result { ... } ["20000021" full 3L | code 3L]- impl<T> fmt::Debug for WeakSender<T> { ... } ["20000024" full 5L | code 5L] - fn fmt(&self, fmt: &mut fmt::Formatter<'>) -> fmt::Result { ... } ["20000023" full 3L | code 3L]- impl<T> fmt::Debug for Receiver<T> { ... } ["20000026" full 5L | code 5L] - fn fmt(&self, fmt: &mut fmt::Formatter<'>) -> fmt::Result { ... } ["20000025" full 3L | code 3L]- impl<'a, T> RecvGuard<'a, T> { ... } ["20000028" full 8L | code 8L] - fn clone_value(&self) -> Option<T> where T: Clone, { ... } ["20000027" full 6L | code 6L]- impl<'a, T> Drop for RecvGuard<'a, T> { ... } ["2000002a" full 8L | code 8L] - fn drop(&mut self) { ... } ["20000029" full 6L | code 6L]- fn is_unpin<T: Unpin>() { ... } ["2000002b" full 1L | code 1L]- #[cfg(not(loom))] #[cfg(test)] mod tests { ... } ["2000002e" full 37L | code 37L] - #[test] fn receiver_count_on_sender_constructor() { ... } ["2000002c" full 21L | code 21L] - #[cfg(not(loom))] #[test] fn receiver_count_on_channel_constructor() { ... } ["2000002d" full 9L | code 9L]

extract · code only · type\_annotated output\_modeaugmented with type info

1257 fn recv_ref(1258 &mut self,1259 waiter: Option<(&UnsafeCell<Waiter>, &Waker)>,1260 ) -> Result<RecvGuard<', T>, TryRecvError> {1261 let idx/: usize/ = (self.next & self.shared.mask as u64) as usize;12621263 // The slot holding the next value to read1264 let mut slot/: MutexGuard<', Slot<T>>/ = self.shared.buffer[idx].lock();12651266 if slot.pos != self.next {1274 drop(slot);1276 let mut old_waker/: Option<Waker>/ = None;1278 let mut tail/: MutexGuard<', Tail>/ = self.shared.tail.lock();1281 slot = self.shared.buffer[idx].lock();1286 if slot.pos != self.next {1287 let next_pos/: u64/ = slot.pos.wrapping_add(self.shared.buffer.len() as u64);1289 if next_pos == self.next {1293 if tail.closed {1294 return Err(TryRecvError::Closed);1295 }1298 if let Some((waiter/: &UnsafeCell<Waiter>/, waker/: &Waker/)) = waiter {1300 unsafe {1302 waiter.with_mut(|ptr/: *mut Waiter/| {1307 match (ptr).waker {1308 Some(ref w/: &Waker*/) if w.will_wake(waker) => {}1309 => {1310 old_waker = (ptr).waker.replace(waker.clone());1311 }1312 }1317 if !(*ptr).queued.load(/*order: /Relaxed) {1320 (ptr).queued.store(/*val: /true, /order: /Relaxed);1321 tail.waiters.push_front(/val: /NonNull::new_unchecked(&mut ptr));1322 }1323 });1324 }1325 }1328 drop(slot);1329 drop(tail);1330 drop(old_waker);1332 return Err(TryRecvError::Empty);1333 }1340 let next/: u64*/ = tail.pos.wrapping_sub(self.shared.buffer.len() as u64);1342 let missed/: u64/ = next.wrapping_sub(self.next);1344 drop(tail);1347 if missed == 0 {1348 self.next = self.next.wrapping_add(1);1350 return Ok(RecvGuard { slot });1351 }1353 self.next = next;1355 return Err(TryRecvError::Lagged(missed));1356 }1357 }1359 self.next = self.next.wrapping_add(1);1361 Ok(RecvGuard { slot })1362 }

1257 fn recv_ref(1258 &mut self,1259 waiter: Option<(&UnsafeCell<Waiter>, &Waker)>,1260 ) -> Result<RecvGuard<', T>, TryRecvError> {1261 let idx/: usize/ = (self.next & self.shared.mask as u64) as usize;12621263 // The slot holding the next value to read1264 let mut slot/: MutexGuard<', Slot<T>>/ = self.shared.buffer[idx].lock();12651266 if slot.pos != self.next {1274 drop(slot);1276 let mut old_waker/: Option<Waker>/ = None;1278 let mut tail/: MutexGuard<', Tail>/ = self.shared.tail.lock();1281 slot = self.shared.buffer[idx].lock();1286 if slot.pos != self.next {1287 let next_pos/: u64/ = slot.pos.wrapping_add(self.shared.buffer.len() as u64);1289 if next_pos == self.next {1293 if tail.closed {1294 return Err(TryRecvError::Closed);1295 }1298 if let Some((waiter/: &UnsafeCell<Waiter>/, waker/: &Waker/)) = waiter {1300 unsafe {1302 waiter.with_mut(|ptr/: *mut Waiter/| {1307 match (ptr).waker {1308 Some(ref w/: &Waker*/) if w.will_wake(waker) => {}1309 => {1310 old_waker = (ptr).waker.replace(waker.clone());1311 }1312 }1317 if !(*ptr).queued.load(/*order: /Relaxed) {1320 (ptr).queued.store(/*val: /true, /order: /Relaxed);1321 tail.waiters.push_front(/val: /NonNull::new_unchecked(&mut ptr));1322 }1323 });1324 }1325 }1328 drop(slot);1329 drop(tail);1330 drop(old_waker);1332 return Err(TryRecvError::Empty);1333 }1340 let next/: u64*/ = tail.pos.wrapping_sub(self.shared.buffer.len() as u64);1342 let missed/: u64/ = next.wrapping_sub(self.next);1344 drop(tail);1347 if missed == 0 {1348 self.next = self.next.wrapping_add(1);1350 return Ok(RecvGuard { slot });1351 }1353 self.next = next;1355 return Err(TryRecvError::Lagged(missed));1356 }1357 }1359 self.next = self.next.wrapping_add(1);1361 Ok(RecvGuard { slot })1362 }

jump · api modeNonNull::new\_unchecked

rust/library/core/src/ptr/non_null.rs- impl<T: PointeeSized> NonNull<T> { ... } - #[stable(feature = "nonnull", since = "1.25.0")] #[rustc_const_stable(feature = "const_nonnull_new_unchecked", since = "1.25.0")] #[inline] #[track_caller] pub const unsafe fn new_unchecked(ptr: *mut T) -> Self { ... } ["1000100b" full 38L | code 15L | docs 23L]

jump · implementation mode · type\_annotated output\_modedefined in Rust standard library

226 #[stable(feature = "nonnull", since = "1.25.0")]227 #[rustc_const_stable(feature = "const_nonnull_new_unchecked", since = "1.25.0")]228 #[inline]229 #[track_caller]230 pub const unsafe fn new_unchecked(ptr: mut T) -> Self {231 // SAFETY: the caller must guarantee that `ptr` is non-null.232 unsafe {233 assert_unsafe_precondition!(234 check_language_ub,235 "NonNull::new_unchecked requires that the pointer is non-null",236 (ptr: *mut () = ptr as *mut ()) => !ptr.is_null()237 );238 transmute(/*src: /ptr)239 }240 }

1. 01raw text 2. 02outline 3. 03extract 4. 04jump

02

Debugging

I use debugging here as shorthand for any task that requires an agent to explore implementation details rather than just inspect an API.

These tasks usually begin in one of two places: with a symbol name — or a guess at one — without knowing where it is defined, or with a file and line number from a failing test, error, or linter warning.

For the first case, Context Engine provides `grep_definition`. It searches symbol definitions by exact name or glob. An agent can, for example, find all data structures and functions matching `config`, while narrowing the search by symbol kind and setting the results limit. When the workflow starts with a known file and line, `line_context` finds the smallest complete symbol containing that line and shows its hierarchy.

In both cases, the agent gets semantic context instead of false-positive text matches or an arbitrary window of nearby lines. `grep_definition` returns the APIs of the matching symbols together with handles. The agent can pass a handle to `extract` to read the full definition or to `show_usage` to see where and how the symbol is used.

`line_context` returns the full implementation of the symbol containing the line. The agent does not have to guess how many lines to read — a range that is too wide pollutes its context, while one that is too narrow leads to repeated reads of the same code.

As you may have noticed in the first animation, Context Engine tools that show complete implementations — including `extract`, `line_context`, `jump` in `implementation` mode, and several others you have not heard about yet — can augment the source with inlay hints. These show resolved types and parameter names at function call sites.

`type_annotated` is the default view because agents read code far more often than they edit it. When an agent needs the exact source, tools that support source-output modes can return `plain_text` or `both`. The `both` mode provides the annotated code for reasoning and the original source for editing.

Seeing resolved contracts makes mistakes caused by guessed types and APIs less likely. It also leaves more of the agent's reasoning budget for the task itself.

The `jump` and `show_usage` tools introduced in the Codebase Exploration section are a perfect fit for debugging too. Starting with a line from a failing test, an agent can call `line_context`, `jump` to the function under test, and then `jump` again to a function called from its body, where the bug may be hiding. That takes exactly three tool calls, regardless of the size of the codebase or where those symbols are defined.

The agent does not pollute its context with unrelated symbols from the same files, guess where definitions might be, or consume false positives from grep results. And `show_usage` shines when the agent needs to see the exact blast radius before refactoring a symbol.

Real workflowHere is the animation of the debugging workflow on a real Django repository. Context Engine is just as useful in dynamically typed codebases:

failing reproductionPython · Django

$ python -c '...; model_to_dict(object())'Traceback (most recent call last): File "<string>", line 1, in <module> File "django/forms/models.py", line 111, in model_to_dict opts = instance._meta ^^^^^^^^^^^^^^AttributeError: 'object' object has no attribute '_meta'

failing reproductionPython · Django

$ python -c '...; model_to_dict(object())'Traceback (most recent call last): File "<string>", line 1, in <module> File "django/forms/models.py", line 111, in model_to_dict opts = instance._meta ^^^^^^^^^^^^^^AttributeError: 'object' object has no attribute '_meta'

saved vs reading full file: 60.8 KB -> 1.0 KB (98% fewer bytes)

"django/forms/models.py" (line 111)

exact containing symbol · lines 99 - 121

99def model_to_dict(instance, fields=None, exclude=None)/: -> dict[Any, Any]/:100 """101 Return a dict containing the data in ``instance`` suitable for passing as102 a Form's ``initial`` keyword argument.103104 ``fields`` is an optional list of field names. If provided, return only the105 named.106107 ``exclude`` is an optional list of field names. If provided, exclude the108 named from the returned dict, even if they are listed in the ``fields``109 argument.110 """111 opts/: Any/ = instance._meta112 data/: dict[Any, Any]/ = {}113 for f in chain/: [Any]/(opts.concrete_fields, opts.private_fields, opts.many_to_many):114 if not getattr(f, "editable", False):115 continue116 if fields is not None and f.name not in fields:117 continue118 if exclude and f.name in exclude:119 continue120 data[f.name] = f.value_from_object(instance)121 return data

saved vs reading full file: 60.8 KB -> 1.0 KB (98% fewer bytes)

"django/forms/models.py" (line 111)

exact containing symbol · lines 99 - 121

99def model_to_dict(instance, fields=None, exclude=None)/: -> dict[Any, Any]/:100 """101 Return a dict containing the data in ``instance`` suitable for passing as102 a Form's ``initial`` keyword argument.103104 ``fields`` is an optional list of field names. If provided, return only the105 named.106107 ``exclude`` is an optional list of field names. If provided, exclude the108 named from the returned dict, even if they are listed in the ``fields``109 argument.110 """111 opts/: Any/ = instance._meta112 data/: dict[Any, Any]/ = {}113 for f in chain/: [Any]/(opts.concrete_fields, opts.private_fields, opts.many_to_many):114 if not getattr(f, "editable", False):115 continue116 if fields is not None and f.name not in fields:117 continue118 if exclude and f.name in exclude:119 continue120 data[f.name] = f.value_from_object(instance)121 return data

django/forms/models.py (2 references)- class BaseModelForm(BaseForm, AltersData): ... - def _init_( self, data=None, files=None, auto_id="id_%s", prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None, ): ... ["1000101m" full 47L | code 47L] - 371| object_data/: dict[Any, Any]/ = model_to_dict(/instance=: /instance, /fields=: /opts.fields, /exclude=: /opts.exclude)## tests/model_forms/tests.py (8 references)- class ModelOneToOneFieldTests(TestCase): ... - def test_modelform_subclassed_model(self): ... ["100050aG" full 27L | code 27L] - 2380| /first=: /sorted(model_to_dict(/instance=: /bw)), /second=: /["id", "name", "score", "writer_ptr"] - 2382| self.assertEqual(/first=: /sorted(model_to_dict(/instance=: /bw, fields=[])), /second=: /[])- class OtherModelFormTests(TestCase): ... - def test_foreignkeys_which_use_to_field(self): ... ["100050cU" full 62L | code 62L] - 3064| data/: dict[Any, Any]/ = model_to_dict(/instance=: /core)- class ModelToDictTests(TestCase): ... - def test_many_to_many(self): ... ["100050gw" full 12L | code 12L] - 3729| data/: Any/ = model_to_dict(/instance=: /item)["colors"]

django/forms/models.py (2 references)- class BaseModelForm(BaseForm, AltersData): ... - def _init_( self, data=None, files=None, auto_id="id_%s", prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None, ): ... ["1000101m" full 47L | code 47L] - 371| object_data/: dict[Any, Any]/ = model_to_dict(/instance=: /instance, /fields=: /opts.fields, /exclude=: /opts.exclude)## tests/model_forms/tests.py (8 references)- class ModelOneToOneFieldTests(TestCase): ... - def test_modelform_subclassed_model(self): ... ["100050aG" full 27L | code 27L] - 2380| /first=: /sorted(model_to_dict(/instance=: /bw)), /second=: /["id", "name", "score", "writer_ptr"] - 2382| self.assertEqual(/first=: /sorted(model_to_dict(/instance=: /bw, fields=[])), /second=: /[])- class OtherModelFormTests(TestCase): ... - def test_foreignkeys_which_use_to_field(self): ... ["100050cU" full 62L | code 62L] - 3064| data/: dict[Any, Any]/ = model_to_dict(/instance=: /core)- class ModelToDictTests(TestCase): ... - def test_many_to_many(self): ... ["100050gw" full 12L | code 12L] - 3729| data/: Any/ = model_to_dict(/instance=: /item)["colors"]

ErrorList (python)## django/forms/utils.py (1 match)- class ErrorList(UserList, list, RenderableErrorMixin): ... ["1000b01g" full 69L | code 69L] (line 141)

1. 01failure 2. 02line\_context 3. 03show\_usage 4. 04grep\_definition

03

Consequences of Fixing the Interface

Fixing the interface has several consequences. Token savings are one of them, but they are not the product category.

First, the size of the codebase becomes much less important. The amount of context an agent consumes can follow the path it takes through the codebase graph instead of the total amount of source around that path. It can navigate between symbols across a huge monorepo, its packages, and external dependencies without loading every file it passes through. This matters especially for enterprises — and for agentic companies trying to serve them.

Second, the agent's context remains useful for longer. Every unrelated function body, irrelevant documentation block, and false-positive search result occupies space that could have been used for the task. Keeping that noise out leaves more room for reasoning, delays compaction, and allows the agent to complete more work — and potentially more tasks — within the same session.

There is also the direct token saving. Context Engine lets the agent fetch a file's API without its implementations, one symbol without the rest of the file, documentation without code, code without documentation, or the exact source of a dependency symbol. It does not load a large block and summarize it afterward. It avoids loading the irrelevant code in the first place.

Resolved contracts save tokens further downstream. When the agent can see types, parameter names, exact dependency APIs, and real usages, it has less to guess. Fewer guesses mean fewer incorrect edits and fewer write-test-rewrite loops.

These benefits recur every time an agent has to acquire the codebase again: at the beginning of a session, after context compaction, when a subagent starts, or when several agents work in parallel. Context Engine makes that reacquisition cheaper because the codebase is available as a compact structural map with exact evidence behind it.

These are not separate optimizations. They are consequences of giving agents an interface to code instead of files. Context Engine is the semantic layer that provides that interface. Token savings are simply one visible result of fixing it.

PS

Postscript

I built Context Engine in 2025 and had it working as an MCP server by December. A public release still required a website, installers, license validation, and the rest of the release infrastructure.

In January 2026, I switched my attention to my current deep-tech project: a math-to-silicon synthesis engine. I used Context Engine as an internal tool on that project until July, when I returned to finish Context Engine for a public release. Both projects are written in Rust. During those six months, I rarely saw agents struggle with the borrow checker or lifetimes, and I did not see them hallucinate a dependency API even once. That experience convinced me to finish the remaining work and release Context Engine as a free Community Preview.

Context Engine has been language-agnostic from day one. It bundles 324 Tree-sitter grammars — the complete set supported by Neovim — and needs only a configured language server to add project-resolved semantic information. I have personally validated it with Rust, Python, Go, TypeScript, and Markdown. Support for the other bundled languages should still be considered experimental.

The MCP server is a thin wrapper around an embeddable Rust core, with C/C++ used only by the compiled Tree-sitter grammars. If you are building agentic tooling and are interested in integrating Context Engine directly through its Rust API, email me at integrations@context-engine.app. Context Engine is already fast through MCP, while direct integration removes the protocol layer entirely.

Context Engine will remain free throughout the Community Preview while I decide what comes next. You can get a free API key and try it on a codebase you know well. I would be glad to hear what works, what does not, and where it breaks in the Context Engine MCP repository.

Get a free API keyInstall Context Engine

context-engine.app · 17 links

Comments (0)

No comments yet