Skip to content

feat: project-local job logs via relative jobsDir (auto git-exclude, migration-safe) - #1

Merged
lloydsk merged 4 commits into
mainfrom
lloydsk/reduce-context-usage
Sep 10, 2026
Merged

feat: project-local job logs via relative jobsDir (auto git-exclude, migration-safe)#1
lloydsk merged 4 commits into
mainfrom
lloydsk/reduce-context-usage

Conversation

@lloydsk

@lloydsk lloydsk commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

What

Opt-in project-local job logs: a relative jobsDir (from any config layer, or PI_BGRUN_DIR) now resolves against the session's project root, so logs land inside the workspace instead of the shared global dir. Set "jobsDir": ".pi-bgrun/jobs" in the project's .pi/pi-bgrun.json → logs at <project>/.pi-bgrun/jobs.

Why

  • Project-sandboxed analysis tools (e.g. context-mode's ctx_execute_file / ctx_index) are confined to the project root — logs in ~/.pi-bgrun/jobs were unreachable by them, forcing agents into uncapped raw reads. Project-local logs restore the intended whole-log analysis path with only derived summaries entering context.
  • Each checkout/worktree gets its own logs — no cross-project clutter in the shared dir.

How it works

  • resolveJobsDirPath (pure, unit-tested): absolute → used as-is; relative + project root → <root>/<jobsDir>; relative + no recognizable root (no .git/.pi at cwd) → global fallback (never scatters logs across arbitrary cwds); unset → global default.
  • Project-local dirs are auto-added once to the enclosing repo's .git/info/exclude — local-only, the tracked .gitignore is never touched, linked worktrees (gitdir: file pointers) are supported, writes retry on transient failure (memoized only on success), and gitdir paths with spaces are handled.
  • bgtail resolves a job's log from the session record's logPath first, so jobs stay readable across mid-session config changes (e.g. switching to project-local right after upgrading).

Migration

  • Absolute jobsDir configs behave byte-for-byte like v0.4.0 — nothing moves, nothing breaks.
  • Old global logs are not migrated (ephemeral, cleanupDays-retained); bgclean all sweeps them once you've switched.
  • Docs: new "Project-local logs" README section + SKILL.md note.

Testing

tsc clean; 43/43 node:test — 7 new: resolver units (absolute/relative/no-root/unset), exclude idempotency, linked worktree, spaces-in-gitdir, retry-after-transient-failure, project-local end-to-end (log lands in project + exclude written), and record-preference bgtail across a config change.

…config-change-safe log lookup)

A relative jobsDir (any config layer or PI_BGRUN_DIR) now resolves against the
session's project root, putting logs inside the workspace — reachable for
project-sandboxed analysis tools (ctx_execute_file/ctx_index) and scoped per
checkout. Absolute paths behave exactly as before (migration-safe). With no
recognizable project root a relative path falls back to the global dir instead
of scattering logs. Project-local dirs are auto-added to .git/info/exclude
(local-only, linked-worktree aware) so logs never pollute git status. bgtail
now prefers the session record's logPath, so jobs stay readable across
mid-session config changes (e.g. switching to project-local after upgrade).
… spaces

ensureGitExcluded now memoizes only on success: a failed attempt (unwritable
exclude file, unparseable .git pointer) is retried on the next bgrun instead of
being permanently skipped. The gitdir pointer regex accepts paths containing
spaces (was \S+, which truncated at the first space).
@lloydsk
lloydsk added this pull request to stack #3 September 10, 2026 16:35
@lloydsk
lloydsk merged commit 14f20a8 into main Sep 10, 2026
1 check passed
@lloydsk
lloydsk deleted the lloydsk/reduce-context-usage branch September 10, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant