Repository navigation
Expose module queries and HTML extraction through minimal bus contracts #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
05185b0
feat(bus): expose typed REPL queries and HTML extraction
senamakel c896708
fix(bus): bound query inputs and preserve summary limits
senamakel f8f3422
fix(repl): bound grep context allocation before response construction
senamakel f87d736
fix(repl): preserve matches and cap complete fallback summaries
senamakel 6742357
Merge remote-tracking branch 'origin/main' into enforce-module-bounda…
senamakel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| //! Shared data for REPL-style output inspection. | ||
|
|
||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// Unit of a Python-style scope slice. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub enum ScopeUnit { | ||
| /// Count lines (the default). | ||
| #[default] | ||
| Lines, | ||
| /// Count Unicode characters. | ||
| Chars, | ||
| } | ||
|
|
||
| /// Caps applied to every op so a query can never return the whole payload. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] | ||
| #[serde(default)] | ||
| pub struct ReplLimits { | ||
|
senamakel marked this conversation as resolved.
|
||
| pub max_hits: usize, | ||
| /// Cap for range-producing modes (`sed`, `awk`) and expanded grep context. | ||
| pub max_lines: usize, | ||
| pub max_output_chars: usize, | ||
| pub max_line_chars: usize, | ||
| pub regex_size_limit: usize, | ||
| } | ||
|
|
||
| impl Default for ReplLimits { | ||
| fn default() -> Self { | ||
| Self { | ||
| max_hits: 50, | ||
| max_lines: 400, | ||
| max_output_chars: 8_000, | ||
| max_line_chars: 240, | ||
| regex_size_limit: 1 << 20, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// A located line. `line` is 1-based. | ||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct Hit { | ||
| pub line: usize, | ||
| pub text: String, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct RegexMatch { | ||
| pub line: usize, | ||
| pub text: String, | ||
| pub captures: Vec<Option<String>>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
| pub struct SearchHit { | ||
| pub line_start: usize, | ||
| pub line_end: usize, | ||
| pub score: f32, | ||
| pub text: String, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct Heading { | ||
| pub level: u8, | ||
| pub text: String, | ||
| pub line: usize, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct Link { | ||
| pub text: String, | ||
| pub href: String, | ||
| } | ||
|
|
||
| /// How `find` reads its query. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub enum FindMode { | ||
| /// Case-insensitive substring. | ||
| #[default] | ||
| Text, | ||
| /// Regex per line (optionally case-insensitive, with context lines). | ||
| Grep, | ||
| /// Regex per line, returning capture groups. | ||
| Regex, | ||
| /// BM25-ranked windows of lines. | ||
| Rank, | ||
| /// sed subset: `-n 10,20p`, `/re/d`, `s/a/b/g`. | ||
| Sed, | ||
| /// awk subset: `-F, '$3 > 5 { print $1, $NF }'`. | ||
| Awk, | ||
| /// jq filter over JSON output: `.items[] | select(.size > 10) | .name`. | ||
| Jq, | ||
| } | ||
|
|
||
| /// What `extract` pulls out of HTML or Markdown. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub enum ExtractKind { | ||
| Links, | ||
| Headings, | ||
| } | ||
|
|
||
| /// An op over a stored original. | ||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
| #[serde(tag = "op", rename_all = "snake_case")] | ||
| pub enum ReplOp { | ||
|
senamakel marked this conversation as resolved.
senamakel marked this conversation as resolved.
|
||
| Find { | ||
| query: String, | ||
| #[serde(default)] | ||
| mode: FindMode, | ||
| #[serde(default)] | ||
| ignore_case: bool, | ||
| #[serde(default)] | ||
| context: usize, | ||
| #[serde(default)] | ||
| top_k: Option<usize>, | ||
| /// Python-style slice to search within, e.g. `[:-100]`. | ||
| #[serde(default)] | ||
| scope: Option<String>, | ||
| #[serde(default)] | ||
| unit: ScopeUnit, | ||
| }, | ||
| Extract { | ||
| what: ExtractKind, | ||
| #[serde(default)] | ||
| scope: Option<String>, | ||
| #[serde(default)] | ||
| unit: ScopeUnit, | ||
| }, | ||
| Summarize { | ||
| #[serde(default)] | ||
| max_chars: Option<usize>, | ||
| /// What the caller cares about; ranks which parts of the scope to keep. | ||
| #[serde(default)] | ||
| hint: Option<String>, | ||
| #[serde(default)] | ||
| scope: Option<String>, | ||
| #[serde(default)] | ||
| unit: ScopeUnit, | ||
| }, | ||
| } | ||
|
|
||
| /// Result of an op. `truncated` counts hits dropped by a cap. | ||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
| #[serde(tag = "kind", rename_all = "snake_case")] | ||
| pub enum ReplOutput { | ||
| Lines { | ||
| hits: Vec<Hit>, | ||
| truncated: usize, | ||
| }, | ||
| Matches { | ||
| matches: Vec<RegexMatch>, | ||
| truncated: usize, | ||
| }, | ||
| Search { | ||
| hits: Vec<SearchHit>, | ||
| truncated: usize, | ||
| }, | ||
| Links { | ||
| links: Vec<Link>, | ||
| truncated: usize, | ||
| }, | ||
| Headings { | ||
| headings: Vec<Heading>, | ||
| truncated: usize, | ||
| }, | ||
| Values { | ||
| values: Vec<String>, | ||
| truncated: usize, | ||
| }, | ||
| Text { | ||
| text: String, | ||
| }, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] | ||
| pub enum ReplError { | ||
| #[error("handle not found or expired; re-run the original tool")] | ||
| HandleNotFound, | ||
| #[error("invalid pattern: {0}")] | ||
| InvalidPattern(String), | ||
| #[error("empty query")] | ||
| EmptyQuery, | ||
| #[error("{0} support is not compiled in")] | ||
| Unsupported(&'static str), | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.