@wjarka/cezarion 0.17.0-dev.5532 → 0.17.0-dev.5548

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,4 +1,4 @@
1
- import { runCheckout, preparePublishCheckout, reclaimCheckoutError, NO_WORKTREE } from './run-checkout.js';
1
+ import { runCheckout, preparePublishCheckout, reclaimCheckoutError } from './run-checkout.js';
2
2
  import { adoptFallbackControl, protectFallbackRun, runArtifactDirectory } from './project-run-files.js';
3
3
  import { deleteSavedWorkflow } from './workflow-files.js';
4
4
  import { projectPaths, fallbackProjectWriteError } from '../project-paths.js';
@@ -3187,11 +3187,10 @@ export function createApp(deps) {
3187
3187
  // "Open in terminal" (spec 003): hand the session off to a real terminal —
3188
3188
  // in the task's worktree when it still exists (spec 006).
3189
3189
  .post('/runs/:id/open-in-cli', async (c) => {
3190
- const { root: repoRoot, store } = c.get('project');
3191
- const id = c.req.param('id');
3192
- const run = store.getRun(id);
3193
- if (!run)
3194
- return c.json({ error: 'not found' }, 404);
3190
+ const project = c.get('project');
3191
+ const checkout = runCheckout(project, c.req.param('id'), 'open', { ignoresEngineOwnership: true, defaultTargetNeedsWorktree: false });
3192
+ if ('status' in checkout)
3193
+ return c.json(checkout.body, checkout.status);
3195
3194
  // Hosted mode: there is no "my machine" to open a terminal on. The UI
3196
3195
  // hides the button when localHandoff is false — this is defense in depth.
3197
3196
  if (!capabilities().localHandoff) {
@@ -3199,15 +3198,15 @@ export function createApp(deps) {
3199
3198
  error: 'local handoff is disabled — this cockpit runs in hosted mode (CEZ_REMOTE); resume the session from a machine that has the checkout',
3200
3199
  }, 409);
3201
3200
  }
3202
- const sessionStep = [...run.steps].reverse().find((s) => s.sessionId);
3201
+ const sessionStep = [...checkout.run.steps].reverse().find((s) => s.sessionId);
3203
3202
  const sessionId = sessionStep?.sessionId;
3204
3203
  if (!sessionId)
3205
3204
  return c.json({ error: 'no agent session to resume' }, 409);
3206
- const backend = sessionStep?.backend ?? run.runner ?? 'claude';
3205
+ const backend = sessionStep?.backend ?? checkout.run.runner ?? 'claude';
3207
3206
  const blocked = await providerActionError([backend]);
3208
3207
  if (blocked)
3209
3208
  return c.json({ error: blocked }, 409);
3210
- const cwd = run.worktreePath && existsSync(run.worktreePath) ? run.worktreePath : repoRoot;
3209
+ const cwd = checkout.directory();
3211
3210
  const refusal = fallbackProjectWriteError(cwd);
3212
3211
  if (refusal)
3213
3212
  return c.json({ error: refusal }, 409);
@@ -3232,11 +3231,10 @@ export function createApp(deps) {
3232
3231
  })
3233
3232
  // Open a run's worktree (or the repo root) in the chosen local app.
3234
3233
  .post('/runs/:id/open-in', jsonZodValidator(openInSchema), async (c) => {
3235
- const { root: repoRoot, store } = c.get('project');
3236
- const id = c.req.param('id');
3237
- const run = store.getRun(id);
3238
- if (!run)
3239
- return c.json({ error: 'not found' }, 404);
3234
+ const project = c.get('project');
3235
+ const checkout = runCheckout(project, c.req.param('id'), 'open', { ignoresEngineOwnership: false, defaultTargetNeedsWorktree: true });
3236
+ if ('status' in checkout)
3237
+ return c.json(checkout.body, checkout.status);
3240
3238
  if (!capabilities().localHandoff) {
3241
3239
  return c.json({
3242
3240
  error: 'local handoff is disabled — this cockpit runs in hosted mode (CEZ_REMOTE)',
@@ -3244,17 +3242,19 @@ export function createApp(deps) {
3244
3242
  }
3245
3243
  // Follows the safeParse convention (#429); the downstream allowlist match is the real
3246
3244
  // injection guard, this just validates the shape.
3247
- const parsedBody = { data: c.req.valid('json') };
3248
- const { target, path: relPath } = parsedBody.data;
3249
- const dir = run.worktreePath && existsSync(run.worktreePath) ? run.worktreePath : repoRoot;
3245
+ const { target, path: relPath } = c.req.valid('json');
3246
+ const dir = checkout.directory();
3250
3247
  if (target === 'default') {
3251
- return openRunDefaultApp(c, run, relPath, openFile, NO_WORKTREE);
3248
+ const worktree = checkout.defaultWorktree();
3249
+ if (typeof worktree !== 'string')
3250
+ return c.json(worktree.body, worktree.status);
3251
+ return openRunDefaultApp(c, worktree, relPath, openFile);
3252
3252
  }
3253
3253
  const cliRunner = agentCliRunner(target);
3254
3254
  if (cliRunner) {
3255
- return openRunCli(c, run, cliRunner, dir, repoRoot, { home: deps.home,
3255
+ return openRunCli(c, checkout.run, cliRunner, dir, project.root, { home: deps.home,
3256
3256
  providerActionError, resumeCommand, handoffEnv, handoffFallbackCommand, openTerminal,
3257
- });
3257
+ }, checkout);
3258
3258
  }
3259
3259
  return openRunApp(c, target, dir, openApp);
3260
3260
  })
@@ -4586,7 +4586,7 @@ export function startServer(deps, port, listener) {
4586
4586
  const visibleProjects = () => workspaceProjects.listVisibleProjects();
4587
4587
  const automationCoordinator = new AutomationCoordinator({ listProjects: () => visibleProjects().then((projects) => prepareProjects(projects, { ownership: deps.ownership, homes: [deps.home], rebrand: deps.legacyCanary })) }); // projects arrive prepared
4588
4588
  const bootProjectId = deps.bootProjectId ?? 'default';
4589
- const bootAutomationStore = automationCoordinator.store(bootProjectId, deps.repoRoot);
4589
+ const bootAutomationStore = () => automationCoordinator.store(bootProjectId, deps.repoRoot); // resolve after preparation
4590
4590
  const taskWebhooks = createTaskWebhooks(deps);
4591
4591
  // #774: the bound origin every agent env carries (`CEZ_COCKPIT_URL`), so `cez automation` calls
4592
4592
  // this cockpit instead of probing ports. Unset until `listening`; a project built after that is