@oxgeneral/orch 0.3.3 → 0.3.4
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/App-RKAPZNZO.js +6682 -0
- package/dist/agent-KBTLGGCT.js +183 -0
- package/dist/agent-shop-YN2BSLHM.js +2 -0
- package/dist/chunk-2C2TFQ7K.js +136 -0
- package/dist/chunk-45K2XID7.js +29 -0
- package/dist/chunk-52BFUGDD.js +220 -0
- package/dist/chunk-7X2GI5OV.js +181 -0
- package/dist/{chunk-HSBYJ5C5.js → chunk-A36WAF2S.js} +89 -2
- package/dist/chunk-CHIP7O6V.js +83 -0
- package/dist/chunk-D6RFF3KN.js +85 -0
- package/dist/{chunk-BCPUTULS.js → chunk-DAVHOWGD.js} +188 -16
- package/dist/chunk-FRTKB575.js +87 -0
- package/dist/chunk-HXYAZGLP.js +15 -0
- package/dist/chunk-I3SMISEF.js +29 -0
- package/dist/chunk-K6DMQERQ.js +89 -0
- package/dist/chunk-LV6GDBBI.js +297 -0
- package/dist/chunk-P6ATSXGL.js +107 -0
- package/dist/chunk-PNE6LQRF.js +5 -0
- package/dist/chunk-U2VDNUZL.js +52 -0
- package/dist/{chunk-BGHCY7WY.js → chunk-VMDQVRBR.js} +18 -8
- package/dist/chunk-VMDQVRBR.js.map +1 -0
- package/dist/chunk-W6RSVMXR.js +66 -0
- package/dist/claude-NHUNA5RZ.js +5 -0
- package/dist/cli.js +199 -1
- package/dist/clipboard-service-RTDUUQQU.js +200 -0
- package/dist/codex-DIXT44JR.js +123 -0
- package/dist/config-OTAVSMOD.js +75 -0
- package/dist/container-LJU4QNDH.js +1594 -0
- package/dist/context-OL4BVUV5.js +83 -0
- package/dist/cursor-C3TR2IJC.js +97 -0
- package/dist/doctor-V2FPS236.js +67 -0
- package/dist/doctor-service-TPOMFAIG.js +2 -0
- package/dist/goal-FMYYN2FR.js +138 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.js +14 -7
- package/dist/index.js.map +1 -1
- package/dist/init-U7MCIOB2.js +165 -0
- package/dist/logs-PHPYWQ6I.js +207 -0
- package/dist/msg-FUWWLEKM.js +95 -0
- package/dist/orchestrator-ADO66XZ3.js +5 -0
- package/dist/{orchestrator-KF4UY5GD.js.map → orchestrator-ADO66XZ3.js.map} +1 -1
- package/dist/orchestrator-E3FQ4SOE.js +1424 -0
- package/dist/process-manager-HUVNAPQV.js +2 -0
- package/dist/registry-PQWRVNF2.js +2 -0
- package/dist/run-N72G5V2H.js +95 -0
- package/dist/shell-3S4VLYEG.js +4 -0
- package/dist/{shell-UXJNTNBC.js → shell-JXOPKDXH.js} +3 -3
- package/dist/shell-JXOPKDXH.js.map +1 -0
- package/dist/shop-picker-2HY67UWP.js +79 -0
- package/dist/status-RZWN2C6C.js +56 -0
- package/dist/task-2TJW6Z7O.js +221 -0
- package/dist/team-PFLP4PPL.js +97 -0
- package/dist/template-engine-4IZKRRHG.js +3 -0
- package/dist/tui-IM3YUUVD.js +245 -0
- package/dist/update-YLP7FPNY.js +64 -0
- package/dist/update-check-4YKLGBFB.js +2 -0
- package/dist/workspace-manager-JM6U7JOH.js +215 -0
- package/package.json +1 -1
- package/readme.md +9 -2
- package/scripts/postinstall.js +44 -2
- package/dist/App-NN7HR7UE.js +0 -20
- package/dist/agent-S4DKSX63.js +0 -9
- package/dist/agent-shop-D2RS4BZK.js +0 -2
- package/dist/chunk-3MQNQ7QW.js +0 -2
- package/dist/chunk-5AJ4LYO5.js +0 -8
- package/dist/chunk-6MJ7V6VY.js +0 -2
- package/dist/chunk-BGHCY7WY.js.map +0 -1
- package/dist/chunk-CDFA4IIQ.js +0 -2
- package/dist/chunk-CHRW4CLD.js +0 -2
- package/dist/chunk-HMMPM7MF.js +0 -3
- package/dist/chunk-HXOMNULD.js +0 -2
- package/dist/chunk-IS3YBE2B.js +0 -3
- package/dist/chunk-KPCT44WU.js +0 -2
- package/dist/chunk-L26TK7Y5.js +0 -2
- package/dist/chunk-LXNRCJ22.js +0 -2
- package/dist/chunk-OQKREZUF.js +0 -11
- package/dist/chunk-PJ5DKXGR.js +0 -2
- package/dist/chunk-QFKVCNKL.js +0 -2
- package/dist/chunk-UMZEA3JT.js +0 -5
- package/dist/claude-GQZNDJ6L.js +0 -2
- package/dist/clipboard-service-MYLSWM5E.js +0 -25
- package/dist/codex-SJV7ZZBY.js +0 -2
- package/dist/config-CCSS2P7R.js +0 -2
- package/dist/container-NEKK5W2B.js +0 -6
- package/dist/context-GSMQHQES.js +0 -7
- package/dist/cursor-4JQOCP5X.js +0 -2
- package/dist/doctor-UAII4VWN.js +0 -2
- package/dist/doctor-service-PB7YBH3F.js +0 -2
- package/dist/goal-RFKFPR7M.js +0 -8
- package/dist/init-2D4RAN7B.js +0 -53
- package/dist/logs-UXFXVYCP.js +0 -12
- package/dist/msg-4SCLBO4K.js +0 -9
- package/dist/orchestrator-KF4UY5GD.js +0 -5
- package/dist/orchestrator-MFL3XK5L.js +0 -13
- package/dist/process-manager-33H27MQF.js +0 -2
- package/dist/registry-BO2PPRNG.js +0 -2
- package/dist/run-HSHRELOP.js +0 -3
- package/dist/shell-F42UUF3U.js +0 -2
- package/dist/shell-UXJNTNBC.js.map +0 -1
- package/dist/shop-picker-LE3SKFOX.js +0 -5
- package/dist/status-DLBNWSWM.js +0 -2
- package/dist/task-AP2TIOOF.js +0 -20
- package/dist/team-MSIBKOQC.js +0 -4
- package/dist/template-engine-ONIDVD4F.js +0 -2
- package/dist/tui-PIQT4ZZ2.js +0 -2
- package/dist/update-PC2ENCKU.js +0 -2
- package/dist/update-check-HGMBDYHL.js +0 -2
- package/dist/workspace-manager-DYN3XJ7X.js +0 -3
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { agentToEditorContent, openInEditor, agentFromEditorContent } from './chunk-P6ATSXGL.js';
|
|
3
|
+
import { printSuccess, agentName, printTable, dim, statusIcon, formatTokens, printKeyValue } from './chunk-7X2GI5OV.js';
|
|
4
|
+
|
|
5
|
+
// src/cli/commands/agent.ts
|
|
6
|
+
function registerAgentCommand(program, container) {
|
|
7
|
+
const agent = program.command("agent").description("Manage agents");
|
|
8
|
+
agent.command("add <name>").description("Add a new agent").requiredOption("--adapter <adapter>", "Adapter type: claude, shell, codex, cursor").option("--role <role>", "Agent role description").option("--command <cmd>", "Shell command (for shell adapter)").option("--model <model>", "Model name (for AI adapters)").option("--max-turns <n>", "Max turns per run").option("--timeout <ms>", "Timeout in ms").option("--approval-policy <policy>", "suggest|auto|manual").option("--workspace-mode <mode>", "shared|worktree|isolated").option("--skills <skills>", "Comma-separated list of agent skills").option("-e, --edit", "Open $EDITOR to write the role description").action(async (name, opts) => {
|
|
9
|
+
await container.paths.requireInit();
|
|
10
|
+
let role = opts.role;
|
|
11
|
+
if (opts.edit) {
|
|
12
|
+
const initial = agentToEditorContent({ name, model: opts.model, role });
|
|
13
|
+
const edited = await openInEditor(initial);
|
|
14
|
+
const parsed = agentFromEditorContent(edited);
|
|
15
|
+
if (parsed.name) name = parsed.name;
|
|
16
|
+
if (parsed.model) opts.model = parsed.model;
|
|
17
|
+
if (parsed.role) role = parsed.role;
|
|
18
|
+
}
|
|
19
|
+
const a = await container.agentService.create({
|
|
20
|
+
name,
|
|
21
|
+
adapter: opts.adapter,
|
|
22
|
+
role,
|
|
23
|
+
command: opts.command,
|
|
24
|
+
model: opts.model,
|
|
25
|
+
max_turns: opts.maxTurns ? parseInt(opts.maxTurns, 10) : void 0,
|
|
26
|
+
timeout_ms: opts.timeout ? parseInt(opts.timeout, 10) : void 0,
|
|
27
|
+
approval_policy: opts.approvalPolicy,
|
|
28
|
+
workspace_mode: opts.workspaceMode,
|
|
29
|
+
skills: opts.skills ? opts.skills.split(",").map((s) => s.trim()) : void 0
|
|
30
|
+
});
|
|
31
|
+
if (container.context.json) {
|
|
32
|
+
console.log(JSON.stringify(a, null, 2));
|
|
33
|
+
} else if (container.context.quiet) {
|
|
34
|
+
console.log(a.id);
|
|
35
|
+
} else {
|
|
36
|
+
printSuccess(`Added agent ${agentName(a.name)} (${a.adapter}) \u2192 ${a.id}`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
agent.command("shop").description("Browse and install pre-built agent templates").option("--list", "Print all templates (non-interactive)").action(async (opts) => {
|
|
40
|
+
await container.paths.requireInit();
|
|
41
|
+
const { AGENT_SHOP_TEMPLATES } = await import('./agent-shop-YN2BSLHM.js');
|
|
42
|
+
if (opts.list || !process.stdout.isTTY) {
|
|
43
|
+
printTable(
|
|
44
|
+
["Key", "Name", "Adapter", "Model", "Skills"],
|
|
45
|
+
AGENT_SHOP_TEMPLATES.map((t) => [t.key, t.name, t.adapter, t.model.replace("claude-", ""), t.skills.slice(0, 2).join(", ")])
|
|
46
|
+
);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const { pickFromShop } = await import('./shop-picker-2HY67UWP.js');
|
|
50
|
+
const template = await pickFromShop(AGENT_SHOP_TEMPLATES);
|
|
51
|
+
if (!template) {
|
|
52
|
+
console.log(" Cancelled.");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const a = await container.agentService.create({
|
|
56
|
+
name: template.name,
|
|
57
|
+
adapter: template.adapter,
|
|
58
|
+
model: template.model,
|
|
59
|
+
role: template.role,
|
|
60
|
+
skills: template.skills,
|
|
61
|
+
approval_policy: template.approval_policy
|
|
62
|
+
});
|
|
63
|
+
printSuccess(`Added agent ${agentName(a.name)} (${a.adapter}) \u2192 ${a.id}`);
|
|
64
|
+
});
|
|
65
|
+
agent.command("list").description("List all agents").action(async () => {
|
|
66
|
+
await container.paths.requireInit();
|
|
67
|
+
const agents = await container.agentService.list();
|
|
68
|
+
if (container.context.json) {
|
|
69
|
+
console.log(JSON.stringify(agents, null, 2));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (container.context.quiet) {
|
|
73
|
+
agents.forEach((a) => console.log(a.id));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (agents.length === 0) {
|
|
77
|
+
console.log(`
|
|
78
|
+
No agents. Add one: ${dim("orch agent add <name> --adapter claude")}
|
|
79
|
+
`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const headers = ["STATUS", "AGENT", "ADAPTER", "TASK", "TIME"];
|
|
83
|
+
const rows = agents.map((a) => [
|
|
84
|
+
`${statusIcon(a.status)} ${a.status}`,
|
|
85
|
+
agentName(a.name),
|
|
86
|
+
a.adapter,
|
|
87
|
+
a.current_task ?? dim("\u2014"),
|
|
88
|
+
dim("\u2014")
|
|
89
|
+
]);
|
|
90
|
+
console.log();
|
|
91
|
+
printTable(headers, rows);
|
|
92
|
+
const running = agents.filter((a) => a.status === "running").length;
|
|
93
|
+
console.log(
|
|
94
|
+
`
|
|
95
|
+
${agents.length} agents \xB7 ${running} running \xB7 ${formatTokens(agents.reduce((sum, a) => sum + (a.stats.tokens_used ?? 0), 0))} tokens total
|
|
96
|
+
`
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
agent.command("status <id>").description("Show agent details").action(async (id) => {
|
|
100
|
+
await container.paths.requireInit();
|
|
101
|
+
const a = await container.agentService.get(id);
|
|
102
|
+
if (container.context.json) {
|
|
103
|
+
console.log(JSON.stringify(a, null, 2));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
console.log(`
|
|
107
|
+
${a.name}`);
|
|
108
|
+
console.log(` ${"\u2550".repeat(42)}`);
|
|
109
|
+
console.log();
|
|
110
|
+
const pairs = [
|
|
111
|
+
["Adapter", `${a.adapter}${a.config.model ? ` (${a.config.model})` : ""}`],
|
|
112
|
+
["Status", `${statusIcon(a.status)} ${a.status}`],
|
|
113
|
+
["Policy", a.config.approval_policy ?? "auto"]
|
|
114
|
+
];
|
|
115
|
+
if (a.current_task) pairs.push(["Task", a.current_task]);
|
|
116
|
+
if (a.role) pairs.push(["Role", a.role]);
|
|
117
|
+
if (a.config.skills?.length) pairs.push(["Skills", a.config.skills.join(", ")]);
|
|
118
|
+
printKeyValue(pairs);
|
|
119
|
+
console.log(`
|
|
120
|
+
Stats
|
|
121
|
+
${"\u2500".repeat(42)}`);
|
|
122
|
+
printKeyValue([
|
|
123
|
+
["Tasks completed", String(a.stats.tasks_completed)],
|
|
124
|
+
["Tasks failed", String(a.stats.tasks_failed)],
|
|
125
|
+
["Total runs", String(a.stats.total_runs)],
|
|
126
|
+
["Tokens used", formatTokens(a.stats.tokens_used ?? 0)]
|
|
127
|
+
]);
|
|
128
|
+
console.log();
|
|
129
|
+
});
|
|
130
|
+
agent.command("edit <id>").description("Edit an agent in $EDITOR").action(async (id) => {
|
|
131
|
+
await container.paths.requireInit();
|
|
132
|
+
const a = await container.agentService.get(id);
|
|
133
|
+
const initial = agentToEditorContent({
|
|
134
|
+
name: a.name,
|
|
135
|
+
model: a.config.model,
|
|
136
|
+
role: a.role
|
|
137
|
+
});
|
|
138
|
+
const edited = await openInEditor(initial);
|
|
139
|
+
const parsed = agentFromEditorContent(edited);
|
|
140
|
+
const updated = await container.agentService.update(id, {
|
|
141
|
+
name: parsed.name,
|
|
142
|
+
role: parsed.role,
|
|
143
|
+
model: parsed.model
|
|
144
|
+
});
|
|
145
|
+
if (container.context.json) {
|
|
146
|
+
console.log(JSON.stringify(updated, null, 2));
|
|
147
|
+
} else if (container.context.quiet) {
|
|
148
|
+
console.log(updated.id);
|
|
149
|
+
} else {
|
|
150
|
+
printSuccess(`Updated agent ${agentName(updated.name)} (${updated.id})`);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
agent.command("remove <id>").description("Remove an agent").action(async (id) => {
|
|
154
|
+
await container.paths.requireInit();
|
|
155
|
+
await container.agentService.remove(id);
|
|
156
|
+
printSuccess(`Removed agent ${id}`);
|
|
157
|
+
});
|
|
158
|
+
agent.command("disable <id>").description("Disable an agent").action(async (id) => {
|
|
159
|
+
await container.paths.requireInit();
|
|
160
|
+
await container.agentService.disable(id);
|
|
161
|
+
printSuccess(`Disabled agent ${id}`);
|
|
162
|
+
});
|
|
163
|
+
agent.command("enable <id>").description("Enable an agent").action(async (id) => {
|
|
164
|
+
await container.paths.requireInit();
|
|
165
|
+
await container.agentService.enable(id);
|
|
166
|
+
printSuccess(`Enabled agent ${id}`);
|
|
167
|
+
});
|
|
168
|
+
agent.command("autonomous <id>").description("Toggle autonomous mode for an agent").option("--on", "Enable autonomous mode").option("--off", "Disable autonomous mode").action(async (id, opts) => {
|
|
169
|
+
await container.paths.requireInit();
|
|
170
|
+
const current = await container.agentService.get(id);
|
|
171
|
+
const enable = opts.on ? true : opts.off ? false : !current.autonomous;
|
|
172
|
+
const a = await container.agentService.setAutonomous(id, enable);
|
|
173
|
+
if (container.context.json) {
|
|
174
|
+
console.log(JSON.stringify(a, null, 2));
|
|
175
|
+
} else if (container.context.quiet) {
|
|
176
|
+
console.log(a.id);
|
|
177
|
+
} else {
|
|
178
|
+
printSuccess(`Autonomous mode ${enable ? "enabled" : "disabled"} for agent ${agentName(a.name)} (${a.id})`);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export { registerAgentCommand };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// src/domain/errors.ts
|
|
3
|
+
var OrchestryError = class extends Error {
|
|
4
|
+
constructor(message, exitCode, hint) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.exitCode = exitCode;
|
|
7
|
+
this.hint = hint;
|
|
8
|
+
this.name = "OrchestryError";
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var NotInitializedError = class extends OrchestryError {
|
|
12
|
+
constructor() {
|
|
13
|
+
super("Not initialized", 3, "Run: orch init");
|
|
14
|
+
this.name = "NotInitializedError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var InvalidArgumentsError = class extends OrchestryError {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message, 2);
|
|
20
|
+
this.name = "InvalidArgumentsError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var LockConflictError = class extends OrchestryError {
|
|
24
|
+
constructor(pid) {
|
|
25
|
+
super(`Orchestrator already running (PID: ${pid})`, 4, "Use: orch status");
|
|
26
|
+
this.name = "LockConflictError";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var NoAgentsError = class extends OrchestryError {
|
|
30
|
+
constructor() {
|
|
31
|
+
super("No agents configured", 1, "Run: orch agent add <name> --adapter claude");
|
|
32
|
+
this.name = "NoAgentsError";
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var TaskNotFoundError = class extends OrchestryError {
|
|
36
|
+
constructor(taskId) {
|
|
37
|
+
super(`Task not found: ${taskId}`, 1);
|
|
38
|
+
this.name = "TaskNotFoundError";
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var AgentNotFoundError = class extends OrchestryError {
|
|
42
|
+
constructor(agentId) {
|
|
43
|
+
super(`Agent not found: ${agentId}`, 1);
|
|
44
|
+
this.name = "AgentNotFoundError";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var TaskAlreadyRunningError = class extends OrchestryError {
|
|
48
|
+
constructor(taskId, runId, agentName) {
|
|
49
|
+
super(
|
|
50
|
+
`Task ${taskId} is already running (run: ${runId}, agent: ${agentName})`,
|
|
51
|
+
1,
|
|
52
|
+
`Use: orch logs --task ${taskId} --follow`
|
|
53
|
+
);
|
|
54
|
+
this.name = "TaskAlreadyRunningError";
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var InvalidTransitionError = class extends OrchestryError {
|
|
58
|
+
constructor(taskId, from, to) {
|
|
59
|
+
super(`Invalid transition for ${taskId}: ${from} \u2192 ${to}`, 1);
|
|
60
|
+
this.name = "InvalidTransitionError";
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var GoalNotFoundError = class extends OrchestryError {
|
|
64
|
+
constructor(goalId) {
|
|
65
|
+
super(`Goal not found: ${goalId}`, 1);
|
|
66
|
+
this.name = "GoalNotFoundError";
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var TeamNotFoundError = class extends OrchestryError {
|
|
70
|
+
constructor(teamId) {
|
|
71
|
+
super(`Team not found: ${teamId}`, 1);
|
|
72
|
+
this.name = "TeamNotFoundError";
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var WorkspaceError = class extends OrchestryError {
|
|
76
|
+
constructor(message, hint) {
|
|
77
|
+
super(message, 6, hint);
|
|
78
|
+
this.name = "WorkspaceError";
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var ERROR_HINTS = {
|
|
82
|
+
["adapter_not_found" /* ADAPTER_NOT_FOUND */]: {
|
|
83
|
+
message: "CLI \u043D\u0435 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D.",
|
|
84
|
+
fix: "\u0423\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435: npm i -g @anthropic-ai/claude-code",
|
|
85
|
+
doctorHint: true
|
|
86
|
+
},
|
|
87
|
+
["auth_failed" /* AUTH_FAILED */]: {
|
|
88
|
+
message: "API \u043A\u043B\u044E\u0447 \u043D\u0435\u0432\u0430\u043B\u0438\u0434\u0435\u043D.",
|
|
89
|
+
fix: "\u041F\u0440\u043E\u0432\u0435\u0440\u044C\u0442\u0435: claude auth status"
|
|
90
|
+
},
|
|
91
|
+
["timeout" /* TIMEOUT */]: {
|
|
92
|
+
message: "\u0410\u0433\u0435\u043D\u0442 \u043F\u0440\u0435\u0432\u044B\u0441\u0438\u043B \u043B\u0438\u043C\u0438\u0442 \u0432\u0440\u0435\u043C\u0435\u043D\u0438.",
|
|
93
|
+
fix: "\u0423\u0432\u0435\u043B\u0438\u0447\u044C\u0442\u0435 \u0447\u0435\u0440\u0435\u0437: orch config set agent_timeout <ms>"
|
|
94
|
+
},
|
|
95
|
+
["rate_limit" /* RATE_LIMIT */]: {
|
|
96
|
+
message: "\u0414\u043E\u0441\u0442\u0438\u0433\u043D\u0443\u0442 \u043B\u0438\u043C\u0438\u0442 API.",
|
|
97
|
+
fix: "\u041F\u043E\u0434\u043E\u0436\u0434\u0438\u0442\u0435 \u0438 \u043F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u0435: orch task retry <id>"
|
|
98
|
+
},
|
|
99
|
+
["process_crash" /* PROCESS_CRASH */]: {
|
|
100
|
+
message: "\u041F\u0440\u043E\u0446\u0435\u0441\u0441 \u0430\u0433\u0435\u043D\u0442\u0430 \u0443\u043F\u0430\u043B.",
|
|
101
|
+
fix: "\u041F\u043E\u043F\u0440\u043E\u0431\u0443\u0439\u0442\u0435: orch task retry <id>"
|
|
102
|
+
},
|
|
103
|
+
["spawn_failed" /* SPAWN_FAILED */]: {
|
|
104
|
+
message: "\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C \u043F\u0440\u043E\u0446\u0435\u0441\u0441.",
|
|
105
|
+
fix: "\u041F\u0440\u043E\u0432\u0435\u0440\u044C\u0442\u0435 PATH \u0438 \u043F\u0440\u0430\u0432\u0430 \u0434\u043E\u0441\u0442\u0443\u043F\u0430"
|
|
106
|
+
},
|
|
107
|
+
["unknown" /* UNKNOWN */]: {
|
|
108
|
+
message: "\u041D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430.",
|
|
109
|
+
fix: "\u0417\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u0435: orch doctor",
|
|
110
|
+
doctorHint: true
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
function classifyAdapterError(error, exitCode) {
|
|
114
|
+
const lower = error.toLowerCase();
|
|
115
|
+
if (lower.includes("enoent") || lower.includes("spawn failed")) {
|
|
116
|
+
return "spawn_failed" /* SPAWN_FAILED */;
|
|
117
|
+
}
|
|
118
|
+
if (lower.includes("not found") || lower.includes("command not found") || lower.includes("no such file")) {
|
|
119
|
+
return "adapter_not_found" /* ADAPTER_NOT_FOUND */;
|
|
120
|
+
}
|
|
121
|
+
if (lower.includes("auth") || lower.includes("unauthorized") || lower.includes("401") || lower.includes("invalid api key") || lower.includes("authentication")) {
|
|
122
|
+
return "auth_failed" /* AUTH_FAILED */;
|
|
123
|
+
}
|
|
124
|
+
if (lower.includes("timeout") || lower.includes("timed out") || lower.includes("etimedout")) {
|
|
125
|
+
return "timeout" /* TIMEOUT */;
|
|
126
|
+
}
|
|
127
|
+
if (lower.includes("rate limit") || lower.includes("429") || lower.includes("too many requests")) {
|
|
128
|
+
return "rate_limit" /* RATE_LIMIT */;
|
|
129
|
+
}
|
|
130
|
+
if (exitCode !== void 0 && exitCode !== 0) {
|
|
131
|
+
return "process_crash" /* PROCESS_CRASH */;
|
|
132
|
+
}
|
|
133
|
+
return "unknown" /* UNKNOWN */;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export { AgentNotFoundError, ERROR_HINTS, GoalNotFoundError, InvalidArgumentsError, InvalidTransitionError, LockConflictError, NoAgentsError, NotInitializedError, OrchestryError, TaskAlreadyRunningError, TaskNotFoundError, TeamNotFoundError, WorkspaceError, classifyAdapterError };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// src/infrastructure/adapters/registry.ts
|
|
3
|
+
var AdapterRegistry = class {
|
|
4
|
+
adapters = /* @__PURE__ */ new Map();
|
|
5
|
+
register(adapter) {
|
|
6
|
+
this.adapters.set(adapter.kind, adapter);
|
|
7
|
+
}
|
|
8
|
+
get(kind) {
|
|
9
|
+
return this.adapters.get(kind);
|
|
10
|
+
}
|
|
11
|
+
require(kind) {
|
|
12
|
+
const adapter = this.adapters.get(kind);
|
|
13
|
+
if (!adapter) {
|
|
14
|
+
throw new Error(`Unknown adapter: "${kind}". Available: ${this.listKinds().join(", ")}`);
|
|
15
|
+
}
|
|
16
|
+
return adapter;
|
|
17
|
+
}
|
|
18
|
+
list() {
|
|
19
|
+
return Array.from(this.adapters.values());
|
|
20
|
+
}
|
|
21
|
+
listKinds() {
|
|
22
|
+
return Array.from(this.adapters.keys());
|
|
23
|
+
}
|
|
24
|
+
has(kind) {
|
|
25
|
+
return this.adapters.has(kind);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { AdapterRegistry };
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readLines } from './chunk-CHIP7O6V.js';
|
|
3
|
+
import { classifyAdapterError } from './chunk-2C2TFQ7K.js';
|
|
4
|
+
import { execFile } from 'child_process';
|
|
5
|
+
import { promisify } from 'util';
|
|
6
|
+
|
|
7
|
+
// src/infrastructure/adapters/event-buffer.ts
|
|
8
|
+
var DEFAULT_CAPACITY = 1024;
|
|
9
|
+
function deferred() {
|
|
10
|
+
let resolve;
|
|
11
|
+
const promise = new Promise((r) => {
|
|
12
|
+
resolve = r;
|
|
13
|
+
});
|
|
14
|
+
return { promise, resolve };
|
|
15
|
+
}
|
|
16
|
+
var EventBuffer = class {
|
|
17
|
+
buf;
|
|
18
|
+
head = 0;
|
|
19
|
+
// read index
|
|
20
|
+
tail = 0;
|
|
21
|
+
// write index
|
|
22
|
+
count = 0;
|
|
23
|
+
capacity;
|
|
24
|
+
// Consumer notification: resolved when new data is available
|
|
25
|
+
dataReady = null;
|
|
26
|
+
// Producer notification: resolved when space is available
|
|
27
|
+
spaceReady = null;
|
|
28
|
+
closed = false;
|
|
29
|
+
constructor(capacity = DEFAULT_CAPACITY) {
|
|
30
|
+
this.capacity = capacity;
|
|
31
|
+
this.buf = new Array(capacity);
|
|
32
|
+
}
|
|
33
|
+
/** Number of buffered events. */
|
|
34
|
+
get size() {
|
|
35
|
+
return this.count;
|
|
36
|
+
}
|
|
37
|
+
get isFull() {
|
|
38
|
+
return this.count >= this.capacity;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Push an event into the buffer.
|
|
42
|
+
* If the buffer is full, waits until space is available (backpressure).
|
|
43
|
+
*/
|
|
44
|
+
async push(event) {
|
|
45
|
+
while (this.isFull && !this.closed) {
|
|
46
|
+
if (!this.spaceReady) {
|
|
47
|
+
this.spaceReady = deferred();
|
|
48
|
+
}
|
|
49
|
+
await this.spaceReady.promise;
|
|
50
|
+
}
|
|
51
|
+
if (this.closed) return;
|
|
52
|
+
this.buf[this.tail] = event;
|
|
53
|
+
this.tail = (this.tail + 1) % this.capacity;
|
|
54
|
+
this.count++;
|
|
55
|
+
if (this.dataReady) {
|
|
56
|
+
const dr = this.dataReady;
|
|
57
|
+
this.dataReady = null;
|
|
58
|
+
dr.resolve();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Dequeue the next event. O(1).
|
|
63
|
+
* Returns undefined only when buffer is empty AND closed.
|
|
64
|
+
*/
|
|
65
|
+
async take() {
|
|
66
|
+
while (this.count === 0) {
|
|
67
|
+
if (this.closed) return void 0;
|
|
68
|
+
if (!this.dataReady) {
|
|
69
|
+
this.dataReady = deferred();
|
|
70
|
+
}
|
|
71
|
+
await this.dataReady.promise;
|
|
72
|
+
}
|
|
73
|
+
const event = this.buf[this.head];
|
|
74
|
+
this.buf[this.head] = void 0;
|
|
75
|
+
this.head = (this.head + 1) % this.capacity;
|
|
76
|
+
this.count--;
|
|
77
|
+
if (this.spaceReady) {
|
|
78
|
+
const sr = this.spaceReady;
|
|
79
|
+
this.spaceReady = null;
|
|
80
|
+
sr.resolve();
|
|
81
|
+
}
|
|
82
|
+
return event;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Signal that no more events will be pushed.
|
|
86
|
+
* Wakes up any waiting consumer/producer.
|
|
87
|
+
*/
|
|
88
|
+
close() {
|
|
89
|
+
this.closed = true;
|
|
90
|
+
if (this.dataReady) {
|
|
91
|
+
const dr = this.dataReady;
|
|
92
|
+
this.dataReady = null;
|
|
93
|
+
dr.resolve();
|
|
94
|
+
}
|
|
95
|
+
if (this.spaceReady) {
|
|
96
|
+
const sr = this.spaceReady;
|
|
97
|
+
this.spaceReady = null;
|
|
98
|
+
sr.resolve();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
get isClosed() {
|
|
102
|
+
return this.closed;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Async iterator that drains the buffer until closed and empty.
|
|
106
|
+
*/
|
|
107
|
+
async *[Symbol.asyncIterator]() {
|
|
108
|
+
while (true) {
|
|
109
|
+
const event = await this.take();
|
|
110
|
+
if (event === void 0) return;
|
|
111
|
+
yield event;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
var execFileAsync = promisify(execFile);
|
|
116
|
+
var ShellAdapter = class {
|
|
117
|
+
constructor(processManager) {
|
|
118
|
+
this.processManager = processManager;
|
|
119
|
+
}
|
|
120
|
+
kind = "shell";
|
|
121
|
+
async test() {
|
|
122
|
+
try {
|
|
123
|
+
const { stdout } = await execFileAsync("bash", ["--version"]);
|
|
124
|
+
const version = stdout.split("\n")[0]?.trim() ?? "unknown";
|
|
125
|
+
return { ok: true, version };
|
|
126
|
+
} catch {
|
|
127
|
+
return { ok: false, error: "bash not found", errorKind: classifyAdapterError("bash not found") };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
execute(params) {
|
|
131
|
+
const command = params.config.command;
|
|
132
|
+
if (!command) {
|
|
133
|
+
async function* errorGen() {
|
|
134
|
+
yield {
|
|
135
|
+
type: "error",
|
|
136
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
137
|
+
data: "Shell adapter requires a command in agent config",
|
|
138
|
+
errorKind: "spawn_failed" /* SPAWN_FAILED */
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return { pid: 0, events: errorGen() };
|
|
142
|
+
}
|
|
143
|
+
const { process: proc, pid } = this.processManager.spawn("bash", ["-lc", command], {
|
|
144
|
+
cwd: params.workspace,
|
|
145
|
+
env: {
|
|
146
|
+
...process.env,
|
|
147
|
+
...params.env,
|
|
148
|
+
ORCHESTRY_TASK_PROMPT: params.prompt
|
|
149
|
+
},
|
|
150
|
+
signal: params.signal
|
|
151
|
+
});
|
|
152
|
+
const signal = params.signal;
|
|
153
|
+
const processManager = this.processManager;
|
|
154
|
+
async function* generateEvents() {
|
|
155
|
+
const buffer = new EventBuffer();
|
|
156
|
+
const onAbort = () => {
|
|
157
|
+
processManager.killWithGrace(pid, 5e3).catch(() => {
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
if (signal) {
|
|
161
|
+
if (signal.aborted) {
|
|
162
|
+
onAbort();
|
|
163
|
+
} else {
|
|
164
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const stdoutPromise = (async () => {
|
|
168
|
+
if (!proc.stdout) return;
|
|
169
|
+
for await (const line of readLines(proc.stdout)) {
|
|
170
|
+
if (signal?.aborted) break;
|
|
171
|
+
await buffer.push({
|
|
172
|
+
type: "output",
|
|
173
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
174
|
+
data: line
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
})();
|
|
178
|
+
const stderrPromise = (async () => {
|
|
179
|
+
if (!proc.stderr) return;
|
|
180
|
+
for await (const line of readLines(proc.stderr)) {
|
|
181
|
+
if (signal?.aborted) break;
|
|
182
|
+
await buffer.push({
|
|
183
|
+
type: "error",
|
|
184
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
185
|
+
data: line,
|
|
186
|
+
errorKind: classifyAdapterError(line)
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
})();
|
|
190
|
+
void Promise.all([stdoutPromise, stderrPromise]).then(
|
|
191
|
+
() => buffer.close(),
|
|
192
|
+
() => buffer.close()
|
|
193
|
+
);
|
|
194
|
+
yield* buffer;
|
|
195
|
+
if (signal && !signal.aborted) {
|
|
196
|
+
signal.removeEventListener("abort", onAbort);
|
|
197
|
+
}
|
|
198
|
+
await new Promise((resolve, reject) => {
|
|
199
|
+
if (proc.exitCode !== null || proc.killed) {
|
|
200
|
+
resolve();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
proc.on("close", (code) => {
|
|
204
|
+
if (code === 0 || signal?.aborted) {
|
|
205
|
+
resolve();
|
|
206
|
+
} else {
|
|
207
|
+
reject(new Error(`Shell command exited with code ${code}`));
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
proc.on("error", reject);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return { pid, events: generateEvents() };
|
|
214
|
+
}
|
|
215
|
+
async stop(pid) {
|
|
216
|
+
await this.processManager.killWithGrace(pid);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export { ShellAdapter };
|