orchestrar 0.2.0 → 0.3.1
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/orchestrator.js +70 -8
- package/package.json +1 -1
package/orchestrator.js
CHANGED
|
@@ -47,7 +47,7 @@ async function runWorkInstance(createOpencode, docs, root) {
|
|
|
47
47
|
"session.create"
|
|
48
48
|
);
|
|
49
49
|
|
|
50
|
-
const sessionID = session.
|
|
50
|
+
const sessionID = extractSessionID(session, "session.create (work instance)");
|
|
51
51
|
const promptPaths = buildPromptPaths(docs, root);
|
|
52
52
|
|
|
53
53
|
await sendPrompt(
|
|
@@ -85,7 +85,7 @@ async function runCommitInstance(createOpencode, root) {
|
|
|
85
85
|
"session.create"
|
|
86
86
|
);
|
|
87
87
|
|
|
88
|
-
const sessionID = session.
|
|
88
|
+
const sessionID = extractSessionID(session, "session.create (commit instance)");
|
|
89
89
|
await sendPrompt(
|
|
90
90
|
client,
|
|
91
91
|
sessionID,
|
|
@@ -156,7 +156,7 @@ async function runReviewCommand(createOpencode, root) {
|
|
|
156
156
|
"session.create"
|
|
157
157
|
);
|
|
158
158
|
|
|
159
|
-
const sessionID = session.
|
|
159
|
+
const sessionID = extractSessionID(session, "session.create (review instance)");
|
|
160
160
|
const commandResult = await unwrap(
|
|
161
161
|
client.session.command({
|
|
162
162
|
path: { id: sessionID },
|
|
@@ -239,7 +239,11 @@ async function waitForSessionIdle(client, sessionID, root, timeoutOverrideMs) {
|
|
|
239
239
|
);
|
|
240
240
|
const status = statusMap?.[sessionID];
|
|
241
241
|
if (!status) {
|
|
242
|
-
|
|
242
|
+
const knownSessions = statusMap ? Object.keys(statusMap) : [];
|
|
243
|
+
const knownList = knownSessions.length ? knownSessions.join(", ") : "none";
|
|
244
|
+
throw new Error(
|
|
245
|
+
`Session status missing for ${sessionID}. Known sessions: ${knownList}.`
|
|
246
|
+
);
|
|
243
247
|
}
|
|
244
248
|
if (status.type === "idle") {
|
|
245
249
|
return;
|
|
@@ -443,15 +447,73 @@ async function fileExists(filePath) {
|
|
|
443
447
|
}
|
|
444
448
|
|
|
445
449
|
function unwrap(result, label) {
|
|
446
|
-
if (result
|
|
447
|
-
|
|
448
|
-
|
|
450
|
+
if (!result || typeof result !== "object") {
|
|
451
|
+
return result;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const hasWrapperFields =
|
|
455
|
+
"request" in result ||
|
|
456
|
+
"response" in result ||
|
|
457
|
+
"error" in result ||
|
|
458
|
+
Object.prototype.hasOwnProperty.call(result, "data");
|
|
459
|
+
|
|
460
|
+
if (result.error) {
|
|
461
|
+
throw new Error(`${label} failed: ${formatError(result.error)}`);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (hasWrapperFields) {
|
|
465
|
+
if ("data" in result || result.data !== undefined) {
|
|
466
|
+
return result.data;
|
|
449
467
|
}
|
|
450
|
-
return result.data;
|
|
451
468
|
}
|
|
469
|
+
|
|
452
470
|
return result;
|
|
453
471
|
}
|
|
454
472
|
|
|
473
|
+
function extractSessionID(session, context) {
|
|
474
|
+
if (!session || typeof session !== "object") {
|
|
475
|
+
throw new Error(`${context} did not return a session object.`);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const candidates = [
|
|
479
|
+
session.id,
|
|
480
|
+
session.sessionID,
|
|
481
|
+
session.data?.id,
|
|
482
|
+
session.data?.sessionID,
|
|
483
|
+
session.info?.id,
|
|
484
|
+
session.info?.sessionID,
|
|
485
|
+
session.data?.info?.id,
|
|
486
|
+
session.data?.info?.sessionID,
|
|
487
|
+
session.properties?.id,
|
|
488
|
+
session.properties?.sessionID,
|
|
489
|
+
session.properties?.info?.id,
|
|
490
|
+
session.properties?.info?.sessionID,
|
|
491
|
+
session.slug,
|
|
492
|
+
];
|
|
493
|
+
|
|
494
|
+
for (const candidate of candidates) {
|
|
495
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
496
|
+
return candidate;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
throw new Error(
|
|
501
|
+
`${context} returned a session without an id. Response: ${safeStringify(session)}`
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function safeStringify(value, maxLength = 1000) {
|
|
506
|
+
try {
|
|
507
|
+
const json = JSON.stringify(value);
|
|
508
|
+
if (typeof json === "string" && json.length > 0) {
|
|
509
|
+
return json.length > maxLength ? `${json.slice(0, maxLength)}...` : json;
|
|
510
|
+
}
|
|
511
|
+
} catch (error) {
|
|
512
|
+
// fall through to String()
|
|
513
|
+
}
|
|
514
|
+
return String(value);
|
|
515
|
+
}
|
|
516
|
+
|
|
455
517
|
function formatError(error) {
|
|
456
518
|
if (!error) {
|
|
457
519
|
return "Unknown error";
|