@codexhost/cli-darwin-arm64 0.2.6 → 0.3.0-test.2
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 +4 -1
- package/THIRD_PARTY_NOTICES.txt +4 -0
- package/app/codexhost-distribution.json +1 -1
- package/app/desktop-controller.mjs +71 -137
- package/app/host-runtime.mjs +6838 -1627
- package/app/renderer-extension.js +777 -285
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/licenses/ws-LICENSE.txt +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Run Pi and Claude Code as first-class external harnesses inside Codex Desktop.
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install -g @codexhost/cli@0.2
|
|
10
|
+
npm install -g @codexhost/cli@0.3.0-test.2
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Do not install this package directly. npm selects it through the optional dependencies of `@codexhost/cli`.
|
|
@@ -21,6 +21,9 @@ codexhost
|
|
|
21
21
|
codexhost --version
|
|
22
22
|
codexhost inspect
|
|
23
23
|
codexhost launch
|
|
24
|
+
codexhost remote install
|
|
25
|
+
codexhost remote status
|
|
26
|
+
codexhost remote uninstall
|
|
24
27
|
```
|
|
25
28
|
|
|
26
29
|
The `codexhost` command launches the packaged Rust launcher with:
|
package/THIRD_PARTY_NOTICES.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"schemaVersion":1,"version":"0.2
|
|
1
|
+
{"schemaVersion":1,"version":"0.3.0-test.2","distribution":"npm","target":"macos-arm64"}
|
|
@@ -560,49 +560,36 @@ async function readMainProcessTitlePolicyCounters(inspector) {
|
|
|
560
560
|
// packages/desktop-control/src/renderer-draft-prewarm-runtime.ts
|
|
561
561
|
function installDraftPrewarmPolicyBridge(bridge, hostId, target, prewarmedThreadManager) {
|
|
562
562
|
const existing = target.__codexhostDraftPrewarmPolicyV1;
|
|
563
|
+
if (existing?.owns?.length === 3 && existing.owns(bridge, hostId, prewarmedThreadManager) === true) {
|
|
564
|
+
return { state: "ready", reason: "owned-request-bridge" };
|
|
565
|
+
}
|
|
563
566
|
existing?.dispose?.();
|
|
564
567
|
const originalSend = bridge.sendRequest;
|
|
565
568
|
const originalPrewarm = bridge.prewarmThreadStart;
|
|
566
569
|
let selectedModel = null;
|
|
567
|
-
let clearInFlight = null;
|
|
568
570
|
const isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
569
|
-
const
|
|
570
|
-
if (selectedModel === null || !isRecord5(parameters)
|
|
571
|
-
|
|
572
|
-
const settings = isRecord5(collaborationMode) ? collaborationMode.settings : null;
|
|
573
|
-
if (!isRecord5(collaborationMode) || !isRecord5(settings)) {
|
|
574
|
-
throw new Error(`Codex ${method} omitted collaborationMode.settings`);
|
|
571
|
+
const routeThreadStart = (parameters) => {
|
|
572
|
+
if (selectedModel === null || !isRecord5(parameters) || parameters.ephemeral === true) {
|
|
573
|
+
return parameters;
|
|
575
574
|
}
|
|
576
|
-
return {
|
|
577
|
-
...parameters,
|
|
578
|
-
collaborationMode: {
|
|
579
|
-
...collaborationMode,
|
|
580
|
-
settings: { ...settings, model: selectedModel }
|
|
581
|
-
}
|
|
582
|
-
};
|
|
583
|
-
};
|
|
584
|
-
const routeThreadStart = (method, parameters) => {
|
|
585
|
-
if (selectedModel === null || !isRecord5(parameters)) return parameters;
|
|
586
|
-
const direct = method === "thread/start";
|
|
587
|
-
const wrapped = method === "prewarm-thread-start-for-host" || method === "send-cli-request-for-host";
|
|
588
|
-
if (!direct && !wrapped) return parameters;
|
|
589
|
-
const threadParams = direct ? parameters : parameters.params;
|
|
590
|
-
if (!isRecord5(threadParams) || threadParams.ephemeral === true) return parameters;
|
|
591
|
-
if (direct) return { ...threadParams, model: selectedModel };
|
|
592
|
-
return { ...parameters, params: { ...threadParams, model: selectedModel } };
|
|
575
|
+
return { ...parameters, model: selectedModel };
|
|
593
576
|
};
|
|
594
577
|
const routedSend = (method, parameters, options) => {
|
|
595
|
-
const routedParameters = method === "start
|
|
578
|
+
const routedParameters = method === "thread/start" ? routeThreadStart(parameters) : parameters;
|
|
596
579
|
return options === void 0 ? originalSend.call(bridge, method, routedParameters) : originalSend.call(bridge, method, routedParameters, options);
|
|
597
580
|
};
|
|
598
581
|
const routedPrewarm = (parameters, options) => {
|
|
599
|
-
const routedParameters = routeThreadStart(
|
|
600
|
-
return options === void 0 ? originalPrewarm
|
|
582
|
+
const routedParameters = routeThreadStart(parameters);
|
|
583
|
+
return options === void 0 ? originalPrewarm.call(bridge, routedParameters) : originalPrewarm.call(bridge, routedParameters, options);
|
|
601
584
|
};
|
|
602
585
|
bridge.sendRequest = routedSend;
|
|
603
|
-
|
|
586
|
+
bridge.prewarmThreadStart = routedPrewarm;
|
|
604
587
|
const policy = Object.freeze({
|
|
605
588
|
state: "ready",
|
|
589
|
+
hostId,
|
|
590
|
+
owns(candidate, candidateHostId, candidatePrewarmedThreadManager) {
|
|
591
|
+
return candidate === bridge && candidateHostId === hostId && candidatePrewarmedThreadManager === prewarmedThreadManager;
|
|
592
|
+
},
|
|
606
593
|
select(model) {
|
|
607
594
|
if (model !== null && (typeof model !== "string" || !model.startsWith("codexhost/"))) {
|
|
608
595
|
throw new Error("Draft route Model must be a codexhost transport carrier");
|
|
@@ -612,24 +599,13 @@ function installDraftPrewarmPolicyBridge(bridge, hostId, target, prewarmedThread
|
|
|
612
599
|
return true;
|
|
613
600
|
},
|
|
614
601
|
clear() {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
return Promise.resolve();
|
|
618
|
-
}
|
|
619
|
-
if (clearInFlight === null) {
|
|
620
|
-
clearInFlight = Promise.resolve(
|
|
621
|
-
originalSend.call(bridge, "clear-prewarmed-threads-for-host", { hostId })
|
|
622
|
-
).then(() => void 0).finally(() => {
|
|
623
|
-
clearInFlight = null;
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
return clearInFlight;
|
|
602
|
+
prewarmedThreadManager.discardAllPrewarmedThreads();
|
|
603
|
+
return Promise.resolve();
|
|
627
604
|
},
|
|
628
605
|
dispose() {
|
|
629
606
|
if (bridge.sendRequest === routedSend) bridge.sendRequest = originalSend;
|
|
630
607
|
if (bridge.prewarmThreadStart === routedPrewarm) {
|
|
631
|
-
|
|
632
|
-
else delete bridge.prewarmThreadStart;
|
|
608
|
+
bridge.prewarmThreadStart = originalPrewarm;
|
|
633
609
|
}
|
|
634
610
|
selectedModel = null;
|
|
635
611
|
}
|
|
@@ -638,6 +614,9 @@ function installDraftPrewarmPolicyBridge(bridge, hostId, target, prewarmedThread
|
|
|
638
614
|
configurable: true,
|
|
639
615
|
value: policy
|
|
640
616
|
});
|
|
617
|
+
if (typeof target.dispatchEvent === "function" && typeof CustomEvent === "function") {
|
|
618
|
+
target.dispatchEvent(new CustomEvent("codexhost:draft-prewarm-policy-changed"));
|
|
619
|
+
}
|
|
641
620
|
return { state: "ready", reason: "owned-request-bridge" };
|
|
642
621
|
}
|
|
643
622
|
async function installDraftPrewarmPolicyInRenderer(contents, findRequestManagerExpression, installRendererPolicyFunction) {
|
|
@@ -672,87 +651,16 @@ async function installDraftPrewarmPolicyInRenderer(contents, findRequestManagerE
|
|
|
672
651
|
const prewarmedThreadManager = managerProperties.result?.find(
|
|
673
652
|
(property) => property.name === "prewarmedThreadManager"
|
|
674
653
|
)?.value;
|
|
675
|
-
if (candidateCount !== 1 || hostId !== "
|
|
654
|
+
if (candidateCount !== 1 || typeof hostId !== "string" || hostId.length === 0 || typeof manager?.objectId !== "string") {
|
|
676
655
|
throw new Error("Renderer request manager is ambiguous");
|
|
677
656
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
});
|
|
681
|
-
const managerPropertyNames = new Set(
|
|
682
|
-
managerFunctions.result?.map((property) => String(property.name)) ?? []
|
|
683
|
-
);
|
|
684
|
-
let hostBridgeObjectId = managerPropertyNames.has("sendRequest") && managerPropertyNames.has("prewarmThreadStart") && managerPropertyNames.has("enqueueRequest") ? manager.objectId : void 0;
|
|
685
|
-
if (!hostBridgeObjectId) {
|
|
686
|
-
let managerSendRequestId = managerFunctions.result?.find(
|
|
687
|
-
(property) => property.name === "sendRequest"
|
|
688
|
-
)?.value?.objectId;
|
|
689
|
-
const managerPrototypeId = managerFunctions.internalProperties?.find(
|
|
690
|
-
(property) => property.name === "[[Prototype]]"
|
|
691
|
-
)?.value?.objectId;
|
|
692
|
-
if (typeof managerSendRequestId !== "string" && typeof managerPrototypeId === "string") {
|
|
693
|
-
const prototypeFunctions = await contents.debugger.sendCommand("Runtime.getProperties", {
|
|
694
|
-
objectId: managerPrototypeId,
|
|
695
|
-
ownProperties: true
|
|
696
|
-
});
|
|
697
|
-
managerSendRequestId = prototypeFunctions.result?.find(
|
|
698
|
-
(property) => property.name === "sendRequest"
|
|
699
|
-
)?.value?.objectId;
|
|
700
|
-
}
|
|
701
|
-
if (typeof managerSendRequestId !== "string") {
|
|
702
|
-
throw new Error("Renderer request manager sendRequest is unavailable");
|
|
703
|
-
}
|
|
704
|
-
const functionProperties = await contents.debugger.sendCommand("Runtime.getProperties", {
|
|
705
|
-
objectId: managerSendRequestId
|
|
706
|
-
});
|
|
707
|
-
const scopesId = functionProperties.internalProperties?.find(
|
|
708
|
-
(property) => property.name === "[[Scopes]]"
|
|
709
|
-
)?.value?.objectId;
|
|
710
|
-
const hostBridgeCandidates = [];
|
|
711
|
-
if (typeof scopesId === "string") {
|
|
712
|
-
const scopes = await contents.debugger.sendCommand("Runtime.getProperties", {
|
|
713
|
-
objectId: scopesId,
|
|
714
|
-
ownProperties: true
|
|
715
|
-
});
|
|
716
|
-
for (const scope of scopes.result ?? []) {
|
|
717
|
-
if (typeof scope.value?.objectId !== "string") continue;
|
|
718
|
-
const scopeProperties = await contents.debugger.sendCommand("Runtime.getProperties", {
|
|
719
|
-
objectId: scope.value.objectId,
|
|
720
|
-
ownProperties: true
|
|
721
|
-
});
|
|
722
|
-
for (const property of scopeProperties.result ?? []) {
|
|
723
|
-
if (property.value?.type !== "object" || typeof property.value.objectId !== "string") {
|
|
724
|
-
continue;
|
|
725
|
-
}
|
|
726
|
-
const candidateSignature = await contents.debugger.sendCommand(
|
|
727
|
-
"Runtime.callFunctionOn",
|
|
728
|
-
{
|
|
729
|
-
objectId: property.value.objectId,
|
|
730
|
-
functionDeclaration: "function(){const send=this.sendRequest;return typeof send==='function'&&Function.prototype.toString.call(send).includes('messageHandler')}",
|
|
731
|
-
returnByValue: true
|
|
732
|
-
}
|
|
733
|
-
);
|
|
734
|
-
if (candidateSignature.result?.value === true) {
|
|
735
|
-
hostBridgeCandidates.push({
|
|
736
|
-
name: String(property.name),
|
|
737
|
-
objectId: property.value.objectId
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
const hostBridge = hostBridgeCandidates[0];
|
|
744
|
-
if (hostBridgeCandidates.length !== 1 || !hostBridge) {
|
|
745
|
-
throw new Error("Renderer Host request bridge is ambiguous");
|
|
746
|
-
}
|
|
747
|
-
hostBridgeObjectId = hostBridge.objectId;
|
|
657
|
+
if (typeof prewarmedThreadManager?.objectId !== "string") {
|
|
658
|
+
throw new Error("Renderer prewarmed Thread manager is unavailable");
|
|
748
659
|
}
|
|
749
660
|
const installed = await contents.debugger.sendCommand("Runtime.callFunctionOn", {
|
|
750
|
-
objectId:
|
|
661
|
+
objectId: manager.objectId,
|
|
751
662
|
functionDeclaration: installRendererPolicyFunction,
|
|
752
|
-
arguments: [
|
|
753
|
-
{ value: hostId },
|
|
754
|
-
...typeof prewarmedThreadManager?.objectId === "string" ? [{ objectId: prewarmedThreadManager.objectId }] : []
|
|
755
|
-
],
|
|
663
|
+
arguments: [{ value: hostId }, { objectId: prewarmedThreadManager.objectId }],
|
|
756
664
|
awaitPromise: true,
|
|
757
665
|
returnByValue: true
|
|
758
666
|
});
|
|
@@ -763,6 +671,19 @@ async function installDraftPrewarmPolicyInRenderer(contents, findRequestManagerE
|
|
|
763
671
|
}
|
|
764
672
|
|
|
765
673
|
// packages/desktop-control/src/renderer-draft-prewarm-policy.ts
|
|
674
|
+
function selectRendererRequestManager(candidates, activeHostIds) {
|
|
675
|
+
const unique = /* @__PURE__ */ new Map();
|
|
676
|
+
for (const candidate of candidates) unique.set(candidate.manager, candidate);
|
|
677
|
+
const hosts = new Set(
|
|
678
|
+
activeHostIds.filter((value) => typeof value === "string" && value.length > 0)
|
|
679
|
+
);
|
|
680
|
+
if (hosts.size > 1) return null;
|
|
681
|
+
const activeHostId = hosts.values().next().value;
|
|
682
|
+
const eligible = [...unique.values()].filter(
|
|
683
|
+
(candidate) => activeHostId === void 0 || candidate.hostId === activeHostId
|
|
684
|
+
);
|
|
685
|
+
return eligible.length === 1 ? eligible[0] ?? null : null;
|
|
686
|
+
}
|
|
766
687
|
function isRecord3(value) {
|
|
767
688
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
768
689
|
}
|
|
@@ -783,7 +704,15 @@ var FIND_REQUEST_MANAGER_EXPRESSION = `(() => {
|
|
|
783
704
|
element = element.parentElement;
|
|
784
705
|
}
|
|
785
706
|
const managers = new Set();
|
|
707
|
+
const activeHostIds = new Set();
|
|
786
708
|
for (let depth = 0; fiber != null && depth < 200; depth += 1, fiber = fiber.return) {
|
|
709
|
+
const props = fiber.memoizedProps;
|
|
710
|
+
if (props != null && typeof props === 'object') {
|
|
711
|
+
for (const name of ['executionTargetHostId', 'permissionsHostId']) {
|
|
712
|
+
const value = props[name];
|
|
713
|
+
if (typeof value === 'string' && value.length > 0) activeHostIds.add(value);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
787
716
|
let hook = fiber.memoizedState;
|
|
788
717
|
for (let index = 0; hook != null && index < 120; index += 1, hook = hook.next) {
|
|
789
718
|
const value = hook.memoizedState;
|
|
@@ -794,25 +723,33 @@ var FIND_REQUEST_MANAGER_EXPRESSION = `(() => {
|
|
|
794
723
|
typeof value.requestClient.prewarmThreadStart === 'function' &&
|
|
795
724
|
typeof value.requestClient.sendRequest === 'function' &&
|
|
796
725
|
typeof value.requestClient.enqueueRequest === 'function' &&
|
|
726
|
+
typeof value.prewarmedThreadManager?.discardAllPrewarmedThreads === 'function' &&
|
|
797
727
|
typeof value.sendRequest === 'function'
|
|
798
728
|
) {
|
|
799
729
|
managers.add(value);
|
|
800
730
|
}
|
|
801
731
|
}
|
|
802
732
|
}
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
733
|
+
const candidates = [...managers].map((manager) => {
|
|
734
|
+
const requestClient =
|
|
735
|
+
typeof manager.requestClient?.sendRequest === 'function' &&
|
|
736
|
+
typeof manager.requestClient?.prewarmThreadStart === 'function' &&
|
|
737
|
+
typeof manager.requestClient?.enqueueRequest === 'function'
|
|
738
|
+
? manager.requestClient
|
|
739
|
+
: manager;
|
|
740
|
+
return {
|
|
741
|
+
manager,
|
|
742
|
+
requestClient,
|
|
743
|
+
hostId: manager?.getHostId?.() ?? requestClient?.hostId ?? null,
|
|
744
|
+
prewarmedThreadManager: manager?.prewarmedThreadManager ?? null,
|
|
745
|
+
};
|
|
746
|
+
});
|
|
747
|
+
const selected = (${selectRendererRequestManager.toString()})(candidates, [...activeHostIds]);
|
|
811
748
|
return {
|
|
812
|
-
candidateCount:
|
|
813
|
-
hostId:
|
|
814
|
-
manager: requestClient,
|
|
815
|
-
prewarmedThreadManager:
|
|
749
|
+
candidateCount: selected == null ? candidates.length : 1,
|
|
750
|
+
hostId: selected?.hostId ?? null,
|
|
751
|
+
manager: selected?.requestClient ?? null,
|
|
752
|
+
prewarmedThreadManager: selected?.prewarmedThreadManager ?? null,
|
|
816
753
|
};
|
|
817
754
|
})()`;
|
|
818
755
|
var INSTALL_RENDERER_POLICY_FUNCTION = `function(hostId, prewarmedThreadManager) {
|
|
@@ -1013,11 +950,6 @@ var defaultOperations = {
|
|
|
1013
950
|
installTitlePolicy: installMainProcessTitlePolicy,
|
|
1014
951
|
markTitlePolicyReady: markRendererTitlePolicyReady,
|
|
1015
952
|
installDraftPrewarmPolicy: installRendererDraftPrewarmPolicy,
|
|
1016
|
-
readDraftPrewarmPolicy: (inspector, rendererWebContentsId) => executeInWebContents(
|
|
1017
|
-
inspector,
|
|
1018
|
-
rendererWebContentsId,
|
|
1019
|
-
"window.__codexhostDraftPrewarmPolicyV1?.state ?? null"
|
|
1020
|
-
),
|
|
1021
953
|
reload: reloadRenderer,
|
|
1022
954
|
execute: executeInWebContents,
|
|
1023
955
|
readBinding: (inspector, rendererWebContentsId) => executeInWebContents(
|
|
@@ -1088,8 +1020,10 @@ var InstalledRendererControlSession = class {
|
|
|
1088
1020
|
);
|
|
1089
1021
|
const existing = await this.operations.readBinding(this.inspector, selected.id).catch(() => null);
|
|
1090
1022
|
if (existing !== null) {
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1023
|
+
const draftPrewarmPolicy2 = await this.operations.installDraftPrewarmPolicy(
|
|
1024
|
+
this.inspector,
|
|
1025
|
+
selected.id
|
|
1026
|
+
);
|
|
1093
1027
|
let binding2;
|
|
1094
1028
|
try {
|
|
1095
1029
|
binding2 = validateBindingStatus(existing, this.enabledAgents);
|