@pxlabz/tasq-cli 0.1.30 → 0.2.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.
@@ -1,135 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Example mention runner — NOT part of the Tasq product.
3
- #
4
- # Tasq stores and delivers mentions; it never runs your agent. This script is
5
- # the smallest honest example of the harness side, which is yours to own: it
6
- # reads `tasq events listen` line by line, hands each event to a command of
7
- # your choosing through the environment, and acknowledges the event only when
8
- # that command succeeds. Copy it, rewrite it, or ignore it.
9
- #
10
- # Usage:
11
- # TASQ_API_KEY=tq_ag_… \
12
- # TASQ_WORKSPACE=acme \
13
- # TASQ_AGENT_CMD='claude -p "handle $TASQ_EVENT_TASK_KEY"' \
14
- # ./mention-runner.sh [--wait 20]
15
- #
16
- # Environment:
17
- # TASQ_AGENT_CMD Required. Shell command run once per event, with the
18
- # TASQ_EVENT_* variables below exported into it.
19
- # TASQ_API_KEY The agent key. TASQ_WORKSPACE and TASQ_API_URL are read by
20
- # the CLI itself; see `tasq --help`.
21
- #
22
- # Exported per event:
23
- # TASQ_EVENT_ID, TASQ_EVENT_KIND, TASQ_EVENT_TASK_KEY, TASQ_EVENT_TASK_ID,
24
- # TASQ_EVENT_PROJECT_ID, TASQ_EVENT_THREAD_ID, TASQ_EVENT_COMMENT_ID,
25
- # TASQ_EVENT_MENTIONED_BY, TASQ_EVENT_MENTIONED_BY_TYPE
26
- #
27
- # Event kinds: `mention` is a request addressed to the agent; `thread_message`
28
- # is a follow-up in a thread it already joined. An unrecognised kind is acked
29
- # and skipped rather than handed to a command that was never written for it.
30
- #
31
- # On a team whose admin has turned agent isolation off, an author can be
32
- # another agent: `mentionedBy.type` is `agent` rather than `user`. This runner
33
- # takes an agent's `mention` as a real request — it names us — but acks an
34
- # agent's `thread_message` without invoking the harness, because answering
35
- # every agent turn is how two agents talk to each other forever. Tasq stops
36
- # waking agents after five agent messages in a row in a thread and never wakes
37
- # more than ten from one message, but the cheapest loop is the one that never
38
- # starts. Change this if your agents are meant to converse.
39
- #
40
- # Acking is deliberate: an event the command failed on is left unacked, and
41
- # Tasq offers it again ten minutes later. A crash loses no work.
42
-
43
- set -euo pipefail
44
-
45
- : "${TASQ_AGENT_CMD:?Set TASQ_AGENT_CMD to the command that handles one event}"
46
-
47
- TASQ_BIN="${TASQ_BIN:-tasq}"
48
-
49
- # jq if it is there, a node one-liner if it is not. Both print the field's
50
- # value, or an empty line when the field is null or missing.
51
- if command -v jq > /dev/null 2>&1; then
52
- field() { printf '%s' "$1" | jq -r --arg f "$2" '.[$f] // empty'; }
53
- else
54
- field() {
55
- printf '%s' "$1" | node -e '
56
- let raw = ""
57
- process.stdin.on("data", (chunk) => { raw += chunk })
58
- process.stdin.on("end", () => {
59
- const value = JSON.parse(raw)[process.argv[1]]
60
- process.stdout.write(value == null ? "" : String(value))
61
- })
62
- ' "$2"
63
- }
64
- fi
65
-
66
- "$TASQ_BIN" events listen "$@" | while IFS= read -r event; do
67
- [[ -z "$event" ]] && continue
68
-
69
- TASQ_EVENT_ID="$(field "$event" id)"
70
- TASQ_EVENT_KIND="$(field "$event" kind)"
71
- TASQ_EVENT_TASK_KEY="$(field "$event" taskKey)"
72
- TASQ_EVENT_TASK_ID="$(field "$event" taskId)"
73
- TASQ_EVENT_PROJECT_ID="$(field "$event" projectId)"
74
- TASQ_EVENT_THREAD_ID="$(field "$event" threadId)"
75
- TASQ_EVENT_COMMENT_ID="$(field "$event" commentId)"
76
- # `mentionedBy` is an object, so it needs its own reader rather than `field`.
77
- mentioned_by() {
78
- printf '%s' "$1" | {
79
- if command -v jq > /dev/null 2>&1; then
80
- jq -r --arg f "$2" '.mentionedBy[$f] // empty'
81
- else
82
- node -e '
83
- let raw = ""
84
- process.stdin.on("data", (chunk) => { raw += chunk })
85
- process.stdin.on("end", () => {
86
- const by = JSON.parse(raw).mentionedBy
87
- const value = by == null ? null : by[process.argv[1]]
88
- process.stdout.write(value == null ? "" : String(value))
89
- })
90
- ' "$2"
91
- fi
92
- }
93
- }
94
-
95
- TASQ_EVENT_MENTIONED_BY="$(mentioned_by "$event" name)"
96
- TASQ_EVENT_MENTIONED_BY_TYPE="$(mentioned_by "$event" type)"
97
-
98
- export TASQ_EVENT_ID TASQ_EVENT_KIND TASQ_EVENT_TASK_KEY \
99
- TASQ_EVENT_TASK_ID TASQ_EVENT_PROJECT_ID TASQ_EVENT_THREAD_ID \
100
- TASQ_EVENT_COMMENT_ID TASQ_EVENT_MENTIONED_BY \
101
- TASQ_EVENT_MENTIONED_BY_TYPE
102
-
103
- TASQ_EVENT_ENTITY="${TASQ_EVENT_TASK_KEY:-${TASQ_EVENT_PROJECT_ID:-?}}"
104
-
105
- echo "→ ${TASQ_EVENT_KIND} on ${TASQ_EVENT_ENTITY} (${TASQ_EVENT_ID})" >&2
106
-
107
- case "$TASQ_EVENT_KIND" in
108
- mention | thread_message)
109
- # An agent's follow-up in a thread is context, not a request: ack it and
110
- # move on. An agent's `mention` still names us, so it is handled below.
111
- if [[ "$TASQ_EVENT_MENTIONED_BY_TYPE" == "agent" \
112
- && "$TASQ_EVENT_KIND" == "thread_message" ]]; then
113
- echo " thread message from agent ${TASQ_EVENT_MENTIONED_BY:-?}; context only, skipping" >&2
114
- "$TASQ_BIN" events ack "$TASQ_EVENT_ID"
115
-
116
- continue
117
- fi
118
-
119
- # `set -e` must not kill the loop on a handler failure: the whole point
120
- # is to leave that event unacked and keep listening.
121
- if sh -c "$TASQ_AGENT_CMD"; then
122
- "$TASQ_BIN" events ack "$TASQ_EVENT_ID"
123
- else
124
- echo " handler failed; leaving ${TASQ_EVENT_ID} unacked for redelivery" >&2
125
- fi
126
- ;;
127
- *)
128
- # A kind this runner predates. Acking clears it from the queue rather
129
- # than letting Tasq redeliver it every ten minutes forever; teach the
130
- # case above about it before the handler can do anything useful with it.
131
- echo " unknown event kind \"${TASQ_EVENT_KIND}\"; acking and skipping" >&2
132
- "$TASQ_BIN" events ack "$TASQ_EVENT_ID"
133
- ;;
134
- esac
135
- done
@@ -1,142 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Example release narrator — NOT part of the Tasq product.
3
- #
4
- # Tasq writes the release row itself on every cycle close and then sends one
5
- # `cycle_closed` event to the team's release narrator, if one is set. This
6
- # script is the smallest honest example of the harness side of that loop: it
7
- # reads `tasq events listen` line by line, and for each `cycle_closed` it
8
- # pulls the release context, writes a narrative, saves it, and acks.
9
- #
10
- # The narrative it writes is a PLACEHOLDER assembled from the context itself.
11
- # This script calls no model and has no opinion about what a release means —
12
- # that is the part you replace. Set TASQ_NARRATOR_CMD to a command that reads
13
- # the context on stdin and writes the narrative on stdout, and this runner
14
- # will use it instead.
15
- #
16
- # Usage:
17
- # TASQ_API_KEY=tq_ag_… \
18
- # TASQ_WORKSPACE=acme \
19
- # TASQ_NARRATOR_CMD='claude -p "write a release narrative from this context"' \
20
- # ./release-narrator.sh [--wait 20]
21
- #
22
- # Environment:
23
- # TASQ_NARRATOR_CMD Optional. Command run per release, with the release's
24
- # Markdown context on stdin; its stdout becomes the
25
- # narrative. Unset, the placeholder below is used.
26
- # TASQ_API_KEY The agent key. TASQ_WORKSPACE and TASQ_API_URL are read
27
- # by the CLI itself; see `tasq --help`.
28
- #
29
- # Only `cycle_closed` is handled here. A `mention` or `thread_message` reaching
30
- # this key is left UNACKED on purpose: it is a conversation, this runner is not
31
- # one, and Tasq will offer it again in ten minutes to whatever does handle it.
32
- # Run `mention-runner.sh` beside this one if the same agent does both.
33
- #
34
- # Acking is deliberate: an event whose narrate failed is left unacked and comes
35
- # back in ten minutes. Saving twice is harmless — the narrative is one field
36
- # with last write wins, so a retry overwrites rather than duplicating.
37
-
38
- set -euo pipefail
39
-
40
- TASQ_BIN="${TASQ_BIN:-tasq}"
41
-
42
- # jq if it is there, a node one-liner if it is not. Both print the field's
43
- # value, or an empty line when the field is null or missing.
44
- if command -v jq > /dev/null 2>&1; then
45
- field() { printf '%s' "$1" | jq -r --arg f "$2" '.[$f] // empty'; }
46
- else
47
- field() {
48
- printf '%s' "$1" | node -e '
49
- let raw = ""
50
- process.stdin.on("data", (chunk) => { raw += chunk })
51
- process.stdin.on("end", () => {
52
- const value = JSON.parse(raw)[process.argv[1]]
53
- process.stdout.write(value == null ? "" : String(value))
54
- })
55
- ' "$2"
56
- }
57
- fi
58
-
59
- # The placeholder narrative: the context's own counts and shipped list, turned
60
- # into three lines of prose-shaped text. It exists so the loop can be run end
61
- # to end without a model attached, and so a reader can see exactly which part
62
- # of this script is the part that thinks. It is not one.
63
- placeholder_narrative() {
64
- local context="$1" summary
65
-
66
- summary="$(printf '%s' "$context" | grep '^- Shipped ' | head -1)"
67
-
68
- printf '%s\n' "## Release notes"
69
- printf '\n'
70
- printf '%s\n' "${summary:-- No counts in the context.}"
71
- printf '\n'
72
- printf '%s\n' "Shipped this cycle:"
73
- printf '\n'
74
- # The context's Shipped section, up to the next heading.
75
- printf '%s' "$context" | awk '
76
- /^## Shipped$/ { inside = 1; next }
77
- /^## / { inside = 0 }
78
- inside && /^- / { print }
79
- '
80
- printf '\n'
81
- printf '%s\n' "_Written by the example narrator, which does not read._"
82
- }
83
-
84
- "$TASQ_BIN" events listen "$@" | while IFS= read -r event; do
85
- [[ -z "$event" ]] && continue
86
-
87
- TASQ_EVENT_ID="$(field "$event" id)"
88
- TASQ_EVENT_KIND="$(field "$event" kind)"
89
- TASQ_EVENT_RELEASE_ID="$(field "$event" releaseId)"
90
-
91
- if [[ "$TASQ_EVENT_KIND" != "cycle_closed" ]]; then
92
- echo "→ ${TASQ_EVENT_KIND} (${TASQ_EVENT_ID}); not a release, leaving it unacked" >&2
93
-
94
- continue
95
- fi
96
-
97
- if [[ -z "$TASQ_EVENT_RELEASE_ID" ]]; then
98
- echo "→ cycle_closed ${TASQ_EVENT_ID} carried no releaseId; acking and skipping" >&2
99
- "$TASQ_BIN" events ack "$TASQ_EVENT_ID"
100
-
101
- continue
102
- fi
103
-
104
- echo "→ cycle_closed on release ${TASQ_EVENT_RELEASE_ID} (${TASQ_EVENT_ID})" >&2
105
-
106
- # `set -e` must not kill the loop on a failed read: leave the event unacked
107
- # and keep listening, the same contract the mention runner keeps.
108
- if ! context="$("$TASQ_BIN" release context "$TASQ_EVENT_RELEASE_ID")"; then
109
- echo " could not read the context; leaving ${TASQ_EVENT_ID} unacked" >&2
110
-
111
- continue
112
- fi
113
-
114
- if [[ -n "${TASQ_NARRATOR_CMD:-}" ]]; then
115
- if ! narrative="$(printf '%s' "$context" | sh -c "$TASQ_NARRATOR_CMD")"; then
116
- echo " narrator command failed; leaving ${TASQ_EVENT_ID} unacked" >&2
117
-
118
- continue
119
- fi
120
- else
121
- narrative="$(placeholder_narrative "$context")"
122
- fi
123
-
124
- if [[ -z "${narrative//[[:space:]]/}" ]]; then
125
- echo " the narrative came back empty; leaving ${TASQ_EVENT_ID} unacked" >&2
126
-
127
- continue
128
- fi
129
-
130
- # `--file` rather than `--body`: a narrative is Markdown with newlines in it,
131
- # and a temporary file keeps it off the argument list and out of `ps`.
132
- body_file="$(mktemp -t tasq-narrative.XXXXXX)"
133
- printf '%s' "$narrative" > "$body_file"
134
-
135
- if "$TASQ_BIN" release narrate "$TASQ_EVENT_RELEASE_ID" --file "$body_file"; then
136
- "$TASQ_BIN" events ack "$TASQ_EVENT_ID"
137
- else
138
- echo " narrate failed; leaving ${TASQ_EVENT_ID} unacked for redelivery" >&2
139
- fi
140
-
141
- rm -f "$body_file"
142
- done