Add browser extension and shell completions (Milestones 12-13)

M12: Browser Extension
- Chrome/Edge Manifest V3 extension
- Popup UI for saving pages
- Context menu integration (save page/selection/link)
- Background service worker
- Content script for extraction

M13: Shell Completions
- Bash, Zsh, Fish, PowerShell completions
- Dynamic node ID completion
- Dynamic tag completion
- Dynamic graph completion
- Auto-install command (--install)
This commit is contained in:
2026-02-03 11:35:41 +01:00
parent b1c62c5da9
commit f21426fc43
11 changed files with 1248 additions and 0 deletions

136
extension/popup/popup.css Normal file
View File

@@ -0,0 +1,136 @@
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
font-size: 14px;
width: 320px;
padding: 16px;
background: #1a1a2e;
color: #eee;
}
.container {
display: flex;
flex-direction: column;
gap: 12px;
}
h1 {
font-size: 18px;
font-weight: 600;
color: #4fc3f7;
margin-bottom: 8px;
}
.status {
padding: 8px;
border-radius: 4px;
font-size: 12px;
display: none;
}
.status.success {
display: block;
background: #1b5e20;
color: #a5d6a7;
}
.status.error {
display: block;
background: #b71c1c;
color: #ef9a9a;
}
.field {
display: flex;
flex-direction: column;
gap: 4px;
}
.field.checkbox {
flex-direction: row;
align-items: center;
}
.field.checkbox label {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
label {
font-size: 12px;
color: #aaa;
font-weight: 500;
}
input[type="text"],
select {
padding: 8px 12px;
border: 1px solid #333;
border-radius: 4px;
background: #0f0f23;
color: #eee;
font-size: 14px;
}
input[type="text"]:focus,
select:focus {
outline: none;
border-color: #4fc3f7;
}
select {
cursor: pointer;
}
input[type="checkbox"] {
width: 16px;
height: 16px;
cursor: pointer;
}
.actions {
display: flex;
gap: 8px;
margin-top: 8px;
}
button {
flex: 1;
padding: 10px 16px;
border: none;
border-radius: 4px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
}
button.primary {
background: #4fc3f7;
color: #000;
}
button.primary:hover {
background: #29b6f6;
}
button:not(.primary) {
background: #333;
color: #eee;
}
button:not(.primary):hover {
background: #444;
}
button:disabled {
opacity: 0.5;
cursor: not-allowed;
}

View File

@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="popup.css">
</head>
<body>
<div class="container">
<h1>Save to Cortex</h1>
<div id="status" class="status"></div>
<div class="field">
<label for="title">Title</label>
<input type="text" id="title" placeholder="Page title">
</div>
<div class="field">
<label for="kind">Kind</label>
<select id="kind">
<option value="memory">Memory</option>
<option value="component">Component</option>
<option value="decision">Decision</option>
<option value="task">Task</option>
</select>
</div>
<div class="field">
<label for="tags">Tags</label>
<input type="text" id="tags" placeholder="comma, separated, tags">
</div>
<div class="field checkbox">
<label>
<input type="checkbox" id="includeContent" checked>
Include page content
</label>
</div>
<div class="field checkbox">
<label>
<input type="checkbox" id="selectionOnly">
Selection only
</label>
</div>
<div class="actions">
<button id="save" class="primary">Save</button>
<button id="cancel">Cancel</button>
</div>
</div>
<script src="popup.js"></script>
</body>
</html>

136
extension/popup/popup.js Normal file
View File

@@ -0,0 +1,136 @@
// Popup script for Cortex browser extension
const CORTEX_API = 'http://localhost:3100/api';
// DOM elements
const titleInput = document.getElementById('title');
const kindSelect = document.getElementById('kind');
const tagsInput = document.getElementById('tags');
const includeContent = document.getElementById('includeContent');
const selectionOnly = document.getElementById('selectionOnly');
const saveButton = document.getElementById('save');
const cancelButton = document.getElementById('cancel');
const statusDiv = document.getElementById('status');
let pageData = null;
// Initialize popup
async function init() {
try {
// Get current tab
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
// Request content from content script
const response = await chrome.tabs.sendMessage(tab.id, { action: 'extract' });
pageData = response;
// Pre-fill form
titleInput.value = response.title || tab.title || '';
// Suggest tags based on URL
const url = new URL(tab.url);
const suggestedTags = ['web-clip'];
if (url.hostname.includes('github')) suggestedTags.push('github');
if (url.hostname.includes('docs')) suggestedTags.push('documentation');
if (url.hostname.includes('stackoverflow')) suggestedTags.push('stackoverflow');
tagsInput.value = suggestedTags.join(', ');
// Enable selection only if there's selected text
if (response.selection) {
selectionOnly.disabled = false;
} else {
selectionOnly.disabled = true;
}
} catch (err) {
showStatus('Could not extract page content', 'error');
console.error('Init error:', err);
}
}
// Save to Cortex
async function save() {
saveButton.disabled = true;
saveButton.textContent = 'Saving...';
try {
const content = selectionOnly.checked
? pageData?.selection
: (includeContent.checked ? pageData?.content : '');
const tags = tagsInput.value
.split(',')
.map(t => t.trim())
.filter(t => t.length > 0);
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
const response = await fetch(`${CORTEX_API}/nodes`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
kind: kindSelect.value,
title: titleInput.value,
content: content,
tags: tags,
metadata: {
source: {
type: 'url',
url: tab.url,
savedAt: Date.now(),
},
},
}),
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const node = await response.json();
showStatus(`Saved! ID: ${node.id.slice(0, 8)}`, 'success');
// Close popup after brief delay
setTimeout(() => window.close(), 1500);
} catch (err) {
showStatus(`Failed to save: ${err.message}`, 'error');
console.error('Save error:', err);
// Check if Cortex server is running
if (err.message.includes('fetch')) {
showStatus('Is Cortex server running? (cortex serve)', 'error');
}
} finally {
saveButton.disabled = false;
saveButton.textContent = 'Save';
}
}
// Show status message
function showStatus(message, type) {
statusDiv.textContent = message;
statusDiv.className = `status ${type}`;
}
// Event listeners
saveButton.addEventListener('click', save);
cancelButton.addEventListener('click', () => window.close());
// Toggle selection only checkbox when include content is unchecked
includeContent.addEventListener('change', () => {
if (!includeContent.checked) {
selectionOnly.checked = false;
}
});
selectionOnly.addEventListener('change', () => {
if (selectionOnly.checked) {
includeContent.checked = true;
}
});
// Initialize on load
init();