@elizaos/plugin-agent-orchestrator 0.3.6 → 0.3.7

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 (79) hide show
  1. package/dist/actions/coding-task-handlers.d.ts +46 -0
  2. package/dist/actions/coding-task-handlers.d.ts.map +1 -0
  3. package/dist/actions/coding-task-helpers.d.ts +27 -0
  4. package/dist/actions/coding-task-helpers.d.ts.map +1 -0
  5. package/dist/actions/finalize-workspace.d.ts +11 -0
  6. package/dist/actions/finalize-workspace.d.ts.map +1 -0
  7. package/dist/actions/list-agents.d.ts +11 -0
  8. package/dist/actions/list-agents.d.ts.map +1 -0
  9. package/dist/actions/manage-issues.d.ts +11 -0
  10. package/dist/actions/manage-issues.d.ts.map +1 -0
  11. package/dist/actions/provision-workspace.d.ts +11 -0
  12. package/dist/actions/provision-workspace.d.ts.map +1 -0
  13. package/dist/actions/send-to-agent.d.ts +11 -0
  14. package/dist/actions/send-to-agent.d.ts.map +1 -0
  15. package/dist/actions/spawn-agent.d.ts +11 -0
  16. package/dist/actions/spawn-agent.d.ts.map +1 -0
  17. package/dist/actions/start-coding-task.d.ts +17 -0
  18. package/dist/actions/start-coding-task.d.ts.map +1 -0
  19. package/dist/actions/stop-agent.d.ts +11 -0
  20. package/dist/actions/stop-agent.d.ts.map +1 -0
  21. package/dist/api/agent-routes.d.ts +18 -0
  22. package/dist/api/agent-routes.d.ts.map +1 -0
  23. package/dist/api/coordinator-routes.d.ts +22 -0
  24. package/dist/api/coordinator-routes.d.ts.map +1 -0
  25. package/dist/api/issue-routes.d.ts +17 -0
  26. package/dist/api/issue-routes.d.ts.map +1 -0
  27. package/dist/api/routes.d.ts +36 -0
  28. package/dist/api/routes.d.ts.map +1 -0
  29. package/dist/api/workspace-routes.d.ts +17 -0
  30. package/dist/api/workspace-routes.d.ts.map +1 -0
  31. package/dist/index.d.ts +33 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +14 -3
  34. package/dist/index.js.map +4 -4
  35. package/dist/providers/action-examples.d.ts +13 -0
  36. package/dist/providers/action-examples.d.ts.map +1 -0
  37. package/dist/providers/active-workspace-context.d.ts +13 -0
  38. package/dist/providers/active-workspace-context.d.ts.map +1 -0
  39. package/dist/services/agent-metrics.d.ts +28 -0
  40. package/dist/services/agent-metrics.d.ts.map +1 -0
  41. package/dist/services/agent-selection.d.ts +53 -0
  42. package/dist/services/agent-selection.d.ts.map +1 -0
  43. package/dist/services/ansi-utils.d.ts +48 -0
  44. package/dist/services/ansi-utils.d.ts.map +1 -0
  45. package/dist/services/pty-auto-response.d.ts +30 -0
  46. package/dist/services/pty-auto-response.d.ts.map +1 -0
  47. package/dist/services/pty-init.d.ts +47 -0
  48. package/dist/services/pty-init.d.ts.map +1 -0
  49. package/dist/services/pty-service.d.ts +92 -0
  50. package/dist/services/pty-service.d.ts.map +1 -0
  51. package/dist/services/pty-session-io.d.ts +49 -0
  52. package/dist/services/pty-session-io.d.ts.map +1 -0
  53. package/dist/services/pty-spawn.d.ts +50 -0
  54. package/dist/services/pty-spawn.d.ts.map +1 -0
  55. package/dist/services/pty-types.d.ts +80 -0
  56. package/dist/services/pty-types.d.ts.map +1 -0
  57. package/dist/services/stall-classifier.d.ts +67 -0
  58. package/dist/services/stall-classifier.d.ts.map +1 -0
  59. package/dist/services/swarm-coordinator-prompts.d.ts +75 -0
  60. package/dist/services/swarm-coordinator-prompts.d.ts.map +1 -0
  61. package/dist/services/swarm-coordinator.d.ts +200 -0
  62. package/dist/services/swarm-coordinator.d.ts.map +1 -0
  63. package/dist/services/swarm-decision-loop.d.ts +44 -0
  64. package/dist/services/swarm-decision-loop.d.ts.map +1 -0
  65. package/dist/services/swarm-event-triage.d.ts +49 -0
  66. package/dist/services/swarm-event-triage.d.ts.map +1 -0
  67. package/dist/services/swarm-idle-watchdog.d.ts +22 -0
  68. package/dist/services/swarm-idle-watchdog.d.ts.map +1 -0
  69. package/dist/services/workspace-git-ops.d.ts +28 -0
  70. package/dist/services/workspace-git-ops.d.ts.map +1 -0
  71. package/dist/services/workspace-github.d.ts +58 -0
  72. package/dist/services/workspace-github.d.ts.map +1 -0
  73. package/dist/services/workspace-lifecycle.d.ts +18 -0
  74. package/dist/services/workspace-lifecycle.d.ts.map +1 -0
  75. package/dist/services/workspace-service.d.ts +84 -0
  76. package/dist/services/workspace-service.d.ts.map +1 -0
  77. package/dist/services/workspace-types.d.ts +81 -0
  78. package/dist/services/workspace-types.d.ts.map +1 -0
  79. package/package.json +1 -1
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Provider that injects structured action call examples into the prompt context.
3
+ *
4
+ * ElizaOS core only shows exampleCalls from its static action-docs registry,
5
+ * which doesn't include custom plugin actions. This provider bridges the gap
6
+ * by formatting our coding agent action examples in the same structured format
7
+ * the model sees for core actions.
8
+ *
9
+ * @module providers/action-examples
10
+ */
11
+ import type { Provider } from "@elizaos/core";
12
+ export declare const codingAgentExamplesProvider: Provider;
13
+ //# sourceMappingURL=action-examples.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-examples.d.ts","sourceRoot":"","sources":["../../src/providers/action-examples.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAyB,QAAQ,EAAS,MAAM,eAAe,CAAC;AAyG5E,eAAO,MAAM,2BAA2B,EAAE,QAsCzC,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Provider that injects active workspace and session context into every prompt.
3
+ *
4
+ * Mima needs to know what workspaces exist, which agents are running, and their
5
+ * current status — without having to call LIST_AGENTS every message. This provider
6
+ * reads from both the workspace service and PTY service to build a live context
7
+ * summary that's always available in the prompt.
8
+ *
9
+ * @module providers/active-workspace-context
10
+ */
11
+ import type { Provider } from "@elizaos/core";
12
+ export declare const activeWorkspaceContextProvider: Provider;
13
+ //# sourceMappingURL=active-workspace-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"active-workspace-context.d.ts","sourceRoot":"","sources":["../../src/providers/active-workspace-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAyB,QAAQ,EAAS,MAAM,eAAe,CAAC;AA2C5E,eAAO,MAAM,8BAA8B,EAAE,QA+H5C,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Lightweight per-agent-type metrics for observability.
3
+ *
4
+ * Self-contained tracker — no dependencies on PTYService state.
5
+ *
6
+ * @module services/agent-metrics
7
+ */
8
+ export interface AgentMetrics {
9
+ spawned: number;
10
+ completed: number;
11
+ completedViaFastPath: number;
12
+ completedViaClassifier: number;
13
+ stallCount: number;
14
+ avgCompletionMs: number;
15
+ totalCompletionMs: number;
16
+ }
17
+ export declare class AgentMetricsTracker {
18
+ private metrics;
19
+ /** Get (or lazily initialize) metrics for a given agent type. */
20
+ get(agentType: string): AgentMetrics;
21
+ /** Record a task completion and update rolling average duration. */
22
+ recordCompletion(agentType: string, method: "fast-path" | "classifier", durationMs: number): void;
23
+ /** Increment the stall counter for an agent type. */
24
+ incrementStalls(agentType: string): void;
25
+ /** Return a serializable copy of all metrics (for API endpoints). */
26
+ getAll(): Record<string, Omit<AgentMetrics, "totalCompletionMs">>;
27
+ }
28
+ //# sourceMappingURL=agent-metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-metrics.d.ts","sourceRoot":"","sources":["../../src/services/agent-metrics.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,OAAO,CAAwC;IAEvD,iEAAiE;IACjE,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY;IAiBpC,oEAAoE;IACpE,gBAAgB,CACd,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,WAAW,GAAG,YAAY,EAClC,UAAU,EAAE,MAAM,GACjB,IAAI;IASP,qDAAqD;IACrD,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAIxC,qEAAqE;IACrE,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC;CAQlE"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Dynamic agent selection strategy.
3
+ *
4
+ * Chooses which coding-agent CLI to spawn when the caller does not
5
+ * specify an explicit `agentType`.
6
+ *
7
+ * - **fixed** — always returns `config.fixedAgentType`
8
+ * - **ranked** — scores each installed agent on success rate,
9
+ * stall frequency, and completion speed, then
10
+ * returns the highest-scoring one
11
+ *
12
+ * @module services/agent-selection
13
+ */
14
+ import type { AdapterType, PreflightResult } from "coding-agent-adapters";
15
+ export type AgentSelectionStrategy = "fixed" | "ranked";
16
+ /** Subset of AgentMetrics fields used for scoring. */
17
+ export interface AgentScoreInput {
18
+ spawned: number;
19
+ completed: number;
20
+ stallCount: number;
21
+ avgCompletionMs: number;
22
+ }
23
+ export interface AgentSelectionConfig {
24
+ strategy: AgentSelectionStrategy;
25
+ fixedAgentType: AdapterType;
26
+ }
27
+ export interface AgentSelectionContext {
28
+ config: AgentSelectionConfig;
29
+ /** Per-agent-type metrics snapshot (may be empty). */
30
+ metrics: Record<string, AgentScoreInput>;
31
+ /** Preflight results — only the `installed` ones are candidates. */
32
+ installedAgents: PreflightResult[];
33
+ }
34
+ /**
35
+ * Compute a 0–1 score for a single agent based on its metrics.
36
+ *
37
+ * - `successRate` = completed / spawned (0.5 neutral prior when no data)
38
+ * - `volumeWeight` = min(1, spawned / 5) — blends toward neutral at low N
39
+ * - `stallPenalty` = (stallCount / spawned) * 0.3
40
+ * - `speedPenalty` = min(avgCompletionMs / 300_000, 1) * 0.1 — weak tiebreaker
41
+ *
42
+ * Cold-start (no spawns): returns 0.5 so all agents are equal.
43
+ */
44
+ export declare function computeAgentScore(metrics: AgentScoreInput | undefined): number;
45
+ /**
46
+ * Select the best agent type given the current strategy, metrics, and
47
+ * installed agents.
48
+ *
49
+ * Explicit user choice (`params.agentType`) should be resolved by the
50
+ * caller *before* reaching this function.
51
+ */
52
+ export declare function selectAgentType(ctx: AgentSelectionContext): AdapterType;
53
+ //# sourceMappingURL=agent-selection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-selection.d.ts","sourceRoot":"","sources":["../../src/services/agent-selection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAG1E,MAAM,MAAM,sBAAsB,GAAG,OAAO,GAAG,QAAQ,CAAC;AAExD,sDAAsD;AACtD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,sBAAsB,CAAC;IACjC,cAAc,EAAE,WAAW,CAAC;CAC7B;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,oBAAoB,CAAC;IAC7B,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACzC,oEAAoE;IACpE,eAAe,EAAE,eAAe,EAAE,CAAC;CACpC;AAID;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,eAAe,GAAG,SAAS,GACnC,MAAM,CAaR;AAOD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,qBAAqB,GAAG,WAAW,CA8BvE"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * ANSI/terminal utility functions for processing PTY output.
3
+ *
4
+ * Pure functions — no state, no dependencies beyond the standard library.
5
+ *
6
+ * @module services/ansi-utils
7
+ */
8
+ /**
9
+ * Strip ANSI escape sequences from raw terminal output for readable text.
10
+ * Replaces cursor-forward codes with spaces (TUI uses these instead of actual spaces).
11
+ */
12
+ export declare function stripAnsi(raw: string): string;
13
+ /**
14
+ * Clean terminal output for display in chat messages.
15
+ *
16
+ * Goes beyond {@link stripAnsi} by also removing:
17
+ * - Unicode spinner/box-drawing/decorative characters from CLI TUIs
18
+ * - Lines that are only loading/thinking status text
19
+ * - Spinner status bar metadata (token counts, timing)
20
+ * - Consecutive blank lines (collapsed to one)
21
+ */
22
+ export declare function cleanForChat(raw: string): string;
23
+ /**
24
+ * Extract meaningful artifacts (PR URLs, commit hashes, key results) from raw
25
+ * terminal output. Returns a compact summary suitable for chat messages,
26
+ * without dumping raw TUI output.
27
+ */
28
+ export declare function extractCompletionSummary(raw: string): string;
29
+ /**
30
+ * Extract a dev server URL from recent terminal output, if present.
31
+ *
32
+ * Looks for common patterns like:
33
+ * - http://localhost:3000
34
+ * - http://127.0.0.1:8080
35
+ * - http://0.0.0.0:5173
36
+ * - https://localhost:4200
37
+ *
38
+ * Returns the first match, or null if no dev server URL is found.
39
+ */
40
+ export declare function extractDevServerUrl(raw: string): string | null;
41
+ /**
42
+ * Capture the agent's output since the last task was sent, cleaned for chat display.
43
+ * Returns readable text with TUI noise removed, or empty string if no marker exists.
44
+ *
45
+ * Mutates `markers` by deleting the entry for `sessionId` after capture.
46
+ */
47
+ export declare function captureTaskResponse(sessionId: string, buffers: Map<string, string[]>, markers: Map<string, number>): string;
48
+ //# sourceMappingURL=ansi-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ansi-utils.d.ts","sourceRoot":"","sources":["../../src/services/ansi-utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwCH;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAgBD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAoBhD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAmC5D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAO9D;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAC9B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3B,MAAM,CASR"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Auto-response rule management for PTY sessions.
3
+ *
4
+ * Contains logic for pushing default auto-response rules per agent type
5
+ * and handling Gemini authentication flow.
6
+ *
7
+ * @module services/pty-auto-response
8
+ */
9
+ import type { IAgentRuntime } from "@elizaos/core";
10
+ import type { BunCompatiblePTYManager, PTYManager } from "pty-manager";
11
+ export interface AutoResponseContext {
12
+ manager: PTYManager | BunCompatiblePTYManager;
13
+ usingBunWorker: boolean;
14
+ runtime: IAgentRuntime;
15
+ log: (msg: string) => void;
16
+ }
17
+ /**
18
+ * Push session-specific auto-response rules that depend on runtime config.
19
+ * Trust prompts, update notices, and other static rules are handled by
20
+ * adapter built-in rules (coding-agent-adapters). This only pushes rules
21
+ * that need runtime values (e.g. API keys).
22
+ */
23
+ export declare function pushDefaultRules(ctx: AutoResponseContext, sessionId: string, agentType: string): Promise<void>;
24
+ /**
25
+ * Handle Gemini authentication when login_required fires.
26
+ * Sends /auth to start the auth flow — auto-response rules
27
+ * then handle menu selection and API key input.
28
+ */
29
+ export declare function handleGeminiAuth(ctx: AutoResponseContext, sessionId: string, sendKeysToSession: (sessionId: string, keys: string | string[]) => Promise<void>): Promise<void>;
30
+ //# sourceMappingURL=pty-auto-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pty-auto-response.d.ts","sourceRoot":"","sources":["../../src/services/pty-auto-response.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAEV,uBAAuB,EACvB,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,UAAU,GAAG,uBAAuB,CAAC;IAC9C,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,aAAa,CAAC;IACvB,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,mBAAmB,EACxB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAwFf;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,mBAAmB,EACxB,SAAS,EAAE,MAAM,EACjB,iBAAiB,EAAE,CACjB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,KACpB,OAAO,CAAC,IAAI,CAAC,GACjB,OAAO,CAAC,IAAI,CAAC,CAwBf"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * PTY manager initialization — extracted from PTYService.initialize().
3
+ *
4
+ * Creates either a BunCompatiblePTYManager (for Bun runtime) or PTYManager
5
+ * (for Node), wires up event handlers, and returns the configured manager.
6
+ *
7
+ * @module services/pty-init
8
+ */
9
+ import { BunCompatiblePTYManager, PTYManager, type StallClassification } from "pty-manager";
10
+ import type { PTYServiceConfig } from "./pty-types.js";
11
+ /**
12
+ * All callbacks and state that the initialization logic needs
13
+ * from the surrounding PTYService instance.
14
+ */
15
+ export interface InitContext {
16
+ serviceConfig: PTYServiceConfig;
17
+ classifyStall: (sessionId: string, recentOutput: string) => Promise<StallClassification | null>;
18
+ emitEvent: (sessionId: string, event: string, data: unknown) => void;
19
+ handleGeminiAuth: (sessionId: string) => void;
20
+ sessionOutputBuffers: Map<string, string[]>;
21
+ taskResponseMarkers: Map<string, number>;
22
+ metricsTracker: {
23
+ recordCompletion(type: string, method: string, durationMs: number): void;
24
+ };
25
+ traceEntries: Array<string | Record<string, unknown>>;
26
+ maxTraceEntries: number;
27
+ log: (msg: string) => void;
28
+ /** Check if a session has an active task in the coordinator. */
29
+ hasActiveTask?: (sessionId: string) => boolean;
30
+ /** Check if a session's task has had any coordinator activity (decisions > 0). */
31
+ hasTaskActivity?: (sessionId: string) => boolean;
32
+ }
33
+ /** Value returned by {@link initializePTYManager}. */
34
+ export interface InitResult {
35
+ manager: PTYManager | BunCompatiblePTYManager;
36
+ usingBunWorker: boolean;
37
+ }
38
+ /**
39
+ * Create and configure a PTY manager for the current runtime.
40
+ *
41
+ * - **Bun**: instantiates a {@link BunCompatiblePTYManager} that spawns a
42
+ * Node worker process and communicates via JSON-RPC over stdio.
43
+ * - **Node**: instantiates a {@link PTYManager} directly and registers
44
+ * all built-in adapters in-process.
45
+ */
46
+ export declare function initializePTYManager(ctx: InitContext): Promise<InitResult>;
47
+ //# sourceMappingURL=pty-init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pty-init.d.ts","sourceRoot":"","sources":["../../src/services/pty-init.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EACL,uBAAuB,EAEvB,UAAU,EAKV,KAAK,mBAAmB,EAGzB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAcvD;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,gBAAgB,CAAC;IAChC,aAAa,EAAE,CACb,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,KACjB,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;IACzC,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACrE,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5C,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,cAAc,EAAE;QACd,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;KAC1E,CAAC;IACF,YAAY,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtD,eAAe,EAAE,MAAM,CAAC;IACxB,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3B,gEAAgE;IAChE,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;IAC/C,kFAAkF;IAClF,eAAe,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;CAClD;AA6BD,sDAAsD;AACtD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,UAAU,GAAG,uBAAuB,CAAC;IAC9C,cAAc,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,WAAW,GACf,OAAO,CAAC,UAAU,CAAC,CAsPrB"}
@@ -0,0 +1,92 @@
1
+ /** @module services/pty-service */
2
+ import { type IAgentRuntime } from "@elizaos/core";
3
+ import { type AdapterType, type AgentFileDescriptor, type ApprovalConfig, type ApprovalPreset, type PreflightResult, type WriteMemoryOptions } from "coding-agent-adapters";
4
+ import { PTYConsoleBridge } from "pty-console";
5
+ import type { SessionFilter, SessionMessage } from "pty-manager";
6
+ import { type AgentSelectionStrategy } from "./agent-selection.js";
7
+ import type { CodingAgentType, PTYServiceConfig, SessionEventCallback, SessionInfo, SpawnSessionOptions } from "./pty-types.js";
8
+ import { SwarmCoordinator } from "./swarm-coordinator.js";
9
+ export type { CodingAgentType, PTYServiceConfig, SessionEventName, SessionInfo, SpawnSessionOptions, } from "./pty-types.js";
10
+ export { normalizeAgentType } from "./pty-types.js";
11
+ /**
12
+ * Retrieve the SwarmCoordinator from the PTYService registered on the runtime.
13
+ * Returns undefined if PTYService or coordinator is not available.
14
+ */
15
+ export declare function getCoordinator(runtime: IAgentRuntime): SwarmCoordinator | undefined;
16
+ export declare class PTYService {
17
+ static serviceType: string;
18
+ capabilityDescription: string;
19
+ private runtime;
20
+ private manager;
21
+ private usingBunWorker;
22
+ private serviceConfig;
23
+ private sessionMetadata;
24
+ private sessionWorkdirs;
25
+ private eventCallbacks;
26
+ private outputUnsubscribers;
27
+ private sessionOutputBuffers;
28
+ private adapterCache;
29
+ /** Tracks the buffer index when a task was sent, so we can capture the response on completion */
30
+ private taskResponseMarkers;
31
+ /** Captures "Task completion trace" log entries from worker stderr (rolling, capped at 200) */
32
+ private traceEntries;
33
+ private static readonly MAX_TRACE_ENTRIES;
34
+ /** Lightweight per-agent-type metrics for observability */
35
+ private metricsTracker;
36
+ /** Console bridge for terminal output streaming and buffered hydration */
37
+ consoleBridge: PTYConsoleBridge | null;
38
+ /** Swarm coordinator instance (if active). Accessed via getCoordinator(runtime). */
39
+ coordinator: SwarmCoordinator | null;
40
+ constructor(runtime: IAgentRuntime, config?: PTYServiceConfig);
41
+ static start(runtime: IAgentRuntime): Promise<PTYService>;
42
+ static stopRuntime(runtime: IAgentRuntime): Promise<void>;
43
+ private initialize;
44
+ stop(): Promise<void>;
45
+ private generateSessionId;
46
+ /** Build a SessionIOContext from current instance state. */
47
+ private ioContext;
48
+ /**
49
+ * Spawn a new PTY session for a coding agent
50
+ */
51
+ spawnSession(options: SpawnSessionOptions): Promise<SessionInfo>;
52
+ private autoResponseContext;
53
+ private pushDefaultRules;
54
+ private handleGeminiAuth;
55
+ sendToSession(sessionId: string, input: string): Promise<SessionMessage | undefined>;
56
+ sendKeysToSession(sessionId: string, keys: string | string[]): Promise<void>;
57
+ stopSession(sessionId: string, force?: boolean): Promise<void>;
58
+ /** Default approval preset — runtime env var takes precedence over config. */
59
+ get defaultApprovalPreset(): ApprovalPreset;
60
+ /** Agent selection strategy — env var takes precedence. */
61
+ get agentSelectionStrategy(): AgentSelectionStrategy;
62
+ /** Default agent type when strategy is "fixed" — env var takes precedence. */
63
+ get defaultAgentType(): AdapterType;
64
+ /**
65
+ * Resolve which agent type to use when the caller didn't specify one.
66
+ *
67
+ * - **fixed**: returns `defaultAgentType` immediately
68
+ * - **ranked**: fetches preflight data, scores installed agents via
69
+ * metrics, and returns the highest scorer
70
+ */
71
+ resolveAgentType(): Promise<string>;
72
+ getSession(sessionId: string): SessionInfo | undefined;
73
+ listSessions(filter?: SessionFilter): Promise<SessionInfo[]>;
74
+ subscribeToOutput(sessionId: string, callback: (data: string) => void): () => void;
75
+ getSessionOutput(sessionId: string, lines?: number): Promise<string>;
76
+ isSessionBlocked(sessionId: string): boolean;
77
+ checkAvailableAgents(types?: AdapterType[]): Promise<PreflightResult[]>;
78
+ getSupportedAgentTypes(): CodingAgentType[];
79
+ private classifyStall;
80
+ private getAdapter;
81
+ getWorkspaceFiles(agentType: AdapterType): AgentFileDescriptor[];
82
+ getMemoryFilePath(agentType: AdapterType): string;
83
+ getApprovalConfig(agentType: AdapterType, preset: ApprovalPreset): ApprovalConfig;
84
+ writeMemoryFile(agentType: AdapterType, workspacePath: string, content: string, options?: WriteMemoryOptions): Promise<string>;
85
+ onSessionEvent(callback: SessionEventCallback): () => void;
86
+ registerAdapter(adapter: unknown): void;
87
+ private toSessionInfo;
88
+ private emitEvent;
89
+ getAgentMetrics(): Record<string, Omit<import("./agent-metrics.js").AgentMetrics, "totalCompletionMs">>;
90
+ private log;
91
+ }
92
+ //# sourceMappingURL=pty-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pty-service.d.ts","sourceRoot":"","sources":["../../src/services/pty-service.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAInC,OAAO,EAAE,KAAK,aAAa,EAAwB,MAAM,eAAe,CAAC;AACzE,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,cAAc,EAKnB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAGV,aAAa,EAEb,cAAc,EAIf,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,sBAAsB,CAAC;AAmB9B,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,aAAa,GACrB,gBAAgB,GAAG,SAAS,CAK9B;AAED,qBAAa,UAAU;IACrB,MAAM,CAAC,WAAW,SAAiB;IACnC,qBAAqB,SAAgD;IAErE,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,OAAO,CAAqD;IACpE,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,aAAa,CAAmB;IACxC,OAAO,CAAC,eAAe,CAA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O,GAAG,IAAI;IAkBvC,OAAO,CAAC,aAAa;IA2BrB,OAAO,CAAC,SAAS;IAYjB,eAAe;IAIf,OAAO,CAAC,GAAG;CAKZ"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Session I/O helpers — extracted from PTYService for maintainability.
3
+ *
4
+ * Standalone functions for sending input/keys to sessions and stopping
5
+ * sessions. Each function takes a {@link SessionIOContext} that provides
6
+ * the manager instance and shared state maps.
7
+ *
8
+ * @module services/pty-session-io
9
+ */
10
+ import type { BunCompatiblePTYManager, PTYManager, SessionMessage } from "pty-manager";
11
+ /**
12
+ * Shared context required by all session I/O functions.
13
+ * Built inline from PTYService instance fields.
14
+ */
15
+ export interface SessionIOContext {
16
+ manager: PTYManager | BunCompatiblePTYManager;
17
+ usingBunWorker: boolean;
18
+ sessionOutputBuffers: Map<string, string[]>;
19
+ taskResponseMarkers: Map<string, number>;
20
+ outputUnsubscribers: Map<string, () => void>;
21
+ }
22
+ /**
23
+ * Send text input to a session.
24
+ *
25
+ * Marks the buffer position for task response capture, then writes the
26
+ * input via the appropriate manager API.
27
+ */
28
+ export declare function sendToSession(ctx: SessionIOContext, sessionId: string, input: string): Promise<SessionMessage | undefined>;
29
+ /**
30
+ * Send key sequences to a session (for special keys like arrows, enter, etc.).
31
+ */
32
+ export declare function sendKeysToSession(ctx: SessionIOContext, sessionId: string, keys: string | string[]): Promise<void>;
33
+ /**
34
+ * Stop a PTY session and clean up all associated state.
35
+ *
36
+ * @param force - When true, sends SIGKILL immediately instead of SIGTERM.
37
+ * Use for sessions whose task is already complete — there's nothing to save.
38
+ */
39
+ export declare function stopSession(ctx: SessionIOContext, sessionId: string, sessionMetadata: Map<string, Record<string, unknown>>, sessionWorkdirs: Map<string, string>, log: (msg: string) => void, force?: boolean): Promise<void>;
40
+ /**
41
+ * Subscribe to live output from a session.
42
+ * Returns an unsubscribe function.
43
+ */
44
+ export declare function subscribeToOutput(ctx: SessionIOContext, sessionId: string, callback: (data: string) => void): () => void;
45
+ /**
46
+ * Get buffered or logged output from a session.
47
+ */
48
+ export declare function getSessionOutput(ctx: SessionIOContext, sessionId: string, lines?: number): Promise<string>;
49
+ //# sourceMappingURL=pty-session-io.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pty-session-io.d.ts","sourceRoot":"","sources":["../../src/services/pty-session-io.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,uBAAuB,EACvB,UAAU,EACV,cAAc,EACf,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,UAAU,GAAG,uBAAuB,CAAC;IAC9C,cAAc,EAAE,OAAO,CAAC;IACxB,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5C,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC;CAC9C;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,gBAAgB,EACrB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAoBrC;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,gBAAgB,EACrB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GACtB,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,gBAAgB,EACrB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACrD,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,EAC1B,KAAK,UAAQ,GACZ,OAAO,CAAC,IAAI,CAAC,CA0Cf;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,gBAAgB,EACrB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC/B,MAAM,IAAI,CAiBZ;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,gBAAgB,EACrB,SAAS,EAAE,MAAM,EACjB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAejB"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * PTY session spawning logic — extracted from PTYService for maintainability.
3
+ *
4
+ * Contains the deferred task delivery, retry logic, per-agent settle delays,
5
+ * and session buffer setup that runs during spawnSession().
6
+ *
7
+ * @module services/pty-spawn
8
+ */
9
+ import type { AdapterType, BaseCodingAdapter } from "coding-agent-adapters";
10
+ import type { BunCompatiblePTYManager, PTYManager, SessionHandle, SpawnConfig, WorkerSessionHandle } from "pty-manager";
11
+ import type { PTYServiceConfig, SessionInfo, SpawnSessionOptions } from "./pty-types.js";
12
+ /**
13
+ * Build a sanitized base environment from process.env, keeping only
14
+ * safe system variables. Agent-specific credentials are injected
15
+ * separately by the adapter's getEnv().
16
+ */
17
+ export declare function buildSanitizedBaseEnv(): Record<string, string>;
18
+ export interface SpawnContext {
19
+ manager: PTYManager | BunCompatiblePTYManager;
20
+ usingBunWorker: boolean;
21
+ serviceConfig: PTYServiceConfig;
22
+ sessionMetadata: Map<string, Record<string, unknown>>;
23
+ sessionWorkdirs: Map<string, string>;
24
+ sessionOutputBuffers: Map<string, string[]>;
25
+ outputUnsubscribers: Map<string, () => void>;
26
+ taskResponseMarkers: Map<string, number>;
27
+ getAdapter: (agentType: AdapterType) => BaseCodingAdapter;
28
+ sendToSession: (sessionId: string, input: string) => Promise<unknown>;
29
+ sendKeysToSession: (sessionId: string, keys: string | string[]) => Promise<void>;
30
+ pushDefaultRules: (sessionId: string, agentType: string) => Promise<void>;
31
+ toSessionInfo: (session: SessionHandle | WorkerSessionHandle, workdir?: string) => SessionInfo;
32
+ log: (msg: string) => void;
33
+ }
34
+ /**
35
+ * Set up session output buffering for Bun worker path.
36
+ */
37
+ export declare function setupOutputBuffer(ctx: SpawnContext, sessionId: string): void;
38
+ /**
39
+ * Set up deferred task delivery with retry logic.
40
+ * IMPORTANT: Must be called BEFORE pushDefaultRules (which has a 1500ms sleep),
41
+ * otherwise session_ready fires during pushDefaultRules and the listener misses it.
42
+ */
43
+ export declare function setupDeferredTaskDelivery(ctx: SpawnContext, session: SessionHandle | WorkerSessionHandle, task: string, agentType: string): void;
44
+ /**
45
+ * Build the SpawnConfig and env vars from SpawnSessionOptions.
46
+ */
47
+ export declare function buildSpawnConfig(sessionId: string, options: SpawnSessionOptions, workdir: string): SpawnConfig & {
48
+ id: string;
49
+ };
50
+ //# sourceMappingURL=pty-spawn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pty-spawn.d.ts","sourceRoot":"","sources":["../../src/services/pty-spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,KAAK,EACV,uBAAuB,EACvB,UAAU,EACV,aAAa,EACb,WAAW,EACX,mBAAmB,EACpB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAsBxB;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAO9D;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,UAAU,GAAG,uBAAuB,CAAC;IAC9C,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,gBAAgB,CAAC;IAChC,eA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AAM,EACjB,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,MAAM,GACd,WAAW,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CA2C9B"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Shared types and helpers for the PTY service layer.
3
+ *
4
+ * Extracted from pty-service.ts to keep that module lean and allow
5
+ * other modules (pty-spawn, pty-init, actions) to import lightweight
6
+ * type-only dependencies without pulling in the full PTYService class.
7
+ *
8
+ * @module services/pty-types
9
+ */
10
+ import type { AdapterType, AgentCredentials, ApprovalPreset } from "coding-agent-adapters";
11
+ import type { SessionHandle } from "pty-manager";
12
+ export interface PTYServiceConfig {
13
+ /** Maximum output lines to keep per session (default: 1000) */
14
+ maxLogLines?: number;
15
+ /** Enable debug logging */
16
+ debug?: boolean;
17
+ /** Auto-register coding agent adapters (default: true) */
18
+ registerCodingAdapters?: boolean;
19
+ /** Maximum concurrent PTY sessions (default: 8) */
20
+ maxConcurrentSessions?: number;
21
+ /**
22
+ * Default approval preset for coding agents when not specified per-spawn.
23
+ * Controls what tools the agent can use without asking for permission.
24
+ * - "readonly" — Read-only tools only
25
+ * - "standard" — Read + write, asks for shell/network
26
+ * - "permissive" — Most tools auto-approved, asks for destructive ops
27
+ * - "autonomous" — All tools auto-approved (yolo mode)
28
+ * Default: "permissive"
29
+ */
30
+ defaultApprovalPreset?: ApprovalPreset;
31
+ }
32
+ /** Available coding agent types */
33
+ export type CodingAgentType = "shell" | "pi" | AdapterType;
34
+ /** True when the user requested the Pi coding agent. */
35
+ export declare const isPiAgentType: (input: string | undefined | null) => boolean;
36
+ /** Normalize user-provided agent type string to a valid CodingAgentType */
37
+ export declare const normalizeAgentType: (input: string) => CodingAgentType;
38
+ /** Build the initial shell command for Pi agent sessions. */
39
+ export declare const toPiCommand: (task: string | undefined) => string;
40
+ export interface SpawnSessionOptions {
41
+ /** Human-readable session name */
42
+ name: string;
43
+ /** Adapter type: "shell" | "pi" | "claude" | "gemini" | "codex" | "aider" */
44
+ agentType: CodingAgentType;
45
+ /** Working directory for the session */
46
+ workdir?: string;
47
+ /** Initial command/task to send */
48
+ initialTask?: string;
49
+ /** Environment variables */
50
+ env?: Record<string, string>;
51
+ /** Session metadata for tracking */
52
+ metadata?: Record<string, unknown>;
53
+ /** Credentials for coding agents (API keys, tokens) */
54
+ credentials?: AgentCredentials;
55
+ /** Memory/instructions content to write to the agent's memory file before spawning */
56
+ memoryContent?: string;
57
+ /** Approval preset controlling tool permissions (readonly, standard, permissive, autonomous) */
58
+ approvalPreset?: ApprovalPreset;
59
+ /** Custom credentials for MCP servers or other integrations */
60
+ customCredentials?: Record<string, string>;
61
+ /** When true, adapter-level blocking prompts (tool permissions, file access)
62
+ * are emitted with autoResponded=false instead of being auto-handled.
63
+ * Used by the swarm coordinator to route decisions through its LLM loop. */
64
+ skipAdapterAutoResponse?: boolean;
65
+ }
66
+ export interface SessionInfo {
67
+ id: string;
68
+ name: string;
69
+ agentType: string;
70
+ workdir: string;
71
+ status: SessionHandle["status"];
72
+ createdAt: Date;
73
+ lastActivityAt: Date;
74
+ metadata?: Record<string, unknown>;
75
+ }
76
+ /** Known event names emitted by the PTY layer. */
77
+ export type SessionEventName = "ready" | "blocked" | "login_required" | "task_complete" | "tool_running" | "stopped" | "error" | "message";
78
+ type SessionEventCallback = (sessionId: string, event: string, data: unknown) => void;
79
+ export type { SessionEventCallback };
80
+ //# sourceMappingURL=pty-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pty-types.d.ts","sourceRoot":"","sources":["../../src/services/pty-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,cAAc,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,WAAW,gBAAgB;IAC/B,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2B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OAAO,CAAC;CACnC;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChC,SAAS,EAAE,IAAI,CAAC;IAChB,cAAc,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,kDAAkD;AAClD,MAAM,MAAM,gBAAgB,GACxB,OAAO,GACP,SAAS,GACT,gBAAgB,GAChB,eAAe,GACf,cAAc,GACd,SAAS,GACT,OAAO,GACP,SAAS,CAAC;AAEd,KAAK,oBAAoB,GAAG,CAC1B,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,OAAO,KACV,IAAI,CAAC;AAEV,YAAY,EAAE,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Stall classification subsystem — determines what a "stalled" coding agent
3
+ * session is doing (finished, waiting for input, still working, or errored).
4
+ *
5
+ * Extracted as standalone functions that receive dependencies as parameters,
6
+ * making them easy to test without coupling to PTYService.
7
+ *
8
+ * @module services/stall-classifier
9
+ */
10
+ import { type IAgentRuntime } from "@elizaos/core";
11
+ import { type StallClassification } from "pty-manager";
12
+ import type { AgentMetricsTracker } from "./agent-metrics.js";
13
+ import type { TaskContextSummary, DecisionHistoryEntry } from "./swarm-coordinator-prompts.js";
14
+ /** Everything the classifier needs, passed in from PTYService. */
15
+ export interface StallClassifierContext {
16
+ sessionId: string;
17
+ recentOutput: string;
18
+ agentType: string;
19
+ buffers: Map<string, string[]>;
20
+ traceEntries: Array<string | Record<string, unknown>>;
21
+ runtime: IAgentRuntime;
22
+ manager: {
23
+ get(id: string): {
24
+ startedAt?: string | Date;
25
+ } | null | undefined;
26
+ } | null;
27
+ metricsTracker: AgentMetricsTracker;
28
+ /** Write debug snapshots to ~/.milady/debug/ on stall (default: false) */
29
+ debugSnapshots?: boolean;
30
+ log: (msg: string) => void;
31
+ }
32
+ /**
33
+ * Build the LLM system prompt used to classify stalled output.
34
+ */
35
+ export declare function buildStallClassificationPrompt(agentType: string, sessionId: string, output: string): string;
36
+ /**
37
+ * Write a debug snapshot to ~/.milady/debug/ for offline stall analysis.
38
+ */
39
+ export declare function writeStallSnapshot(sessionId: string, agentType: string, recentOutput: string, effectiveOutput: string, buffers: Map<string, string[]>, traceEntries: Array<string | Record<string, unknown>>, log: (msg: string) => void): Promise<void>;
40
+ /**
41
+ * Main stall classification logic. Determines what a stalled session is doing
42
+ * by checking the buffer, building a prompt, and asking the LLM.
43
+ */
44
+ export declare function classifyStallOutput(ctx: StallClassifierContext): Promise<StallClassification | null>;
45
+ /** Context for the combined classify-and-decide call. */
46
+ export interface CoordinatorClassifyContext extends StallClassifierContext {
47
+ taskContext: TaskContextSummary;
48
+ decisionHistory?: DecisionHistoryEntry[];
49
+ }
50
+ /**
51
+ * Build a combined prompt that classifies the stall AND decides how to respond,
52
+ * merging stall classification with coordinator decision guidelines.
53
+ *
54
+ * Used for coordinator-managed sessions in autonomous mode to eliminate the
55
+ * redundant second LLM call in the coordinator's handleBlocked path.
56
+ */
57
+ export declare function buildCombinedClassifyDecidePrompt(agentType: string, sessionId: string, output: string, taskContext: TaskContextSummary, decisionHistory: DecisionHistoryEntry[]): string;
58
+ /**
59
+ * Combined classify-and-decide for coordinator-managed autonomous sessions.
60
+ *
61
+ * Performs classification AND coordinator-quality response decision in a single
62
+ * LLM call. The suggestedResponse is kept intact (not stripped), so pty-manager
63
+ * auto-responds and the coordinator receives autoResponded: true — skipping
64
+ * the second LLM call in handleBlocked().
65
+ */
66
+ export declare function classifyAndDecideForCoordinator(ctx: CoordinatorClassifyContext): Promise<StallClassification | null>;
67
+ //# sourceMappingURL=stall-classifier.d.ts.map
@@ -0,0 +1 @@
1
+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