Title: feat(forge-ai): deterministic token-budgeted context builder with untrusted envelope · Issue #89 · elcode-id/elcode-forge · GitHub
Open Graph Title: feat(forge-ai): deterministic token-budgeted context builder with untrusted envelope · Issue #89 · elcode-id/elcode-forge
X Title: feat(forge-ai): deterministic token-budgeted context builder with untrusted envelope · Issue #89 · elcode-id/elcode-forge
Description: 1. Context & Objective Implement the deterministic, token-budgeted context retrieval builder in crates/forge-ai that ranks facts from Repository (security/high findings > target module & 1-hop neighbors > dependencies > pre-redacted code...
Open Graph Description: 1. Context & Objective Implement the deterministic, token-budgeted context retrieval builder in crates/forge-ai that ranks facts from Repository (security/high findings > target module & 1-hop neig...
X Description: 1. Context & Objective Implement the deterministic, token-budgeted context retrieval builder in crates/forge-ai that ranks facts from Repository (security/high findings > target module &...
Opengraph URL: https://github.com/elcode-id/elcode-forge/issues/89
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"feat(forge-ai): deterministic token-budgeted context builder with untrusted envelope","articleBody":"## 1. Context & Objective\nImplement the deterministic, token-budgeted context retrieval builder in `crates/forge-ai` that ranks facts from `Repository` (security/high findings > target module & 1-hop neighbors > dependencies > pre-redacted code snippets), trims lower-priority sections to fit `max_context_tokens`, scans for prompt-injection signals, and wraps the user payload in `UntrustedEnvelope` (PRD §20, §39).\n\n- **Parent Epic:** #83\n- **GitFlow Branch:** `feat/forge-089-ai-context-builder`\n- **Execution Wave:** `wave-11`\n- **DAG Dependencies:** Depends on #86\n- **Estimated Size:** ~310 LOC (`\u003c 400 LOC`)\n\n## 2. Target Files\n- `crates/forge-ai/src/tokens.rs` *(NEW: `estimate_tokens`)*\n- `crates/forge-ai/src/prompt.rs` *(NEW: deterministic system prompts with grounding & untrusted-data rules)*\n- `crates/forge-ai/src/context.rs` *(NEW: `ContextSection`, `ContextInput`, `ContextPack`, `build_context`, `sections_from_repository`)*\n- `crates/forge-ai/src/lib.rs` *(MODIFY)*\n\n## 3. Public Contract\n```rust\npub struct ContextSection {\n pub kind: SectionKind,\n pub title: String,\n pub body: String,\n pub priority: u8,\n}\n\npub struct ContextInput {\n pub task: AiTask,\n pub sections: Vec\u003cContextSection>,\n pub snippets: Vec\u003cCodeSnippet>, // pre-redacted by caller\n}\n\npub struct ContextPack {\n pub system_prompt: String,\n pub user_payload: String,\n pub estimated_tokens: u32,\n pub included: Vec\u003cString>,\n pub dropped: Vec\u003cString>,\n pub injection_signals: Vec\u003cString>,\n}\n\npub fn estimate_tokens(text: &str) -> u32;\npub fn build_context(input: &ContextInput, max_context_tokens: u32) -> Result\u003cContextPack, ForgeError>;\npub fn sections_from_repository(repo: &Repository, focus: Option\u003c&str>) -> Vec\u003cContextSection>;\n```\n\n## 4. Security & Privacy Invariants\n- All repository-sourced sections and snippets are enclosed inside `UntrustedEnvelope` and scanned via `detect_prompt_injection_signals`.\n- System prompt enforces strict data-vs-instruction separation and requires citing deterministic source IDs (`finding.id`, `module.id`, or file path).\n- Identical `ContextInput` + `max_context_tokens` always produces byte-for-byte identical `ContextPack`.\n\n## 5. Definition of Done & Verification (Tier 1)\n- Unit tests for determinism (repeated builds are byte-identical), priority ordering and budget trimming (`included` vs `dropped`), prompt-injection signal detection on hostile snippets, and system prompt invariants.\n- **Selective Verification Gate (Tier 1):**\n 1. `cargo fmt --package forge-ai -- --check`\n 2. `cargo clippy --package forge-ai --all-targets -- -D warnings`\n 3. `cargo test --package forge-ai`","author":{"url":"https://github.com/luksluki","@type":"Person","name":"luksluki"},"datePublished":"2026-10-19T14:22:25Z","url":"https://github.com/elcode-id/elcode-forge/issues/89"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7039092b-4c83-d798-de45-8640fe32b5ad |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E8E8:1009BE:1DE500:28DABB:6B059990 |
| html-safe-nonce | 78da078d52d2718721ba8e365978763a6e188bf59362aefbe5fa547b5cf3ea04 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOEU4OjEwMDlCRToxREU1MDA6MjhEQUJCOjZCMDU5OTkwIiwidmlzaXRvcl9pZCI6IjEyNjU4NjY3NzY3ODEzNjM2MDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b82b57fe872acd0a8bd507dbea6457ad1c1d24741ca3b696c5584073c9b33e79 |
| hovercard-subject-tag | issue:5925665350 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/elcode-id/elcode-forge/89/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a0be171e5098ad556f912a3a735eb03c9d5aa57e237d24a1f217d87ff3ed2883/elcode-id/elcode-forge/issues/89 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a0be171e5098ad556f912a3a735eb03c9d5aa57e237d24a1f217d87ff3ed2883/elcode-id/elcode-forge/issues/89 |
| og:image:alt | 1. Context & Objective Implement the deterministic, token-budgeted context retrieval builder in crates/forge-ai that ranks facts from Repository (security/high findings > target module & 1-hop neig... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | luksluki |
| hostname | github.com |
| expected-hostname | github.com |
| None | 8bd54b96ae4db60ce608a145a6b2fb16216749fbdb431d9879aabfa7459f1139 |
| turbo-cache-control | no-preview |
| go-import | github.com/elcode-id/elcode-forge git https://github.com/elcode-id/elcode-forge.git |
| octolytics-dimension-user_id | 337957755 |
| octolytics-dimension-user_login | elcode-id |
| octolytics-dimension-repository_id | 1423983661 |
| octolytics-dimension-repository_nwo | elcode-id/elcode-forge |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1423983661 |
| octolytics-dimension-repository_network_root_nwo | elcode-id/elcode-forge |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cda4791073b4da3005eb3d470dc0aef3956bbe34 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width