orchestrar 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/orchestrator.js +48 -4
  2. 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.id;
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.id;
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.id;
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
- throw new Error(`Session status missing for ${sessionID}.`);
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;
@@ -452,6 +456,46 @@ function unwrap(result, label) {
452
456
  return result;
453
457
  }
454
458
 
459
+ function extractSessionID(session, context) {
460
+ if (!session || typeof session !== "object") {
461
+ throw new Error(`${context} did not return a session object.`);
462
+ }
463
+
464
+ const candidates = [
465
+ session.id,
466
+ session.sessionID,
467
+ session.info?.id,
468
+ session.info?.sessionID,
469
+ session.properties?.id,
470
+ session.properties?.sessionID,
471
+ session.properties?.info?.id,
472
+ session.properties?.info?.sessionID,
473
+ session.slug,
474
+ ];
475
+
476
+ for (const candidate of candidates) {
477
+ if (typeof candidate === "string" && candidate.trim()) {
478
+ return candidate;
479
+ }
480
+ }
481
+
482
+ throw new Error(
483
+ `${context} returned a session without an id. Response: ${safeStringify(session)}`
484
+ );
485
+ }
486
+
487
+ function safeStringify(value, maxLength = 1000) {
488
+ try {
489
+ const json = JSON.stringify(value);
490
+ if (typeof json === "string" && json.length > 0) {
491
+ return json.length > maxLength ? `${json.slice(0, maxLength)}...` : json;
492
+ }
493
+ } catch (error) {
494
+ // fall through to String()
495
+ }
496
+ return String(value);
497
+ }
498
+
455
499
  function formatError(error) {
456
500
  if (!error) {
457
501
  return "Unknown error";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orchestrar",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "OpenCode milestone orchestrator",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",