@hyperwindmill/caretaker-cli 0.32.0 → 0.34.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/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +9 -1
- package/dist/cli/web/api_access.d.ts +38 -0
- package/dist/cli/web/api_access.d.ts.map +1 -0
- package/dist/cli/web/api_access.js +125 -0
- package/dist/cli/web/openapi.d.ts +7 -0
- package/dist/cli/web/openapi.d.ts.map +1 -0
- package/dist/cli/web/openapi.js +489 -0
- package/dist/cli/web/scheduler/cycle_events.d.ts +8 -3
- package/dist/cli/web/scheduler/cycle_events.d.ts.map +1 -1
- package/dist/cli/web/scheduler/cycle_events.js +2 -0
- package/dist/cli/web/scheduler/email_triage.d.ts +8 -1
- package/dist/cli/web/scheduler/email_triage.d.ts.map +1 -1
- package/dist/cli/web/scheduler/email_triage.js +19 -4
- package/dist/cli/web/scheduler/email_triage_agent.d.ts.map +1 -1
- package/dist/cli/web/scheduler/email_triage_agent.js +1 -0
- package/dist/cli/web/scheduler/heartbeat.d.ts +1 -1
- package/dist/cli/web/scheduler/heartbeat.d.ts.map +1 -1
- package/dist/cli/web/scheduler/heartbeat.js +9 -5
- package/dist/cli/web/scheduler/service_runs.d.ts +12 -0
- package/dist/cli/web/scheduler/service_runs.d.ts.map +1 -0
- package/dist/cli/web/scheduler/service_runs.js +39 -0
- package/dist/cli/web/scheduler/task_review.d.ts +8 -0
- package/dist/cli/web/scheduler/task_review.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_review.js +17 -1
- package/dist/cli/web/scheduler/task_strategy.js +41 -14
- package/dist/cli/web/scheduler.d.ts +9 -0
- package/dist/cli/web/scheduler.d.ts.map +1 -1
- package/dist/cli/web/scheduler.js +24 -2
- package/dist/cli/web/server.d.ts +4 -1
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +67 -13
- package/dist/harness/tools/builtin/task_tools.d.ts.map +1 -1
- package/dist/harness/tools/builtin/task_tools.js +5 -17
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +2 -1
- package/dist/store/db.d.ts +12 -0
- package/dist/store/db.d.ts.map +1 -1
- package/dist/store/db.js +37 -0
- package/dist/store/json.d.ts +29 -0
- package/dist/store/json.d.ts.map +1 -1
- package/dist/store/json.js +54 -0
- package/dist/webview/standalone.js +1039 -768
- package/dist/webview/standalone.js.map +4 -4
- package/package.json +3 -3
package/dist/cli/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAgBA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAgBA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA6F1D"}
|
package/dist/cli/index.js
CHANGED
|
@@ -58,9 +58,17 @@ export async function runCli(argv) {
|
|
|
58
58
|
.description('Launch the Caretaker web server local-first GUI.')
|
|
59
59
|
.option('-p, --port <number>', 'Port to listen on', '3000')
|
|
60
60
|
.option('-h, --host <string>', 'Host to bind to', '127.0.0.1')
|
|
61
|
+
.option('--api-port <number>', 'Port of the token-authenticated API listener (overrides the one saved in the settings)')
|
|
62
|
+
.option('--api-host <string>', 'Host the API listener binds to (default: same as --host)')
|
|
61
63
|
.action(async (opts) => {
|
|
62
64
|
const { startServer } = await import('./web/server.js');
|
|
63
|
-
await
|
|
65
|
+
const { parsePort } = await import('./web/api_access.js');
|
|
66
|
+
const apiPort = opts.apiPort === undefined ? undefined : parsePort(opts.apiPort);
|
|
67
|
+
if (apiPort === null) {
|
|
68
|
+
console.error(`Invalid --api-port "${opts.apiPort}".`);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
await startServer(parseInt(opts.port, 10), opts.host, { port: apiPort, host: opts.apiHost });
|
|
64
72
|
});
|
|
65
73
|
program
|
|
66
74
|
.command('mcp')
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Hono } from 'hono';
|
|
2
|
+
/**
|
|
3
|
+
* The authenticated API listener: a second port that serves the web server's
|
|
4
|
+
* REST routes to clients outside the browser, every request carrying
|
|
5
|
+
* `Authorization: Bearer <token>`.
|
|
6
|
+
*
|
|
7
|
+
* Authentication is decided by the port a request arrives on, never by where
|
|
8
|
+
* it comes from: the main port stays as it always was (the GUI, the WebSocket,
|
|
9
|
+
* no auth — loopback or behind an authenticating proxy), and this one always
|
|
10
|
+
* asks for a token, loopback included. That is what keeps it correct behind a
|
|
11
|
+
* reverse proxy or a Docker port mapping, where the peer address says nothing.
|
|
12
|
+
*/
|
|
13
|
+
type Fetch = (req: Request, ...rest: any[]) => Response | Promise<Response>;
|
|
14
|
+
export declare function bearerToken(header: string | null | undefined): string | null;
|
|
15
|
+
/** REST routes only. Left on the main port: the GUI and its WebSocket, the
|
|
16
|
+
* task MCP bridge (its own per-run tokens), and token management itself — a
|
|
17
|
+
* token must not be able to mint or revoke tokens. */
|
|
18
|
+
export declare function isApiPath(pathname: string): boolean;
|
|
19
|
+
/** Wraps the app's fetch for the API port. The token is checked first, so an
|
|
20
|
+
* unauthenticated caller learns nothing about which paths exist — apart from
|
|
21
|
+
* the two that describe the API (OPENAPI_PUBLIC_PATHS). */
|
|
22
|
+
export declare function guardApiFetch(appFetch: Fetch, verify?: (token: string) => Promise<boolean>): Fetch;
|
|
23
|
+
export declare function parsePort(value: unknown): number | null;
|
|
24
|
+
export interface ApiListenerOptions {
|
|
25
|
+
/** The main web port — the API listener refuses to share it. */
|
|
26
|
+
webPort: number;
|
|
27
|
+
host: string;
|
|
28
|
+
/** `--api-port`: wins over the port saved in api.json. */
|
|
29
|
+
portOverride?: number;
|
|
30
|
+
}
|
|
31
|
+
/** (Re)starts the listener on the configured port, or stops it when none is
|
|
32
|
+
* set. Never throws: a port already in use is reported in the status, and the
|
|
33
|
+
* web server keeps running. */
|
|
34
|
+
export declare function applyApiListener(app: Hono, opts: ApiListenerOptions): Promise<void>;
|
|
35
|
+
/** Token management, on the main port only (see isApiPath). */
|
|
36
|
+
export declare function registerApiAccess(app: Hono, opts: ApiListenerOptions): void;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=api_access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api_access.d.ts","sourceRoot":"","sources":["../../../src/cli/web/api_access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAWjC;;;;;;;;;;GAUG;AAEH,KAAK,KAAK,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE5E,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAG5E;AAED;;uDAEuD;AACvD,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGnD;AAED;;4DAE4D;AAC5D,wBAAgB,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAkB,GAAG,KAAK,CAsBlH;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAGvD;AAED,MAAM,WAAW,kBAAkB;IACjC,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAqBD;;gCAEgC;AAChC,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBzF;AAED,+DAA+D;AAC/D,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAuC3E"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { OPENAPI_PUBLIC_PATHS } from './openapi.js';
|
|
2
|
+
import { serve } from '@hono/node-server';
|
|
3
|
+
import { createApiToken, loadApiAccess, revokeApiToken, setApiPort, verifyApiToken, } from '../../store/json.js';
|
|
4
|
+
export function bearerToken(header) {
|
|
5
|
+
const m = /^Bearer\s+(\S+)\s*$/i.exec(header ?? '');
|
|
6
|
+
return m ? m[1] : null;
|
|
7
|
+
}
|
|
8
|
+
/** REST routes only. Left on the main port: the GUI and its WebSocket, the
|
|
9
|
+
* task MCP bridge (its own per-run tokens), and token management itself — a
|
|
10
|
+
* token must not be able to mint or revoke tokens. */
|
|
11
|
+
export function isApiPath(pathname) {
|
|
12
|
+
if (!pathname.startsWith('/api/'))
|
|
13
|
+
return false;
|
|
14
|
+
return !['/api/ws', '/api/mcp', '/api/access'].some((p) => pathname === p || pathname.startsWith(`${p}/`));
|
|
15
|
+
}
|
|
16
|
+
/** Wraps the app's fetch for the API port. The token is checked first, so an
|
|
17
|
+
* unauthenticated caller learns nothing about which paths exist — apart from
|
|
18
|
+
* the two that describe the API (OPENAPI_PUBLIC_PATHS). */
|
|
19
|
+
export function guardApiFetch(appFetch, verify = verifyApiToken) {
|
|
20
|
+
return async (req, ...rest) => {
|
|
21
|
+
const pathname = new URL(req.url).pathname;
|
|
22
|
+
// The API description carries no data and Swagger UI must load it before
|
|
23
|
+
// anyone can type a token.
|
|
24
|
+
if (req.method === 'GET' && OPENAPI_PUBLIC_PATHS.includes(pathname))
|
|
25
|
+
return appFetch(req, ...rest);
|
|
26
|
+
const token = bearerToken(req.headers.get('authorization'));
|
|
27
|
+
if (!token || !(await verify(token))) {
|
|
28
|
+
// One answer for a missing and a wrong token.
|
|
29
|
+
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
|
|
30
|
+
status: 401,
|
|
31
|
+
headers: { 'content-type': 'application/json', 'www-authenticate': 'Bearer' },
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (!isApiPath(pathname)) {
|
|
35
|
+
return new Response(JSON.stringify({ error: 'Not found' }), {
|
|
36
|
+
status: 404,
|
|
37
|
+
headers: { 'content-type': 'application/json' },
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return appFetch(req, ...rest);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function parsePort(value) {
|
|
44
|
+
const n = typeof value === 'string' && value.trim() ? Number(value) : value;
|
|
45
|
+
return typeof n === 'number' && Number.isInteger(n) && n >= 1 && n <= 65535 ? n : null;
|
|
46
|
+
}
|
|
47
|
+
let server = null;
|
|
48
|
+
let state = null;
|
|
49
|
+
const closeServer = () => new Promise((resolve) => {
|
|
50
|
+
if (!server)
|
|
51
|
+
return resolve();
|
|
52
|
+
const s = server;
|
|
53
|
+
server = null;
|
|
54
|
+
s.close(() => resolve());
|
|
55
|
+
// Keep-alive connections would otherwise hold close() open.
|
|
56
|
+
s.closeAllConnections?.();
|
|
57
|
+
});
|
|
58
|
+
/** (Re)starts the listener on the configured port, or stops it when none is
|
|
59
|
+
* set. Never throws: a port already in use is reported in the status, and the
|
|
60
|
+
* web server keeps running. */
|
|
61
|
+
export async function applyApiListener(app, opts) {
|
|
62
|
+
await closeServer();
|
|
63
|
+
state = null;
|
|
64
|
+
const port = opts.portOverride ?? (await loadApiAccess()).port;
|
|
65
|
+
if (!port)
|
|
66
|
+
return;
|
|
67
|
+
if (port === opts.webPort) {
|
|
68
|
+
state = { port, host: opts.host, error: 'The API port must differ from the web port.' };
|
|
69
|
+
console.error(`[api] ${state.error}`);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const current = { port, host: opts.host };
|
|
73
|
+
state = current;
|
|
74
|
+
await new Promise((resolve) => {
|
|
75
|
+
const s = serve({ fetch: guardApiFetch(app.fetch), port, hostname: opts.host }, () => {
|
|
76
|
+
console.log(`🔑 Caretaker API (token required) at http://${opts.host}:${port}`);
|
|
77
|
+
resolve();
|
|
78
|
+
});
|
|
79
|
+
s.on('error', (err) => {
|
|
80
|
+
current.error = err.message;
|
|
81
|
+
if (server === s)
|
|
82
|
+
server = null;
|
|
83
|
+
console.error(`[api] listener on ${opts.host}:${port} failed: ${err.message}`);
|
|
84
|
+
resolve();
|
|
85
|
+
});
|
|
86
|
+
server = s;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** Token management, on the main port only (see isApiPath). */
|
|
90
|
+
export function registerApiAccess(app, opts) {
|
|
91
|
+
const status = async () => {
|
|
92
|
+
const access = await loadApiAccess();
|
|
93
|
+
return {
|
|
94
|
+
port: access.port ?? null,
|
|
95
|
+
portOverride: opts.portOverride ?? null,
|
|
96
|
+
listener: state,
|
|
97
|
+
tokens: access.tokens.map(({ id, name, createdAt }) => ({ id, name, createdAt })),
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
app.get('/api/access', async (c) => c.json(await status()));
|
|
101
|
+
app.put('/api/access/port', async (c) => {
|
|
102
|
+
const body = await c.req.json().catch(() => null);
|
|
103
|
+
const raw = body?.port;
|
|
104
|
+
const port = raw === null || raw === '' ? null : parsePort(raw);
|
|
105
|
+
if (raw !== null && raw !== '' && port === null) {
|
|
106
|
+
return c.json({ error: 'port must be an integer between 1 and 65535, or null to turn the API off.' }, 400);
|
|
107
|
+
}
|
|
108
|
+
if (port !== null && port === opts.webPort) {
|
|
109
|
+
return c.json({ error: 'The API port must differ from the web port.' }, 400);
|
|
110
|
+
}
|
|
111
|
+
await setApiPort(port);
|
|
112
|
+
await applyApiListener(app, opts);
|
|
113
|
+
return c.json(await status());
|
|
114
|
+
});
|
|
115
|
+
app.post('/api/access/tokens', async (c) => {
|
|
116
|
+
const body = await c.req.json().catch(() => null);
|
|
117
|
+
const name = typeof body?.name === 'string' ? body.name.slice(0, 80) : '';
|
|
118
|
+
const { token } = await createApiToken(name);
|
|
119
|
+
return c.json({ token, ...(await status()) });
|
|
120
|
+
});
|
|
121
|
+
app.delete('/api/access/tokens/:id', async (c) => {
|
|
122
|
+
await revokeApiToken(c.req.param('id'));
|
|
123
|
+
return c.json(await status());
|
|
124
|
+
});
|
|
125
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Hono } from 'hono';
|
|
2
|
+
export declare function openApiDocument(version: string): Record<string, unknown>;
|
|
3
|
+
/** Routes that describe the API rather than expose data: served without a
|
|
4
|
+
* token on the API port too, or Swagger UI's Authorize could never load. */
|
|
5
|
+
export declare const OPENAPI_PUBLIC_PATHS: string[];
|
|
6
|
+
export declare function registerOpenApi(app: Hono): void;
|
|
7
|
+
//# sourceMappingURL=openapi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../src/cli/web/openapi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AA2cjC,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoBxE;AAED;6EAC6E;AAC7E,eAAO,MAAM,oBAAoB,UAAqC,CAAC;AAmCvE,wBAAgB,eAAe,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAI/C"}
|