@orgloop/transform-agent-gate 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OrgLoop contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Agent-gate transform — gates events on running agent sessions.
3
+ *
4
+ * Shells out to `agent-ctl list --json` and checks if any sessions matching
5
+ * the configured filter are still running. If sessions ARE running, the event
6
+ * is dropped (returns null). If NO matching sessions are running, the event
7
+ * passes through.
8
+ *
9
+ * Fails open: CLI errors pass the event through rather than blocking.
10
+ */
11
+ import type { OrgLoopEvent, Transform, TransformContext } from '@orgloop/sdk';
12
+ export interface AgentGateConfig {
13
+ /** Path to agent-ctl binary (default: "agent-ctl") */
14
+ binary_path?: string;
15
+ /** Only count sessions from this adapter (e.g. "claude-code") */
16
+ adapter_filter?: string;
17
+ /** Only count sessions with these statuses as "running" (default: ["running"]) */
18
+ active_statuses?: string[];
19
+ /** Timeout for CLI call in ms (default: 5000) */
20
+ timeout?: number;
21
+ }
22
+ interface AgentSession {
23
+ status: string;
24
+ adapter: string;
25
+ [key: string]: unknown;
26
+ }
27
+ /**
28
+ * Execute agent-ctl list --json and parse the output.
29
+ * Exported for testability (allows mocking in tests).
30
+ */
31
+ export declare function execAgentCtl(binaryPath: string, timeoutMs: number): Promise<AgentSession[]>;
32
+ export declare class AgentGateTransform implements Transform {
33
+ readonly id = "agent-gate";
34
+ private binaryPath;
35
+ private adapterFilter;
36
+ private activeStatuses;
37
+ private timeoutMs;
38
+ /** Override for testing — allows injecting a mock executor */
39
+ _execFn: typeof execAgentCtl;
40
+ init(config: Record<string, unknown>): Promise<void>;
41
+ execute(event: OrgLoopEvent, _context: TransformContext): Promise<OrgLoopEvent | null>;
42
+ shutdown(): Promise<void>;
43
+ }
44
+ export {};
45
+ //# sourceMappingURL=agent-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-gate.d.ts","sourceRoot":"","sources":["../src/agent-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE9E,MAAM,WAAW,eAAe;IAC/B,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kFAAkF;IAClF,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,YAAY;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAQD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAgB3F;AAED,qBAAa,kBAAmB,YAAW,SAAS;IACnD,QAAQ,CAAC,EAAE,gBAAgB;IAC3B,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,cAAc,CAAqC;IAC3D,OAAO,CAAC,SAAS,CAAmB;IAEpC,8DAA8D;IAC9D,OAAO,EAAE,OAAO,YAAY,CAAgB;IAEtC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBpD,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAwBtF,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Agent-gate transform — gates events on running agent sessions.
3
+ *
4
+ * Shells out to `agent-ctl list --json` and checks if any sessions matching
5
+ * the configured filter are still running. If sessions ARE running, the event
6
+ * is dropped (returns null). If NO matching sessions are running, the event
7
+ * passes through.
8
+ *
9
+ * Fails open: CLI errors pass the event through rather than blocking.
10
+ */
11
+ import { execFile } from 'node:child_process';
12
+ const KNOWN_CONFIG_KEYS = new Set(['binary_path', 'adapter_filter', 'active_statuses', 'timeout']);
13
+ const DEFAULT_BINARY = 'agent-ctl';
14
+ const DEFAULT_ACTIVE_STATUSES = ['running'];
15
+ const DEFAULT_TIMEOUT = 5000;
16
+ /**
17
+ * Execute agent-ctl list --json and parse the output.
18
+ * Exported for testability (allows mocking in tests).
19
+ */
20
+ export function execAgentCtl(binaryPath, timeoutMs) {
21
+ return new Promise((resolve, reject) => {
22
+ execFile(binaryPath, ['list', '--json'], { timeout: timeoutMs }, (error, stdout) => {
23
+ if (error) {
24
+ reject(error);
25
+ return;
26
+ }
27
+ try {
28
+ const parsed = JSON.parse(stdout);
29
+ const sessions = Array.isArray(parsed) ? parsed : (parsed.sessions ?? []);
30
+ resolve(sessions);
31
+ }
32
+ catch (parseError) {
33
+ reject(new Error(`Failed to parse agent-ctl output: ${parseError}`));
34
+ }
35
+ });
36
+ });
37
+ }
38
+ export class AgentGateTransform {
39
+ id = 'agent-gate';
40
+ binaryPath = DEFAULT_BINARY;
41
+ adapterFilter;
42
+ activeStatuses = DEFAULT_ACTIVE_STATUSES;
43
+ timeoutMs = DEFAULT_TIMEOUT;
44
+ /** Override for testing — allows injecting a mock executor */
45
+ _execFn = execAgentCtl;
46
+ async init(config) {
47
+ const unknownKeys = Object.keys(config).filter((k) => !KNOWN_CONFIG_KEYS.has(k));
48
+ if (unknownKeys.length > 0) {
49
+ throw new Error(`Agent-gate transform: unknown config keys: ${unknownKeys.join(', ')}. ` +
50
+ `Valid keys are: ${[...KNOWN_CONFIG_KEYS].join(', ')}`);
51
+ }
52
+ const c = config;
53
+ this.binaryPath = c.binary_path ?? DEFAULT_BINARY;
54
+ this.adapterFilter = c.adapter_filter;
55
+ this.activeStatuses = c.active_statuses ?? DEFAULT_ACTIVE_STATUSES;
56
+ this.timeoutMs = c.timeout ?? DEFAULT_TIMEOUT;
57
+ }
58
+ async execute(event, _context) {
59
+ let sessions;
60
+ try {
61
+ sessions = await this._execFn(this.binaryPath, this.timeoutMs);
62
+ }
63
+ catch {
64
+ // Fail open — if we can't check, let the event through
65
+ return event;
66
+ }
67
+ const activeSessions = sessions.filter((s) => this.activeStatuses.includes(s.status) &&
68
+ (!this.adapterFilter || s.adapter === this.adapterFilter));
69
+ // If active sessions exist, gate is closed — drop the event
70
+ if (activeSessions.length > 0) {
71
+ return null;
72
+ }
73
+ // No active sessions — gate is open, pass through
74
+ return event;
75
+ }
76
+ async shutdown() {
77
+ // No resources to clean up
78
+ }
79
+ }
80
+ //# sourceMappingURL=agent-gate.js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d,CAAC;QAED,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CACrC,CAAC,CAAC,EAAE,EAAE,CACL,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;YACtC,CAAC,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,CAAC,OAAO,KAAK,IAAI,CAAC,aAAa,CAAC,CAC1D,CAAC;QAEF,4DAA4D;QAC5D,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC;QACb,CAAC;QAED,kDAAkD;QAClD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,KAAK,CAAC,QAAQ;QACb,2BAA2B;IAC5B,CAAC;CACD"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @orgloop/transform-agent-gate — registration entry point.
3
+ */
4
+ import type { TransformRegistration } from '@orgloop/sdk';
5
+ export declare function register(): TransformRegistration;
6
+ export { AgentGateTransform } from './agent-gate.js';
7
+ export type { AgentGateConfig } from './agent-gate.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAG1D,wBAAgB,QAAQ,IAAI,qBAAqB,CA+BhD;AAED,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @orgloop/transform-agent-gate — registration entry point.
3
+ */
4
+ import { AgentGateTransform } from './agent-gate.js';
5
+ export function register() {
6
+ return {
7
+ id: 'agent-gate',
8
+ transform: AgentGateTransform,
9
+ configSchema: {
10
+ type: 'object',
11
+ properties: {
12
+ binary_path: {
13
+ type: 'string',
14
+ description: 'Path to agent-ctl binary.',
15
+ default: 'agent-ctl',
16
+ },
17
+ adapter_filter: {
18
+ type: 'string',
19
+ description: 'Only count sessions from this adapter (e.g. "claude-code").',
20
+ },
21
+ active_statuses: {
22
+ type: 'array',
23
+ items: { type: 'string' },
24
+ description: 'Statuses considered "running" (default: ["running"]).',
25
+ default: ['running'],
26
+ },
27
+ timeout: {
28
+ type: 'number',
29
+ description: 'Timeout for CLI call in ms.',
30
+ default: 5000,
31
+ },
32
+ },
33
+ additionalProperties: false,
34
+ },
35
+ };
36
+ }
37
+ export { AgentGateTransform } from './agent-gate.js';
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,UAAU,QAAQ;IACvB,OAAO;QACN,EAAE,EAAE,YAAY;QAChB,SAAS,EAAE,kBAAkB;QAC7B,YAAY,EAAE;YACb,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACX,WAAW,EAAE;oBACZ,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,2BAA2B;oBACxC,OAAO,EAAE,WAAW;iBACpB;gBACD,cAAc,EAAE;oBACf,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,6DAA6D;iBAC1E;gBACD,eAAe,EAAE;oBAChB,IAAI,EAAE,OAAO;oBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBACzB,WAAW,EAAE,uDAAuD;oBACpE,OAAO,EAAE,CAAC,SAAS,CAAC;iBACpB;gBACD,OAAO,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,6BAA6B;oBAC1C,OAAO,EAAE,IAAI;iBACb;aACD;YACD,oBAAoB,EAAE,KAAK;SAC3B;KACD,CAAC;AACH,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@orgloop/transform-agent-gate",
3
+ "version": "0.1.8",
4
+ "description": "OrgLoop agent-gate transform — gates events on running agent sessions via agent-ctl",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "dependencies": {
9
+ "@orgloop/sdk": "0.1.8"
10
+ },
11
+ "orgloop": {
12
+ "type": "transform",
13
+ "id": "agent-gate"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "license": "MIT",
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "clean": "rm -rf dist",
25
+ "typecheck": "tsc --noEmit",
26
+ "test": "vitest run"
27
+ }
28
+ }