feat: initial Cutdex application

Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
This commit is contained in:
lingjhf committed 2026-10-05 23:36:23 +08:00
commit 27e77fff39
718 files changed
+183958

No files matched your search

@@ -0,0 +1,98 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:cutdex_sdk/mcp.dart';
/// Private loopback transport for the stdio launcher. This is not an MCP HTTP
/// endpoint. The first line authenticates; remaining bytes are MCP stdio frames.
class LocalMcpBridge {
LocalMcpBridge._(this._listener, this._server, this._token) {
_listener.listen(_accept);
}
final ServerSocket _listener;
final CutdexMcpServer _server;
final String _token;
final _sockets = <Socket>{};
final _sessions = <Future<void>>{};
bool _closed = false;
int get port => _listener.port;
static Future<LocalMcpBridge> start(
CutdexMcpServer server, {
required int port,
required String token,
}) async {
if (port < 0 ||
port > 65535 ||
token.length < 32 ||
token.length > 1024 ||
token.contains('\n') ||
token.contains('\r')) {
throw ArgumentError(
'MCP requires a valid port and a 32-1024 character token',
);
}
final socket = await ServerSocket.bind(InternetAddress.loopbackIPv4, port);
return LocalMcpBridge._(socket, server, token);
}
void _accept(Socket socket) {
if (_closed || _sockets.length >= 32) {
socket.destroy();
return;
}
_sockets.add(socket);
final task = _serve(socket);
_sessions.add(task);
unawaited(
task.whenComplete(() {
_sessions.remove(task);
}),
);
}
Future<void> _serve(Socket socket) async {
final input = StreamIterator<List<int>>(socket);
try {
final bytes = <int>[];
final deadline = DateTime.now().add(const Duration(seconds: 5));
while (await input.moveNext().timeout(
deadline.difference(DateTime.now()),
)) {
final chunk = input.current;
final newline = chunk.indexOf(10);
final count = newline < 0 ? chunk.length : newline;
if (bytes.length + count > 4096) return;
bytes.addAll(chunk.take(count));
if (newline < 0) continue;
if (utf8.decode(bytes) != _token) return;
Stream<List<int>> frames() async* {
if (newline + 1 < chunk.length) yield chunk.sublist(newline + 1);
while (await input.moveNext()) {
yield input.current;
}
}
await serveMcpStdio(_server, input: frames(), output: socket);
return;
}
} catch (_) {
// Transport failures end this connection, not the project or other clients.
} finally {
socket.destroy();
await input.cancel();
_sockets.remove(socket);
}
}
Future<void> close() async {
if (_closed) return;
_closed = true;
await _listener.close();
for (final socket in _sockets.toList()) {
socket.destroy();
}
await Future.wait(_sessions.toList());
}
}