Skip to content

Commit cba7879

Browse files
anandgupta42claude
andcommitted
fix: reset training session tracking, add error logging, fix list truncation
- Call `TrainingPrompt.resetSession()` at session start (step === 1) to prevent applied counters from growing unbounded across sessions - Add structured error logging to all three training tools - Add truncation indicator (`...`) when training list preview is cut off Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 523a129 commit cba7879

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

packages/opencode/src/altimate/tools/training-list.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// altimate_change - Training list tool for AI Teammate learned knowledge
22
import z from "zod"
33
import { Tool } from "../../tool/tool"
4+
import { Log } from "../../util/log"
45
import { TrainingStore, TrainingPrompt, TrainingInsights } from "../training"
56
import { TrainingKind } from "../training/types"
67

8+
const log = Log.create({ service: "tool.training_list" })
9+
710
export const TrainingListTool = Tool.define("training_list", {
811
description: [
912
"List all learned training entries (patterns, rules, glossary, standards).",
@@ -82,7 +85,10 @@ export const TrainingListTool = Tool.define("training_list", {
8285
const applied = e.meta.applied > 0 ? ` (applied ${e.meta.applied}x)` : ""
8386
const source = e.meta.source ? ` — from: ${e.meta.source}` : ""
8487
const scope = e.scope === "global" ? " [global]" : ""
85-
sections.push(`- **${e.name}**${scope}${applied}${source}\n ${e.content.split("\n")[0].slice(0, 120)}`)
88+
const firstLine = e.content.split("\n")[0]
89+
const preview = firstLine.slice(0, 120)
90+
const truncated = firstLine.length > 120 || e.content.includes("\n") ? "..." : ""
91+
sections.push(`- **${e.name}**${scope}${applied}${source}\n ${preview}${truncated}`)
8692
}
8793
sections.push("")
8894
}
@@ -97,10 +103,12 @@ export const TrainingListTool = Tool.define("training_list", {
97103
output: summary + highlights + sections.join("\n") + insightText,
98104
}
99105
} catch (e) {
106+
const msg = e instanceof Error ? e.message : String(e)
107+
log.error("failed to list training", { error: msg })
100108
return {
101109
title: "Training List: ERROR",
102110
metadata: { count: 0, budgetPercent: 0 },
103-
output: `Failed to list training: ${e instanceof Error ? e.message : String(e)}`,
111+
output: `Failed to list training: ${msg}`,
104112
}
105113
}
106114
},

packages/opencode/src/altimate/tools/training-remove.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// altimate_change - Training remove tool for AI Teammate
22
import z from "zod"
33
import { Tool } from "../../tool/tool"
4+
import { Log } from "../../util/log"
45
import { TrainingStore, TrainingPrompt } from "../training"
56
import { TrainingKind } from "../training/types"
67

8+
const log = Log.create({ service: "tool.training_remove" })
9+
710
export const TrainingRemoveTool = Tool.define("training_remove", {
811
description:
912
"Remove a learned training entry (pattern, rule, glossary term, or standard). Use this when a training entry is outdated, incorrect, or no longer relevant.",
@@ -46,10 +49,12 @@ export const TrainingRemoveTool = Tool.define("training_remove", {
4649
output: `Removed ${args.kind} "${args.name}" from ${args.scope} training.${appliedNote}\nTraining usage: ${budget.used}/${budget.budget} chars (${budget.percent}% full).`,
4750
}
4851
} catch (e) {
52+
const msg = e instanceof Error ? e.message : String(e)
53+
log.error("failed to remove training", { kind: args.kind, name: args.name, error: msg })
4954
return {
5055
title: "Training Remove: ERROR",
5156
metadata: { action: "error", kind: args.kind, name: args.name },
52-
output: `Failed to remove training: ${e instanceof Error ? e.message : String(e)}`,
57+
output: `Failed to remove training: ${msg}`,
5358
}
5459
}
5560
},

packages/opencode/src/altimate/tools/training-save.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// altimate_change - Training save tool for AI Teammate learning
22
import z from "zod"
33
import { Tool } from "../../tool/tool"
4+
import { Log } from "../../util/log"
45
import { TrainingStore, TrainingPrompt } from "../training"
56
import { TrainingKind, TRAINING_MAX_PATTERNS_PER_KIND, TRAINING_BUDGET } from "../training/types"
67
import { CitationSchema } from "../../memory/types"
78

9+
const log = Log.create({ service: "tool.training_save" })
10+
811
export const TrainingSaveTool = Tool.define("training_save", {
912
description: [
1013
"Save a learned pattern, rule, glossary term, or standard to your teammate's training.",
@@ -142,10 +145,12 @@ export const TrainingSaveTool = Tool.define("training_save", {
142145
output,
143146
}
144147
} catch (e) {
148+
const msg = e instanceof Error ? e.message : String(e)
149+
log.error("failed to save training", { kind: args.kind, name: args.name, error: msg })
145150
return {
146151
title: "Training Save: ERROR",
147152
metadata: { action: "error" as string, kind: args.kind, name: args.name, scope: args.scope },
148-
output: `Failed to save training: ${e instanceof Error ? e.message : String(e)}`,
153+
output: `Failed to save training: ${msg}`,
149154
}
150155
}
151156
},

packages/opencode/src/session/prompt.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,9 @@ export namespace SessionPrompt {
654654
}
655655

656656
if (step === 1) {
657+
// altimate_change start - reset training session tracking to avoid stale applied counts
658+
TrainingPrompt.resetSession()
659+
// altimate_change end
657660
SessionSummary.summarize({
658661
sessionID: sessionID,
659662
messageID: lastUser.id,

0 commit comments

Comments
 (0)