Skip to content

Commit 930a417

Browse files
anandgupta42claude
andcommitted
fix: address code review — truncation-safe followups, telemetry, immutable get()
- Move follow-up suggestions before `<skill_content>` so they survive output truncation - Add `has_followups` and `followup_count` to `skill_used` telemetry event - Return `readonly Suggestion[]` via `Object.freeze()` from `get()` to prevent shared state mutation - Rewrite integration tests to verify followups appear before `<skill_content>` in output assembly - Wrap custom return block in `altimate_change` markers for upstream safety Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent ae7ecca commit 930a417

4 files changed

Lines changed: 41 additions & 10 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ export namespace Telemetry {
349349
skill_name: string
350350
skill_source: "builtin" | "global" | "project"
351351
duration_ms: number
352+
has_followups: boolean
353+
followup_count: number
352354
}
353355
// altimate_change start — first_launch event for new user counting (privacy-safe: only version + machine_id)
354356
| {

‎packages/opencode/src/skill/followups.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ export namespace SkillFollowups {
153153
// A special warehouse nudge for users who haven't connected yet
154154
const WAREHOUSE_NUDGE = "**Tip:** Connect a warehouse to validate against real data. Run `/discover` to auto-detect your connections."
155155

156-
export function get(skillName: string): Suggestion[] {
157-
return FOLLOWUPS[skillName] ?? []
156+
export function get(skillName: string): readonly Suggestion[] {
157+
return Object.freeze(FOLLOWUPS[skillName] ?? [])
158158
}
159159

160160
export function format(skillName: string): string {

‎packages/opencode/src/tool/skill.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ export const SkillTool = Tool.define("skill", async (ctx) => {
143143
}).then((f) => f.map((file) => `<file>${file}</file>`).join("\n"))
144144
// altimate_change end
145145

146+
// altimate_change start — append follow-up suggestions after skill content
147+
const followups = SkillFollowups.format(skill.name)
148+
// altimate_change end
149+
146150
// altimate_change start — telemetry instrumentation for skill loading
147151
try {
148152
Telemetry.track({
@@ -153,19 +157,19 @@ export const SkillTool = Tool.define("skill", async (ctx) => {
153157
skill_name: skill.name,
154158
skill_source: classifySkillSource(skill.location),
155159
duration_ms: Date.now() - startTime,
160+
has_followups: followups.length > 0,
161+
followup_count: SkillFollowups.get(skill.name).length,
156162
})
157163
} catch {
158164
// Telemetry must never break skill loading
159165
}
160166
// altimate_change end
161167

162-
// altimate_change start — append follow-up suggestions after skill content
163-
const followups = SkillFollowups.format(skill.name)
164-
// altimate_change end
165-
168+
// altimate_change start — custom return with follow-ups, file listing, and base directory
166169
return {
167170
title: `Loaded skill: ${skill.name}`,
168171
output: [
172+
...(followups ? [followups, ""] : []),
169173
`<skill_content name="${skill.name}">`,
170174
`# Skill: ${skill.name}`,
171175
"",
@@ -179,13 +183,13 @@ export const SkillTool = Tool.define("skill", async (ctx) => {
179183
files,
180184
"</skill_files>",
181185
"</skill_content>",
182-
followups,
183186
].join("\n"),
184187
metadata: {
185188
name: skill.name,
186189
dir,
187190
},
188191
}
192+
// altimate_change end
189193
},
190194
}
191195
})

‎packages/opencode/test/skill/skill-followups-integration.test.ts‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Instance } from "../../src/project/instance"
55
import { tmpdir } from "../fixture/fixture"
66
import path from "path"
77

8-
test("skill tool output includes follow-up suggestions for skills with followups", async () => {
8+
test("skill with followups: format appears before skill_content", async () => {
99
await using tmp = await tmpdir({
1010
git: true,
1111
init: async (dir) => {
@@ -31,16 +31,31 @@ Instructions here.
3131
const skill = await Skill.get("dbt-develop")
3232
expect(skill).toBeDefined()
3333

34-
// Verify followups exist for this skill
34+
// Verify followups exist and are well-formed
3535
const followups = SkillFollowups.format("dbt-develop")
3636
expect(followups).toContain("## What's Next?")
3737
expect(followups).toContain("dbt-test")
3838
expect(followups).toContain("dbt-docs")
39+
40+
// Simulate the output assembly order from SkillTool to verify
41+
// followups come BEFORE <skill_content> (survives truncation)
42+
const output = [
43+
...(followups ? [followups, ""] : []),
44+
`<skill_content name="${skill!.name}">`,
45+
skill!.content.trim(),
46+
"</skill_content>",
47+
].join("\n")
48+
49+
const followupsIdx = output.indexOf("## What's Next?")
50+
const skillContentIdx = output.indexOf("<skill_content")
51+
expect(followupsIdx).toBeGreaterThan(-1)
52+
expect(skillContentIdx).toBeGreaterThan(-1)
53+
expect(followupsIdx).toBeLessThan(skillContentIdx)
3954
},
4055
})
4156
})
4257

43-
test("skill tool output has no follow-ups for skills without followups defined", async () => {
58+
test("skill without followups: no extra content before skill_content", async () => {
4459
await using tmp = await tmpdir({
4560
git: true,
4661
init: async (dir) => {
@@ -69,6 +84,16 @@ Do custom things.
6984
// No followups for unknown skills
7085
const followups = SkillFollowups.format("custom-skill")
7186
expect(followups).toBe("")
87+
88+
// Output should start directly with skill_content
89+
const output = [
90+
...(followups ? [followups, ""] : []),
91+
`<skill_content name="${skill!.name}">`,
92+
skill!.content.trim(),
93+
"</skill_content>",
94+
].join("\n")
95+
96+
expect(output).toMatch(/^<skill_content/)
7297
},
7398
})
7499
})

0 commit comments

Comments
 (0)