fix: use character limit instead of sentence split for skill description (#358)

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-02-07 19:08:08 +09:00
parent 8e92704316
commit a0201e17b9
6 changed files with 166 additions and 40 deletions
+1
View File
@@ -42,3 +42,4 @@ export * from "./model-suggestion-retry"
export * from "./opencode-server-auth"
export * from "./port-utils"
export * from "./safe-create-hook"
export * from "./truncate-description"
+104
View File
@@ -0,0 +1,104 @@
import { describe, it, expect } from "bun:test"
import { truncateDescription } from "./truncate-description"
describe("truncateDescription", () => {
it("returns description unchanged when under max length", () => {
// given
const description = "This is a short description"
// when
const result = truncateDescription(description)
// then
expect(result).toBe(description)
})
it("truncates to 120 characters by default and appends ellipsis", () => {
// given
const description = "This is a very long description that exceeds the default maximum length of 120 characters and should be truncated with an ellipsis at the end"
// when
const result = truncateDescription(description)
// then
expect(result.length).toBe(123) // 120 + "..."
expect(result).toEndWith("...")
expect(result).toBe(description.slice(0, 120) + "...")
})
it("respects custom max length parameter", () => {
// given
const description = "This is a description that is longer than fifty characters"
const maxLength = 50
// when
const result = truncateDescription(description, maxLength)
// then
expect(result.length).toBe(53) // 50 + "..."
expect(result).toEndWith("...")
expect(result).toBe(description.slice(0, 50) + "...")
})
it("handles empty string", () => {
// given
const description = ""
// when
const result = truncateDescription(description)
// then
expect(result).toBe("")
})
it("handles exactly max length without truncation", () => {
// given
const description = "a".repeat(120)
// when
const result = truncateDescription(description)
// then
expect(result).toBe(description)
expect(result).not.toEndWith("...")
})
it("handles description with periods correctly", () => {
// given
const description = "First sentence. Second sentence. Third sentence that is very long and continues beyond the normal truncation point with even more text to ensure it exceeds 120 characters."
// when
const result = truncateDescription(description)
// then
expect(result.length).toBe(123) // 120 + "..."
expect(result).toContain("First sentence. Second sentence.")
expect(result).toEndWith("...")
})
it("handles description with URLs correctly", () => {
// given
const description = "Check out https://example.com/very/long/path/that/contains/many/segments for more information about this feature and its capabilities"
// when
const result = truncateDescription(description)
// then
expect(result.length).toBe(123) // 120 + "..."
expect(result).toStartWith("Check out https://example.com")
expect(result).toEndWith("...")
})
it("handles description with version numbers correctly", () => {
// given
const description = "Version 1.2.3 of the library includes many improvements and bug fixes that make it more stable and performant with additional enhancements"
// when
const result = truncateDescription(description)
// then
expect(result.length).toBe(123) // 120 + "..."
expect(result).toStartWith("Version 1.2.3")
expect(result).toEndWith("...")
})
})
+19
View File
@@ -0,0 +1,19 @@
/**
* Truncates a description string to a maximum character length.
* If truncated, appends "..." to indicate continuation.
*
* @param description - The description string to truncate
* @param maxLength - Maximum character length (default: 120)
* @returns Truncated description with "..." appended if it was truncated
*/
export function truncateDescription(description: string, maxLength: number = 120): string {
if (!description) {
return description
}
if (description.length <= maxLength) {
return description
}
return description.slice(0, maxLength) + "..."
}