@loka1/pi-orchestra 0.0.0-stage → 0.5.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/CHANGELOG.md +257 -0
- package/LICENSE +21 -0
- package/README.md +584 -2
- package/assets/preview.html +226 -0
- package/assets/preview.png +0 -0
- package/config/orchestra.json.example +35 -0
- package/config/templates/review-squad.md +11 -0
- package/extensions/lib/agents.ts +110 -0
- package/extensions/lib/chat.ts +171 -0
- package/extensions/lib/commands.ts +115 -0
- package/extensions/lib/config.ts +219 -0
- package/extensions/lib/format.ts +637 -0
- package/extensions/lib/git.ts +99 -0
- package/extensions/lib/log.ts +233 -0
- package/extensions/lib/mail.ts +115 -0
- package/extensions/lib/metrics.ts +365 -0
- package/extensions/lib/providers.ts +355 -0
- package/extensions/lib/redact.ts +57 -0
- package/extensions/lib/retry.ts +61 -0
- package/extensions/lib/state.ts +591 -0
- package/extensions/lib/templates.ts +153 -0
- package/extensions/lib/types.ts +156 -0
- package/extensions/lib/worker.ts +450 -0
- package/extensions/orchestra.ts +2906 -0
- package/extensions/ui/browse.ts +497 -0
- package/extensions/ui/join.ts +289 -0
- package/package.json +56 -4
- package/skills/orchestra/SKILL.md +84 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run templates: a run plus its tasks, written as markdown.
|
|
3
|
+
*
|
|
4
|
+
* Looked up in `.pi/orchestra/templates/*.md` (project) and
|
|
5
|
+
* `~/.pi/agent/orchestra/templates/*.md` (global). Project files win.
|
|
6
|
+
*
|
|
7
|
+
* # Review squad
|
|
8
|
+
* goal: Audit the storage layer before the release.
|
|
9
|
+
* agent: worker
|
|
10
|
+
*
|
|
11
|
+
* ## Extract the storage interface
|
|
12
|
+
* spec: Read src/store.ts, extract the interface, keep the tests green.
|
|
13
|
+
*
|
|
14
|
+
* ## Port the JSONL backend
|
|
15
|
+
* deps: Extract the storage interface
|
|
16
|
+
* agent: reviewer
|
|
17
|
+
*
|
|
18
|
+
* A `## Heading` starts a task; `spec:`, `agent:`, `model:`, `thinking:` and
|
|
19
|
+
* `deps:` are read from its first lines, everything else becomes the spec.
|
|
20
|
+
* `deps` names earlier task titles (comma separated).
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
24
|
+
import { homedir } from "node:os";
|
|
25
|
+
import { join, basename } from "node:path";
|
|
26
|
+
|
|
27
|
+
export interface TemplateTask {
|
|
28
|
+
title: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
agent?: string;
|
|
31
|
+
model?: string;
|
|
32
|
+
thinking?: string;
|
|
33
|
+
/** Titles of tasks in the same template that must finish first. */
|
|
34
|
+
deps: string[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface RunTemplate {
|
|
38
|
+
/** Template name: the `# Heading`, else the file name. */
|
|
39
|
+
name: string;
|
|
40
|
+
goal?: string;
|
|
41
|
+
agent?: string;
|
|
42
|
+
model?: string;
|
|
43
|
+
thinking?: string;
|
|
44
|
+
tasks: TemplateTask[];
|
|
45
|
+
path: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Global first, project last: later entries win when names collide. */
|
|
49
|
+
export function templateDirs(cwd: string, agentDir = process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent")): string[] {
|
|
50
|
+
return [join(agentDir, "orchestra", "templates"), join(cwd, ".pi", "orchestra", "templates")];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const KEY = /^([A-Za-z_-]+)\s*:\s*(.*)$/;
|
|
54
|
+
|
|
55
|
+
function splitDeps(value: string): string[] {
|
|
56
|
+
return value
|
|
57
|
+
.split(",")
|
|
58
|
+
.map((entry) => entry.trim())
|
|
59
|
+
.filter(Boolean);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function parseTemplate(raw: string, path: string): RunTemplate {
|
|
63
|
+
const fallbackName = basename(path).replace(/\.md$/, "");
|
|
64
|
+
const template: RunTemplate = { name: fallbackName, tasks: [], path };
|
|
65
|
+
let task: TemplateTask | undefined;
|
|
66
|
+
const body: string[] = [];
|
|
67
|
+
|
|
68
|
+
const flush = () => {
|
|
69
|
+
if (!task) return;
|
|
70
|
+
const text = body.join("\n").trim();
|
|
71
|
+
if (text) task.description = [task.description, text].filter(Boolean).join("\n\n");
|
|
72
|
+
body.length = 0;
|
|
73
|
+
template.tasks.push(task);
|
|
74
|
+
task = undefined;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
78
|
+
const heading = line.match(/^(#{1,2})\s+(.*)$/);
|
|
79
|
+
if (heading) {
|
|
80
|
+
const level = heading[1]?.length ?? 0;
|
|
81
|
+
const title = (heading[2] ?? "").trim();
|
|
82
|
+
if (level === 1) {
|
|
83
|
+
flush();
|
|
84
|
+
if (template.name === fallbackName) template.name = title;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (level === 2) {
|
|
88
|
+
flush();
|
|
89
|
+
task = { title, deps: [] };
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (task) {
|
|
95
|
+
const key = line.match(KEY);
|
|
96
|
+
if (key && body.join("").trim() === "" && key[1] && key[2] !== undefined) {
|
|
97
|
+
const field = key[1].toLowerCase();
|
|
98
|
+
const value = key[2].trim();
|
|
99
|
+
if (field === "spec" || field === "description") task.description = value;
|
|
100
|
+
else if (field === "agent") task.agent = value;
|
|
101
|
+
else if (field === "model") task.model = value;
|
|
102
|
+
else if (field === "thinking") task.thinking = value;
|
|
103
|
+
else if (field === "deps" || field === "depends") task.deps = splitDeps(value);
|
|
104
|
+
else body.push(line);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
body.push(line);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const top = line.match(KEY);
|
|
112
|
+
if (top && top[1] && top[2] !== undefined) {
|
|
113
|
+
const field = top[1].toLowerCase();
|
|
114
|
+
const value = top[2].trim();
|
|
115
|
+
if (field === "goal") template.goal = value;
|
|
116
|
+
else if (field === "agent") template.agent = value;
|
|
117
|
+
else if (field === "model") template.model = value;
|
|
118
|
+
else if (field === "thinking") template.thinking = value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
flush();
|
|
122
|
+
return template;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function listTemplates(cwd: string): RunTemplate[] {
|
|
126
|
+
const byName = new Map<string, RunTemplate>();
|
|
127
|
+
for (const dir of templateDirs(cwd)) {
|
|
128
|
+
if (!existsSync(dir)) continue;
|
|
129
|
+
let files: string[];
|
|
130
|
+
try {
|
|
131
|
+
files = readdirSync(dir).filter((file) => file.endsWith(".md"));
|
|
132
|
+
} catch {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
for (const file of files) {
|
|
136
|
+
const path = join(dir, file);
|
|
137
|
+
try {
|
|
138
|
+
const parsed = parseTemplate(readFileSync(path, "utf8"), path);
|
|
139
|
+
if (parsed.tasks.length > 0) byName.set(parsed.name, parsed);
|
|
140
|
+
} catch {
|
|
141
|
+
// A broken template must not break the run.
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return [...byName.values()];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function findTemplate(cwd: string, name: string): RunTemplate | undefined {
|
|
149
|
+
const wanted = name.trim().toLowerCase();
|
|
150
|
+
return listTemplates(cwd).find(
|
|
151
|
+
(template) => template.name.toLowerCase() === wanted || basename(template.path, ".md").toLowerCase() === wanted,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the pi-orchestra extension.
|
|
3
|
+
*
|
|
4
|
+
* Everything in this file is type-only: the modules under `extensions/lib`
|
|
5
|
+
* deliberately avoid runtime imports from pi so they can be unit-tested with
|
|
6
|
+
* plain `node scripts/smoke.mjs`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type RunStatus = "active" | "done" | "abandoned";
|
|
10
|
+
|
|
11
|
+
export type TaskStatus = "pending" | "ready" | "running" | "done" | "failed" | "blocked";
|
|
12
|
+
|
|
13
|
+
export type DispatchStatus =
|
|
14
|
+
| "starting"
|
|
15
|
+
| "running"
|
|
16
|
+
| "question" // waiting on an answer from the coordinator
|
|
17
|
+
| "settled"
|
|
18
|
+
| "stopped"
|
|
19
|
+
| "failed"
|
|
20
|
+
| "timeout"
|
|
21
|
+
| "orphaned" // the process is still alive, but it belongs to a previous coordinator
|
|
22
|
+
| "lost"; // state says running, but the process is gone (older session)
|
|
23
|
+
|
|
24
|
+
export interface Run {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
goal?: string;
|
|
28
|
+
status: RunStatus;
|
|
29
|
+
/** Cost ceiling for the whole run; new workers are refused once it is reached. */
|
|
30
|
+
budgetUsd?: number;
|
|
31
|
+
/** Set when the run hit its budget or was stopped as a whole. */
|
|
32
|
+
budgetNote?: string;
|
|
33
|
+
/** budgetAction "ask" hit the ceiling: live workers keep going, new ones wait. */
|
|
34
|
+
budgetPaused?: boolean;
|
|
35
|
+
/** Template the run was created from, for cost comparisons. */
|
|
36
|
+
template?: string;
|
|
37
|
+
createdAt: string;
|
|
38
|
+
updatedAt: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface Task {
|
|
42
|
+
id: string;
|
|
43
|
+
runId: string;
|
|
44
|
+
title: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
agent?: string;
|
|
47
|
+
status: TaskStatus;
|
|
48
|
+
deps: string[];
|
|
49
|
+
dispatchId?: string;
|
|
50
|
+
createdAt: string;
|
|
51
|
+
updatedAt: string;
|
|
52
|
+
result?: string;
|
|
53
|
+
error?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface Dispatch {
|
|
57
|
+
id: string;
|
|
58
|
+
runId: string;
|
|
59
|
+
taskId?: string;
|
|
60
|
+
agent: string;
|
|
61
|
+
spec: string;
|
|
62
|
+
status: DispatchStatus;
|
|
63
|
+
pid?: number;
|
|
64
|
+
model?: string;
|
|
65
|
+
/** Provider that serves `model` in the worker; needed when the id is ambiguous. */
|
|
66
|
+
provider?: string;
|
|
67
|
+
/** Set when the requested model was not available and the coordinator's model was used. */
|
|
68
|
+
modelNote?: string;
|
|
69
|
+
thinking?: string;
|
|
70
|
+
tools?: string[];
|
|
71
|
+
keepOpen: boolean;
|
|
72
|
+
startedAt: string;
|
|
73
|
+
endedAt?: string;
|
|
74
|
+
settledAt?: string;
|
|
75
|
+
exitCode?: number | null;
|
|
76
|
+
signal?: string | null;
|
|
77
|
+
error?: string;
|
|
78
|
+
summary?: string;
|
|
79
|
+
aborted?: boolean;
|
|
80
|
+
usage: DispatchUsage;
|
|
81
|
+
lastToolCall?: string;
|
|
82
|
+
/** Last time the worker produced any event; drives the stall watchdog. */
|
|
83
|
+
lastEventAt?: string;
|
|
84
|
+
/** Set while the worker has been silent for longer than `stallMs`. */
|
|
85
|
+
stalledAt?: string;
|
|
86
|
+
/** Cost ceiling for this dispatch. */
|
|
87
|
+
budgetUsd?: number;
|
|
88
|
+
/** Wall-clock ceiling that first asks the worker to wrap up, then stops it. */
|
|
89
|
+
budgetMs?: number;
|
|
90
|
+
/** Per-dispatch override of `timeoutMs` (0 = no limit). */
|
|
91
|
+
timeoutMs?: number;
|
|
92
|
+
/** Per-dispatch override of `timeoutMode`. */
|
|
93
|
+
timeoutMode?: "total" | "idle";
|
|
94
|
+
/** pi session id, recorded when `sessionMode` is "session" so it can be resumed. */
|
|
95
|
+
sessionId?: string;
|
|
96
|
+
/** Dispatch this one continues (same session). */
|
|
97
|
+
resumedFrom?: string;
|
|
98
|
+
/** Dispatch this one repairs (fresh context, with the failure prepended). */
|
|
99
|
+
retryOf?: string;
|
|
100
|
+
/** git HEAD when the worker started, so its changes can be reviewed. */
|
|
101
|
+
baseCommit?: string;
|
|
102
|
+
/** 1-based attempt number; a repair dispatch carries the previous one + 1. */
|
|
103
|
+
attempt?: number;
|
|
104
|
+
/** Extra attempts allowed for this dispatch (0 or undefined = no retry). */
|
|
105
|
+
retries?: number;
|
|
106
|
+
/** Set while a retry is queued, so the coordinator can show it. */
|
|
107
|
+
retryAt?: string;
|
|
108
|
+
/** Why the coordinator stopped it, as opposed to the worker finishing. */
|
|
109
|
+
stopReason?: "budget" | "stall" | "user" | "timeout";
|
|
110
|
+
/** Human-readable explanation of the stop/budget event. */
|
|
111
|
+
stopNote?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface DispatchUsage {
|
|
115
|
+
turns: number;
|
|
116
|
+
input: number;
|
|
117
|
+
output: number;
|
|
118
|
+
cacheRead: number;
|
|
119
|
+
cacheWrite: number;
|
|
120
|
+
cost: number;
|
|
121
|
+
toolCalls: number;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface Gate {
|
|
125
|
+
id: string;
|
|
126
|
+
runId: string;
|
|
127
|
+
dispatchId: string;
|
|
128
|
+
question: string;
|
|
129
|
+
options?: string[];
|
|
130
|
+
status: "pending" | "answered" | "expired";
|
|
131
|
+
answer?: string;
|
|
132
|
+
createdAt: string;
|
|
133
|
+
answeredAt?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface OrchestraState {
|
|
137
|
+
version: 1;
|
|
138
|
+
activeRunId?: string;
|
|
139
|
+
seq: number;
|
|
140
|
+
runs: Record<string, Run>;
|
|
141
|
+
tasks: Record<string, Task>;
|
|
142
|
+
dispatches: Record<string, Dispatch>;
|
|
143
|
+
gates: Record<string, Gate>;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function emptyState(): OrchestraState {
|
|
147
|
+
return { version: 1, seq: 0, runs: {}, tasks: {}, dispatches: {}, gates: {} };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function emptyUsage(): DispatchUsage {
|
|
151
|
+
return { turns: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, toolCalls: 0 };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function isLiveStatus(status: DispatchStatus): boolean {
|
|
155
|
+
return status === "starting" || status === "running" || status === "question";
|
|
156
|
+
}
|