u-foo 4.0.0 → 4.0.1
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/OBSERVABILITY.md +65 -0
- package/README.md +88 -30
- package/README.zh-CN.md +76 -26
- package/SKILLS/ufoo/SKILL.md +25 -1
- package/SKILLS/ufoo-bus/SKILL.md +25 -2
- package/bin/ufoo.js +3 -3
- 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/package.json +6 -6
- package/src/agents/activity/activityDetector.js +1 -1
- package/src/agents/capabilities/agentManagement/service.js +40 -13
- package/src/agents/capabilities/coordination/index.js +1 -1
- package/src/agents/capabilities/taskReports/index.js +1 -1
- package/src/agents/controller/controllerToolExecutor.js +36 -20
- package/src/agents/controller/index.js +1 -6
- package/src/agents/internal/internalRunner.js +90 -56
- package/src/agents/launch/index.js +0 -1
- package/src/agents/launch/launcher.js +8 -8
- package/src/agents/launch/notifier.js +2 -2
- package/src/agents/launch/readyDetector.js +2 -2
- package/src/agents/profiles/main.js +1 -1
- package/src/agents/prompts/cooperation.js +14 -0
- package/src/agents/prompts/defaultBootstrap.js +1 -1
- package/src/agents/prompts/groupBootstrap.js +23 -7
- package/src/agents/prompts/mainAgent.js +11 -2
- package/src/agents/prompts/native/system.js +4 -1
- package/src/agents/prompts/native/ufoo.js +11 -3
- package/src/agents/prompts/promptProfiles.js +2 -0
- package/src/agents/prompts/reporting.js +16 -0
- package/src/agents/providers/claudeEventTranslator.js +3 -0
- package/src/agents/providers/claudeThreadProvider.js +3 -2
- package/src/agents/providers/clientIdentity.js +75 -0
- package/src/agents/providers/codexEventTranslator.js +23 -2
- package/src/agents/providers/codexThreadProvider.js +15 -6
- package/src/agents/providers/credentials/index.js +2 -0
- package/src/agents/providers/directAuthStatus.js +1 -1
- package/src/agents/providers/index.js +1 -1
- package/src/agents/providers/modelSettings.js +34 -0
- package/src/agents/providers/modelsCatalog.js +379 -0
- package/src/agents/providers/nativeTransport.js +50 -39
- package/src/agents/providers/runtimeConfig.js +10 -8
- package/src/agents/providers/thinkingLevels.js +10 -36
- package/src/agents/providers/transports/responsesProtocol.js +11 -6
- package/src/agents/providers/upstreamRuntime.js +135 -0
- package/src/agents/runtime/context/checkpointStore.js +38 -0
- package/src/agents/runtime/context/compaction.js +151 -0
- package/src/agents/runtime/context/contextBudget.js +93 -0
- package/src/agents/runtime/context/replayHistory.js +28 -0
- package/src/agents/runtime/context/runtimeStore.js +2 -1
- package/src/agents/runtime/core/agentLoop.js +99 -18
- package/src/agents/runtime/core/executionBudget.js +36 -0
- package/src/agents/runtime/createAgentRuntime.js +16 -4
- package/src/agents/runtime/prompts/responseLanguage.js +12 -0
- package/src/agents/runtime/protocol/runObservation.js +24 -0
- package/src/agents/runtime/protocol/traceContext.js +9 -0
- package/src/app/chat/ChatController.js +26 -53
- package/src/app/chat/agentDirectory.js +1 -16
- package/src/app/chat/bootstrap.js +1 -2
- package/src/app/chat/commandExecutor.js +93 -285
- package/src/app/chat/commands.js +32 -45
- package/src/app/chat/daemonMessageRouter.js +0 -45
- package/src/app/chat/historyStore.js +12 -48
- package/src/app/chat/inputSubmitHandler.js +7 -33
- package/src/app/chat/internalAgentLogHistory.js +19 -60
- package/src/app/chat/multiWindow/paneManager.js +10 -3
- package/src/app/chat/streamState.js +0 -4
- package/src/app/cli/features/init.js +5 -5
- package/src/app/cli/metricsCommands.js +68 -0
- package/src/app/cli/run.js +42 -3
- package/src/app/cli/traceCommands.js +36 -0
- package/src/code/agent.js +18 -13
- package/src/code/busConsumer.js +1 -3
- package/src/code/commands.js +1 -1
- package/src/code/context/assembler.js +7 -8
- package/src/code/context/stateCommit.js +2 -1
- package/src/code/internalThread.js +10 -3
- package/src/code/launcher/ucode.js +1 -1
- package/src/code/launcher/ucodeBootstrap.js +1 -1
- package/src/code/modelCommand.js +11 -35
- package/src/code/nativeRunner.js +55 -17
- package/src/code/providers/modelsCatalog.js +1 -317
- package/src/code/repl.js +2 -11
- package/src/code/sessionStore.js +3 -3
- package/src/code/taskDecomposer.js +18 -0
- package/src/code/toolBudget.js +1 -17
- package/src/config.js +22 -72
- package/src/coordination/bus/index.js +12 -3
- package/src/coordination/bus/inject.js +2 -2
- package/src/coordination/bus/message.js +15 -1
- package/src/coordination/bus/nickname.js +1 -1
- package/src/coordination/bus/subscriber.js +3 -2
- package/src/coordination/bus/utils.js +1 -1
- package/src/coordination/history/agentPerformance.js +279 -0
- package/src/coordination/history/agentTrace.js +249 -0
- package/src/coordination/state/workspaceAccess.js +1 -1
- package/src/orchestration/controller/index.js +1 -8
- package/src/orchestration/controller/launchRouting.js +1 -1
- package/src/orchestration/solo/commands.js +3 -1
- package/src/runtime/contracts/agentMode.js +11 -2
- package/src/runtime/contracts/uiProtocol.js +18 -19
- package/src/runtime/daemon/agentHost.js +57 -25
- package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
- package/src/runtime/daemon/busBridge.js +1 -1
- package/src/runtime/daemon/controlPlaneService.js +1 -1
- package/src/runtime/daemon/groupOrchestrator.js +20 -5
- package/src/runtime/daemon/groupStatus.js +20 -0
- package/src/runtime/daemon/index.js +19 -44
- package/src/runtime/daemon/mcpServer.js +1 -1
- package/src/runtime/daemon/nicknameScope.js +1 -1
- package/src/runtime/daemon/ops.js +46 -23
- package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
- package/src/runtime/daemon/promptRequest.js +92 -589
- package/src/runtime/daemon/status.js +5 -6
- package/src/tools/controllerSchemas.js +6 -2
- package/src/tools/handlers/tier2.js +4 -2
- package/src/tools/registry.js +4 -0
- package/src/tools/schemaFixtures.js +26 -2
- package/src/tools/tier0/readAgentMetrics.js +14 -0
- package/src/tools/tier0/readAgentTrace.js +12 -0
- package/src/ui/agentSettingsController.js +107 -0
- package/src/ui/agentSurface.js +1 -1
- package/src/ui/dashboardBridge.js +1 -1
- package/src/ui/format/banner.js +1 -4
- package/src/ui/format/index.js +14 -10
- package/src/ui/format/loopSummary.js +50 -0
- package/src/ui/format/markdownRenderer.js +3 -4
- package/src/ui/rustChatHost.js +191 -206
- package/src/ui/rustMultiSession.js +77 -36
- package/src/ui/rustUcodeHost.js +1 -1
- package/src/ui/settingsBridge.js +33 -16
- package/src/ui/toolMergeBridge.js +0 -4
- package/src/ui/uiHostServer.js +5 -8
- package/src/agents/controller/loopObservability.js +0 -200
- package/src/agents/controller/loopRuntime.js +0 -336
- package/src/agents/controller/ufooAgent.js +0 -830
- package/src/agents/launch/ptyRunner.js +0 -1135
- package/src/agents/providers/controllerJsonTransport.js +0 -28
- package/src/agents/providers/upstreamTransport.js +0 -698
- package/src/app/chat/agentBar.js +0 -135
- package/src/app/chat/agentSockets.js +0 -225
- package/src/app/chat/dashboardView.js +0 -405
- package/src/app/chat/rawKeyMap.js +0 -42
- package/src/app/chat/settingsController.js +0 -111
- package/src/coordination/history/controllerSummary.js +0 -23
- package/src/orchestration/controller/flags.js +0 -167
- package/src/orchestration/controller/gateRouter.js +0 -211
- package/src/orchestration/controller/routerFastPath.js +0 -22
- package/src/orchestration/controller/routerFinalize.js +0 -222
- package/src/orchestration/controller/shadowGuard.js +0 -280
- package/src/runtime/daemon/executionPaths.js +0 -30
- package/src/runtime/daemon/promptLoop.js +0 -136
- package/src/runtime/privacy/shadowDiff.js +0 -174
package/src/app/chat/agentBar.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
const { stripAnsi, truncateAnsi } = require("./text");
|
|
2
|
-
|
|
3
|
-
const ACTIVITY_INDICATORS = {
|
|
4
|
-
working: "*",
|
|
5
|
-
waiting_input: "?",
|
|
6
|
-
blocked: "!",
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const ACTIVITY_COLORS = {
|
|
10
|
-
waiting_input: "\x1b[33m", // yellow
|
|
11
|
-
blocked: "\x1b[31m", // red
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
function computeAgentBar(options = {}) {
|
|
15
|
-
const {
|
|
16
|
-
cols = 80,
|
|
17
|
-
hintText = "",
|
|
18
|
-
focusMode = "input",
|
|
19
|
-
selectedAgentIndex = -1,
|
|
20
|
-
activeAgents = [],
|
|
21
|
-
viewingAgent = null,
|
|
22
|
-
agentListWindowStart = 0,
|
|
23
|
-
maxAgentWindow = 4,
|
|
24
|
-
getAgentLabel = (id) => id,
|
|
25
|
-
agentStates = {},
|
|
26
|
-
} = options;
|
|
27
|
-
|
|
28
|
-
const hintAnsi = `\x1b[90m│ ${hintText}\x1b[0m`;
|
|
29
|
-
const selectionIndex = focusMode === "dashboard"
|
|
30
|
-
? (selectedAgentIndex > 0 ? selectedAgentIndex - 1 : -1)
|
|
31
|
-
: activeAgents.indexOf(viewingAgent);
|
|
32
|
-
const maxAgentLen = Math.max(0, cols - 1 - 2 - stripAnsi(hintAnsi).length);
|
|
33
|
-
let windowItems = Math.max(1, Math.min(maxAgentWindow, activeAgents.length));
|
|
34
|
-
let start = agentListWindowStart;
|
|
35
|
-
const ufooItem = focusMode === "dashboard" && selectedAgentIndex === 0
|
|
36
|
-
? "\x1b[90;7mufoo\x1b[0m"
|
|
37
|
-
: "\x1b[36mufoo\x1b[0m";
|
|
38
|
-
const ufooLen = stripAnsi(ufooItem).length;
|
|
39
|
-
|
|
40
|
-
const computeStart = (items) => {
|
|
41
|
-
if (activeAgents.length === 0) return 0;
|
|
42
|
-
let s = start;
|
|
43
|
-
if (selectionIndex >= 0) {
|
|
44
|
-
if (selectionIndex < s) {
|
|
45
|
-
s = selectionIndex;
|
|
46
|
-
} else if (selectionIndex >= s + items) {
|
|
47
|
-
s = selectionIndex - items + 1;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const maxStart = Math.max(0, activeAgents.length - items);
|
|
51
|
-
if (s > maxStart) s = maxStart;
|
|
52
|
-
if (s < 0) s = 0;
|
|
53
|
-
return s;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const truncateLabel = (label, maxLen) => {
|
|
57
|
-
const text = String(label || "");
|
|
58
|
-
if (maxLen <= 0) return "";
|
|
59
|
-
if (text.length <= maxLen) return text;
|
|
60
|
-
if (maxLen <= 3) return text.slice(0, maxLen);
|
|
61
|
-
return `${text.slice(0, maxLen - 3)}...`;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const buildAgentSegment = (items, maxLabelLen) => {
|
|
65
|
-
const s = computeStart(items);
|
|
66
|
-
const e = s + items;
|
|
67
|
-
const visible = activeAgents.slice(s, e);
|
|
68
|
-
const leftMore = s > 0 ? "\x1b[90m<\x1b[0m " : "";
|
|
69
|
-
const rightMore = e < activeAgents.length ? " \x1b[90m>\x1b[0m" : "";
|
|
70
|
-
let agentParts = [];
|
|
71
|
-
if (activeAgents.length > 0) {
|
|
72
|
-
agentParts = visible.map((agent, i) => {
|
|
73
|
-
const rawLabel = getAgentLabel(agent);
|
|
74
|
-
const label = maxLabelLen ? truncateLabel(rawLabel, maxLabelLen) : rawLabel;
|
|
75
|
-
const actState = agentStates[agent] || "";
|
|
76
|
-
const indicator = ACTIVITY_INDICATORS[actState] || "";
|
|
77
|
-
const indicatorColor = ACTIVITY_COLORS[actState] || "";
|
|
78
|
-
const prefix = indicator
|
|
79
|
-
? `${indicatorColor}${indicator}\x1b[0m`
|
|
80
|
-
: "";
|
|
81
|
-
const idx = s + i + 1; // +1 for ufoo chat at index 0
|
|
82
|
-
if (focusMode === "dashboard" && idx === selectedAgentIndex) {
|
|
83
|
-
return `${prefix}\x1b[90;7m${label}\x1b[0m`;
|
|
84
|
-
}
|
|
85
|
-
if (agent === viewingAgent) return `${prefix}\x1b[1;36m${label}\x1b[0m`;
|
|
86
|
-
return `${prefix}\x1b[36m${label}\x1b[0m`;
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
const agentsText = activeAgents.length > 0
|
|
90
|
-
? `${leftMore}${agentParts.join(" ")}${rightMore}`
|
|
91
|
-
: "\x1b[36mnone\x1b[0m";
|
|
92
|
-
return { segment: `${ufooItem} ${agentsText}`, start: s };
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
let segmentInfo = buildAgentSegment(windowItems, 0);
|
|
96
|
-
while (windowItems > 0) {
|
|
97
|
-
const s = computeStart(windowItems);
|
|
98
|
-
const e = s + windowItems;
|
|
99
|
-
const hasLeft = s > 0;
|
|
100
|
-
const hasRight = e < activeAgents.length;
|
|
101
|
-
const spacingLen = windowItems > 1 ? (windowItems - 1) * 2 : 0;
|
|
102
|
-
const overhead = ufooLen + 2 + (hasLeft ? 2 : 0) + (hasRight ? 2 : 0) + spacingLen;
|
|
103
|
-
const available = maxAgentLen - overhead;
|
|
104
|
-
let maxLabelLen = windowItems > 0 ? Math.floor(available / windowItems) : 0;
|
|
105
|
-
if (windowItems > 1 && maxLabelLen < 3) {
|
|
106
|
-
windowItems -= 1;
|
|
107
|
-
segmentInfo = buildAgentSegment(windowItems, 0);
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
if (maxLabelLen < 1) maxLabelLen = 1;
|
|
111
|
-
segmentInfo = buildAgentSegment(windowItems, maxLabelLen);
|
|
112
|
-
if (stripAnsi(segmentInfo.segment).length <= maxAgentLen || windowItems === 1) break;
|
|
113
|
-
windowItems -= 1;
|
|
114
|
-
segmentInfo = buildAgentSegment(windowItems, 0);
|
|
115
|
-
}
|
|
116
|
-
start = segmentInfo.start;
|
|
117
|
-
const agentSegment = segmentInfo.segment;
|
|
118
|
-
|
|
119
|
-
let bar = ` ${agentSegment} ${hintAnsi}`;
|
|
120
|
-
let barLen = stripAnsi(bar).length;
|
|
121
|
-
if (barLen > cols) {
|
|
122
|
-
bar = truncateAnsi(bar, cols);
|
|
123
|
-
barLen = stripAnsi(bar).length;
|
|
124
|
-
}
|
|
125
|
-
const pad = Math.max(0, cols - barLen);
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
bar: `${bar}${" ".repeat(pad)}`,
|
|
129
|
-
windowStart: start,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
module.exports = {
|
|
134
|
-
computeAgentBar,
|
|
135
|
-
};
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const net = require("net");
|
|
3
|
-
const { PTY_SOCKET_MESSAGE_TYPES, PTY_SOCKET_SUBSCRIBE_MODES } = require("../../runtime/contracts/ptySocketContract");
|
|
4
|
-
|
|
5
|
-
function createAgentSockets(options = {}) {
|
|
6
|
-
const {
|
|
7
|
-
onTermWrite = () => {},
|
|
8
|
-
onPlaceCursor = () => {},
|
|
9
|
-
isAgentView = () => false,
|
|
10
|
-
isBusMode = () => false,
|
|
11
|
-
getViewingAgent = () => "",
|
|
12
|
-
sendBusRaw = () => {},
|
|
13
|
-
} = options;
|
|
14
|
-
|
|
15
|
-
let outputClient = null;
|
|
16
|
-
let outputBuffer = "";
|
|
17
|
-
let inputClient = null;
|
|
18
|
-
let pendingResize = null;
|
|
19
|
-
|
|
20
|
-
function requestSnapshot(mode = PTY_SOCKET_SUBSCRIBE_MODES.SCREEN) {
|
|
21
|
-
if (!outputClient || outputClient.destroyed) return false;
|
|
22
|
-
const safeMode = mode === PTY_SOCKET_SUBSCRIBE_MODES.FULL
|
|
23
|
-
? PTY_SOCKET_SUBSCRIBE_MODES.FULL
|
|
24
|
-
: PTY_SOCKET_SUBSCRIBE_MODES.SCREEN;
|
|
25
|
-
try {
|
|
26
|
-
outputClient.write(JSON.stringify({
|
|
27
|
-
type: PTY_SOCKET_MESSAGE_TYPES.SUBSCRIBE,
|
|
28
|
-
mode: safeMode,
|
|
29
|
-
}) + "\n");
|
|
30
|
-
return true;
|
|
31
|
-
} catch {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function requestScreenSnapshot() {
|
|
37
|
-
return requestSnapshot(PTY_SOCKET_SUBSCRIBE_MODES.SCREEN);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function connectOutput(sockPath) {
|
|
41
|
-
if (outputClient) {
|
|
42
|
-
disconnectOutput();
|
|
43
|
-
}
|
|
44
|
-
outputBuffer = "";
|
|
45
|
-
|
|
46
|
-
if (!fs.existsSync(sockPath)) {
|
|
47
|
-
onTermWrite("\x1b[1;31m[Error]\x1b[0m inject.sock not found\r\n");
|
|
48
|
-
onTermWrite("\x1b[33m[Hint]\x1b[0m Agent may not be running in terminal mode\r\n");
|
|
49
|
-
onTermWrite("Press Esc to return\r\n");
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
outputClient = net.createConnection(sockPath, () => {
|
|
55
|
-
outputClient.write(JSON.stringify({
|
|
56
|
-
type: PTY_SOCKET_MESSAGE_TYPES.SUBSCRIBE,
|
|
57
|
-
mode: PTY_SOCKET_SUBSCRIBE_MODES.FULL,
|
|
58
|
-
}) + "\n");
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const connectTimeout = setTimeout(() => {
|
|
62
|
-
if (outputClient && !outputClient.connecting) return;
|
|
63
|
-
onTermWrite("\x1b[1;31m[Timeout]\x1b[0m Could not connect\r\nPress Esc to return\r\n");
|
|
64
|
-
disconnectOutput();
|
|
65
|
-
}, 5000);
|
|
66
|
-
|
|
67
|
-
outputClient.on("connect", () => {
|
|
68
|
-
clearTimeout(connectTimeout);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
outputClient.on("data", (data) => {
|
|
72
|
-
outputBuffer += data.toString("utf8");
|
|
73
|
-
const lines = outputBuffer.split("\n");
|
|
74
|
-
outputBuffer = lines.pop() || "";
|
|
75
|
-
|
|
76
|
-
for (const line of lines) {
|
|
77
|
-
if (!line.trim()) continue;
|
|
78
|
-
try {
|
|
79
|
-
const msg = JSON.parse(line);
|
|
80
|
-
if (msg.type === PTY_SOCKET_MESSAGE_TYPES.OUTPUT) {
|
|
81
|
-
if (msg.data) onTermWrite(msg.data);
|
|
82
|
-
} else if (msg.type === PTY_SOCKET_MESSAGE_TYPES.REPLAY ||
|
|
83
|
-
msg.type === PTY_SOCKET_MESSAGE_TYPES.SNAPSHOT) {
|
|
84
|
-
if (msg.data) onTermWrite(msg.data);
|
|
85
|
-
if (msg.type === PTY_SOCKET_MESSAGE_TYPES.SNAPSHOT && msg.cursor) {
|
|
86
|
-
onPlaceCursor(msg.cursor);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} catch {
|
|
90
|
-
// ignore malformed messages
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
outputClient.on("error", (err) => {
|
|
96
|
-
if (isAgentView()) {
|
|
97
|
-
onTermWrite(`\r\n\x1b[1;31m[Connection error]\x1b[0m ${err.message}\r\nPress Esc to return\r\n`);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
outputClient.on("close", () => {
|
|
102
|
-
outputClient = null;
|
|
103
|
-
if (isAgentView()) {
|
|
104
|
-
onTermWrite("\r\n\x1b[1;33m[Agent disconnected]\x1b[0m\r\nPress Esc to return\r\n");
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
} catch (err) {
|
|
108
|
-
onTermWrite(`\x1b[1;31m[Error]\x1b[0m ${err.message}\r\nPress Esc to return\r\n`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function disconnectOutput() {
|
|
113
|
-
if (outputClient) {
|
|
114
|
-
try {
|
|
115
|
-
outputClient.removeAllListeners();
|
|
116
|
-
outputClient.destroy();
|
|
117
|
-
} catch {
|
|
118
|
-
// ignore
|
|
119
|
-
}
|
|
120
|
-
outputClient = null;
|
|
121
|
-
}
|
|
122
|
-
outputBuffer = "";
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function connectInput(sockPath) {
|
|
126
|
-
if (inputClient) {
|
|
127
|
-
disconnectInput();
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
inputClient = net.createConnection(sockPath);
|
|
131
|
-
inputClient.on("connect", () => {
|
|
132
|
-
if (pendingResize) {
|
|
133
|
-
const { cols, rows } = pendingResize;
|
|
134
|
-
pendingResize = null;
|
|
135
|
-
try {
|
|
136
|
-
inputClient.write(JSON.stringify({
|
|
137
|
-
type: PTY_SOCKET_MESSAGE_TYPES.RESIZE,
|
|
138
|
-
cols,
|
|
139
|
-
rows,
|
|
140
|
-
}) + "\n");
|
|
141
|
-
} catch {
|
|
142
|
-
// ignore write errors
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
inputClient.on("error", () => {
|
|
147
|
-
inputClient = null;
|
|
148
|
-
});
|
|
149
|
-
inputClient.on("close", () => {
|
|
150
|
-
inputClient = null;
|
|
151
|
-
});
|
|
152
|
-
} catch {
|
|
153
|
-
inputClient = null;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function disconnectInput() {
|
|
158
|
-
if (inputClient) {
|
|
159
|
-
try {
|
|
160
|
-
inputClient.removeAllListeners();
|
|
161
|
-
inputClient.destroy();
|
|
162
|
-
} catch {
|
|
163
|
-
// ignore
|
|
164
|
-
}
|
|
165
|
-
inputClient = null;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function sendRaw(data) {
|
|
170
|
-
if (inputClient && !inputClient.destroyed) {
|
|
171
|
-
try {
|
|
172
|
-
inputClient.write(JSON.stringify({
|
|
173
|
-
type: PTY_SOCKET_MESSAGE_TYPES.RAW,
|
|
174
|
-
data,
|
|
175
|
-
}) + "\n");
|
|
176
|
-
return;
|
|
177
|
-
} catch {
|
|
178
|
-
// ignore write errors
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
if (isBusMode()) {
|
|
182
|
-
const viewingAgent = getViewingAgent();
|
|
183
|
-
if (viewingAgent) {
|
|
184
|
-
sendBusRaw(viewingAgent, data);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function sendResize(cols, rows) {
|
|
190
|
-
if (!inputClient || inputClient.destroyed) {
|
|
191
|
-
pendingResize = { cols, rows };
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
try {
|
|
195
|
-
inputClient.write(JSON.stringify({
|
|
196
|
-
type: PTY_SOCKET_MESSAGE_TYPES.RESIZE,
|
|
197
|
-
cols,
|
|
198
|
-
rows,
|
|
199
|
-
}) + "\n");
|
|
200
|
-
} catch {
|
|
201
|
-
// ignore write errors
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function disconnectAll() {
|
|
206
|
-
disconnectOutput();
|
|
207
|
-
disconnectInput();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return {
|
|
211
|
-
connectOutput,
|
|
212
|
-
disconnectOutput,
|
|
213
|
-
connectInput,
|
|
214
|
-
disconnectInput,
|
|
215
|
-
disconnectAll,
|
|
216
|
-
sendRaw,
|
|
217
|
-
sendResize,
|
|
218
|
-
requestSnapshot,
|
|
219
|
-
requestScreenSnapshot,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
module.exports = {
|
|
224
|
-
createAgentSockets,
|
|
225
|
-
};
|