Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions agents/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Interactive/auth: `agent-browser-odsod connect`, then `agent-browser open|read|c
Public URL for a local server (webhooks, external callers): `tailscale funnel --bg --https=8443 <port>`;
`tailscale funnel --https=8443 off` when done. Not cloudflared or ngrok.

No cloud Artifacts (denied). Write deliverables as files in the repo if instructed.
Put temporary or ephemeral artifacts in `/tmp`.

`gh` always `-R <owner>/<repo>` (jj workspaces have no git remotes).
Owner/repo from `~/Code/<host>/<owner>/<repo>`,
`~/Workspaces/<host>/<owner>/<repo>/<branch>`, or `jj git remote list`.
Expand Down
108 changes: 108 additions & 0 deletions agents/hooks/linear-context.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bash
# Session-start hook: refresh the nearest .linear-context.md from Linear and
# print it as agent context. The frontmatter names the Linear items; the body
# is generated. On a failed fetch, keep and print the old file.
#
# Usage: linear-context.sh [--agy]
# --agy print agy's {"inject_steps": [...]} JSON instead of plain markdown.
set -uo pipefail

name=.linear-context.md

cwd=$PWD
if [ ! -t 0 ]; then
in_cwd=$(jq -r '.cwd // empty' 2>/dev/null || true)
[ -n "$in_cwd" ] && cwd=$in_cwd
fi

file=
dir=$cwd
while :; do
if [ -f "$dir/$name" ]; then
file=$dir/$name
break
fi
[ "$dir" = / ] && break
dir=$(dirname "$dir")
done
[ -n "$file" ] || exit 0

emit() {
if [ "${1:-}" = --agy ]; then
jq -n --rawfile body "$file" '{inject_steps: [{ephemeral_message: $body}]}'
else
cat "$file"
fi
}

project=$(yq --front-matter=extract '.linear.project // ""' "$file" 2>/dev/null)
mapfile -t issues < <(yq --front-matter=extract '.linear.issues // [] | .[]' "$file" 2>/dev/null)

tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT

pids=()
for i in "${!issues[@]}"; do
timeout 10 linear issue view "${issues[$i]}" --no-pager --no-download --no-input \
>"$tmp/issue-$i.md" 2>/dev/null &
pids+=($!)
done
if [ -n "$project" ]; then
timeout 10 linear project view "$project" --no-pager --no-input \
>"$tmp/project.md" 2>/dev/null &
pids+=($!)
timeout 10 linear project-update list "$project" --limit 3 --no-input \
>"$tmp/updates.md" 2>/dev/null &
pids+=($!)
fi

ok=1
for pid in "${pids[@]}"; do
wait "$pid" || ok=0
done

if [ "$ok" = 0 ]; then
emit "$@"
exit 0
fi

# Demote markdown headings one level, outside fenced code blocks.
demote() {
awk '/^```/ { fence = !fence } !fence && /^#/ { $0 = "#" $0 } { print }' "$1"
}

{
# yq prints the opening "---" itself.
yq --front-matter=extract ".refreshed = \"$(date -Iseconds)\"" "$file"
echo ---
cat <<'EOF'

# Linear context

This workspace tracks the Linear items below. Use the /linear-cli skill to
work with them.

- When you start work on an issue, run
`linear issue update <ID> --state started`.
- At each milestone and when you stop, post progress with
`linear issue comment add <ID> --body-file <file>`.
- Link each PR to its issue with `linear issue link <ID> <PR URL>`.
- Do not set an issue to Done or Canceled. The user does that.
- A hook regenerates this file at session start. Do not edit the body. To
change the tracked items, edit the `linear:` frontmatter.
EOF
for i in "${!issues[@]}"; do
echo
demote "$tmp/issue-$i.md"
done
if [ -n "$project" ]; then
echo
demote "$tmp/project.md"
echo
echo "## Recent project updates"
echo
demote "$tmp/updates.md"
fi
} >"$tmp/out" && cp "$tmp/out" "$file.tmp" && mv "$file.tmp" "$file"

emit "$@"
6 changes: 6 additions & 0 deletions antigravity/hooks.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"machine": {
"SessionStart": [
{
"type": "command",
"command": "$HOME/.agents/hooks/linear-context.sh --agy"
}
],
"PostToolUse": [
{
"matcher": "write_to_file|replace_file_content",
Expand Down
14 changes: 13 additions & 1 deletion claude/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@
"pr": ""
},
"permissions": {
"defaultMode": "bypassPermissions"
"defaultMode": "bypassPermissions",
"//": "Deny cloud Artifacts. Agents write deliverables as repo files if instructed, and temporary or ephemeral artifacts in /tmp.",
"deny": ["Artifact"]
},
"model": "opus",
"hooks": {
"PreToolUse": [],
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "$HOME/.agents/hooks/linear-context.sh"
}
]
}
],
"PostToolUse": [
{
"matcher": "Write|Edit",
Expand Down
6 changes: 6 additions & 0 deletions codex/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ matcher = "Write|Edit|apply_patch"
[[hooks.PostToolUse.hooks]]
type = "command"
command = "$HOME/.agents/hooks/format.sh"

[[hooks.SessionStart]]

[[hooks.SessionStart.hooks]]
type = "command"
command = "$HOME/.agents/hooks/linear-context.sh"
3 changes: 3 additions & 0 deletions env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export PATH="$CARGO_HOME/bin:$PATH"
# shellcheck source=/dev/null
[ -f "$CARGO_HOME/env" ] && . "$CARGO_HOME/env"

# slackcli: mise owns updates; the notice suggests `slackcli update`
export SLACKCLI_NO_UPDATE_NOTIFIER=1

# ssh — needed for non-fish shells (e.g. Claude Code's zsh) where
# fish's refresh_ssh_auth_sock doesn't run; without this, jj sign-on-push hangs.
if [ -z "$SSH_AUTH_SOCK" ]; then
Expand Down
3 changes: 3 additions & 0 deletions git/ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/.claude/settings.local.json
.linear-context.md
.linear-context.md.tmp
49 changes: 49 additions & 0 deletions herdr/start-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,54 @@ function select_agent
_write_state last-agent "$agent_kind"
end

# --- Linear context ---

# Ask which Linear issues or project the workspace tracks and write them to
# .linear-context.md, which agents/hooks/linear-context.sh reads at session
# start. Skip when the file exists, linear is missing, or nothing is picked.
function _pick_linear_context --argument-names dir
set -l file "$dir/.linear-context.md"
test -e "$file"; and return 0
command -q linear; or return 0

_status_show "Loading Linear issues..."
set -l lines (timeout 10 linear issue list -s started -s unstarted --json --no-input 2>/dev/null \
| jq -r '.[] | "\(.identifier)\t\(.title)"' 2>/dev/null)
_status_clear

set -l picked (printf '%s\n' $lines | fzf --prompt="Linear> " --height=100% --reverse \
--multi --print-query --delimiter=\t --bind='enter:accept-or-print-query' \
--header='tab: select · type issue IDs or a project slug · esc: skip')
test $status -le 1; or return 0

# Selected list lines win; otherwise read issue IDs and one project from the query.
set -l issues
set -l project
set -l selected (string match -- '*'\t'*' $picked[2..-1])
if test (count $selected) -gt 0
for line in $selected
set -a issues (string split -f1 \t -- "$line")
end
else
for token in (string split -n ' ' -- "$picked[1]")
if string match -rq '^[A-Za-z]+-[0-9]+$' -- "$token"
set -a issues (string upper -- "$token")
else if test -z "$project"
set project "$token"
end
end
end
test (count $issues) -gt 0 -o -n "$project"; or return 0

begin
echo ---
echo linear:
test -n "$project"; and echo " project: $project"
test (count $issues) -gt 0; and echo " issues: ["(string join ', ' -- $issues)"]"
echo ---
end >"$file"
end

# --- Workspace trust ---

# Trust the workspace in every harness, so agent-team siblings of any kind
Expand Down Expand Up @@ -785,6 +833,7 @@ if test "$space_type" = Workspace
_status_clear
_trace "workspace: selecting agent"
select_agent; or exit 0
_pick_linear_context "$workspace_path"
_trace "workspace: launching"

set ws_label (_workspace_label "$repo_name" "$bookmark")
Expand Down
5 changes: 4 additions & 1 deletion herdr/tests/start-workspace.fish
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ function write_stubs --argument-names home
' else' \
' echo "$bm_lines[1]"' \
' end' \
' case "Linear> "' \
' exit 130' \
' case "Agent> "' \
' if test -n "$FZF_AGENT_CHOICE"' \
' echo "$FZF_AGENT_CHOICE"' \
Expand Down Expand Up @@ -118,6 +120,7 @@ function write_stubs --argument-names home
printf '%s\n' "#!$real_fish --no-config" 'exit 0' >"$stub_bin/claude"
printf '%s\n' "#!$real_fish --no-config" 'exit 0' >"$stub_bin/agy"
printf '%s\n' "#!$real_fish --no-config" 'exit 0' >"$stub_bin/pi"
printf '%s\n' "#!$real_fish --no-config" 'exit 1' >"$stub_bin/linear"
printf '%s\n' "#!$real_fish --no-config" 'exit 1' >"$stub_bin/timeout"
if test -n "$real_setsid"
printf '%s\n' \
Expand All @@ -128,7 +131,7 @@ function write_stubs --argument-names home
end
chmod +x "$stub_bin/fzf" "$stub_bin/herdr" "$stub_bin/jj" \
"$stub_bin/ssh" "$stub_bin/codex" "$stub_bin/claude" \
"$stub_bin/agy" "$stub_bin/pi" "$stub_bin/timeout"
"$stub_bin/agy" "$stub_bin/pi" "$stub_bin/linear" "$stub_bin/timeout"
end

function setup_case --argument-names name
Expand Down
47 changes: 47 additions & 0 deletions mise.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ln -fsT "$nvim_path" "$HOME/.local/bin/vi"
pi = "latest"
ruff = "latest"
usage = "latest"
yq = "latest"

# Python dependency graphs need uv >= 0.12.10; Fedora 44 ships 0.12.9, so dnf
# cannot satisfy it. dnf:uv stays for the post-packages hook that runs before
Expand Down
1 change: 1 addition & 0 deletions mise/conf.d/git.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[dotfiles]
"~/.gitconfig" = "../../git/gitconfig"
"~/.config/git/ignore" = "../../git/ignore"

[bootstrap.packages]
"dnf:git" = "latest"
Expand Down
1 change: 1 addition & 0 deletions mise/conf.d/pi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
"~/.pi/agent/models.json" = "../../pi/models.json"
"~/.pi/agent/themes/nord-dark.json" = "../../pi/themes/nord-dark.json"
"~/.pi/agent/themes/nord-claude.json" = "../../pi/themes/nord-claude.json"
"~/.pi/agent/extensions/linear-context.ts" = "../../pi/extensions/linear-context.ts"

22 changes: 22 additions & 0 deletions pi/extensions/linear-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Add the workspace's .linear-context.md to the system prompt.
// Runs the shared session-start hook once per session and caches its output.
import { execFileSync } from "node:child_process";
import { homedir } from "node:os";

export default function (pi: any) {
let context = "";
pi.on("session_start", async () => {
try {
context = execFileSync(`${homedir()}/.agents/hooks/linear-context.sh`, [], {
input: "",
timeout: 20000,
}).toString();
} catch {
context = "";
}
});
pi.on("before_agent_start", async (event: any) => {
if (!context) return;
return { systemPrompt: `${event.systemPrompt}\n\n${context}` };
});
}
Loading