Skip to content

Commit fd4d933

Browse files
feat: report starter_action_picked from the TUI starter
One row per selection in either TUI starter dialog: the action, the prompt's index, and the starter's own workspace, never the prompt text. Nothing before the starter arrives. The served starter now carries its workspace id. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01YNasdD5tQMNtzXsuMEy82X
1 parent ead39c6 commit fd4d933

5 files changed

Lines changed: 204 additions & 2 deletions

File tree

‎packages/opencode/src/altimate/telemetry/index.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,16 @@ export namespace Telemetry {
622622
knowledge: string
623623
memory_enabled?: boolean
624624
}
625+
| {
626+
/** One selection from the TUI's workspace starter: a suggested prompt, open in browser, or done. */
627+
type: "starter_action_picked"
628+
timestamp: number
629+
session_id: string
630+
workspace_id: number
631+
action: "prompt" | "open" | "done"
632+
/** 0-based position of the suggested prompt; only for `prompt`. The prompt's text is never sent. */
633+
prompt_index?: number
634+
}
625635
| {
626636
/** A memory block was written back to the bound workspace's cloud memory. */
627637
type: "workspace_memory_contributed"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// altimate_change - new file
2+
//
3+
// `starter_action_picked`: what the user chose from the workspace starter in the TUI. Kept apart from
4+
// `starter.ts`, which the TUI imports for its type only: building a starter loads the skill module and
5+
// the workspace service client, which the TUI's thread does not otherwise load.
6+
import { Telemetry } from "@/altimate/telemetry"
7+
import type { Starter } from "./starter"
8+
9+
export type StarterAction = "prompt" | "open" | "done"
10+
11+
export interface StarterPick {
12+
action: StarterAction
13+
/** Which suggested prompt, 0-based; only for `prompt`. */
14+
promptIndex?: number
15+
}
16+
17+
/** A starter dialog option's value (`prompt:<i>`, `open`, `done`) as the action it picks; null for any
18+
* other value. Pure. */
19+
export function starterPick(value: string): StarterPick | null {
20+
if (value === "open" || value === "done") return { action: value }
21+
const match = /^prompt:(\d+)$/.exec(value)
22+
if (!match) return null
23+
const index = Number(match[1])
24+
return Number.isSafeInteger(index) ? { action: "prompt", promptIndex: index } : null
25+
}
26+
27+
/** The row for a pick: the action, the prompt's index for a prompt, and the workspace. Never the prompt's text. */
28+
export function starterActionPickedEvent(workspaceId: number, pick: StarterPick, sessionID?: string): Telemetry.Event {
29+
return {
30+
type: "starter_action_picked",
31+
timestamp: Date.now(),
32+
session_id: sessionID ?? Telemetry.getContext().sessionId,
33+
workspace_id: workspaceId,
34+
action: pick.action,
35+
...(pick.action === "prompt" && pick.promptIndex !== undefined ? { prompt_index: pick.promptIndex } : {}),
36+
}
37+
}
38+
39+
/** Track one selection from a starter dialog. `starter` is what the dialog shows; null while it has not
40+
* arrived, when the dialog is the bare link confirmation and a selection is no starter outcome. The row names
41+
* the starter's own workspace, the one its `starter_shown` row named. Nothing for a value that is not a
42+
* starter action or a workspace id that is not a positive integer. Never throws. */
43+
export function trackStarterActionPicked(starter: Pick<Starter, "workspaceId"> | null, value: string): boolean {
44+
try {
45+
const workspaceId = starter?.workspaceId
46+
const pick = starterPick(value)
47+
if (!pick || workspaceId === undefined || !Number.isInteger(workspaceId) || workspaceId <= 0) return false
48+
Telemetry.track(starterActionPickedEvent(workspaceId, pick))
49+
return true
50+
} catch {
51+
return false
52+
}
53+
}

‎packages/opencode/src/altimate/workspace/starter.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export interface Starter {
1919
prompts: string[]
2020
/** The whole message as plain text, for a terminal or a chat bubble. */
2121
text: string
22+
/** The workspace the starter describes, so a client can report a pick against it. Set by `starterFor`. */
23+
workspaceId?: number
2224
}
2325

2426
const MAX_PROMPTS = 3
@@ -174,5 +176,5 @@ export async function starterFor(
174176
const contents = await workspaceContents(directory, binding.datamateId, waitMs)
175177
const starter = renderStarter(binding.datamateName, contents)
176178
trackStarterShown(binding.datamateId, contents)
177-
return starter
179+
return { ...starter, workspaceId: binding.datamateId }
178180
}

‎packages/opencode/src/plugin/tui/altimate/workspace.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
} from "@/altimate/workspace/workspace-name"
4444
import { currentAttachSnapshot } from "@/altimate/workspace/attach-snapshot"
4545
import { trackEngineError, trackInstallPrompt } from "@/altimate/workspace/engine-telemetry"
46+
import { trackStarterActionPicked } from "@/altimate/workspace/starter-telemetry"
4647
import {
4748
accountScope,
4849
loadStatusView,
@@ -449,7 +450,9 @@ function WorkspaceLinkedDialog(props: LinkedProps) {
449450
if (!props.starter()?.prompts.length && option.value !== initial) setMovedEarly(true)
450451
}}
451452
onSelect={(option) => {
452-
// altimate_change start - put the chosen prompt in the input without sending it
453+
// altimate_change start - the pick, once the starter is on screen (before, this is the bare confirmation)
454+
trackStarterActionPicked(props.starter(), option.value)
455+
// put the chosen prompt in the input without sending it
453456
if (option.value.startsWith("prompt:")) {
454457
fillPrompt(props.api, option.title)
455458
return
@@ -524,6 +527,7 @@ function WorkspaceStarterDialog(props: { api: TuiPluginApi; starter: Starter })
524527
]}
525528
current={props.starter.prompts.length > 0 ? "prompt:0" : "done"}
526529
onSelect={(option) => {
530+
trackStarterActionPicked(props.starter, option.value)
527531
if (option.value.startsWith("prompt:")) fillPrompt(props.api, option.title)
528532
else props.api.ui.dialog.clear()
529533
}}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// altimate_change - new file
2+
//
3+
// `starter_action_picked`: one row per selection from a TUI starter dialog, naming the action, the
4+
// prompt's position for a prompt, and the starter's own workspace; never the prompt's text.
5+
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test"
6+
import * as Contents from "../../../src/altimate/workspace/contents"
7+
import type { WorkspaceContents } from "../../../src/altimate/workspace/contents"
8+
import { starterFor } from "../../../src/altimate/workspace/starter"
9+
import {
10+
starterActionPickedEvent,
11+
starterPick,
12+
trackStarterActionPicked,
13+
} from "../../../src/altimate/workspace/starter-telemetry"
14+
import { Telemetry } from "../../../src/altimate/telemetry"
15+
16+
const contents: WorkspaceContents = {
17+
skills: [{ name: "incident-runbook", description: "" }],
18+
integrations: [],
19+
memoryEnabled: true,
20+
knowledge: { kind: "off" },
21+
}
22+
23+
let events: any[]
24+
let trackSpy: ReturnType<typeof spyOn>
25+
26+
beforeEach(() => {
27+
events = []
28+
trackSpy = spyOn(Telemetry, "track").mockImplementation((e) => {
29+
events.push(e)
30+
})
31+
})
32+
33+
afterEach(() => {
34+
trackSpy.mockRestore()
35+
})
36+
37+
describe("starterPick", () => {
38+
test.each([
39+
["prompt:0", { action: "prompt", promptIndex: 0 }],
40+
["prompt:2", { action: "prompt", promptIndex: 2 }],
41+
["open", { action: "open" }],
42+
["done", { action: "done" }],
43+
] as const)("%s is a starter action", (value, pick) => {
44+
expect(starterPick(value)).toEqual(pick)
45+
})
46+
47+
test.each(["", "prompt:", "prompt:-1", "prompt:1.5", "prompt:x", "status", "Done", " done"])(
48+
"%p is not a starter action",
49+
(value) => {
50+
expect(starterPick(value)).toBeNull()
51+
},
52+
)
53+
})
54+
55+
describe("starter_action_picked row", () => {
56+
test("a prompt carries its index and the workspace, and no text", () => {
57+
const row = starterActionPickedEvent(7, { action: "prompt", promptIndex: 1 }, "ses_1") as Record<string, unknown>
58+
expect(Object.keys(row).sort()).toEqual(
59+
["action", "prompt_index", "session_id", "timestamp", "type", "workspace_id"].sort(),
60+
)
61+
expect(row).toEqual(
62+
expect.objectContaining({
63+
type: "starter_action_picked",
64+
session_id: "ses_1",
65+
workspace_id: 7,
66+
action: "prompt",
67+
prompt_index: 1,
68+
}),
69+
)
70+
})
71+
72+
test.each(["open", "done"] as const)("%s carries no prompt_index", (action) => {
73+
const row = starterActionPickedEvent(7, { action }, "ses_1") as Record<string, unknown>
74+
expect(row.action).toBe(action)
75+
expect("prompt_index" in row).toBe(false)
76+
})
77+
78+
test("falls back to the process context's session", () => {
79+
const row = starterActionPickedEvent(7, { action: "done" })
80+
expect(row.session_id).toBe(Telemetry.getContext().sessionId)
81+
})
82+
})
83+
84+
describe("trackStarterActionPicked", () => {
85+
test("tracks exactly one row per selection, against the starter's workspace", () => {
86+
expect(trackStarterActionPicked({ workspaceId: 9 }, "prompt:2")).toBe(true)
87+
expect(events).toHaveLength(1)
88+
expect(events[0]).toEqual(
89+
expect.objectContaining({ type: "starter_action_picked", workspace_id: 9, action: "prompt", prompt_index: 2 }),
90+
)
91+
expect(JSON.stringify(events[0])).not.toContain("Which")
92+
})
93+
94+
test("nothing before the starter arrives: the dialog is then the bare link confirmation", () => {
95+
expect(trackStarterActionPicked(null, "done")).toBe(false)
96+
expect(trackStarterActionPicked(null, "open")).toBe(false)
97+
expect(events).toEqual([])
98+
})
99+
100+
test("nothing for a value that is not a starter action", () => {
101+
expect(trackStarterActionPicked({ workspaceId: 9 }, "status")).toBe(false)
102+
expect(events).toEqual([])
103+
})
104+
105+
test.each([undefined, 0, -3, 1.5, Number.NaN])("nothing for workspace id %p", (workspaceId) => {
106+
expect(trackStarterActionPicked({ workspaceId }, "done")).toBe(false)
107+
expect(events).toEqual([])
108+
})
109+
110+
test("never throws when telemetry does", () => {
111+
trackSpy.mockImplementation(() => {
112+
throw new Error("boom")
113+
})
114+
expect(trackStarterActionPicked({ workspaceId: 9 }, "done")).toBe(false)
115+
})
116+
})
117+
118+
describe("starterFor names its workspace", () => {
119+
test("the served starter carries the id its starter_shown row reported", async () => {
120+
const contentsSpy = spyOn(Contents, "workspaceContents").mockResolvedValue(contents)
121+
try {
122+
const starter = await starterFor("/tmp/project", { datamateId: 31, datamateName: "analytics" })
123+
expect(starter.workspaceId).toBe(31)
124+
const shown = events.find((e) => e.type === "starter_shown")
125+
expect(shown?.workspace_id).toBe(starter.workspaceId)
126+
events.length = 0
127+
trackStarterActionPicked(starter, "prompt:0")
128+
expect(events[0].workspace_id).toBe(shown.workspace_id)
129+
} finally {
130+
contentsSpy.mockRestore()
131+
}
132+
})
133+
})

0 commit comments

Comments
 (0)