@agenthippo-ai/agenthippo 0.2.3-dataplane → 1.110.11
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/out/agentpack/index.js +3 -1
- package/out/agentpack/paths.js +25 -2
- package/out/analytics/dashboard/localFleetAdapter.js +82 -2
- package/out/analytics/dashboard/provider.js +13 -2
- package/out/analytics/dashboard/webview/panel.js +3 -2
- package/out/analytics/identity.js +0 -0
- package/out/analytics/service.js +29 -25
- package/out/analytics/sessionEvents.js +100 -24
- package/out/auth/authBaseUrl.js +59 -0
- package/out/auth/bootstrapApply.js +9 -10
- package/out/auth/brokerClient.js +48 -14
- package/out/auth/provider.js +8 -21
- package/out/auth/sessionStore.js +3 -40
- package/out/auth/signInFlow.js +2 -1
- package/out/auth-broker/config.js +50 -5
- package/out/auth-broker/server.js +126 -26
- package/out/auth-broker/store.js +25 -24
- package/out/authority/warrant.js +206 -0
- package/out/branding.js +27 -1
- package/out/cli/commands/conformance.js +249 -0
- package/out/cli/commands/data-plane.js +151 -0
- package/out/cli/commands/deploy.js +1 -0
- package/out/cli/commands/gateway.js +4 -0
- package/out/cli/commands/pack.js +182 -3
- package/out/cli/commands/sandbox.js +351 -0
- package/out/cli/commands/serve.js +1145 -130
- package/out/cli/commands/store.js +12 -4
- package/out/cli/credential-context.js +17 -0
- package/out/cli/data-plane/gateway.js +28 -5
- package/out/cli/data-plane/index.js +18 -2
- package/out/cli/data-plane/registry.js +9 -0
- package/out/cli/data-plane/remote.js +106 -0
- package/out/cli/data-plane/sidecar.js +225 -0
- package/out/cli/deploy/layers/identity.js +88 -4
- package/out/cli/deploy-init.js +89 -24
- package/out/cli/deps.js +106 -2
- package/out/cli/idp-init.js +35 -0
- package/out/cli/index.js +171 -17
- package/out/cli/pack-install-ref.js +15 -0
- package/out/cli/pack-loader.js +8 -1
- package/out/cli/pack-runtime.js +61 -0
- package/out/cli/runtime.js +35 -1
- package/out/cli/serve-hardening.js +260 -14
- package/out/cli/utils.js +12 -1
- package/out/engines/base.js +32 -3
- package/out/engines/claude.js +33 -15
- package/out/engines/codex.js +111 -27
- package/out/engines/custom.js +15 -1
- package/out/evidence/sessionShip.js +643 -0
- package/out/extension.js +11 -2
- package/out/gateway/bridge.js +40 -2
- package/out/gateway/client.js +34 -1
- package/out/gateway/installSource.js +68 -0
- package/out/gateway/lifecycle.js +185 -51
- package/out/gateway/outboundPaths.js +4 -1
- package/out/gateway/secretsPreflight.js +90 -0
- package/out/gateway/service.js +7 -2
- package/out/headless/index.js +25 -2
- package/out/live-e2e/mcp-demo/server.mjs +32 -0
- package/out/mcp.js +30 -0
- package/out/pack/caps.js +271 -0
- package/out/pack/governor.js +326 -0
- package/out/pack/lease-schema.js +273 -0
- package/out/pack/lease.js +682 -0
- package/out/pack/reconcile.js +217 -0
- package/out/pack/signature.js +839 -0
- package/out/remote/handleRemoteChat.js +44 -3
- package/out/remote/remoteTrust.js +277 -0
- package/out/remote/serveClient.js +52 -5
- package/out/runner/host.js +141 -0
- package/out/runner/protocol.js +128 -0
- package/out/runner/remoteEngine.js +166 -0
- package/out/runtime/interfaces/edit-tracker.js +2 -0
- package/out/runtime/vscode/vscode-edit-tracker.js +2 -0
- package/out/sandbox/containerDriver.js +572 -0
- package/out/sandbox/processDriver.js +318 -0
- package/out/sandbox/sandboxRunner.js +303 -0
- package/out/sandbox/support.js +301 -0
- package/out/sandbox/types.js +55 -0
- package/out/scripts/agentide-litellm.sh +67 -5
- package/out/scripts/agentide_litellm_hooks_v1.py +266 -21
- package/out/scripts/analytics/agentide-litellm-otel.config.yaml +98 -132
- package/out/scripts/analytics/setup-analytics.ps1 +45 -14
- package/out/scripts/analytics/setup-analytics.sh +106 -15
- package/out/scripts/analytics/start-analytics.sh +86 -14
- package/out/scripts/gateway/setup-gateway.sh +72 -32
- package/out/shared/models.js +11 -110
- package/out/spotlight/install.js +7 -1
- package/out/store/index.js +41 -10
- package/out/sync.js +3 -1
- package/out/test/analytics.test.js +162 -23
- package/out/test/auth-baseurl.test.js +132 -0
- package/out/test/auth-bootstrapApply.test.js +27 -6
- package/out/test/auth-broker-hardening.test.js +227 -0
- package/out/test/auth-broker.test.js +59 -9
- package/out/test/branding.test.js +13 -0
- package/out/test/caps-governor.test.js +460 -0
- package/out/test/codex-new-file-survival.test.js +119 -0
- package/out/test/configuration-scopes.test.js +131 -0
- package/out/test/data-plane-engine-wiring.test.js +32 -0
- package/out/test/data-plane.test.js +380 -0
- package/out/test/deploy-init.test.js +47 -1
- package/out/test/gateway-client.test.js +28 -0
- package/out/test/gateway-install-source.test.js +111 -0
- package/out/test/gateway-lifecycle.test.js +1 -1
- package/out/test/gateway-outbound.test.js +7 -0
- package/out/test/gateway-secrets-preflight.test.js +127 -0
- package/out/test/gateway-session-routing.test.js +18 -0
- package/out/test/governor-hardening.test.js +222 -0
- package/out/test/headless-sync.test.js +22 -0
- package/out/test/lease-signature.test.js +357 -0
- package/out/test/lease-trust-root.test.js +273 -0
- package/out/test/lease-validation.test.js +224 -0
- package/out/test/lease.test.js +114 -0
- package/out/test/localFleetAdapter.test.js +91 -0
- package/out/test/mcp.test.js +27 -1
- package/out/test/pack-admission.test.js +216 -0
- package/out/test/pack-digest-parity.test.js +140 -0
- package/out/test/pack-reconcile.test.js +183 -0
- package/out/test/pack-signature-artifact.test.js +103 -0
- package/out/test/pack-signature.test.js +176 -0
- package/out/test/pack-trust-root.test.js +202 -0
- package/out/test/remote-trust.test.js +242 -0
- package/out/test/runner-protocol.test.js +249 -0
- package/out/test/sandbox-driver.test.js +553 -0
- package/out/test/sandbox-hardening.test.js +406 -0
- package/out/test/sandbox-runner.test.js +343 -0
- package/out/test/sandbox-scope.test.js +449 -0
- package/out/test/serve-cron-acceptance.test.js +370 -0
- package/out/test/serve-gateway-turn.test.js +122 -0
- package/out/test/serve-hardening.test.js +227 -15
- package/out/test/serveClient.test.js +6 -5
- package/out/test/sessionShip.test.js +618 -0
- package/out/test/spotlightPublish.test.js +28 -0
- package/out/test/store-install-safe.test.js +69 -0
- package/out/test/tls-bypass.test.js +90 -0
- package/out/test/warrant.test.js +138 -0
- package/out/utils.js +46 -9
- package/package.json +1 -1
|
@@ -9,6 +9,27 @@ const base_js_1 = require("../engines/base.js");
|
|
|
9
9
|
const utils_js_1 = require("../utils.js");
|
|
10
10
|
const sessionEvents_js_1 = require("../analytics/sessionEvents.js");
|
|
11
11
|
const serveClient_js_1 = require("./serveClient.js");
|
|
12
|
+
const remoteTrust_js_1 = require("./remoteTrust.js");
|
|
13
|
+
/**
|
|
14
|
+
* The gate used when the caller does not inject one.
|
|
15
|
+
*
|
|
16
|
+
* `vscode` is resolved lazily (and may legitimately be absent in headless/CLI hosts) so this module
|
|
17
|
+
* stays importable outside the extension host. With no prompt available an untrusted host is
|
|
18
|
+
* REFUSED rather than silently contacted — the refusal message names the host and the env var that
|
|
19
|
+
* whitelists it, so the failure is actionable rather than mysterious.
|
|
20
|
+
*/
|
|
21
|
+
function defaultRemoteTrustGate() {
|
|
22
|
+
try {
|
|
23
|
+
// eslint-disable-next-line no-eval
|
|
24
|
+
const api = eval('require')('vscode');
|
|
25
|
+
return (0, remoteTrust_js_1.createRemoteTrustGate)({
|
|
26
|
+
prompt: (0, remoteTrust_js_1.vscodeRemoteTrustPrompt)((message, options, ...items) => api.window.showWarningMessage(message, options, ...items)),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return (0, remoteTrust_js_1.createRemoteTrustGate)();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
12
33
|
function isLoopbackServeUrl(url) {
|
|
13
34
|
try {
|
|
14
35
|
const host = new URL(url).hostname;
|
|
@@ -78,16 +99,35 @@ async function handleRemoteServeChat(deps, args) {
|
|
|
78
99
|
},
|
|
79
100
|
} : questionEmitter;
|
|
80
101
|
const requestId = (0, base_js_1.generateRequestId)();
|
|
81
|
-
|
|
82
|
-
|
|
102
|
+
// Decide WHO this is before deciding whether to sign in. `remoteUrl` comes from a pack manifest,
|
|
103
|
+
// which is attacker-controllable; forcing a sign-in first (as this used to) meant an untrusted
|
|
104
|
+
// host got a freshly-minted access token handed to it on the very next line.
|
|
105
|
+
const trustGate = deps.remoteTrust ?? defaultRemoteTrustGate();
|
|
106
|
+
const trust = await trustGate.evaluate(remoteUrl);
|
|
107
|
+
if (!trust.allowed) {
|
|
108
|
+
const trustError = trust.verdict.reason
|
|
109
|
+
?? `Refusing to send this chat to ${trust.verdict.origin}.`;
|
|
110
|
+
deps.log(outputChannel, `[AgentIDE] Remote serve refused: ${trustError}`);
|
|
111
|
+
await emitter.error(trustError);
|
|
112
|
+
await emitter.done();
|
|
113
|
+
return { error: trustError };
|
|
114
|
+
}
|
|
115
|
+
let auth = trust.sendAuth && deps.getServeAuth ? await deps.getServeAuth() : undefined;
|
|
116
|
+
// `requireAuth`, not `sendAuth`: a loopback serve may carry a token we already hold but must
|
|
117
|
+
// never trigger an interactive sign-in — an unauthenticated local `agenthippo serve` is a
|
|
118
|
+
// supported setup and used to work without one.
|
|
119
|
+
if (trust.requireAuth && !auth?.accessToken && deps.ensureSignedIn) {
|
|
83
120
|
auth = await deps.ensureSignedIn();
|
|
84
121
|
}
|
|
85
|
-
if (
|
|
122
|
+
if (trust.requireAuth && !auth?.accessToken) {
|
|
86
123
|
const authError = 'Sign in to AgentHippo was cancelled or timed out. Use Command Palette → "Sign In to AgentHippo" to try again.';
|
|
87
124
|
await emitter.error(authError);
|
|
88
125
|
await emitter.done();
|
|
89
126
|
return { error: authError };
|
|
90
127
|
}
|
|
128
|
+
if (!trust.sendAuth) {
|
|
129
|
+
auth = undefined;
|
|
130
|
+
}
|
|
91
131
|
const remoteSessionId = incomingOptions.contextSessionId?.trim() ||
|
|
92
132
|
incomingOptions.sessionId?.trim() ||
|
|
93
133
|
`ide-remote-${streamId}`;
|
|
@@ -102,6 +142,7 @@ async function handleRemoteServeChat(deps, args) {
|
|
|
102
142
|
sessionId: remoteSessionId,
|
|
103
143
|
signal: abortController.signal,
|
|
104
144
|
auth,
|
|
145
|
+
authorizedForAuth: trust.sendAuth,
|
|
105
146
|
}, observableEmitter);
|
|
106
147
|
if (!result.ok) {
|
|
107
148
|
// streamRemoteServeChat already surfaced the failure to the emitter (error + done);
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) AgentHippo.ai. All rights reserved.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.RemoteTrustStore = exports.DEFAULT_TRUSTED_REMOTE_DOMAINS = void 0;
|
|
40
|
+
exports.isLoopbackHostname = isLoopbackHostname;
|
|
41
|
+
exports.classifyRemoteServeUrl = classifyRemoteServeUrl;
|
|
42
|
+
exports.mayReceiveAccessToken = mayReceiveAccessToken;
|
|
43
|
+
exports.defaultRemoteTrustStorePath = defaultRemoteTrustStorePath;
|
|
44
|
+
exports.trustedDomainsFromEnv = trustedDomainsFromEnv;
|
|
45
|
+
exports.createRemoteTrustGate = createRemoteTrustGate;
|
|
46
|
+
exports.untrustedRefusalMessage = untrustedRefusalMessage;
|
|
47
|
+
exports.vscodeRemoteTrustPrompt = vscodeRemoteTrustPrompt;
|
|
48
|
+
/**
|
|
49
|
+
* Who is allowed to receive the user's AgentHippo access token.
|
|
50
|
+
*
|
|
51
|
+
* `spec.remote.url` comes from a PACK MANIFEST — a file that arrives from the store, a PR, or a
|
|
52
|
+
* teammate's library. Before this module existed the remote chat path read that URL, FORCED a
|
|
53
|
+
* sign-in for any non-loopback host, and then sent `Authorization: Bearer <access token>` plus the
|
|
54
|
+
* user's full message to it. Publishing a pack whose manifest named an attacker host was therefore
|
|
55
|
+
* a one-step token exfiltration with no prompt and no scheme check.
|
|
56
|
+
*
|
|
57
|
+
* The model here is deliberately small:
|
|
58
|
+
*
|
|
59
|
+
* - **loopback** (`127.0.0.1` / `localhost` / `::1`): a serve the user started themselves. Allowed
|
|
60
|
+
* without a prompt, and may receive the token — a locally-run `agenthippo serve` validates it,
|
|
61
|
+
* and refusing here would break that with no way to opt back in. Residual risk, stated: another
|
|
62
|
+
* local account that can bind the port would receive the token. That is the same trust boundary
|
|
63
|
+
* the user already extends to anything running as them on that machine.
|
|
64
|
+
* - **trusted**: the product's own domains, plus hosts the user has explicitly approved. These may
|
|
65
|
+
* receive the bearer token.
|
|
66
|
+
* - **untrusted**: everything else. The turn either gets explicit consent (a modal naming the host
|
|
67
|
+
* and saying the access token will be sent) or it is refused. The token is NEVER attached to an
|
|
68
|
+
* unapproved host — not even "just this once".
|
|
69
|
+
* - **refused**: cleartext `http://` to a non-loopback host, or a non-http(s) scheme. There is no
|
|
70
|
+
* consent prompt for these; a bearer token does not go over cleartext.
|
|
71
|
+
*
|
|
72
|
+
* Approvals are persisted per HOST (scheme+hostname+port) in the user's home directory, never in
|
|
73
|
+
* workspace state — a repo must not be able to pre-approve itself by shipping a state file.
|
|
74
|
+
*/
|
|
75
|
+
const fs = __importStar(require("node:fs"));
|
|
76
|
+
const os = __importStar(require("node:os"));
|
|
77
|
+
const path = __importStar(require("node:path"));
|
|
78
|
+
/**
|
|
79
|
+
* Hosts trusted without a prompt. Exact host or any subdomain. Keep this list to domains the
|
|
80
|
+
* product actually operates: every entry here is a host that may receive a user's access token.
|
|
81
|
+
*/
|
|
82
|
+
exports.DEFAULT_TRUSTED_REMOTE_DOMAINS = ['agenthippo.ai'];
|
|
83
|
+
const LOOPBACK_HOSTNAMES = new Set(['127.0.0.1', 'localhost', '::1', '[::1]']);
|
|
84
|
+
function isLoopbackHostname(hostname) {
|
|
85
|
+
return LOOPBACK_HOSTNAMES.has(hostname.toLowerCase());
|
|
86
|
+
}
|
|
87
|
+
function matchesDomain(hostname, domain) {
|
|
88
|
+
const h = hostname.toLowerCase();
|
|
89
|
+
const d = domain.toLowerCase().replace(/^\./, '');
|
|
90
|
+
return h === d || h.endsWith(`.${d}`);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Classify a remote serve URL. Pure — the caller supplies the extra trust it knows about
|
|
94
|
+
* (built-in domains are always included; `approvedOrigins` comes from the persisted consent store).
|
|
95
|
+
*/
|
|
96
|
+
function classifyRemoteServeUrl(rawUrl, opts = {}) {
|
|
97
|
+
const trimmed = (rawUrl ?? '').trim();
|
|
98
|
+
let url;
|
|
99
|
+
try {
|
|
100
|
+
url = new URL(trimmed);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return {
|
|
104
|
+
level: 'refused',
|
|
105
|
+
origin: trimmed,
|
|
106
|
+
hostname: '',
|
|
107
|
+
reason: `remote agent URL "${trimmed}" is not a valid URL`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const hostname = url.hostname;
|
|
111
|
+
const origin = `${url.protocol}//${url.host}`;
|
|
112
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
|
|
113
|
+
return {
|
|
114
|
+
level: 'refused',
|
|
115
|
+
origin,
|
|
116
|
+
hostname,
|
|
117
|
+
reason: `remote agent URL "${trimmed}" uses an unsupported scheme (${url.protocol}) — only https:// is allowed (http:// for loopback)`,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (isLoopbackHostname(hostname)) {
|
|
121
|
+
// Loopback over http is the normal `agenthippo serve` development case and never leaves
|
|
122
|
+
// the machine. It is also the only case that gets no bearer token, so there is nothing
|
|
123
|
+
// on the wire worth protecting with TLS.
|
|
124
|
+
return { level: 'loopback', origin, hostname };
|
|
125
|
+
}
|
|
126
|
+
if (url.protocol === 'http:') {
|
|
127
|
+
return {
|
|
128
|
+
level: 'refused',
|
|
129
|
+
origin,
|
|
130
|
+
hostname,
|
|
131
|
+
reason: `remote agent URL "${trimmed}" is plain http:// to a non-loopback host. ` +
|
|
132
|
+
`This request would carry your AgentHippo access token and your full message, ` +
|
|
133
|
+
`so it is refused. Ask the pack author for an https:// endpoint.`,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const trusted = opts.trustedDomains ?? exports.DEFAULT_TRUSTED_REMOTE_DOMAINS;
|
|
137
|
+
if (trusted.some((domain) => matchesDomain(hostname, domain))) {
|
|
138
|
+
return { level: 'trusted', origin, hostname };
|
|
139
|
+
}
|
|
140
|
+
if ((opts.approvedOrigins ?? []).some((approved) => approved.toLowerCase() === origin.toLowerCase())) {
|
|
141
|
+
return { level: 'trusted', origin, hostname };
|
|
142
|
+
}
|
|
143
|
+
return { level: 'untrusted', origin, hostname };
|
|
144
|
+
}
|
|
145
|
+
/** A verdict that permits sending `Authorization: Bearer <access token>`. */
|
|
146
|
+
function mayReceiveAccessToken(verdict) {
|
|
147
|
+
return verdict.level === 'trusted' || verdict.level === 'loopback';
|
|
148
|
+
}
|
|
149
|
+
// -----------------------------------------------------------------------------
|
|
150
|
+
// Persisted per-host approvals
|
|
151
|
+
// -----------------------------------------------------------------------------
|
|
152
|
+
/**
|
|
153
|
+
* Where approvals live. The user's home directory, NOT workspace state and NOT the extension's
|
|
154
|
+
* workspace-scoped storage: a repository must not be able to ship a file that pre-approves its own
|
|
155
|
+
* exfiltration endpoint. 0600 so another local account cannot add an entry.
|
|
156
|
+
*/
|
|
157
|
+
function defaultRemoteTrustStorePath(homeDir = os.homedir()) {
|
|
158
|
+
return path.join(homeDir, '.agent-hippo', 'remote-trust.json');
|
|
159
|
+
}
|
|
160
|
+
class RemoteTrustStore {
|
|
161
|
+
storePath;
|
|
162
|
+
constructor(storePath = defaultRemoteTrustStorePath()) {
|
|
163
|
+
this.storePath = storePath;
|
|
164
|
+
}
|
|
165
|
+
readApprovedOrigins() {
|
|
166
|
+
try {
|
|
167
|
+
const raw = fs.readFileSync(this.storePath, 'utf8');
|
|
168
|
+
const parsed = JSON.parse(raw);
|
|
169
|
+
return Array.isArray(parsed.approvedOrigins)
|
|
170
|
+
? parsed.approvedOrigins.filter((o) => typeof o === 'string')
|
|
171
|
+
: [];
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
// Missing / unreadable / malformed ⇒ nothing is approved. Fail closed.
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
approveOrigin(origin) {
|
|
179
|
+
const existing = new Set(this.readApprovedOrigins().map((o) => o.toLowerCase()));
|
|
180
|
+
if (existing.has(origin.toLowerCase())) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const next = [...this.readApprovedOrigins(), origin];
|
|
184
|
+
fs.mkdirSync(path.dirname(this.storePath), { recursive: true });
|
|
185
|
+
fs.writeFileSync(this.storePath, JSON.stringify({ approvedOrigins: next }, null, 2), { mode: 0o600 });
|
|
186
|
+
try {
|
|
187
|
+
fs.chmodSync(this.storePath, 0o600);
|
|
188
|
+
}
|
|
189
|
+
catch { /* best effort on platforms without chmod */ }
|
|
190
|
+
}
|
|
191
|
+
revokeOrigin(origin) {
|
|
192
|
+
const next = this.readApprovedOrigins().filter((o) => o.toLowerCase() !== origin.toLowerCase());
|
|
193
|
+
fs.mkdirSync(path.dirname(this.storePath), { recursive: true });
|
|
194
|
+
fs.writeFileSync(this.storePath, JSON.stringify({ approvedOrigins: next }, null, 2), { mode: 0o600 });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.RemoteTrustStore = RemoteTrustStore;
|
|
198
|
+
/**
|
|
199
|
+
* Additional trusted domains from the process environment. Deliberately env and not a VS Code
|
|
200
|
+
* setting that a workspace could reach: this is the enterprise/self-host escape hatch, set by
|
|
201
|
+
* whoever launches the editor, and it must not be settable by a repository.
|
|
202
|
+
*/
|
|
203
|
+
function trustedDomainsFromEnv(env = process.env) {
|
|
204
|
+
return (env.AGENTHIPPO_REMOTE_TRUSTED_HOSTS ?? '')
|
|
205
|
+
.split(',')
|
|
206
|
+
.map((s) => s.trim())
|
|
207
|
+
.filter(Boolean);
|
|
208
|
+
}
|
|
209
|
+
function createRemoteTrustGate(opts = {}) {
|
|
210
|
+
const store = opts.store ?? new RemoteTrustStore();
|
|
211
|
+
const trustedDomains = opts.trustedDomains
|
|
212
|
+
?? [...exports.DEFAULT_TRUSTED_REMOTE_DOMAINS, ...trustedDomainsFromEnv()];
|
|
213
|
+
return {
|
|
214
|
+
async evaluate(url) {
|
|
215
|
+
const approvedOrigins = store.readApprovedOrigins();
|
|
216
|
+
let verdict = classifyRemoteServeUrl(url, { trustedDomains, approvedOrigins });
|
|
217
|
+
if (verdict.level === 'refused') {
|
|
218
|
+
return { allowed: false, sendAuth: false, requireAuth: false, verdict };
|
|
219
|
+
}
|
|
220
|
+
if (verdict.level === 'loopback') {
|
|
221
|
+
// The user's own machine. Allowed without a prompt, and the token may go — a local
|
|
222
|
+
// `agenthippo serve` validates it, and this path has always worked that way. Crucially
|
|
223
|
+
// it does NOT force a sign-in: an unauthenticated local serve stays usable.
|
|
224
|
+
return { allowed: true, sendAuth: true, requireAuth: false, verdict };
|
|
225
|
+
}
|
|
226
|
+
if (verdict.level === 'trusted') {
|
|
227
|
+
return { allowed: true, sendAuth: true, requireAuth: true, verdict };
|
|
228
|
+
}
|
|
229
|
+
// Untrusted: one explicit, modal, host-naming consent — or nothing.
|
|
230
|
+
if (!opts.prompt) {
|
|
231
|
+
return {
|
|
232
|
+
allowed: false,
|
|
233
|
+
sendAuth: false,
|
|
234
|
+
requireAuth: false,
|
|
235
|
+
verdict: {
|
|
236
|
+
...verdict,
|
|
237
|
+
reason: untrustedRefusalMessage(verdict),
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const approved = await opts.prompt(verdict);
|
|
242
|
+
if (!approved) {
|
|
243
|
+
return {
|
|
244
|
+
allowed: false,
|
|
245
|
+
sendAuth: false,
|
|
246
|
+
requireAuth: false,
|
|
247
|
+
verdict: { ...verdict, reason: untrustedRefusalMessage(verdict) },
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
store.approveOrigin(verdict.origin);
|
|
251
|
+
verdict = { ...verdict, level: 'trusted' };
|
|
252
|
+
return { allowed: true, sendAuth: true, requireAuth: true, verdict };
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function untrustedRefusalMessage(verdict) {
|
|
257
|
+
return (`This agent pack routes your chat to "${verdict.origin}", which is not an AgentHippo host and ` +
|
|
258
|
+
`which you have not approved. The request would include your AgentHippo access token and your ` +
|
|
259
|
+
`full message, so it was refused. If you trust this host, approve it when prompted, or set ` +
|
|
260
|
+
`AGENTHIPPO_REMOTE_TRUSTED_HOSTS=${verdict.hostname} in the environment that launches your editor.`);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* The consent prompt, as a modal. Separated from the gate so tests never touch the VS Code API and
|
|
264
|
+
* so a headless/CLI host simply has no prompt (⇒ refuse) rather than a broken import.
|
|
265
|
+
*/
|
|
266
|
+
function vscodeRemoteTrustPrompt(showWarningMessage) {
|
|
267
|
+
return async (verdict) => {
|
|
268
|
+
const choice = await showWarningMessage(`Send your AgentHippo access token to ${verdict.origin}?`, {
|
|
269
|
+
modal: true,
|
|
270
|
+
detail: `This agent pack runs remotely on ${verdict.hostname}, which is not an AgentHippo host.\n\n` +
|
|
271
|
+
`Approving sends your AgentHippo access token and the full text of every message in this ` +
|
|
272
|
+
`chat to that host. Approve only if you operate or trust it.\n\n` +
|
|
273
|
+
`This choice is remembered for ${verdict.origin} on this machine.`,
|
|
274
|
+
}, 'Approve and Remember');
|
|
275
|
+
return choice === 'Approve and Remember';
|
|
276
|
+
};
|
|
277
|
+
}
|
|
@@ -6,31 +6,78 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.buildServeAuthHeaders = buildServeAuthHeaders;
|
|
7
7
|
exports.normalizeServeBaseUrl = normalizeServeBaseUrl;
|
|
8
8
|
exports.getRemoteServeUrl = getRemoteServeUrl;
|
|
9
|
+
exports.getRemoteServeUrlDiagnostic = getRemoteServeUrlDiagnostic;
|
|
9
10
|
exports.streamRemoteServeChat = streamRemoteServeChat;
|
|
11
|
+
const remoteTrust_js_1 = require("./remoteTrust.js");
|
|
10
12
|
/** Abort if the stream sends no data for this long (reset on every chunk). */
|
|
11
13
|
const IDLE_TIMEOUT_MS = 120_000;
|
|
12
14
|
/** Safety net so a runaway stream can't hold the conversation open forever. */
|
|
13
15
|
const HARD_CAP_MS = 30 * 60_000;
|
|
16
|
+
/**
|
|
17
|
+
* Build the outbound auth headers.
|
|
18
|
+
*
|
|
19
|
+
* **No self-asserted identity header.** This used to also send `X-Agent-User: <auth.userEmail>`,
|
|
20
|
+
* and the serve side trusts `x-agent-user` as its first identity alias. On any deployment that does
|
|
21
|
+
* not pin `AGENTHIPPO_IDENTITY_HEADER`, a client could put someone else's address there and be
|
|
22
|
+
* namespaced into that user's session and state, and be issued a data-plane nonce scoped to them.
|
|
23
|
+
* The bearer token already carries a *verified* identity, so the header added nothing but an
|
|
24
|
+
* impersonation primitive: send the credential and let the server derive who it belongs to.
|
|
25
|
+
*/
|
|
14
26
|
function buildServeAuthHeaders(auth) {
|
|
15
27
|
const headers = {};
|
|
16
28
|
if (!auth?.accessToken) {
|
|
17
29
|
return headers;
|
|
18
30
|
}
|
|
19
31
|
headers.Authorization = `Bearer ${auth.accessToken}`;
|
|
20
|
-
if (auth.userEmail?.trim()) {
|
|
21
|
-
headers['X-Agent-User'] = auth.userEmail.trim();
|
|
22
|
-
}
|
|
23
32
|
return headers;
|
|
24
33
|
}
|
|
25
34
|
function normalizeServeBaseUrl(url) {
|
|
26
35
|
return url.trim().replace(/\/+$/, '');
|
|
27
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* The remote endpoint declared by a pack manifest.
|
|
39
|
+
*
|
|
40
|
+
* This value is attacker-controllable in the interesting case: manifests arrive from the store, a
|
|
41
|
+
* pull request, or a shared library. Only the scheme is decided here (`https://`, or `http://` for
|
|
42
|
+
* loopback); WHO may receive the user's access token is decided by `remote/remoteTrust.ts` at the
|
|
43
|
+
* moment of use, because that decision needs the user's persisted approvals.
|
|
44
|
+
*
|
|
45
|
+
* A URL with an unusable scheme is dropped rather than returned, so no other code path can dial it;
|
|
46
|
+
* `getRemoteServeUrlDiagnostic` explains the drop for callers that want to tell the user.
|
|
47
|
+
*/
|
|
28
48
|
function getRemoteServeUrl(manifest) {
|
|
29
49
|
const url = manifest?.spec?.remote?.url?.trim();
|
|
30
|
-
|
|
50
|
+
if (!url) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
return (0, remoteTrust_js_1.classifyRemoteServeUrl)(url).level === 'refused' ? undefined : url;
|
|
54
|
+
}
|
|
55
|
+
/** The reason `getRemoteServeUrl` dropped a manifest's URL, or undefined if it did not. */
|
|
56
|
+
function getRemoteServeUrlDiagnostic(manifest) {
|
|
57
|
+
const url = manifest?.spec?.remote?.url?.trim();
|
|
58
|
+
if (!url) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const verdict = (0, remoteTrust_js_1.classifyRemoteServeUrl)(url);
|
|
62
|
+
return verdict.level === 'refused' ? verdict.reason : undefined;
|
|
31
63
|
}
|
|
32
64
|
async function streamRemoteServeChat(options, emitter) {
|
|
33
65
|
const base = normalizeServeBaseUrl(options.baseUrl);
|
|
66
|
+
// Final gate before anything leaves the process. A refused scheme never reaches fetch(), and a
|
|
67
|
+
// host the caller did not vouch for never receives the bearer token — the request goes out
|
|
68
|
+
// unauthenticated instead, so a misconfigured pack fails with the remote's own 401 rather than
|
|
69
|
+
// handing over the credential.
|
|
70
|
+
const verdict = (0, remoteTrust_js_1.classifyRemoteServeUrl)(base, {
|
|
71
|
+
trustedDomains: [...remoteTrust_js_1.DEFAULT_TRUSTED_REMOTE_DOMAINS, ...(0, remoteTrust_js_1.trustedDomainsFromEnv)()],
|
|
72
|
+
});
|
|
73
|
+
if (verdict.level === 'refused') {
|
|
74
|
+
const message = verdict.reason ?? `Refusing to contact remote agent at ${base}`;
|
|
75
|
+
await emitter.error(message);
|
|
76
|
+
await emitter.done();
|
|
77
|
+
return { ok: false, error: message };
|
|
78
|
+
}
|
|
79
|
+
const authAllowed = options.authorizedForAuth === true || (0, remoteTrust_js_1.mayReceiveAccessToken)(verdict);
|
|
80
|
+
const auth = authAllowed ? options.auth : undefined;
|
|
34
81
|
const url = `${base}/v1/chat/stream`;
|
|
35
82
|
const body = { message: options.message };
|
|
36
83
|
if (options.sessionId?.trim()) {
|
|
@@ -66,7 +113,7 @@ async function streamRemoteServeChat(options, emitter) {
|
|
|
66
113
|
headers: {
|
|
67
114
|
'Content-Type': 'application/json',
|
|
68
115
|
Accept: 'text/event-stream',
|
|
69
|
-
...buildServeAuthHeaders(
|
|
116
|
+
...buildServeAuthHeaders(auth),
|
|
70
117
|
},
|
|
71
118
|
body: JSON.stringify(body),
|
|
72
119
|
signal: ac.signal,
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) AgentHippo.ai. All rights reserved.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.startRunnerHost = startRunnerHost;
|
|
7
|
+
const protocol_1 = require("./protocol");
|
|
8
|
+
/** Engines sweep idle sessions/caches on this cadence (matches the in-process host's timer). */
|
|
9
|
+
const MAINTENANCE_INTERVAL_MS = 1000 * 60 * 5;
|
|
10
|
+
/**
|
|
11
|
+
* The answer the runner gives to every `question`. Mirrors `cli/commands/serve.ts` and
|
|
12
|
+
* `headless/index.ts`: emit for visibility, decline so the run continues. There is no reverse
|
|
13
|
+
* RPC to wait on, so a question can never wedge a turn.
|
|
14
|
+
*/
|
|
15
|
+
const DECLINED = { selected: [], freeText: null, declined: true };
|
|
16
|
+
function startRunnerHost(opts) {
|
|
17
|
+
const send = (frame) => { opts.output.write((0, protocol_1.encodeRunnerFrame)(frame)); };
|
|
18
|
+
const inflight = new Map();
|
|
19
|
+
let buffer = '';
|
|
20
|
+
let closed = false;
|
|
21
|
+
const maintenance = setInterval(() => {
|
|
22
|
+
try {
|
|
23
|
+
opts.engine.onMaintenance(opts.logger ?? consoleLogger());
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
opts.logger?.warn(`[Runner] maintenance failed: ${errText(err)}`);
|
|
27
|
+
}
|
|
28
|
+
}, opts.maintenanceIntervalMs ?? MAINTENANCE_INTERVAL_MS);
|
|
29
|
+
// Never hold the sandbox open on the timer alone.
|
|
30
|
+
if (typeof maintenance.unref === 'function') {
|
|
31
|
+
maintenance.unref();
|
|
32
|
+
}
|
|
33
|
+
let finish = () => undefined;
|
|
34
|
+
const done = new Promise((resolve) => {
|
|
35
|
+
finish = () => {
|
|
36
|
+
if (closed) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
closed = true;
|
|
40
|
+
clearInterval(maintenance);
|
|
41
|
+
for (const ctrl of inflight.values()) {
|
|
42
|
+
ctrl.abort();
|
|
43
|
+
}
|
|
44
|
+
inflight.clear();
|
|
45
|
+
resolve();
|
|
46
|
+
};
|
|
47
|
+
opts.input.on('data', (chunk) => {
|
|
48
|
+
buffer += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
49
|
+
const { lines, rest } = (0, protocol_1.splitFrames)(buffer);
|
|
50
|
+
buffer = rest;
|
|
51
|
+
for (const line of lines) {
|
|
52
|
+
const frame = (0, protocol_1.parseClientFrame)(line);
|
|
53
|
+
if (!frame) {
|
|
54
|
+
opts.logger?.warn('[Runner] dropped malformed client frame');
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
void handle(frame);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
opts.input.on('end', finish);
|
|
61
|
+
opts.input.on('close', finish);
|
|
62
|
+
opts.input.on('error', (err) => {
|
|
63
|
+
opts.logger?.warn(`[Runner] input error: ${errText(err)}`);
|
|
64
|
+
finish();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
async function handle(frame) {
|
|
68
|
+
if (frame.type === 'abort') {
|
|
69
|
+
inflight.get(frame.id)?.abort();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
await run(frame.id, frame.message, frame.options);
|
|
73
|
+
}
|
|
74
|
+
async function run(id, message, options) {
|
|
75
|
+
if (inflight.has(id)) {
|
|
76
|
+
send({ type: 'failed', id, message: `duplicate run id ${id}` });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const controller = new AbortController();
|
|
80
|
+
inflight.set(id, controller);
|
|
81
|
+
const emitter = makeEmitter(send, id);
|
|
82
|
+
try {
|
|
83
|
+
// `options` crossed the boundary already scrubbed of apiKey (see toWireOptions); the
|
|
84
|
+
// engine reaches models via baseUrl + modelToken, both sandbox-scoped.
|
|
85
|
+
await opts.engine.stream(message, options, emitter, opts.runtime, controller.signal);
|
|
86
|
+
const nativeSessionId = opts.nativeSessionId?.();
|
|
87
|
+
send({ type: 'result', id, ...(nativeSessionId ? { nativeSessionId } : {}) });
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
// An aborted turn is a normal terminal, not a crash — report it as such so the caller
|
|
91
|
+
// settles instead of waiting out a timeout.
|
|
92
|
+
const message = controller.signal.aborted ? 'aborted' : errText(err);
|
|
93
|
+
send({ type: 'failed', id, message });
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
inflight.delete(id);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// The runner is live once the engine is constructed and the loop is wired. `demux: true` tells
|
|
100
|
+
// serve this host tags streamed events with their run id, so it may run several turns here at
|
|
101
|
+
// once; a serve talking to an older image never sees it and serializes instead.
|
|
102
|
+
send({ type: 'ready', demux: true });
|
|
103
|
+
return { done, close: () => finish() };
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Bridges `StreamEmitter` calls onto the wire, 1:1 with the existing worker event union.
|
|
107
|
+
*
|
|
108
|
+
* Every event is tagged with the run it came from. One sandbox may host several of a user's
|
|
109
|
+
* sessions, and an untagged event can only be broadcast to every in-flight turn — which wrote one
|
|
110
|
+
* session's tokens and tool calls into another's transcript.
|
|
111
|
+
*/
|
|
112
|
+
function makeEmitter(send, id) {
|
|
113
|
+
const emit = (event) => send({ id, event });
|
|
114
|
+
return {
|
|
115
|
+
async thinking(delta) { emit({ type: 'thinking', delta }); },
|
|
116
|
+
async text(delta) { emit({ type: 'text', delta }); },
|
|
117
|
+
async toolStart(toolName, input, toolCallId) {
|
|
118
|
+
emit({ type: 'toolStart', toolName, ...(input !== undefined ? { input } : {}), ...(toolCallId ? { toolCallId } : {}) });
|
|
119
|
+
},
|
|
120
|
+
async toolEnd(toolName, toolCallId, result, isError) {
|
|
121
|
+
emit({ type: 'toolEnd', toolName, toolCallId, ...(result !== undefined ? { result } : {}), ...(isError !== undefined ? { isError } : {}) });
|
|
122
|
+
},
|
|
123
|
+
async progress(message) { emit({ type: 'progress', message }); },
|
|
124
|
+
async question(payload) {
|
|
125
|
+
// One-way: forwarded for visibility, answered here. No answer frame exists, but it
|
|
126
|
+
// still reaches a client stream, so it carries the run id like any other event.
|
|
127
|
+
send({ type: 'question', payload, id });
|
|
128
|
+
return DECLINED;
|
|
129
|
+
},
|
|
130
|
+
async error(message) { emit({ type: 'error', message }); },
|
|
131
|
+
async done() { emit({ type: 'done' }); },
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function errText(err) {
|
|
135
|
+
return err instanceof Error ? err.message : String(err);
|
|
136
|
+
}
|
|
137
|
+
function consoleLogger() {
|
|
138
|
+
return {
|
|
139
|
+
info: () => undefined, warn: () => undefined, error: () => undefined, debug: () => undefined,
|
|
140
|
+
};
|
|
141
|
+
}
|