Skip to content
/ Lonca
Documentation contents

Working with tasks

Worktrees and setup

A git worktree, a port and the local files each task needs, set up by a resumable pipeline.

Every task gets its own git worktree: a separate working copy of the repository on the task's own branch, next to the main checkout, with the local files it needs and its dependencies installed. Several tasks of one repository can then be worked on at once without touching each other or your main checkout. Setup is the first stage of a handed-off task: a pipeline of steps, and a step that fails can be retried on its own.

Where worktrees live

<repo parent>/worktrees/<repo name>/<branch name>

~/Projects/sales-api                                        your main checkout
~/Projects/worktrees/sales-api/feature/SALES-123-add-booking-shell
  • A worktree is never opened inside the main checkout.
  • Lonca writes a small .lonca_worktree file at the root of each worktree it opens, and keeps it out of git through the repository's own exclude list, so no tracked file changes.
  • Lonca lists only the worktrees that carry this file. One you made yourself with git worktree add has none, and Lonca leaves it alone.

Setting up a task's worktree

Creating a task does not set up its worktree: handing it off does. Setup is the first stage of the Flow tab's rail, and there is no separate way to set up a worktree by hand. Until then the task's header says No worktree yet.

Click Setup on the rail to unfold its steps. In order:

StepDoes
Reading the Jira issue (Reading the story for a local story)Writes the issue’s context folder: the snapshot, attachments, Confluence pages. See Task context.
Deriving the branch nameFrom the repository’s branch pattern and the issue.
Creating the worktreeBrings the base up to date, then opens the worktree on a new branch from it.
Copying local filesCopies the git-ignored local files the worktree needs, such as .env.
Installing dependenciesRuns the repository’s package manager.
Writing the agent briefWrites the brief that points agents at the context, and keeps it out of git.
Linking to the taskRecords the worktree and branch on the task.
Writing the acceptance criteriaWrites ac.md from the issue. Last on purpose: criteria that cannot be read do not cost the worktree.

When all are done, the task's AC, Documents and Token tabs open, the pipeline goes on to Plan, and the list stays under the Setup fold of the Flow tab with its count (8/8 ✓).

Branch names

config.yaml
workspaces:
  - id: sales
    label: Sales
    repos:
      - path: ~/Projects/sales-api
        base: origin/develop                           # default: origin/main
        branch_pattern: feature/{{issueKey}}-{{slug}}  # the default
  • {{issueKey}} is the issue key; it is left out for a task with no issue.
  • {{slug}} is the issue title in lowercase, at most 48 characters, with Turkish letters transliterated (Ödeme akışı becomes odeme-akisi). A title that leaves nothing usable gives task.
  • A revision of an issue gets the same name with -rev1, -rev2… at the end, counted across both local and remote branches.
  • Once a task's branch name is decided it is kept: a setup run again later uses the same name.

When the branch already exists on the remote

Before the worktree is made, Lonca checks the remote. If a branch of that name is already there, setup stops and asks you on the Flow tab (The branch exists on the remote), and the task waits under Needs you. Only you answer it, never the task lead. The question says what each choice costs:

ChoiceWhat happens
Open a new revisionA new branch with the next free -rev suffix, named in the question. The remote branch is left as it is.
Use the remote branchThe worktree takes the remote branch. Your local copy of it is overwritten; the question says how many local commits would be lost, or that the number is unknown.

If the remote cannot be read (no network, no VPN), setup goes on from the local state and the task's notice says so: overwriting is never chosen when what it would overwrite is unknown. Try again on a failed step asks the same in a dialog, This branch already exists on the remote, which offers only Continue based on local state when the remote cannot be read.

The base branch

Lonca works from the local copy of the base and keeps it current itself. For a remote base such as origin/develop, that is your local develop; for a local base such as main, the branch it tracks. Lonca fetches only the base branch, from its remote. One fetch serves every task of the repository and is not repeated for 5 minutes; a fetch that failed is not tried again for a minute.

The local branch is moved by fast-forward only. Lonca leaves it exactly as it is when it has commits the remote does not have, when it is checked out with uncommitted changes, or when it tracks another branch. The task then starts from the remote ref (origin/develop), and the task's record and lonca.log say why. A local base is always used as written.

With no network, setup goes on from the local branch as it is. A stacked task starts on its dependency's branch, which is never refreshed. The pull request still targets the base's branch (develop).

Local files

A fresh worktree has only what git tracks. The files your app needs to run but git ignores, such as .env, are copied from the main checkout into the worktree. They are copies, not links: changing the worktree's .env leaves the main checkout's alone.

Which files is set by a .worktreeinclude file at the root of the main checkout, one pattern per line. Without one, Lonca copies:

.worktreeinclude
# the default when the file is missing
.env
.env.local
.env.*.local
  • Only files git ignores are copied. A tracked file is already in the worktree, and a file already there is not overwritten.
  • A pattern without a / matches a file of that name in any folder; one with a / matches the path from the root.
  • The only wildcard is *, which does not cross a /. Lines starting with # or ! are skipped.
  • node_modules, .git, .nx, dist, coverage, .venv and out are not searched, and links are never followed.
  • File contents are never logged; only their paths are.

The file's name is a setting: setup.include_file, default .worktreeinclude. It is read from your config only, never from anything a repository supplies.

A repository whose app keeps its dotenv files below the root (a monorepo's apps/web/.env.local) names them in env_files, and each is copied into every task's worktree beside what the include file names. Values you enter in Lonca, project and task variables, are never written into the worktree: each process gets them as its environment (see Variables and secrets).

Dependencies

A worktree with a package.json gets its dependencies installed by the package manager its lock file names: pnpm-lock.yaml → pnpm, yarn.lock → Yarn, bun.lockb → Bun, package-lock.json or none → npm. A repository without a package.json skips the step.

  • The install runs with CI=1 set. npm in a repository that keeps no lock file runs with --no-package-lock, so no stray package-lock.json is left for an agent to commit.
  • An install that runs past 20 minutes is stopped and the step fails.
  • The install gets the task's variables as its environment. A failed install offers Set a variable beside Try again, for a value it was missing.
  • The step's row shows a short message such as pnpm install failed. The installer's own output, which can hold registry addresses and tokens, never reaches the screen.

When a step fails

  • The failed step turns red with its message and the later steps do not run. Setup becomes the rail's waiting stage and opens by itself, the pipeline asks Setup did not finish., and the task's row moves to Needs you with a red × in its stage ring.
  • Try again on the step resumes setup: steps already done are not run again. Under consultant or autopilot a setup that could not finish is also tried again by itself.
  • A step that ran but could not do all its work (Confluence pages that timed out, for example) shows its note in orange, and the Setup fold counts it (8/8 ✓ · 1 note). It counts as not finished and runs again on the next attempt; the note clears itself once the cause is fixed.
  • When Background AI could not run for Writing the acceptance criteria (it timed out, or its command is missing), the note says why and the row has its own Try again, which writes the criteria alone, even once the pipeline is past setup. While Lonca drives the task it answers “Lonca is driving this task; pause it first.”
  • If Lonca closes in the middle of setup, the step that was running is marked left unfinished because the application closed when Lonca starts again, and you can try again.

Set up from scratch

For what a retry cannot fix (a step a crash left running, or a handed-off task whose worktree went missing during setup), the Setup stage offers Set up from scratch, and the notification points there. Its dialog, Set up the worktree from scratch, says what goes and what stays:

  • the setup steps are reset, and every step runs again from the start;
  • a half-finished worktree directory for the task's branch, if there is one, is removed;
  • the branch and its commits stay in git, and setup reuses the same branch.

Confirm with Reset and set up. A setup that is really running is never reset under it. A worktree that goes missing once the pipeline is past setup is not reset in place: archive the task, unarchive it and hand it off fresh.

The worktree in the task's header

Once a worktree is set up, the task's header shows the branch as git has it now (switch branches inside the worktree and the header follows), its git status (commits ahead, commits behind, changed files) and the worktree's path; The directory is not on disk. when it has gone. The task's menu (the header's ⋯, or the row's ⋯ or right-click) opens it: Open with → VS Code or Terminal, and Show in Finder for its folder. The pull request is on the Flow tab (see Pull requests, CI and comments).

Running the app

Run App, in the task's header, starts the repository's run command in it, in a tmux session of its own. While the app runs, the header shows its port (● App :3001), the row's card says App running with the port, and the button turns into Stop. Without a run command the button is off and its tooltip says where to add one: Settings → Workspaces.

tmux runs the line with your shell, zsh on macOS. A line that starts several processes and stops them all with a trap must reset its traps first. Plain trap 'kill 0' EXIT INT TERM catches the signal its own kill 0 sends, so zsh runs it again for ever and the shell grows until the Mac runs out of memory. The Configurator never writes such a line, and the update to 12.1.0 has it fix one your file has:

config.yaml
run: trap 'trap - EXIT INT TERM; kill 0' EXIT INT TERM; pnpm api & pnpm web & wait

Lonca also closes a run session whose app has ended while its shell stayed: it looks every 30 seconds, and closes the session when it sees it so twice in a row.

Ports

Several worktrees of one repository cannot all run their app on port 3000. run_ports gives the repository a pool of ports per environment variable; the pools line up slot by slot, so they must be the same size, and no port may appear twice (1024–65535, at most 100 per pool):

config.yaml
workspaces:
  - id: sales
    label: Sales
    repos:
      - path: ~/Projects/sales-mfe
        run: pnpm dev
        run_ports:
          PORT: 3000-3004                           # a range
          API_PORT: [4000, 4001, 4002, 4003, 4004]  # a list; or { start: 4000, count: 5 }
  • Run App takes a free slot, the worktree's own one when it is free so its port stays the same, and starts the app with that slot's ports in its environment (PORT=3001, …). The first variable is the app's own address.
  • The app must read its port from that variable. For Vite: server: { port: Number(process.env.PORT), strictPort: true }.
  • This is the only place Lonca takes ports from; it never takes a port from the worktree's .env.
  • A slot is taken while any of its ports is listened on, by anything, or belongs to another of the repository's apps that is up. With every slot taken, the app waits in the repository's line: the button reads Queued · 2nd, a click leaves the line, and the app starts by itself when a slot frees. The pipeline's E2E step waits in the same line.
  • The slot is recorded on the app's tmux session, so a restarted Lonca still knows it.
  • An app that hard-codes its port uses e2e.fixed_port instead: a pool of one, so the repository's apps run one at a time.

Without run_ports, Lonca knows no port for the app, and finds a conflict from a process listening from a worktree. When something holds the port this worktree's app needs, The app is already running names who has it (another task's app, or an app outside Lonca) and its process, and Stop and start stops it and starts this one.

After a restart

When Lonca starts, it compares its records with git:

  • A worktree in git with no record is linked back to the task whose branch it carries when it has .lonca_worktree, or listed as a task with no key when no single task matches; one without the file is left alone.
  • A worktree in the record that is no longer in git loses its link, but the task is kept: a directory you deleted does not erase the task's history.
  • Apps and stage agents in tmux kept running while Lonca was closed, and are where they were.