@oxgeneral/orch 0.3.2 → 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/{shell-IH2MMTVP.js → chunk-52BFUGDD.js} +8 -6
- 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/{claude-RIB3RQS5.js → chunk-D6RFF3KN.js} +12 -9
- 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-NLQAJ7TW.js +147 -0
- package/dist/chunk-NLQAJ7TW.js.map +1 -0
- package/dist/chunk-P6ATSXGL.js +107 -0
- package/dist/chunk-PNE6LQRF.js +5 -0
- package/dist/{chunk-MGFMVPRD.js → chunk-S3QYSBW4.js} +11 -4
- package/dist/chunk-S3QYSBW4.js.map +1 -0
- package/dist/chunk-U2VDNUZL.js +52 -0
- package/dist/{chunk-QEEM67OA.js → chunk-UIJYU3J7.js} +3 -3
- package/dist/{chunk-QEEM67OA.js.map → chunk-UIJYU3J7.js.map} +1 -1
- package/dist/{chunk-2UC4SVJB.js → chunk-VMDQVRBR.js} +22 -8
- package/dist/chunk-VMDQVRBR.js.map +1 -0
- package/dist/chunk-W6RSVMXR.js +66 -0
- package/dist/claude-INM52PTH.js +88 -0
- package/dist/claude-INM52PTH.js.map +1 -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-VBUSA2GJ.js → codex-DIXT44JR.js} +17 -11
- package/dist/codex-QGH2GRV6.js +125 -0
- package/dist/codex-QGH2GRV6.js.map +1 -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-4QIOTDBW.js → cursor-C3TR2IJC.js} +11 -8
- package/dist/cursor-KQJTQ73D.js +99 -0
- package/dist/cursor-KQJTQ73D.js.map +1 -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 +64 -41
- package/dist/index.js +23 -14
- 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-FGGXK3N3.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-JXOPKDXH.js +221 -0
- 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-T6AXG7XL.js → workspace-manager-EVD67GCG.js} +4 -4
- package/dist/{workspace-manager-T6AXG7XL.js.map → workspace-manager-EVD67GCG.js.map} +1 -1
- 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-YJM5QGP7.js +0 -19
- package/dist/agent-S4DKSX63.js +0 -9
- package/dist/agent-shop-D2RS4BZK.js +0 -2
- package/dist/chunk-2UC4SVJB.js.map +0 -1
- package/dist/chunk-5AJ4LYO5.js +0 -8
- package/dist/chunk-6MJ7V6VY.js +0 -2
- package/dist/chunk-CDFA4IIQ.js +0 -2
- package/dist/chunk-CHRW4CLD.js +0 -2
- package/dist/chunk-GZ2Q56YZ.js +0 -2
- package/dist/chunk-HMMPM7MF.js +0 -3
- package/dist/chunk-HXOMNULD.js +0 -2
- package/dist/chunk-IQXRQBUK.js +0 -83
- package/dist/chunk-IQXRQBUK.js.map +0 -1
- package/dist/chunk-L26TK7Y5.js +0 -2
- package/dist/chunk-L3FYR45M.js +0 -2
- package/dist/chunk-LXNRCJ22.js +0 -2
- package/dist/chunk-MGFMVPRD.js.map +0 -1
- package/dist/chunk-MNXU3KCD.js +0 -2
- package/dist/chunk-PJ5DKXGR.js +0 -2
- package/dist/chunk-UMZEA3JT.js +0 -5
- package/dist/chunk-UW6GUUE6.js +0 -3
- package/dist/chunk-ZA5Z33GO.js +0 -11
- package/dist/claude-E36EGXUV.js +0 -2
- package/dist/claude-RIB3RQS5.js.map +0 -1
- package/dist/clipboard-service-PDTSZIR5.js +0 -25
- package/dist/codex-OTZKVESD.js +0 -2
- package/dist/codex-VBUSA2GJ.js.map +0 -1
- package/dist/config-CCSS2P7R.js +0 -2
- package/dist/container-OIXLFSX2.js +0 -6
- package/dist/context-GSMQHQES.js +0 -7
- package/dist/cursor-3DJA6LWS.js +0 -2
- package/dist/cursor-4QIOTDBW.js.map +0 -1
- package/dist/doctor-KBK5JZBZ.js +0 -2
- package/dist/doctor-service-PB7YBH3F.js +0 -2
- package/dist/goal-RFKFPR7M.js +0 -8
- package/dist/init-WRDFAFS2.js +0 -53
- package/dist/logs-5QHJWMEG.js +0 -12
- package/dist/msg-4SCLBO4K.js +0 -9
- package/dist/orchestrator-FGGXK3N3.js +0 -5
- package/dist/orchestrator-R7IWZUT6.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-EOJBDWTH.js +0 -2
- package/dist/shell-IH2MMTVP.js.map +0 -1
- package/dist/shop-picker-LE3SKFOX.js +0 -5
- package/dist/status-DLBNWSWM.js +0 -2
- package/dist/task-J6ZN7ALI.js +0 -20
- package/dist/team-MSIBKOQC.js +0 -4
- package/dist/template-engine-ONIDVD4F.js +0 -2
- package/dist/tui-LW7WIDE3.js +0 -2
- package/dist/update-PC2ENCKU.js +0 -2
- package/dist/update-check-HGMBDYHL.js +0 -2
- package/dist/workspace-manager-KOOYTO7E.js +0 -3
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { NotInitializedError } from './chunk-2C2TFQ7K.js';
|
|
3
|
+
import { randomBytes } from 'crypto';
|
|
4
|
+
import fs from 'fs/promises';
|
|
5
|
+
import path2 from 'path';
|
|
6
|
+
import yaml from 'js-yaml';
|
|
7
|
+
import { accessSync } from 'fs';
|
|
8
|
+
|
|
9
|
+
async function atomicWrite(filePath, content) {
|
|
10
|
+
const dir = path2.dirname(filePath);
|
|
11
|
+
await ensureDir(dir);
|
|
12
|
+
const tmpPath = path2.join(dir, `.${path2.basename(filePath)}.${randomBytes(4).toString("hex")}.tmp`);
|
|
13
|
+
try {
|
|
14
|
+
await fs.writeFile(tmpPath, content, "utf-8");
|
|
15
|
+
await fs.rename(tmpPath, filePath);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
await fs.unlink(tmpPath).catch(() => {
|
|
18
|
+
});
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function readYaml(filePath) {
|
|
23
|
+
try {
|
|
24
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
25
|
+
return yaml.load(content);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
if (isENOENT(err)) return null;
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function writeYaml(filePath, data) {
|
|
32
|
+
const content = yaml.dump(data, {
|
|
33
|
+
indent: 2,
|
|
34
|
+
lineWidth: 120,
|
|
35
|
+
noRefs: true,
|
|
36
|
+
sortKeys: false
|
|
37
|
+
});
|
|
38
|
+
await atomicWrite(filePath, content);
|
|
39
|
+
}
|
|
40
|
+
async function readJson(filePath) {
|
|
41
|
+
try {
|
|
42
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
43
|
+
return JSON.parse(content);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
if (isENOENT(err)) return null;
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function writeJson(filePath, data) {
|
|
50
|
+
const content = JSON.stringify(data, null, 2) + "\n";
|
|
51
|
+
await atomicWrite(filePath, content);
|
|
52
|
+
}
|
|
53
|
+
var PIPE_BUF = 4096;
|
|
54
|
+
async function appendJsonl(filePath, record) {
|
|
55
|
+
const dir = path2.dirname(filePath);
|
|
56
|
+
await ensureDir(dir);
|
|
57
|
+
let line = JSON.stringify(record) + "\n";
|
|
58
|
+
const byteLen = Buffer.byteLength(line, "utf-8");
|
|
59
|
+
if (byteLen > PIPE_BUF && record !== null && typeof record === "object") {
|
|
60
|
+
const obj = record;
|
|
61
|
+
if (typeof obj.data === "string" && obj.data.length > 0) {
|
|
62
|
+
const shell = JSON.stringify({ ...obj, data: "" }) + "\n";
|
|
63
|
+
const overhead = Buffer.byteLength(shell, "utf-8");
|
|
64
|
+
const budget = PIPE_BUF - overhead - 3;
|
|
65
|
+
if (budget > 0) {
|
|
66
|
+
const truncated = obj.data.slice(0, budget);
|
|
67
|
+
line = JSON.stringify({ ...obj, data: truncated + "\u2026" }) + "\n";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const fd = await fs.open(filePath, "a");
|
|
72
|
+
try {
|
|
73
|
+
await fd.write(line, null, "utf-8");
|
|
74
|
+
} finally {
|
|
75
|
+
await fd.close();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
var MAX_JSONL_READ_SIZE = 50 * 1024 * 1024;
|
|
79
|
+
async function readJsonl(filePath) {
|
|
80
|
+
try {
|
|
81
|
+
const stat = await fs.stat(filePath);
|
|
82
|
+
if (stat.size > MAX_JSONL_READ_SIZE) {
|
|
83
|
+
process.stderr.write(
|
|
84
|
+
`[readJsonl] file too large (${(stat.size / 1024 / 1024).toFixed(1)} MB), reading tail only: ${filePath}
|
|
85
|
+
`
|
|
86
|
+
);
|
|
87
|
+
return readJsonlTail(filePath, 200);
|
|
88
|
+
}
|
|
89
|
+
return readAndParseJsonl(filePath);
|
|
90
|
+
} catch (err) {
|
|
91
|
+
if (isENOENT(err)) return [];
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function readJsonlTail(filePath, count) {
|
|
96
|
+
try {
|
|
97
|
+
const stat = await fs.stat(filePath);
|
|
98
|
+
if (stat.size < 32768) {
|
|
99
|
+
return (await readAndParseJsonl(filePath)).slice(-count);
|
|
100
|
+
}
|
|
101
|
+
const fd = await fs.open(filePath, "r");
|
|
102
|
+
try {
|
|
103
|
+
const chunkSize = Math.min(stat.size, stat.size > 1048576 ? 131072 : 65536);
|
|
104
|
+
let position = Math.max(0, stat.size - chunkSize);
|
|
105
|
+
let earliestReadPosition = position;
|
|
106
|
+
let tail = "";
|
|
107
|
+
for (let attempt = 0; attempt < 4 && position >= 0; attempt++) {
|
|
108
|
+
earliestReadPosition = position;
|
|
109
|
+
const readSize = Math.min(chunkSize, stat.size - position);
|
|
110
|
+
const buf = Buffer.alloc(readSize);
|
|
111
|
+
await fd.read(buf, 0, readSize, position);
|
|
112
|
+
tail = buf.toString("utf-8") + tail;
|
|
113
|
+
const lines2 = tail.split("\n").filter((l) => l.trim().length > 0);
|
|
114
|
+
if (lines2.length >= count + 1) {
|
|
115
|
+
return parseJsonlLines(lines2.slice(-count));
|
|
116
|
+
}
|
|
117
|
+
if (position === 0) break;
|
|
118
|
+
position = Math.max(0, position - chunkSize);
|
|
119
|
+
}
|
|
120
|
+
const lines = tail.split("\n").filter((l) => l.trim().length > 0);
|
|
121
|
+
const safeLines = earliestReadPosition > 0 ? lines.slice(1) : lines;
|
|
122
|
+
return parseJsonlLines(safeLines.slice(-count));
|
|
123
|
+
} finally {
|
|
124
|
+
await fd.close();
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
if (isENOENT(err)) return [];
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async function readAndParseJsonl(filePath) {
|
|
132
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
133
|
+
const lines = content.split("\n").filter((l) => l.trim().length > 0);
|
|
134
|
+
return parseJsonlLines(lines);
|
|
135
|
+
}
|
|
136
|
+
function parseJsonlLines(lines) {
|
|
137
|
+
const results = [];
|
|
138
|
+
for (const raw of lines) {
|
|
139
|
+
const line = raw.trim();
|
|
140
|
+
if (!line) continue;
|
|
141
|
+
try {
|
|
142
|
+
results.push(JSON.parse(line));
|
|
143
|
+
} catch {
|
|
144
|
+
process.stderr.write(`[readJsonl] skipping corrupt line: ${line.slice(0, 200)}
|
|
145
|
+
`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return results;
|
|
149
|
+
}
|
|
150
|
+
async function ensureDir(dirPath) {
|
|
151
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
152
|
+
}
|
|
153
|
+
async function pathExists(filePath) {
|
|
154
|
+
try {
|
|
155
|
+
await fs.access(filePath);
|
|
156
|
+
return true;
|
|
157
|
+
} catch {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async function listFiles(dirPath, ext) {
|
|
162
|
+
try {
|
|
163
|
+
const entries = await fs.readdir(dirPath);
|
|
164
|
+
if (ext) {
|
|
165
|
+
return entries.filter((e) => e.endsWith(ext));
|
|
166
|
+
}
|
|
167
|
+
return entries;
|
|
168
|
+
} catch (err) {
|
|
169
|
+
if (isENOENT(err)) return [];
|
|
170
|
+
throw err;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function isENOENT(err) {
|
|
174
|
+
return err instanceof Error && "code" in err && err.code === "ENOENT";
|
|
175
|
+
}
|
|
176
|
+
var ORCHESTRY_DIR = ".orchestry";
|
|
177
|
+
var ID_PATTERN = /^[A-Za-z0-9._-]+$/;
|
|
178
|
+
var Paths = class {
|
|
179
|
+
constructor(projectRoot) {
|
|
180
|
+
this.projectRoot = projectRoot;
|
|
181
|
+
}
|
|
182
|
+
/** Root .orchestry/ directory */
|
|
183
|
+
get root() {
|
|
184
|
+
return path2.join(this.projectRoot, ORCHESTRY_DIR);
|
|
185
|
+
}
|
|
186
|
+
get configPath() {
|
|
187
|
+
return path2.join(this.root, "config.yml");
|
|
188
|
+
}
|
|
189
|
+
get statePath() {
|
|
190
|
+
return path2.join(this.root, "state.json");
|
|
191
|
+
}
|
|
192
|
+
get lockPath() {
|
|
193
|
+
return path2.join(this.root, "orchestry.lock");
|
|
194
|
+
}
|
|
195
|
+
get tasksDir() {
|
|
196
|
+
return path2.join(this.root, "tasks");
|
|
197
|
+
}
|
|
198
|
+
get agentsDir() {
|
|
199
|
+
return path2.join(this.root, "agents");
|
|
200
|
+
}
|
|
201
|
+
get runsDir() {
|
|
202
|
+
return path2.join(this.root, "runs");
|
|
203
|
+
}
|
|
204
|
+
get templatesDir() {
|
|
205
|
+
return path2.join(this.root, "templates");
|
|
206
|
+
}
|
|
207
|
+
get logsDir() {
|
|
208
|
+
return path2.join(this.root, "logs");
|
|
209
|
+
}
|
|
210
|
+
get contextDir() {
|
|
211
|
+
return path2.join(this.root, "context");
|
|
212
|
+
}
|
|
213
|
+
contextPath(key) {
|
|
214
|
+
return path2.join(this.contextDir, `${sanitizeId(key)}.json`);
|
|
215
|
+
}
|
|
216
|
+
get messagesDir() {
|
|
217
|
+
return path2.join(this.root, "messages");
|
|
218
|
+
}
|
|
219
|
+
messagePath(id) {
|
|
220
|
+
return path2.join(this.messagesDir, `${sanitizeId(id)}.json`);
|
|
221
|
+
}
|
|
222
|
+
get goalsDir() {
|
|
223
|
+
return path2.join(this.root, "goals");
|
|
224
|
+
}
|
|
225
|
+
goalPath(id) {
|
|
226
|
+
return path2.join(this.goalsDir, `${sanitizeId(id)}.yml`);
|
|
227
|
+
}
|
|
228
|
+
get teamsDir() {
|
|
229
|
+
return path2.join(this.root, "teams");
|
|
230
|
+
}
|
|
231
|
+
get attachmentsDir() {
|
|
232
|
+
return path2.join(this.root, "attachments");
|
|
233
|
+
}
|
|
234
|
+
taskAttachmentsDir(taskId) {
|
|
235
|
+
return path2.join(this.attachmentsDir, sanitizeId(taskId));
|
|
236
|
+
}
|
|
237
|
+
teamPath(id) {
|
|
238
|
+
return path2.join(this.teamsDir, `${sanitizeId(id)}.yml`);
|
|
239
|
+
}
|
|
240
|
+
get gitignorePath() {
|
|
241
|
+
return path2.join(this.root, ".gitignore");
|
|
242
|
+
}
|
|
243
|
+
get workspaceExcludePath() {
|
|
244
|
+
return path2.join(this.root, "workspace-exclude");
|
|
245
|
+
}
|
|
246
|
+
taskPath(id) {
|
|
247
|
+
return path2.join(this.tasksDir, `${sanitizeId(id)}.yml`);
|
|
248
|
+
}
|
|
249
|
+
agentPath(id) {
|
|
250
|
+
return path2.join(this.agentsDir, `${sanitizeId(id)}.yml`);
|
|
251
|
+
}
|
|
252
|
+
runPath(id) {
|
|
253
|
+
return path2.join(this.runsDir, `${sanitizeId(id)}.json`);
|
|
254
|
+
}
|
|
255
|
+
runEventsPath(id) {
|
|
256
|
+
return path2.join(this.runsDir, `${sanitizeId(id)}.jsonl`);
|
|
257
|
+
}
|
|
258
|
+
defaultTemplatePath() {
|
|
259
|
+
return path2.join(this.templatesDir, "default.md");
|
|
260
|
+
}
|
|
261
|
+
async isInitialized() {
|
|
262
|
+
return pathExists(this.root);
|
|
263
|
+
}
|
|
264
|
+
async requireInit() {
|
|
265
|
+
if (!await this.isInitialized()) {
|
|
266
|
+
throw new NotInitializedError();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
function sanitizeId(id) {
|
|
271
|
+
if (!ID_PATTERN.test(id)) {
|
|
272
|
+
throw new Error(`Invalid identifier: "${id}"`);
|
|
273
|
+
}
|
|
274
|
+
return id;
|
|
275
|
+
}
|
|
276
|
+
function validateWorkspacePath(workspacePath, projectRoot) {
|
|
277
|
+
const resolved = path2.resolve(workspacePath);
|
|
278
|
+
const root = path2.resolve(projectRoot);
|
|
279
|
+
if (!resolved.startsWith(root + path2.sep) && resolved !== root) {
|
|
280
|
+
throw new Error(`Workspace path "${workspacePath}" is outside project root`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function findProjectRoot(startDir = process.cwd()) {
|
|
284
|
+
let dir = path2.resolve(startDir);
|
|
285
|
+
const root = path2.parse(dir).root;
|
|
286
|
+
while (dir !== root) {
|
|
287
|
+
try {
|
|
288
|
+
accessSync(path2.join(dir, ".orchestry"));
|
|
289
|
+
return dir;
|
|
290
|
+
} catch {
|
|
291
|
+
}
|
|
292
|
+
dir = path2.dirname(dir);
|
|
293
|
+
}
|
|
294
|
+
return startDir;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export { Paths, appendJsonl, atomicWrite, ensureDir, findProjectRoot, listFiles, pathExists, readJson, readJsonl, readJsonlTail, readYaml, sanitizeId, validateWorkspacePath, writeJson, writeYaml };
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// src/domain/errors.ts
|
|
2
|
+
var OrchestryError = class extends Error {
|
|
3
|
+
constructor(message, exitCode, hint) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.exitCode = exitCode;
|
|
6
|
+
this.hint = hint;
|
|
7
|
+
this.name = "OrchestryError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var NotInitializedError = class extends OrchestryError {
|
|
11
|
+
constructor() {
|
|
12
|
+
super("Not initialized", 3, "Run: orch init");
|
|
13
|
+
this.name = "NotInitializedError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var InvalidArgumentsError = class extends OrchestryError {
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message, 2);
|
|
19
|
+
this.name = "InvalidArgumentsError";
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var LockConflictError = class extends OrchestryError {
|
|
23
|
+
constructor(pid) {
|
|
24
|
+
super(`Orchestrator already running (PID: ${pid})`, 4, "Use: orch status");
|
|
25
|
+
this.name = "LockConflictError";
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var NoAgentsError = class extends OrchestryError {
|
|
29
|
+
constructor() {
|
|
30
|
+
super("No agents configured", 1, "Run: orch agent add <name> --adapter claude");
|
|
31
|
+
this.name = "NoAgentsError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var TaskNotFoundError = class extends OrchestryError {
|
|
35
|
+
constructor(taskId) {
|
|
36
|
+
super(`Task not found: ${taskId}`, 1);
|
|
37
|
+
this.name = "TaskNotFoundError";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var AgentNotFoundError = class extends OrchestryError {
|
|
41
|
+
constructor(agentId) {
|
|
42
|
+
super(`Agent not found: ${agentId}`, 1);
|
|
43
|
+
this.name = "AgentNotFoundError";
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var TaskAlreadyRunningError = class extends OrchestryError {
|
|
47
|
+
constructor(taskId, runId, agentName) {
|
|
48
|
+
super(
|
|
49
|
+
`Task ${taskId} is already running (run: ${runId}, agent: ${agentName})`,
|
|
50
|
+
1,
|
|
51
|
+
`Use: orch logs --task ${taskId} --follow`
|
|
52
|
+
);
|
|
53
|
+
this.name = "TaskAlreadyRunningError";
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var InvalidTransitionError = class extends OrchestryError {
|
|
57
|
+
constructor(taskId, from, to) {
|
|
58
|
+
super(`Invalid transition for ${taskId}: ${from} \u2192 ${to}`, 1);
|
|
59
|
+
this.name = "InvalidTransitionError";
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var GoalNotFoundError = class extends OrchestryError {
|
|
63
|
+
constructor(goalId) {
|
|
64
|
+
super(`Goal not found: ${goalId}`, 1);
|
|
65
|
+
this.name = "GoalNotFoundError";
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var TeamNotFoundError = class extends OrchestryError {
|
|
69
|
+
constructor(teamId) {
|
|
70
|
+
super(`Team not found: ${teamId}`, 1);
|
|
71
|
+
this.name = "TeamNotFoundError";
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var WorkspaceError = class extends OrchestryError {
|
|
75
|
+
constructor(message, hint) {
|
|
76
|
+
super(message, 6, hint);
|
|
77
|
+
this.name = "WorkspaceError";
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var AdapterErrorKind = /* @__PURE__ */ ((AdapterErrorKind2) => {
|
|
81
|
+
AdapterErrorKind2["ADAPTER_NOT_FOUND"] = "adapter_not_found";
|
|
82
|
+
AdapterErrorKind2["AUTH_FAILED"] = "auth_failed";
|
|
83
|
+
AdapterErrorKind2["TIMEOUT"] = "timeout";
|
|
84
|
+
AdapterErrorKind2["RATE_LIMIT"] = "rate_limit";
|
|
85
|
+
AdapterErrorKind2["PROCESS_CRASH"] = "process_crash";
|
|
86
|
+
AdapterErrorKind2["SPAWN_FAILED"] = "spawn_failed";
|
|
87
|
+
AdapterErrorKind2["UNKNOWN"] = "unknown";
|
|
88
|
+
return AdapterErrorKind2;
|
|
89
|
+
})(AdapterErrorKind || {});
|
|
90
|
+
var ERROR_HINTS = {
|
|
91
|
+
["adapter_not_found" /* ADAPTER_NOT_FOUND */]: {
|
|
92
|
+
message: "CLI \u043D\u0435 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D.",
|
|
93
|
+
fix: "\u0423\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435: npm i -g @anthropic-ai/claude-code",
|
|
94
|
+
doctorHint: true
|
|
95
|
+
},
|
|
96
|
+
["auth_failed" /* AUTH_FAILED */]: {
|
|
97
|
+
message: "API \u043A\u043B\u044E\u0447 \u043D\u0435\u0432\u0430\u043B\u0438\u0434\u0435\u043D.",
|
|
98
|
+
fix: "\u041F\u0440\u043E\u0432\u0435\u0440\u044C\u0442\u0435: claude auth status"
|
|
99
|
+
},
|
|
100
|
+
["timeout" /* TIMEOUT */]: {
|
|
101
|
+
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.",
|
|
102
|
+
fix: "\u0423\u0432\u0435\u043B\u0438\u0447\u044C\u0442\u0435 \u0447\u0435\u0440\u0435\u0437: orch config set agent_timeout <ms>"
|
|
103
|
+
},
|
|
104
|
+
["rate_limit" /* RATE_LIMIT */]: {
|
|
105
|
+
message: "\u0414\u043E\u0441\u0442\u0438\u0433\u043D\u0443\u0442 \u043B\u0438\u043C\u0438\u0442 API.",
|
|
106
|
+
fix: "\u041F\u043E\u0434\u043E\u0436\u0434\u0438\u0442\u0435 \u0438 \u043F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u0435: orch task retry <id>"
|
|
107
|
+
},
|
|
108
|
+
["process_crash" /* PROCESS_CRASH */]: {
|
|
109
|
+
message: "\u041F\u0440\u043E\u0446\u0435\u0441\u0441 \u0430\u0433\u0435\u043D\u0442\u0430 \u0443\u043F\u0430\u043B.",
|
|
110
|
+
fix: "\u041F\u043E\u043F\u0440\u043E\u0431\u0443\u0439\u0442\u0435: orch task retry <id>"
|
|
111
|
+
},
|
|
112
|
+
["spawn_failed" /* SPAWN_FAILED */]: {
|
|
113
|
+
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.",
|
|
114
|
+
fix: "\u041F\u0440\u043E\u0432\u0435\u0440\u044C\u0442\u0435 PATH \u0438 \u043F\u0440\u0430\u0432\u0430 \u0434\u043E\u0441\u0442\u0443\u043F\u0430"
|
|
115
|
+
},
|
|
116
|
+
["unknown" /* UNKNOWN */]: {
|
|
117
|
+
message: "\u041D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430.",
|
|
118
|
+
fix: "\u0417\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u0435: orch doctor",
|
|
119
|
+
doctorHint: true
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
function classifyAdapterError(error, exitCode) {
|
|
123
|
+
const lower = error.toLowerCase();
|
|
124
|
+
if (lower.includes("enoent") || lower.includes("spawn failed")) {
|
|
125
|
+
return "spawn_failed" /* SPAWN_FAILED */;
|
|
126
|
+
}
|
|
127
|
+
if (lower.includes("not found") || lower.includes("command not found") || lower.includes("no such file")) {
|
|
128
|
+
return "adapter_not_found" /* ADAPTER_NOT_FOUND */;
|
|
129
|
+
}
|
|
130
|
+
if (lower.includes("auth") || lower.includes("unauthorized") || lower.includes("401") || lower.includes("invalid api key") || lower.includes("authentication")) {
|
|
131
|
+
return "auth_failed" /* AUTH_FAILED */;
|
|
132
|
+
}
|
|
133
|
+
if (lower.includes("timeout") || lower.includes("timed out") || lower.includes("etimedout")) {
|
|
134
|
+
return "timeout" /* TIMEOUT */;
|
|
135
|
+
}
|
|
136
|
+
if (lower.includes("rate limit") || lower.includes("429") || lower.includes("too many requests")) {
|
|
137
|
+
return "rate_limit" /* RATE_LIMIT */;
|
|
138
|
+
}
|
|
139
|
+
if (exitCode !== void 0 && exitCode !== 0) {
|
|
140
|
+
return "process_crash" /* PROCESS_CRASH */;
|
|
141
|
+
}
|
|
142
|
+
return "unknown" /* UNKNOWN */;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export { AdapterErrorKind, AgentNotFoundError, ERROR_HINTS, GoalNotFoundError, InvalidArgumentsError, InvalidTransitionError, LockConflictError, NoAgentsError, NotInitializedError, OrchestryError, TaskAlreadyRunningError, TaskNotFoundError, TeamNotFoundError, WorkspaceError, classifyAdapterError };
|
|
146
|
+
//# sourceMappingURL=chunk-NLQAJ7TW.js.map
|
|
147
|
+
//# sourceMappingURL=chunk-NLQAJ7TW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/domain/errors.ts"],"names":["AdapterErrorKind"],"mappings":";AAeO,IAAM,cAAA,GAAN,cAA6B,KAAA,CAAM;AAAA,EACxC,WAAA,CACE,OAAA,EACgB,QAAA,EACA,IAAA,EAChB;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAHG,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AACA,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,gBAAA;AAAA,EACd;AACF;AAEO,IAAM,mBAAA,GAAN,cAAkC,cAAA,CAAe;AAAA,EACtD,WAAA,GAAc;AACZ,IAAA,KAAA,CAAM,iBAAA,EAAmB,GAAG,gBAAgB,CAAA;AAC5C,IAAA,IAAA,CAAK,IAAA,GAAO,qBAAA;AAAA,EACd;AACF;AAEO,IAAM,qBAAA,GAAN,cAAoC,cAAA,CAAe;AAAA,EACxD,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,SAAS,CAAC,CAAA;AAChB,IAAA,IAAA,CAAK,IAAA,GAAO,uBAAA;AAAA,EACd;AACF;AAEO,IAA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AAM,QAAA,CAAS,cAAc,CAAA,IAAK,KAAA,CAAM,SAAS,KAAK,CAAA,IAAK,MAAM,QAAA,CAAS,iBAAiB,KAAK,KAAA,CAAM,QAAA,CAAS,gBAAgB,CAAA,EAAG;AAC9J,IAAA,OAAO,aAAA;AAAA,EACT;AACA,EAAA,IAAI,KAAA,CAAM,QAAA,CAAS,SAAS,CAAA,IAAK,KAAA,CAAM,QAAA,CAAS,WAAW,CAAA,IAAK,KAAA,CAAM,QAAA,CAAS,WAAW,CAAA,EAAG;AAC3F,IAAA,OAAO,SAAA;AAAA,EACT;AACA,EAAA,IAAI,KAAA,CAAM,QAAA,CAAS,YAAY,CAAA,IAAK,KAAA,CAAM,QAAA,CAAS,KAAK,CAAA,IAAK,KAAA,CAAM,QAAA,CAAS,mBAAmB,CAAA,EAAG;AAChG,IAAA,OAAO,YAAA;AAAA,EACT;AACA,EAAA,IAAI,QAAA,KAAa,MAAA,IAAa,QAAA,KAAa,CAAA,EAAG;AAC5C,IAAA,OAAO,eAAA;AAAA,EACT;AAEA,EAAA,OAAO,SAAA;AACT","file":"chunk-NLQAJ7TW.js","sourcesContent":["/**\n * Typed error hierarchy for the orchestrator.\n *\n * Every error carries an exit code (matching CLI_UI_DESIGN.md §11)\n * and an optional hint for the user.\n *\n * Exit codes:\n * 0 - Success\n * 1 - General error\n * 2 - Invalid arguments\n * 3 - Not initialized (.orchestry/ not found)\n * 4 - Lock conflict (orchestrator already running)\n * 5 - Agent error (adapter test failed)\n */\n\nexport class OrchestryError extends Error {\n constructor(\n message: string,\n public readonly exitCode: number,\n public readonly hint?: string,\n ) {\n super(message);\n this.name = 'OrchestryError';\n }\n}\n\nexport class NotInitializedError extends OrchestryError {\n constructor() {\n super('Not initialized', 3, 'Run: orch init');\n this.name = 'NotInitializedError';\n }\n}\n\nexport class InvalidArgumentsError extends OrchestryError {\n constructor(message: string) {\n super(message, 2);\n this.name = 'InvalidArgumentsError';\n }\n}\n\nexport class LockConflictError extends OrchestryError {\n constructor(pid: number) {\n super(`Orchestrator already running (PID: ${pid})`, 4, 'Use: orch status');\n this.name = 'LockConflictError';\n }\n}\n\nexport class AgentAdapterError extends OrchestryError {\n constructor(adapter: string, detail: string) {\n super(`Agent adapter \"${adapter}\" not available`, 5, detail);\n this.name = 'AgentAdapterError';\n }\n}\n\nexport class NoAgentsError extends OrchestryError {\n constructor() {\n super('No agents configured', 1, 'Run: orch agent add <name> --adapter claude');\n this.name = 'NoAgentsError';\n }\n}\n\nexport class TaskNotFoundError extends OrchestryError {\n constructor(taskId: string) {\n super(`Task not found: ${taskId}`, 1);\n this.name = 'TaskNotFoundError';\n }\n}\n\nexport class AgentNotFoundError extends OrchestryError {\n constructor(agentId: string) {\n super(`Agent not found: ${agentId}`, 1);\n this.name = 'AgentNotFoundError';\n }\n}\n\nexport class TaskAlreadyRunningError extends OrchestryError {\n constructor(taskId: string, runId: string, agentName: string) {\n super(\n `Task ${taskId} is already running (run: ${runId}, agent: ${agentName})`,\n 1,\n `Use: orch logs --task ${taskId} --follow`,\n );\n this.name = 'TaskAlreadyRunningError';\n }\n}\n\nexport class InvalidTransitionError extends OrchestryError {\n constructor(taskId: string, from: string, to: string) {\n super(`Invalid transition for ${taskId}: ${from} → ${to}`, 1);\n this.name = 'InvalidTransitionError';\n }\n}\n\nexport class GoalNotFoundError extends OrchestryError {\n constructor(goalId: string) {\n super(`Goal not found: ${goalId}`, 1);\n this.name = 'GoalNotFoundError';\n }\n}\n\nexport class TeamNotFoundError extends OrchestryError {\n constructor(teamId: string) {\n super(`Team not found: ${teamId}`, 1);\n this.name = 'TeamNotFoundError';\n }\n}\n\nexport class MessageNotFoundError extends OrchestryError {\n constructor(messageId: string) {\n super(`Message not found: ${messageId}`, 1);\n this.name = 'MessageNotFoundError';\n }\n}\n\nexport class WorkspaceError extends OrchestryError {\n constructor(message: string, hint?: string) {\n super(message, 6, hint);\n this.name = 'WorkspaceError';\n }\n}\n\n// ── Adapter Error Classification ──────────────────────────────────\n\nexport enum AdapterErrorKind {\n ADAPTER_NOT_FOUND = 'adapter_not_found',\n AUTH_FAILED = 'auth_failed',\n TIMEOUT = 'timeout',\n RATE_LIMIT = 'rate_limit',\n PROCESS_CRASH = 'process_crash',\n SPAWN_FAILED = 'spawn_failed',\n UNKNOWN = 'unknown',\n}\n\nexport interface AdapterErrorHint {\n message: string;\n fix: string;\n doctorHint?: boolean;\n}\n\nexport const ERROR_HINTS: Record<AdapterErrorKind, AdapterErrorHint> = {\n [AdapterErrorKind.ADAPTER_NOT_FOUND]: {\n message: 'CLI не установлен.',\n fix: 'Установите: npm i -g @anthropic-ai/claude-code',\n doctorHint: true,\n },\n [AdapterErrorKind.AUTH_FAILED]: {\n message: 'API ключ невалиден.',\n fix: 'Проверьте: claude auth status',\n },\n [AdapterErrorKind.TIMEOUT]: {\n message: 'Агент превысил лимит времени.',\n fix: 'Увеличьте через: orch config set agent_timeout <ms>',\n },\n [AdapterErrorKind.RATE_LIMIT]: {\n message: 'Достигнут лимит API.',\n fix: 'Подождите и повторите: orch task retry <id>',\n },\n [AdapterErrorKind.PROCESS_CRASH]: {\n message: 'Процесс агента упал.',\n fix: 'Попробуйте: orch task retry <id>',\n },\n [AdapterErrorKind.SPAWN_FAILED]: {\n message: 'Не удалось запустить процесс.',\n fix: 'Проверьте PATH и права доступа',\n },\n [AdapterErrorKind.UNKNOWN]: {\n message: 'Неизвестная ошибка.',\n fix: 'Запустите: orch doctor',\n doctorHint: true,\n },\n};\n\nexport function classifyAdapterError(error: string, exitCode?: number): AdapterErrorKind {\n const lower = error.toLowerCase();\n\n if (lower.includes('enoent') || lower.includes('spawn failed')) {\n return AdapterErrorKind.SPAWN_FAILED;\n }\n if (lower.includes('not found') || lower.includes('command not found') || lower.includes('no such file')) {\n return AdapterErrorKind.ADAPTER_NOT_FOUND;\n }\n if (lower.includes('auth') || lower.includes('unauthorized') || lower.includes('401') || lower.includes('invalid api key') || lower.includes('authentication')) {\n return AdapterErrorKind.AUTH_FAILED;\n }\n if (lower.includes('timeout') || lower.includes('timed out') || lower.includes('etimedout')) {\n return AdapterErrorKind.TIMEOUT;\n }\n if (lower.includes('rate limit') || lower.includes('429') || lower.includes('too many requests')) {\n return AdapterErrorKind.RATE_LIMIT;\n }\n if (exitCode !== undefined && exitCode !== 0) {\n return AdapterErrorKind.PROCESS_CRASH;\n }\n\n return AdapterErrorKind.UNKNOWN;\n}\n"]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdtemp, writeFile, readFile, unlink, rm } from 'fs/promises';
|
|
3
|
+
import { tmpdir } from 'os';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { spawn } from 'child_process';
|
|
6
|
+
|
|
7
|
+
async function openInEditor(initialContent, opts = {}) {
|
|
8
|
+
const { extension = ".yml", prefix = "orch-" } = opts;
|
|
9
|
+
const editor = process.env["EDITOR"] || process.env["VISUAL"] || "vi";
|
|
10
|
+
const dir = await mkdtemp(join(tmpdir(), prefix));
|
|
11
|
+
const filePath = join(dir, `edit${extension}`);
|
|
12
|
+
await writeFile(filePath, initialContent, "utf8");
|
|
13
|
+
try {
|
|
14
|
+
const parts = editor.split(/\s+/);
|
|
15
|
+
const child = spawn(parts[0], [...parts.slice(1), filePath], { stdio: "inherit" });
|
|
16
|
+
await new Promise((resolve, reject) => {
|
|
17
|
+
child.on("close", (code) => {
|
|
18
|
+
if (code === 0) resolve();
|
|
19
|
+
else reject(new Error(`Editor exited with code ${code}`));
|
|
20
|
+
});
|
|
21
|
+
child.on("error", reject);
|
|
22
|
+
});
|
|
23
|
+
return await readFile(filePath, "utf8");
|
|
24
|
+
} finally {
|
|
25
|
+
await unlink(filePath).catch(() => {
|
|
26
|
+
});
|
|
27
|
+
await rm(dir, { recursive: true }).catch(() => {
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function toEditorContent(fields) {
|
|
32
|
+
const lines = [
|
|
33
|
+
"---",
|
|
34
|
+
`title: ${fields.title}`,
|
|
35
|
+
`priority: ${fields.priority}`,
|
|
36
|
+
"---",
|
|
37
|
+
"",
|
|
38
|
+
fields.description ?? ""
|
|
39
|
+
];
|
|
40
|
+
return lines.join("\n");
|
|
41
|
+
}
|
|
42
|
+
function fromEditorContent(content) {
|
|
43
|
+
const match = content.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
44
|
+
if (!match) {
|
|
45
|
+
return { description: content.trim() || void 0 };
|
|
46
|
+
}
|
|
47
|
+
const frontmatter = match[1] ?? "";
|
|
48
|
+
const body = match[2] ?? "";
|
|
49
|
+
const result = {};
|
|
50
|
+
for (const line of frontmatter.split("\n")) {
|
|
51
|
+
const kv = line.match(/^([\w]+):\s*(.*)$/);
|
|
52
|
+
if (!kv) continue;
|
|
53
|
+
const key = kv[1];
|
|
54
|
+
const value = kv[2] ?? "";
|
|
55
|
+
if (key === "title" && value.trim()) {
|
|
56
|
+
result.title = value.trim();
|
|
57
|
+
} else if (key === "priority") {
|
|
58
|
+
const n = parseInt(value.trim(), 10);
|
|
59
|
+
if (n >= 1 && n <= 4) result.priority = n;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const desc = body.trim();
|
|
63
|
+
if (desc) result.description = desc;
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
function agentToEditorContent(fields) {
|
|
67
|
+
const lines = [
|
|
68
|
+
"# Edit agent configuration.",
|
|
69
|
+
"# Lines starting with # are ignored.",
|
|
70
|
+
"# Role description goes below the second --- separator.",
|
|
71
|
+
"---",
|
|
72
|
+
`name: ${fields.name}`,
|
|
73
|
+
`model: ${fields.model ?? ""}`,
|
|
74
|
+
"---",
|
|
75
|
+
"",
|
|
76
|
+
fields.role ?? ""
|
|
77
|
+
];
|
|
78
|
+
return lines.join("\n");
|
|
79
|
+
}
|
|
80
|
+
function agentFromEditorContent(content) {
|
|
81
|
+
const lines = content.split("\n");
|
|
82
|
+
const firstFence = lines.findIndex((l) => l.trimEnd() === "---");
|
|
83
|
+
const stripped = (firstFence >= 0 ? [...lines.slice(0, firstFence).filter((l) => !l.startsWith("#")), ...lines.slice(firstFence)] : lines.filter((l) => !l.startsWith("#"))).join("\n");
|
|
84
|
+
const match = stripped.trimStart().match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
85
|
+
if (!match) {
|
|
86
|
+
const role = stripped.trim();
|
|
87
|
+
return { role: role || void 0 };
|
|
88
|
+
}
|
|
89
|
+
const frontmatter = match[1] ?? "";
|
|
90
|
+
const body = match[2] ?? "";
|
|
91
|
+
const result = {};
|
|
92
|
+
for (const line of frontmatter.split("\n")) {
|
|
93
|
+
const kv = line.match(/^([\w]+):\s*(.*)$/);
|
|
94
|
+
if (!kv) continue;
|
|
95
|
+
const key = kv[1];
|
|
96
|
+
const value = kv[2] ?? "";
|
|
97
|
+
if (key === "name") {
|
|
98
|
+
result.name = value.trim();
|
|
99
|
+
} else if (key === "model") {
|
|
100
|
+
result.model = value.trim();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
result.role = body.trim();
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { agentFromEditorContent, agentToEditorContent, fromEditorContent, openInEditor, toEditorContent };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createTokenUsage } from './chunk-XDVMX2FO.js';
|
|
2
|
+
import { classifyAdapterError } from './chunk-NLQAJ7TW.js';
|
|
2
3
|
import { readLines } from './chunk-O2MSGW3V.js';
|
|
3
4
|
|
|
4
5
|
// src/infrastructure/adapters/utils.ts
|
|
@@ -42,15 +43,21 @@ function createStreamingEvents(proc, parseEvent, adapterName, signal) {
|
|
|
42
43
|
}
|
|
43
44
|
await exitPromise;
|
|
44
45
|
if (exitError && !signal?.aborted && !gotDoneEvent) {
|
|
45
|
-
|
|
46
|
+
const spawnErr = exitError;
|
|
47
|
+
const classified = classifyAdapterError(spawnErr.message, exitCode ?? void 0);
|
|
48
|
+
const err = Object.assign(new Error(spawnErr.message), { errorKind: classified });
|
|
49
|
+
throw err;
|
|
46
50
|
}
|
|
47
51
|
if (exitCode !== 0 && exitCode !== null && !signal?.aborted && !gotDoneEvent) {
|
|
48
|
-
|
|
52
|
+
const msg = `${adapterName} process exited with code ${exitCode}`;
|
|
53
|
+
const classified = classifyAdapterError(msg, exitCode);
|
|
54
|
+
const err = Object.assign(new Error(msg), { errorKind: classified });
|
|
55
|
+
throw err;
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
58
|
return generate();
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
export { createStreamingEvents, extractTokens };
|
|
55
|
-
//# sourceMappingURL=chunk-
|
|
56
|
-
//# sourceMappingURL=chunk-
|
|
62
|
+
//# sourceMappingURL=chunk-S3QYSBW4.js.map
|
|
63
|
+
//# sourceMappingURL=chunk-S3QYSBW4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/infrastructure/adapters/utils.ts"],"names":[],"mappings":";;;;;AAqBO,SAAS,aAAA,CACd,QACA,IAAA,EACuB;AACvB,EAAA,IAAI,QAAQ,MAAA,CAAO,KAAA;AAEnB,EAAA,IAAI,CAAC,KAAA,IAAS,IAAA,EAAM,aAAA,EAAe;AACjC,IAAA,MAAM,QAAQ,MAAA,CAAO,KAAA;AACrB,IAAA,KAAA,GAAQ,KAAA,EAAO,KAAA;AAAA,EACjB;AAEA,EAAA,IAAI,KAAA,IAAS,OAAO,KAAA,CAAM,YAAA,KAAiB,QAAA,EAAU;AACnD,IAAA,MAAM,QAAQ,KAAA,CAAM,YAAA;AACpB,IAAA,MAAM,SAAS,OAAO,KAAA,CAAM,aAAA,KAAkB,QAAA,GAAW,MAAM,aAAA,GAAgB,CAAA;AAC/E,IAAA,OAAO,gBAAA,CAAiB,OAAO,MAAM,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,MAAA;AACT;AAYO,SAAS,qBAAA,CACd,IAAA,EACA,UAAA,EACA,WAAA,E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,CAAA,EAAG,EAAE,SAAA,EAAW,UAAA,EAAY,CAAA;AAChF,MAAA,MAAM,GAAA;AAAA,IACR;AACA,IAAA,IAAI,QAAA,KAAa,KAAK,QAAA,KAAa,IAAA,IAAQ,CAAC,MAAA,EAAQ,OAAA,IAAW,CAAC,YAAA,EAAc;AAC5E,MAAA,MAAM,GAAA,GAAM,CAAA,EAAG,WAAW,CAAA,0BAAA,EAA6B,QAAQ,CAAA,CAAA;AAC/D,MAAA,MAAM,UAAA,GAAa,oBAAA,CAAqB,GAAA,EAAK,QAAQ,CAAA;AACrD,MAAA,MAAM,GAAA,GAAM,MAAA,CAAO,MAAA,CAAO,IAAI,KAAA,CAAM,GAAG,CAAA,EAAG,EAAE,SAAA,EAAW,UAAA,EAAY,CAAA;AACnE,MAAA,MAAM,GAAA;AAAA,IACR;AAAA,EACF;AAEA,EAAA,OAAO,QAAA,EAAS;AAClB","file":"chunk-S3QYSBW4.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/**\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"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// src/domain/transitions.ts
|
|
3
|
+
var VALID_TRANSITIONS = {
|
|
4
|
+
todo: ["in_progress", "cancelled"],
|
|
5
|
+
in_progress: ["review", "retrying", "failed", "cancelled"],
|
|
6
|
+
retrying: ["in_progress", "failed", "cancelled"],
|
|
7
|
+
review: ["done", "todo", "cancelled"],
|
|
8
|
+
done: [],
|
|
9
|
+
failed: ["todo", "retrying"],
|
|
10
|
+
cancelled: ["todo"]
|
|
11
|
+
};
|
|
12
|
+
var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["done", "failed", "cancelled"]);
|
|
13
|
+
function canTransition(from, to) {
|
|
14
|
+
return VALID_TRANSITIONS[from].includes(to);
|
|
15
|
+
}
|
|
16
|
+
function isTerminal(status) {
|
|
17
|
+
return TERMINAL_STATUSES.has(status);
|
|
18
|
+
}
|
|
19
|
+
function isDispatchable(status) {
|
|
20
|
+
return status === "todo" || status === "retrying";
|
|
21
|
+
}
|
|
22
|
+
function isBlocked(task, allTasks) {
|
|
23
|
+
if (task.depends_on.length === 0) return false;
|
|
24
|
+
if (allTasks instanceof Map) {
|
|
25
|
+
return task.depends_on.some((depId) => {
|
|
26
|
+
const dep = allTasks.get(depId);
|
|
27
|
+
return !dep || dep.status !== "done";
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return task.depends_on.some((depId) => {
|
|
31
|
+
const dep = allTasks.find((t) => t.id === depId);
|
|
32
|
+
return !dep || dep.status !== "done";
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function resolveFailureStatus(task) {
|
|
36
|
+
if (task.attempts < task.max_attempts) {
|
|
37
|
+
return "retrying";
|
|
38
|
+
}
|
|
39
|
+
return "failed";
|
|
40
|
+
}
|
|
41
|
+
function resolveCompletionStatus(task, success, _autoApprove) {
|
|
42
|
+
if (success) {
|
|
43
|
+
return "review";
|
|
44
|
+
}
|
|
45
|
+
return resolveFailureStatus(task);
|
|
46
|
+
}
|
|
47
|
+
function calculateRetryDelay(attempt, baseDelayMs, maxDelayMs) {
|
|
48
|
+
const delay = baseDelayMs * Math.pow(2, attempt);
|
|
49
|
+
return Math.min(delay, maxDelayMs);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { calculateRetryDelay, canTransition, isBlocked, isDispatchable, isTerminal, resolveCompletionStatus, resolveFailureStatus };
|