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
11 changes: 7 additions & 4 deletions bin/gstack-skill-end
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ _GH="$_gstack_sr_root"
_TEL=$("$_BIN/gstack-config" get telemetry 2>/dev/null || echo off)
# Plan B1: an unattended session writes no usage, sends no telemetry and never
# drains or pushes the artifacts queue, whatever the inherited settings say. The
# upgrade offer it skipped at start becomes one line here, read from the
# one exception is gstack's own use on Capy: the owner's preferences file can
# opt Capy sessions in at the anonymous tier (gstack-telemetry-tier --capy).
# The upgrade offer it skipped at start becomes one line here, read from the
# update-check cache (no network) so the parent can act on it.
_SESSION_KIND=$("$_BIN/gstack-session-kind" 2>/dev/null || echo "interactive")
if [ "$_SESSION_KIND" = "unattended" ]; then
_TEL="off"
_TEL=$("$_BIN/gstack-telemetry-tier" --capy 2>/dev/null || echo off)
_CACHED_UPD=$(head -1 "$_GH/last-update-check" 2>/dev/null | tr -cd 'A-Za-z0-9._+ ' || true)
case "$_CACHED_UPD" in
UPGRADE_AVAILABLE*) echo "UPGRADE_AVAILABLE: $(printf '%s\n' "$_CACHED_UPD" | awk '{ print $3 (NF >= 4 ? " (main at " $4 ")" : "") }'); run /gstack-upgrade"
Expand Down Expand Up @@ -79,8 +81,9 @@ if [ "$_SESSION_KIND" != "unattended" ]; then
"$_BIN/gstack-brain-sync" --once 2>/dev/null || true
fi

# Local analytics (gated on telemetry setting).
if [ "$_TEL" != "off" ]; then
# Local analytics (gated on telemetry setting; an opted-in Capy session sends
# its one telemetry row below and still records no usage of its own).
if [ "$_TEL" != "off" ] && [ "$_SESSION_KIND" != "unattended" ]; then
echo '{"skill":"'"$SKILL_NAME"'","duration_s":"'"$_TEL_DUR"'","outcome":"'"$OUTCOME"'","browse":"'"$USED_BROWSE"'","session":"'"$SESSION_ID"'","ts":"'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"}' >> "$_GH/analytics/skill-usage.jsonl" 2>/dev/null || true
fi

Expand Down
10 changes: 7 additions & 3 deletions bin/gstack-telemetry-log
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,21 @@ while [ $# -gt 0 ]; do
done

# Source: flag > GSTACK_TELEMETRY_SOURCE > an eval run (the eval harness sets
# EVALS_RUN_ID or GSTACK_EVAL_DIR) > CI > live. An explicit value always wins,
# so CI=true never relabels a row a test marked source=test.
# EVALS_RUN_ID or GSTACK_EVAL_DIR) > CI > Capy (GSTACK_CAPY=1, gstack's own
# use on Capy: capy, or gt from the owner's preferences file, never free text)
# > live. An explicit value always wins, so CI=true never relabels a row a test
# marked source=test, and an eval lane on Capy stays eval.
if [ -z "$SOURCE" ]; then
if [ -n "${GSTACK_TELEMETRY_SOURCE:-}" ]; then SOURCE="$GSTACK_TELEMETRY_SOURCE"
elif [ -n "${EVALS_RUN_ID:-}" ] || [ -n "${GSTACK_EVAL_DIR:-}" ]; then SOURCE="eval"
elif [ "${CI:-}" = "true" ]; then SOURCE="ci"
elif [ "${GSTACK_CAPY:-}" = "1" ]; then SOURCE="$("$GSTACK_DIR/bin/gstack-telemetry-tier" --source 2>/dev/null || echo capy)"
else SOURCE="live"; fi
fi

# ─── Read telemetry tier ─────────────────────────────────────
TIER="$("$CONFIG_CMD" get telemetry 2>/dev/null || true)"
# gstack-telemetry-tier adds the Capy opt-in to this machine's setting.
TIER="$("$GSTACK_DIR/bin/gstack-telemetry-tier" 2>/dev/null || "$CONFIG_CMD" get telemetry 2>/dev/null || true)"
TIER="${TIER:-off}"

# Validate tier
Expand Down
3 changes: 2 additions & 1 deletion bin/gstack-telemetry-sync
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ if [ -f "$RATE_FILE" ]; then
fi

# ─── Read tier ───────────────────────────────────────────────
TIER="$("$CONFIG_CMD" get telemetry 2>/dev/null || true)"
# gstack-telemetry-tier adds the Capy opt-in to this machine's setting.
TIER="$("$GSTACK_DIR/bin/gstack-telemetry-tier" 2>/dev/null || "$CONFIG_CMD" get telemetry 2>/dev/null || true)"
TIER="${TIER:-off}"
[ "$TIER" = "off" ] && exit 0

Expand Down
47 changes: 47 additions & 0 deletions bin/gstack-telemetry-tier
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# gstack-telemetry-tier — the tier this session's telemetry goes out at, and
# the label a Capy session's rows carry.
#
# gstack-telemetry-tier → off | anonymous | community
# gstack-telemetry-tier --capy → the Capy opt-in alone: anonymous | off
# gstack-telemetry-tier --source → the Capy label: capy | gt
#
# A Capy session (GSTACK_CAPY=1) is opted in only by the owner's preferences
# file (GSTACK_PREFERENCES_FILE, beside the Capy skill's SKILL.md) holding
# exactly one `telemetry_capy: anonymous` line. It then sends at the anonymous
# tier whatever this machine's `telemetry` setting says. Only anonymous:
# community's installation_id is a stable device id, and Capy's consent rules
# one out (docs/privacy.md). No file, no line, two lines, another value or a
# file over 4 KB is off. Without the opt-in this prints the machine's setting.
# Unattended sessions stay silent unless opted in: gstack-skill-end asks --capy.
#
# gstack-telemetry-log labels a Capy session's rows from a fixed list:
# `telemetry_capy_source: gt` (gstack's maintainer's own machines) gives gt,
# and anything else, a missing line included, gives capy.

# pref KEY → the value of the file's one `KEY:` line, empty when there is not exactly one.
pref() {
local f="${GSTACK_PREFERENCES_FILE:-}" bom lines
[ "${GSTACK_CAPY:-}" = "1" ] && [ -n "$f" ] && [ -f "$f" ] || return 0
[ "$(wc -c < "$f" 2>/dev/null || echo 4097)" -le 4096 ] || return 0
bom=$(printf '\357\273\277')
lines=$(LC_ALL=C sed -e "1s/^$bom//" "$f" 2>/dev/null | tr -d '\r' | grep -E "^$1:" || true)
[ -n "$lines" ] && [ "$(printf '%s\n' "$lines" | wc -l | tr -d ' ')" = 1 ] || return 0
printf '%s' "${lines#"$1":}" | sed -e 's/[[:space:]]#.*$//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e "s/^\([\"']\)\(.*\)\1\$/\2/"
}

if [ "${1:-}" = "--source" ]; then
case "$(pref telemetry_capy_source)" in gt) echo gt ;; *) echo capy ;; esac
exit 0
fi
capy=off
[ "$(pref telemetry_capy)" = anonymous ] && capy=anonymous
if [ "${1:-}" = "--capy" ] || [ "$capy" != off ]; then
echo "$capy"
exit 0
fi
tier=$("$(dirname "$0")/gstack-config" get telemetry 2>/dev/null || true)
case "$tier" in
anonymous|community) echo "$tier" ;;
*) echo off ;;
esac
1 change: 1 addition & 0 deletions changelog.d/capy-telemetry-opt-in.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**gstack's own use on Capy can be counted, and is kept out of real-use numbers.** Agent-driven sessions on Capy still send no telemetry by default. When the owner's `preferences.yaml` beside the Capy gstack skill holds `telemetry_capy: anonymous`, each skill run there sends one row at the anonymous tier (no device ID, even on a machine set to `community`), labelled `source=capy`, or `source=gt` with `telemetry_capy_source: gt`. Eval and CI labels still win on Capy, unattended sessions elsewhere are unchanged, the ingest function accepts both labels, and the public dashboard's views count only `live` rows. `bin/gstack-telemetry-tier` is the one place that reads these settings.
3 changes: 2 additions & 1 deletion docs/capy-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ When the session starts from the Drive skill (a bootstrapper outside the
checkout), the file also exports `GSTACK_PREFERENCES_FILE`, the path of
`preferences.yaml` beside that skill's SKILL.md, which the `GSTACK_LAUNCH` line
leaves out; `gstack-models resolve --role agent` reads it
([your model preference](model-policy.md#your-model-preference)).
([your model preference](model-policy.md#your-model-preference)), and
`gstack-telemetry-tier` reads its Capy telemetry opt-in ([privacy](privacy.md)).
The file is part of the ok verdict: a passing run that cannot write it exits 1
with `gstack: fail launch-file — could not write the launch file <path>; fix:
make <dir> writable, or set GSTACK_STATE_ROOT to a writable directory
Expand Down
5 changes: 4 additions & 1 deletion docs/model-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ A value gstack can't use stops only the agent role, naming the file and the fix.
**On Capy.** Each cloud machine starts fresh, so config.yaml does not carry
over. Keep the preference in `preferences.yaml` next to the gstack skill's
SKILL.md in your Drive: one `agent_model: <value>` line, with `#` comments
allowed (any other key is ignored with a warning). The session start puts the
allowed. The file may also hold `telemetry_capy: anonymous`, which opts gstack's
own Capy sessions in to anonymous telemetry, and `telemetry_capy_source: gt`,
which labels those rows `gt` ([privacy](privacy.md)); any other key is ignored
with a warning. The session start puts the
file's path in the launch file as `GSTACK_PREFERENCES_FILE` and gstack reads it
where it is: nothing is copied, and `--check` never writes the skill folder. Agents write that
file only when you ask them to remember a preference. To change or clear it for
Expand Down
10 changes: 9 additions & 1 deletion docs/privacy.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,16 @@ no, and `gstack-config set telemetry off` turns it off at any time.
`other`) and the version you came from. `--check` and unattended
sessions send nothing.
- `source` is set to `ci` under CI and `eval` inside gstack's eval runs,
so lab traffic stays out of real-use numbers. A duration gstack can't
so lab traffic stays out of real-use numbers. gstack's own use on Capy is
labelled `capy` (or `gt`, below) and kept out of them too. A duration gstack can't
measure is sent empty instead of 0.
- **On Capy:** sessions an agent drives there send nothing unless the owner's
`preferences.yaml` beside the Capy gstack skill holds the line
`telemetry_capy: anonymous`. Then each skill run sends one row at the
`anonymous` tier (no device ID, even on a machine set to `community`),
labelled `capy`. Any other value, or two such lines, is off. A second line,
`telemetry_capy_source: gt`, labels the rows `gt` instead (gstack's
maintainer's own machines); any other label is `capy`.
- **What's never sent:** code, file paths, repo names, branch names, prompts,
or any other content you write.
- **What stays on your machine:** opted in, each run is also logged to
Expand Down
5 changes: 4 additions & 1 deletion docs/unattended.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ drives still sets `GSTACK_SESSION_KIND=unattended` itself.
onboarding tips and routing blocks are suppressed exactly as they are for
`spawned`. An unanswered consent is `off`.
- **No publishing or sync, enforced at the writers.** Usage analytics are not
written (`TELEMETRY_WRITE: skipped (unattended session)`), the artifacts
written (`TELEMETRY_WRITE: skipped (unattended session)`; the one exception
is a Capy session the owner opted in with `telemetry_capy: anonymous`, which
sends one anonymous row per skill run labelled `capy` (or `gt`), see
[privacy](privacy.md)), the artifacts
repo is neither pulled nor pushed (`ARTIFACTS_SYNC: skipped (unattended
session; mode=<m> queue=<n> retained)`), the sync spool is not fed
(`gstack-brain-enqueue` is a no-op, and `gstack-review-log` says `review-log:
Expand Down
5 changes: 4 additions & 1 deletion lib/agent-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { readConfigKeyWithRoot, type StateRootEnv } from './state-root';

export const AGENT_MODEL_KEY = 'agent_model' as const;
export const PREFERENCES_FILE_MAX_BYTES = 4096;
/** Other keys gstack reads from the preferences file: bin/gstack-telemetry-tier reads the telemetry ones. */
const OTHER_PREFERENCE_KEYS = new Set(['telemetry_capy', 'telemetry_capy_source']);
const DOCS = 'https://github.com/garrytan/gstack/blob/main/docs/model-policy.md#your-model-preference';

/** Family names a preference may use. When gstack's tier catalog lists a family, its entry here is the same model (test/agent-model.test.ts). */
Expand Down Expand Up @@ -94,7 +96,7 @@ function invalid(value: string, where: string, repair: string[]): AgentModelErro
);
}

/** Read agent_model from a preferences file: `key: value` lines, # comments, at most 4 KB. Unknown keys warn; a duplicate agent_model is an error. */
/** Read agent_model from a preferences file: `key: value` lines, # comments, at most 4 KB. Keys gstack reads elsewhere pass silently, unknown keys warn; a duplicate agent_model is an error. */
export function readPreferencesFile(file: string): { value: string | null; warnings: string[] } {
let text: string;
try {
Expand All @@ -114,6 +116,7 @@ export function readPreferencesFile(file: string): { value: string | null; warni
if (trimmed === '' || trimmed.startsWith('#')) return;
const m = /^([a-z][a-z0-9_]*):(.*)$/.exec(line);
if (!m) { warnings.push(`${file}:${i + 1} is not a 'key: value' line; ignored`); return; }
if (OTHER_PREFERENCE_KEYS.has(m[1])) return;
if (m[1] !== AGENT_MODEL_KEY) { warnings.push(`${file}:${i + 1} sets '${sanitize(m[1])}', which gstack does not read from preferences; ignored`); return; }
if (value !== null) throw new AgentModelError(`${file} sets agent_model twice`, 'keep one agent_model line', [`edit ${file}`]);
value = m[2].replace(/\s#.*$/, '').trim().replace(/^(["'])(.*)\1$/, '$2');
Expand Down
5 changes: 3 additions & 2 deletions supabase/functions/telemetry-ingest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ function normalizeOutcome(outcome: unknown) {
}

// bin/gstack-telemetry-log writes source from --source or
// GSTACK_TELEMETRY_SOURCE (default "live"). Keep it so test and eval traffic
// GSTACK_TELEMETRY_SOURCE (default "live"). Keep it so test, eval, CI and
// gstack's own use on Capy ("capy", or "gt" from its maintainer's machines)
// can be told apart from real use; anything unexpected is "other", never "live".
const SOURCES = ["live", "test", "eval", "ci"];
const SOURCES = ["live", "test", "eval", "ci", "capy", "gt"];
function normalizeSource(source: unknown): string {
if (source === undefined || source === null || source === "") return "live";
return SOURCES.includes(String(source)) ? String(source) : "other";
Expand Down
6 changes: 6 additions & 0 deletions test/agent-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ describe('the preferences file', () => {
expect(() => readPreferencesFile(f)).toThrow(/sets agent_model twice/);
});

test('the telemetry keys are read by gstack-telemetry-tier, so they pass without a warning', () => {
const f = path.join(tmp(), 'preferences.yaml');
fs.writeFileSync(f, 'agent_model: opus\ntelemetry_capy: anonymous\ntelemetry_capy_source: gt\n');
expect(readPreferencesFile(f)).toEqual({ value: 'opus', warnings: [] });
});

test('CRLF line endings, a byte-order mark and a trailing comment still read the value', () => {
const f = path.join(tmp(), 'preferences.yaml');
fs.writeFileSync(f, '\ufeff# owner preferences\r\nagent_model: opus # my pick\r\n');
Expand Down
9 changes: 5 additions & 4 deletions test/next-telemetry-fields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ describe.skipIf(process.platform === 'win32')('gstack-telemetry-log next fields'
expect([b.harness_session_id, b.from_version]).toEqual([null, null]);
});

test('source: flag > GSTACK_TELEMETRY_SOURCE > eval run > CI > live, so CI never relabels a test row', () => {
test('source: flag > GSTACK_TELEMETRY_SOURCE > eval run > CI > Capy > live, so CI never relabels a test row', () => {
run('gstack-telemetry-log', ['--outcome', 'success', '--source', 'test'], { CI: 'true', EVALS_RUN_ID: 'r1' });
run('gstack-telemetry-log', ['--outcome', 'success'], { CI: 'true', GSTACK_TELEMETRY_SOURCE: 'test' });
run('gstack-telemetry-log', ['--outcome', 'success'], { CI: 'true', EVALS_RUN_ID: 'r1' });
run('gstack-telemetry-log', ['--outcome', 'success'], { CI: 'true' });
run('gstack-telemetry-log', ['--outcome', 'success'], { CI: 'true', EVALS_RUN_ID: 'r1', GSTACK_CAPY: '1' });
run('gstack-telemetry-log', ['--outcome', 'success'], { CI: 'true', GSTACK_CAPY: '1' });
run('gstack-telemetry-log', ['--outcome', 'success'], { GSTACK_CAPY: '1' });
run('gstack-telemetry-log', ['--outcome', 'success']);
expect(events().map(e => e.source)).toEqual(['test', 'test', 'eval', 'ci', 'live']);
expect(events().map(e => e.source)).toEqual(['test', 'test', 'eval', 'ci', 'capy', 'live']);
});
});

Expand Down
1 change: 1 addition & 0 deletions test/supabase-telemetry-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('telemetry-ingest accepts what the client sends', () => {

test('ingest stores source, so test and eval traffic stay separable', () => {
expect(INGEST).toContain('source: normalizeSource(event.source)');
expect(INGEST).toContain('const SOURCES = ["live", "test", "eval", "ci", "capy", "gt"];');
});

test('ingest writes with the service role key, the only write path once 008 drops the anon policies', () => {
Expand Down
Loading
Loading