@liberseek/boft-cli-win32-arm64 0.7.0 → 0.7.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/README.md +1 -1
- package/THIRD_PARTY_NOTICES.txt +0 -4
- package/app/codexhost-distribution.json +1 -1
- package/app/desktop-controller.mjs +256 -179
- package/app/host-runtime.mjs +646 -323
- package/app/plugins/antigravity/plugin.mjs +123 -1
- package/app/plugins/claude-code/plugin.mjs +252 -46
- package/app/plugins/codebuddy/plugin.mjs +2287 -879
- package/app/plugins/cursor-cli/plugin.mjs +35756 -10755
- package/app/plugins/deepseek-harness/plugin.mjs +70 -0
- package/app/plugins/enabled.json +1 -0
- package/app/plugins/grok/plugin.mjs +193 -82
- package/app/plugins/hermes/plugin.mjs +2444 -94
- package/app/plugins/kiro-cli/plugin.mjs +70 -0
- package/app/plugins/muse/plugin.mjs +70 -0
- package/app/plugins/omp/plugin.mjs +92 -4
- package/app/plugins/opencode/plugin.mjs +70 -0
- package/app/plugins/pi/plugin.mjs +2139 -973
- package/app/plugins/qoder/plugin.mjs +71 -9
- package/app/plugins/qoder-cn/plugin.mjs +71 -9
- package/app/plugins/workbuddy/assets/icon.svg +29 -0
- package/app/plugins/workbuddy/manifest.json +14 -0
- package/app/plugins/workbuddy/plugin.mjs +25007 -0
- package/app/renderer-extension.js +2874 -1408
- package/bin/boft.exe +0 -0
- package/libexec/boft-node-repl.exe +0 -0
- package/libexec/boft-shim.exe +0 -0
- package/libexec/boft-updater.exe +0 -0
- package/package.json +1 -1
- package/licenses/opencodex-LICENSE.txt +0 -21
|
@@ -329,7 +329,7 @@ function retainRendererHostResponses(client, hostId, target) {
|
|
|
329
329
|
if (typeof client.addRequestLifecycleListener !== "function" || typeof target.addEventListener !== "function" || typeof target.removeEventListener !== "function")
|
|
330
330
|
return () => {
|
|
331
331
|
};
|
|
332
|
-
const
|
|
332
|
+
const isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
333
333
|
const pending = /* @__PURE__ */ new Set();
|
|
334
334
|
let retired = false;
|
|
335
335
|
let unsubscribe = () => {
|
|
@@ -343,12 +343,12 @@ function retainRendererHostResponses(client, hostId, target) {
|
|
|
343
343
|
if (source != null && source !== target) return;
|
|
344
344
|
const ownOrigin = target.location?.origin;
|
|
345
345
|
if (source === target && ownOrigin && ownOrigin !== "null" && origin !== ownOrigin) return;
|
|
346
|
-
if (!
|
|
346
|
+
if (!isRecord3(data) || data.type !== "mcp-response" || data.hostId !== hostId) return;
|
|
347
347
|
const message = data.message;
|
|
348
|
-
if (!
|
|
348
|
+
if (!isRecord3(message)) return;
|
|
349
349
|
const id = message.id;
|
|
350
350
|
if (typeof id !== "string" && typeof id !== "number" || !pending.has(id)) return;
|
|
351
|
-
const hasError =
|
|
351
|
+
const hasError = isRecord3(message.error);
|
|
352
352
|
if (!hasError && !Object.prototype.hasOwnProperty.call(message, "result")) return;
|
|
353
353
|
queueMicrotask(() => {
|
|
354
354
|
if (!pending.has(id)) return;
|
|
@@ -358,7 +358,7 @@ function retainRendererHostResponses(client, hostId, target) {
|
|
|
358
358
|
};
|
|
359
359
|
target.addEventListener("message", receive);
|
|
360
360
|
unsubscribe = client.addRequestLifecycleListener((event) => {
|
|
361
|
-
if (!
|
|
361
|
+
if (!isRecord3(event) || event.hostId !== hostId) return;
|
|
362
362
|
const id = event.id;
|
|
363
363
|
if (typeof id !== "string" && typeof id !== "number") return;
|
|
364
364
|
if (!retired && event.type === "started" && typeof event.method === "string" && event.method.startsWith("codexhost/"))
|
|
@@ -375,24 +375,21 @@ function retainRendererHostResponses(client, hostId, target) {
|
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
// packages/desktop-control/src/renderer-draft-prewarm-runtime.ts
|
|
378
|
-
function
|
|
379
|
-
|
|
380
|
-
if (existing?.owns?.length === 5 && existing.owns(manager, bridge, hostId, prewarmedThreadManager, !!isCurrentManager) === true) {
|
|
381
|
-
return { state: "ready", reason: "owned-request-bridge" };
|
|
382
|
-
}
|
|
383
|
-
existing?.dispose?.();
|
|
378
|
+
function createDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewarmedThreadManager, isCurrentManager, retainResponses = retainRendererHostResponses) {
|
|
379
|
+
let disposed = false;
|
|
384
380
|
const originalSend = bridge.sendRequest;
|
|
385
381
|
const originalPrewarm = bridge.prewarmThreadStart;
|
|
386
382
|
const originalOnNotification = manager.onNotification;
|
|
387
383
|
const originalDispatchAppServerResponse = manager.dispatchAppServerResponse;
|
|
388
384
|
let selectedModel = null;
|
|
389
|
-
|
|
385
|
+
let prewarmGeneration = 0;
|
|
386
|
+
const isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
390
387
|
const isUnsupportedPosixBridgeSpawn = (value) => {
|
|
391
388
|
const marker = "AbsolutePathBuf deserialized without a base path";
|
|
392
389
|
if (typeof value === "string") {
|
|
393
390
|
return value.startsWith("Invalid request:") && value.includes(marker);
|
|
394
391
|
}
|
|
395
|
-
if (!
|
|
392
|
+
if (!isRecord3(value)) return false;
|
|
396
393
|
if (typeof value.message === "string" && value.message.includes(marker)) {
|
|
397
394
|
if (value.code === -32600 || value.message.startsWith("Invalid request:")) return true;
|
|
398
395
|
}
|
|
@@ -483,14 +480,14 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
483
480
|
bridgeState = "idle";
|
|
484
481
|
};
|
|
485
482
|
const rememberExternalThread = (value) => {
|
|
486
|
-
if (!
|
|
483
|
+
if (!isRecord3(value) || typeof value.id !== "string") return;
|
|
487
484
|
if (value.modelProvider === "codexhost" || value.cliVersion === "codexhost") {
|
|
488
485
|
knownExternalThreadIds.add(value.id);
|
|
489
486
|
knownOfficialThreadIds.delete(value.id);
|
|
490
487
|
}
|
|
491
488
|
};
|
|
492
489
|
const observeBridgeResult = (request, result) => {
|
|
493
|
-
if (!request || !
|
|
490
|
+
if (!request || !isRecord3(result)) return;
|
|
494
491
|
if (request.method === "thread/list" && Array.isArray(result.data)) {
|
|
495
492
|
for (const thread of result.data) rememberExternalThread(thread);
|
|
496
493
|
return;
|
|
@@ -499,7 +496,7 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
499
496
|
rememberExternalThread(result.thread);
|
|
500
497
|
return;
|
|
501
498
|
}
|
|
502
|
-
if (request.method === "codexhost/thread/inspect" &&
|
|
499
|
+
if (request.method === "codexhost/thread/inspect" && isRecord3(request.parameters) && typeof request.parameters.threadId === "string") {
|
|
503
500
|
if (result.owner === "external") {
|
|
504
501
|
knownExternalThreadIds.add(request.parameters.threadId);
|
|
505
502
|
knownOfficialThreadIds.delete(request.parameters.threadId);
|
|
@@ -509,18 +506,18 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
509
506
|
}
|
|
510
507
|
return;
|
|
511
508
|
}
|
|
512
|
-
if (request.method === "thread/delete" &&
|
|
509
|
+
if (request.method === "thread/delete" && isRecord3(request.parameters) && typeof request.parameters.threadId === "string") {
|
|
513
510
|
knownExternalThreadIds.delete(request.parameters.threadId);
|
|
514
511
|
knownOfficialThreadIds.delete(request.parameters.threadId);
|
|
515
512
|
}
|
|
516
513
|
};
|
|
517
514
|
const handleBridgeFrame = (value) => {
|
|
518
|
-
if (!
|
|
515
|
+
if (!isRecord3(value)) {
|
|
519
516
|
failBridge("received a non-object app-server frame");
|
|
520
517
|
return;
|
|
521
518
|
}
|
|
522
519
|
if (value.method === bridgeReadyMethod && value.id === void 0) {
|
|
523
|
-
if (
|
|
520
|
+
if (isRecord3(value.params) && value.params.protocolVersion === 1) {
|
|
524
521
|
bridgeState = "ready";
|
|
525
522
|
if (bridgeReadyTimeout !== null) globalThis.clearTimeout(bridgeReadyTimeout);
|
|
526
523
|
bridgeReadyTimeout = null;
|
|
@@ -533,7 +530,7 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
533
530
|
return;
|
|
534
531
|
}
|
|
535
532
|
if (typeof value.method === "string" && value.id === void 0) {
|
|
536
|
-
if (value.method === "thread/started" &&
|
|
533
|
+
if (value.method === "thread/started" && isRecord3(value.params)) {
|
|
537
534
|
rememberExternalThread(value.params.thread);
|
|
538
535
|
}
|
|
539
536
|
originalOnNotification.call(manager, value.method, value.params);
|
|
@@ -584,7 +581,7 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
584
581
|
}
|
|
585
582
|
};
|
|
586
583
|
const handleOuterNotification = (method, parameters) => {
|
|
587
|
-
if (method === "process/exited" &&
|
|
584
|
+
if (method === "process/exited" && isRecord3(parameters) && parameters.processHandle === bridgeProcessHandle) {
|
|
588
585
|
const exitCode = typeof parameters.exitCode === "number" ? parameters.exitCode : "unknown";
|
|
589
586
|
const stderr = typeof parameters.stderr === "string" ? parameters.stderr.trim() : "";
|
|
590
587
|
failBridge(
|
|
@@ -593,7 +590,7 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
593
590
|
);
|
|
594
591
|
return true;
|
|
595
592
|
}
|
|
596
|
-
if (method !== "process/outputDelta" || !
|
|
593
|
+
if (method !== "process/outputDelta" || !isRecord3(parameters) || parameters.processHandle !== bridgeProcessHandle || parameters.stream !== "stdout" && parameters.stream !== "stderr" || typeof parameters.deltaBase64 !== "string") {
|
|
597
594
|
return false;
|
|
598
595
|
}
|
|
599
596
|
if (parameters.capReached === true) {
|
|
@@ -698,7 +695,7 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
698
695
|
return bridgeInitialization;
|
|
699
696
|
};
|
|
700
697
|
const threadIdFromParameters = (parameters) => {
|
|
701
|
-
if (!
|
|
698
|
+
if (!isRecord3(parameters)) return null;
|
|
702
699
|
const value = parameters.threadId ?? parameters.conversationId;
|
|
703
700
|
return typeof value === "string" ? value : null;
|
|
704
701
|
};
|
|
@@ -713,9 +710,9 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
713
710
|
threadIds: [threadId]
|
|
714
711
|
})
|
|
715
712
|
).then((value) => {
|
|
716
|
-
const ownerships =
|
|
713
|
+
const ownerships = isRecord3(value) && Array.isArray(value.threads) ? value.threads : null;
|
|
717
714
|
const ownership = ownerships?.[0];
|
|
718
|
-
if (!ownerships || !
|
|
715
|
+
if (!ownerships || !isRecord3(ownership) || ownerships.length !== 1 || ownership.threadId !== threadId || ownership.owner !== "external" && ownership.owner !== "codex") {
|
|
719
716
|
throw transportError("Thread ownership lookup returned an invalid result");
|
|
720
717
|
}
|
|
721
718
|
if (ownership.owner === "external") {
|
|
@@ -751,7 +748,7 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
751
748
|
if (method.startsWith("codexhost/")) return true;
|
|
752
749
|
if (method === "thread/list") return true;
|
|
753
750
|
if (method === "thread/start") {
|
|
754
|
-
return
|
|
751
|
+
return isRecord3(parameters) && typeof parameters.model === "string" && parameters.model.startsWith("codexhost/");
|
|
755
752
|
}
|
|
756
753
|
const threadId = threadIdFromParameters(parameters);
|
|
757
754
|
if (threadId && knownExternalThreadIds.has(threadId)) return true;
|
|
@@ -759,7 +756,7 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
759
756
|
return selectedModel !== null && (method.startsWith("thread/") || method.startsWith("turn/") || method.startsWith("review/"));
|
|
760
757
|
};
|
|
761
758
|
const routeThreadStart = (parameters) => {
|
|
762
|
-
if (!
|
|
759
|
+
if (!isRecord3(parameters) || parameters.ephemeral === true) {
|
|
763
760
|
return parameters;
|
|
764
761
|
}
|
|
765
762
|
return {
|
|
@@ -793,16 +790,23 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
793
790
|
};
|
|
794
791
|
const routedPrewarm = (parameters, options) => {
|
|
795
792
|
const routedParameters = routeThreadStart(parameters);
|
|
796
|
-
|
|
797
|
-
|
|
793
|
+
const generation = prewarmGeneration;
|
|
794
|
+
const pending = shouldUseBridge("thread/start", routedParameters) ? routedSend("thread/start", routedParameters, options) : options === void 0 ? originalPrewarm.call(bridge, routedParameters) : originalPrewarm.call(bridge, routedParameters, options);
|
|
795
|
+
if (isRecord3(parameters) && parameters.ephemeral === true || typeof pending !== "object" && typeof pending !== "function" || pending === null || typeof Reflect.get(pending, "then") !== "function") {
|
|
796
|
+
return pending;
|
|
798
797
|
}
|
|
799
|
-
return
|
|
798
|
+
return Promise.resolve(pending).then((result) => {
|
|
799
|
+
if (disposed || generation !== prewarmGeneration) {
|
|
800
|
+
throw new Error("Renderer draft prewarm was invalidated by a configuration change");
|
|
801
|
+
}
|
|
802
|
+
return result;
|
|
803
|
+
});
|
|
800
804
|
};
|
|
801
805
|
bridge.sendRequest = routedSend;
|
|
802
806
|
bridge.prewarmThreadStart = routedPrewarm;
|
|
803
807
|
const routedWindowMessage = (event) => {
|
|
804
808
|
const message = event.data;
|
|
805
|
-
if (!
|
|
809
|
+
if (!isRecord3(message) || message.type !== "mcp-notification" || message.hostId !== hostId || typeof message.method !== "string") {
|
|
806
810
|
return;
|
|
807
811
|
}
|
|
808
812
|
handleOuterNotification(message.method, message.params);
|
|
@@ -834,26 +838,35 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
834
838
|
state: "ready",
|
|
835
839
|
hostId,
|
|
836
840
|
owns(candidateManager, candidate, candidateHostId, candidatePrewarmedThreadManager, requiresCurrentManager) {
|
|
837
|
-
return candidateManager === manager && candidate === bridge && candidateHostId === hostId && candidatePrewarmedThreadManager === prewarmedThreadManager && requiresCurrentManager === !!isCurrentManager;
|
|
841
|
+
return !disposed && candidateManager === manager && candidate === bridge && candidateHostId === hostId && candidatePrewarmedThreadManager === prewarmedThreadManager && requiresCurrentManager === !!isCurrentManager;
|
|
838
842
|
},
|
|
839
843
|
requestTarget() {
|
|
840
|
-
if (isCurrentManager && !isCurrentManager())
|
|
844
|
+
if (disposed || isCurrentManager && !isCurrentManager())
|
|
841
845
|
throw new Error("Renderer request manager is retired");
|
|
842
846
|
return manager;
|
|
843
847
|
},
|
|
844
848
|
select(model) {
|
|
849
|
+
if (disposed || isCurrentManager && !isCurrentManager())
|
|
850
|
+
throw new Error("Renderer request manager is retired");
|
|
845
851
|
if (model !== null && (typeof model !== "string" || !model.startsWith("codexhost/"))) {
|
|
846
852
|
throw new Error("Draft route Model must be a codexhost transport carrier");
|
|
847
853
|
}
|
|
848
854
|
if (selectedModel === model) return false;
|
|
849
855
|
selectedModel = model;
|
|
856
|
+
prewarmGeneration += 1;
|
|
850
857
|
return true;
|
|
851
858
|
},
|
|
852
859
|
clear() {
|
|
860
|
+
if (disposed || isCurrentManager && !isCurrentManager())
|
|
861
|
+
return Promise.reject(new Error("Renderer request manager is retired"));
|
|
862
|
+
prewarmGeneration += 1;
|
|
853
863
|
prewarmedThreadManager.discardAllPrewarmedThreads();
|
|
854
864
|
return Promise.resolve();
|
|
855
865
|
},
|
|
856
866
|
dispose() {
|
|
867
|
+
if (disposed) return;
|
|
868
|
+
disposed = true;
|
|
869
|
+
prewarmGeneration += 1;
|
|
857
870
|
retireResponses();
|
|
858
871
|
if (bridge.sendRequest === routedSend) bridge.sendRequest = originalSend;
|
|
859
872
|
if (bridge.prewarmThreadStart === routedPrewarm) {
|
|
@@ -886,167 +899,231 @@ function installDraftPrewarmPolicyBridge(manager, bridge, hostId, target, prewar
|
|
|
886
899
|
selectedModel = null;
|
|
887
900
|
}
|
|
888
901
|
});
|
|
889
|
-
|
|
890
|
-
configurable: true,
|
|
891
|
-
value: policy
|
|
892
|
-
});
|
|
893
|
-
if (typeof target.dispatchEvent === "function" && typeof CustomEvent === "function") {
|
|
894
|
-
target.dispatchEvent(new CustomEvent("codexhost:draft-prewarm-policy-changed"));
|
|
895
|
-
}
|
|
896
|
-
return { state: "ready", reason: "owned-request-bridge" };
|
|
902
|
+
return policy;
|
|
897
903
|
}
|
|
898
904
|
|
|
899
|
-
// packages/desktop-control/src/renderer-
|
|
900
|
-
function
|
|
901
|
-
const
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
const activeHostId = hosts.values().next().value;
|
|
908
|
-
const eligible = [...unique.values()].filter(
|
|
909
|
-
(candidate) => activeHostId === void 0 || candidate.hostId === activeHostId
|
|
910
|
-
);
|
|
911
|
-
return eligible.length === 1 ? eligible[0] ?? null : null;
|
|
912
|
-
}
|
|
913
|
-
function requestManagerFromHookState(value, activeHostId) {
|
|
914
|
-
const matchesRequestManager = (candidate) => {
|
|
915
|
-
if (candidate == null || typeof candidate !== "object" || !("requestClient" in candidate) || !("prewarmedThreadManager" in candidate) || !("sendRequest" in candidate)) {
|
|
916
|
-
return false;
|
|
917
|
-
}
|
|
918
|
-
const requestClient = candidate.requestClient;
|
|
919
|
-
const prewarmedThreadManager = candidate.prewarmedThreadManager;
|
|
920
|
-
return requestClient != null && typeof requestClient === "object" && "prewarmThreadStart" in requestClient && typeof requestClient.prewarmThreadStart === "function" && "sendRequest" in requestClient && typeof requestClient.sendRequest === "function" && "enqueueRequest" in requestClient && typeof requestClient.enqueueRequest === "function" && prewarmedThreadManager != null && typeof prewarmedThreadManager === "object" && "discardAllPrewarmedThreads" in prewarmedThreadManager && typeof prewarmedThreadManager.discardAllPrewarmedThreads === "function" && typeof candidate.sendRequest === "function";
|
|
905
|
+
// packages/desktop-control/src/renderer-host-discovery.ts
|
|
906
|
+
function requestManagerFromHookState(value, hostId) {
|
|
907
|
+
const record = (candidate) => typeof candidate === "object" && candidate !== null;
|
|
908
|
+
const manager = (candidate) => {
|
|
909
|
+
if (!record(candidate) || !record(candidate.requestClient) || !record(candidate.prewarmedThreadManager))
|
|
910
|
+
return null;
|
|
911
|
+
const bridge = candidate.requestClient;
|
|
912
|
+
return typeof candidate.sendRequest === "function" && typeof bridge.sendRequest === "function" && typeof bridge.prewarmThreadStart === "function" && typeof bridge.enqueueRequest === "function" && typeof candidate.prewarmedThreadManager.discardAllPrewarmedThreads === "function" ? candidate : null;
|
|
921
913
|
};
|
|
922
|
-
if (
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
if (typeof activeHostId !== "string" || activeHostId.length === 0) return null;
|
|
927
|
-
if (value == null || typeof value !== "object" || !("addManager" in value) || typeof value.addManager !== "function" || !("getForHostId" in value) || typeof value.getForHostId !== "function" || !("waitForManagerForHostId" in value) || typeof value.waitForManagerForHostId !== "function") {
|
|
914
|
+
if (!record(value)) return null;
|
|
915
|
+
const direct = manager(value) ?? manager(value.manager);
|
|
916
|
+
if (direct) return direct;
|
|
917
|
+
if (!hostId || typeof value.addManager !== "function" || typeof value.getForHostId !== "function" || typeof value.waitForManagerForHostId !== "function")
|
|
928
918
|
return null;
|
|
929
|
-
|
|
930
|
-
const manager = value.getForHostId.call(value, activeHostId);
|
|
931
|
-
return matchesRequestManager(manager) ? manager : null;
|
|
932
|
-
}
|
|
933
|
-
function isRecord2(value) {
|
|
934
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
919
|
+
return manager(value.getForHostId(hostId));
|
|
935
920
|
}
|
|
936
|
-
|
|
937
|
-
const
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
)
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
}
|
|
945
|
-
// Main and side chat can expose multiple editors backed by the same manager.
|
|
946
|
-
// Resolve their combined Host ownership before consulting any Host registry.
|
|
947
|
-
const composerAncestors = new Set();
|
|
948
|
-
const activeHostIds = new Set();
|
|
921
|
+
function discoverRendererHosts(root, ancestors = committedReactAncestors, managerFrom = requestManagerFromHookState) {
|
|
922
|
+
const editors = [
|
|
923
|
+
...root.querySelectorAll('[data-codex-composer], [contenteditable="true"][role="textbox"]')
|
|
924
|
+
];
|
|
925
|
+
const hostIds = /* @__PURE__ */ new Set();
|
|
926
|
+
const managers = /* @__PURE__ */ new Set();
|
|
927
|
+
const registries = /* @__PURE__ */ new Set();
|
|
928
|
+
const fibers = /* @__PURE__ */ new Set();
|
|
949
929
|
for (const editor of editors) {
|
|
950
930
|
let element = editor;
|
|
951
|
-
let fiber
|
|
952
|
-
while (element
|
|
953
|
-
const key = Object.getOwnPropertyNames(element).find(
|
|
954
|
-
name.startsWith(
|
|
931
|
+
let fiber;
|
|
932
|
+
while (element && !fiber) {
|
|
933
|
+
const key = Object.getOwnPropertyNames(element).find(
|
|
934
|
+
(name) => name.startsWith("__reactFiber$")
|
|
955
935
|
);
|
|
956
|
-
if (key
|
|
957
|
-
element = element.parentElement;
|
|
936
|
+
if (key) fiber = Object.getOwnPropertyDescriptor(element, key)?.value;
|
|
937
|
+
element = element.parentElement ?? null;
|
|
958
938
|
}
|
|
959
|
-
for (const current of
|
|
960
|
-
|
|
939
|
+
for (const current of ancestors(fiber)) {
|
|
940
|
+
fibers.add(current);
|
|
961
941
|
const props = current.memoizedProps;
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
if (typeof value === 'string' && value.length > 0) activeHostIds.add(value);
|
|
966
|
-
}
|
|
942
|
+
for (const key of ["executionTargetHostId", "permissionsHostId"]) {
|
|
943
|
+
const hostId = props?.[key];
|
|
944
|
+
if (typeof hostId === "string" && hostId) hostIds.add(hostId);
|
|
967
945
|
}
|
|
968
946
|
}
|
|
969
947
|
}
|
|
970
|
-
const
|
|
971
|
-
activeHostIds.size === 1 ? activeHostIds.values().next().value : undefined;
|
|
972
|
-
const managers = new Set();
|
|
973
|
-
for (const fiber of composerAncestors) {
|
|
948
|
+
for (const fiber of fibers) {
|
|
974
949
|
let hook = fiber.memoizedState;
|
|
975
|
-
for (let index = 0; hook
|
|
976
|
-
const
|
|
977
|
-
|
|
950
|
+
for (let index = 0; hook && index < 120; index += 1) {
|
|
951
|
+
const value = hook.memoizedState;
|
|
952
|
+
const manager = managerFrom(value);
|
|
953
|
+
if (manager) managers.add(manager);
|
|
954
|
+
if (value && typeof value === "object" && "addManager" in value && typeof value.addManager === "function" && "getForHostId" in value && typeof value.getForHostId === "function" && "waitForManagerForHostId" in value && typeof value.waitForManagerForHostId === "function") {
|
|
955
|
+
registries.add(value);
|
|
956
|
+
}
|
|
957
|
+
hook = hook.next && typeof hook.next === "object" ? hook.next : null;
|
|
978
958
|
}
|
|
979
959
|
}
|
|
980
|
-
const candidates = [...managers].map((manager) => {
|
|
981
|
-
const requestClient =
|
|
982
|
-
typeof manager.requestClient?.sendRequest === 'function' &&
|
|
983
|
-
typeof manager.requestClient?.prewarmThreadStart === 'function' &&
|
|
984
|
-
typeof manager.requestClient?.enqueueRequest === 'function'
|
|
985
|
-
? manager.requestClient
|
|
986
|
-
: manager;
|
|
987
|
-
return {
|
|
988
|
-
manager,
|
|
989
|
-
requestClient,
|
|
990
|
-
hostId: manager?.getHostId?.() ?? requestClient?.hostId ?? null,
|
|
991
|
-
prewarmedThreadManager: manager?.prewarmedThreadManager ?? null,
|
|
992
|
-
};
|
|
993
|
-
});
|
|
994
|
-
const selected = (${selectRendererRequestManager.toString()})(candidates, [...activeHostIds]);
|
|
995
960
|
return {
|
|
996
|
-
candidateCount: selected == null ? candidates.length : 1,
|
|
997
961
|
editorCount: editors.length,
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
prewarmedThreadManager: selected?.prewarmedThreadManager ?? null,
|
|
962
|
+
hostIds: [...hostIds],
|
|
963
|
+
managers: [...managers],
|
|
964
|
+
registries: [...registries]
|
|
1002
965
|
};
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
var INSTALL_RENDERER_POLICY_FUNCTION = `function(requestClient, hostId, prewarmedThreadManager) {
|
|
1012
|
-
return (${installDraftPrewarmPolicyBridge.toString()})(
|
|
1013
|
-
this,
|
|
1014
|
-
requestClient,
|
|
1015
|
-
hostId,
|
|
1016
|
-
window,
|
|
1017
|
-
prewarmedThreadManager,
|
|
1018
|
-
() => (${IS_CURRENT_REQUEST_MANAGER})(this, requestClient, hostId, prewarmedThreadManager),
|
|
1019
|
-
(${retainRendererHostResponses.toString()}),
|
|
966
|
+
}
|
|
967
|
+
function resolveRendererHostManager(discovery, hostId, managerFrom = requestManagerFromHookState) {
|
|
968
|
+
if (!hostId) return null;
|
|
969
|
+
const candidates = discovery.registries.length ? discovery.registries.map((registry) => managerFrom(registry.getForHostId(hostId))) : discovery.managers;
|
|
970
|
+
const matching = new Set(
|
|
971
|
+
candidates.filter(
|
|
972
|
+
(manager) => manager && (manager.getHostId?.() ?? manager.requestClient.hostId) === hostId && (manager.requestClient.hostId === void 0 || manager.requestClient.hostId === hostId)
|
|
973
|
+
)
|
|
1020
974
|
);
|
|
1021
|
-
|
|
975
|
+
return matching.size === 1 ? matching.values().next().value ?? null : null;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
// packages/desktop-control/src/renderer-host-routing.ts
|
|
979
|
+
function installRendererHostRouting(root, target, discover, resolve, createPolicy) {
|
|
980
|
+
const existing = target.__codexhostHostRoutingV1;
|
|
981
|
+
if (existing) return existing;
|
|
982
|
+
target.__codexhostDraftPrewarmPolicyV1?.dispose?.();
|
|
983
|
+
let disposed = false;
|
|
984
|
+
let lastDiscovery = null;
|
|
985
|
+
const routes = /* @__PURE__ */ new Map();
|
|
986
|
+
const read = (composer) => {
|
|
987
|
+
const source = composer?.matches?.(
|
|
988
|
+
'[data-codex-composer], [contenteditable="true"][role="textbox"]'
|
|
989
|
+
) ? { querySelectorAll: () => [composer] } : composer ?? root;
|
|
990
|
+
const discovery = discover(source);
|
|
991
|
+
if (composer) return discovery;
|
|
992
|
+
if (discovery.editorCount === 0 && lastDiscovery) return lastDiscovery;
|
|
993
|
+
lastDiscovery = discovery;
|
|
994
|
+
return discovery;
|
|
995
|
+
};
|
|
996
|
+
const lookup = (hostId, discovery) => {
|
|
997
|
+
if (disposed) return null;
|
|
998
|
+
try {
|
|
999
|
+
return resolve(discovery ?? read(), hostId);
|
|
1000
|
+
} catch {
|
|
1001
|
+
return null;
|
|
1002
|
+
}
|
|
1003
|
+
};
|
|
1004
|
+
const retire = (hostId) => {
|
|
1005
|
+
const entry = routes.get(hostId);
|
|
1006
|
+
routes.delete(hostId);
|
|
1007
|
+
entry?.route.policy.dispose();
|
|
1008
|
+
};
|
|
1009
|
+
const routeFor = (hostId, discovery) => {
|
|
1010
|
+
const manager = lookup(hostId, discovery);
|
|
1011
|
+
const previous = routes.get(hostId);
|
|
1012
|
+
if (manager && previous?.route.manager === manager && previous.bridge === manager.requestClient && previous.prewarmed === manager.prewarmedThreadManager && previous.route.policy.owns(
|
|
1013
|
+
manager,
|
|
1014
|
+
manager.requestClient,
|
|
1015
|
+
hostId,
|
|
1016
|
+
manager.prewarmedThreadManager,
|
|
1017
|
+
true
|
|
1018
|
+
)) {
|
|
1019
|
+
return previous.route;
|
|
1020
|
+
}
|
|
1021
|
+
retire(hostId);
|
|
1022
|
+
if (!manager) return null;
|
|
1023
|
+
const bridge = manager.requestClient;
|
|
1024
|
+
const prewarmed = manager.prewarmedThreadManager;
|
|
1025
|
+
const policy = createPolicy(
|
|
1026
|
+
manager,
|
|
1027
|
+
bridge,
|
|
1028
|
+
hostId,
|
|
1029
|
+
target,
|
|
1030
|
+
prewarmed,
|
|
1031
|
+
() => lookup(hostId) === manager && manager.requestClient === bridge && manager.prewarmedThreadManager === prewarmed
|
|
1032
|
+
);
|
|
1033
|
+
const route = { hostId, manager, policy };
|
|
1034
|
+
routes.set(hostId, { route, bridge, prewarmed });
|
|
1035
|
+
return route;
|
|
1036
|
+
};
|
|
1037
|
+
const publish = (route) => {
|
|
1038
|
+
const policy = route?.policy;
|
|
1039
|
+
if (target.__codexhostDraftPrewarmPolicyV1 === policy) return;
|
|
1040
|
+
Object.defineProperty(target, "__codexhostDraftPrewarmPolicyV1", {
|
|
1041
|
+
configurable: true,
|
|
1042
|
+
value: policy
|
|
1043
|
+
});
|
|
1044
|
+
if (typeof target.dispatchEvent === "function" && typeof CustomEvent === "function") {
|
|
1045
|
+
target.dispatchEvent(new CustomEvent("codexhost:draft-prewarm-policy-changed"));
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
const composerHostId = (discovery) => {
|
|
1049
|
+
if (discovery.hostIds.length === 0 && discovery.registries.length > 0) return null;
|
|
1050
|
+
const hostIds = new Set(
|
|
1051
|
+
discovery.hostIds.length ? discovery.hostIds : discovery.managers.map(
|
|
1052
|
+
(manager) => manager.getHostId?.() ?? manager.requestClient.hostId
|
|
1053
|
+
)
|
|
1054
|
+
);
|
|
1055
|
+
const hostId = hostIds.size === 1 ? hostIds.values().next().value : null;
|
|
1056
|
+
return typeof hostId === "string" && hostId ? hostId : null;
|
|
1057
|
+
};
|
|
1058
|
+
const routing = {
|
|
1059
|
+
forHost(hostId) {
|
|
1060
|
+
return hostId ? routeFor(hostId) : null;
|
|
1061
|
+
},
|
|
1062
|
+
hostIdForComposer(composer) {
|
|
1063
|
+
if (disposed) return null;
|
|
1064
|
+
try {
|
|
1065
|
+
return composerHostId(read(composer));
|
|
1066
|
+
} catch {
|
|
1067
|
+
return null;
|
|
1068
|
+
}
|
|
1069
|
+
},
|
|
1070
|
+
forComposer(composer) {
|
|
1071
|
+
if (disposed) return null;
|
|
1072
|
+
let discovery;
|
|
1073
|
+
try {
|
|
1074
|
+
discovery = read(composer);
|
|
1075
|
+
} catch {
|
|
1076
|
+
publish(null);
|
|
1077
|
+
return null;
|
|
1078
|
+
}
|
|
1079
|
+
if (!composer) {
|
|
1080
|
+
for (const [hostId2, entry] of routes) {
|
|
1081
|
+
const manager = lookup(hostId2, discovery);
|
|
1082
|
+
if (manager !== entry.route.manager || manager.requestClient !== entry.bridge || manager.prewarmedThreadManager !== entry.prewarmed)
|
|
1083
|
+
retire(hostId2);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
const hostId = composerHostId(discovery);
|
|
1087
|
+
const route = hostId ? routeFor(hostId, discovery) : null;
|
|
1088
|
+
if (!composer) publish(route);
|
|
1089
|
+
return route;
|
|
1090
|
+
},
|
|
1091
|
+
dispose() {
|
|
1092
|
+
if (disposed) return;
|
|
1093
|
+
disposed = true;
|
|
1094
|
+
for (const hostId of routes.keys()) retire(hostId);
|
|
1095
|
+
lastDiscovery = null;
|
|
1096
|
+
if (target.__codexhostHostRoutingV1 === routing) {
|
|
1097
|
+
delete target.__codexhostHostRoutingV1;
|
|
1098
|
+
publish(null);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
Object.defineProperty(target, "__codexhostHostRoutingV1", { configurable: true, value: routing });
|
|
1103
|
+
return routing;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
// packages/desktop-control/src/renderer-draft-prewarm-policy.ts
|
|
1022
1107
|
var REQUEST_MANAGER_WAIT_TIMEOUT_MS = 6e4;
|
|
1023
1108
|
var REQUEST_MANAGER_POLL_INTERVAL_MS = 25;
|
|
1024
1109
|
function directRendererInstaller() {
|
|
1025
|
-
return `(
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
}
|
|
1039
|
-
return (${installDraftPrewarmPolicyBridge.toString()})(
|
|
1040
|
-
selected.manager,
|
|
1041
|
-
selected.requestClient,
|
|
1042
|
-
selected.hostId,
|
|
1043
|
-
window,
|
|
1044
|
-
selected.prewarmedThreadManager,
|
|
1045
|
-
() => (${IS_CURRENT_REQUEST_MANAGER})(
|
|
1046
|
-
selected.manager, selected.requestClient, selected.hostId, selected.prewarmedThreadManager,
|
|
1110
|
+
return `(() => {
|
|
1111
|
+
const committedReactAncestors = ${committedReactAncestors.toString()};
|
|
1112
|
+
const requestManagerFromHookState = ${requestManagerFromHookState.toString()};
|
|
1113
|
+
const discoverRendererHosts = ${discoverRendererHosts.toString()};
|
|
1114
|
+
const resolveRendererHostManager = ${resolveRendererHostManager.toString()};
|
|
1115
|
+
const retainRendererHostResponses = ${retainRendererHostResponses.toString()};
|
|
1116
|
+
const createDraftPrewarmPolicyBridge = ${createDraftPrewarmPolicyBridge.toString()};
|
|
1117
|
+
const routing = (${installRendererHostRouting.toString()})(
|
|
1118
|
+
document, window,
|
|
1119
|
+
(root) => discoverRendererHosts(root, committedReactAncestors, requestManagerFromHookState),
|
|
1120
|
+
(discovery, hostId) => resolveRendererHostManager(discovery, hostId, requestManagerFromHookState),
|
|
1121
|
+
(manager, bridge, hostId, target, prewarmed, isCurrent) => createDraftPrewarmPolicyBridge(
|
|
1122
|
+
manager, bridge, hostId, target, prewarmed, isCurrent, retainRendererHostResponses,
|
|
1047
1123
|
),
|
|
1048
|
-
(${retainRendererHostResponses.toString()}),
|
|
1049
1124
|
);
|
|
1125
|
+
if (!routing.forComposer()) throw new Error('Renderer request manager is ambiguous');
|
|
1126
|
+
return { state: 'ready', reason: 'owned-request-bridge' };
|
|
1050
1127
|
})()`;
|
|
1051
1128
|
}
|
|
1052
1129
|
async function waitForDraftPrewarmPolicy(evaluate, expression) {
|
|
@@ -1054,17 +1131,17 @@ async function waitForDraftPrewarmPolicy(evaluate, expression) {
|
|
|
1054
1131
|
while (true) {
|
|
1055
1132
|
try {
|
|
1056
1133
|
const value = await evaluate(expression);
|
|
1057
|
-
if (!
|
|
1134
|
+
if (typeof value !== "object" || value === null || !("state" in value) || value.state !== "ready" || !("reason" in value) || value.reason !== "owned-request-bridge") {
|
|
1058
1135
|
throw new Error("Renderer draft prewarm policy returned an invalid status");
|
|
1059
1136
|
}
|
|
1060
|
-
return
|
|
1137
|
+
return { state: "ready", reason: "owned-request-bridge" };
|
|
1061
1138
|
} catch (error) {
|
|
1062
1139
|
const message = error instanceof Error ? error.message : String(error);
|
|
1063
1140
|
const remaining = deadline - Date.now();
|
|
1064
1141
|
if (!message.includes("Renderer request manager is ambiguous") || remaining <= 0) throw error;
|
|
1065
|
-
await new Promise(
|
|
1066
|
-
setTimeout(resolve, Math.min(REQUEST_MANAGER_POLL_INTERVAL_MS, remaining))
|
|
1067
|
-
|
|
1142
|
+
await new Promise(
|
|
1143
|
+
(resolve) => setTimeout(resolve, Math.min(REQUEST_MANAGER_POLL_INTERVAL_MS, remaining))
|
|
1144
|
+
);
|
|
1068
1145
|
}
|
|
1069
1146
|
}
|
|
1070
1147
|
}
|
|
@@ -1076,7 +1153,7 @@ function installRendererDraftPrewarmPolicyDirect(renderer) {
|
|
|
1076
1153
|
}
|
|
1077
1154
|
|
|
1078
1155
|
// packages/desktop-control/src/renderer-cdp-control-session.ts
|
|
1079
|
-
function
|
|
1156
|
+
function isRecord2(value) {
|
|
1080
1157
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1081
1158
|
}
|
|
1082
1159
|
function sleep(milliseconds) {
|
|
@@ -1110,7 +1187,7 @@ var RendererAdapterReadinessError = class extends Error {
|
|
|
1110
1187
|
reason;
|
|
1111
1188
|
};
|
|
1112
1189
|
function validateBindingStatus(value, expectedAgents) {
|
|
1113
|
-
if (!
|
|
1190
|
+
if (!isRecord2(value) || value.version !== 2 || !Array.isArray(value.enabledAgents) || value.enabledAgents.some((agent) => typeof agent !== "string") || !sameAgents(value.enabledAgents, expectedAgents) || !isRecord2(value.adapter)) {
|
|
1114
1191
|
throw new Error("Production Renderer binding returned an invalid status");
|
|
1115
1192
|
}
|
|
1116
1193
|
if (value.adapter.state !== "ready" || typeof value.adapter.reason !== "string") {
|
|
@@ -1144,8 +1221,8 @@ async function evaluateSource(renderer, source) {
|
|
|
1144
1221
|
expression: source,
|
|
1145
1222
|
awaitPromise: true
|
|
1146
1223
|
});
|
|
1147
|
-
if (!
|
|
1148
|
-
if (
|
|
1224
|
+
if (!isRecord2(response)) throw new Error("Renderer source evaluation returned an invalid result");
|
|
1225
|
+
if (isRecord2(response.exceptionDetails)) {
|
|
1149
1226
|
const text = typeof response.exceptionDetails.text === "string" ? response.exceptionDetails.text : "Renderer source evaluation failed";
|
|
1150
1227
|
throw new Error(text);
|
|
1151
1228
|
}
|
|
@@ -1235,7 +1312,6 @@ var InstalledRendererCdpControlSession = class {
|
|
|
1235
1312
|
try {
|
|
1236
1313
|
const existing = await readBinding(this.renderer);
|
|
1237
1314
|
if (existing === null) await evaluateSource(this.renderer, this.rendererSource);
|
|
1238
|
-
else validateBindingStatus(existing, this.enabledAgents);
|
|
1239
1315
|
const draftPrewarmPolicy = await this.operations.installDraftPrewarmPolicy(this.renderer);
|
|
1240
1316
|
const binding = await waitForBinding(
|
|
1241
1317
|
this.renderer,
|
|
@@ -1494,6 +1570,7 @@ ${rendererSource}`,
|
|
|
1494
1570
|
"muse",
|
|
1495
1571
|
"kiro-cli",
|
|
1496
1572
|
"codebuddy",
|
|
1573
|
+
"workbuddy",
|
|
1497
1574
|
"cursor-cli",
|
|
1498
1575
|
"qoder",
|
|
1499
1576
|
"qoder-cn"
|