@hellolynk-ai/trae-work-mcp 0.0.0-stage → 0.4.94

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.
Files changed (123) hide show
  1. package/LICENSE +92 -0
  2. package/README.md +86 -2
  3. package/bin/hellolynk-client-setup.mjs +2748 -0
  4. package/bin/hellolynk-mcp-config-shape.mjs +23 -0
  5. package/hellolynk-client-pack-manifest.json +619 -0
  6. package/hellolynk-client-pack-pin.json +4 -0
  7. package/integrations/trae-work/package.json +11 -0
  8. package/integrations/trae-work/runtime/neutral-host-bootstrap.mjs +38 -0
  9. package/integrations/trae-work/runtime/neutral-host-release-entry.mjs +16 -0
  10. package/integrations/trae-work/runtime/trae-work-bootstrap.mjs +30 -0
  11. package/integrations/trae-work/server/dynamic-ui-contract.mjs +376 -0
  12. package/integrations/trae-work/server/host-lifecycle.mjs +128 -0
  13. package/integrations/trae-work/server/mcp-proxy.mjs +181 -0
  14. package/integrations/trae-work/server/mcp-server.mjs +784 -0
  15. package/integrations/trae-work/server/native-task-cdp.mjs +241 -0
  16. package/integrations/trae-work/server/native-task-worker.mjs +199 -0
  17. package/integrations/trae-work/server/neutral-host-adapter.mjs +725 -0
  18. package/integrations/trae-work/server/trae-neutral-production.mjs +97 -0
  19. package/integrations/trae-work/server/trae-ui-launch.mjs +182 -0
  20. package/integrations/trae-work/server/ui-action-gate.mjs +122 -0
  21. package/integrations/trae-work/skills/hellolynk-inbox/SKILL.md +9 -0
  22. package/package.json +61 -4
  23. package/runtime/bootstrap/core/hellolynk-client-account.mjs +180 -0
  24. package/runtime/bootstrap/core/hellolynk-client-core.mjs +770 -0
  25. package/runtime/bootstrap/core/hellolynk-client-profile.mjs +191 -0
  26. package/runtime/bootstrap/core/hellolynk-host-auth.mjs +347 -0
  27. package/runtime/bootstrap/core/hellolynk-host-protected-store.mjs +2721 -0
  28. package/runtime/bootstrap/core/hellolynk-local-process-lock.mjs +157 -0
  29. package/runtime/bootstrap/core/hellolynk-neutral-host-installation-store.mjs +765 -0
  30. package/runtime/bootstrap/core/hellolynk-platform-credential-store.mjs +773 -0
  31. package/runtime/bootstrap/core/hellolynk-runtime-safety.cjs +471 -0
  32. package/runtime/bootstrap/platform/windows/hellolynk-host-protected-store.ps1 +2866 -0
  33. package/runtime/connect-activate.mjs +837 -0
  34. package/runtime/core/hellolynk-agent-configurator.mjs +701 -0
  35. package/runtime/core/hellolynk-client-account.mjs +180 -0
  36. package/runtime/core/hellolynk-client-core.mjs +770 -0
  37. package/runtime/core/hellolynk-client-profile.mjs +191 -0
  38. package/runtime/core/hellolynk-client-update-entry.mjs +31 -0
  39. package/runtime/core/hellolynk-client-update-runtime.mjs +600 -0
  40. package/runtime/core/hellolynk-client-update.mjs +453 -0
  41. package/runtime/core/hellolynk-contact-request-e2ee.mjs +867 -0
  42. package/runtime/core/hellolynk-device-enrollment.mjs +435 -0
  43. package/runtime/core/hellolynk-direct-text-e2ee-client.mjs +1964 -0
  44. package/runtime/core/hellolynk-direct-text-e2ee.mjs +1207 -0
  45. package/runtime/core/hellolynk-host-auth.mjs +347 -0
  46. package/runtime/core/hellolynk-host-protected-store.mjs +2721 -0
  47. package/runtime/core/hellolynk-host-transport-client.mjs +946 -0
  48. package/runtime/core/hellolynk-host.mjs +2374 -0
  49. package/runtime/core/hellolynk-human-confirmation-ledger.mjs +256 -0
  50. package/runtime/core/hellolynk-human-relationship-controller.mjs +1234 -0
  51. package/runtime/core/hellolynk-inbox-read-state.mjs +11 -0
  52. package/runtime/core/hellolynk-indexed-message-store.mjs +1558 -0
  53. package/runtime/core/hellolynk-instance-conversation.mjs +185 -0
  54. package/runtime/core/hellolynk-local-contact-requests.mjs +1733 -0
  55. package/runtime/core/hellolynk-local-contacts.mjs +1228 -0
  56. package/runtime/core/hellolynk-local-data-migration.mjs +766 -0
  57. package/runtime/core/hellolynk-local-data-protection.mjs +747 -0
  58. package/runtime/core/hellolynk-local-identity-trust.mjs +274 -0
  59. package/runtime/core/hellolynk-local-messaging.mjs +3043 -0
  60. package/runtime/core/hellolynk-local-peer-transport.mjs +103 -0
  61. package/runtime/core/hellolynk-local-process-lock.mjs +157 -0
  62. package/runtime/core/hellolynk-model-inbox.mjs +230 -0
  63. package/runtime/core/hellolynk-model-notices.cjs +60 -0
  64. package/runtime/core/hellolynk-native-addressing-tools.cjs +231 -0
  65. package/runtime/core/hellolynk-native-conversations.mjs +280 -0
  66. package/runtime/core/hellolynk-native-human-confirmation-broker.mjs +1036 -0
  67. package/runtime/core/hellolynk-native-inbox-runtime.mjs +553 -0
  68. package/runtime/core/hellolynk-native-notice.mjs +50 -0
  69. package/runtime/core/hellolynk-native-reply-routes.mjs +96 -0
  70. package/runtime/core/hellolynk-native-worker-lease.mjs +84 -0
  71. package/runtime/core/hellolynk-neutral-host-assembly.mjs +955 -0
  72. package/runtime/core/hellolynk-neutral-host-installation-store.mjs +765 -0
  73. package/runtime/core/hellolynk-neutral-host-launcher.mjs +665 -0
  74. package/runtime/core/hellolynk-neutral-host-process.mjs +4374 -0
  75. package/runtime/core/hellolynk-neutral-host-store-adapters.mjs +548 -0
  76. package/runtime/core/hellolynk-neutral-host-workbench-read-model.mjs +1365 -0
  77. package/runtime/core/hellolynk-platform-credential-store.mjs +773 -0
  78. package/runtime/core/hellolynk-relay-client-cli.mjs +232 -0
  79. package/runtime/core/hellolynk-release-retention.mjs +160 -0
  80. package/runtime/core/hellolynk-runtime-safety.cjs +471 -0
  81. package/runtime/core/hellolynk-workbench-action-grants.mjs +457 -0
  82. package/runtime/core/hellolynk-workbench-connection.mjs +234 -0
  83. package/runtime/neutral-host-bootstrap.mjs +38 -0
  84. package/runtime/neutral-host-release-entry.mjs +16 -0
  85. package/runtime/neutral-host-release-loader.mjs +156 -0
  86. package/runtime/neutral-host-release-manifest.json +394 -0
  87. package/runtime/neutral-host-release-pin.json +4 -0
  88. package/runtime/platform/windows/configure-agent.ps1 +281 -0
  89. package/runtime/platform/windows/credential-store.ps1 +844 -0
  90. package/runtime/platform/windows/hellolynk-host-protected-store.ps1 +2866 -0
  91. package/runtime/platform/windows/hellolynk-human-confirmation-ledger.ps1 +155 -0
  92. package/runtime/platform/windows/hellolynk-local-data-key.ps1 +300 -0
  93. package/runtime/platform/windows/hellolynk-native-human-confirmation-broker.ps1 +216 -0
  94. package/runtime/trae-work-bootstrap.mjs +30 -0
  95. package/runtime/workbench/candidate-bootstrap.mjs +54 -0
  96. package/runtime/workbench/contract.mjs +1314 -0
  97. package/runtime/workbench/hellolynk-workbench-build.json +215 -0
  98. package/runtime/workbench/host-capabilities.mjs +80 -0
  99. package/runtime/workbench/i18n.mjs +1127 -0
  100. package/runtime/workbench/loopback-surface.mjs +740 -0
  101. package/runtime/workbench/mcp-app-bundle.mjs +97 -0
  102. package/runtime/workbench/service.mjs +485 -0
  103. package/runtime/workbench/state.mjs +421 -0
  104. package/runtime/workbench/transports.mjs +171 -0
  105. package/runtime/workbench/ui/app.mjs +6120 -0
  106. package/runtime/workbench/ui/connection-form.mjs +155 -0
  107. package/runtime/workbench/ui/hellolynk-mark.png +0 -0
  108. package/runtime/workbench/ui/http-transport.mjs +247 -0
  109. package/runtime/workbench/ui/icons/arrow-left.svg +3 -0
  110. package/runtime/workbench/ui/icons/close.svg +3 -0
  111. package/runtime/workbench/ui/icons/contacts.svg +3 -0
  112. package/runtime/workbench/ui/icons/inbox.svg +3 -0
  113. package/runtime/workbench/ui/icons/refresh.svg +3 -0
  114. package/runtime/workbench/ui/icons/search.svg +3 -0
  115. package/runtime/workbench/ui/icons/security.svg +3 -0
  116. package/runtime/workbench/ui/icons/settings.svg +3 -0
  117. package/runtime/workbench/ui/index.html +139 -0
  118. package/runtime/workbench/ui/loopback-entry.mjs +26 -0
  119. package/runtime/workbench/ui/mcp-app-client.mjs +151 -0
  120. package/runtime/workbench/ui/mcp-app-entry.mjs +452 -0
  121. package/runtime/workbench/ui/styles.css +686 -0
  122. package/tools/hellolynk-activate-neutral-host-clients.mjs +837 -0
  123. package/tools/hellolynk-install-client-skills.mjs +1211 -0
@@ -0,0 +1,181 @@
1
+ #!/usr/bin/env node
2
+
3
+ import path from "node:path";
4
+ import { readClientAccount } from "../../../runtime/core/hellolynk-client-account.mjs";
5
+ import { workbenchConnectionError, isWorkbenchConnectionRequired } from "../../../runtime/core/hellolynk-workbench-connection.mjs";
6
+ import { fileURLToPath } from "node:url";
7
+ import { startInstalledClientUpdate } from "../../../runtime/core/hellolynk-client-update-entry.mjs";
8
+ import {
9
+ createTraeWorkNeutralHostAdapter,
10
+ createTraeWorkProtectedBindingProvider,
11
+ } from "./neutral-host-adapter.mjs";
12
+ import {
13
+ runTraeWorkStdioMcpServer,
14
+ toTraeWorkPublicErrorCode,
15
+ } from "./mcp-server.mjs";
16
+ import { createCurrentTraeWorkNeutralProduction } from "./trae-neutral-production.mjs";
17
+ import { closeTraeWorkInbox, openTraeWorkInbox } from "./trae-ui-launch.mjs";
18
+ import { readTraeNativeTaskWorkerConfig, startTraeNativeTaskWorker } from "./native-task-worker.mjs";
19
+
20
+ export async function runTraeWorkMcpProxy(options = {}) {
21
+ let adapter = options.adapter || null;
22
+ if (!adapter) {
23
+ const updating = options.createAdapter ? Promise.resolve(null) : startInstalledClientUpdate({
24
+ client: "trae-work", packageRoot: fileURLToPath(new URL("../../../", import.meta.url)), storeRoot: options.storeRoot,
25
+ });
26
+ const createProduction = options.createProduction || (options.createAdapter ? null : createCurrentTraeWorkNeutralProduction);
27
+ const connect = async () => {
28
+ // A startup install finishes first. After that the protected binding names the
29
+ // release to use, and a background update can move it while this process stays open.
30
+ await updating;
31
+ const production = options.production || (createProduction ? await createProduction({
32
+ ...(options.storeRoot ? { storeRoot: options.storeRoot } : {}),
33
+ }) : null);
34
+ return (options.createAdapter || createTraeWorkNeutralHostAdapter)({
35
+ capabilityProvider: options.capabilityProvider || production?.capabilityProvider || createTraeWorkProtectedBindingProvider(options),
36
+ discoverHost: options.discoverHost,
37
+ requestHost: options.requestHost,
38
+ hostLauncher: options.hostLauncher || production?.hostLauncher,
39
+ adapterInstanceId: options.adapterInstanceId,
40
+ heartbeatMs: options.heartbeatMs,
41
+ });
42
+ };
43
+ adapter = recoveringAdapter(connect, toTraeWorkPublicErrorCode, [
44
+ "hostStatus", "getNativeTaskScope", "readInbox", "readUnreadCount", "markInboxMessageRead", "deleteReadInboxMessages",
45
+ "listContacts", "saveContact", "deleteContact", "listContactRequests",
46
+ "setAutonomousSendAuthorization", "listAuthorizedContacts", "listAuthorizedInboxMessages", "modelInbox", "listPendingMessages", "claimMessage", "claimBatch", "inboxBatch", "readAuthorizedInboxMessage", "listAuthorizedContactRequests", "readAuthorizedContactRequest", "sendAuthorizedMessage", "replyAuthorizedMessage",
47
+ "readOutbox", "issueOutboxRetryGrant", "retryOutboxMessage", "readChangesSnapshot",
48
+ "readWorkbenchSnapshot", "readWorkbenchChanges", "issueWorkbenchActionGrant", "executeWorkbenchCommand",
49
+ "requestHumanSend", "getHumanSendStatus",
50
+ ], () => readClientAccount("trae-work", options.storeRoot).revision);
51
+ adapter.start();
52
+ }
53
+ let nativeTasks = null;
54
+ try {
55
+ const debugEndpoint = options.nativeTasks === false ? null : options.nativeTaskOptions?.debugEndpoint
56
+ || process.env.HELLOLYNK_TRAE_DEBUG_ENDPOINT || await readTraeNativeTaskWorkerConfig(options.storeRoot);
57
+ nativeTasks = debugEndpoint ? startTraeNativeTaskWorker({ adapter, ...options.nativeTaskOptions, debugEndpoint }) : null;
58
+ return await (options.runServer || runTraeWorkStdioMcpServer)({
59
+ adapter,
60
+ input: options.input || process.stdin,
61
+ output: options.output || process.stdout,
62
+ openInbox: options.openInbox || (() => openTraeWorkInbox({ adapter })),
63
+ privateUiEnabled: options.privateUiEnabled === true,
64
+ });
65
+ } finally {
66
+ try { await nativeTasks?.close(); await closeTraeWorkInbox(); }
67
+ finally { await adapter.close(); }
68
+ }
69
+ }
70
+
71
+ function recoveringAdapter(connectAdapter, publicCode, methods, accountRevision = () => null) {
72
+ let current = null;
73
+ let pending = null;
74
+ let closed = false;
75
+ let closePromise = null;
76
+ const adapterCloses = new WeakMap();
77
+ let revision = accountRevision();
78
+ let accountReset = null;
79
+ function closeAdapter(value) {
80
+ if (!value) return Promise.resolve();
81
+ if (!adapterCloses.has(value)) adapterCloses.set(value, Promise.resolve().then(() => value.close?.()));
82
+ return adapterCloses.get(value);
83
+ }
84
+ async function connect() {
85
+ if (closed) throw codeError("neutral_host_adapter_closed");
86
+ const nextRevision = accountRevision();
87
+ if (!accountReset && revision !== nextRevision) {
88
+ const old = current, previousFlight = pending;
89
+ current = null; pending = null; revision = nextRevision;
90
+ accountReset = Promise.resolve().then(async () => {
91
+ const previous = await previousFlight?.catch(() => null);
92
+ await closeAdapter(previous || old).catch(() => {});
93
+ }).finally(() => { accountReset = null; });
94
+ }
95
+ if (accountReset) await accountReset;
96
+ if (closed) throw codeError("neutral_host_adapter_closed");
97
+ if (revision !== accountRevision()) throw codeError("workbench_account_changed");
98
+ if (current && current.state !== "dead" && current.state !== "closed") return current;
99
+ if (current) await closeAdapter(current).catch(() => {});
100
+ current = null;
101
+ if (closed) throw codeError("neutral_host_adapter_closed");
102
+ if (!pending) {
103
+ const generation = revision;
104
+ const flight = Promise.resolve().then(connectAdapter).then(async (value) => {
105
+ if (closed || generation !== accountRevision()) {
106
+ await closeAdapter(value).catch(() => {});
107
+ throw codeError("neutral_host_adapter_closed");
108
+ }
109
+ current = value;
110
+ return value;
111
+ }, (error) => { throw isWorkbenchConnectionRequired(error) ? workbenchConnectionError(error) : codeError(publicCode(error)); }).finally(() => { if (pending === flight) pending = null; });
112
+ pending = flight;
113
+ }
114
+ return pending;
115
+ }
116
+ const facade = {
117
+ start() {
118
+ const started = connect();
119
+ started.catch(() => {});
120
+ return started;
121
+ },
122
+ async close() {
123
+ if (closed) return closePromise;
124
+ closed = true;
125
+ const value = current;
126
+ current = null;
127
+ // Both the current flight and a reset-detached flight remain owned until
128
+ // their late adapter has been retired. Repeated callers share the drain.
129
+ closePromise = Promise.allSettled([pending, accountReset, closeAdapter(value)]).then(() => undefined);
130
+ return closePromise;
131
+ },
132
+ };
133
+ const workbenchPair = methods.includes("issueWorkbenchActionGrant")
134
+ && methods.includes("executeWorkbenchCommand");
135
+ for (const method of methods) {
136
+ if (workbenchPair && ["issueWorkbenchActionGrant", "executeWorkbenchCommand"].includes(method)) continue;
137
+ facade[method] = async (...args) => (await connect())[method](...args);
138
+ }
139
+ if (workbenchPair) {
140
+ const issueWorkbenchActionGrant = async function issueWorkbenchActionGrant(command) {
141
+ const target = await connect();
142
+ requireWorkbenchPair(target);
143
+ return target.issueWorkbenchActionGrant(command);
144
+ };
145
+ facade.executeWorkbenchCommand = async function executeWorkbenchCommand(command, context) {
146
+ const target = await connect();
147
+ requireWorkbenchPair(target);
148
+ return target.executeWorkbenchCommand(command, context);
149
+ };
150
+ Object.defineProperty(facade, "issueWorkbenchActionGrant", {
151
+ enumerable: true,
152
+ get() { return !current || hasWorkbenchPair(current) ? issueWorkbenchActionGrant : undefined; },
153
+ });
154
+ }
155
+ return Object.freeze(facade);
156
+
157
+ function requireWorkbenchPair(value) {
158
+ if (!hasWorkbenchPair(value)) throw codeError("neutral_host_workbench_action_grant_unavailable");
159
+ }
160
+
161
+ function hasWorkbenchPair(value) {
162
+ return typeof value?.issueWorkbenchActionGrant === "function"
163
+ && value.issueWorkbenchActionGrant.length >= 1
164
+ && typeof value.executeWorkbenchCommand === "function"
165
+ && value.executeWorkbenchCommand.length >= 2;
166
+ }
167
+ }
168
+
169
+ export function formatTraeWorkProxyError(error) {
170
+ return `${JSON.stringify({ ok: false, error: toTraeWorkPublicErrorCode(error) })}\n`;
171
+ }
172
+
173
+ function codeError(code) { const error = new Error(code); error.code = code; return error; }
174
+
175
+ const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
176
+ if (isMain) {
177
+ runTraeWorkMcpProxy().catch((error) => {
178
+ process.stderr.write(formatTraeWorkProxyError(error));
179
+ process.exitCode = 1;
180
+ });
181
+ }