This repository has no description
2.1 kB
48 lines
1{ inputs, ... }:
2{
3 perSystem =
4 { pkgs, system, ... }:
5 {
6 # Start an omp agent in a new herdr tab from one command:
7 # s herd 'fix issue #13' --model opus
8 # Everything is passed through to omp, so any omp flag works. The tab
9 # lands in the focused workspace (one is created from $PWD if there is
10 # none). By default it is not focused, so the caller's pane stays put;
11 # `-f`/`--focus` (before the prompt) switches to the new pane instead.
12 # herdr picks the agent up by itself; name it with
13 # `herdr agent rename <pane> <name>` if you want to address it by name
14 # afterwards.
15 packages.herd =
16 (pkgs.writeShellApplication {
17 name = "herd";
18 runtimeInputs = [
19 inputs.llm-agents.packages.${system}.herdr
20 pkgs.jq
21 ];
22 text = ''
23 focus=--no-focus
24 case "''${1:-}" in
25 -f|--focus)
26 focus=--focus
27 shift
28 ;;
29 esac
30 # Not $HERDR_WORKSPACE_ID: that is the launch-time value and goes
31 # stale once the pane is moved to another workspace (herdr keeps
32 # the old pane id as an alias, so `pane current` still resolves).
33 workspace=$(herdr pane current 2>/dev/null | jq -r '.result.pane.workspace_id // empty')
34 [ -n "$workspace" ] || workspace=$(herdr workspace list | jq -r '.result.workspaces[] | select(.focused) | .workspace_id')
35 label=$(printf '%s' "''${1:-omp}" | cut -c1-32)
36 if [ -n "$workspace" ]; then
37 created=$(herdr tab create --workspace "$workspace" --cwd "$PWD" --label "$label" "$focus")
38 else
39 created=$(herdr workspace create --cwd "$PWD" --label "$(basename "$PWD")" "$focus")
40 fi
41 pane=$(printf '%s' "$created" | jq -er .result.root_pane.pane_id)
42 herdr pane run "$pane" "${pkgs.omp}/bin/omp$(printf ' %q' "$@")" >/dev/null
43 echo "$pane"
44 '';
45 }).overrideAttrs
46 { passthru.usage = builtins.readFile ./usage.kdl; };
47 };
48}