@oxgeneral/orch 1.0.1 → 1.0.3
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-A5TZETZ2.js +21 -0
- package/dist/agent-Q34L27AY.js +9 -0
- package/dist/agent-shop-D2RS4BZK.js +2 -0
- package/dist/chunk-4MMHVHA6.js +112 -0
- package/dist/chunk-64WUDYEM.js +6 -0
- package/dist/chunk-6MJ7V6VY.js +2 -0
- package/dist/{chunk-DAVHOWGD.js → chunk-BCPUTULS.js} +16 -188
- package/dist/{chunk-UIJYU3J7.js → chunk-BSJVYRI3.js} +5 -2
- package/dist/chunk-BSJVYRI3.js.map +1 -0
- package/dist/chunk-CDFA4IIQ.js +2 -0
- package/dist/chunk-CHRW4CLD.js +2 -0
- package/dist/{chunk-O2OQCSBL.js → chunk-FDSFFFMT.js} +46 -29
- package/dist/chunk-FDSFFFMT.js.map +1 -0
- package/dist/chunk-HMMPM7MF.js +3 -0
- package/dist/chunk-HXOMNULD.js +2 -0
- package/dist/chunk-IKNBPOQL.js +2 -0
- package/dist/chunk-KFQTWMZI.js +3 -0
- package/dist/chunk-LXNRCJ22.js +2 -0
- package/dist/{chunk-C6XZ3FJT.js → chunk-MOWC2CHX.js} +7 -4
- package/dist/chunk-MOWC2CHX.js.map +1 -0
- package/dist/chunk-P4JTJBWO.js +2 -0
- package/dist/chunk-PJ5DKXGR.js +2 -0
- package/dist/chunk-QNZ6D63E.js +4 -0
- package/dist/chunk-RHFRHCN5.js +16 -0
- package/dist/chunk-RHFRHCN5.js.map +1 -0
- package/dist/chunk-TPTHLFOB.js +2 -0
- package/dist/chunk-UMZEA3JT.js +5 -0
- package/dist/chunk-X54D5JZG.js +11 -0
- package/dist/{claude-WUJU5KIE.js → claude-4R6L6BWY.js} +4 -4
- package/dist/{claude-WUJU5KIE.js.map → claude-4R6L6BWY.js.map} +1 -1
- package/dist/claude-ZLVOLRUG.js +2 -0
- package/dist/cli.js +1 -199
- package/dist/clipboard-service-WVON5ZN4.js +25 -0
- package/dist/{codex-NYJWEPRQ.js → codex-IMOW5ZUZ.js} +4 -4
- package/dist/{codex-NYJWEPRQ.js.map → codex-IMOW5ZUZ.js.map} +1 -1
- package/dist/codex-YRSODLH4.js +2 -0
- package/dist/config-OOB7QEKM.js +2 -0
- package/dist/container-CFMUT5KS.js +4 -0
- package/dist/context-FXRERFSP.js +7 -0
- package/dist/cursor-2HILMNM3.js +2 -0
- package/dist/{cursor-3YHVD4NP.js → cursor-NHV7X3WG.js} +4 -4
- package/dist/{cursor-3YHVD4NP.js.map → cursor-NHV7X3WG.js.map} +1 -1
- package/dist/doctor-GKTV4YYD.js +2 -0
- package/dist/doctor-service-PB7YBH3F.js +2 -0
- package/dist/editor-7IFRWVTL.js +8 -0
- package/dist/goal-RNNZYMNR.js +8 -0
- package/dist/index.d.ts +16 -14
- package/dist/index.js +247 -75
- package/dist/index.js.map +1 -1
- package/dist/init-56QC5QVX.js +53 -0
- package/dist/logs-4ISTWUWV.js +12 -0
- package/dist/msg-4ELI7Q52.js +9 -0
- package/dist/opencode-3S4VDXRG.js +2 -0
- package/dist/{opencode-FAMPSA6X.js → opencode-ULT6DYCT.js} +6 -5
- package/dist/opencode-ULT6DYCT.js.map +1 -0
- package/dist/orchestrator-6XH2TY3T.js +6 -0
- package/dist/{orchestrator-X2CWGFCL.js.map → orchestrator-6XH2TY3T.js.map} +1 -1
- package/dist/orchestrator-DRITPUWT.js +13 -0
- package/dist/org-WAK3CDPG.js +3 -0
- package/dist/process-manager-33H27MQF.js +2 -0
- package/dist/registry-BO2PPRNG.js +2 -0
- package/dist/run-NE5E4JPW.js +3 -0
- package/dist/shell-OBHIVC2H.js +2 -0
- package/dist/{shell-NJNW3O6K.js → shell-UXEJRK3D.js} +4 -4
- package/dist/{shell-NJNW3O6K.js.map → shell-UXEJRK3D.js.map} +1 -1
- package/dist/shop-picker-LE3SKFOX.js +5 -0
- package/dist/status-NYHZ7Q5G.js +2 -0
- package/dist/task-JUS5OZJR.js +20 -0
- package/dist/team-VCJSUDWX.js +4 -0
- package/dist/template-engine-42PKL5KD.js +2 -0
- package/dist/tui-R6LXKKSH.js +2 -0
- package/dist/update-FFKCOV63.js +2 -0
- package/dist/update-check-HGMBDYHL.js +2 -0
- package/dist/{workspace-manager-EVD67GCG.js → workspace-manager-ABXFBL2A.js} +3 -3
- package/dist/{workspace-manager-EVD67GCG.js.map → workspace-manager-ABXFBL2A.js.map} +1 -1
- package/dist/workspace-manager-Q6WWXSTR.js +3 -0
- package/package.json +1 -1
- package/readme.md +5 -5
- package/dist/App-GJVTVGRU.js +0 -6717
- package/dist/agent-7ZJ3ZDJ7.js +0 -183
- package/dist/agent-shop-YN2BSLHM.js +0 -2
- package/dist/chunk-2C2TFQ7K.js +0 -136
- package/dist/chunk-45K2XID7.js +0 -29
- package/dist/chunk-4IFIOMCW.js +0 -86
- package/dist/chunk-7X2GI5OV.js +0 -181
- package/dist/chunk-C6XZ3FJT.js.map +0 -1
- package/dist/chunk-CHIP7O6V.js +0 -83
- package/dist/chunk-FRTKB575.js +0 -87
- package/dist/chunk-HXYAZGLP.js +0 -15
- package/dist/chunk-I3SMISEF.js +0 -29
- package/dist/chunk-K6DMQERQ.js +0 -89
- package/dist/chunk-LV6GDBBI.js +0 -297
- package/dist/chunk-MGGSRXWJ.js +0 -69
- package/dist/chunk-O2OQCSBL.js.map +0 -1
- package/dist/chunk-P6ATSXGL.js +0 -107
- package/dist/chunk-PNE6LQRF.js +0 -5
- package/dist/chunk-U2VDNUZL.js +0 -52
- package/dist/chunk-UIJYU3J7.js.map +0 -1
- package/dist/chunk-VXS2CJFH.js +0 -273
- package/dist/chunk-XDVMX2FO.js +0 -8
- package/dist/chunk-XDVMX2FO.js.map +0 -1
- package/dist/chunk-XJTJ2TJV.js +0 -221
- package/dist/claude-ZUEKJJ4X.js +0 -5
- package/dist/clipboard-service-RTDUUQQU.js +0 -200
- package/dist/codex-7IXXXG5U.js +0 -123
- package/dist/config-OTAVSMOD.js +0 -75
- package/dist/container-RY54L3XC.js +0 -1596
- package/dist/context-OL4BVUV5.js +0 -83
- package/dist/cursor-622RBRHH.js +0 -97
- package/dist/doctor-XSGQSD57.js +0 -67
- package/dist/doctor-service-TPOMFAIG.js +0 -2
- package/dist/goal-FMYYN2FR.js +0 -138
- package/dist/init-45BEMVL6.js +0 -199
- package/dist/logs-PHPYWQ6I.js +0 -207
- package/dist/msg-FUWWLEKM.js +0 -95
- package/dist/opencode-FAMPSA6X.js.map +0 -1
- package/dist/opencode-WOR53TSC.js +0 -98
- package/dist/orchestrator-O6MFMATT.js +0 -1448
- package/dist/orchestrator-X2CWGFCL.js +0 -5
- package/dist/process-manager-HUVNAPQV.js +0 -2
- package/dist/registry-PQWRVNF2.js +0 -2
- package/dist/run-N72G5V2H.js +0 -95
- package/dist/shell-DVFHHYAZ.js +0 -5
- package/dist/shop-picker-2HY67UWP.js +0 -79
- package/dist/status-RZWN2C6C.js +0 -56
- package/dist/task-5EL2RNGW.js +0 -221
- package/dist/team-PFLP4PPL.js +0 -97
- package/dist/template-engine-AWIS56BL.js +0 -3
- package/dist/tui-LN5XHSQY.js +0 -245
- package/dist/update-YLP7FPNY.js +0 -64
- package/dist/update-check-4YKLGBFB.js +0 -2
- package/dist/workspace-manager-JM6U7JOH.js +0 -215
package/dist/agent-7ZJ3ZDJ7.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
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, opencode, codex, cursor, shell").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 };
|
package/dist/chunk-2C2TFQ7K.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
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 };
|
package/dist/chunk-45K2XID7.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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 };
|
package/dist/chunk-4IFIOMCW.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createStreamingEvents, extractTokens } from './chunk-MGGSRXWJ.js';
|
|
3
|
-
import { classifyAdapterError } from './chunk-2C2TFQ7K.js';
|
|
4
|
-
import { execFile } from 'child_process';
|
|
5
|
-
import { promisify } from 'util';
|
|
6
|
-
|
|
7
|
-
var execFileAsync = promisify(execFile);
|
|
8
|
-
var ClaudeAdapter = class {
|
|
9
|
-
constructor(processManager) {
|
|
10
|
-
this.processManager = processManager;
|
|
11
|
-
}
|
|
12
|
-
kind = "claude";
|
|
13
|
-
async test() {
|
|
14
|
-
try {
|
|
15
|
-
const { stdout } = await execFileAsync("claude", ["--version"]);
|
|
16
|
-
return { ok: true, version: stdout.trim() };
|
|
17
|
-
} catch (err) {
|
|
18
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
19
|
-
return {
|
|
20
|
-
ok: false,
|
|
21
|
-
error: "Claude Code CLI not found. Install: npm i -g @anthropic-ai/claude-code",
|
|
22
|
-
errorKind: classifyAdapterError(msg)
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
execute(params) {
|
|
27
|
-
const args = [
|
|
28
|
-
"--print",
|
|
29
|
-
"--output-format",
|
|
30
|
-
"stream-json",
|
|
31
|
-
"--max-turns",
|
|
32
|
-
String(params.config.max_turns ?? 50),
|
|
33
|
-
"--verbose",
|
|
34
|
-
"--dangerously-skip-permissions"
|
|
35
|
-
// Agents run autonomously; stdin is 'ignore' so prompts would hang
|
|
36
|
-
];
|
|
37
|
-
if (params.config.model) {
|
|
38
|
-
args.push("--model", params.config.model);
|
|
39
|
-
}
|
|
40
|
-
const effectiveSystemPrompt = params.systemPrompt ?? params.config.system_prompt;
|
|
41
|
-
if (effectiveSystemPrompt) {
|
|
42
|
-
args.push("--system-prompt", effectiveSystemPrompt);
|
|
43
|
-
}
|
|
44
|
-
args.push(params.prompt);
|
|
45
|
-
const { process: proc, pid } = this.processManager.spawn("claude", args, {
|
|
46
|
-
cwd: params.workspace,
|
|
47
|
-
env: { ...process.env, ...params.env },
|
|
48
|
-
signal: params.signal
|
|
49
|
-
});
|
|
50
|
-
const events = createStreamingEvents(proc, parseClaudeEvent, "Claude", params.signal);
|
|
51
|
-
return { pid, events };
|
|
52
|
-
}
|
|
53
|
-
async stop(pid) {
|
|
54
|
-
await this.processManager.killWithGrace(pid);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
function parseClaudeEvent(line) {
|
|
58
|
-
if (!line.trim()) return null;
|
|
59
|
-
try {
|
|
60
|
-
const parsed = JSON.parse(line);
|
|
61
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
62
|
-
switch (parsed.type) {
|
|
63
|
-
case "assistant":
|
|
64
|
-
return { type: "output", timestamp, data: parsed.message ?? parsed };
|
|
65
|
-
case "tool_use":
|
|
66
|
-
return { type: "tool_call", timestamp, data: parsed };
|
|
67
|
-
case "tool_result":
|
|
68
|
-
return { type: "output", timestamp, data: parsed };
|
|
69
|
-
case "error": {
|
|
70
|
-
const errData = parsed.error ?? parsed;
|
|
71
|
-
const errMsg = typeof errData === "string" ? errData : JSON.stringify(errData);
|
|
72
|
-
return { type: "error", timestamp, data: errData, errorKind: classifyAdapterError(errMsg) };
|
|
73
|
-
}
|
|
74
|
-
case "result": {
|
|
75
|
-
const tokens = extractTokens(parsed, { statsFallback: true });
|
|
76
|
-
return { type: "done", timestamp, data: parsed, tokens };
|
|
77
|
-
}
|
|
78
|
-
default:
|
|
79
|
-
return { type: "output", timestamp, data: parsed };
|
|
80
|
-
}
|
|
81
|
-
} catch {
|
|
82
|
-
return { type: "output", timestamp: (/* @__PURE__ */ new Date()).toISOString(), data: line };
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export { ClaudeAdapter };
|
package/dist/chunk-7X2GI5OV.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
|
|
4
|
-
var icons = {
|
|
5
|
-
running: "\u25CF",
|
|
6
|
-
todo: "\u25CB",
|
|
7
|
-
review: "\u25C8",
|
|
8
|
-
done: "\u2713",
|
|
9
|
-
failed: "\u2715",
|
|
10
|
-
retrying: "\u21BB",
|
|
11
|
-
cancelled: "\u25CB",
|
|
12
|
-
idle: "\u25CB",
|
|
13
|
-
error: "\u2715",
|
|
14
|
-
disabled: "\u2500",
|
|
15
|
-
agentAction: "\u25B8",
|
|
16
|
-
orchestratorEvent: "\u2192",
|
|
17
|
-
warning: "\u26A0"
|
|
18
|
-
};
|
|
19
|
-
var asciiIcons = {
|
|
20
|
-
running: "*",
|
|
21
|
-
todo: "o",
|
|
22
|
-
review: "#",
|
|
23
|
-
done: "+",
|
|
24
|
-
failed: "x",
|
|
25
|
-
retrying: "~",
|
|
26
|
-
cancelled: "o",
|
|
27
|
-
idle: "o",
|
|
28
|
-
error: "x",
|
|
29
|
-
disabled: "-",
|
|
30
|
-
agentAction: ">",
|
|
31
|
-
orchestratorEvent: "->",
|
|
32
|
-
warning: "!!"
|
|
33
|
-
};
|
|
34
|
-
var COLOR_CODES = {
|
|
35
|
-
amber: 214,
|
|
36
|
-
green: 72,
|
|
37
|
-
red: 167,
|
|
38
|
-
blue: 74,
|
|
39
|
-
yellow: 178,
|
|
40
|
-
dim: 240,
|
|
41
|
-
ghost: 236,
|
|
42
|
-
white: 255,
|
|
43
|
-
purple: 141
|
|
44
|
-
};
|
|
45
|
-
var _colors;
|
|
46
|
-
function getColors() {
|
|
47
|
-
if (!_colors) {
|
|
48
|
-
_colors = {};
|
|
49
|
-
for (const [name, code] of Object.entries(COLOR_CODES)) {
|
|
50
|
-
_colors[name] = chalk.ansi256(code);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return _colors;
|
|
54
|
-
}
|
|
55
|
-
var colors = new Proxy({}, {
|
|
56
|
-
get(_target, prop) {
|
|
57
|
-
return getColors()[prop];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
var useAscii = false;
|
|
61
|
-
function setAsciiMode(ascii) {
|
|
62
|
-
useAscii = ascii;
|
|
63
|
-
}
|
|
64
|
-
function setNoColor(noColor) {
|
|
65
|
-
if (noColor) {
|
|
66
|
-
chalk.level = 0;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function getIcon(name) {
|
|
70
|
-
return useAscii ? asciiIcons[name] : icons[name];
|
|
71
|
-
}
|
|
72
|
-
function statusIcon(status) {
|
|
73
|
-
const icon = getIcon(status);
|
|
74
|
-
switch (status) {
|
|
75
|
-
case "running":
|
|
76
|
-
case "in_progress":
|
|
77
|
-
return colors.green(getIcon("running"));
|
|
78
|
-
case "todo":
|
|
79
|
-
return colors.dim(getIcon("todo"));
|
|
80
|
-
case "review":
|
|
81
|
-
return colors.blue(getIcon("review"));
|
|
82
|
-
case "done":
|
|
83
|
-
return colors.green(getIcon("done"));
|
|
84
|
-
case "failed":
|
|
85
|
-
return colors.red(getIcon("failed"));
|
|
86
|
-
case "retrying":
|
|
87
|
-
return colors.yellow(getIcon("retrying"));
|
|
88
|
-
case "cancelled":
|
|
89
|
-
return colors.dim(getIcon("cancelled"));
|
|
90
|
-
case "idle":
|
|
91
|
-
return colors.dim(getIcon("idle"));
|
|
92
|
-
case "error":
|
|
93
|
-
return colors.red(getIcon("error"));
|
|
94
|
-
case "disabled":
|
|
95
|
-
return colors.ghost(getIcon("disabled"));
|
|
96
|
-
default:
|
|
97
|
-
return icon;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function priorityLabel(priority) {
|
|
101
|
-
switch (priority) {
|
|
102
|
-
case 1:
|
|
103
|
-
return colors.red("P1");
|
|
104
|
-
case 2:
|
|
105
|
-
return colors.yellow("P2");
|
|
106
|
-
case 3:
|
|
107
|
-
return "P3";
|
|
108
|
-
case 4:
|
|
109
|
-
return colors.dim("P4");
|
|
110
|
-
default:
|
|
111
|
-
return `P${priority}`;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function formatDuration(ms) {
|
|
115
|
-
const seconds = Math.floor(ms / 1e3);
|
|
116
|
-
if (seconds < 60) return `${seconds}s`;
|
|
117
|
-
const minutes = Math.floor(seconds / 60);
|
|
118
|
-
const secs = seconds % 60;
|
|
119
|
-
if (minutes < 60) return `${minutes}:${String(secs).padStart(2, "0")}`;
|
|
120
|
-
const hours = Math.floor(minutes / 60);
|
|
121
|
-
const mins = minutes % 60;
|
|
122
|
-
return `${hours}h${String(mins).padStart(2, "0")}m`;
|
|
123
|
-
}
|
|
124
|
-
function formatDurationSince(isoDate) {
|
|
125
|
-
const ms = Date.now() - new Date(isoDate).getTime();
|
|
126
|
-
return formatDuration(ms);
|
|
127
|
-
}
|
|
128
|
-
function formatTokens(n) {
|
|
129
|
-
if (n >= 1e3) return `${(n / 1e3).toFixed(1)}k`;
|
|
130
|
-
return String(n);
|
|
131
|
-
}
|
|
132
|
-
function printError(message, hint) {
|
|
133
|
-
console.error(` ${colors.red(getIcon("failed"))} ${message}`);
|
|
134
|
-
if (hint) {
|
|
135
|
-
console.error(` ${hint}`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function printSuccess(message) {
|
|
139
|
-
console.log(` ${colors.green(getIcon("done"))} ${message}`);
|
|
140
|
-
}
|
|
141
|
-
function printWarning(message) {
|
|
142
|
-
console.log(` ${colors.yellow(getIcon("warning"))} ${message}`);
|
|
143
|
-
}
|
|
144
|
-
function printTable(headers, rows, padding = 2) {
|
|
145
|
-
const colWidths = headers.map(
|
|
146
|
-
(h, i) => Math.max(h.length, ...rows.map((r) => stripAnsi(r[i] ?? "").length))
|
|
147
|
-
);
|
|
148
|
-
const headerLine = headers.map((h, i) => h.padEnd(colWidths[i] + padding)).join("");
|
|
149
|
-
console.log(` ${colors.dim(headerLine)}`);
|
|
150
|
-
for (const row of rows) {
|
|
151
|
-
const line = row.map((cell, i) => {
|
|
152
|
-
const stripped = stripAnsi(cell);
|
|
153
|
-
const pad = (colWidths[i] ?? 0) + padding - stripped.length;
|
|
154
|
-
return cell + " ".repeat(Math.max(0, pad));
|
|
155
|
-
}).join("");
|
|
156
|
-
console.log(` ${line}`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function printKeyValue(pairs) {
|
|
160
|
-
const maxKey = Math.max(...pairs.map(([k]) => k.length));
|
|
161
|
-
for (const [key, value] of pairs) {
|
|
162
|
-
console.log(` ${colors.dim(key.padEnd(maxKey + 2))}${value}`);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
function filePath(p) {
|
|
166
|
-
return colors.purple(p);
|
|
167
|
-
}
|
|
168
|
-
function agentName(name) {
|
|
169
|
-
return colors.green(name);
|
|
170
|
-
}
|
|
171
|
-
function amber(text) {
|
|
172
|
-
return colors.amber(text);
|
|
173
|
-
}
|
|
174
|
-
function dim(text) {
|
|
175
|
-
return colors.dim(text);
|
|
176
|
-
}
|
|
177
|
-
function stripAnsi(str) {
|
|
178
|
-
return str.replace(/\x1b\[[0-9;]*m/g, "");
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export { agentName, amber, dim, filePath, formatDuration, formatDurationSince, formatTokens, getIcon, printError, printKeyValue, printSuccess, printTable, printWarning, priorityLabel, setAsciiMode, setNoColor, statusIcon };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/infrastructure/adapters/utils.ts"],"names":[],"mappings":"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","file":"chunk-C6XZ3FJT.js","sourcesContent":["/**\n * Shared utilities for agent adapters.\n *\n * Deduplicates extractTokens and streaming event generation logic\n * common to claude, codex, and cursor adapters.\n */\n\nimport type { ChildProcess } from 'node:child_process';\nimport type { AgentEvent } from './interface.js';\nimport { readLines } from '../process/process-manager.js';\nimport { createTokenUsage } from '../../domain/run.js';\nimport { classifyAdapterError } from '../../domain/errors.js';\n\nexport type TokenInfo = { input: number; output: number; total: number };\n\n/** Combine system and user prompts. Adapters without native system prompt support use this. */\nexport function buildFullPrompt(systemPrompt: string | undefined, userPrompt: string): string {\n return systemPrompt ? systemPrompt + '\\n\\n' + userPrompt : userPrompt;\n}\n\n/**\n * Extract token usage from a parsed JSON event.\n *\n * @param parsed - The parsed JSON object from an adapter event line.\n * @param opts.statsFallback - If true, also checks `parsed.stats?.usage` (Claude-specific).\n */\nexport function extractTokens(\n parsed: Record<string, unknown>,\n opts?: { statsFallback?: boolean },\n): TokenInfo | undefined {\n let usage = parsed.usage as Record<string, unknown> | undefined;\n\n if (!usage && opts?.statsFallback) {\n const stats = parsed.stats as Record<string, unknown> | undefined;\n usage = stats?.usage as Record<string, unknown> | undefined;\n }\n\n if (usage && typeof usage.input_tokens === 'number') {\n const input = usage.input_tokens;\n const output = typeof usage.output_tokens === 'number' ? usage.output_tokens : 0;\n return createTokenUsage(input, output);\n }\n return undefined;\n}\n\n/**\n * Create an async generator that streams AgentEvents from a child process.\n *\n * Handles: exit promise setup, line-by-line reading, abort signal, exit code checking.\n *\n * @param proc - The spawned child process.\n * @param parseEvent - Adapter-specific function to parse a line into an AgentEvent.\n * @param adapterName - Name used in error messages (e.g. \"Claude\", \"Codex\").\n * @param signal - Optional abort signal.\n */\nexport function createStreamingEvents(\n proc: ChildProcess,\n parseEvent: (line: string) => AgentEvent | null,\n adapterName: string,\n signal?: AbortSignal,\n): AsyncGenerator<AgentEvent> {\n async function* generate(): AsyncGenerator<AgentEvent> {\n let gotDoneEvent = false;\n\n let exitCode: number | null = null;\n let exitError: Error | null = null;\n const exitPromise = new Promise<void>((resolve) => {\n proc.on('close', (code) => { exitCode = code; resolve(); });\n proc.on('error', (err) => { exitError = err; resolve(); });\n });\n\n if (proc.stdout) {\n for await (const line of readLines(proc.stdout)) {\n if (signal?.aborted) break;\n const event = parseEvent(line);\n if (event) {\n if (event.type === 'done') gotDoneEvent = true;\n yield event;\n }\n }\n }\n\n await exitPromise;\n\n if (exitError && !signal?.aborted && !gotDoneEvent) {\n const spawnErr = exitError as Error;\n const classified = classifyAdapterError(spawnErr.message, exitCode ?? undefined);\n const err = Object.assign(new Error(spawnErr.message), { errorKind: classified });\n throw err;\n }\n if (exitCode !== 0 && exitCode !== null && !signal?.aborted && !gotDoneEvent) {\n const msg = `${adapterName} process exited with code ${exitCode}`;\n const classified = classifyAdapterError(msg, exitCode);\n const err = Object.assign(new Error(msg), { errorKind: classified });\n throw err;\n }\n }\n\n return generate();\n}\n"]}
|