@agentage/extension 0.20.1 → 0.20.3
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/dist/auth/part-auth.js +4 -5
- package/dist/context/context.d.ts +0 -1
- package/dist/host/child-env.d.ts +11 -0
- package/dist/host/child-env.js +12 -0
- package/dist/host/{daemon/guard.js → guard.js} +1 -1
- package/dist/host/host-extension.js +1 -1
- package/dist/host/host-main.d.ts +1 -0
- package/dist/host/host-main.js +3 -0
- package/dist/host/index.d.ts +1 -5
- package/dist/host/index.js +1 -5
- package/dist/host/kit-shell.d.ts +1 -0
- package/dist/host/kit-shell.js +2 -0
- package/dist/host/serve-host.js +1 -1
- package/dist/internal/index.d.ts +29 -0
- package/dist/internal/index.js +30 -0
- package/dist/runtime/part-mounts.d.ts +0 -1
- package/dist/runtime/part-mounts.js +1 -1
- package/dist/runtime/run-part.js +0 -2
- package/dist/server/app.d.ts +0 -1
- package/dist/server/app.js +4 -5
- package/dist/tool/check.js +3 -0
- package/dist/tool/recipe.js +2 -2
- package/dist/tool/up/gateway.js +0 -3
- package/package.json +5 -1
- package/dist/host/daemon/add.d.ts +0 -11
- package/dist/host/daemon/add.js +0 -93
- package/dist/host/daemon/app-files.d.ts +0 -8
- package/dist/host/daemon/app-files.js +0 -34
- package/dist/host/daemon/app-header.d.ts +0 -2
- package/dist/host/daemon/app-header.js +0 -12
- package/dist/host/daemon/app-reload.d.ts +0 -10
- package/dist/host/daemon/app-reload.js +0 -18
- package/dist/host/daemon/child-files.d.ts +0 -20
- package/dist/host/daemon/child-files.js +0 -53
- package/dist/host/daemon/child.d.ts +0 -30
- package/dist/host/daemon/child.js +0 -126
- package/dist/host/daemon/cli-user-watch.d.ts +0 -9
- package/dist/host/daemon/cli-user-watch.js +0 -47
- package/dist/host/daemon/cli-user.d.ts +0 -2
- package/dist/host/daemon/cli-user.js +0 -42
- package/dist/host/daemon/daemon-files.d.ts +0 -20
- package/dist/host/daemon/daemon-files.js +0 -46
- package/dist/host/daemon/daemon-owner.d.ts +0 -1
- package/dist/host/daemon/daemon-owner.js +0 -32
- package/dist/host/daemon/daemon.d.ts +0 -19
- package/dist/host/daemon/daemon.js +0 -137
- package/dist/host/daemon/entries.d.ts +0 -21
- package/dist/host/daemon/entries.js +0 -24
- package/dist/host/daemon/gate.d.ts +0 -3
- package/dist/host/daemon/gate.js +0 -19
- package/dist/host/daemon/health-routes.d.ts +0 -18
- package/dist/host/daemon/health-routes.js +0 -75
- package/dist/host/daemon/host-token.d.ts +0 -6
- package/dist/host/daemon/host-token.js +0 -28
- package/dist/host/daemon/installation.d.ts +0 -35
- package/dist/host/daemon/installation.js +0 -90
- package/dist/host/daemon/installer-call.d.ts +0 -21
- package/dist/host/daemon/installer-call.js +0 -48
- package/dist/host/daemon/json-file.d.ts +0 -6
- package/dist/host/daemon/json-file.js +0 -90
- package/dist/host/daemon/lane.d.ts +0 -9
- package/dist/host/daemon/lane.js +0 -24
- package/dist/host/daemon/last-words.d.ts +0 -2
- package/dist/host/daemon/last-words.js +0 -28
- package/dist/host/daemon/limits.d.ts +0 -16
- package/dist/host/daemon/limits.js +0 -31
- package/dist/host/daemon/ops.d.ts +0 -12
- package/dist/host/daemon/ops.js +0 -94
- package/dist/host/daemon/patch-values.d.ts +0 -6
- package/dist/host/daemon/patch-values.js +0 -39
- package/dist/host/daemon/pending.d.ts +0 -15
- package/dist/host/daemon/pending.js +0 -18
- package/dist/host/daemon/proxy.d.ts +0 -11
- package/dist/host/daemon/proxy.js +0 -106
- package/dist/host/daemon/queue.d.ts +0 -3
- package/dist/host/daemon/queue.js +0 -27
- package/dist/host/daemon/redact-stream.d.ts +0 -4
- package/dist/host/daemon/redact-stream.js +0 -24
- package/dist/host/daemon/reload-marker.d.ts +0 -8
- package/dist/host/daemon/reload-marker.js +0 -57
- package/dist/host/daemon/reload.d.ts +0 -10
- package/dist/host/daemon/reload.js +0 -72
- package/dist/host/daemon/restart.d.ts +0 -14
- package/dist/host/daemon/restart.js +0 -59
- package/dist/host/daemon/routes.d.ts +0 -6
- package/dist/host/daemon/routes.js +0 -101
- package/dist/host/daemon/run-lock.d.ts +0 -1
- package/dist/host/daemon/run-lock.js +0 -15
- package/dist/host/daemon/seal-reach.d.ts +0 -2
- package/dist/host/daemon/seal-reach.js +0 -38
- package/dist/host/daemon/seal.d.ts +0 -20
- package/dist/host/daemon/seal.js +0 -93
- package/dist/host/daemon/shell-events.d.ts +0 -9
- package/dist/host/daemon/shell-events.js +0 -36
- package/dist/host/daemon/shell-routes.d.ts +0 -29
- package/dist/host/daemon/shell-routes.js +0 -68
- package/dist/host/daemon/sign-in-page.d.ts +0 -3
- package/dist/host/daemon/sign-in-page.js +0 -30
- package/dist/host/daemon/start-checks.d.ts +0 -6
- package/dist/host/daemon/start-checks.js +0 -29
- package/dist/host/daemon/stopping.d.ts +0 -10
- package/dist/host/daemon/stopping.js +0 -28
- package/dist/host/daemon/supervisor.d.ts +0 -59
- package/dist/host/daemon/supervisor.js +0 -107
- package/dist/host/daemon/write-all.d.ts +0 -8
- package/dist/host/daemon/write-all.js +0 -45
- package/dist/shell/dist/index.html +0 -49
- package/dist/shell/dist/shell.css +0 -2
- package/dist/shell/dist/shell.js +0 -69
- package/dist/shell/dist/vendor/app.js +0 -1
- package/dist/shell/dist/vendor/chunk-AOJ3DQEL.js +0 -14
- package/dist/shell/dist/vendor/chunk-LW5HXGAJ.js +0 -14
- package/dist/shell/dist/vendor/chunk-PQJPUKWH.js +0 -14
- package/dist/shell/dist/vendor/chunk-SQE76S5B.js +0 -1
- package/dist/shell/dist/vendor/jsx-runtime.js +0 -1
- package/dist/shell/dist/vendor/react-dom-client.js +0 -33
- package/dist/shell/dist/vendor/react-dom.js +0 -1
- package/dist/shell/dist/vendor/react.js +0 -1
- package/dist/shell/package.json +0 -5
- /package/dist/host/{daemon/guard.d.ts → guard.d.ts} +0 -0
package/dist/host/daemon/seal.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
|
-
import { dirname, join, parse, sep } from 'node:path';
|
|
4
|
-
import {} from '../../manifest/manifest.schema.js';
|
|
5
|
-
import { hasStore } from '../../manifest/parts.js';
|
|
6
|
-
import { assertReach, real } from './seal-reach.js';
|
|
7
|
-
// G6 (PD2): a git store spawns git for each operation; no other package gets a child process.
|
|
8
|
-
export const spawnsGit = (pkg) => hasStore(pkg, 'git');
|
|
9
|
-
export const sealOfEntry = (seal, pkg) => seal === 'on' && pkg && spawnsGit(pkg) ? 'partial' : seal;
|
|
10
|
-
// C2: the permission model with the bypass fixes of D2; the same rule as e2e sealFloorMet.
|
|
11
|
-
const SEAL_FLOOR = 'Node 22.22.2 or 24.14.1';
|
|
12
|
-
const versionOf = (version) => version.split('.').map(Number);
|
|
13
|
-
const atLeast = (version, major, minor, patch) => {
|
|
14
|
-
const [a = 0, b = 0, c = 0] = versionOf(version);
|
|
15
|
-
return a === major && (b > minor || (b === minor && c >= patch));
|
|
16
|
-
};
|
|
17
|
-
// An odd major has no known fix release: off; an even major above 24 is on.
|
|
18
|
-
export const sealOf = (version) => {
|
|
19
|
-
const [major = 0] = versionOf(version);
|
|
20
|
-
if (major === 22)
|
|
21
|
-
return atLeast(version, 22, 22, 2) ? 'on' : 'off';
|
|
22
|
-
if (major === 24)
|
|
23
|
-
return atLeast(version, 24, 14, 1) ? 'on' : 'off';
|
|
24
|
-
return major > 24 && major % 2 === 0 ? 'on' : 'off';
|
|
25
|
-
};
|
|
26
|
-
// --permission is a stable flag from 22.13.0 and 23.5.0: below the floor it still limits, seal off.
|
|
27
|
-
export const permissionFlag = (version) => {
|
|
28
|
-
const [major = 0] = versionOf(version);
|
|
29
|
-
return major >= 24 || atLeast(version, 22, 13, 0) || atLeast(version, 23, 5, 0);
|
|
30
|
-
};
|
|
31
|
-
export const sealOffReason = (version) => `seal off: ${SEAL_FLOOR} needed, this is Node ${version}`;
|
|
32
|
-
const NODE_MODULES = `${sep}node_modules${sep}`;
|
|
33
|
-
// The folder that holds the node_modules a path sits in (a tree of the cli); else the path itself.
|
|
34
|
-
export const treeOf = (dir) => {
|
|
35
|
-
const at = dir.lastIndexOf(NODE_MODULES);
|
|
36
|
-
return at < 0 ? dir : dir.slice(0, at);
|
|
37
|
-
};
|
|
38
|
-
const hasWorkspaces = (dir) => {
|
|
39
|
-
try {
|
|
40
|
-
return 'workspaces' in JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
// The folders from start up, never above the user's home nor the root.
|
|
47
|
-
const upward = (start) => {
|
|
48
|
-
const found = [start];
|
|
49
|
-
for (let dir = start; dir !== homedir() && dir !== parse(dir).root;)
|
|
50
|
-
found.push((dir = dirname(dir)));
|
|
51
|
-
return found;
|
|
52
|
-
};
|
|
53
|
-
// The nearest folder with a package.json; none: the folder of the file.
|
|
54
|
-
const packageRoot = (file) => upward(dirname(file)).find((dir) => existsSync(join(dir, 'package.json'))) ?? dirname(file);
|
|
55
|
-
const kitDeps = (pkgDir) => {
|
|
56
|
-
try {
|
|
57
|
-
const pkg = JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf8'));
|
|
58
|
-
return Object.keys({ ...pkg.dependencies, ...pkg.peerDependencies });
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
// Node walks out of a kit nested under the cli to the node_modules npm hoisted a dependency to.
|
|
65
|
-
const hoistedDirs = (inner, main) => {
|
|
66
|
-
const walk = upward(dirname(inner)).map((dir) => join(dir, 'node_modules'));
|
|
67
|
-
const found = kitDeps(packageRoot(main)).map((dep) => walk.find((dir) => existsSync(join(dir, dep, 'package.json'))));
|
|
68
|
-
return [...new Set([inner, ...found.filter((dir) => dir !== undefined)])];
|
|
69
|
-
};
|
|
70
|
-
// Installed: the node_modules of the kit and its dependencies. A checkout: its package and workspace root.
|
|
71
|
-
export const kitReadDirs = (main) => {
|
|
72
|
-
const at = main.lastIndexOf(NODE_MODULES);
|
|
73
|
-
if (at >= 0)
|
|
74
|
-
return hoistedDirs(main.slice(0, at + NODE_MODULES.length - 1), main);
|
|
75
|
-
const root = packageRoot(main);
|
|
76
|
-
return [...new Set([root, upward(root).find(hasWorkspaces) ?? root])];
|
|
77
|
-
};
|
|
78
|
-
// C2: read kit, tree, run/{id}, data/{id}; write the last two; no worker, addon, WASI, sqlite; a child process for git only.
|
|
79
|
-
export const sealFlags = (at) => {
|
|
80
|
-
const { id, main, dir, configDir, runDir, dataDir } = at;
|
|
81
|
-
const both = (paths) => [...new Set(paths.flatMap((path) => [path, real(path)]))];
|
|
82
|
-
const writes = both([runDir, dataDir]);
|
|
83
|
-
const kit = both([...kitReadDirs(main), treeOf(dir)]);
|
|
84
|
-
assertReach(kit, writes, configDir, id);
|
|
85
|
-
const reads = [...new Set([...kit, ...writes])];
|
|
86
|
-
return [
|
|
87
|
-
'--permission',
|
|
88
|
-
'--no-experimental-sqlite',
|
|
89
|
-
...(at.childProcess ? ['--allow-child-process'] : []),
|
|
90
|
-
...reads.map((path) => `--allow-fs-read=${path}`),
|
|
91
|
-
...writes.map((path) => `--allow-fs-write=${path}`),
|
|
92
|
-
];
|
|
93
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type RequestHandler } from 'express';
|
|
2
|
-
export type ShellEvent = 'extensions' | 'app' | 'session';
|
|
3
|
-
export interface ShellEvents {
|
|
4
|
-
send(event: ShellEvent, data: unknown): void;
|
|
5
|
-
stream: RequestHandler;
|
|
6
|
-
}
|
|
7
|
-
export declare const HEARTBEAT_MS = 25000;
|
|
8
|
-
export declare const STALLED_WRITES = 32;
|
|
9
|
-
export declare const shellEvents: (heartbeatMs?: number) => ShellEvents;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {} from 'express';
|
|
2
|
-
// A comment line now and then, so an idle connection is not cut by a proxy or a browser.
|
|
3
|
-
export const HEARTBEAT_MS = 25_000;
|
|
4
|
-
// A tab that does not read: after this many writes in a row that the socket refused, the stream is dropped.
|
|
5
|
-
export const STALLED_WRITES = 32;
|
|
6
|
-
export const shellEvents = (heartbeatMs = HEARTBEAT_MS) => {
|
|
7
|
-
const open = new Map();
|
|
8
|
-
const write = (res, frame) => {
|
|
9
|
-
const refused = res.write(frame) ? 0 : (open.get(res) ?? 0) + 1;
|
|
10
|
-
if (refused < STALLED_WRITES)
|
|
11
|
-
return void open.set(res, refused);
|
|
12
|
-
open.delete(res);
|
|
13
|
-
res.destroy();
|
|
14
|
-
};
|
|
15
|
-
const send = (event, data) => {
|
|
16
|
-
const frame = `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
|
|
17
|
-
for (const res of [...open.keys()])
|
|
18
|
-
write(res, frame);
|
|
19
|
-
};
|
|
20
|
-
// GET /shell/events: server-sent events; the daemon's stop closes every stream.
|
|
21
|
-
const stream = (req, res) => {
|
|
22
|
-
res.writeHead(200, {
|
|
23
|
-
'content-type': 'text/event-stream',
|
|
24
|
-
'cache-control': 'no-store',
|
|
25
|
-
connection: 'keep-alive',
|
|
26
|
-
});
|
|
27
|
-
res.write('retry: 1000\n\n');
|
|
28
|
-
open.set(res, 0);
|
|
29
|
-
const beat = setInterval(() => res.write(': beat\n\n'), heartbeatMs).unref();
|
|
30
|
-
req.on('close', () => {
|
|
31
|
-
clearInterval(beat);
|
|
32
|
-
open.delete(res);
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
return { send, stream };
|
|
36
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type Express } from 'express';
|
|
2
|
-
import { type CliUser } from './cli-user-watch.js';
|
|
3
|
-
import { type Entries } from './entries.js';
|
|
4
|
-
import { type ShellEvents } from './shell-events.js';
|
|
5
|
-
export declare const kitShellDir: (base?: string) => string | undefined;
|
|
6
|
-
export interface Shell {
|
|
7
|
-
dir: string;
|
|
8
|
-
package: string;
|
|
9
|
-
version: string;
|
|
10
|
-
}
|
|
11
|
-
export declare const readShell: (dir: string, version?: string) => Promise<Shell>;
|
|
12
|
-
type User = {
|
|
13
|
-
id: string;
|
|
14
|
-
email?: string;
|
|
15
|
-
};
|
|
16
|
-
type Session = {
|
|
17
|
-
user: User | null;
|
|
18
|
-
host: 'local';
|
|
19
|
-
signIn?: string;
|
|
20
|
-
};
|
|
21
|
-
export declare const sessionOf: ({ sub, text }: CliUser) => Session;
|
|
22
|
-
export declare const shellRoutes: (app: Express, { shell, entries, events, user }: ShellDeps) => void;
|
|
23
|
-
export interface ShellDeps {
|
|
24
|
-
shell?: Shell;
|
|
25
|
-
entries: Entries;
|
|
26
|
-
events: ShellEvents;
|
|
27
|
-
user: CliUser;
|
|
28
|
-
}
|
|
29
|
-
export {};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import express, {} from 'express';
|
|
6
|
-
import { fail } from '../../envelope/envelope.js';
|
|
7
|
-
import { hasApp } from './app-files.js';
|
|
8
|
-
import {} from './cli-user-watch.js';
|
|
9
|
-
import {} from './entries.js';
|
|
10
|
-
import {} from './shell-events.js';
|
|
11
|
-
import { LOCAL_SIGN_IN, signInPage } from './sign-in-page.js';
|
|
12
|
-
// The shell the kit carries (dist/shell, written by the kit build); none when run from src.
|
|
13
|
-
export const kitShellDir = (base = import.meta.url) => {
|
|
14
|
-
const dir = fileURLToPath(new URL('../../shell', base));
|
|
15
|
-
return existsSync(join(dir, 'package.json')) ? dir : undefined;
|
|
16
|
-
};
|
|
17
|
-
// `version` overrides the package's: the kit's own shell reports the kit that built it.
|
|
18
|
-
export const readShell = async (dir, version) => {
|
|
19
|
-
const pkg = JSON.parse(await readFile(join(dir, 'package.json'), 'utf8'));
|
|
20
|
-
if (typeof pkg.version !== 'string' || typeof pkg.name !== 'string')
|
|
21
|
-
throw new Error(`${dir}/package.json has no name or version: not a shell package`);
|
|
22
|
-
return { dir, package: pkg.name, version: version ?? pkg.version };
|
|
23
|
-
};
|
|
24
|
-
const textOf = (value) => (typeof value === 'string' ? value : undefined);
|
|
25
|
-
// K9: the user the children run as (issuer checked in cli-user.ts) and the email of its auth.json.
|
|
26
|
-
// The fields of a cloud app host's session (id, email; no name), so both frames show one label.
|
|
27
|
-
export const sessionOf = ({ sub, text }) => {
|
|
28
|
-
if (sub === undefined)
|
|
29
|
-
return { user: null, host: 'local', signIn: LOCAL_SIGN_IN };
|
|
30
|
-
let shown = {};
|
|
31
|
-
try {
|
|
32
|
-
shown = JSON.parse(text ?? '').user ?? {};
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
// the sub alone
|
|
36
|
-
}
|
|
37
|
-
const email = textOf(shown['email']);
|
|
38
|
-
return { user: { id: sub, ...(email && { email }) }, host: 'local' };
|
|
39
|
-
};
|
|
40
|
-
// First path segments that are daemon routes: an unknown path under them stays a JSON 404.
|
|
41
|
-
const OWN = new Set(['api', 'mcp', 'host', 'shell', 'app', 'health', '.well-known']);
|
|
42
|
-
const page = (shell, entries) => async (req, res, next) => {
|
|
43
|
-
const id = req.path.split('/')[1] ?? '';
|
|
44
|
-
const read = req.method === 'GET' || req.method === 'HEAD';
|
|
45
|
-
if (!read || OWN.has(id) || req.accepts(['html', 'json']) !== 'html')
|
|
46
|
-
return next();
|
|
47
|
-
const known = id === '' || (await hasApp(entries, id));
|
|
48
|
-
res.status(known ? 200 : 404).set('Cache-Control', 'no-cache');
|
|
49
|
-
// The daemon names this path: a dot folder above it (~/.agentage) is allowed.
|
|
50
|
-
res.sendFile(join(shell.dir, 'dist', 'index.html'), { dotfiles: 'allow' }, (err) => err && next(err));
|
|
51
|
-
};
|
|
52
|
-
const notAFile = (req) => {
|
|
53
|
-
throw fail('NOT_FOUND', `${req.originalUrl} is not a shell file`);
|
|
54
|
-
};
|
|
55
|
-
// S1.2.1: /, /{id}/* (the shell page, 404 for an id with no app), /shell/*, the session, the events,
|
|
56
|
-
// and the page of the Sign in link.
|
|
57
|
-
export const shellRoutes = (app, { shell, entries, events, user }) => {
|
|
58
|
-
app.get('/shell/session', async (_req, res) => {
|
|
59
|
-
res.set('Cache-Control', 'no-store').json(sessionOf(user));
|
|
60
|
-
});
|
|
61
|
-
app.get(LOCAL_SIGN_IN, signInPage);
|
|
62
|
-
app.get('/shell/events', events.stream);
|
|
63
|
-
if (!shell)
|
|
64
|
-
return;
|
|
65
|
-
const files = express.static(join(shell.dir, 'dist'), { index: false, dotfiles: 'deny' });
|
|
66
|
-
app.use('/shell', files, notAFile);
|
|
67
|
-
app.use(page(shell, entries));
|
|
68
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {} from 'express';
|
|
2
|
-
// The shell's Sign in link on the daemon: one fixed same-origin path, never a URL of another origin.
|
|
3
|
-
export const LOCAL_SIGN_IN = '/shell/sign-in';
|
|
4
|
-
const PAGE = `<!doctype html>
|
|
5
|
-
<html lang="en">
|
|
6
|
-
<meta charset="utf-8">
|
|
7
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
|
-
<title>Sign in - agentage</title>
|
|
9
|
-
<style>
|
|
10
|
-
:root { color-scheme: light dark; }
|
|
11
|
-
body { font: 15px/1.5 system-ui, sans-serif; max-width: 32rem; margin: 15vh auto; padding: 0 16px; }
|
|
12
|
-
code { font-size: 14px; padding: 2px 6px; border-radius: 4px; background: rgba(127, 127, 127, 0.18); }
|
|
13
|
-
</style>
|
|
14
|
-
<h1>Sign in</h1>
|
|
15
|
-
<p>This dashboard runs on your machine. To sign in, run <code>agentage setup</code> in a terminal.</p>
|
|
16
|
-
<p>The dashboard shows your account a few seconds after the sign-in.</p>
|
|
17
|
-
<p><a href="/">Back to the dashboard</a></p>
|
|
18
|
-
</html>
|
|
19
|
-
`;
|
|
20
|
-
// A browser cannot start the cli: the page says how to sign in. The desktop catches the link first.
|
|
21
|
-
export const signInPage = (_req, res) => {
|
|
22
|
-
res
|
|
23
|
-
.status(200)
|
|
24
|
-
.set({
|
|
25
|
-
'Content-Type': 'text/html; charset=utf-8',
|
|
26
|
-
'Cache-Control': 'no-store',
|
|
27
|
-
'Content-Security-Policy': "default-src 'none'; style-src 'unsafe-inline'",
|
|
28
|
-
})
|
|
29
|
-
.send(PAGE);
|
|
30
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type ExtensionPackage } from '../../manifest/manifest.schema.js';
|
|
2
|
-
export declare const assertSecrets: (pkg: ExtensionPackage, secrets: Record<string, string>) => void;
|
|
3
|
-
export declare const needsSecret: (err: unknown) => boolean;
|
|
4
|
-
export declare const healthy: (port: number, ms: number) => Promise<void>;
|
|
5
|
-
export declare const maskedForms: (secrets: Record<string, string>) => string[];
|
|
6
|
-
export declare const redact: (text: string, secrets: Record<string, string>) => string;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {} from '../../manifest/manifest.schema.js';
|
|
2
|
-
import { hostParts, mountedIn } from '../../manifest/parts.js';
|
|
3
|
-
const NEEDS_SECRET = 'NEEDS_SECRET';
|
|
4
|
-
// C6: a declared secret of a server part with no value; the daemon checks it before the fork.
|
|
5
|
-
export const assertSecrets = (pkg, secrets) => {
|
|
6
|
-
const names = new Set(hostParts(pkg).flatMap((part) => mountedIn(pkg, part)));
|
|
7
|
-
const missing = [...names].find((name) => !secrets[name]);
|
|
8
|
-
if (missing)
|
|
9
|
-
throw Object.assign(new Error(`needs secret ${missing}`), { code: NEEDS_SECRET });
|
|
10
|
-
};
|
|
11
|
-
export const needsSecret = (err) => err?.code === NEEDS_SECRET;
|
|
12
|
-
// Healthy before it gets the route: the child's own /health answers 200.
|
|
13
|
-
export const healthy = async (port, ms) => {
|
|
14
|
-
const signal = AbortSignal.timeout(ms);
|
|
15
|
-
const res = await fetch(`http://127.0.0.1:${port}/health`, { signal }).catch((err) => {
|
|
16
|
-
if (err.name === 'TimeoutError')
|
|
17
|
-
throw new Error(`health did not answer in ${ms} ms`);
|
|
18
|
-
const cause = err.cause?.code ?? err.message;
|
|
19
|
-
throw new Error(`health could not be reached (${cause})`);
|
|
20
|
-
});
|
|
21
|
-
if (res.status !== 200)
|
|
22
|
-
throw new Error(`health answered ${res.status}`);
|
|
23
|
-
};
|
|
24
|
-
// Each value raw and as it shows inside a JSON log row (quotes, backslashes escaped).
|
|
25
|
-
export const maskedForms = (secrets) => [...new Set(Object.values(secrets).flatMap((v) => [v, JSON.stringify(v).slice(1, -1)]))]
|
|
26
|
-
.filter((value) => value.length >= 4)
|
|
27
|
-
.sort((a, b) => b.length - a.length);
|
|
28
|
-
// A secret value this child was given never reaches error, /health, the list or the log.
|
|
29
|
-
export const redact = (text, secrets) => maskedForms(secrets).reduce((out, value) => out.split(value).join('***'), text);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type Child, type Launch } from './child.js';
|
|
2
|
-
export interface Stopping {
|
|
3
|
-
signal: AbortSignal;
|
|
4
|
-
launching: Set<Promise<unknown>>;
|
|
5
|
-
children: Set<Child>;
|
|
6
|
-
}
|
|
7
|
-
export declare const stoppingOf: (signal: AbortSignal) => Stopping;
|
|
8
|
-
export declare const stopsNow: () => import("../../envelope/envelope.js").Failure;
|
|
9
|
-
export declare const launchUnlessStopping: (stopping: Stopping, launch: Launch) => Launch;
|
|
10
|
-
export declare const stopAll: (stopping: Stopping) => Promise<void>;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { fail } from '../../envelope/envelope.js';
|
|
2
|
-
import {} from './child.js';
|
|
3
|
-
export const stoppingOf = (signal) => ({
|
|
4
|
-
signal,
|
|
5
|
-
launching: new Set(),
|
|
6
|
-
children: new Set(),
|
|
7
|
-
});
|
|
8
|
-
export const stopsNow = () => fail('UNAVAILABLE', 'the daemon stops', { retryAfter: 5 });
|
|
9
|
-
const started = async (stopping, launch) => {
|
|
10
|
-
if (stopping.signal.aborted)
|
|
11
|
-
throw stopsNow();
|
|
12
|
-
const child = await launch();
|
|
13
|
-
stopping.children.add(child);
|
|
14
|
-
void child.exited.then(() => stopping.children.delete(child));
|
|
15
|
-
return child;
|
|
16
|
-
};
|
|
17
|
-
// No child outlives stop(): none starts once it began; stopAll waits for the ones in flight.
|
|
18
|
-
export const launchUnlessStopping = (stopping, launch) => (spec) => {
|
|
19
|
-
const run = started(stopping, () => launch(spec));
|
|
20
|
-
stopping.launching.add(run);
|
|
21
|
-
void run.catch(() => undefined).finally(() => stopping.launching.delete(run));
|
|
22
|
-
return run;
|
|
23
|
-
};
|
|
24
|
-
// After the drain of each route: a child still starting or swapping is stopped too.
|
|
25
|
-
export const stopAll = async (stopping) => {
|
|
26
|
-
await Promise.allSettled([...stopping.launching]);
|
|
27
|
-
await Promise.all([...stopping.children].map((child) => child.stop()));
|
|
28
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { type Log } from '../../log/log.js';
|
|
2
|
-
import { type Launch } from './child.js';
|
|
3
|
-
import { type CliUser } from './cli-user-watch.js';
|
|
4
|
-
import { type InstallEntry } from './installation.js';
|
|
5
|
-
import { type Lane } from './lane.js';
|
|
6
|
-
import { type Limits } from './limits.js';
|
|
7
|
-
import { type PendingChanges } from './pending.js';
|
|
8
|
-
import { type Queue } from './queue.js';
|
|
9
|
-
import { type Retry } from './restart.js';
|
|
10
|
-
import { type Stopping } from './stopping.js';
|
|
11
|
-
export interface InstallSpec {
|
|
12
|
-
id: string;
|
|
13
|
-
version?: string;
|
|
14
|
-
signal?: AbortSignal;
|
|
15
|
-
}
|
|
16
|
-
export type Installer = (spec: InstallSpec) => Promise<{
|
|
17
|
-
id: string;
|
|
18
|
-
version: string;
|
|
19
|
-
dir: string;
|
|
20
|
-
}>;
|
|
21
|
-
export type State = 'starting' | 'running' | 'failed' | 'disabled';
|
|
22
|
-
export interface Entry {
|
|
23
|
-
id: string;
|
|
24
|
-
install: InstallEntry;
|
|
25
|
-
state: State;
|
|
26
|
-
version: string;
|
|
27
|
-
dir?: string;
|
|
28
|
-
error?: string;
|
|
29
|
-
lane?: Lane;
|
|
30
|
-
gate?: Promise<void>;
|
|
31
|
-
exits?: number[];
|
|
32
|
-
restarts?: number;
|
|
33
|
-
retry?: Retry;
|
|
34
|
-
}
|
|
35
|
-
export interface Values {
|
|
36
|
-
settings: Record<string, unknown>;
|
|
37
|
-
secrets: Record<string, string>;
|
|
38
|
-
}
|
|
39
|
-
export interface Next {
|
|
40
|
-
install: InstallEntry;
|
|
41
|
-
values: Values;
|
|
42
|
-
dir?: string;
|
|
43
|
-
}
|
|
44
|
-
export interface SupervisorDeps extends Limits {
|
|
45
|
-
configDir: string;
|
|
46
|
-
launch: Launch;
|
|
47
|
-
origin: () => string;
|
|
48
|
-
install?: Installer;
|
|
49
|
-
log: Log;
|
|
50
|
-
queue: Queue;
|
|
51
|
-
pending: PendingChanges;
|
|
52
|
-
stopping: Stopping;
|
|
53
|
-
unsynced: Set<string>;
|
|
54
|
-
user: CliUser;
|
|
55
|
-
}
|
|
56
|
-
export declare const valuesOf: (configDir: string, id: string) => Promise<Values>;
|
|
57
|
-
export declare const startEntry: (deps: SupervisorDeps, entry: Entry, fresh?: boolean) => Promise<Error | undefined>;
|
|
58
|
-
export declare const startFailed: (entry: Entry, err: unknown) => import("../../envelope/envelope.js").Failure;
|
|
59
|
-
export declare const swap: (deps: SupervisorDeps, entry: Entry, to: Next, undo?: () => Promise<unknown>) => Promise<void>;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { fail } from '../../envelope/envelope.js';
|
|
2
|
-
import {} from '../../log/log.js';
|
|
3
|
-
import { readManifest } from '../../manifest/read-manifest.js';
|
|
4
|
-
import {} from './child.js';
|
|
5
|
-
import {} from './cli-user-watch.js';
|
|
6
|
-
import { dataDirOf, readValues } from './daemon-files.js';
|
|
7
|
-
import {} from './installation.js';
|
|
8
|
-
import { halt } from './gate.js';
|
|
9
|
-
import { laneOf } from './lane.js';
|
|
10
|
-
import {} from './limits.js';
|
|
11
|
-
import { runInstaller } from './installer-call.js';
|
|
12
|
-
import {} from './pending.js';
|
|
13
|
-
import {} from './queue.js';
|
|
14
|
-
import { crashed, healthyFor, reasonOf, resetRestarts } from './restart.js';
|
|
15
|
-
import { assertSecrets, healthy, redact } from './start-checks.js';
|
|
16
|
-
import {} from './stopping.js';
|
|
17
|
-
export const valuesOf = async (configDir, id) => ({
|
|
18
|
-
settings: await readValues(configDir, 'settings', id),
|
|
19
|
-
secrets: (await readValues(configDir, 'secrets', id)),
|
|
20
|
-
});
|
|
21
|
-
// The package folder: the source itself, the folder an install gave, or the installer again.
|
|
22
|
-
const dirOf = async (deps, entry, install, given) => {
|
|
23
|
-
if (given)
|
|
24
|
-
return given;
|
|
25
|
-
if (install.source)
|
|
26
|
-
return install.source;
|
|
27
|
-
if (entry.dir && install.version === entry.install.version)
|
|
28
|
-
return entry.dir;
|
|
29
|
-
return (await runInstaller(deps, { id: entry.id, version: install.version })).dir;
|
|
30
|
-
};
|
|
31
|
-
// A new child for to, healthy, then the route; fresh: a start the owner asked for (restarts reset).
|
|
32
|
-
const launchFor = async (deps, entry, to, fresh) => {
|
|
33
|
-
const dir = await dirOf(deps, entry, to.install, to.dir);
|
|
34
|
-
const pkg = await readManifest(dir);
|
|
35
|
-
assertSecrets(pkg, to.values.secrets);
|
|
36
|
-
const spec = { id: entry.id, dir, dataDir: dataDirOf(deps.configDir, entry.id), ...to.values };
|
|
37
|
-
const child = await deps
|
|
38
|
-
.launch({ ...spec, origin: deps.origin(), storeOpenMs: deps.healthMs, userSub: deps.user.sub })
|
|
39
|
-
.catch((err) => Promise.reject(Object.assign(err, { message: redact(err.message, to.values.secrets) })));
|
|
40
|
-
await healthy(child.port, deps.healthMs).catch(async (err) => {
|
|
41
|
-
await child.stop();
|
|
42
|
-
throw err;
|
|
43
|
-
});
|
|
44
|
-
const lane = laneOf(child);
|
|
45
|
-
Object.assign(entry, { dir, version: pkg.version, lane, state: 'running', error: undefined });
|
|
46
|
-
if (fresh)
|
|
47
|
-
resetRestarts(entry);
|
|
48
|
-
// Watched only once it is the route: an exit that came before this line is seen, not lost.
|
|
49
|
-
const words = (how) => redact(reasonOf(how), to.values.secrets);
|
|
50
|
-
void child.exited.then((how) => exitedEarly(deps, entry, lane, words(how)));
|
|
51
|
-
healthyFor(deps, entry, lane);
|
|
52
|
-
};
|
|
53
|
-
// A child that exits while it is the route restarts (C6); a retired one was detached first.
|
|
54
|
-
const exitedEarly = (deps, entry, lane, why) => {
|
|
55
|
-
if (entry.lane !== lane)
|
|
56
|
-
return;
|
|
57
|
-
entry.lane = undefined;
|
|
58
|
-
crashed(deps, entry, why, () => restartEntry(deps, entry));
|
|
59
|
-
};
|
|
60
|
-
const failed = (deps, entry, err) => {
|
|
61
|
-
Object.assign(entry, { state: 'failed', error: err.message });
|
|
62
|
-
deps.log.warn('extension failed to start', { id: entry.id, reason: entry.error });
|
|
63
|
-
};
|
|
64
|
-
// The install and values of installation.json, as they are on disk; the error when it failed.
|
|
65
|
-
export const startEntry = async (deps, entry, fresh = false) => {
|
|
66
|
-
entry.state = 'starting';
|
|
67
|
-
try {
|
|
68
|
-
const values = await valuesOf(deps.configDir, entry.id);
|
|
69
|
-
await launchFor(deps, entry, { install: entry.install, values }, fresh);
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
73
|
-
failed(deps, entry, err);
|
|
74
|
-
return err;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
// A restart that does not start counts as one more exit.
|
|
78
|
-
const restartEntry = async (deps, entry) => {
|
|
79
|
-
const err = await startEntry(deps, entry);
|
|
80
|
-
if (err)
|
|
81
|
-
crashed(deps, entry, err.message, () => restartEntry(deps, entry));
|
|
82
|
-
};
|
|
83
|
-
// The old install again after a refused change; a disabled one stays stopped.
|
|
84
|
-
const restore = async (deps, entry) => {
|
|
85
|
-
if (entry.install.enabled === false)
|
|
86
|
-
entry.state = 'disabled';
|
|
87
|
-
else
|
|
88
|
-
await startEntry(deps, entry);
|
|
89
|
-
};
|
|
90
|
-
// C6: the envelope of a refused start; reason is the child's own words.
|
|
91
|
-
export const startFailed = (entry, err) => {
|
|
92
|
-
const reason = err.message;
|
|
93
|
-
const details = { code: 'START_FAILED', reason };
|
|
94
|
-
return fail('VALIDATION_ERROR', `${entry.id} failed to start: ${reason}`, { details });
|
|
95
|
-
};
|
|
96
|
-
// One writer per data folder (the caller holds the gate): stop the old child, start the new one.
|
|
97
|
-
export const swap = async (deps, entry, to, undo = async () => undefined) => {
|
|
98
|
-
try {
|
|
99
|
-
await halt(entry, deps.drainMs);
|
|
100
|
-
await launchFor(deps, entry, to, true);
|
|
101
|
-
}
|
|
102
|
-
catch (err) {
|
|
103
|
-
await undo();
|
|
104
|
-
await restore(deps, entry);
|
|
105
|
-
throw startFailed(entry, err);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type InstallEntry } from './installation.js';
|
|
2
|
-
import { type SupervisorDeps, type Values } from './supervisor.js';
|
|
3
|
-
export interface Written {
|
|
4
|
-
install?: InstallEntry;
|
|
5
|
-
values?: Values;
|
|
6
|
-
}
|
|
7
|
-
export declare const unsynced: (deps: SupervisorDeps, id: string) => void;
|
|
8
|
-
export declare const writeAll: (deps: SupervisorDeps, id: string, to: Written, was?: Written) => Promise<void>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { writeValues } from './daemon-files.js';
|
|
2
|
-
import { persist } from './entries.js';
|
|
3
|
-
import {} from './installation.js';
|
|
4
|
-
import {} from './supervisor.js';
|
|
5
|
-
const stepsOf = (deps, id, to, was) => {
|
|
6
|
-
// An empty object is no row: what valuesOf reads for an id the file does not name.
|
|
7
|
-
const values = (kind, v) => () => {
|
|
8
|
-
const rows = v?.[kind];
|
|
9
|
-
return writeValues(deps.configDir, kind, id, rows && Object.keys(rows).length ? rows : undefined, deps.lockMs);
|
|
10
|
-
};
|
|
11
|
-
const steps = [
|
|
12
|
-
[() => persist(deps, id, to.install), () => persist(deps, id, was.install)],
|
|
13
|
-
[values('settings', to.values), values('settings', was.values)],
|
|
14
|
-
// Last: a failed write before it leaves secrets.json as it was.
|
|
15
|
-
[values('secrets', to.values), values('secrets', was.values)],
|
|
16
|
-
];
|
|
17
|
-
// A remove deletes the secrets first: a crash half way leaves none for a later install of id.
|
|
18
|
-
return to.install ? steps : steps.reverse();
|
|
19
|
-
};
|
|
20
|
-
// An undo that failed leaves the files of id unlike the list: one warn line, and /health names it.
|
|
21
|
-
export const unsynced = (deps, id) => {
|
|
22
|
-
deps.unsynced.add(id);
|
|
23
|
-
deps.log.warn('a failed write could not be undone: the daemon files may not match the list', {
|
|
24
|
-
id,
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
// installation.json, settings.json, secrets.json in turn; a failed one undoes those written before it.
|
|
28
|
-
export const writeAll = async (deps, id, to, was = {}) => {
|
|
29
|
-
const done = [];
|
|
30
|
-
try {
|
|
31
|
-
for (const [run, undo] of stepsOf(deps, id, to, was)) {
|
|
32
|
-
await run();
|
|
33
|
-
done.unshift(undo);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
let lost = false;
|
|
38
|
-
for (const undo of done)
|
|
39
|
-
await undo().catch(() => (lost = true));
|
|
40
|
-
if (lost)
|
|
41
|
-
unsynced(deps, id);
|
|
42
|
-
throw err;
|
|
43
|
-
}
|
|
44
|
-
deps.unsynced.delete(id);
|
|
45
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'sha256-rPnVQ9IYe8CdsZZF35pNR4JDk/fH7Uqv6mzmCnCCky8=' 'sha256-lofENefBf5fETbin4TmrCuvlqGNlwIr9jsrkSYCOq+c=' 'sha256-ZowhplWzFwaUWeLf0FFjuCiJ6T38qHnoSSn0bfCSIG4='; style-src 'self'; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'" />
|
|
5
|
-
<meta charset="utf-8" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
-
<meta name="agentage-shell" content="0.20.1" />
|
|
8
|
-
<title>agentage</title>
|
|
9
|
-
<script>
|
|
10
|
-
try {
|
|
11
|
-
var d = document.documentElement,
|
|
12
|
-
L = localStorage,
|
|
13
|
-
g = function (k, a, b) {
|
|
14
|
-
var n = parseInt(L.getItem(k), 10);
|
|
15
|
-
return n >= a && n <= b ? n : 0;
|
|
16
|
-
};
|
|
17
|
-
var w = g('ag.nav', 232, 420),
|
|
18
|
-
a = g('ag.aside', 280, 640),
|
|
19
|
-
b = g('ag.bot', 100, 420),
|
|
20
|
-
t = g('ag.side', 200, 420);
|
|
21
|
-
if (w) d.style.setProperty('--nav-full', w + 'px');
|
|
22
|
-
if (a) d.style.setProperty('--aside-w', a + 'px');
|
|
23
|
-
if (b) d.style.setProperty('--bot-h', b + 'px');
|
|
24
|
-
if (t) d.style.setProperty('--side-w', t + 'px');
|
|
25
|
-
if (L.getItem('ag.navh') === '1') d.classList.add('nh');
|
|
26
|
-
if (L.getItem('ag.bot.open') === '1') d.classList.add('bo');
|
|
27
|
-
} catch (e) {}
|
|
28
|
-
</script>
|
|
29
|
-
<script>
|
|
30
|
-
try{var d=document.documentElement,L=localStorage,E=function(k){return k.replace(/[^A-Za-z0-9-]/g,function(c){return '_'+c.charCodeAt(0).toString(16)+'_'})};for(var i=0;i<L.length;i++){var k=L.key(i),m=/^ag\.split\.[a-z0-9-]+\.[a-z0-9-]+$/.test(k),n=parseInt(L.getItem(k),10);if(m&&n>0&&n<8000)d.style.setProperty('--split-'+E(k),n+'px');if(m&&L.getItem(k+'.collapsed')==='1')d.style.setProperty('--splitc-'+E(k),'0px')}}catch(e){}
|
|
31
|
-
</script>
|
|
32
|
-
<script type="importmap">
|
|
33
|
-
{
|
|
34
|
-
"imports": {
|
|
35
|
-
"react": "/shell/vendor/react.js",
|
|
36
|
-
"react/jsx-runtime": "/shell/vendor/jsx-runtime.js",
|
|
37
|
-
"react-dom": "/shell/vendor/react-dom.js",
|
|
38
|
-
"react-dom/client": "/shell/vendor/react-dom-client.js",
|
|
39
|
-
"@agentage/extension/app": "/shell/vendor/app.js"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
</script>
|
|
43
|
-
<link rel="stylesheet" href="/shell/shell.css" />
|
|
44
|
-
<script type="module" src="/shell/shell.js"></script>
|
|
45
|
-
</head>
|
|
46
|
-
<body>
|
|
47
|
-
<div id="root"></div>
|
|
48
|
-
</body>
|
|
49
|
-
</html>
|