@peakflo/agent-harness 0.2.19 → 0.2.20-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -0
- package/dist/browser-broker/agent-actions.mjs +799 -0
- package/dist/browser-broker/browsers.mjs +1699 -0
- package/dist/browser-broker/credentials.mjs +211 -0
- package/dist/browser-broker/disk-guard.mjs +84 -0
- package/dist/browser-broker/egress.mjs +183 -0
- package/dist/browser-broker/input.mjs +270 -0
- package/dist/browser-broker/lease.mjs +547 -0
- package/dist/browser-broker/local-network.mjs +173 -0
- package/dist/browser-broker/local.mjs +158 -0
- package/dist/browser-broker/log.mjs +28 -0
- package/dist/browser-broker/network-policy.mjs +144 -0
- package/dist/browser-broker/os-users.mjs +493 -0
- package/dist/browser-broker/package.json +1 -0
- package/dist/browser-broker/protocol.mjs +321 -0
- package/dist/browser-broker/queue.mjs +37 -0
- package/dist/browser-broker/recorder-scripts.mjs +221 -0
- package/dist/browser-broker/recorder.mjs +438 -0
- package/dist/browser-broker/recording-store.mjs +493 -0
- package/dist/browser-broker/relay.mjs +399 -0
- package/dist/browser-broker/screencast.mjs +198 -0
- package/dist/browser-broker/state-store.mjs +112 -0
- package/dist/browser-broker/transfers.mjs +460 -0
- package/dist/control-plane.d.ts +6 -0
- package/dist/control-plane.js +10 -0
- package/dist/github-proxy.d.ts +1 -1
- package/dist/github-workspace.d.ts +2 -0
- package/dist/github-workspace.js +4 -0
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +27 -1
- package/dist/runtime/knowledge-tools.d.ts +1 -0
- package/dist/runtime/knowledge-tools.js +3 -0
- package/dist/runtime/local-browser.d.ts +33 -0
- package/dist/runtime/local-browser.js +135 -0
- package/package.json +5 -3
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalBrowsers = exports.LOCAL_BROWSER_FEATURE = void 0;
|
|
4
|
+
exports.localChromium = localChromium;
|
|
5
|
+
/** Owns one preview broker per leased chat, also while the agent is idle. */
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const node_module_1 = require("node:module");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const node_url_1 = require("node:url");
|
|
10
|
+
const packageRequire = (0, node_module_1.createRequire)(__filename);
|
|
11
|
+
exports.LOCAL_BROWSER_FEATURE = 'localBrowserPreview';
|
|
12
|
+
function localChromium() {
|
|
13
|
+
if (process.platform !== 'darwin' && process.platform !== 'linux')
|
|
14
|
+
return null;
|
|
15
|
+
const candidates = process.platform === 'darwin'
|
|
16
|
+
? [
|
|
17
|
+
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
18
|
+
'/Applications/Chromium.app/Contents/MacOS/Chromium'
|
|
19
|
+
]
|
|
20
|
+
: [
|
|
21
|
+
'/usr/bin/chromium',
|
|
22
|
+
'/usr/bin/chromium-browser',
|
|
23
|
+
'/usr/bin/google-chrome'
|
|
24
|
+
];
|
|
25
|
+
try {
|
|
26
|
+
candidates.push(packageRequire('playwright-core').chromium.executablePath());
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Cloud installs omit these optional local-preview dependencies.
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return candidates.find((file) => (0, node_fs_1.existsSync)(file)) ?? null;
|
|
33
|
+
}
|
|
34
|
+
// tsc rewrites plain import() to require() in this CJS package. Keep Node's
|
|
35
|
+
// native import for the packaged ESM broker, as for the optional backend SDKs.
|
|
36
|
+
const nativeImport = new Function('url', 'return import(url)');
|
|
37
|
+
class LocalBrowsers {
|
|
38
|
+
options;
|
|
39
|
+
sessions = new Map();
|
|
40
|
+
opening = new Set();
|
|
41
|
+
stopped = false;
|
|
42
|
+
constructor(options) {
|
|
43
|
+
this.options = options;
|
|
44
|
+
}
|
|
45
|
+
async ensure(sessionId) {
|
|
46
|
+
if (this.stopped ||
|
|
47
|
+
this.sessions.has(sessionId) ||
|
|
48
|
+
this.opening.has(sessionId))
|
|
49
|
+
return;
|
|
50
|
+
this.opening.add(sessionId);
|
|
51
|
+
try {
|
|
52
|
+
const grant = await this.options.grant(sessionId);
|
|
53
|
+
const bundled = (0, node_path_1.join)(__dirname, '..', 'browser-broker', 'local.mjs');
|
|
54
|
+
const moduleUrl = (0, node_url_1.pathToFileURL)((0, node_fs_1.existsSync)(bundled)
|
|
55
|
+
? bundled
|
|
56
|
+
: (0, node_path_1.join)(__dirname, '../../../agentSandbox/browser-broker/local.mjs')).href;
|
|
57
|
+
const module = await (this.options.load
|
|
58
|
+
? this.options.load()
|
|
59
|
+
: nativeImport(moduleUrl));
|
|
60
|
+
const broker = await module.startLocalBrowser({
|
|
61
|
+
...grant,
|
|
62
|
+
sessionId,
|
|
63
|
+
root: (0, node_path_1.join)(this.options.root, 'browser-previews', sessionId),
|
|
64
|
+
executablePath: this.options.executablePath,
|
|
65
|
+
deniedPorts: this.options.deniedPorts,
|
|
66
|
+
controlPlaneUrl: grant.controlPlaneUrl
|
|
67
|
+
});
|
|
68
|
+
if (this.stopped) {
|
|
69
|
+
await broker.close();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const entry = {
|
|
73
|
+
broker,
|
|
74
|
+
timer: setInterval(() => {
|
|
75
|
+
void this.refresh(sessionId);
|
|
76
|
+
}, 20_000),
|
|
77
|
+
at: Date.now(),
|
|
78
|
+
tokenAt: Date.now(),
|
|
79
|
+
refreshing: false
|
|
80
|
+
};
|
|
81
|
+
entry.timer.unref();
|
|
82
|
+
this.sessions.set(sessionId, entry);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
const status = error.status;
|
|
86
|
+
const reason = typeof status === 'number'
|
|
87
|
+
? `grant HTTP ${status}`
|
|
88
|
+
: error instanceof Error
|
|
89
|
+
? error.name
|
|
90
|
+
: 'unknown failure';
|
|
91
|
+
// Error bodies can contain credentials. Log only the status/error class.
|
|
92
|
+
this.options.log(`Local preview setup failed (${reason}). The agent turn can continue.`);
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
this.opening.delete(sessionId);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async refresh(sessionId) {
|
|
99
|
+
const entry = this.sessions.get(sessionId);
|
|
100
|
+
if (!entry || entry.refreshing)
|
|
101
|
+
return;
|
|
102
|
+
entry.refreshing = true;
|
|
103
|
+
try {
|
|
104
|
+
const grant = await this.options.grant(sessionId);
|
|
105
|
+
// Leave room for two transient grant failures before the 120 s expiry.
|
|
106
|
+
if (Date.now() - entry.tokenAt >= 40_000) {
|
|
107
|
+
entry.broker.updateToken(grant.token);
|
|
108
|
+
entry.tokenAt = Date.now();
|
|
109
|
+
}
|
|
110
|
+
entry.at = Date.now();
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
// Fail closed on a revoked grant, or after one minute without the API.
|
|
114
|
+
const status = error.status;
|
|
115
|
+
if (status === 401 || status === 403 || Date.now() - entry.at >= 60_000) {
|
|
116
|
+
this.sessions.delete(sessionId);
|
|
117
|
+
clearInterval(entry.timer);
|
|
118
|
+
await entry.broker.close();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
entry.refreshing = false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async close() {
|
|
126
|
+
this.stopped = true;
|
|
127
|
+
const entries = [...this.sessions.values()];
|
|
128
|
+
this.sessions.clear();
|
|
129
|
+
await Promise.all(entries.map(async (entry) => {
|
|
130
|
+
clearInterval(entry.timer);
|
|
131
|
+
await entry.broker.close();
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.LocalBrowsers = LocalBrowsers;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peakflo/agent-harness",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.20-rc.2",
|
|
4
4
|
"description": "Headless Peakflo coding-agent harness. One codebase, three hosting modes: a Daytona cloud sandbox, a customer VM, and the 20x desktop.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"registry": "https://registry.npmjs.org/"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"build": "rm -rf dist && tsc -p tsconfig.json && node scripts/make-executable.mjs",
|
|
28
|
+
"build": "rm -rf dist && tsc -p tsconfig.json && node scripts/make-executable.mjs && node scripts/copy-browser.mjs",
|
|
29
29
|
"dev": "tsc -p tsconfig.json --watch --preserveWatchOutput",
|
|
30
30
|
"start": "tsx src/cli.ts start",
|
|
31
31
|
"clean": "rm -rf dist",
|
|
@@ -44,7 +44,9 @@
|
|
|
44
44
|
"reflect-metadata": "^0.2.2"
|
|
45
45
|
},
|
|
46
46
|
"optionalDependencies": {
|
|
47
|
-
"@anthropic-ai/claude-agent-sdk": "0.3.258"
|
|
47
|
+
"@anthropic-ai/claude-agent-sdk": "0.3.258",
|
|
48
|
+
"playwright-core": "1.63.0",
|
|
49
|
+
"ws": "8.18.1"
|
|
48
50
|
},
|
|
49
51
|
"repository": {
|
|
50
52
|
"type": "git",
|