Prevent governed work from starting in a stale, dirty or incorrectly scoped
workspace. Add one dependency-free runtime service that observes an existing
local Git worktree, resolves the active ticket through the existing governance
checker and produces a deterministic, read-only t2c.workspace-preflight/v1
report.
The motivating incident occurred immediately after a clean-main audit: a
parallel generator modified TODO.md, project/, project2.sh and several
untracked analysis files while another session was preparing a ticket. The
preflight must expose that state before an agent assumes it owns a clean
workspace. It must preserve all user data and must not attempt an automatic
repair.
The runtime service accepts:
refs/remotes/origin/main;It returns a bounded report containing:
HEAD and baseline SHA;GOV-* diagnostics without reimplementing
allowedPaths, forbidden-path or workstream matching in TypeScript;The service may run only local read-only Git commands and the repository’s
existing .governance/governance_check.py --format json. It fails closed when
the baseline, checker, JSON report or ticket binding is unavailable.
The first version is limited to:
WS-ROOT-001: root is not a valid Git worktree;WS-BASE-002: baseline ref is missing, unsafe or unresolved;WS-BRANCH-003: current branch differs from the expected target;WS-SYNC-004: current branch is ahead/behind or diverged from baseline;WS-DIRTY-005: tracked or untracked workspace changes exist;WS-GOVERNANCE-006: the managed checker failed or reported diagnostics;WS-TICKET-007: no unique active ticket is resolved for implementation.Safe actions are non-executable enum values such as PRESERVE_CHANGES,
USE_ISOLATED_WORKTREE, FAST_FORWARD_AFTER_PRESERVE and
RESOLVE_TICKET_SCOPE. No shell command, stash mutation or automatic checkout
is returned or executed.
runtime.S; maximum two implementation files and one component.src/services/workspace-preflight.ts and
test/git-workspace-preflight.test.ts.main@db368c020876ccac537538c9e8cac03c9ae2f02f.project.sh, Makefile, workflow,
dependency manifest, automatic fix, network access or remote mutation.PASS; a dirty, stale, detached or
wrongly scoped fixture yields stable diagnostics and safe-action enums.The user approved this exact contract and replacement base
db368c020876ccac537538c9e8cac03c9ae2f02f by replying tak after plan PR #47
merged. The ticket entered IN_PROGRESS / EDIT and the approval was recorded
before either implementation file was created. It has since moved to
DONE without widening that approval. Chat approval authorized the bounded
interactive edit; merge authority came from protected exact-head Koru,
Validator App and required CI evidence.
inspectWorkspace() with bounded local Git reads,
strict full-ref/root validation, porcelain-v2 parsing, canonical fingerprint
and the seven stable WS-* diagnostic families.activeTicket.make governance and git diff --check pass with zero findings.runGovernance at CC=16. It
is now a small orchestrator over checker discovery, argument construction,
process execution, JSON validation and ticket reading. Command-start/output
failures retain their owning WS-* code and expose only stderr/stdout size
plus SHA-256, never raw content.The built service inspected its own in-progress isolated worktree against
refs/remotes/origin/main. It correctly returned BLOCKED because two
implementation files were uncommitted, retained governance passed, resolved
exactly ticket-040, reported one local plan/approval commit and emitted
fingerprint dade38bc751e87da9edcb044bc8f0c0d97f33b5c02c27edf0cafdf937b351d62.
This is the intended pre-edit safety behavior; no Git state changed.
567424b58234907eb1d7faedf399a700f808da19
after two earlier exact-head reviews correctly blocked CC=16.ticket-040 and correlation ID
t2c-ticket-040-workspace-preflight-20260805-final using
openrouter/z-ai/glm-5.2. Its semantic verdict was explicitly advisory and
not the trust root.behindBy, the head-right count as aheadBy, and all commands use
spawn argument arrays rather than a shell. Its remaining @{ concern does
not pass the branch regex; stale test counts in the PR body were corrected
without changing the reviewed commit.567424b as
main@008bee503b45a78d463d8802b61deb74d23c1124 without an administrative
bypass.