@drisp/cli 0.7.10 → 0.7.12

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/cli.js CHANGED
@@ -10,8 +10,10 @@ import {
10
10
  ServiceNotEnabledError,
11
11
  approvalAnswer,
12
12
  attachRuntimeEventLoop,
13
+ attemptForecast,
13
14
  behindMain,
14
15
  bootstrapRuntimeConfig,
16
+ budgetCheck,
15
17
  buildApiKeyHelperSettings,
16
18
  buildPhaseFeedEvent,
17
19
  buildPlanSchema,
@@ -49,7 +51,6 @@ import {
49
51
  finalizePlan,
50
52
  fit,
51
53
  fitAnsi,
52
- forecastOfCap,
53
54
  forgetRunner,
54
55
  formatClock,
55
56
  formatProbeCommand,
@@ -143,7 +144,7 @@ import {
143
144
  visualPositionToOffset,
144
145
  wrapText,
145
146
  writeIdentityOnce
146
- } from "./chunk-ISH6VEYL.js";
147
+ } from "./chunk-UUUCDIHI.js";
147
148
  import {
148
149
  generateId as generateId2
149
150
  } from "./chunk-PQIB66SG.js";
@@ -202,7 +203,7 @@ import {
202
203
  workflowRegistryDir,
203
204
  writeGlobalConfig,
204
205
  writeProjectConfig
205
- } from "./chunk-FYXEDUQ6.js";
206
+ } from "./chunk-SACVOS6T.js";
206
207
  import {
207
208
  __toESM
208
209
  } from "./chunk-G3PMV62Z.js";
@@ -210,10 +211,10 @@ import {
210
211
  // src/app/entry/cli.tsx
211
212
  import { render } from "ink";
212
213
  import meow from "meow";
213
- import fs12 from "fs";
214
+ import fs13 from "fs";
214
215
  import { createRequire } from "module";
215
216
  import os5 from "os";
216
- import path12 from "path";
217
+ import path13 from "path";
217
218
  import { fileURLToPath } from "url";
218
219
 
219
220
  // src/app/shell/sessionUiState.ts
@@ -5332,14 +5333,14 @@ function extractWebSearch(_input, response) {
5332
5333
  return { type: "text", content: extractTextContent(response), maxLines: 10 };
5333
5334
  }
5334
5335
  function extractNotebookEdit(input, _response) {
5335
- const path13 = typeof input["notebook_path"] === "string" ? input["notebook_path"] : "";
5336
+ const path14 = typeof input["notebook_path"] === "string" ? input["notebook_path"] : "";
5336
5337
  const mode = typeof input["edit_mode"] === "string" ? input["edit_mode"] : "replace";
5337
5338
  const source = typeof input["new_source"] === "string" ? input["new_source"] : "";
5338
- if (!source) return { type: "text", content: `${mode} cell in ${path13}` };
5339
+ if (!source) return { type: "text", content: `${mode} cell in ${path14}` };
5339
5340
  return {
5340
5341
  type: "code",
5341
5342
  content: source,
5342
- language: detectLanguage(path13),
5343
+ language: detectLanguage(path14),
5343
5344
  maxLines: 10
5344
5345
  };
5345
5346
  }
@@ -5865,10 +5866,10 @@ function extractToolSubject(toolName, toolInput) {
5865
5866
  const parts = [];
5866
5867
  const pattern = str(input, "pattern");
5867
5868
  const glob = str(input, "glob");
5868
- const path13 = str(input, "path");
5869
+ const path14 = str(input, "path");
5869
5870
  if (pattern) parts.push(`"${pattern}"`);
5870
5871
  if (glob) parts.push(glob);
5871
- if (path13) parts.push(`in ${path13}`);
5872
+ if (path14) parts.push(`in ${path14}`);
5872
5873
  return parts.length > 0 ? parts.join(" ") : void 0;
5873
5874
  }
5874
5875
  case "Skill":
@@ -13099,7 +13100,7 @@ var thisMachine = (installationId) => ({
13099
13100
  os: `${platform()} ${release()}`.slice(0, 64),
13100
13101
  softwareVersion: runnerSoftwareVersion
13101
13102
  });
13102
- var post = (origin, path13, body) => fetch(new URL(path13, origin), {
13103
+ var post = (origin, path14, body) => fetch(new URL(path14, origin), {
13103
13104
  method: "POST",
13104
13105
  headers: { "Content-Type": "application/json" },
13105
13106
  body: JSON.stringify(body)
@@ -13118,8 +13119,8 @@ async function alreadyConnected(existing, { forTeam, ownIdentity }) {
13118
13119
  const problem = own ? await credentialAccepted(own.config) ? void 0 : "lapsed" : forTeam(existing.orgId).length ? "other_runner" : "missing";
13119
13120
  const runner = { orgId: existing.orgId, runnerId: existing.runnerId, name: existing.name };
13120
13121
  if (own && problem === void 0) return { status: "already_connected", ...runner, path: own.path };
13121
- const path13 = (own ?? forTeam(existing.orgId)[0])?.path;
13122
- return { status: "identity_unusable", ...runner, problem, ...path13 ? { path: path13 } : {} };
13122
+ const path14 = (own ?? forTeam(existing.orgId)[0])?.path;
13123
+ return { status: "identity_unusable", ...runner, problem, ...path14 ? { path: path14 } : {} };
13123
13124
  }
13124
13125
  async function connectWithCode({
13125
13126
  code,
@@ -13191,20 +13192,20 @@ async function saveIdentity(origin, credential, { single, forTeam }, directory)
13191
13192
  name: credential.name
13192
13193
  });
13193
13194
  const replaced = [];
13194
- for (const { path: path14 } of forTeam(credential.orgId)) {
13195
- const aside = `${path14}.replaced-${Date.now()}`;
13196
- await rename(path14, aside);
13195
+ for (const { path: path15 } of forTeam(credential.orgId)) {
13196
+ const aside = `${path15}.replaced-${Date.now()}`;
13197
+ await rename(path15, aside);
13197
13198
  replaced.push(aside);
13198
13199
  }
13199
- const path13 = single ?? teamIdentityPath(origin, credential.orgId, directory);
13200
+ const path14 = single ?? teamIdentityPath(origin, credential.orgId, directory);
13200
13201
  try {
13201
- await writeIdentityOnce(path13, JSON.stringify(config, null, 2) + "\n");
13202
+ await writeIdentityOnce(path14, JSON.stringify(config, null, 2) + "\n");
13202
13203
  } catch (error) {
13203
13204
  if (error.code === "EEXIST")
13204
- throw new Error(`Another Connect wrote a Runner identity for this Team at ${path13} meanwhile; it was left unchanged.`);
13205
+ throw new Error(`Another Connect wrote a Runner identity for this Team at ${path14} meanwhile; it was left unchanged.`);
13205
13206
  throw error;
13206
13207
  }
13207
- return { status: "connected", config, path: path13, replaced };
13208
+ return { status: "connected", config, path: path14, replaced };
13208
13209
  }
13209
13210
  function pathSegment(value) {
13210
13211
  const segment = encodeURIComponent(value);
@@ -13244,7 +13245,7 @@ async function refuseExisting(target) {
13244
13245
  throw new Error(`This machine already has a Runner${name ? ` (${name})` : ""} configured at ${target}.`);
13245
13246
  }
13246
13247
  async function disconnectRunner({
13247
- identity: { path: path13, config },
13248
+ identity: { path: path14, config },
13248
13249
  serviceManager,
13249
13250
  othersRemain
13250
13251
  }) {
@@ -13277,7 +13278,7 @@ async function disconnectRunner({
13277
13278
  await restore();
13278
13279
  throw new Error(`The Hub refused to disconnect ${name} (${body.error ?? response.status}); it is still connected.`);
13279
13280
  }
13280
- await forgetRunner(path13);
13281
+ await forgetRunner(path14);
13281
13282
  if (othersRemain) await restore();
13282
13283
  else await serviceManager?.remove();
13283
13284
  return result;
@@ -13430,18 +13431,18 @@ async function runRunnerCommandV2(input, options = {}) {
13430
13431
  `This machine is already connected to this Team as ${outcome.name}, but ${why}. ` + (code ? `The code was not used: connect a new Runner in its place with ${retry}. ` : `Connect a new Runner in its place with a Connect code from Settings \u2192 Runners: ${retry}. `) + `The old ${outcome.name} stays listed in Settings \u2192 Runners, offline.`
13431
13432
  );
13432
13433
  }
13433
- const { config, path: path13, replaced } = outcome;
13434
+ const { config, path: path14, replaced } = outcome;
13434
13435
  for (const aside of replaced)
13435
13436
  process.stdout.write(
13436
13437
  `The Hub no longer recognised this machine's earlier identity for this Team; it was moved aside to ${aside}.
13437
13438
  `
13438
13439
  );
13439
13440
  process.stdout.write(
13440
- `Connected as ${config.name ?? config.runnerId}. Identity saved to ${path13}.
13441
+ `Connected as ${config.name ?? config.runnerId}. Identity saved to ${path14}.
13441
13442
  `
13442
13443
  );
13443
13444
  if (services) {
13444
- const service = await ensureService(services, config, path13);
13445
+ const service = await ensureService(services, config, path14);
13445
13446
  process.stdout.write(`${serviceStarted(service)}
13446
13447
  `);
13447
13448
  return 0;
@@ -13450,7 +13451,7 @@ async function runRunnerCommandV2(input, options = {}) {
13450
13451
  process.stdout.write(
13451
13452
  "No launchd or systemd here to run the Runner as a background service; running it in the foreground instead.\n"
13452
13453
  );
13453
- await runConfiguredRunner(path13, options.signal);
13454
+ await runConfiguredRunner(path14, options.signal);
13454
13455
  return 0;
13455
13456
  }
13456
13457
  case "disconnect": {
@@ -13521,9 +13522,9 @@ async function runRunnerCommandV2(input, options = {}) {
13521
13522
  configured: true,
13522
13523
  // One entry per Team this machine serves; credentials are never printed.
13523
13524
  teams: identities.map(
13524
- ({ path: path13, config: { token: _token, ...config } }) => ({
13525
+ ({ path: path14, config: { token: _token, ...config } }) => ({
13525
13526
  ...config,
13526
- path: path13
13527
+ path: path14
13527
13528
  })
13528
13529
  ),
13529
13530
  service: service ? {
@@ -13872,9 +13873,9 @@ var DrispClient = class _DrispClient {
13872
13873
  if (!match) throw new Error("invalid_hub_url");
13873
13874
  return new _DrispClient(url.origin, decodeURIComponent(match[1]), async () => token);
13874
13875
  }
13875
- async request(path13, body) {
13876
+ async request(path14, body) {
13876
13877
  const response = await fetch(
13877
- `${this.baseUrl}/v2/orgs/${encodeURIComponent(this.orgId)}${path13}`,
13878
+ `${this.baseUrl}/v2/orgs/${encodeURIComponent(this.orgId)}${path14}`,
13878
13879
  {
13879
13880
  method: body === void 0 ? "GET" : "POST",
13880
13881
  headers: {
@@ -14206,8 +14207,15 @@ var buildStateSchema = external_exports.strictObject({
14206
14207
  * written before parses.
14207
14208
  */
14208
14209
  done: external_exports.array(external_exports.string()).optional(),
14209
- /** The merged issues the Orchestrator was already asked to repair in Linear, so it is asked once. */
14210
- repaired: external_exports.array(external_exports.string()).optional()
14210
+ /**
14211
+ * The merged issues the Orchestrator was asked to repair in Linear. No longer written since reconcile (DRI-277),
14212
+ * still read so a state written before parses.
14213
+ */
14214
+ repaired: external_exports.array(external_exports.string()).optional(),
14215
+ /** Additive (DRI-277): the `once` keys of the comments reconcile already asked for, so each is asked once. */
14216
+ posted: external_exports.array(external_exports.string()).optional(),
14217
+ /** Additive (DRI-277): reconcile ticks in a row; at `RECONCILE_PASSES` the tick goes on without one. */
14218
+ reconcilePasses: external_exports.number().int().nonnegative().optional()
14211
14219
  });
14212
14220
 
14213
14221
  // src/core/build/childStart.ts
@@ -14265,11 +14273,14 @@ function outcomeOf(view) {
14265
14273
  return "failed";
14266
14274
  }
14267
14275
  function buildLimits(own, delegation) {
14268
- if (!delegation) return own;
14276
+ if (!delegation) return { ...own, maxChildren: own.maxChildren ?? 1 };
14269
14277
  return {
14270
14278
  ...own,
14271
- maxChildren: Math.min(own.maxChildren, delegation.maxChildren),
14272
- tokenBudget: Math.min(own.tokenBudget, delegation.tokenBudget)
14279
+ maxChildren: Math.min(
14280
+ own.maxChildren ?? Infinity,
14281
+ delegation.maxChildren ?? own.maxChildren ?? 1
14282
+ ),
14283
+ tokenBudget: delegation.tokenBudget
14273
14284
  };
14274
14285
  }
14275
14286
  function occupies(view) {
@@ -14314,8 +14325,8 @@ function assessTick(facts) {
14314
14325
  ].sort((a, b) => a.n - b.n);
14315
14326
  }
14316
14327
  }
14317
- for (const attempts of Object.values(state.attempts))
14318
- for (const attempt of attempts) {
14328
+ for (const attempts2 of Object.values(state.attempts))
14329
+ for (const attempt of attempts2) {
14319
14330
  const view = views.get(attempt.runId);
14320
14331
  if (view?.closed && !attempt.outcome) attempt.outcome = outcomeOf(view);
14321
14332
  }
@@ -14326,11 +14337,13 @@ function assessTick(facts) {
14326
14337
  state.needsPerson[entry.id] = BUILD_STRINGS.rebaseFailed(branchOf(entry));
14327
14338
  }
14328
14339
  const pullRequests = /* @__PURE__ */ new Map();
14340
+ const byEntry = /* @__PURE__ */ new Map();
14329
14341
  const prsOf = (entry) => {
14330
14342
  const branch = attemptsOf(entry.id).at(-1)?.branch ?? issues.get(entry.id)?.branchName;
14331
14343
  if (!branch) return void 0;
14332
14344
  if (!pullRequests.has(branch))
14333
14345
  pullRequests.set(branch, facts.pullRequests(branch));
14346
+ byEntry.set(entry.id, pullRequests.get(branch));
14334
14347
  return pullRequests.get(branch);
14335
14348
  };
14336
14349
  const status = /* @__PURE__ */ new Map();
@@ -14338,29 +14351,15 @@ function assessTick(facts) {
14338
14351
  const linear = issues.get(id)?.state.type;
14339
14352
  return linear === "completed" ? "done" : "blocked";
14340
14353
  };
14341
- const repair = [];
14342
- const repaired = new Set(state.repaired ?? []);
14343
14354
  for (const entry of entries) {
14344
- const attempts = attemptsOf(entry.id);
14345
- const newest = attempts.at(-1);
14355
+ const attempts2 = attemptsOf(entry.id);
14356
+ const newest = attempts2.at(-1);
14346
14357
  const view = newest && views.get(newest.runId);
14347
14358
  const linear = issues.get(entry.id)?.state.type;
14348
14359
  const statusOf = () => {
14349
14360
  if (linear === "completed" || linear === "canceled") return "done";
14350
14361
  const prs = entry.profile === "investigation" ? void 0 : prsOf(entry);
14351
- if (prs?.merged) {
14352
- if (!repaired.has(entry.id) && !(newest && occupies(view))) {
14353
- const prUrl = prs.mergedUrl ?? branchOf(entry);
14354
- repair.push({
14355
- id: entry.id,
14356
- identifier: entry.identifier,
14357
- prUrl,
14358
- comment: BUILD_STRINGS.repairComment(prUrl, orchestratorRunId)
14359
- });
14360
- repaired.add(entry.id);
14361
- }
14362
- return "done";
14363
- }
14362
+ if (prs?.merged) return "done";
14364
14363
  if (newest && (!view || !view.closed)) return "live";
14365
14364
  const current = issues.get(entry.id);
14366
14365
  if (!current || eligibilityReason(current)) {
@@ -14373,8 +14372,8 @@ function assessTick(facts) {
14373
14372
  }
14374
14373
  if (newest?.outcome === "template_mismatch") return "replan";
14375
14374
  if (newest?.outcome === "completed")
14376
- state.needsPerson[entry.id] ??= entry.profile === "investigation" ? "The investigation ended without marking its accepted findings Done in Linear. Review its evidence." : BUILD_STRINGS.completedUnmerged;
14377
- if (state.needsPerson[entry.id] || newest && !mayRetry(attempts))
14375
+ state.needsPerson[entry.id] ??= entry.profile === "investigation" ? "The investigation ended. Review its findings and evidence on the issue." : BUILD_STRINGS.completedUnmerged;
14376
+ if (state.needsPerson[entry.id] || newest && !mayRetry(attempts2))
14378
14377
  return "needs_person";
14379
14378
  const blockers = [
14380
14379
  .../* @__PURE__ */ new Set([
@@ -14398,47 +14397,74 @@ function assessTick(facts) {
14398
14397
  if (status.get(entry.id) === "done" && state.needsPerson[entry.id] === BUILD_STRINGS.completedUnmerged)
14399
14398
  delete state.needsPerson[entry.id];
14400
14399
  }
14401
- if (repaired.size > 0) state.repaired = [...repaired];
14402
- let parkReason = facts.templateVersion !== state.templateVersion ? "template" : state.tickCount >= facts.limits.tickAllowance ? "budget" : void 0;
14400
+ const tokenBudget = facts.limits.tokenBudget;
14401
+ const attempts = [
14402
+ ...facts.children.map((view) => ({
14403
+ tokenCap: view.parent?.tokenCap ?? Number.NaN,
14404
+ closed: view.closed,
14405
+ ...view.usage ? { spent: view.usage.counted } : {}
14406
+ })),
14407
+ ...Object.values(state.attempts).flat().filter((attempt) => !views.has(attempt.runId)).map((attempt) => ({ tokenCap: attempt.tokenCap, closed: false }))
14408
+ ];
14409
+ let park = facts.templateVersion !== state.templateVersion ? { reason: "template", message: BUILD_STRINGS.templatePark } : state.tickCount >= facts.limits.tickAllowance ? {
14410
+ reason: "ticks",
14411
+ message: BUILD_STRINGS.tickPark(facts.limits.tickAllowance)
14412
+ } : void 0;
14403
14413
  const occupying = entries.filter((entry) => {
14404
14414
  const newest = attemptsOf(entry.id).at(-1);
14405
14415
  return newest !== void 0 && occupies(views.get(newest.runId));
14406
14416
  }).length;
14407
14417
  const queue = [];
14408
- if (!parkReason) {
14409
- let committed = Object.values(state.attempts).flat().reduce((sum, attempt) => sum + forecastOfCap(attempt.tokenCap), 0);
14418
+ if (!park) {
14419
+ const admitted = [...attempts];
14410
14420
  for (const entry of entries) {
14411
14421
  if (status.get(entry.id) !== "ready") continue;
14412
- if (committed + forecastOfCap(entry.tokenCap) > facts.limits.tokenBudget) {
14413
- parkReason = "budget";
14422
+ const next = attemptForecast(entry.tokenCap);
14423
+ const check = budgetCheck({ tokenBudget, attempts: admitted, next });
14424
+ if (!check.fits) {
14425
+ park = {
14426
+ reason: "tokens",
14427
+ message: BUILD_STRINGS.tokenPark({
14428
+ used: check.used,
14429
+ tokenBudget,
14430
+ identifier: entry.identifier,
14431
+ forecast: next
14432
+ })
14433
+ };
14414
14434
  break;
14415
14435
  }
14416
14436
  queue.push(entry);
14417
- committed += forecastOfCap(entry.tokenCap);
14437
+ admitted.push({ tokenCap: entry.tokenCap, closed: false });
14418
14438
  }
14419
14439
  }
14420
14440
  return {
14421
14441
  state,
14422
14442
  status,
14423
- repair,
14443
+ pullRequests: byEntry,
14424
14444
  queue,
14425
14445
  slots: Math.max(0, facts.limits.maxChildren - occupying),
14426
- ...parkReason ? { parkReason } : {}
14446
+ ...park ? { park } : {}
14427
14447
  };
14428
14448
  }
14429
14449
  function tickAction(input) {
14430
14450
  const live = input.children.filter((view) => !view.closed);
14451
+ const questions = live.filter(
14452
+ (view) => view.execution?.status === "awaiting_attention" && view.scheduling === "idle" && view.execution.interruption?.kind === "question" && view.execution.interruption.respondent === "orchestrator" && !view.cancellation
14453
+ );
14454
+ if (questions.length)
14455
+ return {
14456
+ action: "supervise",
14457
+ children: questions.map((view) => ({
14458
+ runId: view.runId,
14459
+ message: view.execution.interruption.message
14460
+ }))
14461
+ };
14431
14462
  if (input.started > 0 || live.some((view) => occupies(view)))
14432
14463
  return { action: "wait" };
14433
14464
  const remaining = input.entries.some(
14434
14465
  (entry) => ["ready", "pending"].includes(input.status.get(entry.id))
14435
14466
  );
14436
- if (input.parkReason && remaining)
14437
- return {
14438
- action: "park",
14439
- reason: input.parkReason,
14440
- message: input.parkReason === "budget" ? BUILD_STRINGS.budgetPark : BUILD_STRINGS.templatePark
14441
- };
14467
+ if (input.park && remaining) return { action: "park", ...input.park };
14442
14468
  if (live.length > 0) return { action: "wait" };
14443
14469
  const done = input.entries.filter(
14444
14470
  (entry) => input.status.get(entry.id) === "done"
@@ -14455,13 +14481,126 @@ function tickAction(input) {
14455
14481
  };
14456
14482
  }
14457
14483
 
14484
+ // src/core/build/reconcile.ts
14485
+ var RECONCILE_PASSES = 3;
14486
+ var WEB_QA = /* @__PURE__ */ new Set(["web", "both"]);
14487
+ var NOT_HUMAN = "waiting";
14488
+ function teamStatus(status, issue) {
14489
+ const states = issue.teamStates;
14490
+ if (!states) return status;
14491
+ const type = status === "Todo" ? "unstarted" : status === "Released" ? "completed" : "started";
14492
+ const names = status === "Review" || status === "QA" || status === "Ready" ? [status, "In Review", "Review", "In Progress"] : status === "Released" ? [status, "Done"] : [status];
14493
+ for (const name of names) {
14494
+ const match = states.find(
14495
+ (s) => s.type === type && s.name.toLowerCase() === name.toLowerCase()
14496
+ );
14497
+ if (match) return match.name;
14498
+ }
14499
+ if (status === "Needs Input") return void 0;
14500
+ if (issue.state.type === type && states.some((s) => s.name === issue.state.name))
14501
+ return issue.state.name;
14502
+ return states.find((s) => s.type === type)?.name;
14503
+ }
14504
+ function desired(entry, facts, views) {
14505
+ const newest = facts.attempts[entry.id]?.at(-1);
14506
+ const view = newest && views.get(newest.runId);
14507
+ const live = newest !== void 0 && (!view || !view.closed);
14508
+ const prs = facts.pullRequests.get(entry.id);
14509
+ const interruption = view?.execution?.interruption;
14510
+ if (facts.released?.(entry.id)) return { status: "Released", comments: [] };
14511
+ if (live && view?.execution?.status === "awaiting_attention" && interruption && interruption.kind !== NOT_HUMAN && !(interruption.kind === "question" && interruption.respondent === "orchestrator")) {
14512
+ const step = facts.step?.(view.runId);
14513
+ return {
14514
+ status: "Needs Input",
14515
+ comments: [
14516
+ {
14517
+ body: BUILD_STRINGS.askComment({
14518
+ message: interruption.message,
14519
+ runId: view.runId,
14520
+ ...step ? { step } : {}
14521
+ }),
14522
+ once: `ask:${view.runId}:${interruption.interruptionId}`
14523
+ }
14524
+ ]
14525
+ };
14526
+ }
14527
+ if (prs?.merged) {
14528
+ const pr = prComment(prs.mergedUrl);
14529
+ if (!WEB_QA.has(entry.qa)) return { status: "Ready", comments: pr };
14530
+ const results = facts.qa?.(entry.id) ?? [];
14531
+ const last = results.at(-1);
14532
+ if (!last) return { status: "QA", comments: pr };
14533
+ if (last.passed) return { status: "Ready", comments: pr };
14534
+ const failures = results.filter((result) => !result.passed).length;
14535
+ return {
14536
+ status: failures >= 2 ? "Needs Input" : "Todo",
14537
+ comments: [...pr, { body: last.report, once: `qa:${last.runId}` }]
14538
+ };
14539
+ }
14540
+ if (prs?.open) return { status: "Review", comments: prComment(prs.openUrl) };
14541
+ if (live) return { status: "In Progress", comments: [] };
14542
+ if (entry.profile === "investigation" && newest?.outcome === "completed")
14543
+ return { status: "Review", comments: [] };
14544
+ if (newest) return { status: "Todo", comments: [] };
14545
+ return { comments: [] };
14546
+ }
14547
+ function prComment(url) {
14548
+ return url ? [{ body: BUILD_STRINGS.prComment(url), once: `pr:${url}` }] : [];
14549
+ }
14550
+ var closedIssue = (issue) => issue.state.type === "completed" || issue.state.type === "canceled";
14551
+ function projectStatus(facts) {
14552
+ const current = facts.project.status;
14553
+ const issues = facts.issues.filter((issue) => !issue.external);
14554
+ const completed = issues.length > 0 && issues.every(closedIssue);
14555
+ const started = facts.entries.some(
14556
+ (entry) => (facts.attempts[entry.id]?.length ?? 0) > 0
14557
+ );
14558
+ if (current === "Planned" && started) return "In Progress";
14559
+ if (current === "In Progress" && completed) return "Completed";
14560
+ if (current === "Completed" && !completed) return "In Progress";
14561
+ return void 0;
14562
+ }
14563
+ function reconcile(facts) {
14564
+ const views = new Map(facts.children.map((view) => [view.runId, view]));
14565
+ const issues = new Map(facts.issues.map((issue) => [issue.id, issue]));
14566
+ const posted = new Set(facts.posted);
14567
+ const actions = [];
14568
+ const asked = [];
14569
+ for (const entry of facts.entries) {
14570
+ const issue = issues.get(entry.id);
14571
+ if (!issue || issue.external || closedIssue(issue) || issue.labels.includes("ready-for-human"))
14572
+ continue;
14573
+ const implied = desired(entry, facts, views);
14574
+ const { comments } = implied;
14575
+ const status = implied.status ?? (issue.state.name === "In Progress" ? "Todo" : void 0);
14576
+ const target = status && teamStatus(status, issue);
14577
+ if (target && target !== issue.state.name)
14578
+ actions.push({ kind: "issue.state", issue: entry.id, state: target });
14579
+ for (const comment of comments) {
14580
+ if (posted.has(comment.once)) continue;
14581
+ posted.add(comment.once);
14582
+ asked.push(comment.once);
14583
+ actions.push({ kind: "issue.comment", issue: entry.id, ...comment });
14584
+ }
14585
+ }
14586
+ const project = projectStatus(facts);
14587
+ if (project)
14588
+ actions.push({
14589
+ kind: "project.state",
14590
+ project: facts.project.id,
14591
+ state: project
14592
+ });
14593
+ return { actions, posted: asked };
14594
+ }
14595
+
14458
14596
  // src/core/build/tick.ts
14459
14597
  var UNAVAILABLE_RETRY_MS = 2e3;
14460
14598
  var UNAVAILABLE_RETRY_FOR_MS = 3e4;
14461
14599
  var NEVER = (/* @__PURE__ */ new Date(0)).toISOString();
14462
14600
  var notStarted = () => ({
14463
- action: "complete",
14464
- message: BUILD_STRINGS.notStarted
14601
+ action: "park",
14602
+ reason: "attention",
14603
+ message: "This Build has not been started. Review the plan and choose Start; no child work has completed."
14465
14604
  });
14466
14605
  var guidanceFile = (artifacts) => path7.join(artifacts, "input", "guidance.json");
14467
14606
  function replan(artifacts, guidance) {
@@ -14580,7 +14719,7 @@ async function runBuildTick(deps) {
14580
14719
  state: stored,
14581
14720
  children: children.runs,
14582
14721
  templateVersion,
14583
- // The approved plan's budget (the member's, once it is editable) narrowed by what the Hub enforces.
14722
+ // The Hub Run's budget, read each tick (a member may change it); the plan's binds only a Run without delegation.
14584
14723
  limits: buildLimits(
14585
14724
  { ...ORCHESTRATOR_LIMITS, tokenBudget: plan.budget.tokenBudget },
14586
14725
  parent.delegation
@@ -14591,7 +14730,7 @@ async function runBuildTick(deps) {
14591
14730
  now: deps.now().toISOString()
14592
14731
  });
14593
14732
  const { state, status } = assessment;
14594
- let parkReason = assessment.parkReason;
14733
+ let park = assessment.park;
14595
14734
  const record = () => {
14596
14735
  writeFile(statePath, json(state));
14597
14736
  const files = [path7.join(relativePlanDir, "build-state.json")];
@@ -14608,10 +14747,6 @@ async function runBuildTick(deps) {
14608
14747
  ))
14609
14748
  push(worktree.path, worktree.branch);
14610
14749
  };
14611
- if (assessment.repair.length > 0) {
14612
- record();
14613
- return { action: "repair", issues: assessment.repair };
14614
- }
14615
14750
  const deferred = [];
14616
14751
  const behind = [];
14617
14752
  let started = 0;
@@ -14689,7 +14824,13 @@ async function runBuildTick(deps) {
14689
14824
  reason: BUILD_STRINGS.hubUnreachable(entry.identifier)
14690
14825
  });
14691
14826
  else if (result.kind === "budget") {
14692
- parkReason = "budget";
14827
+ park = {
14828
+ reason: "tokens",
14829
+ message: BUILD_STRINGS.tokenParkRefused(
14830
+ entry.identifier,
14831
+ attemptForecast(entry.tokenCap)
14832
+ )
14833
+ };
14693
14834
  break;
14694
14835
  } else {
14695
14836
  state.needsPerson[entry.id] = BUILD_STRINGS.startRefused(result.code);
@@ -14721,6 +14862,24 @@ async function runBuildTick(deps) {
14721
14862
  }
14722
14863
  if (installed) removeWorkflow(entry.workflowName);
14723
14864
  }
14865
+ const linear = reconcile({
14866
+ project: input.project,
14867
+ entries,
14868
+ issues: input.issues,
14869
+ attempts: state.attempts,
14870
+ children: children.runs,
14871
+ pullRequests: assessment.pullRequests,
14872
+ posted: state.posted ?? []
14873
+ });
14874
+ const passes = state.reconcilePasses ?? 0;
14875
+ if (linear.actions.length > 0 && passes < RECONCILE_PASSES) {
14876
+ state.reconcilePasses = passes + 1;
14877
+ if (linear.posted.length > 0)
14878
+ state.posted = [...state.posted ?? [], ...linear.posted];
14879
+ record();
14880
+ return { action: "reconcile", actions: linear.actions };
14881
+ }
14882
+ delete state.reconcilePasses;
14724
14883
  record();
14725
14884
  if (behind.length > 0) return { action: "rebase", items: behind };
14726
14885
  return tickAction({
@@ -14728,7 +14887,7 @@ async function runBuildTick(deps) {
14728
14887
  status,
14729
14888
  children: children.runs,
14730
14889
  started,
14731
- ...parkReason ? { parkReason } : {}
14890
+ ...park ? { park } : {}
14732
14891
  });
14733
14892
  }
14734
14893
  function locate(deps, entry, branchName) {
@@ -15080,8 +15239,120 @@ function runBuildCheck(input) {
15080
15239
  return code;
15081
15240
  }
15082
15241
 
15242
+ // src/core/build/supervision.ts
15243
+ import { randomUUID as randomUUID3 } from "crypto";
15244
+ async function superviseChild(input) {
15245
+ const { hub, parentId, operation } = input;
15246
+ if (operation === "children") return hub.runs({ parent: parentId });
15247
+ if (!input.childId) throw new BuildUsageError("A child Run id is required.");
15248
+ const child = await hub.run(input.childId);
15249
+ if (child.parent?.runId !== parentId)
15250
+ throw new BuildUsageError(
15251
+ "Only a direct child of this Build can be inspected or guided."
15252
+ );
15253
+ if (operation === "inspect") {
15254
+ const after = input.after ?? 0;
15255
+ if (!Number.isSafeInteger(after) || after < 0)
15256
+ throw new BuildUsageError(
15257
+ "The history cursor must be a nonnegative integer."
15258
+ );
15259
+ return { child, history: await hub.historyPage(child.runId, after) };
15260
+ }
15261
+ const text = input.text?.trim();
15262
+ if (!text || text.length > 12e4)
15263
+ throw new BuildUsageError("Guidance must contain 1\u2013120000 characters.");
15264
+ if (child.closed || child.cancellation)
15265
+ throw new BuildUsageError("The child is closed or cancelling.");
15266
+ const interruption = child.execution?.interruption;
15267
+ const message = `Orchestrator ${parentId} technical guidance (not a human approval):
15268
+ ${text}`;
15269
+ const { hubEpoch } = await hub.runs({ parent: parentId });
15270
+ const base = {
15271
+ commandId: randomUUID3(),
15272
+ hubEpoch,
15273
+ runId: child.runId,
15274
+ expectedRecordRevision: child.recordRevision
15275
+ };
15276
+ if (child.execution?.status === "awaiting_attention") {
15277
+ if (interruption?.kind !== "question" || interruption.respondent !== "orchestrator" || interruption.requestId)
15278
+ throw new BuildUsageError(
15279
+ "This interruption is reserved for a member. Inspect it and escalate the specific decision."
15280
+ );
15281
+ return hub.submit({
15282
+ ...base,
15283
+ intent: {
15284
+ kind: "answer",
15285
+ interruptionId: interruption.interruptionId,
15286
+ expectedInterruptionRevision: interruption.revision,
15287
+ answer: message
15288
+ }
15289
+ });
15290
+ }
15291
+ if (child.execution?.status !== "running")
15292
+ throw new BuildUsageError(
15293
+ "The child is not running; inspect its scheduling state before retrying."
15294
+ );
15295
+ return hub.submit({ ...base, intent: { kind: "steer", text: message } });
15296
+ }
15297
+
15298
+ // src/core/build/evidenceCopy.ts
15299
+ import fs11 from "fs";
15300
+ import path11 from "path";
15301
+ function copyEvidence(cwd, source, name) {
15302
+ if (!source || !name || !/^[a-zA-Z0-9][a-zA-Z0-9._-]*\.(png|jpe?g|webp)$/i.test(name))
15303
+ throw new BuildUsageError(
15304
+ "Usage: drisp build evidence-copy <screenshot> <filename.png|jpg|webp>"
15305
+ );
15306
+ const root = fs11.realpathSync(cwd);
15307
+ let directory = root;
15308
+ for (const part of [".athena", "evidence"]) {
15309
+ directory = path11.join(directory, part);
15310
+ try {
15311
+ fs11.mkdirSync(directory);
15312
+ } catch (error) {
15313
+ if (error.code !== "EEXIST") throw error;
15314
+ }
15315
+ const stat = fs11.lstatSync(directory);
15316
+ if (stat.isSymbolicLink() || !stat.isDirectory())
15317
+ throw new BuildUsageError(
15318
+ "Evidence directories must be real directories inside this worktree."
15319
+ );
15320
+ }
15321
+ const sourcePath = path11.resolve(root, source);
15322
+ const fd = fs11.openSync(
15323
+ sourcePath,
15324
+ fs11.constants.O_RDONLY | fs11.constants.O_NOFOLLOW
15325
+ );
15326
+ let bytes;
15327
+ try {
15328
+ const stat = fs11.fstatSync(fd);
15329
+ if (!stat.isFile() || stat.size > 25 * 1024 * 1024)
15330
+ throw new BuildUsageError(
15331
+ "A screenshot must be a regular image file of at most 25 MiB."
15332
+ );
15333
+ bytes = fs11.readFileSync(fd);
15334
+ } finally {
15335
+ fs11.closeSync(fd);
15336
+ }
15337
+ const png = bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]));
15338
+ const jpg = bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255;
15339
+ const webp = bytes.toString("ascii", 0, 4) === "RIFF" && bytes.toString("ascii", 8, 12) === "WEBP";
15340
+ const extension = path11.extname(name).toLowerCase();
15341
+ if (!(extension === ".png" && png || [".jpg", ".jpeg"].includes(extension) && jpg || extension === ".webp" && webp))
15342
+ throw new BuildUsageError(
15343
+ "The source must be a PNG, JPEG or WebP screenshot matching the destination extension."
15344
+ );
15345
+ const target = path11.join(directory, name);
15346
+ fs11.writeFileSync(target, bytes, { flag: "wx" });
15347
+ return { path: target };
15348
+ }
15349
+
15083
15350
  // src/app/entry/buildCommand.ts
15084
15351
  var USAGE3 = `Usage: drisp build plan --input <path>
15352
+ drisp build children
15353
+ drisp build inspect <child-run-id> [history-cursor]
15354
+ drisp build guide <child-run-id> "<technical guidance>"
15355
+ drisp build evidence-copy <screenshot> <filename.png|jpg|webp>
15085
15356
  drisp build tick --input <path> [--rebase-failed <IDENTIFIER>]...
15086
15357
  drisp build checks
15087
15358
  drisp build step <n> [--qa none|web|macos|both] [--profile implementation|documentation|investigation]
@@ -15124,10 +15395,12 @@ function githubPullRequests(folder, branch) {
15124
15395
  function parsePullRequests(output) {
15125
15396
  const prs = JSON.parse(output);
15126
15397
  const merged = prs.find((pr) => pr.state === "MERGED");
15398
+ const open = prs.find((pr) => pr.state === "OPEN");
15127
15399
  return {
15128
- open: prs.some((pr) => pr.state === "OPEN"),
15400
+ open: open !== void 0,
15129
15401
  merged: merged !== void 0,
15130
- ...merged ? { mergedUrl: merged.url } : {}
15402
+ ...merged ? { mergedUrl: merged.url } : {},
15403
+ ...open ? { openUrl: open.url } : {}
15131
15404
  };
15132
15405
  }
15133
15406
  function hostCapabilities(folder) {
@@ -15199,6 +15472,31 @@ async function runBuildCommand(input) {
15199
15472
  try {
15200
15473
  let output;
15201
15474
  switch (input.subcommand) {
15475
+ case "evidence-copy":
15476
+ output = copyEvidence(
15477
+ input.cwd,
15478
+ input.positional?.[0],
15479
+ input.positional?.[1]
15480
+ );
15481
+ break;
15482
+ case "children":
15483
+ case "inspect":
15484
+ case "guide": {
15485
+ const parentId = requireEnv(env2, "DRISP_RUN_ID");
15486
+ const hub = input.supervisionHub ?? DrispClient.delegated(
15487
+ requireEnv(env2, "DRISP_HUB_URL"),
15488
+ requireEnv(env2, "DRISP_RUN_TOKEN")
15489
+ );
15490
+ output = await superviseChild({
15491
+ hub,
15492
+ parentId,
15493
+ operation: input.subcommand,
15494
+ childId: input.positional?.[0],
15495
+ text: input.positional?.[1],
15496
+ ...input.subcommand === "inspect" && input.positional?.[1] !== void 0 ? { after: Number(input.positional[1]) } : {}
15497
+ });
15498
+ break;
15499
+ }
15202
15500
  case "plan": {
15203
15501
  const calibration = input.dependencies?.calibration ?? await measuredForecasts(env2);
15204
15502
  output = runBuildPlan({
@@ -15292,9 +15590,9 @@ import process7 from "process";
15292
15590
 
15293
15591
  // src/harnesses/claude/system/doctorEnvironment.ts
15294
15592
  import { execFileSync as execFileSync3 } from "child_process";
15295
- import * as fs11 from "fs";
15593
+ import * as fs12 from "fs";
15296
15594
  import * as os4 from "os";
15297
- import * as path11 from "path";
15595
+ import * as path12 from "path";
15298
15596
  var MANAGED_POLICY_KEYS = [
15299
15597
  "forceLoginMethod",
15300
15598
  "forceLoginOrgUUID",
@@ -15398,8 +15696,8 @@ function collectEnvironment(options = {}) {
15398
15696
  const detectVersion = options.detectClaudeVersionFn ?? detectClaudeVersion;
15399
15697
  const runAuthStatus = options.runClaudeAuthStatusFn ?? runClaudeAuthStatus;
15400
15698
  const resolveForwarder = options.resolveHookForwarderCommandFn ?? resolveHookForwarderCommand;
15401
- const statFn = options.statFn ?? ((p) => fs11.statSync(p));
15402
- const readFileFn = options.readFileFn ?? ((p) => fs11.readFileSync(p, "utf8"));
15699
+ const statFn = options.statFn ?? ((p) => fs12.statSync(p));
15700
+ const readFileFn = options.readFileFn ?? ((p) => fs12.readFileSync(p, "utf8"));
15403
15701
  const settingsPaths = resolveClaudeSettingsSurfacePaths(
15404
15702
  homeDir,
15405
15703
  cwd,
@@ -15444,7 +15742,7 @@ function collectEnvironment(options = {}) {
15444
15742
  });
15445
15743
  let globalConfigPresent = false;
15446
15744
  try {
15447
- statFn(path11.join(homeDir, ".claude.json"));
15745
+ statFn(path12.join(homeDir, ".claude.json"));
15448
15746
  globalConfigPresent = true;
15449
15747
  } catch {
15450
15748
  globalConfigPresent = false;
@@ -15924,13 +16222,13 @@ function runRunsCommand(input) {
15924
16222
  // src/app/entry/cli.tsx
15925
16223
  import { jsx as jsx24 } from "react/jsx-runtime";
15926
16224
  function resolvePackageJsonPath(entryUrl) {
15927
- let currentDir = path12.dirname(fileURLToPath(entryUrl));
16225
+ let currentDir = path13.dirname(fileURLToPath(entryUrl));
15928
16226
  for (; ; ) {
15929
- const candidatePath = path12.join(currentDir, "package.json");
15930
- if (fs12.existsSync(candidatePath)) {
16227
+ const candidatePath = path13.join(currentDir, "package.json");
16228
+ if (fs13.existsSync(candidatePath)) {
15931
16229
  return candidatePath;
15932
16230
  }
15933
- const parentDir = path12.dirname(currentDir);
16231
+ const parentDir = path13.dirname(currentDir);
15934
16232
  if (parentDir === currentDir) {
15935
16233
  throw new Error("Could not locate package.json for CLI metadata.");
15936
16234
  }
@@ -16100,6 +16398,10 @@ var cli = meow(
16100
16398
  runner [sub] Run the runner that connects this machine to a Team and executes its Runs
16101
16399
  (no subcommand: foreground; connect [code] --hub <url> [--replace], disconnect [team], status, restart, recover, help)
16102
16400
  build plan --input <path> Plan a Build inside an Orchestrator Run (prints one JSON object)
16401
+ build children List this Build's children and their interruptions
16402
+ build inspect <run> [cursor] Read a child's state and paged history
16403
+ build guide <run> "<text>" Guide a child or answer its delegated technical question
16404
+ build evidence-copy <image> <name> Copy a screenshot into this worktree's evidence directory
16103
16405
  build tick --input <path> Run one step of a started Build (prints the next action; [--rebase-failed <ID>]...)
16104
16406
  build checks The merge gate's verdict on HEAD's GitHub runs (in a child's worktree)
16105
16407
  build step <n> Report the Run's current step: writes the step run artifact ([--qa none|web|macos|both], --profile, --merge you, --sign-off <sha>, --complete --evidence, --verify)
@@ -16292,7 +16594,7 @@ var cli = meow(
16292
16594
  }
16293
16595
  );
16294
16596
  async function main() {
16295
- const projectDir = path12.resolve(cli.flags.projectDir);
16597
+ const projectDir = path13.resolve(cli.flags.projectDir);
16296
16598
  const [command, ...commandArgs] = cli.input;
16297
16599
  const isRunCommand = command === "run" || command === "exec";
16298
16600
  if (command && !KNOWN_COMMANDS.has(command)) {
@@ -16346,7 +16648,7 @@ Available commands: ${[...KNOWN_COMMANDS].join(", ")}`
16346
16648
  await exitWith(1);
16347
16649
  return;
16348
16650
  }
16349
- const { default: WorkflowInstallWizard } = await import("./WorkflowInstallWizard-FKASDA6N.js");
16651
+ const { default: WorkflowInstallWizard } = await import("./WorkflowInstallWizard-VPBOZJY5.js");
16350
16652
  const { waitUntilExit } = render(
16351
16653
  /* @__PURE__ */ jsx24(
16352
16654
  WorkflowInstallWizard,
@@ -16526,8 +16828,8 @@ Available commands: ${[...KNOWN_COMMANDS].join(", ")}`
16526
16828
  const showSetup = isRunCommand ? false : shouldShowSetup({
16527
16829
  cliInput: cli.input,
16528
16830
  setupComplete: globalConfig.setupComplete,
16529
- globalConfigExists: fs12.existsSync(
16530
- path12.join(os5.homedir(), ".config", "athena", "config.json")
16831
+ globalConfigExists: fs13.existsSync(
16832
+ path13.join(os5.homedir(), ".config", "athena", "config.json")
16531
16833
  )
16532
16834
  });
16533
16835
  let runtimeConfig;