pretticlaw 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +123 -0
- package/README.md +150 -0
- package/assets/logo.png +0 -0
- package/dist/agent/context.d.ts +22 -0
- package/dist/agent/context.js +85 -0
- package/dist/agent/loop.d.ts +63 -0
- package/dist/agent/loop.js +244 -0
- package/dist/agent/memory.d.ts +16 -0
- package/dist/agent/memory.js +98 -0
- package/dist/agent/skills.d.ts +18 -0
- package/dist/agent/skills.js +121 -0
- package/dist/agent/subagent.d.ts +30 -0
- package/dist/agent/subagent.js +92 -0
- package/dist/agent/tools/base.d.ts +10 -0
- package/dist/agent/tools/base.js +58 -0
- package/dist/agent/tools/cron.d.ts +43 -0
- package/dist/agent/tools/cron.js +83 -0
- package/dist/agent/tools/filesystem.d.ts +79 -0
- package/dist/agent/tools/filesystem.js +125 -0
- package/dist/agent/tools/message.d.ts +41 -0
- package/dist/agent/tools/message.js +55 -0
- package/dist/agent/tools/registry.d.ts +9 -0
- package/dist/agent/tools/registry.js +33 -0
- package/dist/agent/tools/shell.d.ts +26 -0
- package/dist/agent/tools/shell.js +78 -0
- package/dist/agent/tools/spawn.d.ts +27 -0
- package/dist/agent/tools/spawn.js +35 -0
- package/dist/agent/tools/web.d.ts +50 -0
- package/dist/agent/tools/web.js +119 -0
- package/dist/bus/async-queue.d.ts +7 -0
- package/dist/bus/async-queue.js +20 -0
- package/dist/bus/events.d.ts +19 -0
- package/dist/bus/events.js +3 -0
- package/dist/bus/queue.d.ts +12 -0
- package/dist/bus/queue.js +23 -0
- package/dist/channels/base.d.ts +22 -0
- package/dist/channels/base.js +35 -0
- package/dist/channels/discord.d.ts +24 -0
- package/dist/channels/discord.js +133 -0
- package/dist/channels/manager.d.ts +17 -0
- package/dist/channels/manager.js +67 -0
- package/dist/channels/stub.d.ts +10 -0
- package/dist/channels/stub.js +18 -0
- package/dist/channels/telegram.d.ts +20 -0
- package/dist/channels/telegram.js +93 -0
- package/dist/cli/commands.d.ts +2 -0
- package/dist/cli/commands.js +552 -0
- package/dist/config/loader.d.ts +5 -0
- package/dist/config/loader.js +55 -0
- package/dist/config/schema.d.ts +246 -0
- package/dist/config/schema.js +94 -0
- package/dist/cron/service.d.ts +33 -0
- package/dist/cron/service.js +195 -0
- package/dist/cron/types.d.ts +47 -0
- package/dist/cron/types.js +1 -0
- package/dist/dashboard/index.html +1567 -0
- package/dist/heartbeat/service.d.ts +21 -0
- package/dist/heartbeat/service.js +101 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/providers/base.d.ts +23 -0
- package/dist/providers/base.js +21 -0
- package/dist/providers/custom-provider.d.ts +16 -0
- package/dist/providers/custom-provider.js +49 -0
- package/dist/providers/litellm-provider.d.ts +19 -0
- package/dist/providers/litellm-provider.js +128 -0
- package/dist/providers/registry.d.ts +5 -0
- package/dist/providers/registry.js +45 -0
- package/dist/session/manager.d.ts +31 -0
- package/dist/session/manager.js +116 -0
- package/dist/skills/README.md +25 -0
- package/dist/skills/clawhub/SKILL.md +53 -0
- package/dist/skills/cron/SKILL.md +57 -0
- package/dist/skills/github/SKILL.md +48 -0
- package/dist/skills/memory/SKILL.md +31 -0
- package/dist/skills/skill-creator/SKILL.md +371 -0
- package/dist/skills/summarize/SKILL.md +67 -0
- package/dist/skills/tmux/SKILL.md +121 -0
- package/dist/skills/tmux/scripts/find-sessions.sh +112 -0
- package/dist/skills/tmux/scripts/wait-for-text.sh +83 -0
- package/dist/skills/weather/SKILL.md +49 -0
- package/dist/templates/AGENTS.md +23 -0
- package/dist/templates/HEARTBEAT.md +16 -0
- package/dist/templates/SOUL.md +21 -0
- package/dist/templates/TOOLS.md +15 -0
- package/dist/templates/USER.md +49 -0
- package/dist/templates/memory/MEMORY.md +23 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +3 -0
- package/dist/utils/helpers.d.ts +5 -0
- package/dist/utils/helpers.js +53 -0
- package/dist/web/server.d.ts +15 -0
- package/dist/web/server.js +169 -0
- package/package.json +37 -0
- package/scripts/copy-assets.mjs +21 -0
- package/src/agent/context.ts +90 -0
- package/src/agent/loop.ts +291 -0
- package/src/agent/memory.ts +104 -0
- package/src/agent/skills.ts +121 -0
- package/src/agent/subagent.ts +96 -0
- package/src/agent/tools/base.ts +59 -0
- package/src/agent/tools/cron.ts +79 -0
- package/src/agent/tools/filesystem.ts +93 -0
- package/src/agent/tools/message.ts +57 -0
- package/src/agent/tools/registry.ts +36 -0
- package/src/agent/tools/shell.ts +69 -0
- package/src/agent/tools/spawn.ts +37 -0
- package/src/agent/tools/web.ts +108 -0
- package/src/bus/async-queue.ts +20 -0
- package/src/bus/events.ts +23 -0
- package/src/bus/queue.ts +31 -0
- package/src/channels/base.ts +36 -0
- package/src/channels/discord.ts +156 -0
- package/src/channels/manager.ts +70 -0
- package/src/channels/stub.ts +20 -0
- package/src/channels/telegram.ts +120 -0
- package/src/cli/commands.ts +581 -0
- package/src/config/loader.ts +58 -0
- package/src/config/schema.ts +144 -0
- package/src/cron/service.ts +190 -0
- package/src/cron/types.ts +36 -0
- package/src/dashboard/index.html +1567 -0
- package/src/heartbeat/service.ts +95 -0
- package/src/index.ts +6 -0
- package/src/providers/base.ts +43 -0
- package/src/providers/custom-provider.ts +46 -0
- package/src/providers/litellm-provider.ts +131 -0
- package/src/providers/registry.ts +48 -0
- package/src/session/manager.ts +129 -0
- package/src/skills/README.md +25 -0
- package/src/skills/clawhub/SKILL.md +53 -0
- package/src/skills/cron/SKILL.md +57 -0
- package/src/skills/github/SKILL.md +48 -0
- package/src/skills/memory/SKILL.md +31 -0
- package/src/skills/skill-creator/SKILL.md +371 -0
- package/src/skills/summarize/SKILL.md +67 -0
- package/src/skills/tmux/SKILL.md +121 -0
- package/src/skills/tmux/scripts/find-sessions.sh +112 -0
- package/src/skills/tmux/scripts/wait-for-text.sh +83 -0
- package/src/skills/weather/SKILL.md +49 -0
- package/src/templates/AGENTS.md +23 -0
- package/src/templates/HEARTBEAT.md +16 -0
- package/src/templates/SOUL.md +21 -0
- package/src/templates/TOOLS.md +15 -0
- package/src/templates/USER.md +49 -0
- package/src/templates/memory/MEMORY.md +23 -0
- package/src/types/prompts.d.ts +14 -0
- package/src/types/ws.d.ts +15 -0
- package/src/types.ts +5 -0
- package/src/utils/helpers.ts +55 -0
- package/src/web/server.ts +198 -0
- package/test/context.test.ts +27 -0
- package/test/cron-service.test.ts +31 -0
- package/test/message-tool.test.ts +10 -0
- package/test/providers.test.ts +43 -0
- package/test/tool-validation.test.ts +61 -0
- package/tsconfig.json +16 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: tmux
|
|
3
|
+
description: Remote-control tmux sessions for interactive CLIs by sending keystrokes and scraping pane output.
|
|
4
|
+
metadata: {"pretticlaw":{"emoji":"🧵","os":["darwin","linux"],"requires":{"bins":["tmux"]}}}
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# tmux Skill
|
|
8
|
+
|
|
9
|
+
Use tmux only when you need an interactive TTY. Prefer exec background mode for long-running, non-interactive tasks.
|
|
10
|
+
|
|
11
|
+
## Quickstart (isolated socket, exec tool)
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
SOCKET_DIR="${PRETTICLAW_TMUX_SOCKET_DIR:-${TMPDIR:-/tmp}/pretticlaw-tmux-sockets}"
|
|
15
|
+
mkdir -p "$SOCKET_DIR"
|
|
16
|
+
SOCKET="$SOCKET_DIR/pretticlaw.sock"
|
|
17
|
+
SESSION=pretticlaw-python
|
|
18
|
+
|
|
19
|
+
tmux -S "$SOCKET" new -d -s "$SESSION" -n shell
|
|
20
|
+
tmux -S "$SOCKET" send-keys -t "$SESSION":0.0 -- 'PYTHON_BASIC_REPL=1 python3 -q' Enter
|
|
21
|
+
tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":0.0 -S -200
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
After starting a session, always print monitor commands:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
To monitor:
|
|
28
|
+
tmux -S "$SOCKET" attach -t "$SESSION"
|
|
29
|
+
tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":0.0 -S -200
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Socket convention
|
|
33
|
+
|
|
34
|
+
- Use `PRETTICLAW_TMUX_SOCKET_DIR` environment variable.
|
|
35
|
+
- Default socket path: `"$PRETTICLAW_TMUX_SOCKET_DIR/pretticlaw.sock"`.
|
|
36
|
+
|
|
37
|
+
## Targeting panes and naming
|
|
38
|
+
|
|
39
|
+
- Target format: `session:window.pane` (defaults to `:0.0`).
|
|
40
|
+
- Keep names short; avoid spaces.
|
|
41
|
+
- Inspect: `tmux -S "$SOCKET" list-sessions`, `tmux -S "$SOCKET" list-panes -a`.
|
|
42
|
+
|
|
43
|
+
## Finding sessions
|
|
44
|
+
|
|
45
|
+
- List sessions on your socket: `{baseDir}/scripts/find-sessions.sh -S "$SOCKET"`.
|
|
46
|
+
- Scan all sockets: `{baseDir}/scripts/find-sessions.sh --all` (uses `PRETTICLAW_TMUX_SOCKET_DIR`).
|
|
47
|
+
|
|
48
|
+
## Sending input safely
|
|
49
|
+
|
|
50
|
+
- Prefer literal sends: `tmux -S "$SOCKET" send-keys -t target -l -- "$cmd"`.
|
|
51
|
+
- Control keys: `tmux -S "$SOCKET" send-keys -t target C-c`.
|
|
52
|
+
|
|
53
|
+
## Watching output
|
|
54
|
+
|
|
55
|
+
- Capture recent history: `tmux -S "$SOCKET" capture-pane -p -J -t target -S -200`.
|
|
56
|
+
- Wait for prompts: `{baseDir}/scripts/wait-for-text.sh -t session:0.0 -p 'pattern'`.
|
|
57
|
+
- Attaching is OK; detach with `Ctrl+b d`.
|
|
58
|
+
|
|
59
|
+
## Spawning processes
|
|
60
|
+
|
|
61
|
+
- For python REPLs, set `PYTHON_BASIC_REPL=1` (non-basic REPL breaks send-keys flows).
|
|
62
|
+
|
|
63
|
+
## Windows / WSL
|
|
64
|
+
|
|
65
|
+
- tmux is supported on macOS/Linux. On Windows, use WSL and install tmux inside WSL.
|
|
66
|
+
- This skill is gated to `darwin`/`linux` and requires `tmux` on PATH.
|
|
67
|
+
|
|
68
|
+
## Orchestrating Coding Agents (Codex, Claude Code)
|
|
69
|
+
|
|
70
|
+
tmux excels at running multiple coding agents in parallel:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
SOCKET="${TMPDIR:-/tmp}/codex-army.sock"
|
|
74
|
+
|
|
75
|
+
# Create multiple sessions
|
|
76
|
+
for i in 1 2 3 4 5; do
|
|
77
|
+
tmux -S "$SOCKET" new-session -d -s "agent-$i"
|
|
78
|
+
done
|
|
79
|
+
|
|
80
|
+
# Launch agents in different workdirs
|
|
81
|
+
tmux -S "$SOCKET" send-keys -t agent-1 "cd /tmp/project1 && codex --yolo 'Fix bug X'" Enter
|
|
82
|
+
tmux -S "$SOCKET" send-keys -t agent-2 "cd /tmp/project2 && codex --yolo 'Fix bug Y'" Enter
|
|
83
|
+
|
|
84
|
+
# Poll for completion (check if prompt returned)
|
|
85
|
+
for sess in agent-1 agent-2; do
|
|
86
|
+
if tmux -S "$SOCKET" capture-pane -p -t "$sess" -S -3 | grep -q "❯"; then
|
|
87
|
+
echo "$sess: DONE"
|
|
88
|
+
else
|
|
89
|
+
echo "$sess: Running..."
|
|
90
|
+
fi
|
|
91
|
+
done
|
|
92
|
+
|
|
93
|
+
# Get full output from completed session
|
|
94
|
+
tmux -S "$SOCKET" capture-pane -p -t agent-1 -S -500
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Tips:**
|
|
98
|
+
- Use separate git worktrees for parallel fixes (no branch conflicts)
|
|
99
|
+
- `pnpm install` first before running codex in fresh clones
|
|
100
|
+
- Check for shell prompt (`❯` or `$`) to detect completion
|
|
101
|
+
- Codex needs `--yolo` or `--full-auto` for non-interactive fixes
|
|
102
|
+
|
|
103
|
+
## Cleanup
|
|
104
|
+
|
|
105
|
+
- Kill a session: `tmux -S "$SOCKET" kill-session -t "$SESSION"`.
|
|
106
|
+
- Kill all sessions on a socket: `tmux -S "$SOCKET" list-sessions -F '#{session_name}' | xargs -r -n1 tmux -S "$SOCKET" kill-session -t`.
|
|
107
|
+
- Remove everything on the private socket: `tmux -S "$SOCKET" kill-server`.
|
|
108
|
+
|
|
109
|
+
## Helper: wait-for-text.sh
|
|
110
|
+
|
|
111
|
+
`{baseDir}/scripts/wait-for-text.sh` polls a pane for a regex (or fixed string) with a timeout.
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
{baseDir}/scripts/wait-for-text.sh -t session:0.0 -p 'pattern' [-F] [-T 20] [-i 0.5] [-l 2000]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
- `-t`/`--target` pane target (required)
|
|
118
|
+
- `-p`/`--pattern` regex to match (required); add `-F` for fixed string
|
|
119
|
+
- `-T` timeout seconds (integer, default 15)
|
|
120
|
+
- `-i` poll interval seconds (default 0.5)
|
|
121
|
+
- `-l` history lines to search (integer, default 1000)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
usage() {
|
|
5
|
+
cat <<'USAGE'
|
|
6
|
+
Usage: find-sessions.sh [-L socket-name|-S socket-path|-A] [-q pattern]
|
|
7
|
+
|
|
8
|
+
List tmux sessions on a socket (default tmux socket if none provided).
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
-L, --socket tmux socket name (passed to tmux -L)
|
|
12
|
+
-S, --socket-path tmux socket path (passed to tmux -S)
|
|
13
|
+
-A, --all scan all sockets under PRETTICLAW_TMUX_SOCKET_DIR
|
|
14
|
+
-q, --query case-insensitive substring to filter session names
|
|
15
|
+
-h, --help show this help
|
|
16
|
+
USAGE
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
socket_name=""
|
|
20
|
+
socket_path=""
|
|
21
|
+
query=""
|
|
22
|
+
scan_all=false
|
|
23
|
+
socket_dir="${PRETTICLAW_TMUX_SOCKET_DIR:-${TMPDIR:-/tmp}/pretticlaw-tmux-sockets}"
|
|
24
|
+
|
|
25
|
+
while [[ $# -gt 0 ]]; do
|
|
26
|
+
case "$1" in
|
|
27
|
+
-L|--socket) socket_name="${2-}"; shift 2 ;;
|
|
28
|
+
-S|--socket-path) socket_path="${2-}"; shift 2 ;;
|
|
29
|
+
-A|--all) scan_all=true; shift ;;
|
|
30
|
+
-q|--query) query="${2-}"; shift 2 ;;
|
|
31
|
+
-h|--help) usage; exit 0 ;;
|
|
32
|
+
*) echo "Unknown option: $1" >&2; usage; exit 1 ;;
|
|
33
|
+
esac
|
|
34
|
+
done
|
|
35
|
+
|
|
36
|
+
if [[ "$scan_all" == true && ( -n "$socket_name" || -n "$socket_path" ) ]]; then
|
|
37
|
+
echo "Cannot combine --all with -L or -S" >&2
|
|
38
|
+
exit 1
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
if [[ -n "$socket_name" && -n "$socket_path" ]]; then
|
|
42
|
+
echo "Use either -L or -S, not both" >&2
|
|
43
|
+
exit 1
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
if ! command -v tmux >/dev/null 2>&1; then
|
|
47
|
+
echo "tmux not found in PATH" >&2
|
|
48
|
+
exit 1
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
list_sessions() {
|
|
52
|
+
local label="$1"; shift
|
|
53
|
+
local tmux_cmd=(tmux "$@")
|
|
54
|
+
|
|
55
|
+
if ! sessions="$("${tmux_cmd[@]}" list-sessions -F '#{session_name}\t#{session_attached}\t#{session_created_string}' 2>/dev/null)"; then
|
|
56
|
+
echo "No tmux server found on $label" >&2
|
|
57
|
+
return 1
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
|
+
if [[ -n "$query" ]]; then
|
|
61
|
+
sessions="$(printf '%s\n' "$sessions" | grep -i -- "$query" || true)"
|
|
62
|
+
fi
|
|
63
|
+
|
|
64
|
+
if [[ -z "$sessions" ]]; then
|
|
65
|
+
echo "No sessions found on $label"
|
|
66
|
+
return 0
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
echo "Sessions on $label:"
|
|
70
|
+
printf '%s\n' "$sessions" | while IFS=$'\t' read -r name attached created; do
|
|
71
|
+
attached_label=$([[ "$attached" == "1" ]] && echo "attached" || echo "detached")
|
|
72
|
+
printf ' - %s (%s, started %s)\n' "$name" "$attached_label" "$created"
|
|
73
|
+
done
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if [[ "$scan_all" == true ]]; then
|
|
77
|
+
if [[ ! -d "$socket_dir" ]]; then
|
|
78
|
+
echo "Socket directory not found: $socket_dir" >&2
|
|
79
|
+
exit 1
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
shopt -s nullglob
|
|
83
|
+
sockets=("$socket_dir"/*)
|
|
84
|
+
shopt -u nullglob
|
|
85
|
+
|
|
86
|
+
if [[ "${#sockets[@]}" -eq 0 ]]; then
|
|
87
|
+
echo "No sockets found under $socket_dir" >&2
|
|
88
|
+
exit 1
|
|
89
|
+
fi
|
|
90
|
+
|
|
91
|
+
exit_code=0
|
|
92
|
+
for sock in "${sockets[@]}"; do
|
|
93
|
+
if [[ ! -S "$sock" ]]; then
|
|
94
|
+
continue
|
|
95
|
+
fi
|
|
96
|
+
list_sessions "socket path '$sock'" -S "$sock" || exit_code=$?
|
|
97
|
+
done
|
|
98
|
+
exit "$exit_code"
|
|
99
|
+
fi
|
|
100
|
+
|
|
101
|
+
tmux_cmd=(tmux)
|
|
102
|
+
socket_label="default socket"
|
|
103
|
+
|
|
104
|
+
if [[ -n "$socket_name" ]]; then
|
|
105
|
+
tmux_cmd+=(-L "$socket_name")
|
|
106
|
+
socket_label="socket name '$socket_name'"
|
|
107
|
+
elif [[ -n "$socket_path" ]]; then
|
|
108
|
+
tmux_cmd+=(-S "$socket_path")
|
|
109
|
+
socket_label="socket path '$socket_path'"
|
|
110
|
+
fi
|
|
111
|
+
|
|
112
|
+
list_sessions "$socket_label" "${tmux_cmd[@]:1}"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
usage() {
|
|
5
|
+
cat <<'USAGE'
|
|
6
|
+
Usage: wait-for-text.sh -t target -p pattern [options]
|
|
7
|
+
|
|
8
|
+
Poll a tmux pane for text and exit when found.
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
-t, --target tmux target (session:window.pane), required
|
|
12
|
+
-p, --pattern regex pattern to look for, required
|
|
13
|
+
-F, --fixed treat pattern as a fixed string (grep -F)
|
|
14
|
+
-T, --timeout seconds to wait (integer, default: 15)
|
|
15
|
+
-i, --interval poll interval in seconds (default: 0.5)
|
|
16
|
+
-l, --lines number of history lines to inspect (integer, default: 1000)
|
|
17
|
+
-h, --help show this help
|
|
18
|
+
USAGE
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
target=""
|
|
22
|
+
pattern=""
|
|
23
|
+
grep_flag="-E"
|
|
24
|
+
timeout=15
|
|
25
|
+
interval=0.5
|
|
26
|
+
lines=1000
|
|
27
|
+
|
|
28
|
+
while [[ $# -gt 0 ]]; do
|
|
29
|
+
case "$1" in
|
|
30
|
+
-t|--target) target="${2-}"; shift 2 ;;
|
|
31
|
+
-p|--pattern) pattern="${2-}"; shift 2 ;;
|
|
32
|
+
-F|--fixed) grep_flag="-F"; shift ;;
|
|
33
|
+
-T|--timeout) timeout="${2-}"; shift 2 ;;
|
|
34
|
+
-i|--interval) interval="${2-}"; shift 2 ;;
|
|
35
|
+
-l|--lines) lines="${2-}"; shift 2 ;;
|
|
36
|
+
-h|--help) usage; exit 0 ;;
|
|
37
|
+
*) echo "Unknown option: $1" >&2; usage; exit 1 ;;
|
|
38
|
+
esac
|
|
39
|
+
done
|
|
40
|
+
|
|
41
|
+
if [[ -z "$target" || -z "$pattern" ]]; then
|
|
42
|
+
echo "target and pattern are required" >&2
|
|
43
|
+
usage
|
|
44
|
+
exit 1
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
if ! [[ "$timeout" =~ ^[0-9]+$ ]]; then
|
|
48
|
+
echo "timeout must be an integer number of seconds" >&2
|
|
49
|
+
exit 1
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
if ! [[ "$lines" =~ ^[0-9]+$ ]]; then
|
|
53
|
+
echo "lines must be an integer" >&2
|
|
54
|
+
exit 1
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
if ! command -v tmux >/dev/null 2>&1; then
|
|
58
|
+
echo "tmux not found in PATH" >&2
|
|
59
|
+
exit 1
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
# End time in epoch seconds (integer, good enough for polling)
|
|
63
|
+
start_epoch=$(date +%s)
|
|
64
|
+
deadline=$((start_epoch + timeout))
|
|
65
|
+
|
|
66
|
+
while true; do
|
|
67
|
+
# -J joins wrapped lines, -S uses negative index to read last N lines
|
|
68
|
+
pane_text="$(tmux capture-pane -p -J -t "$target" -S "-${lines}" 2>/dev/null || true)"
|
|
69
|
+
|
|
70
|
+
if printf '%s\n' "$pane_text" | grep $grep_flag -- "$pattern" >/dev/null 2>&1; then
|
|
71
|
+
exit 0
|
|
72
|
+
fi
|
|
73
|
+
|
|
74
|
+
now=$(date +%s)
|
|
75
|
+
if (( now >= deadline )); then
|
|
76
|
+
echo "Timed out after ${timeout}s waiting for pattern: $pattern" >&2
|
|
77
|
+
echo "Last ${lines} lines from $target:" >&2
|
|
78
|
+
printf '%s\n' "$pane_text" >&2
|
|
79
|
+
exit 1
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
sleep "$interval"
|
|
83
|
+
done
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: weather
|
|
3
|
+
description: Get current weather and forecasts (no API key required).
|
|
4
|
+
homepage: https://wttr.in/:help
|
|
5
|
+
metadata: {"pretticlaw":{"emoji":"🌤️","requires":{"bins":["curl"]}}}
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Weather
|
|
9
|
+
|
|
10
|
+
Two free services, no API keys needed.
|
|
11
|
+
|
|
12
|
+
## wttr.in (primary)
|
|
13
|
+
|
|
14
|
+
Quick one-liner:
|
|
15
|
+
```bash
|
|
16
|
+
curl -s "wttr.in/London?format=3"
|
|
17
|
+
# Output: London: ⛅️ +8°C
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Compact format:
|
|
21
|
+
```bash
|
|
22
|
+
curl -s "wttr.in/London?format=%l:+%c+%t+%h+%w"
|
|
23
|
+
# Output: London: ⛅️ +8°C 71% ↙5km/h
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Full forecast:
|
|
27
|
+
```bash
|
|
28
|
+
curl -s "wttr.in/London?T"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Format codes: `%c` condition · `%t` temp · `%h` humidity · `%w` wind · `%l` location · `%m` moon
|
|
32
|
+
|
|
33
|
+
Tips:
|
|
34
|
+
- URL-encode spaces: `wttr.in/New+York`
|
|
35
|
+
- Airport codes: `wttr.in/JFK`
|
|
36
|
+
- Units: `?m` (metric) `?u` (USCS)
|
|
37
|
+
- Today only: `?1` · Current only: `?0`
|
|
38
|
+
- PNG: `curl -s "wttr.in/Berlin.png" -o /tmp/weather.png`
|
|
39
|
+
|
|
40
|
+
## Open-Meteo (fallback, JSON)
|
|
41
|
+
|
|
42
|
+
Free, no key, good for programmatic use:
|
|
43
|
+
```bash
|
|
44
|
+
curl -s "https://api.open-meteo.com/v1/forecast?latitude=51.5&longitude=-0.12¤t_weather=true"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Find coordinates for a city, then query. Returns JSON with temp, windspeed, weathercode.
|
|
48
|
+
|
|
49
|
+
Docs: https://open-meteo.com/en/docs
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Agent Instructions
|
|
2
|
+
|
|
3
|
+
You are a helpful AI assistant. Be concise, accurate, and friendly.
|
|
4
|
+
|
|
5
|
+
## Scheduled Reminders
|
|
6
|
+
|
|
7
|
+
When user asks for a reminder at a specific time, use `exec` to run:
|
|
8
|
+
```
|
|
9
|
+
pretticlaw cron add --name "reminder" --message "Your message" --at "YYYY-MM-DDTHH:MM:SS" --deliver --to "USER_ID" --channel "CHANNEL"
|
|
10
|
+
```
|
|
11
|
+
Get USER_ID and CHANNEL from the current session (e.g., `8281248569` and `telegram` from `telegram:8281248569`).
|
|
12
|
+
|
|
13
|
+
**Do NOT just write reminders to MEMORY.md** — that won't trigger actual notifications.
|
|
14
|
+
|
|
15
|
+
## Heartbeat Tasks
|
|
16
|
+
|
|
17
|
+
`HEARTBEAT.md` is checked every 30 minutes. Use file tools to manage periodic tasks:
|
|
18
|
+
|
|
19
|
+
- **Add**: `edit_file` to append new tasks
|
|
20
|
+
- **Remove**: `edit_file` to delete completed tasks
|
|
21
|
+
- **Rewrite**: `write_file` to replace all tasks
|
|
22
|
+
|
|
23
|
+
When the user asks for a recurring/periodic task, update `HEARTBEAT.md` instead of creating a one-time cron reminder.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Heartbeat Tasks
|
|
2
|
+
|
|
3
|
+
This file is checked every 30 minutes by your pretticlaw agent.
|
|
4
|
+
Add tasks below that you want the agent to work on periodically.
|
|
5
|
+
|
|
6
|
+
If this file has no tasks (only headers and comments), the agent will skip the heartbeat.
|
|
7
|
+
|
|
8
|
+
## Active Tasks
|
|
9
|
+
|
|
10
|
+
<!-- Add your periodic tasks below this line -->
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Completed
|
|
14
|
+
|
|
15
|
+
<!-- Move completed tasks here or delete them -->
|
|
16
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Soul
|
|
2
|
+
|
|
3
|
+
I am pretticlaw 💅, a personal AI assistant.
|
|
4
|
+
|
|
5
|
+
## Personality
|
|
6
|
+
|
|
7
|
+
- Helpful and friendly
|
|
8
|
+
- Concise and to the point
|
|
9
|
+
- Curious and eager to learn
|
|
10
|
+
|
|
11
|
+
## Values
|
|
12
|
+
|
|
13
|
+
- Accuracy over speed
|
|
14
|
+
- User privacy and safety
|
|
15
|
+
- Transparency in actions
|
|
16
|
+
|
|
17
|
+
## Communication Style
|
|
18
|
+
|
|
19
|
+
- Be clear and direct
|
|
20
|
+
- Explain reasoning when helpful
|
|
21
|
+
- Ask clarifying questions when needed
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Tool Usage Notes
|
|
2
|
+
|
|
3
|
+
Tool signatures are provided automatically via function calling.
|
|
4
|
+
This file documents non-obvious constraints and usage patterns.
|
|
5
|
+
|
|
6
|
+
## exec — Safety Limits
|
|
7
|
+
|
|
8
|
+
- Commands have a configurable timeout (default 60s)
|
|
9
|
+
- Dangerous commands are blocked (rm -rf, format, dd, shutdown, etc.)
|
|
10
|
+
- Output is truncated at 10,000 characters
|
|
11
|
+
- `restrictToWorkspace` config can limit file access to the workspace
|
|
12
|
+
|
|
13
|
+
## cron — Scheduled Reminders
|
|
14
|
+
|
|
15
|
+
- Please refer to cron skill for usage.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# User Profile
|
|
2
|
+
|
|
3
|
+
Information about the user to help personalize interactions.
|
|
4
|
+
|
|
5
|
+
## Basic Information
|
|
6
|
+
|
|
7
|
+
- **Name**: (your name)
|
|
8
|
+
- **Timezone**: (your timezone, e.g., UTC+8)
|
|
9
|
+
- **Language**: (preferred language)
|
|
10
|
+
|
|
11
|
+
## Preferences
|
|
12
|
+
|
|
13
|
+
### Communication Style
|
|
14
|
+
|
|
15
|
+
- [ ] Casual
|
|
16
|
+
- [ ] Professional
|
|
17
|
+
- [ ] Technical
|
|
18
|
+
|
|
19
|
+
### Response Length
|
|
20
|
+
|
|
21
|
+
- [ ] Brief and concise
|
|
22
|
+
- [ ] Detailed explanations
|
|
23
|
+
- [ ] Adaptive based on question
|
|
24
|
+
|
|
25
|
+
### Technical Level
|
|
26
|
+
|
|
27
|
+
- [ ] Beginner
|
|
28
|
+
- [ ] Intermediate
|
|
29
|
+
- [ ] Expert
|
|
30
|
+
|
|
31
|
+
## Work Context
|
|
32
|
+
|
|
33
|
+
- **Primary Role**: (your role, e.g., developer, researcher)
|
|
34
|
+
- **Main Projects**: (what you're working on)
|
|
35
|
+
- **Tools You Use**: (IDEs, languages, frameworks)
|
|
36
|
+
|
|
37
|
+
## Topics of Interest
|
|
38
|
+
|
|
39
|
+
-
|
|
40
|
+
-
|
|
41
|
+
-
|
|
42
|
+
|
|
43
|
+
## Special Instructions
|
|
44
|
+
|
|
45
|
+
(Any specific instructions for how the assistant should behave)
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
*Edit this file to customize pretticlaw's behavior for your needs.*
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Long-term Memory
|
|
2
|
+
|
|
3
|
+
This file stores important information that should persist across sessions.
|
|
4
|
+
|
|
5
|
+
## User Information
|
|
6
|
+
|
|
7
|
+
(Important facts about the user)
|
|
8
|
+
|
|
9
|
+
## Preferences
|
|
10
|
+
|
|
11
|
+
(User preferences learned over time)
|
|
12
|
+
|
|
13
|
+
## Project Context
|
|
14
|
+
|
|
15
|
+
(Information about ongoing projects)
|
|
16
|
+
|
|
17
|
+
## Important Notes
|
|
18
|
+
|
|
19
|
+
(Things to remember)
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
*This file is automatically updated by pretticlaw when important information should be remembered.*
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function ensureDir(dir: string): string;
|
|
2
|
+
export declare function getDataPath(): string;
|
|
3
|
+
export declare function getWorkspacePath(workspace?: string): string;
|
|
4
|
+
export declare function safeFilename(name: string): string;
|
|
5
|
+
export declare function syncWorkspaceTemplates(workspace: string, silent?: boolean): string[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
const UNSAFE = /[<>:"/\\|?*]/g;
|
|
6
|
+
export function ensureDir(dir) {
|
|
7
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
8
|
+
return dir;
|
|
9
|
+
}
|
|
10
|
+
export function getDataPath() {
|
|
11
|
+
return ensureDir(path.join(os.homedir(), ".pretticlaw"));
|
|
12
|
+
}
|
|
13
|
+
export function getWorkspacePath(workspace) {
|
|
14
|
+
const p = workspace ? workspace.replace(/^~(?=$|[\\/])/, os.homedir()) : path.join(os.homedir(), ".pretticlaw", "workspace");
|
|
15
|
+
return ensureDir(path.resolve(p));
|
|
16
|
+
}
|
|
17
|
+
export function safeFilename(name) {
|
|
18
|
+
return name.replace(UNSAFE, "_").trim();
|
|
19
|
+
}
|
|
20
|
+
export function syncWorkspaceTemplates(workspace, silent = false) {
|
|
21
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
22
|
+
const candidates = [
|
|
23
|
+
path.resolve(here, "../templates"),
|
|
24
|
+
path.resolve(here, "../../src/templates"),
|
|
25
|
+
path.resolve(process.cwd(), "dist/templates"),
|
|
26
|
+
path.resolve(process.cwd(), "src/templates"),
|
|
27
|
+
];
|
|
28
|
+
const templates = candidates.find((p) => fs.existsSync(path.join(p, "AGENTS.md")));
|
|
29
|
+
if (!templates)
|
|
30
|
+
return [];
|
|
31
|
+
const created = [];
|
|
32
|
+
const writeIfMissing = (src, dest) => {
|
|
33
|
+
if (fs.existsSync(dest))
|
|
34
|
+
return;
|
|
35
|
+
ensureDir(path.dirname(dest));
|
|
36
|
+
if (src)
|
|
37
|
+
fs.copyFileSync(src, dest);
|
|
38
|
+
else
|
|
39
|
+
fs.writeFileSync(dest, "", "utf8");
|
|
40
|
+
created.push(path.relative(workspace, dest));
|
|
41
|
+
};
|
|
42
|
+
const md = ["AGENTS.md", "SOUL.md", "USER.md", "TOOLS.md", "HEARTBEAT.md"];
|
|
43
|
+
for (const f of md)
|
|
44
|
+
writeIfMissing(path.join(templates, f), path.join(workspace, f));
|
|
45
|
+
writeIfMissing(path.join(templates, "memory", "MEMORY.md"), path.join(workspace, "memory", "MEMORY.md"));
|
|
46
|
+
writeIfMissing(null, path.join(workspace, "memory", "HISTORY.md"));
|
|
47
|
+
ensureDir(path.join(workspace, "skills"));
|
|
48
|
+
if (!silent) {
|
|
49
|
+
for (const item of created)
|
|
50
|
+
console.log(` Created ${item}`);
|
|
51
|
+
}
|
|
52
|
+
return created;
|
|
53
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AgentLoop } from "../agent/loop.js";
|
|
2
|
+
import type { CronService } from "../cron/service.js";
|
|
3
|
+
import type { Config } from "../config/schema.js";
|
|
4
|
+
import type { SessionManager } from "../session/manager.js";
|
|
5
|
+
export declare function startDashboardServer(input: {
|
|
6
|
+
agent: AgentLoop;
|
|
7
|
+
cron: CronService;
|
|
8
|
+
config: Config;
|
|
9
|
+
sessionManager: SessionManager;
|
|
10
|
+
sessionKey: string;
|
|
11
|
+
port?: number;
|
|
12
|
+
}): {
|
|
13
|
+
close: () => Promise<void>;
|
|
14
|
+
port: number;
|
|
15
|
+
};
|