@ordewell/core 0.13.0 → 0.13.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/dist/index.js CHANGED
@@ -38171,6 +38171,18 @@ function renderCarriedOver(from, work) {
38171
38171
  const body = work?.outcome === "fallback" ? `${moved} The work its previous attempt on ${from} left could not be applied on top of the integration tip, so your working tree starts fresh at the integration tip. ${keptWorkLines(work.preserved, "the previous attempt's work")} It may be unfinished.` : `${moved} The files in your working tree come from a previous attempt on ${from} and may be unfinished: check what is already there before building on it. That attempt's session is not continued.`;
38172
38172
  return ["## Work carried over", "", body].join("\n");
38173
38173
  }
38174
+ function renderLoopVerdict(loop, round) {
38175
+ const ahead = "A `failed` round with rounds left runs the fix, then this check again; a `failed` last round ends the loop, and the tasks after it wait for the user.";
38176
+ const rounds = round === void 0 ? `It runs at most ${loop.maxRounds} rounds. ${ahead}` : round >= loop.maxRounds ? `This is round ${round} of ${loop.maxRounds}, the last: a \`failed\` now ends the loop, and the tasks after it wait for the user.` : `This is round ${round} of ${loop.maxRounds}. ${ahead}`;
38177
+ return [
38178
+ "## You are this loop's check",
38179
+ "",
38180
+ "Ordewell reads your `task_complete` status as this check's verdict. If you confirm any problem, call `task_complete` with status `failed` and put each confirmed problem in `findings`: that starts the fix. Call it with status `done` only when you confirm none; finishing the check is not a pass. Use `blocked` only when you could not do the check: it starts no fix.",
38181
+ "",
38182
+ rounds
38183
+ ].join("\n");
38184
+ }
38185
+ var LOOP_VERDICT_REMINDER = "You are this loop's check: your `task_complete` status is its verdict, `failed` when you confirm any problem and `done` only when you confirm none.";
38174
38186
  var CHECKPOINT_INSTRUCTION = [
38175
38187
  "## Human-in-the-loop checkpoints",
38176
38188
  "",
@@ -38202,6 +38214,7 @@ function composeAugmentedPrompt(task2, allTasks, opts) {
38202
38214
  if (opts?.skills?.length) blocks.push(renderTaskSkills(opts.skills));
38203
38215
  if (opts?.readOnly) blocks.push(READ_ONLY_PATCH_NOTE, READ_ONLY_WEB_NOTE);
38204
38216
  if (isHitlTask(task2)) blocks.push(CHECKPOINT_INSTRUCTION);
38217
+ if (task2.type === "ai" && task2.loop) blocks.push(renderLoopVerdict(task2.loop, opts?.loop?.round));
38205
38218
  if (blocks.length === 0) return basePrompt;
38206
38219
  return `${blocks.join("\n\n")}
38207
38220
 
@@ -38211,6 +38224,9 @@ function composeContinuationPrompt(task2, message, opts = {}) {
38211
38224
  const reminder = [
38212
38225
  opts.ops ? "(Ordewell) You are continuing this task in the same session, in the same checkout. What your earlier attempt did outside the repository was not undone: check what already exists before acting again." : "(Ordewell) You are continuing this task in the same session. Check the working tree before relying on the files remembered from your earlier attempt."
38213
38226
  ];
38227
+ if (task2.type === "ai" && task2.loop) {
38228
+ reminder.push(LOOP_VERDICT_REMINDER);
38229
+ }
38214
38230
  if (isHitlTask(task2)) {
38215
38231
  reminder.push("If you reach a decision that needs human judgment, call the `checkpoint` tool: its result is `continue` or `rejected: <why>`.");
38216
38232
  }
@@ -40147,11 +40163,11 @@ function attemptPrompt(kind, src) {
40147
40163
  const { task: task2, plan, planMapEnabled } = src;
40148
40164
  const between = betweenRounds(task2);
40149
40165
  const round = loopRoundOf(task2) + (between ? 1 : 0);
40150
- const loop = task2.type === "ai" && task2.loop && round > 1 && takesSkills(kind) ? {
40166
+ const loop = task2.type === "ai" && task2.loop && takesSkills(kind) ? round > 1 ? {
40151
40167
  round,
40152
40168
  previousHandoff: src.previousHandoff(task2.id),
40153
40169
  previousReport: between ? task2.outputSummary?.report : src.previousRound?.round === round - 1 ? src.previousRound.report : void 0
40154
- } : void 0;
40170
+ } : { round } : void 0;
40155
40171
  switch (kind.kind) {
40156
40172
  case "continuation": {
40157
40173
  const where = kind.work === "readOnly" ? READ_ONLY_CONTINUED_NOTE : continuedWorkNote(src.previousWork);
@@ -40160,7 +40176,7 @@ function attemptPrompt(kind, src) {
40160
40176
  ${where}`, { ops: kind.work === "ops" });
40161
40177
  }
40162
40178
  case "repair":
40163
- return composeAugmentedPrompt({ ...task2, prompt: src.repairPrompt(task2) }, plan, { planMapEnabled });
40179
+ return composeAugmentedPrompt({ ...task2, prompt: src.repairPrompt(task2), loop: void 0 }, plan, { planMapEnabled });
40164
40180
  case "ops":
40165
40181
  return composeAugmentedPrompt(task2, plan, { planMapEnabled, skills: src.skills, previousAttempt: src.previousAttempt(task2.id), loop });
40166
40182
  case "change":
@@ -56112,9 +56128,7 @@ var CGROUP_V1 = "Boot the host with cgroup v2, by adding `systemd.unified_cgroup
56112
56128
  async function inspectEngine({ cli, platform = process.platform }) {
56113
56129
  const install = INSTALL[platform];
56114
56130
  const start = START[platform];
56115
- if (install === void 0 || start === void 0) {
56116
- return refused6("platform-unsupported", `Containers have only been proven on Linux and macOS, and this host is ${platform}.`, "Run Ordewell on Linux, or on a Mac with Docker Desktop or Colima.");
56117
- }
56131
+ if (install === void 0 || start === void 0) return { problems: platformProblems(platform) };
56118
56132
  const ask = (args) => cli.call(args, { timeoutMs: ASK_MS });
56119
56133
  const context = await ask(["context", "inspect", "--format", "{{.Endpoints.docker.Host}}"]);
56120
56134
  if (context.code === -1) return refused6("docker-missing", "The docker command was not found.", install);
@@ -56138,6 +56152,13 @@ async function inspectEngine({ cli, platform = process.platform }) {
56138
56152
  if (cgroup === "1") return refused6("cgroup-v1", "This engine uses cgroup v1, and the memory limit can only be proven on cgroup v2.", CGROUP_V1);
56139
56153
  return { problems: [], engine: { version: version.stdout.trim(), endpoint, memoryBytes } };
56140
56154
  }
56155
+ function platformProblems(platform) {
56156
+ if (INSTALL[platform] !== void 0 && START[platform] !== void 0) return [];
56157
+ return [problem("platform-unsupported", `Containers have only been proven on Linux and macOS, and this host is ${platform}.`, "Run Ordewell on Linux, or on a Mac with Docker Desktop or Colima.")];
56158
+ }
56159
+ function standingProblems(raw, platform = process.platform) {
56160
+ return [...platformProblems(platform), ...readSetting(raw).problems];
56161
+ }
56141
56162
  var CONTAINER_ASSUMPTIONS = [
56142
56163
  "The engine behind a unix:// socket is on this machine: a socket forwarded from elsewhere looks the same.",
56143
56164
  "Containers on an engine share one kernel, this host's on Linux and the VM's on a Mac. kernel.separate means separate from this host, never from another task: a kernel flaw reaches every task on the engine.",
@@ -57106,6 +57127,8 @@ var DockerExecutionBackend = class {
57106
57127
  const agent = request.role === "task";
57107
57128
  const runner = agent && containerRunner(request.runner) || null;
57108
57129
  if (agent && !runner) throw new Error(`This session runs tasks in containers, and ${request.runner ?? "this runner"} has not been proven in one: assign the task to ${CONTAINER_RUNNER_IDS.join(", ")}.`);
57130
+ const standing = this.standing();
57131
+ if (standing.length > 0) throw new Error(cannotStart(describeProblems(standing)));
57109
57132
  if (spec.task) await this.collect(spec.task.id).catch((err) => {
57110
57133
  if (err instanceof KeptWorkError) throw err;
57111
57134
  });
@@ -57140,11 +57163,14 @@ var DockerExecutionBackend = class {
57140
57163
  async preflight(runner, model) {
57141
57164
  const setupCommand = this.options.setupCommand?.();
57142
57165
  const { problems, settings } = await inspectReadiness(this.options.settings, { cli: this.cli, broker: this.broker, ...this.options.platform ? { platform: this.options.platform } : {}, agent: runner !== null, ...runner ? { runner } : {}, ...setupCommand ? { setupCommand } : {} });
57143
- if (!settings) throw new Error(`This session runs tasks in containers, and this task cannot start in one. ${describeProblems(problems)}`);
57166
+ if (!settings) throw new Error(cannotStart(describeProblems(problems)));
57144
57167
  const refusal4 = runner && settings.login.kind === "broker" ? brokerRefusal(runner, model) : null;
57145
- if (refusal4) throw new Error(`This session runs tasks in containers, and this task cannot start in one. ${refusal4}`);
57168
+ if (refusal4) throw new Error(cannotStart(refusal4));
57146
57169
  return settings;
57147
57170
  }
57171
+ standing() {
57172
+ return standingProblems(this.options.settings, this.options.platform);
57173
+ }
57148
57174
  /**
57149
57175
  * What a container is seeded from. A script with no worktree of its own runs
57150
57176
  * where a script always does, at the workspace root (ADR-0035), so it gets what
@@ -57567,7 +57593,7 @@ var DockerExecutionBackend = class {
57567
57593
  if (how.keep && !box.landsNothing) await this.bringBack(box).catch((err) => this.options.tell("warn", errorText3(err)));
57568
57594
  if (this.boxes.get(taskId) === box) this.boxes.delete(taskId);
57569
57595
  }
57570
- if (!how.keep) {
57596
+ if (!how.keep && this.standing().length === 0) {
57571
57597
  await this.dropVolume(`ordewell-task-${this.taskKey(taskId)}`);
57572
57598
  await this.dropVolume(this.heldVolume(taskId));
57573
57599
  }
@@ -57596,6 +57622,7 @@ var DockerExecutionBackend = class {
57596
57622
  await reclaimTree(this.tree(), this.cli, "refused" in settings ? null : settings, (text6) => this.options.tell("warn", text6));
57597
57623
  }
57598
57624
  };
57625
+ var cannotStart = (why) => `This session runs tasks in containers, and this task cannot start in one. ${why}`;
57599
57626
  function heldBack(taskId, why) {
57600
57627
  return `The work of task ${taskId} stays in its container's volume: ${why.replace(/\.$/, "")}. Nothing starts over it until you retry the task, which gives that work up.`;
57601
57628
  }