fix(core/config, approvals): normalize cwd to git repo root; warn on missing approval

- Normalize session cwd to Git repo root when launched from a subdirectory so file edits and execs resolve from project root. Prevents bad paths like <repo>/docs/.../server/src and related stalls.
- Clarify approval plumbing by using  (not sub_id) in  and log a warning if no pending approval is found. Helps diagnose/avoid approval hangs after user clicks Approve.

Closes #20
This commit is contained in:
James Peter
2025-09-06 03:04:59 +10:00
parent 7238eb1a48
commit 7c96f256b8
6 changed files with 133 additions and 4 deletions
+38
View File
@@ -701,6 +701,44 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
# --- Homebrew Tap Update -------------------------------------------------
- name: Generate Homebrew formula (Code.rb)
shell: bash
run: |
set -euo pipefail
bash scripts/generate-homebrew-formula.sh
test -s Formula/Code.rb || { echo "Formula/Code.rb missing" >&2; exit 1; }
- name: Publish Homebrew formula to just-every/homebrew-tap
shell: bash
env:
GH_PAT: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
if [ -z "${GH_PAT:-}" ]; then
echo "GH_PAT/GITHUB_TOKEN not available; skipping tap publish" >&2
exit 0
fi
tmpdir=$(mktemp -d)
git clone "https://x-access-token:${GH_PAT}@github.com/just-every/homebrew-tap.git" "$tmpdir"
mkdir -p "$tmpdir/Formula"
cp -f Formula/Code.rb "$tmpdir/Formula/Code.rb"
cd "$tmpdir"
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add -A
if git diff --staged --quiet; then
echo "No tap changes to commit." >&2
exit 0
fi
ver="${{ steps.version.outputs.version }}"
git commit -m "chore(homebrew): bump Code formula to v${ver}"
# Ensure default branch exists
if ! git rev-parse --abbrev-ref --symbolic-full-name @{u} >/dev/null 2>&1; then
git branch -M main || true
fi
git push -u origin HEAD:main
- name: Publish per-target npm binary packages (last)
if: ${{ env.NPM_TOKEN != '' }}
env:
+27
View File
@@ -0,0 +1,27 @@
class Code < Formula
desc "Terminal coding agent"
homepage "https://github.com/just-every/code"
version "v0.2.67"
on_macos do
if Hardware::CPU.arm?
url "https://github.com/just-every/code/releases/download/v0.2.67/code-aarch64-apple-darwin.tar.gz"
sha256 "ed8fbb68d8cff0f76d28c9c9b69445dab66f8e645613e9145061e950e8cf7507"
else
url "https://github.com/just-every/code/releases/download/v0.2.67/code-x86_64-apple-darwin.tar.gz"
sha256 "642f656b1d45fe305738f519b5d44c8329bd9963f3e3781ee542a4313d2102f7"
end
end
def install
bin.install Dir["code-*"].first => "code"
# Provide a compatibility shim
(bin/"coder").write <<~EOS
#!/bin/bash
exec "#{bin}/code" "$@"
EOS
end
test do
system "#{bin}/code", "--help"
end
end
+7 -3
View File
@@ -869,10 +869,14 @@ impl Session {
rx_approve
}
pub fn notify_approval(&self, sub_id: &str, decision: ReviewDecision) {
pub fn notify_approval(&self, call_id: &str, decision: ReviewDecision) {
let mut state = self.state.lock().unwrap();
if let Some(tx_approve) = state.pending_approvals.remove(sub_id) {
tx_approve.send(decision).ok();
if let Some(tx_approve) = state.pending_approvals.remove(call_id) {
let _ = tx_approve.send(decision);
} else {
// If we cannot find a pending approval for this call id, surface a warning
// to aid debugging of stuck approvals.
tracing::warn!("no pending approval found for call_id={}", call_id);
}
}
+16 -1
View File
@@ -738,7 +738,7 @@ impl Config {
let shell_environment_policy = cfg.shell_environment_policy.into();
let resolved_cwd = {
let mut resolved_cwd = {
use std::env;
match cwd {
@@ -757,6 +757,21 @@ impl Config {
}
};
// If launched from inside a Git worktree subdirectory, normalize the
// session cwd to the repository root so model-provided relative paths
// are resolved from the project root (prevents accidental nesting like
// `<repo>/docs/.../server/src` when starting in `docs/`).
if let Some(repo_root) = crate::git_info::get_git_repo_root(&resolved_cwd) {
if repo_root != resolved_cwd {
tracing::info!(
"normalizing cwd to git repo root: {} -> {}",
resolved_cwd.display(),
repo_root.display()
);
resolved_cwd = repo_root;
}
}
let history = cfg.history.unwrap_or_default();
let tools_web_search_request = override_tools_web_search_request
+27
View File
@@ -0,0 +1,27 @@
class Code < Formula
desc "Terminal coding agent"
homepage "https://github.com/just-every/code"
version "v0.2.67"
on_macos do
if Hardware::CPU.arm?
url "https://github.com/just-every/code/releases/download/v0.2.67/code-aarch64-apple-darwin.tar.gz"
sha256 "ed8fbb68d8cff0f76d28c9c9b69445dab66f8e645613e9145061e950e8cf7507"
else
url "https://github.com/just-every/code/releases/download/v0.2.67/code-x86_64-apple-darwin.tar.gz"
sha256 "642f656b1d45fe305738f519b5d44c8329bd9963f3e3781ee542a4313d2102f7"
end
end
def install
bin.install Dir["code-*"].first => "code"
# Provide a compatibility shim
(bin/"coder").write <<~EOS
#!/bin/bash
exec "#{bin}/code" "$@"
EOS
end
test do
system "#{bin}/code", "--help"
end
end
+18
View File
@@ -0,0 +1,18 @@
# just-every/homebrew-tap
Unofficial tap for Code (terminal coding agent).
## Usage
```bash
brew tap just-every/tap
brew install code
```
## Updating
- Regenerate the formula in the main repo:
```bash
scripts/generate-homebrew-formula.sh
```
- Copy `Formula/Code.rb` into this tap at `Formula/Code.rb` and push a commit.