u-foo 4.0.5 → 4.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +224 -19
- package/README.zh-CN.md +3 -3
- package/bin/ucode.js +10 -2
- package/bin/ufoo.js +3 -0
- package/dist/tui/darwin-arm64/ufoo-tui +0 -0
- package/dist/tui/darwin-x64/ufoo-tui +0 -0
- package/dist/tui/linux-arm64/ufoo-tui +0 -0
- package/dist/tui/linux-x64/ufoo-tui +0 -0
- package/{OBSERVABILITY.md → docs/OBSERVABILITY.md} +3 -3
- package/docs/README.md +27 -0
- package/extensions/ufoo-browser/LICENSE +152 -0
- package/extensions/ufoo-browser/NOTICE +10 -0
- package/extensions/ufoo-browser/README.md +30 -0
- package/extensions/ufoo-browser/background.js +409 -0
- package/extensions/ufoo-browser/icons/icon-128.png +0 -0
- package/extensions/ufoo-browser/icons/icon-16.png +0 -0
- package/extensions/ufoo-browser/icons/icon-256.png +0 -0
- package/extensions/ufoo-browser/icons/icon-32.png +0 -0
- package/extensions/ufoo-browser/icons/icon-48.png +0 -0
- package/extensions/ufoo-browser/icons/logo.png +0 -0
- package/extensions/ufoo-browser/icons/toolbar-16.png +0 -0
- package/extensions/ufoo-browser/icons/toolbar-32.png +0 -0
- package/extensions/ufoo-browser/icons/toolbar-logo.png +0 -0
- package/extensions/ufoo-browser/manifest.json +30 -0
- package/extensions/ufoo-browser/popup.css +71 -0
- package/extensions/ufoo-browser/popup.html +44 -0
- package/extensions/ufoo-browser/popup.js +153 -0
- package/package.json +5 -3
- package/scripts/postinstall.js +6 -0
- package/src/agents/capabilities/browser/index.js +49 -0
- package/src/agents/capabilities/coding/backgroundHooks.js +94 -0
- package/src/agents/capabilities/coding/index.js +30 -1
- package/src/agents/capabilities/index.js +5 -2
- package/src/agents/capabilities/planning/index.js +44 -5
- package/src/agents/capabilities/turnRecall/index.js +341 -0
- package/src/agents/controller/controllerToolExecutor.js +2 -2
- package/src/agents/internal/internalRunner.js +30 -8
- package/src/agents/internal/taskControl.js +107 -0
- package/src/agents/profiles/coding.js +1 -1
- package/src/agents/profiles/main.js +1 -1
- package/src/agents/prompts/mainAgent.js +1 -0
- package/src/agents/prompts/native/toolDescriptions/bash.js +7 -1
- package/src/agents/providers/claudeSessionFiles.js +1 -1
- package/src/agents/providers/codexThreadProvider.js +6 -1
- package/src/agents/providers/credentials/agy.js +171 -0
- package/src/agents/providers/directAuthStatus.js +20 -2
- package/src/agents/providers/modelsCatalog.js +26 -5
- package/src/agents/providers/nativeTransport.js +36 -20
- package/src/agents/providers/providerId.js +17 -0
- package/src/agents/providers/runtimeConfig.js +26 -19
- package/src/agents/providers/transports/antigravityTransport.js +242 -0
- package/src/agents/providers/transports/index.js +1 -0
- package/src/agents/providers/transports/openaiChatTransport.js +3 -2
- package/src/agents/providers/transports/openaiResponsesTransport.js +2 -1
- package/src/agents/providers/transports/responsesProtocol.js +119 -18
- package/src/agents/providers/transports/transportContract.js +1 -0
- package/src/agents/providers/upstreamRuntime.js +3 -1
- package/src/agents/runtime/context/contextBudget.js +1 -19
- package/src/agents/runtime/context/contextWindow.js +5 -0
- package/src/agents/runtime/context/replayHistory.js +16 -10
- package/src/agents/runtime/context/runtimeStore.js +0 -2
- package/src/agents/runtime/context/sessionJournal.js +1 -1
- package/src/agents/runtime/context/slidingWindowManager.js +792 -0
- package/src/agents/runtime/context/topicSelector.js +338 -0
- package/src/agents/runtime/context/turnAnalyzer.js +767 -0
- package/src/agents/runtime/context/turnIndexStore.js +515 -0
- package/src/agents/runtime/core/agentLoop.js +95 -32
- package/src/agents/runtime/core/executionBudget.js +2 -1
- package/src/agents/runtime/core/toolErrorGuard.js +39 -0
- package/src/agents/runtime/createAgentRuntime.js +80 -7
- package/src/agents/runtime/index.js +5 -0
- package/src/agents/runtime/protocol/materialize.js +1 -1
- package/src/agents/runtime/tasks/hooks.js +137 -0
- package/src/app/chat/ChatController.js +8 -4
- package/src/app/chat/daemonMessageRouter.js +3 -1
- package/src/app/chat/inputSubmitHandler.js +2 -2
- package/src/app/chat/transport.js +1 -1
- package/src/app/cli/browserCommands.js +340 -0
- package/src/app/cli/features/doctor.js +21 -0
- package/src/app/cli/metricsCommands.js +1 -1
- package/src/app/cli/run.js +80 -1
- package/src/app/cli/setupCommands.js +200 -0
- package/src/code/UcodeController.js +31 -1
- package/src/code/agent.js +41 -7
- package/src/code/busConsumer.js +13 -12
- package/src/code/commands.js +0 -1
- package/src/code/context/assembler.js +11 -88
- package/src/code/context/planGraphService.js +83 -9
- package/src/code/context/planProjection.js +10 -2
- package/src/code/context/reducers.js +172 -4
- package/src/code/context/stateCommit.js +0 -32
- package/src/code/context/transcript.js +7 -4
- package/src/code/internalThread.js +9 -1
- package/src/code/launcher/ucode.js +4 -2
- package/src/code/nativeRunner.js +221 -10
- package/src/code/repl.js +27 -1
- package/src/code/runtime/agentWakeup.js +20 -3
- package/src/code/runtime/backgroundWakeHost.js +45 -0
- package/src/code/runtime/taskFocusContext.js +7 -0
- package/src/code/runtime/taskLoop.js +24 -1
- package/src/code/sessionStore.js +14 -10
- package/src/code/taskDecomposer.js +13 -7
- package/src/code/tools/backgroundProcess.js +23 -0
- package/src/code/tools/bash.js +764 -12
- package/src/code/tools/executor.js +12 -4
- package/src/code/tools/specs.js +60 -3
- package/src/code/tools/taskRun.js +38 -0
- package/src/config.js +92 -6
- package/src/coordination/bus/subscriber.js +1 -1
- package/src/coordination/history/agentPerformance.js +18 -18
- package/src/coordination/history/agentTrace.js +7 -3
- package/src/coordination/state/workspaceAccess.js +3 -1
- package/src/orchestration/groups/modelConfig.js +66 -0
- package/src/orchestration/groups/validateTemplate.js +2 -0
- package/src/runtime/browser/broker.js +1027 -0
- package/src/runtime/browser/brokerClient.js +108 -0
- package/src/runtime/browser/componentInstaller.js +275 -0
- package/src/runtime/browser/installState.js +329 -0
- package/src/runtime/browser/manifest.js +145 -0
- package/src/runtime/browser/native-host-runner.js +198 -0
- package/src/runtime/browser/nativeHost.js +213 -0
- package/src/runtime/browser/nativeMessagingProtocol.js +50 -0
- package/src/runtime/browser/paths.js +134 -0
- package/src/runtime/browser/playwrightSession.js +614 -0
- package/src/runtime/daemon/agentHost.js +175 -30
- package/src/runtime/daemon/busBridge.js +2 -1
- package/src/runtime/daemon/globalDaemon.js +20 -0
- package/src/runtime/daemon/groupOrchestrator.js +20 -1
- package/src/runtime/daemon/index.js +5 -4
- package/src/runtime/daemon/ops.js +14 -8
- package/src/tools/handlers/listAgents.js +1 -1
- package/src/tools/handlers/readBusSummary.js +1 -1
- package/src/tools/handlers/routeAgent.js +122 -5
- package/src/tools/schemaFixtures.js +1 -1
- package/src/ui/agentSurface.js +26 -3
- package/src/ui/format/index.js +34 -2
- package/src/ui/rustChatHost.js +22 -7
- package/src/ui/rustMultiSession.js +14 -2
- package/src/ui/rustUcodeHost.js +246 -77
- package/src/ui/ucodeAgentSession.js +88 -0
- package/templates/groups/build-lane.json +57 -3
- package/templates/groups/build-ultra.json +114 -6
- package/templates/groups/design-system.json +57 -3
- package/templates/groups/product-discovery.json +57 -3
- package/templates/groups/ui-plan-review.json +57 -3
- package/templates/groups/ui-polish.json +57 -3
- package/templates/groups/verify-ship.json +57 -3
- package/src/agents/runtime/context/checkpointStore.js +0 -52
- package/src/agents/runtime/context/compaction.js +0 -171
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Ufoo Chrome Extension
|
|
2
|
+
|
|
3
|
+
Manifest V3 Chrome extension for connecting daily Chrome tabs to local `ufoo` and `ucode` agents via Native Messaging and the user-scoped `ufoo` browser broker.
|
|
4
|
+
|
|
5
|
+
## Differences From Upstream Playwright Extension
|
|
6
|
+
|
|
7
|
+
- **Brand & Identity**: Uses a standalone ufoo Manifest V3 identity (`DEV_EXTENSION_ID=hepkcmckfedpfpijhdpbfccnddjpdceh` in unpacked dev builds; separate Chrome Web Store ID for release). Does not reuse Playwright's extension ID or branding.
|
|
8
|
+
- **Auto-Discovery via Native Messaging**: Connects to `com.ufoo.browser` / `com.ufoo.browser.dev` on startup instead of requiring a manual pairing tab or copied token.
|
|
9
|
+
- **Per-Tab Ownership & Isolation**: Lists normal non-incognito tabs without attaching `chrome.debugger` globally; only attaches to tabs claimed by an agent session.
|
|
10
|
+
- **Extension Panel Controls**: A light, compact connection panel shows project/agent ownership, page titles, addresses and live counts. `暂停全部控制 / 恢复浏览器控制` and per-page `释放` actions remain available. Installation help and technical errors expand on demand; failed actions report an inline error and pending actions prevent duplicate clicks.
|
|
11
|
+
- **Icon Assets**: The panel and extension list use the dark tile from `icons/logo.png` (`icons/icon-*.png`). The Chrome toolbar independently uses an enlarged amber saucer on transparency from `icons/toolbar-logo.png`, exported as `toolbar-16.png` and `toolbar-32.png` via `action.default_icon`. The toolbar has no status badges. All assets are bundled locally, with no external fonts or icon requests.
|
|
12
|
+
- **Protocol Compatibility**: Control protocol `v1` (`protocolVersion: 1`), compatible with `ufoo` host `>= 4.0.6`.
|
|
13
|
+
|
|
14
|
+
## Developer Loading (Unpacked Mode)
|
|
15
|
+
|
|
16
|
+
1. Run:
|
|
17
|
+
```bash
|
|
18
|
+
ufoo browser install --dev
|
|
19
|
+
```
|
|
20
|
+
2. Open `chrome://extensions` in Google Chrome.
|
|
21
|
+
3. Enable **Developer mode** (top right).
|
|
22
|
+
4. Click **Load unpacked** and select this directory (`extensions/ufoo-browser/`).
|
|
23
|
+
5. Verify extension ID matches `hepkcmckfedpfpijhdpbfccnddjpdceh` and verify connection with:
|
|
24
|
+
```bash
|
|
25
|
+
ufoo browser status --json
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
After updating these files, use **Reload** for Ufoo in `chrome://extensions`,
|
|
29
|
+
then reopen its popup. Reloading releases existing browser-control connections;
|
|
30
|
+
do it between browser tasks. The extension key and protocol are unchanged.
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const PROTOCOL_VERSION = 1;
|
|
4
|
+
const RELEASE_NATIVE_HOST = "com.ufoo.browser";
|
|
5
|
+
const DEV_NATIVE_HOST = "com.ufoo.browser.dev";
|
|
6
|
+
const DEV_EXTENSION_ID = "hepkcmckfedpfpijhdpbfccnddjpdceh";
|
|
7
|
+
|
|
8
|
+
let ws = null;
|
|
9
|
+
let nativePort = null;
|
|
10
|
+
let reconnectTimer = null;
|
|
11
|
+
let reconnectDelayMs = 2000;
|
|
12
|
+
let stopAutoReconnect = false;
|
|
13
|
+
const attachedTabIds = new Set();
|
|
14
|
+
|
|
15
|
+
const uiState = {
|
|
16
|
+
connectionState: "connecting", // connected | waiting_for_ufoo | native_not_installed | disabled | protocol_mismatch | paused
|
|
17
|
+
paused: false,
|
|
18
|
+
error: "",
|
|
19
|
+
hostVersion: "",
|
|
20
|
+
tabOwners: [],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function isSupportedTab(tab) {
|
|
24
|
+
if (!tab || tab.id === undefined || tab.id === null) return false;
|
|
25
|
+
if (tab.incognito === true) return false;
|
|
26
|
+
const rawUrl = String(tab.url || tab.pendingUrl || "").trim().toLowerCase();
|
|
27
|
+
if (!rawUrl) return true;
|
|
28
|
+
return !(
|
|
29
|
+
rawUrl.startsWith("chrome://")
|
|
30
|
+
|| rawUrl.startsWith("chrome-extension://")
|
|
31
|
+
|| rawUrl.startsWith("devtools://")
|
|
32
|
+
|| rawUrl.startsWith("edge://")
|
|
33
|
+
|| rawUrl.startsWith("view-source:chrome-extension://")
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function summarizeTab(tab) {
|
|
38
|
+
return {
|
|
39
|
+
id: tab.id,
|
|
40
|
+
windowId: tab.windowId,
|
|
41
|
+
active: Boolean(tab.active),
|
|
42
|
+
incognito: Boolean(tab.incognito),
|
|
43
|
+
title: String(tab.title || ""),
|
|
44
|
+
url: String(tab.url || tab.pendingUrl || ""),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function persistState() {
|
|
49
|
+
try {
|
|
50
|
+
chrome.storage.local.set({ ufooBrowserState: { ...uiState } });
|
|
51
|
+
} catch {
|
|
52
|
+
// ignore storage errors
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
// Keep the toolbar logo clear, including badges left by older versions.
|
|
56
|
+
// Connection state and tab counts are shown in the popup instead.
|
|
57
|
+
chrome.action.setBadgeText({ text: "" });
|
|
58
|
+
} catch {
|
|
59
|
+
// ignore badge errors
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function clearReconnect() {
|
|
64
|
+
if (reconnectTimer) {
|
|
65
|
+
clearTimeout(reconnectTimer);
|
|
66
|
+
reconnectTimer = null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function scheduleReconnect() {
|
|
71
|
+
if (stopAutoReconnect) return;
|
|
72
|
+
clearReconnect();
|
|
73
|
+
const delay = reconnectDelayMs;
|
|
74
|
+
reconnectDelayMs = Math.min(30000, Math.round(reconnectDelayMs * 1.5));
|
|
75
|
+
reconnectTimer = setTimeout(() => {
|
|
76
|
+
reconnectTimer = null;
|
|
77
|
+
connectToNativeHost();
|
|
78
|
+
}, delay);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function detachAllLocalTabs() {
|
|
82
|
+
for (const tabId of [...attachedTabIds]) {
|
|
83
|
+
attachedTabIds.delete(tabId);
|
|
84
|
+
try {
|
|
85
|
+
await chrome.debugger.detach({ tabId });
|
|
86
|
+
} catch {
|
|
87
|
+
// ignore already detached tabs
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function disconnectWs(reason = "Disconnected") {
|
|
93
|
+
if (ws) {
|
|
94
|
+
try {
|
|
95
|
+
if (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING) {
|
|
96
|
+
ws.close(1000, reason);
|
|
97
|
+
}
|
|
98
|
+
} catch {
|
|
99
|
+
// ignore
|
|
100
|
+
}
|
|
101
|
+
ws = null;
|
|
102
|
+
}
|
|
103
|
+
void detachAllLocalTabs();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function preferredHostNames() {
|
|
107
|
+
if (chrome.runtime.id === DEV_EXTENSION_ID) {
|
|
108
|
+
return [DEV_NATIVE_HOST, RELEASE_NATIVE_HOST];
|
|
109
|
+
}
|
|
110
|
+
return [RELEASE_NATIVE_HOST];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function connectToNativeHost(hostIndex = 0) {
|
|
114
|
+
clearReconnect();
|
|
115
|
+
if (ws && ws.readyState === WebSocket.OPEN) return;
|
|
116
|
+
const candidates = preferredHostNames();
|
|
117
|
+
if (hostIndex >= candidates.length) {
|
|
118
|
+
uiState.connectionState = "native_not_installed";
|
|
119
|
+
uiState.error = "本机 ufoo Native Messaging Host 未注册";
|
|
120
|
+
stopAutoReconnect = true;
|
|
121
|
+
persistState();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const hostName = candidates[hostIndex];
|
|
126
|
+
try {
|
|
127
|
+
nativePort = chrome.runtime.connectNative(hostName);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
connectToNativeHost(hostIndex + 1);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let receivedMessage = false;
|
|
134
|
+
nativePort.onMessage.addListener((msg) => {
|
|
135
|
+
receivedMessage = true;
|
|
136
|
+
if (!msg || typeof msg !== "object") return;
|
|
137
|
+
if (msg.type === "connect_info" && msg.wsUrl) {
|
|
138
|
+
stopAutoReconnect = false;
|
|
139
|
+
reconnectDelayMs = 2000;
|
|
140
|
+
uiState.hostVersion = msg.hostVersion || "";
|
|
141
|
+
openRelaySocket(msg.wsUrl);
|
|
142
|
+
try { nativePort?.disconnect(); } catch { /* ignore */ }
|
|
143
|
+
nativePort = null;
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (msg.type === "status") {
|
|
147
|
+
uiState.error = msg.error || "";
|
|
148
|
+
if (msg.state === "native_not_installed" || msg.state === "disabled" || msg.state === "protocol_mismatch") {
|
|
149
|
+
uiState.connectionState = msg.state;
|
|
150
|
+
stopAutoReconnect = true;
|
|
151
|
+
disconnectWs(msg.state);
|
|
152
|
+
} else {
|
|
153
|
+
uiState.connectionState = "waiting_for_ufoo";
|
|
154
|
+
stopAutoReconnect = false;
|
|
155
|
+
scheduleReconnect();
|
|
156
|
+
}
|
|
157
|
+
persistState();
|
|
158
|
+
try { nativePort?.disconnect(); } catch { /* ignore */ }
|
|
159
|
+
nativePort = null;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
nativePort.onDisconnect.addListener(() => {
|
|
164
|
+
const errMsg = chrome.runtime.lastError?.message || "";
|
|
165
|
+
nativePort = null;
|
|
166
|
+
if (!receivedMessage) {
|
|
167
|
+
if (hostIndex + 1 < candidates.length) {
|
|
168
|
+
connectToNativeHost(hostIndex + 1);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (errMsg.toLowerCase().includes("not found") || errMsg.toLowerCase().includes("forbidden")) {
|
|
172
|
+
uiState.connectionState = "native_not_installed";
|
|
173
|
+
uiState.error = errMsg;
|
|
174
|
+
stopAutoReconnect = true;
|
|
175
|
+
persistState();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
uiState.connectionState = "waiting_for_ufoo";
|
|
179
|
+
uiState.error = errMsg;
|
|
180
|
+
persistState();
|
|
181
|
+
scheduleReconnect();
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const manifest = chrome.runtime.getManifest();
|
|
186
|
+
nativePort.postMessage({
|
|
187
|
+
type: "hello",
|
|
188
|
+
id: Date.now(),
|
|
189
|
+
extensionId: chrome.runtime.id,
|
|
190
|
+
extensionVersion: manifest.version,
|
|
191
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function openRelaySocket(wsUrl) {
|
|
196
|
+
disconnectWs("Reconnecting");
|
|
197
|
+
const socket = new WebSocket(wsUrl);
|
|
198
|
+
ws = socket;
|
|
199
|
+
|
|
200
|
+
socket.onopen = async () => {
|
|
201
|
+
if (ws !== socket) return;
|
|
202
|
+
let tabs = [];
|
|
203
|
+
try {
|
|
204
|
+
const queried = await chrome.tabs.query({});
|
|
205
|
+
tabs = queried.filter(isSupportedTab).map(summarizeTab);
|
|
206
|
+
} catch {
|
|
207
|
+
tabs = [];
|
|
208
|
+
}
|
|
209
|
+
const manifest = chrome.runtime.getManifest();
|
|
210
|
+
socket.send(JSON.stringify({
|
|
211
|
+
method: "extension.initialized",
|
|
212
|
+
params: {
|
|
213
|
+
extensionId: chrome.runtime.id,
|
|
214
|
+
extensionVersion: manifest.version,
|
|
215
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
216
|
+
tabs,
|
|
217
|
+
},
|
|
218
|
+
}));
|
|
219
|
+
uiState.connectionState = uiState.paused ? "paused" : "connected";
|
|
220
|
+
uiState.error = "";
|
|
221
|
+
persistState();
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
socket.onmessage = async (event) => {
|
|
225
|
+
let msg;
|
|
226
|
+
try {
|
|
227
|
+
msg = JSON.parse(event.data);
|
|
228
|
+
} catch {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (msg.id !== undefined) {
|
|
232
|
+
try {
|
|
233
|
+
const result = await handleBrokerRpc(msg.method, msg.params || []);
|
|
234
|
+
if (ws === socket && socket.readyState === WebSocket.OPEN) {
|
|
235
|
+
socket.send(JSON.stringify({ id: msg.id, result }));
|
|
236
|
+
}
|
|
237
|
+
} catch (error) {
|
|
238
|
+
if (ws === socket && socket.readyState === WebSocket.OPEN) {
|
|
239
|
+
socket.send(JSON.stringify({ id: msg.id, error: error?.message || String(error) }));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (msg.method === "host.state_sync") {
|
|
246
|
+
uiState.paused = Boolean(msg.params?.paused);
|
|
247
|
+
uiState.tabOwners = Array.isArray(msg.params?.tabOwners) ? msg.params.tabOwners : [];
|
|
248
|
+
uiState.connectionState = uiState.paused ? "paused" : "connected";
|
|
249
|
+
persistState();
|
|
250
|
+
} else if (msg.method === "host.disabled") {
|
|
251
|
+
uiState.connectionState = "disabled";
|
|
252
|
+
uiState.tabOwners = [];
|
|
253
|
+
stopAutoReconnect = true;
|
|
254
|
+
persistState();
|
|
255
|
+
disconnectWs("Disabled by host");
|
|
256
|
+
} else if (msg.method === "host.protocol_mismatch") {
|
|
257
|
+
uiState.connectionState = "protocol_mismatch";
|
|
258
|
+
uiState.error = msg.params?.reason || "Protocol version mismatch";
|
|
259
|
+
stopAutoReconnect = true;
|
|
260
|
+
persistState();
|
|
261
|
+
disconnectWs("Protocol mismatch");
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
socket.onclose = () => {
|
|
266
|
+
if (ws !== socket) return;
|
|
267
|
+
ws = null;
|
|
268
|
+
void detachAllLocalTabs();
|
|
269
|
+
uiState.tabOwners = [];
|
|
270
|
+
if (!stopAutoReconnect) {
|
|
271
|
+
uiState.connectionState = "waiting_for_ufoo";
|
|
272
|
+
persistState();
|
|
273
|
+
scheduleReconnect();
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
socket.onerror = () => {};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async function handleBrokerRpc(method, params = []) {
|
|
281
|
+
switch (method) {
|
|
282
|
+
case "ufoo.listTabs": {
|
|
283
|
+
const queried = await chrome.tabs.query({});
|
|
284
|
+
return queried.filter(isSupportedTab).map(summarizeTab);
|
|
285
|
+
}
|
|
286
|
+
case "chrome.tabs.create": {
|
|
287
|
+
const tab = await chrome.tabs.create(params[0] || {});
|
|
288
|
+
return summarizeTab(tab);
|
|
289
|
+
}
|
|
290
|
+
case "chrome.tabs.remove": {
|
|
291
|
+
await chrome.tabs.remove(params[0]);
|
|
292
|
+
return {};
|
|
293
|
+
}
|
|
294
|
+
case "chrome.debugger.attach": {
|
|
295
|
+
const [target, version] = params;
|
|
296
|
+
const tab = await chrome.tabs.get(target.tabId);
|
|
297
|
+
if (!isSupportedTab(tab)) {
|
|
298
|
+
throw new Error("Refusing to attach to internal or incognito Chrome tab");
|
|
299
|
+
}
|
|
300
|
+
await chrome.debugger.attach(target, version || "1.3");
|
|
301
|
+
attachedTabIds.add(target.tabId);
|
|
302
|
+
return {};
|
|
303
|
+
}
|
|
304
|
+
case "chrome.debugger.detach": {
|
|
305
|
+
const [target] = params;
|
|
306
|
+
if (target && target.tabId !== undefined) attachedTabIds.delete(target.tabId);
|
|
307
|
+
await chrome.debugger.detach(target).catch(() => {});
|
|
308
|
+
return {};
|
|
309
|
+
}
|
|
310
|
+
case "chrome.debugger.sendCommand": {
|
|
311
|
+
const [target, cdpMethod, cdpParams] = params;
|
|
312
|
+
return await chrome.debugger.sendCommand(target, cdpMethod, cdpParams);
|
|
313
|
+
}
|
|
314
|
+
default:
|
|
315
|
+
throw new Error(`Unsupported broker RPC: ${method}`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function sendWsNotification(method, params = {}) {
|
|
320
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
321
|
+
try {
|
|
322
|
+
ws.send(JSON.stringify({ method, params }));
|
|
323
|
+
} catch {
|
|
324
|
+
// ignore
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
chrome.tabs.onCreated.addListener((tab) => {
|
|
330
|
+
if (isSupportedTab(tab)) sendWsNotification("chrome.tabs.onCreated", [summarizeTab(tab)]);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
|
334
|
+
if (isSupportedTab(tab)) sendWsNotification("chrome.tabs.onUpdated", [tabId, changeInfo, summarizeTab(tab)]);
|
|
335
|
+
else sendWsNotification("chrome.tabs.onRemoved", [tabId]);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
chrome.tabs.onRemoved.addListener((tabId) => {
|
|
339
|
+
attachedTabIds.delete(tabId);
|
|
340
|
+
sendWsNotification("chrome.tabs.onRemoved", [tabId]);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
chrome.debugger.onEvent.addListener((source, method, params) => {
|
|
344
|
+
sendWsNotification("chrome.debugger.onEvent", [source, method, params]);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
chrome.debugger.onDetach.addListener((source, reason) => {
|
|
348
|
+
if (source && source.tabId !== undefined) attachedTabIds.delete(source.tabId);
|
|
349
|
+
sendWsNotification("chrome.debugger.onDetach", [source, reason]);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => {
|
|
353
|
+
if (!msg || typeof msg !== "object") return false;
|
|
354
|
+
if (msg.type === "ufoo.getStatus") {
|
|
355
|
+
sendResponse({ ...uiState });
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
if (msg.type === "ufoo.pauseAll") {
|
|
359
|
+
uiState.paused = true;
|
|
360
|
+
uiState.connectionState = "paused";
|
|
361
|
+
sendWsNotification("extension.pause_all", {});
|
|
362
|
+
void detachAllLocalTabs();
|
|
363
|
+
persistState();
|
|
364
|
+
sendResponse({ ok: true, ...uiState });
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
if (msg.type === "ufoo.resumeAll") {
|
|
368
|
+
uiState.paused = false;
|
|
369
|
+
uiState.connectionState = ws && ws.readyState === WebSocket.OPEN ? "connected" : "waiting_for_ufoo";
|
|
370
|
+
sendWsNotification("extension.resume_all", {});
|
|
371
|
+
persistState();
|
|
372
|
+
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
|
373
|
+
stopAutoReconnect = false;
|
|
374
|
+
connectToNativeHost();
|
|
375
|
+
}
|
|
376
|
+
sendResponse({ ok: true, ...uiState });
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
if (msg.type === "ufoo.releaseTab") {
|
|
380
|
+
const tabId = Number(msg.tabId);
|
|
381
|
+
if (Number.isInteger(tabId)) {
|
|
382
|
+
attachedTabIds.delete(tabId);
|
|
383
|
+
chrome.debugger.detach({ tabId }).catch(() => {});
|
|
384
|
+
sendWsNotification("extension.release_tab", { tabId });
|
|
385
|
+
}
|
|
386
|
+
sendResponse({ ok: true });
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
if (msg.type === "ufoo.reconnect") {
|
|
390
|
+
stopAutoReconnect = false;
|
|
391
|
+
reconnectDelayMs = 2000;
|
|
392
|
+
connectToNativeHost();
|
|
393
|
+
sendResponse({ ok: true });
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
return false;
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
chrome.runtime.onInstalled.addListener(() => {
|
|
400
|
+
stopAutoReconnect = false;
|
|
401
|
+
connectToNativeHost();
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
chrome.runtime.onStartup.addListener(() => {
|
|
405
|
+
stopAutoReconnect = false;
|
|
406
|
+
connectToNativeHost();
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
connectToNativeHost();
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifest_version": 3,
|
|
3
|
+
"name": "Ufoo",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Connect your daily Chrome tabs to local ufoo and ucode agents without manual tokens or pairing pages.",
|
|
6
|
+
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4xXww7f6Y4sIvjvV0L2Xv/ZxQuyfgmTM9O2dimgSenMRaquoLGovCEEbzyPXQqnbmFEA3CdNwJPa6G5LChuiFdXTVLGECEOThdz4SWFuLrsJTrUD1N5RcN6bkWeW1oNbYjssfvQqr69G4QiSRVBPrwdNLWvoAwkdZJOdvOsLhYimopPUrnd1ga3saGcf9JaT0vH9HYeIE/tf9GOsGZ0LGi/BKdzkD7rUhuglWjFmiPOVTyScwrXfCiPAUZoPybYKBbW3EyUDYjfJAevcJIYLeoz7isYnZpEh4dhb7D5Twnk6PbzEgDjecPfOmDhol+eATkhOeOSG/UKVjU2XWSRDWQIDAQAB",
|
|
7
|
+
"permissions": [
|
|
8
|
+
"debugger",
|
|
9
|
+
"tabs",
|
|
10
|
+
"nativeMessaging",
|
|
11
|
+
"storage"
|
|
12
|
+
],
|
|
13
|
+
"background": {
|
|
14
|
+
"service_worker": "background.js"
|
|
15
|
+
},
|
|
16
|
+
"action": {
|
|
17
|
+
"default_popup": "popup.html",
|
|
18
|
+
"default_title": "Ufoo",
|
|
19
|
+
"default_icon": {
|
|
20
|
+
"16": "icons/toolbar-16.png",
|
|
21
|
+
"32": "icons/toolbar-32.png"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"icons": {
|
|
25
|
+
"16": "icons/icon-16.png",
|
|
26
|
+
"32": "icons/icon-32.png",
|
|
27
|
+
"48": "icons/icon-48.png",
|
|
28
|
+
"128": "icons/icon-128.png"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
color-scheme: light;
|
|
3
|
+
--paper: #f5f4f0; --surface: #fffefa; --ink: #242620; --muted: #686d61; --line: #e6e6dd; --accent: #d95826;
|
|
4
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
|
|
5
|
+
font-size: 13px;
|
|
6
|
+
}
|
|
7
|
+
* { box-sizing: border-box; }
|
|
8
|
+
[hidden] { display: none !important; }
|
|
9
|
+
body { width: 380px; max-height: 600px; overflow-y: auto; margin: 0; background: var(--paper); color: var(--ink); }
|
|
10
|
+
button { font: inherit; }
|
|
11
|
+
button, summary { -webkit-tap-highlight-color: transparent; }
|
|
12
|
+
button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
|
|
13
|
+
.panel { padding: 22px 20px 0; }
|
|
14
|
+
.header, .brand, .connection-top, .section-heading, .footer { display: flex; align-items: center; }
|
|
15
|
+
.header { justify-content: space-between; margin-bottom: 24px; }
|
|
16
|
+
.brand { gap: 10px; }
|
|
17
|
+
.brand-icon { flex-shrink: 0; }
|
|
18
|
+
.wordmark { display: block; font-size: 29px; font-weight: 750; line-height: 1; letter-spacing: -1.5px; }
|
|
19
|
+
.brand-dot { color: var(--accent); }
|
|
20
|
+
.brand-label { display: block; margin-top: 4px; font-size: 9px; color: var(--muted); letter-spacing: .35px; }
|
|
21
|
+
.local-label { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 10px; }
|
|
22
|
+
.local-dot { width: 5px; height: 5px; border-radius: 50%; background: #93978b; }
|
|
23
|
+
.connection { padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
|
|
24
|
+
.connection-top { justify-content: space-between; margin-bottom: 15px; }
|
|
25
|
+
.connection-symbol { width: 36px; height: 29px; stroke: #9c9f92; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
|
|
26
|
+
.badge { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; font-weight: 550; }
|
|
27
|
+
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px #f0f0e9; }
|
|
28
|
+
.badge.connected { color: #397259; }
|
|
29
|
+
.badge.paused { color: #9a6a25; }
|
|
30
|
+
.badge.error { color: #b24635; }
|
|
31
|
+
h1 { margin: 0 0 8px; font-size: 21px; font-weight: 650; letter-spacing: -.6px; line-height: 1.4; }
|
|
32
|
+
.detail { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.75; text-wrap: pretty; }
|
|
33
|
+
.actions { display: flex; gap: 8px; }
|
|
34
|
+
.actions:has(button:not([hidden])) { margin-top: 18px; }
|
|
35
|
+
.btn { min-height: 36px; padding: 8px 13px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; font-weight: 550; font-size: 12px; transition: background .15s, border-color .15s, transform .15s; }
|
|
36
|
+
.btn:active:not(:disabled) { transform: translateY(1px); }
|
|
37
|
+
.btn:disabled { opacity: .55; cursor: wait; }
|
|
38
|
+
.btn-primary { background: var(--ink); color: #fffefa; }
|
|
39
|
+
.btn-primary:hover:not(:disabled) { background: #45483e; }
|
|
40
|
+
.btn-secondary { background: #f0f1e9; color: #4b5144; border-color: #e4e6db; }
|
|
41
|
+
.btn-secondary:hover:not(:disabled) { background: #e6e9dd; border-color: #cdd3c1; }
|
|
42
|
+
.connection-help { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.7; overflow-wrap: anywhere; }
|
|
43
|
+
.connection-help summary { cursor: pointer; }
|
|
44
|
+
.connection-help p { margin: 8px 0 0; }
|
|
45
|
+
.connection-help code { display: block; padding: 8px; margin-top: 8px; background: var(--paper); border-radius: 5px; user-select: all; color: var(--ink); }
|
|
46
|
+
.action-error { padding: 10px 12px; color: #973e2f; background: #f9e9e2; border-radius: 8px; font-size: 12px; line-height: 1.5; }
|
|
47
|
+
.tabs-section { margin-top: 24px; }
|
|
48
|
+
.section-heading { justify-content: space-between; gap: 8px; margin-bottom: 13px; }
|
|
49
|
+
h2 { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 12px; font-weight: 650; }
|
|
50
|
+
.count { min-width: 19px; padding: 2px 5px; text-align: center; background: #e9e9e1; color: #64685b; border-radius: 5px; font-size: 10px; font-variant-numeric: tabular-nums; }
|
|
51
|
+
.section-caption { font-size: 10px; color: var(--muted); }
|
|
52
|
+
.tab-list { margin: 0; padding: 0; list-style: none; max-height: 260px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #cccfc1 transparent; }
|
|
53
|
+
.tab-item { display: flex; align-items: center; gap: 10px; padding: 14px 0; border-top: 1px solid var(--line); }
|
|
54
|
+
.tab-item:first-child { border-top: 0; padding-top: 4px; }
|
|
55
|
+
.tab-symbol { flex: 0 0 30px; width: 30px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; color: #8d9381; }
|
|
56
|
+
.tab-symbol svg { width: 16px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
|
|
57
|
+
.tab-meta { min-width: 0; flex: 1; }
|
|
58
|
+
.tab-owner { margin-bottom: 4px; font-size: 10px; color: #a9512c; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
59
|
+
.tab-title { font-size: 12px; font-weight: 600; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
60
|
+
.tab-url { margin-top: 3px; font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
61
|
+
.btn-release { flex-shrink: 0; min-height: 30px; padding: 5px 9px; border-color: var(--line); background: transparent; color: var(--muted); font-size: 11px; }
|
|
62
|
+
.btn-release:hover:not(:disabled) { background: #f8e7df; border-color: #eac8b8; color: #a94725; }
|
|
63
|
+
.empty { padding: 20px 12px 26px; text-align: center; border: 1px dashed #dcded2; border-radius: 12px; }
|
|
64
|
+
.empty-symbol { width: 57px; height: 47px; stroke: #a9af9b; stroke-width: 1.4; stroke-linecap: round; }
|
|
65
|
+
.empty-symbol rect { fill: var(--paper); }
|
|
66
|
+
.empty h3 { margin: 10px 0 7px; font-size: 12px; font-weight: 550; }
|
|
67
|
+
.empty p { margin: 0; font-size: 11px; color: var(--muted); line-height: 1.8; }
|
|
68
|
+
.footer { gap: 6px; margin-top: 22px; padding: 14px 0; border-top: 1px solid var(--line); font-size: 10px; color: var(--muted); }
|
|
69
|
+
.footer-mark { color: var(--accent); font-size: 15px; }
|
|
70
|
+
.version { margin-left: auto; font-variant-numeric: tabular-nums; }
|
|
71
|
+
@media (prefers-reduced-motion: reduce) { .btn { transition: none; } }
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>ufoo Browser</title>
|
|
7
|
+
<link rel="stylesheet" href="popup.css" />
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<main class="panel">
|
|
11
|
+
<header class="header">
|
|
12
|
+
<div class="brand">
|
|
13
|
+
<img class="brand-icon" src="icons/icon-128.png" width="40" height="40" alt="" />
|
|
14
|
+
<div><span class="wordmark">ufoo<span class="brand-dot">.</span></span><span class="brand-label">Browser companion</span></div>
|
|
15
|
+
</div>
|
|
16
|
+
<span class="local-label"><span class="local-dot"></span>本机连接</span>
|
|
17
|
+
</header>
|
|
18
|
+
<section class="connection" aria-labelledby="status-title" data-state="connecting">
|
|
19
|
+
<div class="connection-top"><span id="status-badge" class="badge" role="status">连接中</span>
|
|
20
|
+
<svg class="connection-symbol" viewBox="0 0 40 32" fill="none" aria-hidden="true"><rect x="3" y="4" width="34" height="24" rx="5"/><path d="M3 11h34M9 8h1m3 0h1M15 19h10m-4-4 4 4-4 4"/></svg>
|
|
21
|
+
</div>
|
|
22
|
+
<h1 id="status-title">正在连接你的浏览器</h1>
|
|
23
|
+
<p id="status-detail" class="detail">正在查找本机 ufoo,请稍候。</p>
|
|
24
|
+
<div class="actions">
|
|
25
|
+
<button id="toggle-pause" class="btn btn-secondary" type="button" hidden>暂停全部控制</button>
|
|
26
|
+
<button id="reconnect" class="btn btn-primary" type="button" hidden>重新连接</button>
|
|
27
|
+
</div>
|
|
28
|
+
<details id="connection-help" class="connection-help" hidden><summary>连接详情与帮助</summary><p id="help-text"></p><code id="help-command" hidden></code><p id="connection-error"></p></details>
|
|
29
|
+
</section>
|
|
30
|
+
<p id="action-error" class="action-error" role="alert" hidden></p>
|
|
31
|
+
<section class="tabs-section" aria-labelledby="tabs-title">
|
|
32
|
+
<div class="section-heading"><h2 id="tabs-title">正在协作的页面 <span id="tab-count" class="count">0</span></h2><span id="project-count" class="section-caption">随时可以释放控制</span></div>
|
|
33
|
+
<ul id="tab-list" class="tab-list"></ul>
|
|
34
|
+
<div id="empty-tabs" class="empty">
|
|
35
|
+
<svg class="empty-symbol" viewBox="0 0 64 52" fill="none" aria-hidden="true"><rect x="9" y="6" width="38" height="30" rx="6"/><rect x="17" y="14" width="38" height="30" rx="6"/><path d="M17 23h38M24 19h1m4 0h1M29 33h14"/></svg>
|
|
36
|
+
<h3 id="empty-title">还没有正在协作的页面</h3>
|
|
37
|
+
<p id="empty-detail">在 ufoo 或 ucode 中发起浏览器任务,<br />正在被操作的页面会显示在这里。</p>
|
|
38
|
+
</div>
|
|
39
|
+
</section>
|
|
40
|
+
<footer class="footer"><span class="footer-mark" aria-hidden="true">↳</span><span>连接你的浏览器,协作由你掌控。</span><span id="version" class="version"></span></footer>
|
|
41
|
+
</main>
|
|
42
|
+
<script src="popup.js"></script>
|
|
43
|
+
</body>
|
|
44
|
+
</html>
|