feat: add Agrifine browser extension scaffold (Phase 1)#3216
Open
leanmachine1209-ui wants to merge 12 commits into
Open
feat: add Agrifine browser extension scaffold (Phase 1)#3216leanmachine1209-ui wants to merge 12 commits into
leanmachine1209-ui wants to merge 12 commits into
Conversation
Manifest V3 Chrome extension with a persistent side-panel dashboard
for farm data management. Includes:
- Background service worker that proxies all Anthropic API calls
(API key stored in chrome.storage.session, never in content scripts)
- Content script that extracts page text for reading-list summarisation
- Sidebar UI with bottom tab bar and settings panel (API key entry)
- Five module stubs wired to live storage:
1. ReadingList — save pages with AI summary + topic tagging
2. DataIngest — drag-and-drop CSV/Excel/PDF → AI-structured JSON
3. FieldProfile — per-field cards with CLU, acres, soil, coordinates
4. Dashboard — unified filterable view + natural-language AI query bar
5. CarbonEstimator — Phase 7 stub with feature preview
- Shared storage schema (chrome.storage.local) with context-bundle
builder for passing reading-list + field data as AI system context
- Tailwind CSS + Webpack 5 build pipeline; builds successfully
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KBD2dN2KEjzz3UQFa9hEpu
Multi-step AI agent in src/ag-refine/: - agent.js: Claude tool-use loop (up to 10 iterations), streams events to UI as it thinks and calls tools - tools.js: 6 live tools — get_reading_list, get_field_profiles, get_ingested_files, get_weather (Open-Meteo), lookup_usda_soil (USDA SDA API), calculate_gdd - index.js: chat UI with streaming tool-call display, suggested prompts, clear conversation - Wired as new Agent tab in sidebar (6th tab) - Also fixes manifest.json paths (dist/ prefix removed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KBD2dN2KEjzz3UQFa9hEpu
Driver (.claude/skills/run-agrifine-extension/driver.mjs): - Launches Chrome with unpacked extension via Playwright persistent context - Stubs chrome.* APIs so sidebar renders headlessly without real extension context - REPL commands: ss, tab, click, type, eval, quit - Screenshots land in screenshots/ - Verified: all 6 tabs render correctly (Reading, Ingest, Fields, Dashboard, Carbon, Agent) SKILL.md documents agent path first, gotchas, and troubleshooting from actual execution in this container. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KBD2dN2KEjzz3UQFa9hEpu
- agent.js: add anthropic-dangerous-direct-browser-access header to _callAPI (root cause of 401 CORS errors in AgriAgent tab) - agent.js: handle stop_reason=max_tokens alongside end_turn - ag-refine/index.js: reset isRunning in a try/catch around agent.run() - tools.js: check res.ok before parsing JSON in toolLookupUSDAsoil - tools.js: guard p.name?.toLowerCase() against null field names - field-profile/index.js: guard both lat and lon before toFixed() - reading-list/index.js: escapeHtml + safeHref to prevent XSS from page titles/urls - dashboard/index.js: escapeHtml AI answer and all dynamic list content - data-ingest/index.js: add .xlsx/.xls extension fallbacks for missing MIME type - storage.js: check chrome.runtime.lastError in all four storage helpers Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KBD2dN2KEjzz3UQFa9hEpu
screenshot_active_tab — captures current browser tab as JPEG; agent.js formats the result as an Anthropic vision image block so Claude can actually see the page (not just its text) get_page_content — reads text of the active tab via content script, or falls back to the reading-list cache when a URL is supplied export_farm_data — generates a CSV or JSON file and triggers a browser download for reading_list, field_profiles, ingested_files, or all data open_tab — opens any https:// URL in a new browser tab and waits for it to finish loading; returns tab_id for chained tool calls read_tab_content — extracts and parses page text from any tab by tab_id (or active tab) using chrome.scripting.executeScript; more reliable than the content-script sendMessage path Background worker gains CAPTURE_SCREENSHOT, GET_ACTIVE_TAB_CONTENT, OPEN_TAB, and READ_TAB_CONTENT message handlers; agent.js detects _type:'image' results and formats them as vision content blocks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KBD2dN2KEjzz3UQFa9hEpu
Farm memory (agrifine_farm_memory in chrome.storage.local): - New FarmMemory schema: aiGeneratedSummary, farm_name, total_acres, primary_crops, soil_overview, key_insights, action_items, risk_flags, opportunities, lastUpdated - getFarmMemory() / saveFarmMemory() in storage.js buildContextBundle() now loads all four data sources in parallel: 1. Farm memory snapshot (AI synthesis from prior sessions) — at top 2. Field profiles with crop history, harvest records, and coordinates 3. Ingested data files with structured-data previews 4. Reading list articles with summaries and tags Two new AgriAgent tools: - get_farm_memory: retrieve the stored knowledge snapshot - update_farm_memory: agent saves a comprehensive farm synthesis so future sessions start with full context (the key to persistent memory) System prompt rewrite in agent.js: - Agent now understands its role as the farm's persistent advisor - Memory protocol: reference farm memory first, update it when new insights are discovered - Explicit reasoning steps: Ground → Gaps → Connect → Cite → Remember - Full tool selection guide with when-to-use guidance for all 11 tools Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KBD2dN2KEjzz3UQFa9hEpu
Replace all light-mode Tailwind classes across every module with the AG-Refine dark design system: #0f1621 body, #131c2b header/nav, #1a2438 cards, #1e2d40 borders, agri-green (22c55e/16a34a) accents. - tailwind.config.js: add `night` dark palette (950–300) - sidebar.css: full dark rewrite (cards, tags, inputs, scrollbar) - sidebar.html: AG/REFINE/FIELD INTELLIGENCE logo, dark tab bar with INTEL/INGEST/FIELDS/DATA/CARBON/AGENT labels and dot indicators - sidebar/index.js: manage inactive tab color via inline style - reading-list: card links → agri-400, summary/date → gray-400/500 - data-ingest: drop zone → night borders, file cards → dark theme - field-profile: form → night-700 bg, inputs use .ag-input, cards dark - dashboard: AI query bar and category pills → dark, answer box dark - carbon-estimator: feature list and notify banner → dark palette - ag-refine: suggestions → night-700, chat bubbles dark, tool call cards use night-700/border-night-600, errors use red-900/20 tint Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KBD2dN2KEjzz3UQFa9hEpu
Chrome loads files from dist/ directly, so the built output needs to be in the repo. Removed dist/ from .gitignore and committed the current build which includes the AG-Refine dark theme redesign. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KBD2dN2KEjzz3UQFa9hEpu
Document parsing fixes: - Copy pdf.worker.min.mjs to dist/pdf.worker.js via webpack CopyPlugin (was missing, causing all PDF parsing to silently fail) - Set webpack output.publicPath '/' so dynamic import chunks resolve correctly from Chrome extension chrome-extension:// URLs - pdfjs: pass Uint8Array and set useWorkerFetch/isEvalSupported for extension CSP compatibility - Add Python doc server (tools/doc_server.py) using flask + pandas + PyPDF2 at localhost:7432; extension tries it first then falls back to browser-side parsing for more robust CSV/Excel/PDF extraction AG-Refine sister-app integration: - New utils/agrefine-bridge.js: detects open AG-Refine tab by URL pattern, executes script to dump its localStorage, maps field/load data to Agrifine field profile schema, merges without overwriting user edits, logs sync history - Background handler AGREFINE_SYNC calls syncFromAgRefine() - Field Profiles module: "AG-Refine" sync button, status feedback, synced-field badge, "Open in AG-Refine ↗" link in expanded detail - Settings panel: AG-Refine URL field so sync pins to a specific origin - sidebar/index.js: loads and saves AG-Refine URL on settings open/save Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KBD2dN2KEjzz3UQFa9hEpu
Previously the Anthropic API key was session-only and lost on Chrome restart. Now: - KEYS.API_KEY_SAVED added to storage schema (chrome.storage.local) - Background service worker restores saved key into session on startup, so the key is available immediately without re-entering it - SET_API_KEY handler accepts a `remember` flag: if true, writes to both session and local; if false, clears the local copy - Settings panel: "Remember across sessions" checkbox next to Save, "Forget saved key" button appears when a key is persisted - Status text distinguishes "Key saved across sessions" vs "Key active this session only" Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KBD2dN2KEjzz3UQFa9hEpu
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Manifest V3 Chrome extension with a persistent side-panel dashboard for farm data management. Includes:
Claude-Session: https://claude.ai/code/session_01KBD2dN2KEjzz3UQFa9hEpu
Project
Project Name
Checklist
Add project-name- [project-name](url) - Description ending with period.Why This Project Is Awesome
Which criterion does it meet? (pick one)
Explain:
How It Differs
If similar entries exist, what makes this one unique?