@a5c-ai/genty-runtime 5.1.1-staging.0ad6ac75ae4a
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 +69 -0
- package/dist/apiResult.d.ts +19 -0
- package/dist/apiResult.d.ts.map +1 -0
- package/dist/apiResult.js +16 -0
- package/dist/background/state.d.ts +20 -0
- package/dist/background/state.d.ts.map +1 -0
- package/dist/background/state.js +52 -0
- package/dist/backgroundProcessRegistry.d.ts +124 -0
- package/dist/backgroundProcessRegistry.d.ts.map +1 -0
- package/dist/backgroundProcessRegistry.js +427 -0
- package/dist/cost/claudeCodeParser.d.ts +81 -0
- package/dist/cost/claudeCodeParser.d.ts.map +1 -0
- package/dist/cost/claudeCodeParser.js +232 -0
- package/dist/cost/collector.d.ts +42 -0
- package/dist/cost/collector.d.ts.map +1 -0
- package/dist/cost/collector.js +105 -0
- package/dist/cost/effectCost.d.ts +23 -0
- package/dist/cost/effectCost.d.ts.map +1 -0
- package/dist/cost/effectCost.js +26 -0
- package/dist/cost/index.d.ts +19 -0
- package/dist/cost/index.d.ts.map +1 -0
- package/dist/cost/index.js +39 -0
- package/dist/cost/journal.d.ts +40 -0
- package/dist/cost/journal.d.ts.map +1 -0
- package/dist/cost/journal.js +137 -0
- package/dist/cost/types.d.ts +164 -0
- package/dist/cost/types.d.ts.map +1 -0
- package/dist/cost/types.js +228 -0
- package/dist/daemon/automationExecutor.d.ts +16 -0
- package/dist/daemon/automationExecutor.d.ts.map +1 -0
- package/dist/daemon/automationExecutor.js +222 -0
- package/dist/daemon/config.d.ts +8 -0
- package/dist/daemon/config.d.ts.map +1 -0
- package/dist/daemon/config.js +245 -0
- package/dist/daemon/daemonLog.d.ts +30 -0
- package/dist/daemon/daemonLog.d.ts.map +1 -0
- package/dist/daemon/daemonLog.js +140 -0
- package/dist/daemon/durableQueue.d.ts +41 -0
- package/dist/daemon/durableQueue.d.ts.map +1 -0
- package/dist/daemon/durableQueue.js +183 -0
- package/dist/daemon/fileWatcher.d.ts +9 -0
- package/dist/daemon/fileWatcher.d.ts.map +1 -0
- package/dist/daemon/fileWatcher.js +144 -0
- package/dist/daemon/index.d.ts +15 -0
- package/dist/daemon/index.d.ts.map +1 -0
- package/dist/daemon/index.js +25 -0
- package/dist/daemon/lifecycle.d.ts +13 -0
- package/dist/daemon/lifecycle.d.ts.map +1 -0
- package/dist/daemon/lifecycle.js +320 -0
- package/dist/daemon/loop.d.ts +27 -0
- package/dist/daemon/loop.d.ts.map +1 -0
- package/dist/daemon/loop.js +387 -0
- package/dist/daemon/timerScheduler.d.ts +13 -0
- package/dist/daemon/timerScheduler.d.ts.map +1 -0
- package/dist/daemon/timerScheduler.js +212 -0
- package/dist/daemon/types.d.ts +122 -0
- package/dist/daemon/types.d.ts.map +1 -0
- package/dist/daemon/types.js +25 -0
- package/dist/daemon/webhookListener.d.ts +6 -0
- package/dist/daemon/webhookListener.d.ts.map +1 -0
- package/dist/daemon/webhookListener.js +132 -0
- package/dist/execution/index.d.ts +10 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +20 -0
- package/dist/execution/modes/docker.d.ts +26 -0
- package/dist/execution/modes/docker.d.ts.map +1 -0
- package/dist/execution/modes/docker.js +183 -0
- package/dist/execution/modes/index.d.ts +10 -0
- package/dist/execution/modes/index.d.ts.map +1 -0
- package/dist/execution/modes/index.js +14 -0
- package/dist/execution/modes/kubernetes.d.ts +46 -0
- package/dist/execution/modes/kubernetes.d.ts.map +1 -0
- package/dist/execution/modes/kubernetes.js +334 -0
- package/dist/execution/modes/local.d.ts +23 -0
- package/dist/execution/modes/local.d.ts.map +1 -0
- package/dist/execution/modes/local.js +117 -0
- package/dist/execution/modes/ssh.d.ts +23 -0
- package/dist/execution/modes/ssh.d.ts.map +1 -0
- package/dist/execution/modes/ssh.js +144 -0
- package/dist/execution/policy.d.ts +15 -0
- package/dist/execution/policy.d.ts.map +1 -0
- package/dist/execution/policy.js +121 -0
- package/dist/execution/provider.d.ts +32 -0
- package/dist/execution/provider.d.ts.map +1 -0
- package/dist/execution/provider.js +90 -0
- package/dist/execution/types.d.ts +189 -0
- package/dist/execution/types.d.ts.map +1 -0
- package/dist/execution/types.js +9 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/observability/diagnostics.d.ts +25 -0
- package/dist/observability/diagnostics.d.ts.map +1 -0
- package/dist/observability/diagnostics.js +98 -0
- package/dist/observability/health.d.ts +19 -0
- package/dist/observability/health.d.ts.map +1 -0
- package/dist/observability/health.js +145 -0
- package/dist/observability/index.d.ts +7 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +25 -0
- package/dist/observability/runStatus.d.ts +44 -0
- package/dist/observability/runStatus.d.ts.map +1 -0
- package/dist/observability/runStatus.js +169 -0
- package/dist/observability/timeline.d.ts +11 -0
- package/dist/observability/timeline.d.ts.map +1 -0
- package/dist/observability/timeline.js +176 -0
- package/dist/observability/types.d.ts +65 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability/types.js +8 -0
- package/dist/observability/webhooks.d.ts +68 -0
- package/dist/observability/webhooks.d.ts.map +1 -0
- package/dist/observability/webhooks.js +132 -0
- package/dist/resources/budget-tracker.d.ts +56 -0
- package/dist/resources/budget-tracker.d.ts.map +1 -0
- package/dist/resources/budget-tracker.js +131 -0
- package/dist/resources/concurrency-guard.d.ts +55 -0
- package/dist/resources/concurrency-guard.d.ts.map +1 -0
- package/dist/resources/concurrency-guard.js +132 -0
- package/dist/resources/index.d.ts +12 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +20 -0
- package/dist/resources/manager.d.ts +52 -0
- package/dist/resources/manager.d.ts.map +1 -0
- package/dist/resources/manager.js +150 -0
- package/dist/resources/timeout-cascade.d.ts +56 -0
- package/dist/resources/timeout-cascade.d.ts.map +1 -0
- package/dist/resources/timeout-cascade.js +145 -0
- package/dist/resources/types.d.ts +130 -0
- package/dist/resources/types.d.ts.map +1 -0
- package/dist/resources/types.js +9 -0
- package/dist/rpc/index.d.ts +5 -0
- package/dist/rpc/index.d.ts.map +1 -0
- package/dist/rpc/index.js +7 -0
- package/dist/rpc/server.d.ts +13 -0
- package/dist/rpc/server.d.ts.map +1 -0
- package/dist/rpc/server.js +64 -0
- package/dist/rpc/server.test.d.ts +2 -0
- package/dist/rpc/server.test.d.ts.map +1 -0
- package/dist/rpc/server.test.js +35 -0
- package/dist/rpc/types.d.ts +23 -0
- package/dist/rpc/types.d.ts.map +1 -0
- package/dist/rpc/types.js +20 -0
- package/dist/session/context.d.ts +22 -0
- package/dist/session/context.d.ts.map +1 -0
- package/dist/session/context.js +113 -0
- package/dist/session/continuityState.d.ts +39 -0
- package/dist/session/continuityState.d.ts.map +1 -0
- package/dist/session/continuityState.js +164 -0
- package/dist/session/cost.d.ts +63 -0
- package/dist/session/cost.d.ts.map +1 -0
- package/dist/session/cost.js +194 -0
- package/dist/session/discovery.d.ts +22 -0
- package/dist/session/discovery.d.ts.map +1 -0
- package/dist/session/discovery.js +35 -0
- package/dist/session/export.d.ts +4 -0
- package/dist/session/export.d.ts.map +1 -0
- package/dist/session/export.js +56 -0
- package/dist/session/export.test.d.ts +2 -0
- package/dist/session/export.test.d.ts.map +1 -0
- package/dist/session/export.test.js +42 -0
- package/dist/session/history.d.ts +30 -0
- package/dist/session/history.d.ts.map +1 -0
- package/dist/session/history.js +143 -0
- package/dist/session/index.d.ts +20 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +78 -0
- package/dist/session/memoryExtraction.d.ts +65 -0
- package/dist/session/memoryExtraction.d.ts.map +1 -0
- package/dist/session/memoryExtraction.js +201 -0
- package/dist/session/parse.d.ts +45 -0
- package/dist/session/parse.d.ts.map +1 -0
- package/dist/session/parse.js +170 -0
- package/dist/session/persistence.d.ts +46 -0
- package/dist/session/persistence.d.ts.map +1 -0
- package/dist/session/persistence.js +180 -0
- package/dist/session/tree.d.ts +29 -0
- package/dist/session/tree.d.ts.map +1 -0
- package/dist/session/tree.js +115 -0
- package/dist/session/tree.test.d.ts +2 -0
- package/dist/session/tree.test.d.ts.map +1 -0
- package/dist/session/tree.test.js +75 -0
- package/dist/session/types.d.ts +267 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +45 -0
- package/dist/session/write.d.ts +61 -0
- package/dist/session/write.d.ts.map +1 -0
- package/dist/session/write.js +213 -0
- package/dist/shellInvocation.d.ts +6 -0
- package/dist/shellInvocation.d.ts.map +1 -0
- package/dist/shellInvocation.js +8 -0
- package/dist/shellInvocation.test.d.ts +2 -0
- package/dist/shellInvocation.test.d.ts.map +1 -0
- package/dist/shellInvocation.test.js +18 -0
- package/dist/telemetry/audit-log.d.ts +56 -0
- package/dist/telemetry/audit-log.d.ts.map +1 -0
- package/dist/telemetry/audit-log.js +59 -0
- package/dist/telemetry/exporters.d.ts +35 -0
- package/dist/telemetry/exporters.d.ts.map +1 -0
- package/dist/telemetry/exporters.js +141 -0
- package/dist/telemetry/index.d.ts +12 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +25 -0
- package/dist/telemetry/provider.d.ts +57 -0
- package/dist/telemetry/provider.d.ts.map +1 -0
- package/dist/telemetry/provider.js +261 -0
- package/dist/telemetry/span-tree.d.ts +46 -0
- package/dist/telemetry/span-tree.d.ts.map +1 -0
- package/dist/telemetry/span-tree.js +93 -0
- package/dist/telemetry/traceContext.d.ts +10 -0
- package/dist/telemetry/traceContext.d.ts.map +1 -0
- package/dist/telemetry/traceContext.js +43 -0
- package/dist/telemetry/types.d.ts +109 -0
- package/dist/telemetry/types.d.ts.map +1 -0
- package/dist/telemetry/types.js +21 -0
- package/package.json +137 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveExecutionEnvironment = resolveExecutionEnvironment;
|
|
7
|
+
exports.validateFilesystemPolicy = validateFilesystemPolicy;
|
|
8
|
+
exports.validateFilesystemMounts = validateFilesystemMounts;
|
|
9
|
+
exports.validateLocalExecutionPolicy = validateLocalExecutionPolicy;
|
|
10
|
+
exports.normalizeResourceLimits = normalizeResourceLimits;
|
|
11
|
+
exports.admitExecutionPolicy = admitExecutionPolicy;
|
|
12
|
+
exports.shouldInheritParentEnv = shouldInheritParentEnv;
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
function resolveExecutionEnvironment(explicitEnv, policy, parentEnv = process.env) {
|
|
15
|
+
const env = {};
|
|
16
|
+
const environment = policy?.environment;
|
|
17
|
+
if (environment?.inheritParentEnv) {
|
|
18
|
+
for (const [key, value] of Object.entries(parentEnv)) {
|
|
19
|
+
if (value !== undefined) {
|
|
20
|
+
env[key] = value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
for (const key of environment?.allow ?? []) {
|
|
25
|
+
const value = parentEnv[key];
|
|
26
|
+
if (value !== undefined) {
|
|
27
|
+
env[key] = value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
Object.assign(env, explicitEnv ?? {}, environment?.values ?? {});
|
|
31
|
+
for (const key of environment?.deny ?? []) {
|
|
32
|
+
delete env[key];
|
|
33
|
+
}
|
|
34
|
+
return env;
|
|
35
|
+
}
|
|
36
|
+
function validateFilesystemPolicy(cwd, policy) {
|
|
37
|
+
const filesystem = policy?.filesystem;
|
|
38
|
+
if (!filesystem?.allowedRoots?.length) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const resolvedCwd = node_path_1.default.resolve(cwd);
|
|
42
|
+
validatePathAgainstRoots(resolvedCwd, filesystem.allowedRoots, `Execution cwd "${cwd}"`);
|
|
43
|
+
validateFilesystemMounts(policy);
|
|
44
|
+
}
|
|
45
|
+
function validateFilesystemMounts(policy) {
|
|
46
|
+
const filesystem = policy?.filesystem;
|
|
47
|
+
if (!filesystem?.allowedRoots?.length) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
for (const mount of filesystem.mounts ?? []) {
|
|
51
|
+
validatePathAgainstRoots(node_path_1.default.resolve(mount.hostPath), filesystem.allowedRoots, `Execution mount "${mount.hostPath}"`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function validatePathAgainstRoots(candidate, roots, label) {
|
|
55
|
+
const resolvedCandidate = node_path_1.default.resolve(candidate);
|
|
56
|
+
const allowedRoots = roots.map((root) => node_path_1.default.resolve(root));
|
|
57
|
+
if (!allowedRoots.some((root) => isPathInside(resolvedCandidate, root))) {
|
|
58
|
+
throw new Error(`${label} is outside the configured filesystem allowed roots`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function validateLocalExecutionPolicy(config) {
|
|
62
|
+
const policy = config.policy;
|
|
63
|
+
validateFilesystemPolicy(config.cwd, policy);
|
|
64
|
+
if (!policy) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const allowUnsupported = policy.sandbox?.allowUnsupportedLocal === true;
|
|
68
|
+
const requestedSandbox = policy.sandbox?.requireNamespaces ||
|
|
69
|
+
policy.sandbox?.requireChroot ||
|
|
70
|
+
policy.sandbox?.requireSeccomp ||
|
|
71
|
+
policy.sandbox?.requireCapabilitiesDrop;
|
|
72
|
+
if (requestedSandbox && !allowUnsupported) {
|
|
73
|
+
throw new Error("Local executor cannot enforce sandbox guarantees such as namespaces, chroot, seccomp, or capabilities");
|
|
74
|
+
}
|
|
75
|
+
if (policy.network && !allowUnsupported) {
|
|
76
|
+
throw new Error("Local executor cannot enforce network policy; use Docker/Kubernetes or allowUnsupportedLocal explicitly");
|
|
77
|
+
}
|
|
78
|
+
const unsupportedResourceRequests = [];
|
|
79
|
+
if (policy.resources?.cpuCount !== undefined)
|
|
80
|
+
unsupportedResourceRequests.push("cpu");
|
|
81
|
+
if (policy.resources?.memoryBytes !== undefined)
|
|
82
|
+
unsupportedResourceRequests.push("memory");
|
|
83
|
+
if (policy.resources?.pidsLimit !== undefined)
|
|
84
|
+
unsupportedResourceRequests.push("pids");
|
|
85
|
+
if (policy.resources?.openFilesLimit !== undefined)
|
|
86
|
+
unsupportedResourceRequests.push("openFiles");
|
|
87
|
+
if (unsupportedResourceRequests.length > 0 && !allowUnsupported) {
|
|
88
|
+
throw new Error(`Local executor cannot enforce OS resource limits: ${unsupportedResourceRequests.join(", ")}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function normalizeResourceLimits(policy) {
|
|
92
|
+
const resources = policy?.resources;
|
|
93
|
+
return {
|
|
94
|
+
cpuCount: resources?.cpuCount,
|
|
95
|
+
memoryBytes: resources?.memoryBytes,
|
|
96
|
+
pidsLimit: resources?.pidsLimit,
|
|
97
|
+
openFilesLimit: resources?.openFilesLimit,
|
|
98
|
+
timeoutMs: resources?.timeoutMs,
|
|
99
|
+
maxOutputBytes: resources?.maxOutputBytes,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function admitExecutionPolicy(policy) {
|
|
103
|
+
const osLimits = normalizeResourceLimits(policy);
|
|
104
|
+
const unsupported = [];
|
|
105
|
+
if (osLimits.openFilesLimit !== undefined) {
|
|
106
|
+
unsupported.push("openFilesLimit");
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
accepted: unsupported.length === 0,
|
|
110
|
+
osLimits,
|
|
111
|
+
unsupported,
|
|
112
|
+
warnings: unsupported.map((name) => `${name} is tracked as policy metadata but is not enforced by ResourceManagerImpl`),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function shouldInheritParentEnv(policy) {
|
|
116
|
+
return policy?.environment?.inheritParentEnv === true;
|
|
117
|
+
}
|
|
118
|
+
function isPathInside(candidate, root) {
|
|
119
|
+
const relative = node_path_1.default.relative(root, candidate);
|
|
120
|
+
return relative === "" || (!relative.startsWith("..") && !node_path_1.default.isAbsolute(relative));
|
|
121
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExecutionProviderImpl — dispatches spawn/attach/list/destroy calls to
|
|
3
|
+
* mode-specific executors registered at construction time.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const provider = new ExecutionProviderImpl(
|
|
9
|
+
* new Map([
|
|
10
|
+
* ["local", localExecutor],
|
|
11
|
+
* ["docker", dockerExecutor],
|
|
12
|
+
* ["ssh", sshExecutor],
|
|
13
|
+
* ["kubernetes", k8sExecutor],
|
|
14
|
+
* ]),
|
|
15
|
+
* );
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import type { ExecutionConfig, ExecutionHandle, ExecutionMode, ExecutionProvider } from "./types";
|
|
19
|
+
import type { Executor } from "./modes/local";
|
|
20
|
+
export declare class ExecutionProviderImpl implements ExecutionProvider {
|
|
21
|
+
/** Registered mode executors. */
|
|
22
|
+
private readonly executors;
|
|
23
|
+
/** Global index: handleId -> mode, so attach/destroy can route correctly. */
|
|
24
|
+
private readonly handleIndex;
|
|
25
|
+
constructor(executors: Map<ExecutionMode, Executor<unknown>>);
|
|
26
|
+
spawn(config: ExecutionConfig): Promise<ExecutionHandle>;
|
|
27
|
+
attach(id: string): Promise<ExecutionHandle | undefined>;
|
|
28
|
+
list(): Promise<ExecutionHandle[]>;
|
|
29
|
+
destroy(id: string): Promise<void>;
|
|
30
|
+
private _executorFor;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/execution/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,aAAa,EACb,iBAAiB,EAClB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAM9C,qBAAa,qBAAsB,YAAW,iBAAiB;IAC7D,iCAAiC;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsC;IAChE,6EAA6E;IAC7E,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoC;gBAEpD,SAAS,EAAE,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IAQtD,KAAK,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAaxD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAexD,IAAI,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IASlC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBxC,OAAO,CAAC,YAAY;CAOrB"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ExecutionProviderImpl — dispatches spawn/attach/list/destroy calls to
|
|
4
|
+
* mode-specific executors registered at construction time.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const provider = new ExecutionProviderImpl(
|
|
10
|
+
* new Map([
|
|
11
|
+
* ["local", localExecutor],
|
|
12
|
+
* ["docker", dockerExecutor],
|
|
13
|
+
* ["ssh", sshExecutor],
|
|
14
|
+
* ["kubernetes", k8sExecutor],
|
|
15
|
+
* ]),
|
|
16
|
+
* );
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.ExecutionProviderImpl = void 0;
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// ExecutionProviderImpl
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
class ExecutionProviderImpl {
|
|
25
|
+
/** Registered mode executors. */
|
|
26
|
+
executors;
|
|
27
|
+
/** Global index: handleId -> mode, so attach/destroy can route correctly. */
|
|
28
|
+
handleIndex = new Map();
|
|
29
|
+
constructor(executors) {
|
|
30
|
+
// Cast once at the boundary — internally we dispatch with the correct
|
|
31
|
+
// config type per mode so this is type-safe in practice.
|
|
32
|
+
this.executors = executors;
|
|
33
|
+
}
|
|
34
|
+
// ---------- ExecutionProvider interface ------------------------------------
|
|
35
|
+
async spawn(config) {
|
|
36
|
+
const executor = this._executorFor(config.mode);
|
|
37
|
+
// Each executor.spawn() takes (command, args, config). The provider
|
|
38
|
+
// layer doesn't know the command/args — those are part of the config
|
|
39
|
+
// at a higher level. For the provider's spawn() we pass a default
|
|
40
|
+
// shell invocation and forward the mode-specific config.
|
|
41
|
+
const handle = await executor.spawn("sh", ["-c", "true"], config);
|
|
42
|
+
this.handleIndex.set(handle.id, config.mode);
|
|
43
|
+
return handle;
|
|
44
|
+
}
|
|
45
|
+
async attach(id) {
|
|
46
|
+
const mode = this.handleIndex.get(id);
|
|
47
|
+
if (!mode) {
|
|
48
|
+
// Try all executors — the handle may predate this provider instance.
|
|
49
|
+
for (const executor of this.executors.values()) {
|
|
50
|
+
const handle = await executor.attach(id);
|
|
51
|
+
if (handle)
|
|
52
|
+
return handle;
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const executor = this.executors.get(mode);
|
|
57
|
+
return executor?.attach(id);
|
|
58
|
+
}
|
|
59
|
+
async list() {
|
|
60
|
+
const all = [];
|
|
61
|
+
for (const executor of this.executors.values()) {
|
|
62
|
+
const handles = executor.list();
|
|
63
|
+
all.push(...handles);
|
|
64
|
+
}
|
|
65
|
+
return all;
|
|
66
|
+
}
|
|
67
|
+
async destroy(id) {
|
|
68
|
+
const mode = this.handleIndex.get(id);
|
|
69
|
+
if (!mode) {
|
|
70
|
+
// Attempt all executors — best effort.
|
|
71
|
+
for (const executor of this.executors.values()) {
|
|
72
|
+
await executor.destroy(id);
|
|
73
|
+
}
|
|
74
|
+
this.handleIndex.delete(id);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const executor = this.executors.get(mode);
|
|
78
|
+
await executor?.destroy(id);
|
|
79
|
+
this.handleIndex.delete(id);
|
|
80
|
+
}
|
|
81
|
+
// ---------- Helpers -------------------------------------------------------
|
|
82
|
+
_executorFor(mode) {
|
|
83
|
+
const executor = this.executors.get(mode);
|
|
84
|
+
if (!executor) {
|
|
85
|
+
throw new Error(`No executor registered for execution mode "${mode}"`);
|
|
86
|
+
}
|
|
87
|
+
return executor;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.ExecutionProviderImpl = ExecutionProviderImpl;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution mode abstraction for Babysitter Agent Runtime.
|
|
3
|
+
*
|
|
4
|
+
* Defines how effects and sub-agents are spawned — locally, in Docker,
|
|
5
|
+
* over SSH, or on Kubernetes. Interface-only stubs; implementations
|
|
6
|
+
* will follow in issue #217.
|
|
7
|
+
*/
|
|
8
|
+
/** Supported execution environments. */
|
|
9
|
+
export type ExecutionMode = "local" | "docker" | "ssh" | "kubernetes";
|
|
10
|
+
export interface ExecutionEnvironmentPolicy {
|
|
11
|
+
readonly inheritParentEnv?: boolean;
|
|
12
|
+
readonly allow?: string[];
|
|
13
|
+
readonly values?: Record<string, string>;
|
|
14
|
+
readonly deny?: string[];
|
|
15
|
+
readonly redact?: string[];
|
|
16
|
+
}
|
|
17
|
+
export interface ExecutionMount {
|
|
18
|
+
readonly hostPath: string;
|
|
19
|
+
readonly containerPath: string;
|
|
20
|
+
readonly readOnly?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ExecutionFilesystemPolicy {
|
|
23
|
+
readonly allowedRoots?: string[];
|
|
24
|
+
readonly mounts?: ExecutionMount[];
|
|
25
|
+
readonly readOnlyRootFilesystem?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface ExecutionNetworkPolicy {
|
|
28
|
+
readonly mode?: "none" | "bridge" | "host" | "custom";
|
|
29
|
+
readonly name?: string;
|
|
30
|
+
readonly dns?: string[];
|
|
31
|
+
readonly allowEgress?: string[];
|
|
32
|
+
readonly blockEgress?: string[];
|
|
33
|
+
}
|
|
34
|
+
export interface ExecutionResourcePolicy {
|
|
35
|
+
readonly cpuCount?: number;
|
|
36
|
+
readonly memoryBytes?: number;
|
|
37
|
+
readonly pidsLimit?: number;
|
|
38
|
+
readonly openFilesLimit?: number;
|
|
39
|
+
readonly timeoutMs?: number;
|
|
40
|
+
readonly maxOutputBytes?: number;
|
|
41
|
+
}
|
|
42
|
+
export type NormalizedResourceLimits = ExecutionResourcePolicy;
|
|
43
|
+
export interface ExecutionSandboxPolicy {
|
|
44
|
+
readonly requireNamespaces?: boolean;
|
|
45
|
+
readonly requireChroot?: boolean;
|
|
46
|
+
readonly requireSeccomp?: boolean;
|
|
47
|
+
readonly requireCapabilitiesDrop?: boolean;
|
|
48
|
+
readonly allowUnsupportedLocal?: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface DockerPolicy {
|
|
51
|
+
readonly readOnlyRootFilesystem?: boolean;
|
|
52
|
+
readonly user?: string;
|
|
53
|
+
readonly capDrop?: string[];
|
|
54
|
+
readonly securityOpt?: string[];
|
|
55
|
+
readonly skipPreflight?: boolean;
|
|
56
|
+
readonly insecureAllowPrivilegedOptions?: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface SshHostKeyPolicy {
|
|
59
|
+
readonly strictHostKeyChecking?: "yes" | "accept-new";
|
|
60
|
+
readonly knownHostsFile?: string;
|
|
61
|
+
readonly insecureSkipHostKeyChecking?: boolean;
|
|
62
|
+
}
|
|
63
|
+
export interface KubernetesPolicy {
|
|
64
|
+
readonly runAsNonRoot?: boolean;
|
|
65
|
+
readonly readOnlyRootFilesystem?: boolean;
|
|
66
|
+
readonly allowPrivilegeEscalation?: boolean;
|
|
67
|
+
}
|
|
68
|
+
export interface ExecutionPolicy {
|
|
69
|
+
readonly environment?: ExecutionEnvironmentPolicy;
|
|
70
|
+
readonly filesystem?: ExecutionFilesystemPolicy;
|
|
71
|
+
readonly network?: ExecutionNetworkPolicy;
|
|
72
|
+
readonly resources?: ExecutionResourcePolicy;
|
|
73
|
+
readonly sandbox?: ExecutionSandboxPolicy;
|
|
74
|
+
readonly docker?: DockerPolicy;
|
|
75
|
+
readonly ssh?: SshHostKeyPolicy;
|
|
76
|
+
readonly kubernetes?: KubernetesPolicy;
|
|
77
|
+
}
|
|
78
|
+
/** Configuration for local (host-process) execution. */
|
|
79
|
+
export interface LocalExecutionConfig {
|
|
80
|
+
readonly mode: "local";
|
|
81
|
+
/** Working directory for spawned processes. */
|
|
82
|
+
readonly cwd: string;
|
|
83
|
+
/** Optional environment variable overrides. */
|
|
84
|
+
readonly env?: Record<string, string>;
|
|
85
|
+
/** Shared execution policy. Secure defaults apply when omitted. */
|
|
86
|
+
readonly policy?: ExecutionPolicy;
|
|
87
|
+
}
|
|
88
|
+
/** Configuration for Docker-based execution. */
|
|
89
|
+
export interface DockerExecutionConfig {
|
|
90
|
+
readonly mode: "docker";
|
|
91
|
+
/** Container image reference (e.g. "node:20-slim"). */
|
|
92
|
+
readonly image: string;
|
|
93
|
+
/** Volume mounts in "host:container" format. */
|
|
94
|
+
readonly volumes?: string[];
|
|
95
|
+
/** Docker network to attach to. */
|
|
96
|
+
readonly network?: string;
|
|
97
|
+
/** Optional environment variable overrides. */
|
|
98
|
+
readonly env?: Record<string, string>;
|
|
99
|
+
/** Shared execution policy. Secure defaults apply when omitted. */
|
|
100
|
+
readonly policy?: ExecutionPolicy;
|
|
101
|
+
}
|
|
102
|
+
/** Configuration for SSH-based remote execution. */
|
|
103
|
+
export interface SshExecutionConfig {
|
|
104
|
+
readonly mode: "ssh";
|
|
105
|
+
/** Remote hostname or IP address. */
|
|
106
|
+
readonly host: string;
|
|
107
|
+
/** SSH port; defaults to 22. */
|
|
108
|
+
readonly port?: number;
|
|
109
|
+
/** Remote user. */
|
|
110
|
+
readonly user: string;
|
|
111
|
+
/** Path to the private key file. */
|
|
112
|
+
readonly keyPath?: string;
|
|
113
|
+
/** Optional environment variable overrides. */
|
|
114
|
+
readonly env?: Record<string, string>;
|
|
115
|
+
/** Shared execution policy. Secure defaults apply when omitted. */
|
|
116
|
+
readonly policy?: ExecutionPolicy;
|
|
117
|
+
}
|
|
118
|
+
/** Configuration for Kubernetes pod-based execution. */
|
|
119
|
+
export interface KubernetesExecutionConfig {
|
|
120
|
+
readonly mode: "kubernetes";
|
|
121
|
+
/** Kubernetes namespace. */
|
|
122
|
+
readonly namespace: string;
|
|
123
|
+
/** Container image reference. */
|
|
124
|
+
readonly image: string;
|
|
125
|
+
/** Optional environment variable overrides. */
|
|
126
|
+
readonly env?: Record<string, string>;
|
|
127
|
+
/** Service account to run under. */
|
|
128
|
+
readonly serviceAccount?: string;
|
|
129
|
+
/** Resource requests/limits (e.g. `{ cpu: "500m", memory: "256Mi" }`). */
|
|
130
|
+
readonly resources?: Record<string, string>;
|
|
131
|
+
/** Shared execution policy. Secure defaults apply when omitted. */
|
|
132
|
+
readonly policy?: ExecutionPolicy;
|
|
133
|
+
/** Maximum time to wait for Job completion. Defaults to 5 minutes. */
|
|
134
|
+
readonly timeoutMs?: number;
|
|
135
|
+
/** Maximum time for each kubectl invocation. */
|
|
136
|
+
readonly kubectlTimeoutMs?: number;
|
|
137
|
+
/** Delete the Job after terminal success, failure, or timeout. */
|
|
138
|
+
readonly cleanupAfterCompletion?: boolean;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Discriminated union of all execution config types.
|
|
142
|
+
* Discriminant field is `mode`.
|
|
143
|
+
*/
|
|
144
|
+
export type ExecutionConfig = LocalExecutionConfig | DockerExecutionConfig | SshExecutionConfig | KubernetesExecutionConfig;
|
|
145
|
+
/** Handle to a running or completed execution. */
|
|
146
|
+
export interface ExecutionHandle {
|
|
147
|
+
/** Unique identifier for this execution instance. */
|
|
148
|
+
readonly id: string;
|
|
149
|
+
/** The execution mode this handle was spawned with. */
|
|
150
|
+
readonly mode: ExecutionMode;
|
|
151
|
+
/** Current lifecycle status. */
|
|
152
|
+
readonly status: "running" | "stopped" | "failed";
|
|
153
|
+
/**
|
|
154
|
+
* Attach to the execution's I/O streams (e.g. for log tailing).
|
|
155
|
+
*/
|
|
156
|
+
attach(): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Tear down the execution and release its resources.
|
|
159
|
+
*/
|
|
160
|
+
destroy(): Promise<void>;
|
|
161
|
+
}
|
|
162
|
+
/** Abstraction over an execution backend. */
|
|
163
|
+
export interface ExecutionProvider {
|
|
164
|
+
/**
|
|
165
|
+
* Spawn a new execution from the given config.
|
|
166
|
+
*
|
|
167
|
+
* @param config - Discriminated execution configuration.
|
|
168
|
+
* @returns A handle to the running execution.
|
|
169
|
+
*/
|
|
170
|
+
spawn(config: ExecutionConfig): Promise<ExecutionHandle>;
|
|
171
|
+
/**
|
|
172
|
+
* Re-attach to a previously spawned execution.
|
|
173
|
+
*
|
|
174
|
+
* @param id - Execution identifier returned by a prior `spawn`.
|
|
175
|
+
* @returns The handle, or undefined if not found.
|
|
176
|
+
*/
|
|
177
|
+
attach(id: string): Promise<ExecutionHandle | undefined>;
|
|
178
|
+
/**
|
|
179
|
+
* List all known execution handles managed by this provider.
|
|
180
|
+
*/
|
|
181
|
+
list(): Promise<ExecutionHandle[]>;
|
|
182
|
+
/**
|
|
183
|
+
* Destroy an execution by ID.
|
|
184
|
+
*
|
|
185
|
+
* @param id - Execution identifier.
|
|
186
|
+
*/
|
|
187
|
+
destroy(id: string): Promise<void>;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/execution/types.ts"],"names":[],"mappings":"AAAA;;;;;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E,OAAO,CAAC;CAC3C;AAMD;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB,oBAAoB,GACpB,qBAAqB,GACrB,kBAAkB,GAClB,yBAAyB,CAAC;AAM9B,kDAAkD;AAClD,MAAM,WAAW,eAAe;IAC9B,qDAAqD;IACrD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,gCAAgC;IAChC,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IAClD;;OAEG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAMD,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,KAAK,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAEzD;;;;;OAKG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;IAEzD;;OAEG;IACH,IAAI,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IAEnC;;;;OAIG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Execution mode abstraction for Babysitter Agent Runtime.
|
|
4
|
+
*
|
|
5
|
+
* Defines how effects and sub-agents are spawned — locally, in Docker,
|
|
6
|
+
* over SSH, or on Kubernetes. Interface-only stubs; implementations
|
|
7
|
+
* will follow in issue #217.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { BackgroundProcessRegistry, type BackgroundTaskRecord, type BackgroundCompletionEvent, type SpawnOptions, } from "./backgroundProcessRegistry";
|
|
2
|
+
export { getBackgroundRegistry, disposeBackgroundRegistry, } from "./background/state";
|
|
3
|
+
export { buildShellInvocation, type ShellInvocation, } from "./shellInvocation";
|
|
4
|
+
export { ok, fail, type ApiResult } from "./apiResult";
|
|
5
|
+
export * from "./daemon";
|
|
6
|
+
export * from "./session";
|
|
7
|
+
export * from "./cost";
|
|
8
|
+
export * from "./observability";
|
|
9
|
+
export * from "./telemetry";
|
|
10
|
+
export * from "./execution";
|
|
11
|
+
export * from "./resources";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,yBAAyB,EACzB,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,YAAY,GAClB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,oBAAoB,EACpB,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAGvD,cAAc,UAAU,CAAC;AAGzB,cAAc,WAAW,CAAC;AAG1B,cAAc,QAAQ,CAAC;AAGvB,cAAc,iBAAiB,CAAC;AAGhC,cAAc,aAAa,CAAC;AAG5B,cAAc,aAAa,CAAC;AAG5B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// L5 Agent-Runtime layer exports
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.fail = exports.ok = exports.buildShellInvocation = exports.disposeBackgroundRegistry = exports.getBackgroundRegistry = exports.BackgroundProcessRegistry = void 0;
|
|
19
|
+
// Background process management (moved from agent-core)
|
|
20
|
+
var backgroundProcessRegistry_1 = require("./backgroundProcessRegistry");
|
|
21
|
+
Object.defineProperty(exports, "BackgroundProcessRegistry", { enumerable: true, get: function () { return backgroundProcessRegistry_1.BackgroundProcessRegistry; } });
|
|
22
|
+
var state_1 = require("./background/state");
|
|
23
|
+
Object.defineProperty(exports, "getBackgroundRegistry", { enumerable: true, get: function () { return state_1.getBackgroundRegistry; } });
|
|
24
|
+
Object.defineProperty(exports, "disposeBackgroundRegistry", { enumerable: true, get: function () { return state_1.disposeBackgroundRegistry; } });
|
|
25
|
+
var shellInvocation_1 = require("./shellInvocation");
|
|
26
|
+
Object.defineProperty(exports, "buildShellInvocation", { enumerable: true, get: function () { return shellInvocation_1.buildShellInvocation; } });
|
|
27
|
+
// Result envelope utility (used by daemon lifecycle/config)
|
|
28
|
+
var apiResult_1 = require("./apiResult");
|
|
29
|
+
Object.defineProperty(exports, "ok", { enumerable: true, get: function () { return apiResult_1.ok; } });
|
|
30
|
+
Object.defineProperty(exports, "fail", { enumerable: true, get: function () { return apiResult_1.fail; } });
|
|
31
|
+
// Daemon management (moved from agent-platform)
|
|
32
|
+
__exportStar(require("./daemon"), exports);
|
|
33
|
+
// Session state management (moved from agent-platform)
|
|
34
|
+
__exportStar(require("./session"), exports);
|
|
35
|
+
// Cost tracking (moved from agent-platform)
|
|
36
|
+
__exportStar(require("./cost"), exports);
|
|
37
|
+
// Observability (moved from agent-platform)
|
|
38
|
+
__exportStar(require("./observability"), exports);
|
|
39
|
+
// Telemetry (L5 type stubs — issue #217)
|
|
40
|
+
__exportStar(require("./telemetry"), exports);
|
|
41
|
+
// Execution modes (L5 type stubs — issue #217)
|
|
42
|
+
__exportStar(require("./execution"), exports);
|
|
43
|
+
// Resource management (L5 type stubs — issue #217)
|
|
44
|
+
__exportStar(require("./resources"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DaemonConfig } from "../daemon/types";
|
|
2
|
+
import type { DaemonLoopStatus } from "../daemon/loop";
|
|
3
|
+
import type { RunHealthSnapshot } from "./types";
|
|
4
|
+
export type DiagnosticsRequestPath = "/health" | "/metrics" | "/config" | "/queue";
|
|
5
|
+
export interface DiagnosticsContext {
|
|
6
|
+
health: RunHealthSnapshot;
|
|
7
|
+
queue?: DaemonLoopStatus | null;
|
|
8
|
+
config?: DaemonConfig | Record<string, unknown> | null;
|
|
9
|
+
}
|
|
10
|
+
export interface DiagnosticsSnapshot {
|
|
11
|
+
health: RunHealthSnapshot;
|
|
12
|
+
metrics: string;
|
|
13
|
+
config: unknown;
|
|
14
|
+
queue: DaemonLoopStatus | null;
|
|
15
|
+
}
|
|
16
|
+
export interface DiagnosticsResponse {
|
|
17
|
+
status: number;
|
|
18
|
+
contentType: string;
|
|
19
|
+
body: unknown;
|
|
20
|
+
}
|
|
21
|
+
export declare function redactDiagnosticsConfig(value: unknown): unknown;
|
|
22
|
+
export declare function buildDiagnosticsSnapshot(context: DiagnosticsContext): DiagnosticsSnapshot;
|
|
23
|
+
export declare function renderPrometheusMetrics(context: Pick<DiagnosticsContext, "health" | "queue">): string;
|
|
24
|
+
export declare function handleDiagnosticsRequest(requestPath: DiagnosticsRequestPath, context: DiagnosticsContext): DiagnosticsResponse;
|
|
25
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/observability/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEnF,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CACxD;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;CACf;AAID,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE/D;AAmBD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,kBAAkB,GAAG,mBAAmB,CAQzF;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,MAAM,CAsCrG;AAED,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,sBAAsB,EACnC,OAAO,EAAE,kBAAkB,GAC1B,mBAAmB,CAuBrB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redactDiagnosticsConfig = redactDiagnosticsConfig;
|
|
4
|
+
exports.buildDiagnosticsSnapshot = buildDiagnosticsSnapshot;
|
|
5
|
+
exports.renderPrometheusMetrics = renderPrometheusMetrics;
|
|
6
|
+
exports.handleDiagnosticsRequest = handleDiagnosticsRequest;
|
|
7
|
+
const SECRET_KEY_PATTERN = /(secret|token|api[-_]?key|authorization|password|credential|private[-_]?key)/i;
|
|
8
|
+
function redactDiagnosticsConfig(value) {
|
|
9
|
+
return redactValue(value, "");
|
|
10
|
+
}
|
|
11
|
+
function redactValue(value, key) {
|
|
12
|
+
if (SECRET_KEY_PATTERN.test(key)) {
|
|
13
|
+
return "[REDACTED]";
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
return value.map((item) => redactValue(item, ""));
|
|
17
|
+
}
|
|
18
|
+
if (value && typeof value === "object") {
|
|
19
|
+
const result = {};
|
|
20
|
+
for (const [childKey, childValue] of Object.entries(value)) {
|
|
21
|
+
result[childKey] = redactValue(childValue, childKey);
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
function buildDiagnosticsSnapshot(context) {
|
|
28
|
+
const queue = context.queue ?? null;
|
|
29
|
+
return {
|
|
30
|
+
health: context.health,
|
|
31
|
+
queue,
|
|
32
|
+
config: redactDiagnosticsConfig(context.config ?? null),
|
|
33
|
+
metrics: renderPrometheusMetrics({ health: context.health, queue }),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function renderPrometheusMetrics(context) {
|
|
37
|
+
const metrics = context.health.metrics;
|
|
38
|
+
const lines = [
|
|
39
|
+
"# HELP babysitter_run_effect_latency_ms Run effect latency in milliseconds.",
|
|
40
|
+
"# TYPE babysitter_run_effect_latency_ms gauge",
|
|
41
|
+
`babysitter_run_effect_latency_ms{quantile="avg"} ${metrics.avgEffectLatencyMs}`,
|
|
42
|
+
`babysitter_run_effect_latency_ms{quantile="0.5"} ${metrics.p50EffectLatencyMs}`,
|
|
43
|
+
`babysitter_run_effect_latency_ms{quantile="0.95"} ${metrics.p95EffectLatencyMs}`,
|
|
44
|
+
`babysitter_run_effect_latency_ms{quantile="0.99"} ${metrics.p99EffectLatencyMs}`,
|
|
45
|
+
"# HELP babysitter_run_effects_total Run effects by state.",
|
|
46
|
+
"# TYPE babysitter_run_effects_total gauge",
|
|
47
|
+
`babysitter_run_effects_total{state="total"} ${metrics.totalEffects}`,
|
|
48
|
+
`babysitter_run_effects_total{state="resolved"} ${metrics.resolvedEffects}`,
|
|
49
|
+
`babysitter_run_effects_total{state="failed"} ${metrics.failedEffects}`,
|
|
50
|
+
`babysitter_run_effects_total{state="pending"} ${metrics.pendingCount}`,
|
|
51
|
+
"# HELP babysitter_run_error_rate Run effect error rate.",
|
|
52
|
+
"# TYPE babysitter_run_error_rate gauge",
|
|
53
|
+
`babysitter_run_error_rate ${metrics.errorRate}`,
|
|
54
|
+
"# HELP babysitter_daemon_queue_active_runs Active daemon runs.",
|
|
55
|
+
"# TYPE babysitter_daemon_queue_active_runs gauge",
|
|
56
|
+
`babysitter_daemon_queue_active_runs ${context.queue?.activeRuns ?? 0}`,
|
|
57
|
+
"# HELP babysitter_daemon_queue_pending_runs Pending daemon runs.",
|
|
58
|
+
"# TYPE babysitter_daemon_queue_pending_runs gauge",
|
|
59
|
+
`babysitter_daemon_queue_pending_runs ${context.queue?.pendingRuns ?? 0}`,
|
|
60
|
+
"# HELP babysitter_daemon_queue_dead_letter_runs Dead-lettered daemon runs.",
|
|
61
|
+
"# TYPE babysitter_daemon_queue_dead_letter_runs gauge",
|
|
62
|
+
`babysitter_daemon_queue_dead_letter_runs ${context.queue?.deadLetterRuns ?? 0}`,
|
|
63
|
+
"# HELP babysitter_daemon_trigger_rejections_total Trigger admissions rejected by the daemon.",
|
|
64
|
+
"# TYPE babysitter_daemon_trigger_rejections_total counter",
|
|
65
|
+
`babysitter_daemon_trigger_rejections_total ${context.queue?.rejectedTriggers ?? 0}`,
|
|
66
|
+
"# HELP babysitter_daemon_trigger_duplicates_total Trigger admissions suppressed as duplicates by the daemon.",
|
|
67
|
+
"# TYPE babysitter_daemon_trigger_duplicates_total counter",
|
|
68
|
+
`babysitter_daemon_trigger_duplicates_total ${context.queue?.duplicateTriggers ?? 0}`,
|
|
69
|
+
"# HELP babysitter_daemon_trigger_rate_limited_total Trigger admissions rejected by rate limiting.",
|
|
70
|
+
"# TYPE babysitter_daemon_trigger_rate_limited_total counter",
|
|
71
|
+
`babysitter_daemon_trigger_rate_limited_total ${context.queue?.rateLimitedTriggers ?? 0}`,
|
|
72
|
+
];
|
|
73
|
+
return `${lines.join("\n")}\n`;
|
|
74
|
+
}
|
|
75
|
+
function handleDiagnosticsRequest(requestPath, context) {
|
|
76
|
+
switch (requestPath) {
|
|
77
|
+
case "/health":
|
|
78
|
+
return { status: 200, contentType: "application/json", body: context.health };
|
|
79
|
+
case "/metrics":
|
|
80
|
+
return {
|
|
81
|
+
status: 200,
|
|
82
|
+
contentType: "text/plain; version=0.0.4",
|
|
83
|
+
body: renderPrometheusMetrics({ health: context.health, queue: context.queue }),
|
|
84
|
+
};
|
|
85
|
+
case "/config":
|
|
86
|
+
return {
|
|
87
|
+
status: 200,
|
|
88
|
+
contentType: "application/json",
|
|
89
|
+
body: redactDiagnosticsConfig(context.config ?? null),
|
|
90
|
+
};
|
|
91
|
+
case "/queue":
|
|
92
|
+
return {
|
|
93
|
+
status: 200,
|
|
94
|
+
contentType: "application/json",
|
|
95
|
+
body: context.queue ?? null,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|