@powerhousedao/clint 6.2.3-dev.57 → 6.2.3-dev.59

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.
Files changed (28) hide show
  1. package/dist/{build-skills-C1Vr_kQh.mjs → build-skills-C8MlDvTC.mjs} +3 -3
  2. package/dist/{build-skills-C1Vr_kQh.mjs.map → build-skills-C8MlDvTC.mjs.map} +1 -1
  3. package/dist/{events-DkzJFZeW.mjs → events-BnwGFTjv.mjs} +2 -2
  4. package/dist/{events-DkzJFZeW.mjs.map → events-BnwGFTjv.mjs.map} +1 -1
  5. package/dist/index.mjs +6 -4
  6. package/dist/{markdown-C1TFXoB6.mjs → markdown-D-sP2zw_.mjs} +2 -2
  7. package/dist/{markdown-C1TFXoB6.mjs.map → markdown-D-sP2zw_.mjs.map} +1 -1
  8. package/dist/proxy-BFR8GScT.mjs +302 -0
  9. package/dist/proxy-BFR8GScT.mjs.map +1 -0
  10. package/dist/proxy-routes-DP3ztsnS.mjs +215 -0
  11. package/dist/proxy-routes-DP3ztsnS.mjs.map +1 -0
  12. package/dist/runners/clint-runner.d.mts +46 -2
  13. package/dist/runners/clint-runner.d.mts.map +1 -1
  14. package/dist/runners/clint-runner.mjs +81 -3
  15. package/dist/runners/clint-runner.mjs.map +1 -1
  16. package/dist/runners/mastra-runner.d.mts +46 -1
  17. package/dist/runners/mastra-runner.d.mts.map +1 -1
  18. package/dist/runners/mastra-runner.mjs +6 -2
  19. package/dist/runners/mastra-runner.mjs.map +1 -1
  20. package/dist/{services-BvLvP5Qh.mjs → services-9E-r0nWl.mjs} +3 -214
  21. package/dist/services-9E-r0nWl.mjs.map +1 -0
  22. package/dist/{src-DRDGtXYJ.mjs → src-v5f_WnlY.mjs} +8 -302
  23. package/dist/src-v5f_WnlY.mjs.map +1 -0
  24. package/dist/{start-CKRhuB1Y.mjs → start-b7Mn2cxB.mjs} +3 -3
  25. package/dist/{start-CKRhuB1Y.mjs.map → start-b7Mn2cxB.mjs.map} +1 -1
  26. package/package.json +15 -15
  27. package/dist/services-BvLvP5Qh.mjs.map +0 -1
  28. package/dist/src-DRDGtXYJ.mjs.map +0 -1
@@ -1,6 +1,8 @@
1
- import { C as slugToTitle, S as getSchemaFields, _ as supervisedSpawnOptions, a as scanProjects, d as deriveBasePath, g as killTree, h as resolveImplicitProxyRoot, l as buildSwitchboardRoutes, m as prefixMatches, n as defineService, o as buildServiceRoutes, p as normalizeLoopbackHost, r as resolveServiceName, s as buildSwitchboardProxyUrls, t as createServiceManager, v as checkCommand, x as isPortFree, y as checkPort } from "./services-BvLvP5Qh.mjs";
2
- import { a as getGhostSuggestion, i as getCompletions, o as formatStreamChunk, r as getCompletionSuffix, t as renderMarkdown } from "./markdown-C1TFXoB6.mjs";
3
- import { n as createServiceCommands, t as createEventBus } from "./events-DkzJFZeW.mjs";
1
+ import { a as scanProjects, c as checkCommand, d as isPortFree, f as getSchemaFields, l as checkPort, n as defineService, o as killTree, p as slugToTitle, r as resolveServiceName, s as supervisedSpawnOptions, t as createServiceManager } from "./services-9E-r0nWl.mjs";
2
+ import { a as getGhostSuggestion, i as getCompletions, o as formatStreamChunk, r as getCompletionSuffix, t as renderMarkdown } from "./markdown-D-sP2zw_.mjs";
3
+ import { i as buildSwitchboardRoutes, n as buildSwitchboardProxyUrls, o as deriveBasePath, t as buildServiceRoutes, u as resolveImplicitProxyRoot } from "./proxy-routes-DP3ztsnS.mjs";
4
+ import { n as createServiceCommands, t as createEventBus } from "./events-BnwGFTjv.mjs";
5
+ import { t as createProxyServer } from "./proxy-BFR8GScT.mjs";
4
6
  import "./reactor-C9VIUX1H.mjs";
5
7
  import "./switchboard-DAS-5x53.mjs";
6
8
  import "./folders-mLL9D5Ck.mjs";
@@ -15,8 +17,6 @@ import crypto, { randomBytes, randomUUID } from "node:crypto";
15
17
  import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
16
18
  import { homedir } from "node:os";
17
19
  import Handlebars from "handlebars";
18
- import http from "node:http";
19
- import httpProxy from "http-proxy";
20
20
  //#region src/core/pkg.ts
21
21
  /**
22
22
  * Read CLI identity from the implementation project's package.json.
@@ -2162,300 +2162,6 @@ function createReplSession(opts) {
2162
2162
  return session;
2163
2163
  }
2164
2164
  //#endregion
2165
- //#region src/core/proxy.ts
2166
- /**
2167
- * Embedded reverse proxy — exposes all service endpoints through a single port.
2168
- * Uses http-proxy for HTTP + WebSocket forwarding.
2169
- */
2170
- /**
2171
- * Compute the X-Forwarded-Prefix value to send upstream. `base` is the
2172
- * mount base path ('' | '/x') prepended so upstreams emitting absolute
2173
- * paths reconstruct the externally-visible prefix.
2174
- */
2175
- function computeForwardedPrefix(route, base) {
2176
- if (!route.upstream) return void 0;
2177
- const strip = (s) => s.replace(/\/$/, "");
2178
- const prefix = strip(route.prefix);
2179
- const upstreamPath = strip(route.upstream.pathname);
2180
- return base + (upstreamPath && prefix.endsWith(upstreamPath) ? prefix.slice(0, -upstreamPath.length) : prefix) || void 0;
2181
- }
2182
- function envMs(name, fallback) {
2183
- const raw = process.env[name];
2184
- if (!raw) return fallback;
2185
- const n = Number(raw);
2186
- return Number.isFinite(n) && n >= 0 ? n : fallback;
2187
- }
2188
- const DEFAULT_UPSTREAM_TIMEOUT_MS = 3e4;
2189
- const DEFAULT_INCOMING_TIMEOUT_MS = 6e4;
2190
- function splitUrl(url) {
2191
- const qIdx = url.indexOf("?");
2192
- return qIdx === -1 ? [url, ""] : [url.slice(0, qIdx), url.slice(qIdx)];
2193
- }
2194
- const DEFAULT_DRAIN_TIMEOUT_MS = 1e4;
2195
- /**
2196
- * Create and start an embedded reverse proxy server.
2197
- */
2198
- async function createProxyServer(options) {
2199
- const { host, logger } = options;
2200
- let routes = [];
2201
- let stopped = false;
2202
- const basePath = deriveBasePath(options.publicUrl);
2203
- function stripBase(pathname) {
2204
- if (!basePath) return pathname;
2205
- if (!prefixMatches(basePath, pathname)) return void 0;
2206
- return pathname === basePath ? "/" : pathname.slice(basePath.length);
2207
- }
2208
- function prefixRedirect(location) {
2209
- if (!basePath) return location;
2210
- if (!location.startsWith("/") || location.startsWith("//")) return location;
2211
- if (prefixMatches(basePath, location)) return location;
2212
- return basePath + location;
2213
- }
2214
- const upstreamAgent = new http.Agent({
2215
- keepAlive: true,
2216
- autoSelectFamily: false
2217
- });
2218
- const proxy = httpProxy.createProxyServer({
2219
- xfwd: true,
2220
- agent: upstreamAgent,
2221
- proxyTimeout: envMs("PH_PROXY_UPSTREAM_TIMEOUT_MS", DEFAULT_UPSTREAM_TIMEOUT_MS),
2222
- timeout: envMs("PH_PROXY_INCOMING_TIMEOUT_MS", DEFAULT_INCOMING_TIMEOUT_MS)
2223
- });
2224
- proxy.on("proxyRes", (proxyRes, _req, res) => {
2225
- if (!String(proxyRes.headers["content-type"] ?? "").toLowerCase().includes("text/event-stream")) return;
2226
- proxyRes.socket?.setTimeout(0);
2227
- res.socket?.setTimeout(0);
2228
- });
2229
- proxy.on("proxyRes", (proxyRes, _req, res) => {
2230
- const serverRes = res;
2231
- proxyRes.on("close", () => {
2232
- if (!proxyRes.readableEnded && !serverRes.writableEnded) serverRes.destroy();
2233
- });
2234
- });
2235
- proxy.on("proxyRes", (proxyRes) => {
2236
- const status = proxyRes.statusCode ?? 0;
2237
- if (status < 300 || status >= 400) return;
2238
- const location = proxyRes.headers.location;
2239
- if (typeof location !== "string") return;
2240
- proxyRes.headers.location = prefixRedirect(location);
2241
- });
2242
- proxy.on("error", (err, req, res) => {
2243
- logger.warn(`Proxy error for ${req.url}: ${err.message}`);
2244
- const code = err.code;
2245
- const status = code === "ETIMEDOUT" || code === "ECONNRESET" ? 504 : 502;
2246
- const message = status === 504 ? "Gateway Timeout" : "Bad Gateway";
2247
- if (res && "writeHead" in res) {
2248
- const serverRes = res;
2249
- if (!serverRes.headersSent && serverRes.writable) {
2250
- serverRes.writeHead(status, { "Content-Type": "application/json" });
2251
- serverRes.end(JSON.stringify({
2252
- error: message,
2253
- message: err.message
2254
- }));
2255
- } else if (!serverRes.writableEnded) serverRes.end();
2256
- } else if (res && "destroy" in res) res.destroy();
2257
- });
2258
- function matchRoute(pathname) {
2259
- for (const route of routes) if (route.exact && pathname === route.prefix) return route;
2260
- for (const route of routes) {
2261
- if (route.exact) continue;
2262
- if (prefixMatches(route.prefix, pathname)) return route;
2263
- }
2264
- }
2265
- function sortRoutes() {
2266
- routes.sort((a, b) => b.prefix.length - a.prefix.length);
2267
- }
2268
- function rewriteTarget(route, upstream, requestPath) {
2269
- const suffix = requestPath.slice(route.prefix.length);
2270
- const upstreamPath = upstream.pathname;
2271
- if (upstreamPath.endsWith("/") && suffix.startsWith("/")) return upstreamPath + suffix.slice(1);
2272
- if (!upstreamPath.endsWith("/") && suffix.length > 0 && !suffix.startsWith("/")) return upstreamPath + "/" + suffix;
2273
- return upstreamPath + suffix;
2274
- }
2275
- const server = http.createServer((req, res) => {
2276
- const [rawPath, query] = splitUrl(req.url ?? "/");
2277
- const stripped = stripBase(rawPath);
2278
- if (stripped === void 0) {
2279
- res.writeHead(404, { "Content-Type": "application/json" });
2280
- res.end(JSON.stringify({
2281
- error: "Not Found",
2282
- path: rawPath
2283
- }));
2284
- return;
2285
- }
2286
- const pathname = stripped;
2287
- if (pathname === "/_proxy/health") {
2288
- res.writeHead(200, { "Content-Type": "application/json" });
2289
- res.end(JSON.stringify({
2290
- ok: true,
2291
- routes: routes.length
2292
- }));
2293
- return;
2294
- }
2295
- if (pathname === "/_proxy/routes") {
2296
- res.writeHead(200, { "Content-Type": "application/json" });
2297
- res.end(JSON.stringify(routes.map((r) => ({
2298
- prefix: r.prefix,
2299
- upstream: r.upstream?.toString(),
2300
- ws: r.ws,
2301
- source: r.source,
2302
- ...r.redirectTo ? { redirectTo: r.redirectTo } : {},
2303
- ...r.exact ? { exact: true } : {}
2304
- }))));
2305
- return;
2306
- }
2307
- const route = matchRoute(pathname);
2308
- if (!route) {
2309
- res.writeHead(404, { "Content-Type": "application/json" });
2310
- res.end(JSON.stringify({
2311
- error: "Not Found",
2312
- path: pathname
2313
- }));
2314
- return;
2315
- }
2316
- if (route.redirectTo) {
2317
- res.writeHead(302, { Location: prefixRedirect(route.redirectTo) + query });
2318
- res.end();
2319
- return;
2320
- }
2321
- if (!route.upstream) {
2322
- res.writeHead(502, { "Content-Type": "application/json" });
2323
- res.end(JSON.stringify({
2324
- error: "Bad Gateway",
2325
- message: "route has no upstream"
2326
- }));
2327
- return;
2328
- }
2329
- const upstream = route.upstream;
2330
- const targetPath = rewriteTarget(route, upstream, pathname);
2331
- const target = `${upstream.protocol}//${normalizeLoopbackHost(upstream.host)}`;
2332
- const forwardedPrefix = computeForwardedPrefix(route, basePath);
2333
- if (forwardedPrefix) req.headers["x-forwarded-prefix"] = forwardedPrefix;
2334
- else delete req.headers["x-forwarded-prefix"];
2335
- req.url = (targetPath || "/") + query;
2336
- proxy.web(req, res, {
2337
- target,
2338
- changeOrigin: true
2339
- });
2340
- });
2341
- server.on("connection", (socket) => {
2342
- socket.on("error", (err) => {
2343
- logger.debug(`Proxy client socket error: ${err.message}`);
2344
- socket.destroy();
2345
- });
2346
- });
2347
- server.on("clientError", (err, socket) => {
2348
- logger.debug(`Proxy client error: ${err.message}`);
2349
- if (err.code !== "ECONNRESET" && socket.writable) {
2350
- socket.end("HTTP/1.1 400 Bad Request\r\n\r\n");
2351
- return;
2352
- }
2353
- socket.destroy();
2354
- });
2355
- const upgradeSockets = /* @__PURE__ */ new Set();
2356
- server.on("upgrade", (req, socket, head) => {
2357
- upgradeSockets.add(socket);
2358
- socket.on("close", () => upgradeSockets.delete(socket));
2359
- socket.on("error", (err) => {
2360
- logger.warn(`Proxy WS client socket error for ${req.url}: ${err.message}`);
2361
- socket.destroy();
2362
- });
2363
- const [rawPath, query] = splitUrl(req.url ?? "/");
2364
- const stripped = stripBase(rawPath);
2365
- if (stripped === void 0) {
2366
- socket.destroy();
2367
- return;
2368
- }
2369
- const pathname = stripped;
2370
- const route = matchRoute(pathname);
2371
- if (!route || !route.ws || !route.upstream) {
2372
- socket.destroy();
2373
- return;
2374
- }
2375
- const upstream = route.upstream;
2376
- const targetPath = rewriteTarget(route, upstream, pathname);
2377
- const target = `${upstream.protocol}//${normalizeLoopbackHost(upstream.host)}`;
2378
- const forwardedPrefix = computeForwardedPrefix(route, basePath);
2379
- if (forwardedPrefix) req.headers["x-forwarded-prefix"] = forwardedPrefix;
2380
- else delete req.headers["x-forwarded-prefix"];
2381
- req.url = (targetPath || "/") + query;
2382
- proxy.ws(req, socket, head, {
2383
- target,
2384
- changeOrigin: true
2385
- });
2386
- });
2387
- const assignedPort = await new Promise((resolve, reject) => {
2388
- server.on("error", reject);
2389
- server.listen(options.port, host, () => {
2390
- const addr = server.address();
2391
- resolve(typeof addr === "object" && addr ? addr.port : options.port);
2392
- });
2393
- });
2394
- const url = options.publicUrl?.trim().replace(/\/+$/, "") || `http://${host === "0.0.0.0" ? "localhost" : host}:${assignedPort}`;
2395
- return {
2396
- get port() {
2397
- return assignedPort;
2398
- },
2399
- get host() {
2400
- return host;
2401
- },
2402
- get url() {
2403
- return url;
2404
- },
2405
- addRoute(route) {
2406
- const sameMatch = (r) => r.prefix === route.prefix && !!r.exact === !!route.exact;
2407
- const ownIdx = routes.findIndex((r) => sameMatch(r) && r.source === route.source);
2408
- if (ownIdx !== -1) {
2409
- const prev = routes[ownIdx];
2410
- routes[ownIdx] = route;
2411
- const prevDest = prev.redirectTo ?? prev.upstream?.toString() ?? "(no upstream)";
2412
- const newDest = route.redirectTo ?? route.upstream?.toString() ?? "(no upstream)";
2413
- if (prevDest !== newDest) logger.warn(`Proxy route replaced: '${route.prefix}' (${route.source}) upstream ${prevDest} → ${newDest}`);
2414
- } else {
2415
- const existing = routes.find(sameMatch);
2416
- if (existing) logger.warn(`Proxy route conflict: '${route.prefix}'${route.exact ? " (exact)" : ""} already registered by ${existing.source}; route from ${route.source} will be shadowed`);
2417
- routes.push(route);
2418
- sortRoutes();
2419
- }
2420
- const dest = route.redirectTo ? `redirect → ${route.redirectTo}` : route.upstream?.toString() ?? "(no upstream)";
2421
- logger.debug(`Proxy route added: ${route.prefix} → ${dest} (${route.source})`);
2422
- },
2423
- removeRoutesBySource(source) {
2424
- const before = routes.length;
2425
- routes = routes.filter((r) => r.source !== source);
2426
- const removed = before - routes.length;
2427
- if (removed > 0) logger.debug(`Proxy: removed ${removed} route(s) for source '${source}'`);
2428
- },
2429
- getRoutes() {
2430
- return routes;
2431
- },
2432
- async stop() {
2433
- if (stopped) return;
2434
- stopped = true;
2435
- const drainTimeout = envMs("PH_PROXY_DRAIN_TIMEOUT_MS", DEFAULT_DRAIN_TIMEOUT_MS);
2436
- const drained = new Promise((resolve) => {
2437
- server.close(() => resolve());
2438
- });
2439
- for (const socket of upgradeSockets) socket.destroy();
2440
- upgradeSockets.clear();
2441
- let timer;
2442
- const deadline = new Promise((resolve) => {
2443
- timer = setTimeout(() => {
2444
- logger.warn(`Proxy drain timed out after ${drainTimeout}ms; force-closing connections`);
2445
- server.closeAllConnections?.();
2446
- resolve();
2447
- }, drainTimeout);
2448
- timer.unref?.();
2449
- });
2450
- await Promise.race([drained, deadline]);
2451
- if (timer) clearTimeout(timer);
2452
- proxy.close();
2453
- upstreamAgent.destroy();
2454
- logger.debug("Proxy server stopped");
2455
- }
2456
- };
2457
- }
2458
- //#endregion
2459
2165
  //#region ../reactor-attachments/dist/switchboard-attachment-transport-BH3ZAmxE.js
2460
2166
  /**
2461
2167
  * Thrown when an attachment ref or hash is not known to the store.
@@ -4470,7 +4176,7 @@ function defineCli(options) {
4470
4176
  switch (mode) {
4471
4177
  case "interactive-terminal": {
4472
4178
  /* istanbul ignore next -- Ink REPL requires a real terminal */
4473
- const { startInkRepl } = await import("./start-CKRhuB1Y.mjs");
4179
+ const { startInkRepl } = await import("./start-b7Mn2cxB.mjs");
4474
4180
  /* istanbul ignore next */
4475
4181
  await startInkRepl(session, {
4476
4182
  services: context.services,
@@ -5056,6 +4762,6 @@ async function buildDefaultReactor(ctx, options) {
5056
4762
  return result;
5057
4763
  }
5058
4764
  //#endregion
5059
- export { createConfigCommand as A, createMemoryWorkdirStore as B, isSkillInvocation as C, readSkills as D, renderSkillTemplate as E, localConfigPath as F, createLogger as G, defaultPort as H, resolveConfig as I, readPackageInfo as J, formatZodError as K, toUpperSnake as L, resolveWorkdir as M, configKeyToEnvVar as N, installSkills as O, getMissingRequiredFields as P, userConfigPath as R, createSkillCommands as S, registerDefaultHelpers as T, resolvePort as U, createWorkdirStore as V, resolveReactorDefaults as W, createRoutine as _, getProjectMapping as a, createProcessManager as b, defineTrigger as c, createProxyServer as d, createReplSession as f, createRoutineServiceAdapter as g, createCompositeServiceManager as h, defineRegistry as i, generateConfigCommandHelp as j, createHelpCommand as k, defineCli as l, tokenizeArgs as m, isDocType as n, createTypes as o, parseReplInput as p, defineCommand as q, deterministicId as r, createDocumentChangeTrigger as s, buildDefaultReactor as t, initLifecycle as u, IDENTITY_WRAPS as v, extractTemplateVars as w, DEFAULT_SKILL_INSTRUCTION as x, composeWraps as y, userStoreFolder as z };
4765
+ export { generateConfigCommandHelp as A, createWorkdirStore as B, extractTemplateVars as C, installSkills as D, readSkills as E, resolveConfig as F, formatZodError as G, resolvePort as H, toUpperSnake as I, defineCommand as K, userConfigPath as L, configKeyToEnvVar as M, getMissingRequiredFields as N, createHelpCommand as O, localConfigPath as P, userStoreFolder as R, isSkillInvocation as S, renderSkillTemplate as T, resolveReactorDefaults as U, defaultPort as V, createLogger as W, IDENTITY_WRAPS as _, getProjectMapping as a, DEFAULT_SKILL_INSTRUCTION as b, defineTrigger as c, createReplSession as d, parseReplInput as f, createRoutine as g, createRoutineServiceAdapter as h, defineRegistry as i, resolveWorkdir as j, createConfigCommand as k, defineCli as l, createCompositeServiceManager as m, isDocType as n, createTypes as o, tokenizeArgs as p, readPackageInfo as q, deterministicId as r, createDocumentChangeTrigger as s, buildDefaultReactor as t, initLifecycle as u, composeWraps as v, registerDefaultHelpers as w, createSkillCommands as x, createProcessManager as y, createMemoryWorkdirStore as z };
5060
4766
 
5061
- //# sourceMappingURL=src-DRDGtXYJ.mjs.map
4767
+ //# sourceMappingURL=src-v5f_WnlY.mjs.map