zelio-cli 0.1.0-beta.6 → 0.1.0-beta.7

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,6 +1,8 @@
1
1
  import { Hono } from "hono";
2
2
  import { streamSSE } from "hono/streaming";
3
3
  import { randomBytes } from "node:crypto";
4
+ import { execFile } from "node:child_process";
5
+ import { promisify } from "node:util";
4
6
  import { existsSync } from "node:fs";
5
7
  import { readFile } from "node:fs/promises";
6
8
  import { basename, join } from "node:path";
@@ -247,6 +249,7 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
247
249
  const plannerThinkingForTurn = () => plannerThinking ?? db.getBoardSettings().plannerThinking;
248
250
  const testsFirstForcedOff = () => testsFirstEnabled === false || process.env.ZELIO_TESTS_FIRST === "off";
249
251
  const testsFirstForRun = () => !testsFirstForcedOff() && db.getBoardSettings().testsFirstEnabled;
252
+ const plannerChoiceForRun = () => db.getBoardSettings().plannerChoiceEnabled;
250
253
  const prepareOverride = prepare ?? prepareTicket;
251
254
  // One planning run at a time. Two in flight would cost twice and race on
252
255
  // creating the same cards.
@@ -592,7 +595,7 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
592
595
  ...(watchdogTickMs ? { tickMs: watchdogTickMs } : {}),
593
596
  ...(watchdogBackstopMs ? { backstopMs: watchdogBackstopMs } : {}),
594
597
  }
595
- : undefined);
598
+ : undefined, plannerChoiceForRun);
596
599
  /**
597
600
  * The ticket's checkout, with its branch recorded on the row the first time.
598
601
  * Every path that starts work goes through here: a branch that exists on disk
@@ -741,6 +744,7 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
741
744
  verify: normaliseVerify(card.verify),
742
745
  state: "todo",
743
746
  quick: true,
747
+ planner_harness: source.planner_harness,
744
748
  repo: source.repo,
745
749
  });
746
750
  }
@@ -1005,13 +1009,17 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
1005
1009
  listedModels.set(command, { at: Date.now(), models });
1006
1010
  return models;
1007
1011
  };
1008
- const developerBrief = async () => {
1012
+ const developerBrief = async (plannerHarness) => {
1009
1013
  const profile = db.getProfile("developer") ?? profileFor("developer");
1010
- const command = profile.harness.trim() || effectiveHarness();
1014
+ const command = plannerChoiceForRun() && plannerHarness
1015
+ ? plannerHarness
1016
+ : profile.harness.trim() || effectiveHarness();
1017
+ const profileHarness = profile.harness.trim() || effectiveHarness();
1011
1018
  return {
1012
1019
  harness: command,
1013
1020
  models: await harnessModels(command),
1014
- model: profile.model.trim() || (command === effectiveHarness() ? effectiveDeveloperModel() : ""),
1021
+ model: (command === profileHarness ? profile.model.trim() : "") ||
1022
+ (command === effectiveHarness() ? effectiveDeveloperModel() : ""),
1015
1023
  thinking: profile.thinking,
1016
1024
  skills: skillBriefs(readSkills(skills)),
1017
1025
  };
@@ -1022,7 +1030,10 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
1022
1030
  */
1023
1031
  const plannerChoice = (turnHarness, turnModel) => {
1024
1032
  const command = turnHarness || effectiveHarness();
1025
- return { command, model: turnModel || plannerModelFor(command) };
1033
+ return {
1034
+ command,
1035
+ model: turnModel === undefined ? plannerModelFor(command) : turnModel.trim(),
1036
+ };
1026
1037
  };
1027
1038
  const runPlan = plan ??
1028
1039
  (async (messages, brief, draft, board, onStatus, handoff, mode, onStats, attachments = [], images = [], thinking, findings, timeoutMs, linked, turnModel, turnHarness) => {
@@ -1054,7 +1065,9 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
1054
1065
  timeoutMs,
1055
1066
  linkedBoards: linked,
1056
1067
  // The intake drafts no run, so it does not wait on a model list.
1057
- developer: mode === "intake" ? null : await developerBrief(),
1068
+ developer: mode === "intake"
1069
+ ? null
1070
+ : await developerBrief(plannerChoice(turnHarness, turnModel).command),
1058
1071
  });
1059
1072
  });
1060
1073
  // A test that injected the planner explicitly asked for no subprocess. Only
@@ -1276,6 +1289,24 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
1276
1289
  return c.json({ error: "testsFirstEnabled must be a boolean" }, 400);
1277
1290
  patch.testsFirstEnabled = body.testsFirstEnabled;
1278
1291
  }
1292
+ if (body.plannerChoiceEnabled !== undefined) {
1293
+ if (typeof body.plannerChoiceEnabled !== "boolean")
1294
+ return c.json({ error: "plannerChoiceEnabled must be a boolean" }, 400);
1295
+ patch.plannerChoiceEnabled = body.plannerChoiceEnabled;
1296
+ }
1297
+ if (body.plannerHarness !== undefined) {
1298
+ if (typeof body.plannerHarness !== "string")
1299
+ return c.json({ error: "plannerHarness must be a string" }, 400);
1300
+ const invalidHarness = unknownHarness(body.plannerHarness);
1301
+ if (invalidHarness)
1302
+ return c.json({ error: `unknown harness: ${invalidHarness}` }, 400);
1303
+ patch.plannerHarness = body.plannerHarness.trim();
1304
+ }
1305
+ if (body.plannerModel !== undefined) {
1306
+ if (typeof body.plannerModel !== "string" || body.plannerModel.trim().length > 200)
1307
+ return c.json({ error: "plannerModel must be a string up to 200 characters" }, 400);
1308
+ patch.plannerModel = body.plannerModel.trim();
1309
+ }
1279
1310
  if (Object.keys(patch).length === 0)
1280
1311
  return c.json({ error: "nothing to save" }, 400);
1281
1312
  db.setBoardSettings(patch);
@@ -1847,11 +1878,22 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
1847
1878
  return c.json({ ticket: removed });
1848
1879
  });
1849
1880
  /** The home repo and the repos attached to this board. */
1850
- app.get("/api/repos", (c) => c.json({
1851
- home: { name: basename(root), root },
1852
- repos: db.listRepos(),
1853
- folderPicker: repoPicker.available && c.get("principal").kind === "local",
1854
- }));
1881
+ const execFileAsync = promisify(execFile);
1882
+ app.get("/api/repos", async (c) => {
1883
+ let home = null;
1884
+ try {
1885
+ await execFileAsync("git", ["-C", root, "rev-parse", "--show-toplevel"], { timeout: 3000 });
1886
+ home = { name: basename(root), root };
1887
+ }
1888
+ catch {
1889
+ // An ordinary folder is not the board's home repository.
1890
+ }
1891
+ return c.json({
1892
+ home,
1893
+ repos: db.listRepos(),
1894
+ folderPicker: repoPicker.available && c.get("principal").kind === "local",
1895
+ });
1896
+ });
1855
1897
  app.post("/api/repos/pick-folder", async (c) => {
1856
1898
  if (c.get("principal").kind !== "local") {
1857
1899
  return c.json({ error: "choosing a repository is available from the local board only" }, 403);
@@ -2148,6 +2190,21 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
2148
2190
  quick: body.quick === true,
2149
2191
  thinking: asThinking(body.thinking) ?? null,
2150
2192
  model: typeof body.model === "string" ? body.model.trim().slice(0, 200) || null : null,
2193
+ planner_harness: (() => {
2194
+ const source = typeof draft.conversationId === "string"
2195
+ ? db.getConversation(draft.conversationId)
2196
+ : null;
2197
+ if (source?.kind === "task")
2198
+ return source.plannerHarness ?? null;
2199
+ if (body.quick === true) {
2200
+ const requested = typeof draft.plannerHarness === "string" ? draft.plannerHarness : "";
2201
+ if (requested && !unknownHarness(requested))
2202
+ return requested.trim();
2203
+ const saved = db.getBoardSettings().plannerHarness ?? "";
2204
+ return saved && !unknownHarness(saved) ? saved : null;
2205
+ }
2206
+ return null;
2207
+ })(),
2151
2208
  skills: body.skills,
2152
2209
  });
2153
2210
  return c.json({ ticket }, 201);
@@ -2428,11 +2485,15 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
2428
2485
  else {
2429
2486
  conversation = db.appendMessage("user", said, "message", conversation.id);
2430
2487
  }
2488
+ const requestedHarness = options.harness || target.plannerHarness || undefined;
2489
+ const turnChoice = plannerChoice(requestedHarness, options.model !== undefined
2490
+ ? options.model
2491
+ : requestedHarness === target.plannerHarness
2492
+ ? (target.plannerModel ?? undefined)
2493
+ : undefined);
2431
2494
  // The reading starts with the request, from the original description only:
2432
2495
  // a code search here, and scouts for any linked repo the intake names.
2433
- const intakeReading = mode === "intake"
2434
- ? startSearch(conversation.id, text, plannerChoice(options.harness, options.model))
2435
- : undefined;
2496
+ const intakeReading = mode === "intake" ? startSearch(conversation.id, text, turnChoice) : undefined;
2436
2497
  // With no linked repo there is nothing for the intake to decide that the
2437
2498
  // draft cannot: the search has already read, so the first pass is the draft.
2438
2499
  const merged = mode === "intake" && candidates.length === 0;
@@ -2445,18 +2506,24 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
2445
2506
  indexMs = Date.now() - indexStarted;
2446
2507
  const brief = index ? renderBrief(index) : "";
2447
2508
  // One planner run. Its stats are its own, so the row it writes is too.
2448
- const planOnce = (passMode, findings) => {
2509
+ const planOnce = async (passMode, findings) => {
2449
2510
  stats = EMPTY_TURN_STATS;
2450
2511
  // The intake decides, it does not read at length: its level is capped in
2451
2512
  // this one place so the injected test planner and the real one agree.
2452
2513
  const level = options.thinking ?? plannerThinkingForTurn();
2453
2514
  const passThinking = passMode === "intake" ? capThinking(level, INTAKE_THINKING_CAP) : level;
2454
- return runPlan(conversation.messages, brief, draft, board, publish, handoff, passMode, (measured) => {
2515
+ const planned = await runPlan(conversation.messages, brief, draft, board, publish, handoff, passMode, (measured) => {
2455
2516
  stats = measured;
2456
2517
  }, attachments, images, passThinking, findings,
2457
2518
  // What is left of the request, not a fresh clock per pass: the intake,
2458
2519
  // the scouts and the draft share one deadline, and the planner is told it.
2459
- Math.max(MIN_PASS_MS, PLAN_TURN_DEADLINE_MS - (Date.now() - startedAt)), repoBriefs, options.model, options.harness);
2520
+ Math.max(MIN_PASS_MS, PLAN_TURN_DEADLINE_MS - (Date.now() - startedAt)), repoBriefs, turnChoice.model, turnChoice.command);
2521
+ conversation = db.setConversationPlannerChoice(conversation.id, turnChoice.command, turnChoice.model || null);
2522
+ // The real orchestrator already filters card models against this pass's
2523
+ // developer brief. Do not make intake or injected planners discover a
2524
+ // model list just to repeat that check; ticket runs and plan edits each
2525
+ // validate against their authoritative harness before use.
2526
+ return planned;
2460
2527
  };
2461
2528
  // Saves what the planner decided. Research is a planner input, not part of
2462
2529
  // the plan the dialog reads, so it is not stored.
@@ -2514,7 +2581,7 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
2514
2581
  const named = [...new Set(drafted.boards ?? [])]
2515
2582
  .filter((name) => onBoard.has(name))
2516
2583
  .slice(0, MAX_REPO_SCOUTS);
2517
- extendResearch(conversation.id, named.map((name) => linkedBoardQuestion(name, text)), plannerChoice(options.harness, options.model));
2584
+ extendResearch(conversation.id, named.map((name) => linkedBoardQuestion(name, text)), turnChoice);
2518
2585
  }
2519
2586
  let outcome;
2520
2587
  if (pass !== "intake") {
@@ -2590,7 +2657,7 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
2590
2657
  conversationId: asConversationId(body.conversationId),
2591
2658
  attachments,
2592
2659
  thinking: thinking ?? undefined,
2593
- model: typeof body.model === "string" ? body.model.trim() || undefined : undefined,
2660
+ model: typeof body.model === "string" ? body.model.trim() : undefined,
2594
2661
  harness: typeof body.harness === "string" ? body.harness.trim() || undefined : undefined,
2595
2662
  }),
2596
2663
  });
@@ -2655,7 +2722,7 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
2655
2722
  conversationId: session.id,
2656
2723
  attachments,
2657
2724
  thinking: thinking ?? undefined,
2658
- model: typeof body.model === "string" ? body.model.trim() || undefined : undefined,
2725
+ model: typeof body.model === "string" ? body.model.trim() : undefined,
2659
2726
  harness: typeof body.harness === "string" ? body.harness.trim() || undefined : undefined,
2660
2727
  }),
2661
2728
  });
@@ -2695,9 +2762,10 @@ export function createApp({ db, token, port, webRoot, repoRoot, accountAvatarUrl
2695
2762
  }
2696
2763
  // A model the developer harness does not list is cleared, as a planner turn
2697
2764
  // clears it, so the card shows the default instead of a model it cannot run.
2698
- const plan = keepListedModels({ ...conversation.plan, cards }, await developerBrief());
2765
+ const plannerHarness = conversation.plannerHarness ?? undefined;
2766
+ const filteredPlan = keepListedModels({ ...conversation.plan, cards }, await developerBrief(plannerHarness));
2699
2767
  return c.json({
2700
- conversation: db.setPlan(plan, conversation.id),
2768
+ conversation: db.setPlan(filteredPlan, conversation.id),
2701
2769
  });
2702
2770
  });
2703
2771
  /** "New chat": a new row, so the old transcript can still be read later. */