@oisincoveney/pipeline 3.19.3 → 3.19.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.
@@ -1,3 +1,4 @@
1
+ import { uniqueGeneratedId } from "../strings.js";
1
2
  import { dependentsByNeed, flattenNodes, hasReachableDependent } from "./graph.js";
2
3
  import { workflowSchema } from "../config/schemas.js";
3
4
  import { validatePipelineConfig } from "../config/validate.js";
@@ -29,6 +30,7 @@ const ID_RE = /^[a-z][a-z0-9-]*$/;
29
30
  const SCHEDULE_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
30
31
  const MARKDOWN_YAML_FENCE_RE = /```(?:ya?ml)?\s*\r?\n([\s\S]*?)\r?\n```/i;
31
32
  const SCHEDULE_PLANNER_REPAIR_ATTEMPTS = 1;
33
+ const PREFERRED_IMPLEMENTATION_PROFILE_IDS = ["moka-code-writer"];
32
34
  const SCHEDULE_BUILTINS = [
33
35
  "drain-merge",
34
36
  "duplication",
@@ -196,7 +198,13 @@ function scheduleArtifactPath(worktreePath, scheduleId) {
196
198
  }
197
199
  async function planScheduleArtifact(baseline, plannerProfile, options, planningContext) {
198
200
  const requiredPlannerProfile = requireSchedulePlannerProfile(plannerProfile, options.entrypointId);
199
- const source = requireSchedulePlannerSource(await runSchedulePlanner(requiredPlannerProfile, plannerPrompt(options.entrypointId, options.task, baseline, options.config, planningContext), options));
201
+ const ticketPlanFallback = ticketPlanScheduleArtifact(baseline, options.config, planningContext, options.phaseContext);
202
+ const sourceResult = await runSchedulePlannerSource(requiredPlannerProfile, plannerPrompt(options.entrypointId, options.task, baseline, options.config, planningContext), options);
203
+ if (!sourceResult.ok) {
204
+ if (ticketPlanFallback) return ticketPlanFallback;
205
+ throw sourceResult.error;
206
+ }
207
+ const source = requireSchedulePlannerSource(sourceResult.source);
200
208
  const initial = acceptedGeneratedSchedule(parseGeneratedSchedule(source, "planner output"));
201
209
  if (initial.ok) return initial.artifact;
202
210
  return scheduleArtifactAfterRepair(await repairInvalidScheduleArtifact({
@@ -205,7 +213,53 @@ async function planScheduleArtifact(baseline, plannerProfile, options, planningC
205
213
  initialSource: source,
206
214
  options,
207
215
  plannerProfile: requiredPlannerProfile
208
- }), baseline, initial.error, source);
216
+ }), ticketPlanFallback ?? baseline, initial.error, source);
217
+ }
218
+ async function runSchedulePlannerSource(plannerProfile, prompt, options) {
219
+ try {
220
+ return {
221
+ ok: true,
222
+ source: await runSchedulePlanner(plannerProfile, prompt, options)
223
+ };
224
+ } catch (err) {
225
+ if (err instanceof ScheduleArtifactError) return {
226
+ error: err,
227
+ ok: false
228
+ };
229
+ throw err;
230
+ }
231
+ }
232
+ function ticketPlanScheduleArtifact(baseline, config, planningContext, phaseContext) {
233
+ if (!phaseContext?.ticketPlan || planningContext.workUnits.length === 0) return;
234
+ const implementationProfile = profileIdForSchedulingRole(config, "implementation", PREFERRED_IMPLEMENTATION_PROFILE_IDS);
235
+ if (!implementationProfile) throw new ScheduleArtifactError("Cannot generate TicketPlan schedule: no profile declares scheduling role 'implementation'");
236
+ const usedIds = /* @__PURE__ */ new Set();
237
+ const nodeIdsByUnit = new Map(planningContext.workUnits.map((unit) => [unit.id, uniqueGeneratedId(`${unit.id}-implement`, usedIds, "work-implement")]));
238
+ const nodes = planningContext.workUnits.map((unit) => {
239
+ const needs = (unit.dependencies ?? []).flatMap((id) => {
240
+ const nodeId = nodeIdsByUnit.get(id);
241
+ return nodeId ? [nodeId] : [];
242
+ });
243
+ return {
244
+ id: nodeIdsByUnit.get(unit.id) ?? "work-implement",
245
+ kind: "agent",
246
+ ...needs.length > 0 ? { needs } : {},
247
+ profile: implementationProfile,
248
+ task_context: { id: unit.id }
249
+ };
250
+ });
251
+ return {
252
+ ...baseline,
253
+ root_workflow: "root",
254
+ workflows: { root: {
255
+ description: "Generated deterministic schedule from TicketPlan.",
256
+ nodes
257
+ } }
258
+ };
259
+ }
260
+ function profileIdForSchedulingRole(config, role, preferredIds) {
261
+ const matchingIds = Object.entries(config.profiles).filter(([, profile]) => profile.scheduling_roles?.includes(role)).map(([id]) => id);
262
+ return preferredIds.find((id) => matchingIds.includes(id)) ?? matchingIds.sort()[0];
209
263
  }
210
264
  function requireSchedulePlannerProfile(plannerProfile, entrypointId) {
211
265
  if (plannerProfile) return plannerProfile;
package/package.json CHANGED
@@ -132,7 +132,7 @@
132
132
  "prepack": "nub run build:cli"
133
133
  },
134
134
  "type": "module",
135
- "version": "3.19.3",
135
+ "version": "3.19.4",
136
136
  "description": "Config-driven multi-agent pipeline runner for repository work",
137
137
  "main": "./dist/index.js",
138
138
  "types": "./dist/index.d.ts",