@ponythewhite/base-context 1.0.0 → 1.0.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/CHANGELOG.md +37 -0
- package/NOTICE +0 -5
- package/README.md +44 -27
- package/dist/NOTICE +0 -5
- package/dist/base-context-runtime/pyproject.toml +1 -1
- package/dist/base-context-runtime/src/rlm/__init__.py +7 -5
- package/dist/base-context-runtime/test/test_subagent_registry.py +28 -1
- package/dist/base-context-runtime/uv.lock +1 -1
- package/dist/build-info.json +1 -1
- package/dist/bundle/amazon-bedrock.js +21 -0
- package/dist/bundle/{anthropic-YY4S534V.js → anthropic-UV5GZDGU.js} +5 -5
- package/dist/bundle/{azure-openai-responses-JRP6MIM3.js → azure-openai-responses-WSNPXLYC.js} +6 -6
- package/dist/bundle/{bundled-modules-P5HARVZA.js → bundled-modules-PWOGKUQQ.js} +71 -16
- package/dist/bundle/chunk-27QCJ2AZ.js +2578 -0
- package/dist/bundle/{chunk-BYVP7LWV.js → chunk-44PEHPOG.js} +1916 -4689
- package/dist/bundle/{chunk-MZHTNNVA.js → chunk-4GXPNXOJ.js} +8 -0
- package/dist/bundle/{chunk-SC5KG5R4.js → chunk-DGNX7HQ3.js} +1 -7
- package/dist/bundle/{chunk-A53O363M.js → chunk-GRJFXLBM.js} +0 -1
- package/dist/bundle/chunk-HKINIBP4.js +29 -0
- package/dist/bundle/{chunk-73DCPU3D.js → chunk-IADCPVEI.js} +1019 -3427
- package/dist/bundle/{chunk-UDSW6FNG.js → chunk-KTNETTHI.js} +1 -1
- package/dist/bundle/{chunk-U7AUVG3B.js → chunk-VSIYFWYI.js} +24 -6
- package/dist/bundle/{chunk-IW77OXFS.js → chunk-W46VZFI6.js} +0 -2099
- package/dist/bundle/{cli-main-O4X7GFGY.js → cli-main-4DS7Y3PI.js} +8 -6
- package/dist/bundle/cli.js +2 -2
- package/dist/bundle/{google-AUTVGDGZ.js → google-T32FMD4G.js} +6 -6
- package/dist/bundle/{google-vertex-Q75D7RKS.js → google-vertex-56KP6I3B.js} +3 -3
- package/dist/bundle/{main-XKOW2BV6.js → main-SV7JLVEB.js} +7 -5
- package/dist/bundle/{mistral-7ESB7QUD.js → mistral-WGBMYIVU.js} +5 -5
- package/dist/bundle/{openai-codex-responses-LV3QRPN4.js → openai-codex-responses-PIV2RQ3G.js} +6 -6
- package/dist/bundle/{openai-completions-OJECLPXJ.js → openai-completions-64C3JPR4.js} +11 -22
- package/dist/bundle/{openai-responses-FN6HZMBC.js → openai-responses-UI7RSTDV.js} +6 -6
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +108 -59
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/daemon-ps.d.ts +4 -3
- package/dist/cli/daemon-ps.d.ts.map +1 -1
- package/dist/cli/daemon-ps.js +6 -1
- package/dist/cli/daemon-ps.js.map +1 -1
- package/dist/cli/product-doctor.d.ts +0 -1
- package/dist/cli/product-doctor.d.ts.map +1 -1
- package/dist/cli/product-doctor.js +6 -3
- package/dist/cli/product-doctor.js.map +1 -1
- package/dist/config.d.ts +0 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -8
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-config.d.ts +1 -2
- package/dist/core/agent-session-config.d.ts.map +1 -1
- package/dist/core/agent-session-config.js +0 -3
- package/dist/core/agent-session-config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +5 -4
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +5 -3
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +2 -27
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +10 -6
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +107 -107
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +8 -35
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +33 -243
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/cron-jobs.d.ts.map +1 -1
- package/dist/core/cron-jobs.js +7 -1
- package/dist/core/cron-jobs.js.map +1 -1
- package/dist/core/inference-coordinator.d.ts +6 -1
- package/dist/core/inference-coordinator.d.ts.map +1 -1
- package/dist/core/inference-coordinator.js +18 -2
- package/dist/core/inference-coordinator.js.map +1 -1
- package/dist/core/kernel/bootstrap.d.ts.map +1 -1
- package/dist/core/kernel/bootstrap.js +2 -2
- package/dist/core/kernel/bootstrap.js.map +1 -1
- package/dist/core/kernel/repl-manager.d.ts +2 -0
- package/dist/core/kernel/repl-manager.d.ts.map +1 -1
- package/dist/core/kernel/repl-manager.js +44 -1
- package/dist/core/kernel/repl-manager.js.map +1 -1
- package/dist/core/logging.d.ts +4 -3
- package/dist/core/logging.d.ts.map +1 -1
- package/dist/core/logging.js +6 -6
- package/dist/core/logging.js.map +1 -1
- package/dist/core/mcp/mcp-manager.d.ts.map +1 -1
- package/dist/core/mcp/mcp-manager.js +3 -3
- package/dist/core/mcp/mcp-manager.js.map +1 -1
- package/dist/core/model-registry.d.ts +1 -16
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +88 -196
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +2 -19
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +36 -266
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/provider-contracts.d.ts +5 -6
- package/dist/core/provider-contracts.d.ts.map +1 -1
- package/dist/core/provider-contracts.js +25 -36
- package/dist/core/provider-contracts.js.map +1 -1
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +0 -2
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/rlm-max-subagents.d.ts +32 -0
- package/dist/core/rlm-max-subagents.d.ts.map +1 -0
- package/dist/core/rlm-max-subagents.js +50 -0
- package/dist/core/rlm-max-subagents.js.map +1 -0
- package/dist/core/rlm-runtime.d.ts +3 -3
- package/dist/core/rlm-runtime.d.ts.map +1 -1
- package/dist/core/rlm-runtime.js.map +1 -1
- package/dist/core/sdk.d.ts +4 -3
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +27 -14
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +3 -16
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +12 -44
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +6 -6
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/installer.mjs +2 -3
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +39 -34
- package/dist/main.js.map +1 -1
- package/dist/modes/acp/acp-mode.d.ts.map +1 -1
- package/dist/modes/acp/acp-mode.js +1 -1
- package/dist/modes/acp/acp-mode.js.map +1 -1
- package/dist/modes/agent-connection/daemon-agent-connection.d.ts +6 -2
- package/dist/modes/agent-connection/daemon-agent-connection.d.ts.map +1 -1
- package/dist/modes/agent-connection/daemon-agent-connection.js +13 -2
- package/dist/modes/agent-connection/daemon-agent-connection.js.map +1 -1
- package/dist/modes/agent-connection/in-process-agent-connection.d.ts +2 -0
- package/dist/modes/agent-connection/in-process-agent-connection.d.ts.map +1 -1
- package/dist/modes/agent-connection/in-process-agent-connection.js +6 -0
- package/dist/modes/agent-connection/in-process-agent-connection.js.map +1 -1
- package/dist/modes/agent-connection/types.d.ts +3 -0
- package/dist/modes/agent-connection/types.d.ts.map +1 -1
- package/dist/modes/agent-connection/types.js.map +1 -1
- package/dist/modes/agents-view/agents-view-mode.d.ts.map +1 -1
- package/dist/modes/agents-view/agents-view-mode.js +2 -19
- package/dist/modes/agents-view/agents-view-mode.js.map +1 -1
- package/dist/modes/daemon/daemon-mode.d.ts +5 -0
- package/dist/modes/daemon/daemon-mode.d.ts.map +1 -1
- package/dist/modes/daemon/daemon-mode.js +107 -12
- package/dist/modes/daemon/daemon-mode.js.map +1 -1
- package/dist/modes/daemon/daemon-protocol.d.ts +194 -165
- package/dist/modes/daemon/daemon-protocol.d.ts.map +1 -1
- package/dist/modes/daemon/daemon-protocol.js +16 -11
- package/dist/modes/daemon/daemon-protocol.js.map +1 -1
- package/dist/modes/daemon/daemon-rlm-capacity-coordinator.d.ts +19 -0
- package/dist/modes/daemon/daemon-rlm-capacity-coordinator.d.ts.map +1 -0
- package/dist/modes/daemon/daemon-rlm-capacity-coordinator.js +74 -0
- package/dist/modes/daemon/daemon-rlm-capacity-coordinator.js.map +1 -0
- package/dist/modes/daemon/daemon-rlm-capacity.d.ts +19 -0
- package/dist/modes/daemon/daemon-rlm-capacity.d.ts.map +1 -0
- package/dist/modes/daemon/daemon-rlm-capacity.js +85 -0
- package/dist/modes/daemon/daemon-rlm-capacity.js.map +1 -0
- package/dist/modes/daemon/daemon-session-summarizer.d.ts +2 -3
- package/dist/modes/daemon/daemon-session-summarizer.d.ts.map +1 -1
- package/dist/modes/daemon/daemon-session-summarizer.js +32 -23
- package/dist/modes/daemon/daemon-session-summarizer.js.map +1 -1
- package/dist/modes/daemon/daemon-state-root.d.ts +15 -0
- package/dist/modes/daemon/daemon-state-root.d.ts.map +1 -0
- package/dist/modes/daemon/daemon-state-root.js +40 -0
- package/dist/modes/daemon/daemon-state-root.js.map +1 -0
- package/dist/modes/daemon/daemon-supervisor-ownership.d.ts +2 -0
- package/dist/modes/daemon/daemon-supervisor-ownership.d.ts.map +1 -1
- package/dist/modes/daemon/daemon-supervisor-ownership.js +27 -0
- package/dist/modes/daemon/daemon-supervisor-ownership.js.map +1 -1
- package/dist/modes/daemon/daemon-supervisor.d.ts +10 -1
- package/dist/modes/daemon/daemon-supervisor.d.ts.map +1 -1
- package/dist/modes/daemon/daemon-supervisor.js +213 -20
- package/dist/modes/daemon/daemon-supervisor.js.map +1 -1
- package/dist/modes/daemon/daemon-worker-protocol.d.ts +28 -1
- package/dist/modes/daemon/daemon-worker-protocol.d.ts.map +1 -1
- package/dist/modes/daemon/daemon-worker-protocol.js +16 -2
- package/dist/modes/daemon/daemon-worker-protocol.js.map +1 -1
- package/dist/modes/daemon/saved-session-catalog.d.ts.map +1 -1
- package/dist/modes/daemon/saved-session-catalog.js +2 -0
- package/dist/modes/daemon/saved-session-catalog.js.map +1 -1
- package/dist/modes/interactive/auth-flows.d.ts +0 -6
- package/dist/modes/interactive/auth-flows.d.ts.map +1 -1
- package/dist/modes/interactive/auth-flows.js +6 -126
- package/dist/modes/interactive/auth-flows.js.map +1 -1
- package/dist/modes/interactive/components/configuration-menu.d.ts +3 -0
- package/dist/modes/interactive/components/configuration-menu.d.ts.map +1 -1
- package/dist/modes/interactive/components/configuration-menu.js +13 -2
- package/dist/modes/interactive/components/configuration-menu.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +2 -2
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +0 -1
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +0 -1
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +0 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +3 -40
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +2 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +13 -2
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +2 -11
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/feature-hints.d.ts.map +1 -1
- package/dist/modes/interactive/feature-hints.js +0 -4
- package/dist/modes/interactive/feature-hints.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +3 -12
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +81 -507
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/onboarding.d.ts +0 -3
- package/dist/modes/interactive/onboarding.d.ts.map +1 -1
- package/dist/modes/interactive/onboarding.js +0 -17
- package/dist/modes/interactive/onboarding.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +4 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +82 -42
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/node/amazon-bedrock.d.ts +2 -0
- package/dist/node/amazon-bedrock.d.ts.map +1 -0
- package/dist/node/amazon-bedrock.js +6 -0
- package/dist/node/amazon-bedrock.js.map +1 -0
- package/dist/product-identity.d.ts +0 -1
- package/dist/product-identity.d.ts.map +1 -1
- package/dist/product-identity.js +0 -1
- package/dist/product-identity.js.map +1 -1
- package/docs/development.md +1 -1
- package/docs/fork-philosophy.md +4 -8
- package/docs/installation.md +83 -62
- package/docs/providers.md +23 -25
- package/docs/quickstart.md +19 -10
- package/docs/rlm-runtime.md +13 -5
- package/docs/rpc.md +4 -4
- package/docs/sdk.md +20 -11
- package/docs/sessions.md +0 -1
- package/docs/settings.md +9 -42
- package/docs/skills.md +0 -1
- package/docs/upstream-0.9.5.md +171 -0
- package/docs/usage.md +14 -10
- package/package.json +4 -4
- package/dist/core/agent-traces.d.ts +0 -149
- package/dist/core/agent-traces.d.ts.map +0 -1
- package/dist/core/agent-traces.js +0 -904
- package/dist/core/agent-traces.js.map +0 -1
- package/dist/core/prime-inference-auth.d.ts +0 -70
- package/dist/core/prime-inference-auth.d.ts.map +0 -1
- package/dist/core/prime-inference-auth.js +0 -352
- package/dist/core/prime-inference-auth.js.map +0 -1
- package/dist/core/prime-inference-model-selection.d.ts +0 -16
- package/dist/core/prime-inference-model-selection.d.ts.map +0 -1
- package/dist/core/prime-inference-model-selection.js +0 -16
- package/dist/core/prime-inference-model-selection.js.map +0 -1
- package/dist/core/prime-inference-models.d.ts +0 -6
- package/dist/core/prime-inference-models.d.ts.map +0 -1
- package/dist/core/prime-inference-models.js +0 -62
- package/dist/core/prime-inference-models.js.map +0 -1
- package/dist/core/telemetry.d.ts +0 -95
- package/dist/core/telemetry.d.ts.map +0 -1
- package/dist/core/telemetry.js +0 -637
- package/dist/core/telemetry.js.map +0 -1
- package/dist/modes/interactive/components/prime-onboarding-splash.d.ts +0 -39
- package/dist/modes/interactive/components/prime-onboarding-splash.d.ts.map +0 -1
- package/dist/modes/interactive/components/prime-onboarding-splash.js +0 -286
- package/dist/modes/interactive/components/prime-onboarding-splash.js.map +0 -1
- package/dist/modes/interactive/components/prime-team-selector.d.ts +0 -30
- package/dist/modes/interactive/components/prime-team-selector.d.ts.map +0 -1
- package/dist/modes/interactive/components/prime-team-selector.js +0 -166
- package/dist/modes/interactive/components/prime-team-selector.js.map +0 -1
- package/dist/skills/prime-intellect/SKILL.md +0 -87
- package/dist/skills/prime-intellect/references/compute.md +0 -45
- package/dist/skills/prime-intellect/references/environments.md +0 -73
- package/dist/skills/prime-intellect/references/inference.md +0 -47
- package/dist/skills/prime-intellect/references/sandboxes.md +0 -75
- package/skills/prime-intellect/SKILL.md +0 -87
- package/skills/prime-intellect/references/compute.md +0 -45
- package/skills/prime-intellect/references/environments.md +0 -73
- package/skills/prime-intellect/references/inference.md +0 -47
- package/skills/prime-intellect/references/sandboxes.md +0 -75
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import type { Api, Model } from "@ponythewhite/base-context-ai";
|
|
2
|
-
import type { AuthStatus } from "../../core/auth-storage.js";
|
|
3
2
|
export interface OnboardingSettingsReader {
|
|
4
3
|
getOnboardingShown(): boolean;
|
|
5
4
|
}
|
|
6
5
|
export interface OnboardingModelRegistryReader {
|
|
7
6
|
refresh(): void;
|
|
8
7
|
hasConfiguredAuth(model: Model<Api>): boolean;
|
|
9
|
-
getProviderAuthStatus(provider: string): AuthStatus;
|
|
10
8
|
}
|
|
11
9
|
export interface OnboardingStartupState {
|
|
12
10
|
settingsManager: OnboardingSettingsReader;
|
|
13
11
|
modelRegistry: OnboardingModelRegistryReader;
|
|
14
12
|
model: Model<Api> | undefined;
|
|
15
13
|
}
|
|
16
|
-
export declare function shouldRunPrimeCliOnboardingSplash(state: OnboardingStartupState): boolean;
|
|
17
14
|
export declare function isOnboardingModelReady(state: OnboardingStartupState): boolean;
|
|
18
15
|
export declare function shouldRunOnboarding(state: OnboardingStartupState): boolean;
|
|
19
16
|
//# sourceMappingURL=onboarding.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onboarding.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/onboarding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"onboarding.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/onboarding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,WAAW,wBAAwB;IACxC,kBAAkB,IAAI,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,6BAA6B;IAC7C,OAAO,IAAI,IAAI,CAAC;IAChB,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;CAC9C;AAED,MAAM,WAAW,sBAAsB;IACtC,eAAe,EAAE,wBAAwB,CAAC;IAC1C,aAAa,EAAE,6BAA6B,CAAC;IAC7C,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;CAC9B;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAE7E;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAG1E","sourcesContent":["import type { Api, Model } from \"@ponythewhite/base-context-ai\";\n\nexport interface OnboardingSettingsReader {\n\tgetOnboardingShown(): boolean;\n}\n\nexport interface OnboardingModelRegistryReader {\n\trefresh(): void;\n\thasConfiguredAuth(model: Model<Api>): boolean;\n}\n\nexport interface OnboardingStartupState {\n\tsettingsManager: OnboardingSettingsReader;\n\tmodelRegistry: OnboardingModelRegistryReader;\n\tmodel: Model<Api> | undefined;\n}\n\nexport function isOnboardingModelReady(state: OnboardingStartupState): boolean {\n\treturn state.model !== undefined && state.modelRegistry.hasConfiguredAuth(state.model);\n}\n\nexport function shouldRunOnboarding(state: OnboardingStartupState): boolean {\n\tstate.modelRegistry.refresh();\n\treturn !isOnboardingModelReady(state);\n}\n"]}
|
|
@@ -1,25 +1,8 @@
|
|
|
1
|
-
import { PRIME_INFERENCE_PROVIDER_ID } from "../../core/prime-inference-auth.js";
|
|
2
|
-
export function shouldRunPrimeCliOnboardingSplash(state) {
|
|
3
|
-
if (state.settingsManager.getOnboardingShown()) {
|
|
4
|
-
return false;
|
|
5
|
-
}
|
|
6
|
-
if (!state.model || state.model.provider !== PRIME_INFERENCE_PROVIDER_ID) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
const authStatus = state.modelRegistry.getProviderAuthStatus(PRIME_INFERENCE_PROVIDER_ID);
|
|
10
|
-
return authStatus.source === "prime_cli";
|
|
11
|
-
}
|
|
12
1
|
export function isOnboardingModelReady(state) {
|
|
13
2
|
return state.model !== undefined && state.modelRegistry.hasConfiguredAuth(state.model);
|
|
14
3
|
}
|
|
15
4
|
export function shouldRunOnboarding(state) {
|
|
16
|
-
if (state.settingsManager.getOnboardingShown()) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
5
|
state.modelRegistry.refresh();
|
|
20
|
-
if (shouldRunPrimeCliOnboardingSplash(state)) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
6
|
return !isOnboardingModelReady(state);
|
|
24
7
|
}
|
|
25
8
|
//# sourceMappingURL=onboarding.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onboarding.js","sourceRoot":"","sources":["../../../src/modes/interactive/onboarding.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"onboarding.js","sourceRoot":"","sources":["../../../src/modes/interactive/onboarding.ts"],"names":[],"mappings":"AAiBA,MAAM,UAAU,sBAAsB,CAAC,KAA6B,EAAW;IAC9E,OAAO,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,aAAa,CAAC,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAAA,CACvF;AAED,MAAM,UAAU,mBAAmB,CAAC,KAA6B,EAAW;IAC3E,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;IAC9B,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;AAAA,CACtC","sourcesContent":["import type { Api, Model } from \"@ponythewhite/base-context-ai\";\n\nexport interface OnboardingSettingsReader {\n\tgetOnboardingShown(): boolean;\n}\n\nexport interface OnboardingModelRegistryReader {\n\trefresh(): void;\n\thasConfiguredAuth(model: Model<Api>): boolean;\n}\n\nexport interface OnboardingStartupState {\n\tsettingsManager: OnboardingSettingsReader;\n\tmodelRegistry: OnboardingModelRegistryReader;\n\tmodel: Model<Api> | undefined;\n}\n\nexport function isOnboardingModelReady(state: OnboardingStartupState): boolean {\n\treturn state.model !== undefined && state.modelRegistry.hasConfiguredAuth(state.model);\n}\n\nexport function shouldRunOnboarding(state: OnboardingStartupState): boolean {\n\tstate.modelRegistry.refresh();\n\treturn !isOnboardingModelReady(state);\n}\n"]}
|
|
@@ -66,7 +66,7 @@ export declare class RpcClient {
|
|
|
66
66
|
getStderr(): string;
|
|
67
67
|
/**
|
|
68
68
|
* Send a prompt to the agent.
|
|
69
|
-
*
|
|
69
|
+
* Resolves after admission succeeds; use onEvent() to receive streaming events.
|
|
70
70
|
* Use waitForIdle() to wait for completion.
|
|
71
71
|
*/
|
|
72
72
|
prompt(message: string, images?: ImageContent[]): Promise<void>;
|
|
@@ -245,10 +245,13 @@ export declare class RpcClient {
|
|
|
245
245
|
* Collect events until agent becomes idle.
|
|
246
246
|
*/
|
|
247
247
|
collectEvents(timeout?: number): Promise<AgentEvent[]>;
|
|
248
|
+
private createEventCollection;
|
|
248
249
|
/**
|
|
249
250
|
* Send prompt and wait for completion, returning all events.
|
|
250
251
|
*/
|
|
251
252
|
promptAndWait(message: string, images?: ImageContent[], timeout?: number): Promise<AgentEvent[]>;
|
|
253
|
+
private processExitError;
|
|
254
|
+
private rejectPendingRequests;
|
|
252
255
|
private handleLine;
|
|
253
256
|
private send;
|
|
254
257
|
private getData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACN,KAAK,UAAU,EACf,KAAK,YAAY,EAEjB,KAAK,aAAa,EAClB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,0BAA0B,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAChH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,KAAK,EACX,YAAY,EACZ,0BAA0B,EAC1B,8BAA8B,EAC9B,0BAA0B,EAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;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;YAmCJ,IAAI;IA+BlB,OAAO,CAAC,OAAO;CAUf","sourcesContent":["/**\n * RPC Client for programmatic access to the coding agent.\n *\n * Spawns the agent in RPC mode and provides a typed API for all operations.\n */\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport {\n\ttype AgentEvent,\n\ttype AgentMessage,\n\tAgentOutputLimitError,\n\ttype ThinkingLevel,\n} from \"@ponythewhite/base-context-agent\";\nimport type { ImageContent } from \"@ponythewhite/base-context-ai\";\nimport type { AgentSessionMessageReceipt, AgentSessionMessageSafetyStatus } from \"../../core/agent-messages.js\";\nimport type { BashResult } from \"../../core/bash-executor.js\";\nimport type { CompactionResult } from \"../../core/compaction/index.js\";\nimport type {\n\tAgentCronJob,\n\tAgentHeartbeatDeliveryMode,\n\tAgentHeartbeatManagementAction,\n\tAgentHeartbeatUpdateAction,\n} from \"../../core/cron-jobs.js\";\nimport type { RefinementResult } from \"../../core/refinement/index.js\";\nimport type { SessionStats } from \"../../core/session-stats.js\";\nimport type { AgentConnectionHeartbeat } from \"../agent-connection/types.js\";\nimport { CANONICAL_SESSION_OWNERSHIP_COMPATIBILITY, DAEMON_PROTOCOL_VERSION } from \"../daemon/daemon-protocol.js\";\nimport { attachJsonlLineReader, serializeJsonLine } from \"./jsonl.js\";\nimport type {\n\tRpcCommand,\n\tRpcObservedSessionEvent,\n\tRpcPromptCompletionError,\n\tRpcResponse,\n\tRpcSessionState,\n\tRpcSlashCommand,\n} from \"./rpc-types.js\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\nfunction promptCompletionError(event: AgentEvent): string | undefined {\n\tconst output = event as AgentEvent | RpcPromptCompletionError;\n\tif (\n\t\toutput.type === \"extension_error\" &&\n\t\toutput.extensionPath === \"<session-input>\" &&\n\t\toutput.event === \"prompt_completion\"\n\t)\n\t\treturn output.error;\n\treturn undefined;\n}\n\n/** Extended response timeout for refine requests, which run an LLM pass. */\nexport const REFINE_REQUEST_TIMEOUT_MS = 10 * 60 * 1000;\n\n/** Distributive Omit that works with union types */\ntype DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;\n\n/** RpcCommand without the id field (for internal send) */\ntype RpcCommandBody = DistributiveOmit<RpcCommand, \"id\">;\n\nexport interface RpcClientOptions {\n\t/** Path to the CLI entry point (default: searches for dist/cli.js) */\n\tcliPath?: string;\n\t/** Working directory for the agent */\n\tcwd?: string;\n\t/** Environment variables */\n\tenv?: Record<string, string>;\n\t/** Provider to use */\n\tprovider?: string;\n\t/** Model ID to use */\n\tmodel?: string;\n\t/** Additional CLI arguments */\n\targs?: string[];\n}\n\nexport interface ModelInfo {\n\tprovider: string;\n\tid: string;\n\tcontextWindow: number;\n\treasoning: boolean;\n}\n\nexport type RpcEventListener = (event: AgentEvent) => void;\nexport type RpcObservedSessionListener = (event: RpcObservedSessionEvent) => void;\n\n// ============================================================================\n// RPC Client\n// ============================================================================\n\nexport class RpcClient {\n\tprivate process: ChildProcess | null = null;\n\tprivate stopReadingStdout: (() => void) | null = null;\n\tprivate eventListeners: RpcEventListener[] = [];\n\tprivate observedSessionListeners: RpcObservedSessionListener[] = [];\n\tprivate pendingRequests: Map<string, { resolve: (response: RpcResponse) => void; reject: (error: Error) => void }> =\n\t\tnew Map();\n\tprivate requestId = 0;\n\tprivate stderr = \"\";\n\n\tconstructor(private options: RpcClientOptions = {}) {}\n\n\t/**\n\t * Start the RPC agent process.\n\t */\n\tasync start(): Promise<void> {\n\t\tif (this.process) {\n\t\t\tthrow new Error(\"Client already started\");\n\t\t}\n\n\t\tconst cliPath = this.options.cliPath ?? \"dist/cli.js\";\n\t\tconst args = [\"--mode\", \"rpc\", \"--rpc-protocol-version\", String(DAEMON_PROTOCOL_VERSION)];\n\n\t\tif (this.options.provider) {\n\t\t\targs.push(\"--provider\", this.options.provider);\n\t\t}\n\t\tif (this.options.model) {\n\t\t\targs.push(\"--model\", this.options.model);\n\t\t}\n\t\tif (this.options.args) {\n\t\t\targs.push(...this.options.args);\n\t\t}\n\n\t\tthis.process = spawn(\"node\", [cliPath, ...args], {\n\t\t\tcwd: this.options.cwd,\n\t\t\tenv: { ...process.env, ...this.options.env },\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t});\n\n\t\t// Collect stderr for debugging\n\t\tthis.process.stderr?.on(\"data\", (data) => {\n\t\t\tthis.stderr += data.toString();\n\t\t\tprocess.stderr.write(data);\n\t\t});\n\n\t\t// Set up strict JSONL reader for stdout.\n\t\tthis.stopReadingStdout = attachJsonlLineReader(this.process.stdout!, (line) => {\n\t\t\tthis.handleLine(line);\n\t\t});\n\n\t\t// Wait a moment for process to initialize\n\t\tawait new Promise((resolve) => setTimeout(resolve, 100));\n\n\t\tif (this.process.exitCode !== null) {\n\t\t\tthrow new Error(`Agent process exited immediately with code ${this.process.exitCode}. Stderr: ${this.stderr}`);\n\t\t}\n\t\ttry {\n\t\t\tconst state = await this.getState();\n\t\t\tif (state.protocolVersion !== DAEMON_PROTOCOL_VERSION)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Incompatible RPC protocol: expected ${DAEMON_PROTOCOL_VERSION}, got ${state.protocolVersion ?? \"unversioned\"}`,\n\t\t\t\t);\n\t\t\tconst minimumSchema = CANONICAL_SESSION_OWNERSHIP_COMPATIBILITY.minSchemaRevision;\n\t\t\tif (!Number.isSafeInteger(state.schemaRevision) || (state.schemaRevision ?? 0) < minimumSchema)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Incompatible RPC schema: expected at least ${minimumSchema}, got ${state.schemaRevision ?? \"unversioned\"}`,\n\t\t\t\t);\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tawait this.stop();\n\t\t\t} catch (cleanupError) {\n\t\t\t\tthrow new AggregateError([error, cleanupError], \"RPC startup and cleanup failed\", { cause: error });\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Stop the RPC agent process.\n\t */\n\tasync stop(): Promise<void> {\n\t\tif (!this.process) return;\n\n\t\tthis.stopReadingStdout?.();\n\t\tthis.stopReadingStdout = null;\n\t\tthis.process.kill(\"SIGTERM\");\n\n\t\t// Wait for process to exit\n\t\tawait new Promise<void>((resolve) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tthis.process?.kill(\"SIGKILL\");\n\t\t\t\tresolve();\n\t\t\t}, 1000);\n\n\t\t\tthis.process?.on(\"exit\", () => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\n\t\tthis.process = null;\n\t\tthis.pendingRequests.clear();\n\t}\n\n\t/**\n\t * Subscribe to agent events.\n\t */\n\tonEvent(listener: RpcEventListener): () => void {\n\t\tthis.eventListeners.push(listener);\n\t\treturn () => {\n\t\t\tconst index = this.eventListeners.indexOf(listener);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.eventListeners.splice(index, 1);\n\t\t\t}\n\t\t};\n\t}\n\n\tonObservedSessionEvent(listener: RpcObservedSessionListener): () => void {\n\t\tthis.observedSessionListeners.push(listener);\n\t\treturn () => {\n\t\t\tconst index = this.observedSessionListeners.indexOf(listener);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.observedSessionListeners.splice(index, 1);\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Get collected stderr output (useful for debugging).\n\t */\n\tgetStderr(): string {\n\t\treturn this.stderr;\n\t}\n\n\t// =========================================================================\n\t// Command Methods\n\t// =========================================================================\n\n\t/**\n\t * Send a prompt to the agent.\n\t * Returns immediately after sending; use onEvent() to receive streaming events.\n\t * Use waitForIdle() to wait for completion.\n\t */\n\tasync prompt(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"prompt\", message, images });\n\t}\n\n\t/**\n\t * Queue a steering message to interrupt the agent mid-run.\n\t */\n\tasync steer(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"steer\", message, images });\n\t}\n\n\t/**\n\t * Queue a follow-up message to be processed after the agent finishes.\n\t */\n\tasync followUp(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"follow_up\", message, images });\n\t}\n\n\t/**\n\t * Abort current operation.\n\t */\n\tasync abort(): Promise<void> {\n\t\tawait this.send({ type: \"abort\" });\n\t}\n\n\t/**\n\t * Start a new session, optionally with parent tracking.\n\t * @param parentSession - Optional parent session path for lineage tracking\n\t * @returns Object with `cancelled: true` if an extension cancelled the new session\n\t */\n\tasync newSession(parentSession?: string): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"new_session\", parentSession });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get current session state.\n\t */\n\tasync getState(): Promise<RpcSessionState> {\n\t\tconst response = await this.send({ type: \"get_state\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set model by provider and ID.\n\t */\n\tasync setModel(provider: string, modelId: string): Promise<{ provider: string; id: string }> {\n\t\tconst response = await this.send({ type: \"set_model\", provider, modelId });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Cycle to next model.\n\t */\n\tasync cycleModel(): Promise<{\n\t\tmodel: { provider: string; id: string };\n\t\tthinkingLevel: ThinkingLevel;\n\t\tisScoped: boolean;\n\t} | null> {\n\t\tconst response = await this.send({ type: \"cycle_model\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get list of available models.\n\t */\n\tasync getAvailableModels(): Promise<ModelInfo[]> {\n\t\tconst response = await this.send({ type: \"get_available_models\" });\n\t\treturn this.getData<{ models: ModelInfo[] }>(response).models;\n\t}\n\n\t/**\n\t * Set thinking level.\n\t */\n\tasync setThinkingLevel(level: ThinkingLevel): Promise<void> {\n\t\tawait this.send({ type: \"set_thinking_level\", level });\n\t}\n\n\t/**\n\t * Cycle thinking level.\n\t */\n\tasync cycleThinkingLevel(): Promise<{ level: ThinkingLevel } | null> {\n\t\tconst response = await this.send({ type: \"cycle_thinking_level\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set steering mode.\n\t */\n\tasync setSteeringMode(mode: \"all\" | \"one-at-a-time\"): Promise<void> {\n\t\tawait this.send({ type: \"set_steering_mode\", mode });\n\t}\n\n\t/**\n\t * Set follow-up mode.\n\t */\n\tasync setFollowUpMode(mode: \"all\" | \"one-at-a-time\"): Promise<void> {\n\t\tawait this.send({ type: \"set_follow_up_mode\", mode });\n\t}\n\n\t/**\n\t * Compact session context.\n\t */\n\tasync compact(customInstructions?: string): Promise<CompactionResult> {\n\t\tconst response = await this.send({ type: \"compact\", customInstructions });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Refine editable continual harness state.\n\t */\n\tasync refine(\n\t\toptions: { instructions?: string; rollbackId?: string; global?: boolean } = {},\n\t): Promise<RefinementResult> {\n\t\t// Refinement runs an LLM pass that routinely exceeds the default 30s response\n\t\t// timeout, so use the same extended window as the daemon refine path.\n\t\tconst command = { type: \"refine\", instructions: options.instructions, rollbackId: options.rollbackId } as {\n\t\t\ttype: \"refine\";\n\t\t\tinstructions?: string;\n\t\t\trollbackId?: string;\n\t\t\tglobal?: boolean;\n\t\t};\n\t\tif (options.global !== undefined) {\n\t\t\tcommand.global = options.global;\n\t\t}\n\t\tconst response = await this.send(command, REFINE_REQUEST_TIMEOUT_MS);\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set auto-compaction enabled/disabled.\n\t */\n\tasync setAutoCompaction(enabled: boolean): Promise<void> {\n\t\tawait this.send({ type: \"set_auto_compaction\", enabled });\n\t}\n\n\t/**\n\t * Set auto-retry enabled/disabled.\n\t */\n\tasync setAutoRetry(enabled: boolean): Promise<void> {\n\t\tawait this.send({ type: \"set_auto_retry\", enabled });\n\t}\n\n\t/**\n\t * Abort in-progress retry.\n\t */\n\tasync abortRetry(): Promise<void> {\n\t\tawait this.send({ type: \"abort_retry\" });\n\t}\n\n\t/**\n\t * Execute a bash command.\n\t */\n\tasync bash(command: string): Promise<BashResult> {\n\t\tconst response = await this.send({ type: \"bash\", command });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Abort running bash command.\n\t */\n\tasync abortBash(): Promise<void> {\n\t\tawait this.send({ type: \"abort_bash\" });\n\t}\n\n\t/**\n\t * Get session statistics.\n\t */\n\tasync getSessionStats(): Promise<SessionStats> {\n\t\tconst response = await this.send({ type: \"get_session_stats\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Export session to HTML.\n\t */\n\tasync exportHtml(outputPath?: string): Promise<{ path: string }> {\n\t\tconst response = await this.send({ type: \"export_html\", outputPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Switch to a different session file.\n\t * @returns Object with `cancelled: true` if an extension cancelled the switch\n\t */\n\tasync switchSession(sessionPath: string): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"switch_session\", sessionPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Fork from a specific message.\n\t * @returns Object with `text` (the message text) and `cancelled` (if extension cancelled)\n\t */\n\tasync fork(entryId: string): Promise<{ text: string; cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"fork\", entryId });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Clone the current active branch into a new session.\n\t * @returns Object with `cancelled: true` if an extension cancelled the clone\n\t */\n\tasync clone(): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"clone\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get messages available for forking.\n\t */\n\tasync getForkMessages(): Promise<Array<{ entryId: string; text: string }>> {\n\t\tconst response = await this.send({ type: \"get_fork_messages\" });\n\t\treturn this.getData<{ messages: Array<{ entryId: string; text: string }> }>(response).messages;\n\t}\n\n\t/**\n\t * Get text of last assistant message.\n\t */\n\tasync getLastAssistantText(): Promise<string | null> {\n\t\tconst response = await this.send({ type: \"get_last_assistant_text\" });\n\t\treturn this.getData<{ text: string | null }>(response).text;\n\t}\n\n\t/**\n\t * Set the session display name.\n\t */\n\tasync setSessionName(name: string): Promise<void> {\n\t\tawait this.send({ type: \"set_session_name\", name });\n\t}\n\n\t/**\n\t * Get all messages in the session.\n\t */\n\tasync getMessages(): Promise<AgentMessage[]> {\n\t\tconst response = await this.send({ type: \"get_messages\" });\n\t\treturn this.getData<{ messages: AgentMessage[] }>(response).messages;\n\t}\n\n\tasync sendAgentMessage(targetActiveSessionId: string, message: string): Promise<AgentSessionMessageReceipt> {\n\t\tconst response = await this.send({\n\t\t\ttype: \"send_message\",\n\t\t\ttargetActiveSessionId,\n\t\t\tmessage,\n\t\t});\n\t\treturn this.getData(response);\n\t}\n\n\tasync getAgentMessageStatus(): Promise<AgentSessionMessageSafetyStatus> {\n\t\treturn this.getData(await this.send({ type: \"agent_messages_status\" }));\n\t}\n\n\tasync pauseAgentMessages(): Promise<AgentSessionMessageSafetyStatus> {\n\t\treturn this.getData(await this.send({ type: \"agent_messages_pause\" }));\n\t}\n\n\tasync resumeAgentMessages(): Promise<AgentSessionMessageSafetyStatus> {\n\t\treturn this.getData(await this.send({ type: \"agent_messages_resume\" }));\n\t}\n\n\tasync clearAgentMessages(): Promise<number> {\n\t\tconst response = await this.send({ type: \"agent_messages_clear\" });\n\t\treturn this.getData<{ cleared: number }>(response).cleared;\n\t}\n\n\tasync listSchedules(includeInactive?: boolean): Promise<AgentCronJob[]> {\n\t\tconst response = await this.send({ type: \"list_schedules\", includeInactive });\n\t\treturn this.getData<{ jobs: AgentCronJob[] }>(response).jobs;\n\t}\n\n\tasync addSchedule(schedule: string, prompt: string): Promise<AgentCronJob> {\n\t\tconst response = await this.send({ type: \"add_schedule\", schedule, prompt });\n\t\treturn this.getData<{ job: AgentCronJob }>(response).job;\n\t}\n\n\tasync cancelSchedule(jobId: string): Promise<AgentCronJob> {\n\t\tconst response = await this.send({ type: \"cancel_schedule\", jobId });\n\t\treturn this.getData<{ job: AgentCronJob }>(response).job;\n\t}\n\n\tasync listHeartbeats(): Promise<AgentConnectionHeartbeat[]> {\n\t\tconst response = await this.send({ type: \"list_heartbeats\" });\n\t\treturn this.getData<{ heartbeats: AgentConnectionHeartbeat[] }>(response).heartbeats;\n\t}\n\n\tasync getHeartbeat(): Promise<AgentCronJob | null> {\n\t\tconst response = await this.send({ type: \"get_heartbeat\" });\n\t\treturn this.getData<{ heartbeat: AgentCronJob | null }>(response).heartbeat;\n\t}\n\n\tasync setHeartbeat(\n\t\tschedule: string,\n\t\tprompt: string,\n\t\tdeliveryMode?: AgentHeartbeatDeliveryMode,\n\t): Promise<AgentCronJob> {\n\t\tconst response = await this.send({ type: \"set_heartbeat\", schedule, prompt, deliveryMode });\n\t\tconst heartbeat = this.getData<{ heartbeat: AgentCronJob | null }>(response).heartbeat;\n\t\tif (!heartbeat) {\n\t\t\tthrow new Error(\"Daemon did not return the created heartbeat\");\n\t\t}\n\t\treturn heartbeat;\n\t}\n\n\tasync updateHeartbeat(action: AgentHeartbeatUpdateAction): Promise<AgentCronJob | null> {\n\t\tconst response = await this.send({ type: \"update_heartbeat\", action });\n\t\treturn this.getData<{ heartbeat: AgentCronJob | null }>(response).heartbeat;\n\t}\n\n\tasync manageHeartbeat(\n\t\tactiveSessionId: string,\n\t\tjobId: string,\n\t\taction: AgentHeartbeatManagementAction,\n\t): Promise<AgentCronJob> {\n\t\tconst response = await this.send({ type: \"manage_heartbeat\", activeSessionId, jobId, action });\n\t\tconst heartbeat = this.getData<{ heartbeat: AgentCronJob | null }>(response).heartbeat;\n\t\tif (!heartbeat) {\n\t\t\tthrow new Error(\"Daemon did not return the managed heartbeat\");\n\t\t}\n\t\treturn heartbeat;\n\t}\n\n\tasync observe(activeSessionId: string): Promise<AgentMessage[]> {\n\t\tconst response = await this.send({ type: \"observe\", activeSessionId });\n\t\treturn this.getData<{ messages: AgentMessage[] }>(response).messages;\n\t}\n\n\tasync unobserve(activeSessionId: string): Promise<void> {\n\t\tawait this.send({ type: \"unobserve\", activeSessionId });\n\t}\n\n\t/**\n\t * Get available commands (extension commands, prompt templates, skills).\n\t */\n\tasync getCommands(): Promise<RpcSlashCommand[]> {\n\t\tconst response = await this.send({ type: \"get_commands\" });\n\t\treturn this.getData<{ commands: RpcSlashCommand[] }>(response).commands;\n\t}\n\n\t// =========================================================================\n\t// Helpers\n\t// =========================================================================\n\n\t/**\n\t * Wait for agent to become idle (no streaming).\n\t * Resolves when agent_end event is received.\n\t */\n\twaitForIdle(timeout = 60000): Promise<void> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tunsubscribe();\n\t\t\t\treject(new Error(`Timeout waiting for agent to become idle. Stderr: ${this.stderr}`));\n\t\t\t}, timeout);\n\n\t\t\tconst unsubscribe = this.onEvent((event) => {\n\t\t\t\tconst error = promptCompletionError(event);\n\t\t\t\tif (error !== undefined) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\treject(new Error(error));\n\t\t\t\t} else if (event.type === \"agent_end\") {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Collect events until agent becomes idle.\n\t */\n\tcollectEvents(timeout = 60000): Promise<AgentEvent[]> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst events: AgentEvent[] = [];\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tunsubscribe();\n\t\t\t\treject(new Error(`Timeout collecting events. Stderr: ${this.stderr}`));\n\t\t\t}, timeout);\n\n\t\t\tconst unsubscribe = this.onEvent((event) => {\n\t\t\t\tevents.push(event);\n\t\t\t\tconst error = promptCompletionError(event);\n\t\t\t\tif (error !== undefined) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\treject(new Error(error));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (event.type === \"agent_end\") {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tresolve(events);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Send prompt and wait for completion, returning all events.\n\t */\n\tasync promptAndWait(message: string, images?: ImageContent[], timeout = 60000): Promise<AgentEvent[]> {\n\t\tconst eventsPromise = this.collectEvents(timeout);\n\t\tawait this.prompt(message, images);\n\t\tconst events = await eventsPromise;\n\t\tconst terminal = events.find((event) => event.type === \"agent_end\");\n\t\tif (terminal?.type === \"agent_end\" && terminal.refusal) throw new AgentOutputLimitError(terminal.refusal);\n\t\treturn events;\n\t}\n\n\t// =========================================================================\n\t// Internal\n\t// =========================================================================\n\n\tprivate handleLine(line: string): void {\n\t\ttry {\n\t\t\tconst data = JSON.parse(line);\n\n\t\t\t// Check if it's a response to a pending request\n\t\t\tif (data.type === \"response\" && data.id && this.pendingRequests.has(data.id)) {\n\t\t\t\tconst pending = this.pendingRequests.get(data.id)!;\n\t\t\t\tthis.pendingRequests.delete(data.id);\n\t\t\t\tpending.resolve(data as RpcResponse);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (data.type === \"observed_session_event\" || data.type === \"observed_session_closed\") {\n\t\t\t\tfor (const listener of [...this.observedSessionListeners]) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlistener(data as RpcObservedSessionEvent);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Listener failures must not block other RPC subscribers.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Otherwise it's an event\n\t\t\tfor (const listener of [...this.eventListeners]) {\n\t\t\t\ttry {\n\t\t\t\t\tlistener(data as AgentEvent);\n\t\t\t\t} catch {\n\t\t\t\t\t// Listener failures must not block other RPC subscribers.\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore non-JSON lines\n\t\t}\n\t}\n\n\tprivate async send(command: RpcCommandBody, timeoutMs = 30000): Promise<RpcResponse> {\n\t\tif (!this.process?.stdin) {\n\t\t\tthrow new Error(\"Client not started\");\n\t\t}\n\n\t\tconst id = `req_${++this.requestId}`;\n\t\tconst fullCommand = { ...command, id } as RpcCommand;\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.pendingRequests.set(id, { resolve, reject });\n\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\treject(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));\n\t\t\t}, timeoutMs);\n\n\t\t\tthis.pendingRequests.set(id, {\n\t\t\t\tresolve: (response) => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\tresolve(response);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tthis.process!.stdin!.write(serializeJsonLine(fullCommand));\n\t\t});\n\t}\n\n\tprivate getData<T>(response: RpcResponse): T {\n\t\tif (!response.success) {\n\t\t\tconst errorResponse = response as Extract<RpcResponse, { success: false }>;\n\t\t\tthrow new Error(errorResponse.error);\n\t\t}\n\t\t// Type assertion: we trust response.data matches T based on the command sent.\n\t\t// This is safe because each public method specifies the correct T for its command.\n\t\tconst successResponse = response as Extract<RpcResponse, { success: true; data: unknown }>;\n\t\treturn successResponse.data as T;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACN,KAAK,UAAU,EACf,KAAK,YAAY,EAEjB,KAAK,aAAa,EAClB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,0BAA0B,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAChH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE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CAAC,CAEpD;IAED,OAAO,CAAC,qBAAqB;IA+B7B;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,EAAE,OAAO,SAAQ,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAWpG;IAMD,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,UAAU;YAmCJ,IAAI;IAiClB,OAAO,CAAC,OAAO;CAUf","sourcesContent":["/**\n * RPC Client for programmatic access to the coding agent.\n *\n * Spawns the agent in RPC mode and provides a typed API for all operations.\n */\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport {\n\ttype AgentEvent,\n\ttype AgentMessage,\n\tAgentOutputLimitError,\n\ttype ThinkingLevel,\n} from \"@ponythewhite/base-context-agent\";\nimport type { ImageContent } from \"@ponythewhite/base-context-ai\";\nimport type { AgentSessionMessageReceipt, AgentSessionMessageSafetyStatus } from \"../../core/agent-messages.js\";\nimport type { BashResult } from \"../../core/bash-executor.js\";\nimport type { CompactionResult } from \"../../core/compaction/index.js\";\nimport type {\n\tAgentCronJob,\n\tAgentHeartbeatDeliveryMode,\n\tAgentHeartbeatManagementAction,\n\tAgentHeartbeatUpdateAction,\n} from \"../../core/cron-jobs.js\";\nimport type { RefinementResult } from \"../../core/refinement/index.js\";\nimport type { SessionStats } from \"../../core/session-stats.js\";\nimport type { AgentConnectionHeartbeat } from \"../agent-connection/types.js\";\nimport { CANONICAL_SESSION_OWNERSHIP_COMPATIBILITY, DAEMON_PROTOCOL_VERSION } from \"../daemon/daemon-protocol.js\";\nimport { attachJsonlLineReader, serializeJsonLine } from \"./jsonl.js\";\nimport type {\n\tRpcCommand,\n\tRpcObservedSessionEvent,\n\tRpcPromptCompletionError,\n\tRpcResponse,\n\tRpcSessionState,\n\tRpcSlashCommand,\n} from \"./rpc-types.js\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\nfunction promptCompletionError(event: AgentEvent): string | undefined {\n\tconst output = event as AgentEvent | RpcPromptCompletionError;\n\tif (\n\t\toutput.type === \"extension_error\" &&\n\t\toutput.extensionPath === \"<session-input>\" &&\n\t\toutput.event === \"prompt_completion\"\n\t)\n\t\treturn output.error;\n\treturn undefined;\n}\n\n/** Extended response timeout for refine requests, which run an LLM pass. */\nexport const REFINE_REQUEST_TIMEOUT_MS = 10 * 60 * 1000;\n\n/** Distributive Omit that works with union types */\ntype DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;\n\n/** RpcCommand without the id field (for internal send) */\ntype RpcCommandBody = DistributiveOmit<RpcCommand, \"id\">;\n\nexport interface RpcClientOptions {\n\t/** Path to the CLI entry point (default: searches for dist/cli.js) */\n\tcliPath?: string;\n\t/** Working directory for the agent */\n\tcwd?: string;\n\t/** Environment variables */\n\tenv?: Record<string, string>;\n\t/** Provider to use */\n\tprovider?: string;\n\t/** Model ID to use */\n\tmodel?: string;\n\t/** Additional CLI arguments */\n\targs?: string[];\n}\n\nexport interface ModelInfo {\n\tprovider: string;\n\tid: string;\n\tcontextWindow: number;\n\treasoning: boolean;\n}\n\nexport type RpcEventListener = (event: AgentEvent) => void;\nexport type RpcObservedSessionListener = (event: RpcObservedSessionEvent) => void;\n\n// ============================================================================\n// RPC Client\n// ============================================================================\n\nexport class RpcClient {\n\tprivate process: ChildProcess | null = null;\n\tprivate stopReadingStdout: (() => void) | null = null;\n\tprivate eventListeners: RpcEventListener[] = [];\n\tprivate observedSessionListeners: RpcObservedSessionListener[] = [];\n\tprivate pendingRequests: Map<string, { resolve: (response: RpcResponse) => void; reject: (error: Error) => void }> =\n\t\tnew Map();\n\tprivate requestId = 0;\n\tprivate stderr = \"\";\n\n\tconstructor(private options: RpcClientOptions = {}) {}\n\n\t/**\n\t * Start the RPC agent process.\n\t */\n\tasync start(): Promise<void> {\n\t\tif (this.process) {\n\t\t\tthrow new Error(\"Client already started\");\n\t\t}\n\n\t\tconst cliPath = this.options.cliPath ?? \"dist/cli.js\";\n\t\tconst args = [\"--mode\", \"rpc\", \"--rpc-protocol-version\", String(DAEMON_PROTOCOL_VERSION)];\n\n\t\tif (this.options.provider) {\n\t\t\targs.push(\"--provider\", this.options.provider);\n\t\t}\n\t\tif (this.options.model) {\n\t\t\targs.push(\"--model\", this.options.model);\n\t\t}\n\t\tif (this.options.args) {\n\t\t\targs.push(...this.options.args);\n\t\t}\n\n\t\tconst child = spawn(\"node\", [cliPath, ...args], {\n\t\t\tcwd: this.options.cwd,\n\t\t\tenv: { ...process.env, ...this.options.env },\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t});\n\t\tthis.process = child;\n\t\tthis.stderr = \"\";\n\n\t\t// Collect stderr for debugging\n\t\tchild.stderr?.on(\"data\", (data) => {\n\t\t\tif (this.process !== child) return;\n\t\t\tthis.stderr += data.toString();\n\t\t\tprocess.stderr.write(data);\n\t\t});\n\t\tchild.once(\"error\", (error) => {\n\t\t\tif (this.process === child) this.rejectPendingRequests(error);\n\t\t});\n\t\t// Drain final stdout/stderr before rejecting requests that received no response.\n\t\tchild.once(\"close\", () => {\n\t\t\tif (this.process === child) this.rejectPendingRequests(this.processExitError(child));\n\t\t});\n\n\t\t// Set up strict JSONL reader for stdout.\n\t\tthis.stopReadingStdout = attachJsonlLineReader(child.stdout!, (line) => {\n\t\t\tif (this.process === child) this.handleLine(line);\n\t\t});\n\n\t\ttry {\n\t\t\tconst state = await this.getState();\n\t\t\tif (state.protocolVersion !== DAEMON_PROTOCOL_VERSION)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Incompatible RPC protocol: expected ${DAEMON_PROTOCOL_VERSION}, got ${state.protocolVersion ?? \"unversioned\"}`,\n\t\t\t\t);\n\t\t\tconst minimumSchema = CANONICAL_SESSION_OWNERSHIP_COMPATIBILITY.minSchemaRevision;\n\t\t\tif (!Number.isSafeInteger(state.schemaRevision) || (state.schemaRevision ?? 0) < minimumSchema)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Incompatible RPC schema: expected at least ${minimumSchema}, got ${state.schemaRevision ?? \"unversioned\"}`,\n\t\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (this.process === child) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.stop();\n\t\t\t\t} catch (cleanupError) {\n\t\t\t\t\tthrow new AggregateError([error, cleanupError], \"RPC startup and cleanup failed\", { cause: error });\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Stop the RPC agent process.\n\t */\n\tasync stop(): Promise<void> {\n\t\tconst child = this.process;\n\t\tif (!child) return;\n\n\t\tthis.stopReadingStdout?.();\n\t\tthis.stopReadingStdout = null;\n\n\t\tif (child.exitCode === null && child.signalCode === null) {\n\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\t\tchild.kill(\"SIGKILL\");\n\t\t\t\t\tresolve();\n\t\t\t\t}, 1000);\n\n\t\t\t\tchild.once(\"exit\", () => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\t\tchild.kill(\"SIGTERM\");\n\t\t\t});\n\t\t}\n\n\t\tif (this.process === child) {\n\t\t\tthis.process = null;\n\t\t\tthis.rejectPendingRequests(new Error(\"RPC client stopped\"));\n\t\t}\n\t}\n\n\t/**\n\t * Subscribe to agent events.\n\t */\n\tonEvent(listener: RpcEventListener): () => void {\n\t\tthis.eventListeners.push(listener);\n\t\treturn () => {\n\t\t\tconst index = this.eventListeners.indexOf(listener);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.eventListeners.splice(index, 1);\n\t\t\t}\n\t\t};\n\t}\n\n\tonObservedSessionEvent(listener: RpcObservedSessionListener): () => void {\n\t\tthis.observedSessionListeners.push(listener);\n\t\treturn () => {\n\t\t\tconst index = this.observedSessionListeners.indexOf(listener);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.observedSessionListeners.splice(index, 1);\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Get collected stderr output (useful for debugging).\n\t */\n\tgetStderr(): string {\n\t\treturn this.stderr;\n\t}\n\n\t// =========================================================================\n\t// Command Methods\n\t// =========================================================================\n\n\t/**\n\t * Send a prompt to the agent.\n\t * Resolves after admission succeeds; use onEvent() to receive streaming events.\n\t * Use waitForIdle() to wait for completion.\n\t */\n\tasync prompt(message: string, images?: ImageContent[]): Promise<void> {\n\t\tthis.getData(await this.send({ type: \"prompt\", message, images }));\n\t}\n\n\t/**\n\t * Queue a steering message to interrupt the agent mid-run.\n\t */\n\tasync steer(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"steer\", message, images });\n\t}\n\n\t/**\n\t * Queue a follow-up message to be processed after the agent finishes.\n\t */\n\tasync followUp(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"follow_up\", message, images });\n\t}\n\n\t/**\n\t * Abort current operation.\n\t */\n\tasync abort(): Promise<void> {\n\t\tawait this.send({ type: \"abort\" });\n\t}\n\n\t/**\n\t * Start a new session, optionally with parent tracking.\n\t * @param parentSession - Optional parent session path for lineage tracking\n\t * @returns Object with `cancelled: true` if an extension cancelled the new session\n\t */\n\tasync newSession(parentSession?: string): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"new_session\", parentSession });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get current session state.\n\t */\n\tasync getState(): Promise<RpcSessionState> {\n\t\tconst response = await this.send({ type: \"get_state\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set model by provider and ID.\n\t */\n\tasync setModel(provider: string, modelId: string): Promise<{ provider: string; id: string }> {\n\t\tconst response = await this.send({ type: \"set_model\", provider, modelId });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Cycle to next model.\n\t */\n\tasync cycleModel(): Promise<{\n\t\tmodel: { provider: string; id: string };\n\t\tthinkingLevel: ThinkingLevel;\n\t\tisScoped: boolean;\n\t} | null> {\n\t\tconst response = await this.send({ type: \"cycle_model\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get list of available models.\n\t */\n\tasync getAvailableModels(): Promise<ModelInfo[]> {\n\t\tconst response = await this.send({ type: \"get_available_models\" });\n\t\treturn this.getData<{ models: ModelInfo[] }>(response).models;\n\t}\n\n\t/**\n\t * Set thinking level.\n\t */\n\tasync setThinkingLevel(level: ThinkingLevel): Promise<void> {\n\t\tawait this.send({ type: \"set_thinking_level\", level });\n\t}\n\n\t/**\n\t * Cycle thinking level.\n\t */\n\tasync cycleThinkingLevel(): Promise<{ level: ThinkingLevel } | null> {\n\t\tconst response = await this.send({ type: \"cycle_thinking_level\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set steering mode.\n\t */\n\tasync setSteeringMode(mode: \"all\" | \"one-at-a-time\"): Promise<void> {\n\t\tawait this.send({ type: \"set_steering_mode\", mode });\n\t}\n\n\t/**\n\t * Set follow-up mode.\n\t */\n\tasync setFollowUpMode(mode: \"all\" | \"one-at-a-time\"): Promise<void> {\n\t\tawait this.send({ type: \"set_follow_up_mode\", mode });\n\t}\n\n\t/**\n\t * Compact session context.\n\t */\n\tasync compact(customInstructions?: string): Promise<CompactionResult> {\n\t\tconst response = await this.send({ type: \"compact\", customInstructions });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Refine editable continual harness state.\n\t */\n\tasync refine(\n\t\toptions: { instructions?: string; rollbackId?: string; global?: boolean } = {},\n\t): Promise<RefinementResult> {\n\t\t// Refinement runs an LLM pass that routinely exceeds the default 30s response\n\t\t// timeout, so use the same extended window as the daemon refine path.\n\t\tconst command = { type: \"refine\", instructions: options.instructions, rollbackId: options.rollbackId } as {\n\t\t\ttype: \"refine\";\n\t\t\tinstructions?: string;\n\t\t\trollbackId?: string;\n\t\t\tglobal?: boolean;\n\t\t};\n\t\tif (options.global !== undefined) {\n\t\t\tcommand.global = options.global;\n\t\t}\n\t\tconst response = await this.send(command, REFINE_REQUEST_TIMEOUT_MS);\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set auto-compaction enabled/disabled.\n\t */\n\tasync setAutoCompaction(enabled: boolean): Promise<void> {\n\t\tawait this.send({ type: \"set_auto_compaction\", enabled });\n\t}\n\n\t/**\n\t * Set auto-retry enabled/disabled.\n\t */\n\tasync setAutoRetry(enabled: boolean): Promise<void> {\n\t\tawait this.send({ type: \"set_auto_retry\", enabled });\n\t}\n\n\t/**\n\t * Abort in-progress retry.\n\t */\n\tasync abortRetry(): Promise<void> {\n\t\tawait this.send({ type: \"abort_retry\" });\n\t}\n\n\t/**\n\t * Execute a bash command.\n\t */\n\tasync bash(command: string): Promise<BashResult> {\n\t\tconst response = await this.send({ type: \"bash\", command });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Abort running bash command.\n\t */\n\tasync abortBash(): Promise<void> {\n\t\tawait this.send({ type: \"abort_bash\" });\n\t}\n\n\t/**\n\t * Get session statistics.\n\t */\n\tasync getSessionStats(): Promise<SessionStats> {\n\t\tconst response = await this.send({ type: \"get_session_stats\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Export session to HTML.\n\t */\n\tasync exportHtml(outputPath?: string): Promise<{ path: string }> {\n\t\tconst response = await this.send({ type: \"export_html\", outputPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Switch to a different session file.\n\t * @returns Object with `cancelled: true` if an extension cancelled the switch\n\t */\n\tasync switchSession(sessionPath: string): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"switch_session\", sessionPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Fork from a specific message.\n\t * @returns Object with `text` (the message text) and `cancelled` (if extension cancelled)\n\t */\n\tasync fork(entryId: string): Promise<{ text: string; cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"fork\", entryId });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Clone the current active branch into a new session.\n\t * @returns Object with `cancelled: true` if an extension cancelled the clone\n\t */\n\tasync clone(): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"clone\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get messages available for forking.\n\t */\n\tasync getForkMessages(): Promise<Array<{ entryId: string; text: string }>> {\n\t\tconst response = await this.send({ type: \"get_fork_messages\" });\n\t\treturn this.getData<{ messages: Array<{ entryId: string; text: string }> }>(response).messages;\n\t}\n\n\t/**\n\t * Get text of last assistant message.\n\t */\n\tasync getLastAssistantText(): Promise<string | null> {\n\t\tconst response = await this.send({ type: \"get_last_assistant_text\" });\n\t\treturn this.getData<{ text: string | null }>(response).text;\n\t}\n\n\t/**\n\t * Set the session display name.\n\t */\n\tasync setSessionName(name: string): Promise<void> {\n\t\tawait this.send({ type: \"set_session_name\", name });\n\t}\n\n\t/**\n\t * Get all messages in the session.\n\t */\n\tasync getMessages(): Promise<AgentMessage[]> {\n\t\tconst response = await this.send({ type: \"get_messages\" });\n\t\treturn this.getData<{ messages: AgentMessage[] }>(response).messages;\n\t}\n\n\tasync sendAgentMessage(targetActiveSessionId: string, message: string): Promise<AgentSessionMessageReceipt> {\n\t\tconst response = await this.send({\n\t\t\ttype: \"send_message\",\n\t\t\ttargetActiveSessionId,\n\t\t\tmessage,\n\t\t});\n\t\treturn this.getData(response);\n\t}\n\n\tasync getAgentMessageStatus(): Promise<AgentSessionMessageSafetyStatus> {\n\t\treturn this.getData(await this.send({ type: \"agent_messages_status\" }));\n\t}\n\n\tasync pauseAgentMessages(): Promise<AgentSessionMessageSafetyStatus> {\n\t\treturn this.getData(await this.send({ type: \"agent_messages_pause\" }));\n\t}\n\n\tasync resumeAgentMessages(): Promise<AgentSessionMessageSafetyStatus> {\n\t\treturn this.getData(await this.send({ type: \"agent_messages_resume\" }));\n\t}\n\n\tasync clearAgentMessages(): Promise<number> {\n\t\tconst response = await this.send({ type: \"agent_messages_clear\" });\n\t\treturn this.getData<{ cleared: number }>(response).cleared;\n\t}\n\n\tasync listSchedules(includeInactive?: boolean): Promise<AgentCronJob[]> {\n\t\tconst response = await this.send({ type: \"list_schedules\", includeInactive });\n\t\treturn this.getData<{ jobs: AgentCronJob[] }>(response).jobs;\n\t}\n\n\tasync addSchedule(schedule: string, prompt: string): Promise<AgentCronJob> {\n\t\tconst response = await this.send({ type: \"add_schedule\", schedule, prompt });\n\t\treturn this.getData<{ job: AgentCronJob }>(response).job;\n\t}\n\n\tasync cancelSchedule(jobId: string): Promise<AgentCronJob> {\n\t\tconst response = await this.send({ type: \"cancel_schedule\", jobId });\n\t\treturn this.getData<{ job: AgentCronJob }>(response).job;\n\t}\n\n\tasync listHeartbeats(): Promise<AgentConnectionHeartbeat[]> {\n\t\tconst response = await this.send({ type: \"list_heartbeats\" });\n\t\treturn this.getData<{ heartbeats: AgentConnectionHeartbeat[] }>(response).heartbeats;\n\t}\n\n\tasync getHeartbeat(): Promise<AgentCronJob | null> {\n\t\tconst response = await this.send({ type: \"get_heartbeat\" });\n\t\treturn this.getData<{ heartbeat: AgentCronJob | null }>(response).heartbeat;\n\t}\n\n\tasync setHeartbeat(\n\t\tschedule: string,\n\t\tprompt: string,\n\t\tdeliveryMode?: AgentHeartbeatDeliveryMode,\n\t): Promise<AgentCronJob> {\n\t\tconst response = await this.send({ type: \"set_heartbeat\", schedule, prompt, deliveryMode });\n\t\tconst heartbeat = this.getData<{ heartbeat: AgentCronJob | null }>(response).heartbeat;\n\t\tif (!heartbeat) {\n\t\t\tthrow new Error(\"Daemon did not return the created heartbeat\");\n\t\t}\n\t\treturn heartbeat;\n\t}\n\n\tasync updateHeartbeat(action: AgentHeartbeatUpdateAction): Promise<AgentCronJob | null> {\n\t\tconst response = await this.send({ type: \"update_heartbeat\", action });\n\t\treturn this.getData<{ heartbeat: AgentCronJob | null }>(response).heartbeat;\n\t}\n\n\tasync manageHeartbeat(\n\t\tactiveSessionId: string,\n\t\tjobId: string,\n\t\taction: AgentHeartbeatManagementAction,\n\t): Promise<AgentCronJob> {\n\t\tconst response = await this.send({ type: \"manage_heartbeat\", activeSessionId, jobId, action });\n\t\tconst heartbeat = this.getData<{ heartbeat: AgentCronJob | null }>(response).heartbeat;\n\t\tif (!heartbeat) {\n\t\t\tthrow new Error(\"Daemon did not return the managed heartbeat\");\n\t\t}\n\t\treturn heartbeat;\n\t}\n\n\tasync observe(activeSessionId: string): Promise<AgentMessage[]> {\n\t\tconst response = await this.send({ type: \"observe\", activeSessionId });\n\t\treturn this.getData<{ messages: AgentMessage[] }>(response).messages;\n\t}\n\n\tasync unobserve(activeSessionId: string): Promise<void> {\n\t\tawait this.send({ type: \"unobserve\", activeSessionId });\n\t}\n\n\t/**\n\t * Get available commands (extension commands, prompt templates, skills).\n\t */\n\tasync getCommands(): Promise<RpcSlashCommand[]> {\n\t\tconst response = await this.send({ type: \"get_commands\" });\n\t\treturn this.getData<{ commands: RpcSlashCommand[] }>(response).commands;\n\t}\n\n\t// =========================================================================\n\t// Helpers\n\t// =========================================================================\n\n\t/**\n\t * Wait for agent to become idle (no streaming).\n\t * Resolves when agent_end event is received.\n\t */\n\twaitForIdle(timeout = 60000): Promise<void> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tunsubscribe();\n\t\t\t\treject(new Error(`Timeout waiting for agent to become idle. Stderr: ${this.stderr}`));\n\t\t\t}, timeout);\n\n\t\t\tconst unsubscribe = this.onEvent((event) => {\n\t\t\t\tconst error = promptCompletionError(event);\n\t\t\t\tif (error !== undefined) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\treject(new Error(error));\n\t\t\t\t} else if (event.type === \"agent_end\") {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Collect events until agent becomes idle.\n\t */\n\tcollectEvents(timeout = 60000): Promise<AgentEvent[]> {\n\t\treturn this.createEventCollection(timeout).result;\n\t}\n\n\tprivate createEventCollection(timeout: number): { result: Promise<AgentEvent[]>; cancel: () => void } {\n\t\tlet cancel = () => {};\n\t\tconst result = new Promise<AgentEvent[]>((resolve, reject) => {\n\t\t\tconst events: AgentEvent[] = [];\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tcancel();\n\t\t\t\treject(new Error(`Timeout collecting events. Stderr: ${this.stderr}`));\n\t\t\t}, timeout);\n\n\t\t\tconst unsubscribe = this.onEvent((event) => {\n\t\t\t\tevents.push(event);\n\t\t\t\tconst error = promptCompletionError(event);\n\t\t\t\tif (error !== undefined) {\n\t\t\t\t\tcancel();\n\t\t\t\t\treject(new Error(error));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (event.type === \"agent_end\") {\n\t\t\t\t\tcancel();\n\t\t\t\t\tresolve(events);\n\t\t\t\t}\n\t\t\t});\n\t\t\tcancel = () => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tunsubscribe();\n\t\t\t\tcancel = () => {};\n\t\t\t};\n\t\t});\n\t\treturn { result, cancel: () => cancel() };\n\t}\n\n\t/**\n\t * Send prompt and wait for completion, returning all events.\n\t */\n\tasync promptAndWait(message: string, images?: ImageContent[], timeout = 60000): Promise<AgentEvent[]> {\n\t\tconst collection = this.createEventCollection(timeout);\n\t\tlet events: AgentEvent[];\n\t\ttry {\n\t\t\t[, events] = await Promise.all([this.prompt(message, images), collection.result]);\n\t\t} finally {\n\t\t\tcollection.cancel();\n\t\t}\n\t\tconst terminal = events.find((event) => event.type === \"agent_end\");\n\t\tif (terminal?.type === \"agent_end\" && terminal.refusal) throw new AgentOutputLimitError(terminal.refusal);\n\t\treturn events;\n\t}\n\n\t// =========================================================================\n\t// Internal\n\t// =========================================================================\n\n\tprivate processExitError(child: ChildProcess): Error {\n\t\tconst reason = child.signalCode ? `signal ${child.signalCode}` : `code ${child.exitCode}`;\n\t\treturn new Error(`Agent process exited with ${reason}. Stderr: ${this.stderr}`);\n\t}\n\n\tprivate rejectPendingRequests(error: Error): void {\n\t\tfor (const pending of this.pendingRequests.values()) pending.reject(error);\n\t\tthis.pendingRequests.clear();\n\t}\n\n\tprivate handleLine(line: string): void {\n\t\ttry {\n\t\t\tconst data = JSON.parse(line);\n\n\t\t\t// Check if it's a response to a pending request\n\t\t\tif (data.type === \"response\" && data.id && this.pendingRequests.has(data.id)) {\n\t\t\t\tconst pending = this.pendingRequests.get(data.id)!;\n\t\t\t\tthis.pendingRequests.delete(data.id);\n\t\t\t\tpending.resolve(data as RpcResponse);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (data.type === \"observed_session_event\" || data.type === \"observed_session_closed\") {\n\t\t\t\tfor (const listener of [...this.observedSessionListeners]) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlistener(data as RpcObservedSessionEvent);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Listener failures must not block other RPC subscribers.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Otherwise it's an event\n\t\t\tfor (const listener of [...this.eventListeners]) {\n\t\t\t\ttry {\n\t\t\t\t\tlistener(data as AgentEvent);\n\t\t\t\t} catch {\n\t\t\t\t\t// Listener failures must not block other RPC subscribers.\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore non-JSON lines\n\t\t}\n\t}\n\n\tprivate async send(command: RpcCommandBody, timeoutMs = 30000): Promise<RpcResponse> {\n\t\tconst child = this.process;\n\t\tif (!child?.stdin) {\n\t\t\tthrow new Error(\"Client not started\");\n\t\t}\n\t\tif (child.exitCode !== null || child.signalCode !== null) {\n\t\t\tthrow this.processExitError(child);\n\t\t}\n\n\t\tconst id = `req_${++this.requestId}`;\n\t\tconst fullCommand = { ...command, id } as RpcCommand;\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\treject(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));\n\t\t\t}, timeoutMs);\n\n\t\t\tthis.pendingRequests.set(id, {\n\t\t\t\tresolve: (response) => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\tresolve(response);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tchild.stdin!.write(serializeJsonLine(fullCommand));\n\t\t});\n\t}\n\n\tprivate getData<T>(response: RpcResponse): T {\n\t\tif (!response.success) {\n\t\t\tconst errorResponse = response as Extract<RpcResponse, { success: false }>;\n\t\t\tthrow new Error(errorResponse.error);\n\t\t}\n\t\t// Type assertion: we trust response.data matches T based on the command sent.\n\t\t// This is safe because each public method specifies the correct T for its command.\n\t\tconst successResponse = response as Extract<RpcResponse, { success: true; data: unknown }>;\n\t\treturn successResponse.data as T;\n\t}\n}\n"]}
|
|
@@ -53,25 +53,34 @@ export class RpcClient {
|
|
|
53
53
|
if (this.options.args) {
|
|
54
54
|
args.push(...this.options.args);
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
const child = spawn("node", [cliPath, ...args], {
|
|
57
57
|
cwd: this.options.cwd,
|
|
58
58
|
env: { ...process.env, ...this.options.env },
|
|
59
59
|
stdio: ["pipe", "pipe", "pipe"],
|
|
60
60
|
});
|
|
61
|
+
this.process = child;
|
|
62
|
+
this.stderr = "";
|
|
61
63
|
// Collect stderr for debugging
|
|
62
|
-
|
|
64
|
+
child.stderr?.on("data", (data) => {
|
|
65
|
+
if (this.process !== child)
|
|
66
|
+
return;
|
|
63
67
|
this.stderr += data.toString();
|
|
64
68
|
process.stderr.write(data);
|
|
65
69
|
});
|
|
70
|
+
child.once("error", (error) => {
|
|
71
|
+
if (this.process === child)
|
|
72
|
+
this.rejectPendingRequests(error);
|
|
73
|
+
});
|
|
74
|
+
// Drain final stdout/stderr before rejecting requests that received no response.
|
|
75
|
+
child.once("close", () => {
|
|
76
|
+
if (this.process === child)
|
|
77
|
+
this.rejectPendingRequests(this.processExitError(child));
|
|
78
|
+
});
|
|
66
79
|
// Set up strict JSONL reader for stdout.
|
|
67
|
-
this.stopReadingStdout = attachJsonlLineReader(
|
|
68
|
-
this.
|
|
80
|
+
this.stopReadingStdout = attachJsonlLineReader(child.stdout, (line) => {
|
|
81
|
+
if (this.process === child)
|
|
82
|
+
this.handleLine(line);
|
|
69
83
|
});
|
|
70
|
-
// Wait a moment for process to initialize
|
|
71
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
72
|
-
if (this.process.exitCode !== null) {
|
|
73
|
-
throw new Error(`Agent process exited immediately with code ${this.process.exitCode}. Stderr: ${this.stderr}`);
|
|
74
|
-
}
|
|
75
84
|
try {
|
|
76
85
|
const state = await this.getState();
|
|
77
86
|
if (state.protocolVersion !== DAEMON_PROTOCOL_VERSION)
|
|
@@ -81,11 +90,13 @@ export class RpcClient {
|
|
|
81
90
|
throw new Error(`Incompatible RPC schema: expected at least ${minimumSchema}, got ${state.schemaRevision ?? "unversioned"}`);
|
|
82
91
|
}
|
|
83
92
|
catch (error) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
if (this.process === child) {
|
|
94
|
+
try {
|
|
95
|
+
await this.stop();
|
|
96
|
+
}
|
|
97
|
+
catch (cleanupError) {
|
|
98
|
+
throw new AggregateError([error, cleanupError], "RPC startup and cleanup failed", { cause: error });
|
|
99
|
+
}
|
|
89
100
|
}
|
|
90
101
|
throw error;
|
|
91
102
|
}
|
|
@@ -94,24 +105,28 @@ export class RpcClient {
|
|
|
94
105
|
* Stop the RPC agent process.
|
|
95
106
|
*/
|
|
96
107
|
async stop() {
|
|
97
|
-
|
|
108
|
+
const child = this.process;
|
|
109
|
+
if (!child)
|
|
98
110
|
return;
|
|
99
111
|
this.stopReadingStdout?.();
|
|
100
112
|
this.stopReadingStdout = null;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
114
|
+
await new Promise((resolve) => {
|
|
115
|
+
const timeout = setTimeout(() => {
|
|
116
|
+
child.kill("SIGKILL");
|
|
117
|
+
resolve();
|
|
118
|
+
}, 1000);
|
|
119
|
+
child.once("exit", () => {
|
|
120
|
+
clearTimeout(timeout);
|
|
121
|
+
resolve();
|
|
122
|
+
});
|
|
123
|
+
child.kill("SIGTERM");
|
|
111
124
|
});
|
|
112
|
-
}
|
|
113
|
-
this.process
|
|
114
|
-
|
|
125
|
+
}
|
|
126
|
+
if (this.process === child) {
|
|
127
|
+
this.process = null;
|
|
128
|
+
this.rejectPendingRequests(new Error("RPC client stopped"));
|
|
129
|
+
}
|
|
115
130
|
}
|
|
116
131
|
/**
|
|
117
132
|
* Subscribe to agent events.
|
|
@@ -145,11 +160,11 @@ export class RpcClient {
|
|
|
145
160
|
// =========================================================================
|
|
146
161
|
/**
|
|
147
162
|
* Send a prompt to the agent.
|
|
148
|
-
*
|
|
163
|
+
* Resolves after admission succeeds; use onEvent() to receive streaming events.
|
|
149
164
|
* Use waitForIdle() to wait for completion.
|
|
150
165
|
*/
|
|
151
166
|
async prompt(message, images) {
|
|
152
|
-
await this.send({ type: "prompt", message, images });
|
|
167
|
+
this.getData(await this.send({ type: "prompt", message, images }));
|
|
153
168
|
}
|
|
154
169
|
/**
|
|
155
170
|
* Queue a steering message to interrupt the agent mid-run.
|
|
@@ -454,36 +469,49 @@ export class RpcClient {
|
|
|
454
469
|
* Collect events until agent becomes idle.
|
|
455
470
|
*/
|
|
456
471
|
collectEvents(timeout = 60000) {
|
|
457
|
-
return
|
|
472
|
+
return this.createEventCollection(timeout).result;
|
|
473
|
+
}
|
|
474
|
+
createEventCollection(timeout) {
|
|
475
|
+
let cancel = () => { };
|
|
476
|
+
const result = new Promise((resolve, reject) => {
|
|
458
477
|
const events = [];
|
|
459
478
|
const timer = setTimeout(() => {
|
|
460
|
-
|
|
479
|
+
cancel();
|
|
461
480
|
reject(new Error(`Timeout collecting events. Stderr: ${this.stderr}`));
|
|
462
481
|
}, timeout);
|
|
463
482
|
const unsubscribe = this.onEvent((event) => {
|
|
464
483
|
events.push(event);
|
|
465
484
|
const error = promptCompletionError(event);
|
|
466
485
|
if (error !== undefined) {
|
|
467
|
-
|
|
468
|
-
unsubscribe();
|
|
486
|
+
cancel();
|
|
469
487
|
reject(new Error(error));
|
|
470
488
|
return;
|
|
471
489
|
}
|
|
472
490
|
if (event.type === "agent_end") {
|
|
473
|
-
|
|
474
|
-
unsubscribe();
|
|
491
|
+
cancel();
|
|
475
492
|
resolve(events);
|
|
476
493
|
}
|
|
477
494
|
});
|
|
495
|
+
cancel = () => {
|
|
496
|
+
clearTimeout(timer);
|
|
497
|
+
unsubscribe();
|
|
498
|
+
cancel = () => { };
|
|
499
|
+
};
|
|
478
500
|
});
|
|
501
|
+
return { result, cancel: () => cancel() };
|
|
479
502
|
}
|
|
480
503
|
/**
|
|
481
504
|
* Send prompt and wait for completion, returning all events.
|
|
482
505
|
*/
|
|
483
506
|
async promptAndWait(message, images, timeout = 60000) {
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
|
|
507
|
+
const collection = this.createEventCollection(timeout);
|
|
508
|
+
let events;
|
|
509
|
+
try {
|
|
510
|
+
[, events] = await Promise.all([this.prompt(message, images), collection.result]);
|
|
511
|
+
}
|
|
512
|
+
finally {
|
|
513
|
+
collection.cancel();
|
|
514
|
+
}
|
|
487
515
|
const terminal = events.find((event) => event.type === "agent_end");
|
|
488
516
|
if (terminal?.type === "agent_end" && terminal.refusal)
|
|
489
517
|
throw new AgentOutputLimitError(terminal.refusal);
|
|
@@ -492,6 +520,15 @@ export class RpcClient {
|
|
|
492
520
|
// =========================================================================
|
|
493
521
|
// Internal
|
|
494
522
|
// =========================================================================
|
|
523
|
+
processExitError(child) {
|
|
524
|
+
const reason = child.signalCode ? `signal ${child.signalCode}` : `code ${child.exitCode}`;
|
|
525
|
+
return new Error(`Agent process exited with ${reason}. Stderr: ${this.stderr}`);
|
|
526
|
+
}
|
|
527
|
+
rejectPendingRequests(error) {
|
|
528
|
+
for (const pending of this.pendingRequests.values())
|
|
529
|
+
pending.reject(error);
|
|
530
|
+
this.pendingRequests.clear();
|
|
531
|
+
}
|
|
495
532
|
handleLine(line) {
|
|
496
533
|
try {
|
|
497
534
|
const data = JSON.parse(line);
|
|
@@ -528,13 +565,16 @@ export class RpcClient {
|
|
|
528
565
|
}
|
|
529
566
|
}
|
|
530
567
|
async send(command, timeoutMs = 30000) {
|
|
531
|
-
|
|
568
|
+
const child = this.process;
|
|
569
|
+
if (!child?.stdin) {
|
|
532
570
|
throw new Error("Client not started");
|
|
533
571
|
}
|
|
572
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
573
|
+
throw this.processExitError(child);
|
|
574
|
+
}
|
|
534
575
|
const id = `req_${++this.requestId}`;
|
|
535
576
|
const fullCommand = { ...command, id };
|
|
536
577
|
return new Promise((resolve, reject) => {
|
|
537
|
-
this.pendingRequests.set(id, { resolve, reject });
|
|
538
578
|
const timeout = setTimeout(() => {
|
|
539
579
|
this.pendingRequests.delete(id);
|
|
540
580
|
reject(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));
|
|
@@ -549,7 +589,7 @@ export class RpcClient {
|
|
|
549
589
|
reject(error);
|
|
550
590
|
},
|
|
551
591
|
});
|
|
552
|
-
|
|
592
|
+
child.stdin.write(serializeJsonLine(fullCommand));
|
|
553
593
|
});
|
|
554
594
|
}
|
|
555
595
|
getData(response) {
|