Compare commits

...

4 Commits

Author SHA1 Message Date
ab1e2eb430 inform on max configuration 2026-05-31 02:12:54 -04:00
d2ef124369 automatic failover 2026-05-31 02:01:37 -04:00
925e37938b round robin 2026-05-31 01:57:52 -04:00
8e2e24d0e3 depend on pi defaults, and global yaml 2026-05-31 01:35:52 -04:00
6 changed files with 766 additions and 410 deletions

View File

@@ -98,16 +98,46 @@ tasks:
## Configuration
Create `.ralpi/config.yaml`:
Create config files. Both are optional:
| Scope | Path |
|-------|------|
| **Global** | `~/.pi/ralpi/config.yaml` |
| **Project** | `./.ralpi/config.yaml` |
```yaml
maxRetries: 3
retryDelayMs: 5000
timeoutMs: 1800000
maxParallel: 3
projectContext: "Additional context for all tasks"
execution:
maxParallel: 3 # ralpi-level concurrency only
models: # round-robin in <provider>/<model> format
- google/gemini-3.5-flash # 1st and 3rd task in parallel
- openai/gpt-5.5 # 2nd task in parallel
prompts:
projectContext: "Additional context for all tasks"
```
> ralpi deliberately does **not** set timeouts or retries — those are inherited
> from Pi's own settings. Tasks run until they complete or Pi's own flow stops them.
>
> `execution.models` uses slot-aware round-robin: with 3 models and 2 concurrent
> tasks, only the first two models are used. The third model is only touched when
> a third concurrent task starts. Freed model slots are reused before new ones
> are allocated.
>
> **Automatic failover**: if a provider/API is unreachable (rate limit, 503, etc.),
> the task automatically cycles to the next model in the list without counting it
> as a task failure. Each model is tried once before the task is marked as failed.
The keys mirror the nested structure of `RalpiConfig` in `src/types.ts`.
### Precedence (highest wins)
| Priority | Source |
|----------|--------|
| **1st** | In-memory overrides (`model`, `thinkingLevel` from parent Pi session) |
| **2nd** | `./.ralpi/config.yaml` — project-level |
| **3rd** | `~/.pi/ralpi/config.yaml` — global, shared across projects |
| **4th** | `DEFAULT_CONFIG` in `src/types.ts` |
### Task-Level Timeout
You can set a timeout for individual tasks using a meta block in the task file:

View File

@@ -66,9 +66,10 @@ async function selectExecutionMode(
ctx: ExtensionContext,
project: import("./src/types").Project,
taskFile: string,
config: import("./src/types").RalpiConfig,
): Promise<ExecutionMode> {
const mode = await ctx.ui.select("Execution mode for this run?", [
"Parallel (where dependencies allow)",
`Parallel (where dependencies allow)-[${config.execution.maxParallel} max]`,
"Sequential (one at a time)",
]);
const isParallel = mode?.startsWith("Parallel") ?? false;
@@ -117,7 +118,7 @@ async function executePlanBatches(
plan: ReturnType<typeof buildPlanByMode>,
project: Parameters<typeof buildExecutionPlan>[0],
taskFile: string,
config: import("./src/types").ralpiConfig,
config: import("./src/types").RalpiConfig,
progress: ProgressTracker,
ctx: ExtensionContext,
mode: ExecutionMode,
@@ -220,6 +221,16 @@ export default function ralpiLoopExtension(pi: ExtensionAPI): void {
},
);
// Register the extension's prompts/ directory so Pi discovers @task-manager
pi.on("resources_discover", async (_event, _ctx) => {
const promptsDir = fs.existsSync(path.resolve(__dirname, "prompts"))
? path.resolve(__dirname, "prompts")
: path.resolve(__dirname, "..", "prompts");
return {
promptPaths: [promptsDir],
};
});
pi.registerCommand("ralpi", {
description:
"Execute tasks from a task file using DAG-based dependency resolution",
@@ -248,21 +259,45 @@ export default function ralpiLoopExtension(pi: ExtensionAPI): void {
return handlePlan(ctx, parts);
}
if (looksLikePath(parts[0])) {
return handleRun(ctx, parts, sendProgress);
return handleRun(
ctx,
parts,
sendProgress,
ctx.model,
pi.getThinkingLevel(),
);
}
const command = parts[0];
switch (command) {
case "run":
return handleRun(ctx, parts.slice(1), sendProgress);
return handleRun(
ctx,
parts.slice(1),
sendProgress,
ctx.model,
pi.getThinkingLevel(),
);
case "plan":
return handlePlan(ctx, parts.slice(1));
case "status":
return handleStatus(ctx, parts.slice(1));
case "resume":
return handleResume(ctx, parts.slice(1), sendProgress);
return handleResume(
ctx,
parts.slice(1),
sendProgress,
ctx.model,
pi.getThinkingLevel(),
);
case "next":
return handleNext(ctx, parts.slice(1), sendProgress);
return handleNext(
ctx,
parts.slice(1),
sendProgress,
ctx.model,
pi.getThinkingLevel(),
);
case "reset":
return handleReset(ctx, parts.slice(1));
default: {
@@ -316,6 +351,8 @@ async function handleRun(
ctx: ExtensionContext,
args: string[],
sendChatMessage?: SendChatMessage,
parentModel?: unknown,
parentThinkingLevel?: unknown,
): Promise<void> {
const taskFile = resolveTaskArg(args[0] || "README.md", process.cwd());
@@ -323,7 +360,13 @@ async function handleRun(
// auto-resume instead of starting fresh
const existingProgress = findProgressFile(process.cwd(), taskFile);
if (existingProgress) {
return handleResume(ctx, args.slice(0, 1), sendChatMessage);
return handleResume(
ctx,
args.slice(0, 1),
sendChatMessage,
parentModel,
parentThinkingLevel,
);
}
// No existing progress for this task — check for any progress at all
@@ -336,7 +379,13 @@ async function handleRun(
);
if (shouldResume?.startsWith("Yes")) {
return handleResume(ctx, [], sendChatMessage);
return handleResume(
ctx,
[],
sendChatMessage,
parentModel,
parentThinkingLevel,
);
}
}
@@ -346,16 +395,12 @@ async function handleRun(
const project = parseTaskFile(taskFile);
const config = loadConfig(projectDir);
config.model = parentModel ?? ctx.model;
config.thinkingLevel = parentThinkingLevel;
const progress = new ProgressTracker(projectDir, taskFile);
// Set initial status
ctx.ui.setStatus(
"ralpi",
`Starting ${project.tasks.length} tasks from ${path.basename(taskFile)}`,
);
const completed = buildCompletedSet(progress, project);
const mode = await selectExecutionMode(ctx, project, taskFile);
const mode = await selectExecutionMode(ctx, project, taskFile, config);
const plan = buildPlanByMode(mode, project, completed);
// Show execution plan before starting so user can see batch breakdown
@@ -434,6 +479,8 @@ async function handleResume(
ctx: ExtensionContext,
args: string[],
sendChatMessage?: SendChatMessage,
parentModel?: unknown,
parentThinkingLevel?: unknown,
): Promise<void> {
let taskFile: string;
let projectDir: string;
@@ -473,15 +520,14 @@ async function handleResume(
);
}
const config = loadConfig(projectDir);
config.model = parentModel ?? ctx.model;
config.thinkingLevel = parentThinkingLevel;
const progress = new ProgressTracker(projectDir, taskFile, found.prdKey);
progress.setPaused(false);
// Set resume status
ctx.ui.setStatus("ralpi", `Resuming from ${path.basename(taskFile)}`);
const completed = buildCompletedSet(progress, project);
const mode = await selectExecutionMode(ctx, project, taskFile);
const mode = await selectExecutionMode(ctx, project, taskFile, config);
const plan = buildPlanByMode(mode, project, completed);
await executePlanBatches(
@@ -505,6 +551,8 @@ async function handleNext(
ctx: ExtensionContext,
args: string[],
sendChatMessage?: SendChatMessage,
parentModel?: unknown,
parentThinkingLevel?: unknown,
): Promise<void> {
let taskFile: string;
let projectDir: string;
@@ -540,6 +588,8 @@ async function handleNext(
);
}
const config = loadConfig(projectDir);
config.model = parentModel ?? ctx.model;
config.thinkingLevel = parentThinkingLevel;
const progress = new ProgressTracker(projectDir, taskFile, found?.prdKey);
const completed = buildCompletedSet(progress, project);

View File

@@ -1,7 +1,7 @@
{
"name": "ralpi-loop",
"version": "1.0.0",
"description": "Execute tasks from task files using DAG-based dependency resolution with persistent progress tracking",
"name": "ralpi",
"version": "0.1.0",
"description": "Execute tasks from task files/PRD's using DAG-based dependency resolution with persistent progress tracking",
"main": "dist/index.js",
"keywords": [
"pi-package",

File diff suppressed because it is too large Load Diff

View File

@@ -153,6 +153,8 @@ export interface RalpiConfig {
timeoutMs: number;
/** Maximum parallel tasks (0 = unlimited) */
maxParallel: number;
/** Round-robin model list for parallel tasks (empty = inherit parent model) */
models: string[];
};
prompts: {
/** Additional context injected into every task prompt */
@@ -160,6 +162,10 @@ export interface RalpiConfig {
/** Custom prompt suffix for reflection extraction */
reflectionPrompt: string;
};
/** Parent session model to inherit in child agent sessions */
model?: unknown;
/** Parent session thinking level to inherit in child agent sessions */
thinkingLevel?: unknown;
}
export const DEFAULT_CONFIG: RalpiConfig = {
@@ -168,10 +174,11 @@ export const DEFAULT_CONFIG: RalpiConfig = {
reflectionsDir: ".ralpi/reflections",
},
execution: {
maxRetries: 3,
retryDelayMs: 5000,
timeoutMs: 30 * 60 * 1000, // 30 minutes
maxRetries: 0,
retryDelayMs: 0,
timeoutMs: 0, // 0 = inherit Pi's own defaults (no ralpi-level timeout)
maxParallel: 3,
models: [],
},
prompts: {
projectContext: "",

View File

@@ -82,32 +82,35 @@ export function findProgressFile(
// ─── Config ──────────────────────────────────────────────────────────────────
function parseSimpleYaml(content: string): Record<string, any> {
const result: Record<string, any> = {};
const lines = content.split("\n");
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith("#")) continue;
const match = trimmed.match(/^([^:]+):\s*(.+)$/);
if (match) {
const key = match[1].trim();
let value: string | boolean | number = match[2].trim();
// Parse booleans
if (value === "true") value = true;
else if (value === "false") value = false;
// Parse numbers
else if (/^\d+$/.test(value)) value = parseInt(value, 10);
else if (/^\d+\.\d+$/.test(value)) value = parseFloat(value);
result[key] = value;
}
/** Try to use the `yaml` package (real dependency in package.json).
* Falls back to a flat key:value parser when unavailable. */
const parseSimpleYaml: (content: string) => Record<string, any> = (() => {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { parse } = require("yaml");
return (content: string) => parse(content) ?? {};
} catch {
return (content: string) => {
const result: Record<string, any> = {};
for (const line of content.split("\n")) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith("#")) continue;
const match = trimmed.match(/^([^:]+):\s*(.*)$/);
if (match) {
const value = match[2].trim();
if (value === "true") result[match[1].trim()] = true;
else if (value === "false") result[match[1].trim()] = false;
else if (/^\d+$/.test(value))
result[match[1].trim()] = parseInt(value, 10);
else if (/^\d+\.\d+$/.test(value))
result[match[1].trim()] = parseFloat(value);
else result[match[1].trim()] = value;
}
}
return result;
};
}
return result;
}
})();
/**
* Deep merge configuration objects
@@ -129,25 +132,44 @@ function mergeConfig(
return result as RalpiConfig;
}
/** Path to the global ralpi config under the user's Pi home directory. */
const GLOBAL_CONFIG_PATH = path.join(
process.env.HOME || "/tmp",
".pi",
"ralpi",
"config.yaml",
);
/**
* Load configuration from .ralpi/config.yaml or return defaults
* Load and merge config from global and project sources.
*
* Precedence (highest wins):
* 1. Project-level: `<projectDir>/.ralpi/config.yaml`
* 2. Global: `~/.pi/ralpi/config.yaml`
* 3. `DEFAULT_CONFIG` in `src/types.ts`
*/
export function loadConfig(projectDir: string): RalpiConfig {
const configPath = path.join(projectDir, ".ralpi", "config.yaml");
// Start with defaults
const merged: RalpiConfig = { ...DEFAULT_CONFIG };
// Return defaults silently when config file does not exist
if (!fs.existsSync(configPath)) {
return { ...DEFAULT_CONFIG };
}
// Layer 1: global config (~/.pi/ralpi/config.yaml)
tryLoadConfigFile(GLOBAL_CONFIG_PATH, merged);
try {
const content = fs.readFileSync(configPath, "utf-8");
// Simple YAML parsing (key: value format)
const config = parseSimpleYaml(content);
return mergeConfig(DEFAULT_CONFIG, config);
} catch {
// Malformed config — fall back to defaults silently
return { ...DEFAULT_CONFIG };
// Layer 2: project config (.ralpi/config.yaml) — overrides global
tryLoadConfigFile(path.join(projectDir, ".ralpi", "config.yaml"), merged);
return merged;
/** Attempt to load a single config file and merge into `acc` in place. */
function tryLoadConfigFile(filePath: string, acc: RalpiConfig): void {
if (!fs.existsSync(filePath)) return;
try {
const content = fs.readFileSync(filePath, "utf-8");
const parsed = parseSimpleYaml(content);
Object.assign(acc, mergeConfig(acc, parsed));
} catch {
// Malformed config — skip silently
}
}
}
@@ -339,6 +361,8 @@ export async function runAgentSession(
onEvent?: (event: AgentSessionEvent) => void,
signal?: AbortSignal,
sessionFile?: string,
model?: unknown,
thinkingLevel?: unknown,
): Promise<{
success: boolean;
text: string;
@@ -361,10 +385,13 @@ export async function runAgentSession(
? fs.createWriteStream(sessionFile, { flags: "a" })
: null;
// Wire timeout via abort signal
const timeoutHandle = setTimeout(() => {
if (sessionRef?.session) sessionRef.session.agent.abort();
}, timeoutMs);
// Wire timeout via abort signal (only when set; 0 means inherit Pi's defaults)
let timeoutHandle: NodeJS.Timeout | null = null;
if (timeoutMs > 0) {
timeoutHandle = setTimeout(() => {
if (sessionRef?.session) sessionRef.session.agent.abort();
}, timeoutMs);
}
const sessionRef: {
session?: Awaited<ReturnType<typeof createAgentSession>>["session"];
@@ -387,6 +414,8 @@ export async function runAgentSession(
sessionManager: SessionManager.inMemory(),
resourceLoader: loader,
tools: ["read", "bash", "edit", "write", "grep", "find", "ls"],
model: model as any,
thinkingLevel: thinkingLevel as any,
});
sessionRef.session = result.session;
@@ -437,7 +466,7 @@ export async function runAgentSession(
unsubscribe();
result.session.dispose();
signal?.removeEventListener("abort", abortHandler);
clearTimeout(timeoutHandle);
if (timeoutHandle) clearTimeout(timeoutHandle);
// Flush and close the event stream before returning
if (eventStream) {
@@ -463,7 +492,7 @@ export async function runAgentSession(
events: [], // streamed to file
};
} catch (error) {
clearTimeout(timeoutHandle);
if (timeoutHandle) clearTimeout(timeoutHandle);
if (eventStream && !eventStream.destroyed) {
eventStream.end();
}