agent86-web 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +86 -2
- package/dist/agent-process.js +284 -0
- package/dist/agent86.js +77 -0
- package/dist/auth.js +96 -0
- package/dist/cli.js +152 -0
- package/dist/duration.js +9 -0
- package/dist/files.js +69 -0
- package/dist/policy.js +99 -0
- package/dist/public/agent86-logo.png +0 -0
- package/dist/public/assets/engine-B6asLUEM.js +6 -0
- package/dist/public/assets/index-DTCJJId8.js +107 -0
- package/dist/public/assets/index-IoOJPMXl.css +2 -0
- package/dist/public/favicon.png +0 -0
- package/dist/public/index.html +15 -0
- package/dist/server.js +311 -0
- package/dist/sessions.js +61 -0
- package/dist/static.js +66 -0
- package/dist/threads.js +79 -0
- package/dist/trust.js +102 -0
- package/dist/updates.js +70 -0
- package/dist/workspaces.js +24 -0
- package/package.json +50 -3
package/dist/trust.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Project trust from the browser (docs/adr/0004-project-trust-from-the-browser.md).
|
|
2
|
+
//
|
|
3
|
+
// agent86 ignores a project file's riskier settings until the user trusts the file. Over ACP it
|
|
4
|
+
// never asks, and `--trust-project` trusts for one run without remembering. So the bridge keeps
|
|
5
|
+
// its own record of what the user trusted here, by the file's real path and the SHA-256 of its
|
|
6
|
+
// bytes, and passes `--trust-project` when it starts agent86 for a project whose file still
|
|
7
|
+
// matches. Any change to the file needs trust again. The bridge never writes agent86's own record.
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { chmodSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import { realpath, within } from "./workspaces.js";
|
|
13
|
+
/** The largest project file shown for review. A config file is small; anything bigger is refused. */
|
|
14
|
+
export const MAX_CONFIG_BYTES = 256 * 1024;
|
|
15
|
+
export function sha256(bytes) {
|
|
16
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The project's agent86 config file, if it has one (read-only, for review and hashing). A file that
|
|
20
|
+
* is not a regular file inside the workspace (a symlink to `~/.ssh/id_ed25519`, say) is refused, so
|
|
21
|
+
* the review never shows a file from elsewhere.
|
|
22
|
+
*/
|
|
23
|
+
export function readProjectConfig(workspace) {
|
|
24
|
+
let path;
|
|
25
|
+
try {
|
|
26
|
+
path = realpath(join(workspace, ".agent86", "config.toml"));
|
|
27
|
+
if (!within(path, realpath(workspace)) || !statSync(path).isFile())
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
let bytes;
|
|
34
|
+
try {
|
|
35
|
+
bytes = readFileSync(path);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
if (bytes.length > MAX_CONFIG_BYTES)
|
|
41
|
+
return undefined;
|
|
42
|
+
return { path, contents: bytes.toString("utf8"), sha256: sha256(bytes) };
|
|
43
|
+
}
|
|
44
|
+
export class TrustStore {
|
|
45
|
+
file;
|
|
46
|
+
/** `dir` is the bridge's own state directory (default `~/.agent86-web`). */
|
|
47
|
+
constructor(dir = join(homedir(), ".agent86-web")) {
|
|
48
|
+
this.file = join(dir, "trusted-projects.json");
|
|
49
|
+
}
|
|
50
|
+
list() {
|
|
51
|
+
try {
|
|
52
|
+
const parsed = JSON.parse(readFileSync(this.file, "utf8"));
|
|
53
|
+
return Array.isArray(parsed.projects) ? parsed.projects : [];
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Whether the workspace's config file, as it is now, was trusted here. */
|
|
60
|
+
isTrusted(workspace) {
|
|
61
|
+
const config = readProjectConfig(workspace);
|
|
62
|
+
if (!config)
|
|
63
|
+
return false;
|
|
64
|
+
return this.list().some((r) => r.path === config.path && r.sha256 === config.sha256);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Trust the workspace's config file, if it still has the hash the user reviewed. Returns false
|
|
68
|
+
* when the file is gone or has changed since (the user must review it again).
|
|
69
|
+
*/
|
|
70
|
+
trust(workspace, reviewedSha256) {
|
|
71
|
+
const config = readProjectConfig(workspace);
|
|
72
|
+
if (!config || config.sha256 !== reviewedSha256)
|
|
73
|
+
return false;
|
|
74
|
+
const records = this.list().filter((r) => r.path !== config.path);
|
|
75
|
+
records.push({ path: config.path, sha256: config.sha256, trustedAt: new Date().toISOString() });
|
|
76
|
+
this.write(records);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
revoke(path) {
|
|
80
|
+
const records = this.list();
|
|
81
|
+
const kept = records.filter((r) => r.path !== path);
|
|
82
|
+
if (kept.length === records.length)
|
|
83
|
+
return false;
|
|
84
|
+
this.write(kept);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
/** Written atomically, readable only by the user (docs/SECURITY.md T16, T17). */
|
|
88
|
+
write(records) {
|
|
89
|
+
mkdirSync(dirname(this.file), { recursive: true, mode: 0o700 });
|
|
90
|
+
const temporary = `${this.file}.${process.pid}.tmp`;
|
|
91
|
+
writeFileSync(temporary, `${JSON.stringify({ projects: records }, null, 2)}\n`, {
|
|
92
|
+
mode: 0o600,
|
|
93
|
+
});
|
|
94
|
+
renameSync(temporary, this.file);
|
|
95
|
+
try {
|
|
96
|
+
chmodSync(this.file, 0o600);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// Windows: permissions are by ACL; the user profile directory already restricts it.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
package/dist/updates.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// A notice when a newer agent86 or agent86-web is out (docs/OPEN_QUESTIONS.md Q10). At most one
|
|
2
|
+
// check a day, against the npm registry, never blocking startup; any failure means no notice.
|
|
3
|
+
// Turned off with --no-update-check or AGENT86_WEB_NO_UPDATE_CHECK=1.
|
|
4
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { compareVersions } from "./agent86.js";
|
|
8
|
+
export const PACKAGES = { agent86: "agent86", agent86Web: "agent86-web" };
|
|
9
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
10
|
+
const TIMEOUT_MS = 5_000;
|
|
11
|
+
/** Whether the environment turns the check off. */
|
|
12
|
+
export function updateCheckDisabled(env = process.env) {
|
|
13
|
+
const value = env.AGENT86_WEB_NO_UPDATE_CHECK?.trim().toLowerCase();
|
|
14
|
+
return !!value && value !== "0" && value !== "false";
|
|
15
|
+
}
|
|
16
|
+
async function npmLatest(pkg) {
|
|
17
|
+
try {
|
|
18
|
+
const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`, {
|
|
19
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
20
|
+
headers: { accept: "application/json" },
|
|
21
|
+
});
|
|
22
|
+
if (!res.ok)
|
|
23
|
+
return undefined;
|
|
24
|
+
const version = (await res.json()).version;
|
|
25
|
+
return typeof version === "string" ? version : undefined;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** The products with a newer release than the one running, by their latest version. */
|
|
32
|
+
export async function checkForUpdates(options) {
|
|
33
|
+
const now = (options.now ?? Date.now)();
|
|
34
|
+
const file = join(options.stateDir ?? join(homedir(), ".agent86-web"), "update-check.json");
|
|
35
|
+
let latest;
|
|
36
|
+
try {
|
|
37
|
+
const cache = JSON.parse(readFileSync(file, "utf8"));
|
|
38
|
+
if (now - cache.checkedAt < DAY_MS)
|
|
39
|
+
latest = cache.latest;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// No cache yet.
|
|
43
|
+
}
|
|
44
|
+
if (!latest) {
|
|
45
|
+
const lookup = options.latestVersion ?? npmLatest;
|
|
46
|
+
const [agent86, agent86Web] = await Promise.all([
|
|
47
|
+
lookup(PACKAGES.agent86),
|
|
48
|
+
lookup(PACKAGES.agent86Web),
|
|
49
|
+
]);
|
|
50
|
+
latest = {};
|
|
51
|
+
if (agent86)
|
|
52
|
+
latest.agent86 = agent86;
|
|
53
|
+
if (agent86Web)
|
|
54
|
+
latest.agent86Web = agent86Web;
|
|
55
|
+
try {
|
|
56
|
+
mkdirSync(join(file, ".."), { recursive: true, mode: 0o700 });
|
|
57
|
+
writeFileSync(file, JSON.stringify({ checkedAt: now, latest }));
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Not cached; asked again next start.
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const updates = {};
|
|
64
|
+
for (const product of Object.keys(PACKAGES)) {
|
|
65
|
+
const version = latest[product];
|
|
66
|
+
if (version && compareVersions(version, options.current[product]) > 0)
|
|
67
|
+
updates[product] = version;
|
|
68
|
+
}
|
|
69
|
+
return updates;
|
|
70
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The --root jail for workspaces (docs/SECURITY.md T7).
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import { sep } from "node:path";
|
|
4
|
+
export function realpath(path) {
|
|
5
|
+
return realpathSync.native(path);
|
|
6
|
+
}
|
|
7
|
+
/** Whether `path` (already a real path) is `root` or inside it. */
|
|
8
|
+
export function within(path, root) {
|
|
9
|
+
if (path === root)
|
|
10
|
+
return true;
|
|
11
|
+
const prefix = root.endsWith(sep) ? root : root + sep;
|
|
12
|
+
return path.startsWith(prefix);
|
|
13
|
+
}
|
|
14
|
+
/** The real path of `requested` if it exists and lies inside one of `roots`, else undefined. */
|
|
15
|
+
export function resolveWorkspace(requested, roots) {
|
|
16
|
+
let real;
|
|
17
|
+
try {
|
|
18
|
+
real = realpath(requested);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return roots.some((root) => within(real, root)) ? real : undefined;
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent86-web",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A browser interface for agent86. Runs a local bridge between your browser and `agent86 acp`.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Maetek Technologies",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"agent86-web": "./dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20.19"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"agent86",
|
|
21
|
+
"acp",
|
|
22
|
+
"agent-client-protocol",
|
|
23
|
+
"ai",
|
|
24
|
+
"agent"
|
|
25
|
+
],
|
|
26
|
+
"homepage": "https://github.com/Maetek-Technologies/Agent86-web#readme",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/Maetek-Technologies/Agent86-web/issues"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/Maetek-Technologies/Agent86-web.git",
|
|
33
|
+
"directory": "packages/bridge"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"provenance": true
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"ws": "8.22.2"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/ws": "8.18.2",
|
|
44
|
+
"tsx": "4.23.15",
|
|
45
|
+
"@agent86-web/mock-agent": "0.0.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "node scripts/build.mjs",
|
|
49
|
+
"dev": "tsx watch src/cli.ts --port 8686 --dev-origin http://localhost:5173 --no-open",
|
|
50
|
+
"start": "node dist/cli.js",
|
|
51
|
+
"typecheck": "tsc --noEmit"
|
|
52
|
+
}
|
|
6
53
|
}
|