@bastani/atomic 0.5.2 → 0.5.3-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-1gb5qxz9.js +1 -0
- package/dist/chunk-fdk7tact.js +417 -0
- package/dist/chunk-mn870nrv.js +982 -0
- package/dist/sdk/components/color-utils.d.ts +3 -0
- package/dist/sdk/components/connectors.d.ts +14 -0
- package/dist/sdk/components/connectors.test.d.ts +1 -0
- package/dist/sdk/components/edge.d.ts +3 -0
- package/dist/sdk/components/error-boundary.d.ts +22 -0
- package/dist/sdk/components/graph-theme.d.ts +16 -0
- package/dist/sdk/components/header.d.ts +2 -0
- package/dist/sdk/components/layout.d.ts +26 -0
- package/dist/sdk/components/layout.test.d.ts +1 -0
- package/dist/sdk/components/node-card.d.ts +8 -0
- package/dist/sdk/components/orchestrator-panel-contexts.d.ts +15 -0
- package/dist/sdk/components/orchestrator-panel-store.d.ts +35 -0
- package/dist/sdk/components/orchestrator-panel-store.test.d.ts +1 -0
- package/dist/sdk/components/orchestrator-panel-types.d.ts +16 -0
- package/dist/sdk/components/orchestrator-panel.d.ts +51 -0
- package/dist/sdk/components/session-graph-panel.d.ts +6 -0
- package/dist/sdk/components/status-helpers.d.ts +5 -0
- package/dist/sdk/components/statusline.d.ts +6 -0
- package/dist/sdk/define-workflow.d.ts +77 -0
- package/dist/sdk/define-workflow.test.d.ts +1 -0
- package/dist/sdk/errors.d.ts +21 -0
- package/dist/sdk/index.d.ts +12 -0
- package/dist/sdk/index.js +52 -0
- package/dist/sdk/providers/claude.d.ts +159 -0
- package/dist/sdk/providers/copilot.d.ts +14 -0
- package/dist/sdk/providers/opencode.d.ts +14 -0
- package/dist/sdk/runtime/discovery.d.ts +31 -0
- package/dist/sdk/runtime/executor-entry.d.ts +10 -0
- package/dist/sdk/runtime/executor.d.ts +61 -0
- package/dist/sdk/runtime/executor.test.d.ts +1 -0
- package/dist/sdk/runtime/graph-inference.d.ts +34 -0
- package/dist/sdk/runtime/loader.d.ts +72 -0
- package/dist/sdk/runtime/panel.d.ts +8 -0
- package/dist/sdk/runtime/theme.d.ts +27 -0
- package/dist/sdk/runtime/tmux.d.ts +191 -0
- package/dist/sdk/types.d.ts +214 -0
- package/dist/sdk/workflows/builtin/ralph/claude/index.d.ts +13 -0
- package/dist/sdk/workflows/builtin/ralph/claude/index.js +95 -0
- package/dist/sdk/workflows/builtin/ralph/copilot/index.d.ts +13 -0
- package/dist/sdk/workflows/builtin/ralph/copilot/index.js +118 -0
- package/dist/sdk/workflows/builtin/ralph/helpers/git.d.ts +16 -0
- package/dist/sdk/workflows/builtin/ralph/helpers/prompts.d.ts +118 -0
- package/dist/sdk/workflows/builtin/ralph/helpers/review.d.ts +19 -0
- package/dist/sdk/workflows/builtin/ralph/opencode/index.d.ts +13 -0
- package/dist/sdk/workflows/builtin/ralph/opencode/index.js +147 -0
- package/dist/sdk/workflows/index.d.ts +24 -0
- package/dist/sdk/workflows/index.js +94 -0
- package/package.json +33 -6
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow runtime executor.
|
|
3
|
+
*
|
|
4
|
+
* Architecture:
|
|
5
|
+
* 1. `executeWorkflow()` is called by the CLI command
|
|
6
|
+
* 2. It creates a tmux session with an orchestrator pane that runs
|
|
7
|
+
* `bun run executor-entry.ts` (a thin wrapper that calls `runOrchestrator()`)
|
|
8
|
+
* 3. The CLI then attaches to the tmux session (user sees it live)
|
|
9
|
+
* 4. The orchestrator pane calls `definition.run(workflowCtx)` — the
|
|
10
|
+
* user's callback uses `ctx.stage()` to spawn agent sessions
|
|
11
|
+
*
|
|
12
|
+
* The entry point is in executor-entry.ts (not this file) to avoid Bun's
|
|
13
|
+
* dual-module-identity issue: Bun evaluates a file twice when it is both
|
|
14
|
+
* the entry point and reached through package.json `exports` self-referencing.
|
|
15
|
+
*/
|
|
16
|
+
import type { WorkflowDefinition, AgentType, SavedMessage } from "../types.js";
|
|
17
|
+
export interface WorkflowRunOptions {
|
|
18
|
+
/** The compiled workflow definition */
|
|
19
|
+
definition: WorkflowDefinition;
|
|
20
|
+
/** Agent type */
|
|
21
|
+
agent: AgentType;
|
|
22
|
+
/** The user's prompt */
|
|
23
|
+
prompt: string;
|
|
24
|
+
/** Absolute path to the workflow's index.ts file (from discovery) */
|
|
25
|
+
workflowFile: string;
|
|
26
|
+
/** Project root (defaults to cwd) */
|
|
27
|
+
projectRoot?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Escape a string for safe interpolation inside a bash double-quoted string.
|
|
31
|
+
*
|
|
32
|
+
* In bash `"..."` strings only `$`, `` ` ``, `\`, `"`, and `!` are special.
|
|
33
|
+
* Single quotes are literal inside double quotes and need no escaping.
|
|
34
|
+
* Null bytes are stripped because bash strings cannot contain them.
|
|
35
|
+
*/
|
|
36
|
+
export declare function escBash(s: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Escape a string for safe interpolation inside a PowerShell double-quoted string.
|
|
39
|
+
*
|
|
40
|
+
* In PowerShell `"..."` strings, backtick is the escape character and `$` triggers
|
|
41
|
+
* variable expansion. Null bytes are stripped for safety.
|
|
42
|
+
*/
|
|
43
|
+
export declare function escPwsh(s: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Called by `atomic workflow -n <name> -a <agent> <prompt>`.
|
|
46
|
+
*
|
|
47
|
+
* Creates a tmux session with the orchestrator as the initial pane,
|
|
48
|
+
* then attaches so the user sees everything live.
|
|
49
|
+
*/
|
|
50
|
+
export declare function executeWorkflow(options: WorkflowRunOptions): Promise<void>;
|
|
51
|
+
/** Type guard for objects with a string `content` property (Copilot assistant.message data). */
|
|
52
|
+
export declare function hasContent(value: unknown): value is {
|
|
53
|
+
content: string;
|
|
54
|
+
};
|
|
55
|
+
/** Type guard for Claude message objects whose `content` is an array of text blocks. */
|
|
56
|
+
export declare function isTextBlockArray(value: unknown): value is Array<{
|
|
57
|
+
type: "text";
|
|
58
|
+
text: string;
|
|
59
|
+
}>;
|
|
60
|
+
export declare function renderMessagesToText(messages: SavedMessage[]): string;
|
|
61
|
+
export declare function runOrchestrator(): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frontier-based graph inference for workflow stage topology.
|
|
3
|
+
*
|
|
4
|
+
* Automatically infers parent-child edges from JavaScript's execution order:
|
|
5
|
+
* - **Sequential** (`await`): completed stages are in the frontier when the
|
|
6
|
+
* next stage spawns → parent-child edge.
|
|
7
|
+
* - **Parallel** (`Promise.all`): both calls fire in the same synchronous
|
|
8
|
+
* frame → frontier is empty for the second call → sibling edges.
|
|
9
|
+
* - **Fan-in**: after `Promise.all` resolves, all parallel stages are in the
|
|
10
|
+
* frontier → the next stage depends on all of them.
|
|
11
|
+
*/
|
|
12
|
+
export declare class GraphFrontierTracker {
|
|
13
|
+
/**
|
|
14
|
+
* Stages that completed since the last stage was spawned in this scope.
|
|
15
|
+
* When non-empty at spawn time, the new stage is sequential (depends on frontier).
|
|
16
|
+
*/
|
|
17
|
+
private frontier;
|
|
18
|
+
/**
|
|
19
|
+
* The parent set for the current parallel batch — a snapshot of the frontier
|
|
20
|
+
* at the point the first sibling consumed it.
|
|
21
|
+
*/
|
|
22
|
+
private parallelAncestors;
|
|
23
|
+
constructor(parentName: string);
|
|
24
|
+
/**
|
|
25
|
+
* Called synchronously when a new stage is spawned.
|
|
26
|
+
* Returns the inferred graph parents for this stage.
|
|
27
|
+
*/
|
|
28
|
+
onSpawn(): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Called when a stage settles (completes or fails).
|
|
31
|
+
* Adds the stage to the frontier so the next spawn can chain from it.
|
|
32
|
+
*/
|
|
33
|
+
onSettle(name: string): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Loader — multi-stage pipeline for resolving and loading workflows.
|
|
3
|
+
*
|
|
4
|
+
* Pipeline: Discover → Resolve → Validate → Load
|
|
5
|
+
*
|
|
6
|
+
* Each stage returns a typed discriminated result so callers get structured
|
|
7
|
+
* error information without try/catch guesswork.
|
|
8
|
+
*
|
|
9
|
+
* Discovery (finding workflow files on disk) remains in `discovery.ts`.
|
|
10
|
+
* This module handles everything after a workflow is discovered.
|
|
11
|
+
*/
|
|
12
|
+
import type { WorkflowDefinition } from "../types.js";
|
|
13
|
+
import type { DiscoveredWorkflow } from "./discovery.js";
|
|
14
|
+
export declare namespace WorkflowLoader {
|
|
15
|
+
/** Successful pipeline result. */
|
|
16
|
+
type Ok<T> = {
|
|
17
|
+
ok: true;
|
|
18
|
+
value: T;
|
|
19
|
+
};
|
|
20
|
+
/** Failed pipeline result with stage and error context. */
|
|
21
|
+
type StageError<S extends string> = {
|
|
22
|
+
ok: false;
|
|
23
|
+
stage: S;
|
|
24
|
+
error: unknown;
|
|
25
|
+
message: string;
|
|
26
|
+
};
|
|
27
|
+
type StageResult<T, S extends string> = Ok<T> | StageError<S>;
|
|
28
|
+
/** Input to the pipeline — a discovered workflow from disk. */
|
|
29
|
+
type Plan = DiscoveredWorkflow;
|
|
30
|
+
/** Output of the resolve stage. */
|
|
31
|
+
type Resolved = Plan;
|
|
32
|
+
/** A source validation warning (agent-specific). */
|
|
33
|
+
interface ValidationWarning {
|
|
34
|
+
rule: string;
|
|
35
|
+
message: string;
|
|
36
|
+
}
|
|
37
|
+
/** Output of the validate stage. */
|
|
38
|
+
type Validated = Resolved & {
|
|
39
|
+
warnings: ValidationWarning[];
|
|
40
|
+
};
|
|
41
|
+
/** Output of the load stage — the final result. */
|
|
42
|
+
type Loaded = Validated & {
|
|
43
|
+
definition: WorkflowDefinition;
|
|
44
|
+
};
|
|
45
|
+
interface Report {
|
|
46
|
+
/** Called when a stage begins. */
|
|
47
|
+
start?: (stage: "resolve" | "validate" | "load") => void;
|
|
48
|
+
/** Called when source validation produces warnings. */
|
|
49
|
+
warn?: (warnings: ValidationWarning[]) => void;
|
|
50
|
+
/** Called when a stage fails. */
|
|
51
|
+
error?: (stage: "resolve" | "validate" | "load", error: unknown, message: string) => void;
|
|
52
|
+
}
|
|
53
|
+
/** Verify the workflow file exists. */
|
|
54
|
+
function resolve(plan: Plan): Promise<StageResult<Resolved, "resolve">>;
|
|
55
|
+
/**
|
|
56
|
+
* Read the workflow source and run agent-specific validation checks.
|
|
57
|
+
* Validation warnings are non-fatal — the pipeline continues.
|
|
58
|
+
*/
|
|
59
|
+
function validate(resolved: Resolved): Promise<StageResult<Validated, "validate">>;
|
|
60
|
+
/**
|
|
61
|
+
* Import the workflow module and extract the WorkflowDefinition.
|
|
62
|
+
* Checks for common authoring mistakes (missing `.compile()`, wrong export).
|
|
63
|
+
*/
|
|
64
|
+
function load(validated: Validated): Promise<StageResult<Loaded, "load">>;
|
|
65
|
+
/**
|
|
66
|
+
* Run the full pipeline: resolve → validate → load.
|
|
67
|
+
*
|
|
68
|
+
* Returns a structured result with the loaded WorkflowDefinition on success,
|
|
69
|
+
* or a stage-specific error on failure.
|
|
70
|
+
*/
|
|
71
|
+
function loadWorkflow(plan: Plan, report?: Report): Promise<StageResult<Loaded, "resolve" | "validate" | "load">>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenTUI React-based orchestrator panel with session graph view.
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports the public API from the components/ directory.
|
|
5
|
+
* Internal implementation is modularized under ../components/.
|
|
6
|
+
*/
|
|
7
|
+
export { OrchestratorPanel } from "../components/orchestrator-panel.js";
|
|
8
|
+
export type { PanelSession, PanelOptions } from "../components/orchestrator-panel-types.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal color theme using Catppuccin palettes.
|
|
3
|
+
*
|
|
4
|
+
* Uses OpenTUI's built-in dark/light mode detection (via the renderer's
|
|
5
|
+
* themeMode property) to select the appropriate palette:
|
|
6
|
+
* - Mocha for dark terminals (and as fallback)
|
|
7
|
+
* - Latte for light terminals
|
|
8
|
+
*/
|
|
9
|
+
import type { ThemeMode } from "@opentui/core";
|
|
10
|
+
export interface TerminalTheme {
|
|
11
|
+
bg: string;
|
|
12
|
+
surface: string;
|
|
13
|
+
selection: string;
|
|
14
|
+
border: string;
|
|
15
|
+
borderDim: string;
|
|
16
|
+
accent: string;
|
|
17
|
+
text: string;
|
|
18
|
+
dim: string;
|
|
19
|
+
success: string;
|
|
20
|
+
error: string;
|
|
21
|
+
warning: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the terminal theme from the renderer's detected theme mode.
|
|
25
|
+
* Returns Catppuccin Latte for light terminals, Mocha for dark or unknown.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveTheme(mode: ThemeMode | null): TerminalTheme;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tmux session and pane management utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides low-level tmux operations for the workflow runtime:
|
|
5
|
+
* creating sessions, splitting panes, spawning commands, capturing output,
|
|
6
|
+
* sending keystrokes, and pane state detection.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the terminal multiplexer binary for the current platform.
|
|
10
|
+
*
|
|
11
|
+
* On Windows, tries psmux → pmux → tmux (psmux ships all three as aliases).
|
|
12
|
+
* On Unix/macOS, uses tmux directly.
|
|
13
|
+
*
|
|
14
|
+
* Returns the binary name (not the full path) or null if none is found.
|
|
15
|
+
* The result is cached after the first call.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getMuxBinary(): string | null;
|
|
18
|
+
/**
|
|
19
|
+
* Reset the cached multiplexer binary resolution.
|
|
20
|
+
* Call after installing tmux/psmux to force re-detection.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resetMuxBinaryCache(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Check if tmux is installed and available.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isTmuxInstalled(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Check if we're currently inside a tmux session.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isInsideTmux(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Run a tmux command and return a result object.
|
|
33
|
+
* Prefers this over the throwing `tmux()` for cases where callers
|
|
34
|
+
* need to handle failure gracefully.
|
|
35
|
+
*/
|
|
36
|
+
export declare function tmuxRun(args: string[]): {
|
|
37
|
+
ok: true;
|
|
38
|
+
stdout: string;
|
|
39
|
+
} | {
|
|
40
|
+
ok: false;
|
|
41
|
+
stderr: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Create a new tmux session with the given name.
|
|
45
|
+
* The session starts detached with an initial command in the first pane.
|
|
46
|
+
*
|
|
47
|
+
* @param sessionName - Unique session name
|
|
48
|
+
* @param initialCommand - Shell command to run in the initial pane
|
|
49
|
+
* @param windowName - Optional name for the initial window
|
|
50
|
+
* @param cwd - Optional working directory for the initial pane
|
|
51
|
+
* @param envVars - Optional environment variables for the initial pane
|
|
52
|
+
* @returns The pane ID of the initial pane (e.g., "%0")
|
|
53
|
+
*/
|
|
54
|
+
export declare function createSession(sessionName: string, initialCommand: string, windowName?: string, cwd?: string, envVars?: Record<string, string>): string;
|
|
55
|
+
/**
|
|
56
|
+
* Create a new window in an existing session without switching focus.
|
|
57
|
+
*
|
|
58
|
+
* @param sessionName - Target session name
|
|
59
|
+
* @param windowName - Name for the new window
|
|
60
|
+
* @param command - Shell command to run in the new window
|
|
61
|
+
* @param cwd - Optional working directory for the new window
|
|
62
|
+
* @param envVars - Optional environment variables for the new window
|
|
63
|
+
* @returns The pane ID of the new window's pane
|
|
64
|
+
*/
|
|
65
|
+
export declare function createWindow(sessionName: string, windowName: string, command: string, cwd?: string, envVars?: Record<string, string>): string;
|
|
66
|
+
/**
|
|
67
|
+
* Create a new pane in an existing session by splitting.
|
|
68
|
+
*
|
|
69
|
+
* @returns The pane ID of the new pane
|
|
70
|
+
*/
|
|
71
|
+
export declare function createPane(sessionName: string, command: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Send literal text to a tmux pane using `-l` flag (no special key interpretation).
|
|
74
|
+
* Uses `--` to prevent text starting with `-` from being parsed as flags.
|
|
75
|
+
*/
|
|
76
|
+
export declare function sendLiteralText(paneId: string, text: string): void;
|
|
77
|
+
/**
|
|
78
|
+
* Send a special key (C-m, C-c, C-u, Tab, etc.) to a tmux pane.
|
|
79
|
+
*/
|
|
80
|
+
export declare function sendSpecialKey(paneId: string, key: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Send literal text and submit with C-m (carriage return).
|
|
83
|
+
* Uses C-m instead of Enter for raw-mode TUI compatibility.
|
|
84
|
+
*
|
|
85
|
+
* @param presses - Number of C-m presses (default: 1)
|
|
86
|
+
* @param delayMs - Delay between presses in ms (default: 100)
|
|
87
|
+
*/
|
|
88
|
+
export declare function sendKeysAndSubmit(paneId: string, text: string, presses?: number, delayMs?: number): void;
|
|
89
|
+
/**
|
|
90
|
+
* Capture the visible content of a tmux pane.
|
|
91
|
+
*
|
|
92
|
+
* @param paneId - The pane ID (e.g., "%0")
|
|
93
|
+
* @param start - Start line (negative = from bottom, default: capture visible only)
|
|
94
|
+
*/
|
|
95
|
+
export declare function capturePane(paneId: string, start?: number): string;
|
|
96
|
+
/**
|
|
97
|
+
* Capture only the visible portion of a pane (no scrollback).
|
|
98
|
+
* Preferred for state detection (ready/busy) to avoid stale prompt lines
|
|
99
|
+
* or old activity indicators in scrollback triggering false positives.
|
|
100
|
+
* Returns empty string on failure instead of throwing.
|
|
101
|
+
*/
|
|
102
|
+
export declare function capturePaneVisible(paneId: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* Capture last N lines of scrollback from a pane.
|
|
105
|
+
* Preferred for output collection where you need recent history.
|
|
106
|
+
* Returns empty string on failure instead of throwing.
|
|
107
|
+
*/
|
|
108
|
+
export declare function capturePaneScrollback(paneId: string, lines?: number): string;
|
|
109
|
+
/**
|
|
110
|
+
* Kill a tmux session.
|
|
111
|
+
*/
|
|
112
|
+
export declare function killSession(sessionName: string): void;
|
|
113
|
+
/** Kill a specific tmux window within a session. Silences errors if already dead. */
|
|
114
|
+
export declare function killWindow(sessionName: string, windowName: string): void;
|
|
115
|
+
/**
|
|
116
|
+
* Check if a tmux session exists.
|
|
117
|
+
*/
|
|
118
|
+
export declare function sessionExists(sessionName: string): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Attach to an existing tmux session (takes over the current terminal).
|
|
121
|
+
*/
|
|
122
|
+
export declare function attachSession(sessionName: string): void;
|
|
123
|
+
/**
|
|
124
|
+
* Switch the current tmux client to a different session.
|
|
125
|
+
* Use this instead of `attachSession` when already inside tmux to avoid
|
|
126
|
+
* creating a nested tmux client.
|
|
127
|
+
*/
|
|
128
|
+
export declare function switchClient(sessionName: string): void;
|
|
129
|
+
/**
|
|
130
|
+
* Get the name of the current tmux session (when running inside tmux).
|
|
131
|
+
* Returns null if not inside tmux or if the query fails.
|
|
132
|
+
*/
|
|
133
|
+
export declare function getCurrentSession(): string | null;
|
|
134
|
+
/**
|
|
135
|
+
* Attach or switch to a tmux session depending on whether we're already
|
|
136
|
+
* inside tmux. Avoids nested tmux clients.
|
|
137
|
+
*
|
|
138
|
+
* - Outside tmux: spawns `attach-session` (blocks until session ends).
|
|
139
|
+
* - Inside tmux: runs `switch-client` (returns immediately).
|
|
140
|
+
*/
|
|
141
|
+
export declare function attachOrSwitch(sessionName: string): void;
|
|
142
|
+
/**
|
|
143
|
+
* Select (switch to) a window within the current tmux session.
|
|
144
|
+
*/
|
|
145
|
+
export declare function selectWindow(target: string): void;
|
|
146
|
+
/**
|
|
147
|
+
* Collapse all whitespace to single spaces for robust capture comparison.
|
|
148
|
+
* Prevents false negatives from tmux inserting/stripping whitespace.
|
|
149
|
+
*/
|
|
150
|
+
export declare function normalizeTmuxCapture(text: string): string;
|
|
151
|
+
/**
|
|
152
|
+
* Normalize captured text preserving line structure (for display output).
|
|
153
|
+
*/
|
|
154
|
+
export declare function normalizeTmuxLines(text: string): string;
|
|
155
|
+
/**
|
|
156
|
+
* Returns true when the pane shows an agent prompt ready for input.
|
|
157
|
+
* Detects Claude Code (❯), Codex (›), and generic (>) prompts.
|
|
158
|
+
*/
|
|
159
|
+
export declare function paneLooksReady(captured: string): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Returns true when the agent has an active task in progress.
|
|
162
|
+
* Checks last 40 lines for known busy indicators.
|
|
163
|
+
*/
|
|
164
|
+
export declare function paneHasActiveTask(captured: string): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Returns true when the pane is idle — showing a prompt and not processing.
|
|
167
|
+
* Uses visible-only capture to avoid stale scrollback matches.
|
|
168
|
+
*/
|
|
169
|
+
export declare function paneIsIdle(paneId: string): boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Wait for the pane to be idle (prompt visible, no active task) with
|
|
172
|
+
* exponential backoff. Returns the time spent waiting (ms).
|
|
173
|
+
*/
|
|
174
|
+
export declare function waitForPaneReady(paneId: string, timeoutMs?: number): Promise<number>;
|
|
175
|
+
/**
|
|
176
|
+
* Attempt to submit by pressing C-m, verifying after each round.
|
|
177
|
+
* Returns true as soon as the trigger text disappears from the visible
|
|
178
|
+
* capture or an active task is detected.
|
|
179
|
+
*/
|
|
180
|
+
export declare function attemptSubmitRounds(paneId: string, normalizedPrompt: string, rounds: number, pressesPerRound?: number): Promise<boolean>;
|
|
181
|
+
/**
|
|
182
|
+
* Wait for a pattern to appear in a tmux pane's output.
|
|
183
|
+
* Polls the pane content at the given interval until the pattern matches
|
|
184
|
+
* or the timeout is reached.
|
|
185
|
+
*
|
|
186
|
+
* @returns The full pane content when the pattern was found
|
|
187
|
+
*/
|
|
188
|
+
export declare function waitForOutput(paneId: string, pattern: RegExp, options?: {
|
|
189
|
+
timeoutMs?: number;
|
|
190
|
+
pollIntervalMs?: number;
|
|
191
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow SDK Types
|
|
3
|
+
*
|
|
4
|
+
* Uses native SDK types directly — no re-definitions.
|
|
5
|
+
*/
|
|
6
|
+
import type { SessionEvent } from "@github/copilot-sdk";
|
|
7
|
+
import type { SessionPromptResponse } from "@opencode-ai/sdk/v2";
|
|
8
|
+
import type { SessionMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
9
|
+
import type { CopilotClient, CopilotClientOptions, CopilotSession, SessionConfig as CopilotSessionConfig } from "@github/copilot-sdk";
|
|
10
|
+
import type { OpencodeClient, Session as OpencodeSession } from "@opencode-ai/sdk/v2";
|
|
11
|
+
import type { ClaudeClientWrapper, ClaudeSessionWrapper, ClaudeQueryDefaults } from "./providers/claude.js";
|
|
12
|
+
/** Supported agent types */
|
|
13
|
+
export type AgentType = "copilot" | "opencode" | "claude";
|
|
14
|
+
/**
|
|
15
|
+
* Maps each agent to the client init options the user passes to `ctx.stage()`.
|
|
16
|
+
* Auto-injected fields (`cliUrl`, `baseUrl`, `paneId`) are omitted.
|
|
17
|
+
*/
|
|
18
|
+
type ClientOptionsMap = {
|
|
19
|
+
opencode: {
|
|
20
|
+
directory?: string;
|
|
21
|
+
experimental_workspaceID?: string;
|
|
22
|
+
};
|
|
23
|
+
copilot: Omit<CopilotClientOptions, "cliUrl">;
|
|
24
|
+
claude: {
|
|
25
|
+
chatFlags?: string[];
|
|
26
|
+
readyTimeoutMs?: number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Maps each agent to the session create options the user passes to `ctx.stage()`.
|
|
31
|
+
* - OpenCode: `client.session.create()` body params
|
|
32
|
+
* - Copilot: `client.createSession()` config (onPermissionRequest defaults to approveAll)
|
|
33
|
+
* - Claude: `claudeQuery()` defaults for subsequent queries
|
|
34
|
+
*/
|
|
35
|
+
type SessionOptionsMap = {
|
|
36
|
+
opencode: {
|
|
37
|
+
parentID?: string;
|
|
38
|
+
title?: string;
|
|
39
|
+
workspaceID?: string;
|
|
40
|
+
};
|
|
41
|
+
copilot: Partial<CopilotSessionConfig>;
|
|
42
|
+
claude: ClaudeQueryDefaults;
|
|
43
|
+
};
|
|
44
|
+
/** Maps each agent to the `s.client` type provided in the stage callback. */
|
|
45
|
+
type ClientMap = {
|
|
46
|
+
opencode: OpencodeClient;
|
|
47
|
+
copilot: CopilotClient;
|
|
48
|
+
claude: ClaudeClientWrapper;
|
|
49
|
+
};
|
|
50
|
+
/** Maps each agent to the `s.session` type provided in the stage callback. */
|
|
51
|
+
type SessionMap = {
|
|
52
|
+
opencode: OpencodeSession;
|
|
53
|
+
copilot: CopilotSession;
|
|
54
|
+
claude: ClaudeSessionWrapper;
|
|
55
|
+
};
|
|
56
|
+
/** Client init options for `ctx.stage()`, resolved by agent type. */
|
|
57
|
+
export type StageClientOptions<A extends AgentType> = ClientOptionsMap[A];
|
|
58
|
+
/** Session create options for `ctx.stage()`, resolved by agent type. */
|
|
59
|
+
export type StageSessionOptions<A extends AgentType> = SessionOptionsMap[A];
|
|
60
|
+
/** The `s.client` type in a stage callback, resolved by agent type. */
|
|
61
|
+
export type ProviderClient<A extends AgentType> = ClientMap[A];
|
|
62
|
+
/** The `s.session` type in a stage callback, resolved by agent type. */
|
|
63
|
+
export type ProviderSession<A extends AgentType> = SessionMap[A];
|
|
64
|
+
export type { CopilotClient, CopilotClientOptions, CopilotSession, CopilotSessionConfig, OpencodeClient, OpencodeSession, ClaudeClientWrapper, ClaudeSessionWrapper, ClaudeQueryDefaults, };
|
|
65
|
+
/**
|
|
66
|
+
* A transcript from a completed session.
|
|
67
|
+
* Provides both the file path and rendered text content.
|
|
68
|
+
*/
|
|
69
|
+
export interface Transcript {
|
|
70
|
+
/** Absolute path to the transcript file on disk */
|
|
71
|
+
path: string;
|
|
72
|
+
/** The transcript content (assistant text extracted from messages) */
|
|
73
|
+
content: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A saved message from any provider, stored as JSON.
|
|
77
|
+
* Uses native SDK types directly.
|
|
78
|
+
*/
|
|
79
|
+
export type SavedMessage = {
|
|
80
|
+
provider: "copilot";
|
|
81
|
+
data: SessionEvent;
|
|
82
|
+
} | {
|
|
83
|
+
provider: "opencode";
|
|
84
|
+
data: SessionPromptResponse;
|
|
85
|
+
} | {
|
|
86
|
+
provider: "claude";
|
|
87
|
+
data: SessionMessage;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Save native message objects from the provider SDK.
|
|
91
|
+
*
|
|
92
|
+
* - **Copilot**: `s.save(await s.session.getMessages())`
|
|
93
|
+
* - **OpenCode**: `s.save(result.data)` — the full `{ info, parts }` response
|
|
94
|
+
* - **Claude**: `s.save(sessionId)` — auto-reads via `getSessionMessages()`
|
|
95
|
+
*/
|
|
96
|
+
export interface SaveTranscript {
|
|
97
|
+
/** Save Copilot SessionEvent[] from session.getMessages() */
|
|
98
|
+
(messages: SessionEvent[]): Promise<void>;
|
|
99
|
+
/** Save OpenCode prompt response `{ info, parts }` from session.prompt().data */
|
|
100
|
+
(response: SessionPromptResponse): Promise<void>;
|
|
101
|
+
/** Save Claude messages — pass the session ID to auto-read transcript */
|
|
102
|
+
(claudeSessionId: string): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
/** A reference to a completed session — either a handle or a session name string. */
|
|
105
|
+
export type SessionRef = string | SessionHandle<unknown>;
|
|
106
|
+
/**
|
|
107
|
+
* Handle returned by `ctx.stage()`. Used for type-safe transcript references
|
|
108
|
+
* and carries the callback's return value.
|
|
109
|
+
*/
|
|
110
|
+
export interface SessionHandle<T = void> {
|
|
111
|
+
/** The session's unique name */
|
|
112
|
+
readonly name: string;
|
|
113
|
+
/** The session's generated UUID */
|
|
114
|
+
readonly id: string;
|
|
115
|
+
/** The value returned by the session callback */
|
|
116
|
+
readonly result: T;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Options for spawning a session via `ctx.stage()`.
|
|
120
|
+
*/
|
|
121
|
+
export interface SessionRunOptions {
|
|
122
|
+
/** Unique name for this session (used for transcript references and graph display) */
|
|
123
|
+
name: string;
|
|
124
|
+
/** Human-readable description */
|
|
125
|
+
description?: string;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Context provided to each session's callback.
|
|
129
|
+
* Created by `ctx.stage(opts, clientOpts, sessionOpts, fn)` — the callback
|
|
130
|
+
* receives this as its argument with pre-initialized `client` and `session`.
|
|
131
|
+
*/
|
|
132
|
+
export interface SessionContext<A extends AgentType = AgentType> {
|
|
133
|
+
/** Provider-specific SDK client (auto-created by runtime) */
|
|
134
|
+
client: ProviderClient<A>;
|
|
135
|
+
/** Provider-specific session (auto-created by runtime) */
|
|
136
|
+
session: ProviderSession<A>;
|
|
137
|
+
/** The original user prompt from the CLI invocation */
|
|
138
|
+
userPrompt: string;
|
|
139
|
+
/** Which agent is running */
|
|
140
|
+
agent: A;
|
|
141
|
+
/**
|
|
142
|
+
* Get a completed session's transcript as rendered text.
|
|
143
|
+
* Accepts a SessionHandle (recommended) or session name string.
|
|
144
|
+
*/
|
|
145
|
+
transcript(ref: SessionRef): Promise<Transcript>;
|
|
146
|
+
/**
|
|
147
|
+
* Get a completed session's raw native messages.
|
|
148
|
+
* Accepts a SessionHandle (recommended) or session name string.
|
|
149
|
+
*/
|
|
150
|
+
getMessages(ref: SessionRef): Promise<SavedMessage[]>;
|
|
151
|
+
/**
|
|
152
|
+
* Save this session's output for subsequent sessions.
|
|
153
|
+
* Accepts native SDK message objects only.
|
|
154
|
+
*/
|
|
155
|
+
save: SaveTranscript;
|
|
156
|
+
/** Path to this session's storage directory on disk */
|
|
157
|
+
sessionDir: string;
|
|
158
|
+
/** tmux pane ID for this session */
|
|
159
|
+
paneId: string;
|
|
160
|
+
/** Session UUID */
|
|
161
|
+
sessionId: string;
|
|
162
|
+
/**
|
|
163
|
+
* Spawn a nested sub-session with its own tmux window and graph node.
|
|
164
|
+
* The sub-session is a child of this session in the graph.
|
|
165
|
+
* The callback's return value is available as `handle.result`.
|
|
166
|
+
*/
|
|
167
|
+
stage<T = void>(options: SessionRunOptions, clientOpts: StageClientOptions<A>, sessionOpts: StageSessionOptions<A>, run: (ctx: SessionContext<A>) => Promise<T>): Promise<SessionHandle<T>>;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Top-level context provided to the workflow's `.run()` callback.
|
|
171
|
+
* Does not have session-specific fields (paneId, save, etc.).
|
|
172
|
+
*/
|
|
173
|
+
export interface WorkflowContext<A extends AgentType = AgentType> {
|
|
174
|
+
/** The original user prompt from the CLI invocation */
|
|
175
|
+
userPrompt: string;
|
|
176
|
+
/** Which agent is running */
|
|
177
|
+
agent: A;
|
|
178
|
+
/**
|
|
179
|
+
* Spawn a session with its own tmux window and graph node.
|
|
180
|
+
* The runtime manages the full lifecycle: create client → create session →
|
|
181
|
+
* run callback → cleanup. The callback's return value is available as
|
|
182
|
+
* `handle.result`.
|
|
183
|
+
*/
|
|
184
|
+
stage<T = void>(options: SessionRunOptions, clientOpts: StageClientOptions<A>, sessionOpts: StageSessionOptions<A>, run: (ctx: SessionContext<A>) => Promise<T>): Promise<SessionHandle<T>>;
|
|
185
|
+
/**
|
|
186
|
+
* Get a completed session's transcript as rendered text.
|
|
187
|
+
* Accepts a SessionHandle (recommended) or session name string.
|
|
188
|
+
*/
|
|
189
|
+
transcript(ref: SessionRef): Promise<Transcript>;
|
|
190
|
+
/**
|
|
191
|
+
* Get a completed session's raw native messages.
|
|
192
|
+
* Accepts a SessionHandle (recommended) or session name string.
|
|
193
|
+
*/
|
|
194
|
+
getMessages(ref: SessionRef): Promise<SavedMessage[]>;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Options for defining a workflow.
|
|
198
|
+
*/
|
|
199
|
+
export interface WorkflowOptions {
|
|
200
|
+
/** Unique workflow name */
|
|
201
|
+
name: string;
|
|
202
|
+
/** Human-readable description */
|
|
203
|
+
description?: string;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* A compiled workflow definition — the sealed output of defineWorkflow().compile().
|
|
207
|
+
*/
|
|
208
|
+
export interface WorkflowDefinition<A extends AgentType = AgentType> {
|
|
209
|
+
readonly __brand: "WorkflowDefinition";
|
|
210
|
+
readonly name: string;
|
|
211
|
+
readonly description: string;
|
|
212
|
+
/** The workflow's entry point. Called by the executor with a WorkflowContext. */
|
|
213
|
+
readonly run: (ctx: WorkflowContext<A>) => Promise<void>;
|
|
214
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ralph workflow for Claude Code — plan → orchestrate → review → debug loop.
|
|
3
|
+
*
|
|
4
|
+
* Each sub-agent invocation spawns its own visible session in the graph,
|
|
5
|
+
* so users can see each iteration's progress in real time. The loop
|
|
6
|
+
* terminates when:
|
|
7
|
+
* - {@link MAX_LOOPS} iterations have completed, OR
|
|
8
|
+
* - Two consecutive reviewer passes return zero findings.
|
|
9
|
+
*
|
|
10
|
+
* Run: atomic workflow -n ralph -a claude "<your spec>"
|
|
11
|
+
*/
|
|
12
|
+
declare const _default: import("../../../index.ts").WorkflowDefinition<"claude">;
|
|
13
|
+
export default _default;
|