feat: add memory usage event metrics

This commit is contained in:
2026-05-11 21:29:48 +09:00
parent 1d8db0aadd
commit 6c93ec38df
10 changed files with 701 additions and 93 deletions
+21 -3
View File
@@ -33,6 +33,8 @@ const SUMMARY_FILE: &str = "summary.md";
const DECISIONS_DIR: &str = "decisions";
const REQUESTS_DIR: &str = "requests";
const STAGING_DIR: &str = "_staging";
const USAGE_DIR: &str = "_usage";
const USAGE_EVENTS_FILE: &str = "events.jsonl";
/// What kind of record a path under the memory tree represents.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -126,6 +128,14 @@ impl WorkspaceLayout {
self.memory_dir().join(STAGING_DIR)
}
pub fn usage_dir(&self) -> PathBuf {
self.memory_dir().join(USAGE_DIR)
}
pub fn usage_events_path(&self) -> PathBuf {
self.usage_dir().join(USAGE_EVENTS_FILE)
}
pub fn decision_path(&self, slug: &Slug) -> PathBuf {
self.decisions_dir().join(format!("{slug}.md"))
}
@@ -145,7 +155,7 @@ impl WorkspaceLayout {
/// Classify a path under the memory tree. Returns `None` if the
/// path is not under `.insomnia/memory/`, `.insomnia/knowledge/`,
/// or `.insomnia/workflow/` of this workspace, or if it lives in
/// `_staging/` (which is opaque to the linter).
/// `_staging/` / `_usage/` (opaque subsystem-owned trees).
///
/// On a conventional path that's *almost* a record but malformed
/// (e.g. `.insomnia/memory/decisions/Foo.md` with an invalid slug),
@@ -182,8 +192,8 @@ impl WorkspaceLayout {
slug: None,
}));
}
if first == STAGING_DIR {
// Linter opts out of `_staging/`; extract handles its schema.
if first == STAGING_DIR || first == USAGE_DIR {
// Linter opts out of subsystem-owned opaque trees.
return Ok(None);
}
@@ -295,6 +305,14 @@ mod tests {
);
}
#[test]
fn usage_tree_is_opaque_to_classifier() {
let cp = layout()
.classify(&PathBuf::from("/ws/.insomnia/memory/_usage/events.jsonl"))
.unwrap();
assert!(cp.is_none());
}
#[test]
fn outside_returns_none() {
assert!(