fix: revert delegate-task to string category schema, fix mock isolation and restore UB7 originals
This commit is contained in:
@@ -8,9 +8,11 @@ import type { PluginInput } from "@opencode-ai/plugin"
|
|||||||
import { createOpencodeClient, type Project } from "@opencode-ai/sdk"
|
import { createOpencodeClient, type Project } from "@opencode-ai/sdk"
|
||||||
|
|
||||||
const isCallerOrchestratorMock = mock(async () => true)
|
const isCallerOrchestratorMock = mock(async () => true)
|
||||||
const collectGitDiffStatsMock = mock(() => {
|
const collectGitDiffStatsMock = mock(() => ({
|
||||||
throw new Error("background launches should not trigger verification")
|
filesChanged: 0,
|
||||||
})
|
insertions: 0,
|
||||||
|
deletions: 0,
|
||||||
|
}))
|
||||||
|
|
||||||
mock.module("../../shared/session-utils", () => ({
|
mock.module("../../shared/session-utils", () => ({
|
||||||
isCallerOrchestrator: isCallerOrchestratorMock,
|
isCallerOrchestrator: isCallerOrchestratorMock,
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/// <reference path="../../../bun-test.d.ts" />
|
|
||||||
|
|
||||||
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
|
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
|
||||||
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
|
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
|
||||||
import { tmpdir } from "node:os"
|
import { tmpdir } from "node:os"
|
||||||
@@ -120,37 +118,6 @@ describe("autoMigrateLegacyPluginEntry", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#given opencode.jsonc contains a nested plugin key before the top-level plugin array", () => {
|
|
||||||
it("#then rewrites only the top-level plugin array", async () => {
|
|
||||||
// given
|
|
||||||
writeFileSync(
|
|
||||||
join(testConfigDir, "opencode.jsonc"),
|
|
||||||
`{
|
|
||||||
"nested": {
|
|
||||||
"plugin": ["oh-my-opencode"]
|
|
||||||
},
|
|
||||||
"plugin": ["oh-my-opencode@latest"]
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
)
|
|
||||||
|
|
||||||
const { autoMigrateLegacyPluginEntry } = await importFreshAutoMigrateModule()
|
|
||||||
|
|
||||||
// when
|
|
||||||
const result = autoMigrateLegacyPluginEntry(testConfigDir)
|
|
||||||
|
|
||||||
// then
|
|
||||||
expect(result.migrated).toBe(true)
|
|
||||||
const content = readFileSync(join(testConfigDir, "opencode.jsonc"), "utf-8")
|
|
||||||
expect(content).toContain(`"nested": {
|
|
||||||
"plugin": ["oh-my-opencode"]
|
|
||||||
}`)
|
|
||||||
expect(content).toContain(`"plugin": [
|
|
||||||
"oh-my-openagent@latest"
|
|
||||||
]`)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("#given only canonical entry exists", () => {
|
describe("#given only canonical entry exists", () => {
|
||||||
it("#then returns migrated false and leaves file untouched", async () => {
|
it("#then returns migrated false and leaves file untouched", async () => {
|
||||||
// given
|
// given
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { existsSync, readFileSync } from "node:fs"
|
import { existsSync, readFileSync, writeFileSync } from "node:fs"
|
||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
|
|
||||||
import { parseJsoncSafe } from "../../shared/jsonc-parser"
|
import { parseJsoncSafe } from "../../shared/jsonc-parser"
|
||||||
import { migrateLegacyPluginEntry } from "../../shared/migrate-legacy-plugin-entry"
|
|
||||||
import { getOpenCodeConfigPaths } from "../../shared/opencode-config-dir"
|
import { getOpenCodeConfigPaths } from "../../shared/opencode-config-dir"
|
||||||
import { LEGACY_PLUGIN_NAME, PLUGIN_NAME } from "../../shared/plugin-identity"
|
import { LEGACY_PLUGIN_NAME, PLUGIN_NAME } from "../../shared/plugin-identity"
|
||||||
|
|
||||||
@@ -21,6 +20,10 @@ function isLegacyEntry(entry: string): boolean {
|
|||||||
return entry === LEGACY_PLUGIN_NAME || entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)
|
return entry === LEGACY_PLUGIN_NAME || entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isCanonicalEntry(entry: string): boolean {
|
||||||
|
return entry === PLUGIN_NAME || entry.startsWith(`${PLUGIN_NAME}@`)
|
||||||
|
}
|
||||||
|
|
||||||
function toLegacyCanonical(entry: string): string {
|
function toLegacyCanonical(entry: string): string {
|
||||||
if (entry === LEGACY_PLUGIN_NAME) return PLUGIN_NAME
|
if (entry === LEGACY_PLUGIN_NAME) return PLUGIN_NAME
|
||||||
if (entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)) {
|
if (entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)) {
|
||||||
@@ -57,13 +60,29 @@ export function autoMigrateLegacyPluginEntry(overrideConfigDir?: string): Migrat
|
|||||||
const legacyEntries = plugins.filter(isLegacyEntry)
|
const legacyEntries = plugins.filter(isLegacyEntry)
|
||||||
if (legacyEntries.length === 0) return { migrated: false, from: null, to: null, configPath }
|
if (legacyEntries.length === 0) return { migrated: false, from: null, to: null, configPath }
|
||||||
|
|
||||||
|
const hasCanonical = plugins.some(isCanonicalEntry)
|
||||||
const from = legacyEntries[0]
|
const from = legacyEntries[0]
|
||||||
const to = toLegacyCanonical(from)
|
const to = toLegacyCanonical(from)
|
||||||
|
|
||||||
if (!migrateLegacyPluginEntry(configPath)) {
|
const normalized = hasCanonical
|
||||||
return { migrated: false, from: null, to: null, configPath }
|
? plugins.filter((p) => !isLegacyEntry(p))
|
||||||
|
: plugins.map((p) => (isLegacyEntry(p) ? toLegacyCanonical(p) : p))
|
||||||
|
|
||||||
|
const isJsonc = configPath.endsWith(".jsonc")
|
||||||
|
if (isJsonc) {
|
||||||
|
const pluginArrayRegex = /((?:"plugin"|plugin)\s*:\s*)\[([\s\S]*?)\]/
|
||||||
|
const match = content.match(pluginArrayRegex)
|
||||||
|
if (match) {
|
||||||
|
const formattedPlugins = normalized.map((p) => `"${p}"`).join(",\n ")
|
||||||
|
const newContent = content.replace(pluginArrayRegex, `$1[\n ${formattedPlugins}\n ]`)
|
||||||
|
writeFileSync(configPath, newContent)
|
||||||
|
return { migrated: true, from, to, configPath }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parsed = JSON.parse(content) as Record<string, unknown>
|
||||||
|
parsed.plugin = normalized
|
||||||
|
writeFileSync(configPath, JSON.stringify(parsed, null, 2) + "\n")
|
||||||
return { migrated: true, from, to, configPath }
|
return { migrated: true, from, to, configPath }
|
||||||
} catch {
|
} catch {
|
||||||
return { migrated: false, from: null, to: null, configPath }
|
return { migrated: false, from: null, to: null, configPath }
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
/// <reference path="../../../bun-test.d.ts" />
|
|
||||||
|
|
||||||
import { afterAll, beforeEach, describe, expect, it, mock } from "bun:test"
|
import { afterAll, beforeEach, describe, expect, it, mock } from "bun:test"
|
||||||
|
|
||||||
import type { LegacyPluginCheckResult } from "../../shared/legacy-plugin-warning"
|
|
||||||
import type { MigrationResult } from "./auto-migrate"
|
import type { MigrationResult } from "./auto-migrate"
|
||||||
|
|
||||||
const mockCheckForLegacyPluginEntry = mock((): LegacyPluginCheckResult => ({
|
const mockCheckForLegacyPluginEntry = mock(() => ({
|
||||||
hasLegacyEntry: false,
|
hasLegacyEntry: false,
|
||||||
hasCanonicalEntry: false,
|
hasCanonicalEntry: false,
|
||||||
legacyEntries: [] as string[],
|
legacyEntries: [] as string[],
|
||||||
configPath: null,
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const mockAutoMigrate = mock((): MigrationResult => ({
|
const mockAutoMigrate = mock((): MigrationResult => ({
|
||||||
@@ -72,7 +67,6 @@ describe("createLegacyPluginToastHook", () => {
|
|||||||
hasLegacyEntry: false,
|
hasLegacyEntry: false,
|
||||||
hasCanonicalEntry: true,
|
hasCanonicalEntry: true,
|
||||||
legacyEntries: [],
|
legacyEntries: [],
|
||||||
configPath: null,
|
|
||||||
})
|
})
|
||||||
mockAutoMigrate.mockReturnValue({ migrated: false, from: null, to: null, configPath: null })
|
mockAutoMigrate.mockReturnValue({ migrated: false, from: null, to: null, configPath: null })
|
||||||
mockShowToast.mockResolvedValue(undefined)
|
mockShowToast.mockResolvedValue(undefined)
|
||||||
@@ -99,7 +93,6 @@ describe("createLegacyPluginToastHook", () => {
|
|||||||
hasLegacyEntry: true,
|
hasLegacyEntry: true,
|
||||||
hasCanonicalEntry: false,
|
hasCanonicalEntry: false,
|
||||||
legacyEntries: ["oh-my-opencode"],
|
legacyEntries: ["oh-my-opencode"],
|
||||||
configPath: "/tmp/opencode.json",
|
|
||||||
})
|
})
|
||||||
mockAutoMigrate.mockReturnValue({
|
mockAutoMigrate.mockReturnValue({
|
||||||
migrated: true,
|
migrated: true,
|
||||||
@@ -127,7 +120,6 @@ describe("createLegacyPluginToastHook", () => {
|
|||||||
hasLegacyEntry: true,
|
hasLegacyEntry: true,
|
||||||
hasCanonicalEntry: false,
|
hasCanonicalEntry: false,
|
||||||
legacyEntries: ["oh-my-opencode"],
|
legacyEntries: ["oh-my-opencode"],
|
||||||
configPath: "/tmp/opencode.json",
|
|
||||||
})
|
})
|
||||||
mockAutoMigrate.mockReturnValue({
|
mockAutoMigrate.mockReturnValue({
|
||||||
migrated: false,
|
migrated: false,
|
||||||
@@ -155,7 +147,6 @@ describe("createLegacyPluginToastHook", () => {
|
|||||||
hasLegacyEntry: true,
|
hasLegacyEntry: true,
|
||||||
hasCanonicalEntry: false,
|
hasCanonicalEntry: false,
|
||||||
legacyEntries: ["oh-my-opencode"],
|
legacyEntries: ["oh-my-opencode"],
|
||||||
configPath: "/tmp/opencode.json",
|
|
||||||
})
|
})
|
||||||
mockAutoMigrate.mockReturnValue({
|
mockAutoMigrate.mockReturnValue({
|
||||||
migrated: true,
|
migrated: true,
|
||||||
@@ -182,7 +173,6 @@ describe("createLegacyPluginToastHook", () => {
|
|||||||
hasLegacyEntry: true,
|
hasLegacyEntry: true,
|
||||||
hasCanonicalEntry: false,
|
hasCanonicalEntry: false,
|
||||||
legacyEntries: ["oh-my-opencode"],
|
legacyEntries: ["oh-my-opencode"],
|
||||||
configPath: "/tmp/opencode.json",
|
|
||||||
})
|
})
|
||||||
const { createLegacyPluginToastHook } = await importFreshModule()
|
const { createLegacyPluginToastHook } = await importFreshModule()
|
||||||
const hook = createLegacyPluginToastHook(createMockCtx())
|
const hook = createLegacyPluginToastHook(createMockCtx())
|
||||||
@@ -202,7 +192,6 @@ describe("createLegacyPluginToastHook", () => {
|
|||||||
hasLegacyEntry: true,
|
hasLegacyEntry: true,
|
||||||
hasCanonicalEntry: false,
|
hasCanonicalEntry: false,
|
||||||
legacyEntries: ["oh-my-opencode"],
|
legacyEntries: ["oh-my-opencode"],
|
||||||
configPath: "/tmp/opencode.json",
|
|
||||||
})
|
})
|
||||||
const { createLegacyPluginToastHook } = await importFreshModule()
|
const { createLegacyPluginToastHook } = await importFreshModule()
|
||||||
const hook = createLegacyPluginToastHook(createMockCtx())
|
const hook = createLegacyPluginToastHook(createMockCtx())
|
||||||
@@ -214,25 +203,4 @@ describe("createLegacyPluginToastHook", () => {
|
|||||||
expect(mockCheckForLegacyPluginEntry).not.toHaveBeenCalled()
|
expect(mockCheckForLegacyPluginEntry).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#given a project directory is available", () => {
|
|
||||||
it("#then passes the project directory into legacy config detection", async () => {
|
|
||||||
// given
|
|
||||||
mockCheckForLegacyPluginEntry.mockReturnValue({
|
|
||||||
hasLegacyEntry: true,
|
|
||||||
hasCanonicalEntry: false,
|
|
||||||
legacyEntries: ["oh-my-opencode"],
|
|
||||||
configPath: "/tmp/test/.opencode/opencode.json",
|
|
||||||
})
|
|
||||||
const { createLegacyPluginToastHook } = await importFreshModule()
|
|
||||||
const hook = createLegacyPluginToastHook(createMockCtx())
|
|
||||||
|
|
||||||
// when
|
|
||||||
await hook.event(createEvent("session.created"))
|
|
||||||
|
|
||||||
// then
|
|
||||||
expect(mockCheckForLegacyPluginEntry).toHaveBeenCalledWith(undefined, "/tmp/test")
|
|
||||||
expect(mockAutoMigrate).toHaveBeenCalledWith("/tmp/test/.opencode")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { dirname } from "node:path"
|
|
||||||
|
|
||||||
import type { PluginInput } from "@opencode-ai/plugin"
|
import type { PluginInput } from "@opencode-ai/plugin"
|
||||||
|
|
||||||
import { checkForLegacyPluginEntry } from "../../shared/legacy-plugin-warning"
|
import { checkForLegacyPluginEntry } from "../../shared/legacy-plugin-warning"
|
||||||
@@ -19,10 +17,10 @@ export function createLegacyPluginToastHook(ctx: PluginInput) {
|
|||||||
|
|
||||||
fired = true
|
fired = true
|
||||||
|
|
||||||
const result = checkForLegacyPluginEntry(undefined, ctx.directory)
|
const result = checkForLegacyPluginEntry()
|
||||||
if (!result.hasLegacyEntry) return
|
if (!result.hasLegacyEntry) return
|
||||||
|
|
||||||
const migration = autoMigrateLegacyPluginEntry(result.configPath ? dirname(result.configPath) : undefined)
|
const migration = autoMigrateLegacyPluginEntry()
|
||||||
|
|
||||||
if (migration.migrated) {
|
if (migration.migrated) {
|
||||||
log("[legacy-plugin-toast] Auto-migrated opencode.json plugin entry", {
|
log("[legacy-plugin-toast] Auto-migrated opencode.json plugin entry", {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/// <reference path="../../bun-test.d.ts" />
|
|
||||||
|
|
||||||
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
|
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
|
||||||
import { mkdirSync, rmSync, writeFileSync } from "node:fs"
|
import { mkdirSync, rmSync, writeFileSync } from "node:fs"
|
||||||
import { tmpdir } from "node:os"
|
import { tmpdir } from "node:os"
|
||||||
@@ -82,26 +80,4 @@ describe("checkForLegacyPluginEntry", () => {
|
|||||||
expect(result.legacyEntries).toEqual([])
|
expect(result.legacyEntries).toEqual([])
|
||||||
expect(result.configPath).toBeNull()
|
expect(result.configPath).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#given a project-local .opencode config contains a legacy plugin entry", () => {
|
|
||||||
it("#then detects the project-local config path", () => {
|
|
||||||
// given
|
|
||||||
const projectDir = join(testConfigDir, "project")
|
|
||||||
const projectConfigDir = join(projectDir, ".opencode")
|
|
||||||
mkdirSync(projectConfigDir, { recursive: true })
|
|
||||||
writeFileSync(
|
|
||||||
join(projectConfigDir, "opencode.json"),
|
|
||||||
JSON.stringify({ plugin: ["oh-my-opencode"] }, null, 2),
|
|
||||||
)
|
|
||||||
|
|
||||||
// when
|
|
||||||
const result = checkForLegacyPluginEntry(undefined, projectDir)
|
|
||||||
|
|
||||||
// then
|
|
||||||
expect(result.hasLegacyEntry).toBe(true)
|
|
||||||
expect(result.hasCanonicalEntry).toBe(false)
|
|
||||||
expect(result.legacyEntries).toEqual(["oh-my-opencode"])
|
|
||||||
expect(result.configPath).toBe(join(projectConfigDir, "opencode.json"))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -16,36 +16,20 @@ export interface LegacyPluginCheckResult {
|
|||||||
configPath: string | null
|
configPath: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConfigPathFromDirectory(configDir: string): string | null {
|
function getOpenCodeConfigPath(overrideConfigDir?: string): string | null {
|
||||||
const jsonPath = join(configDir, "opencode.json")
|
|
||||||
const jsoncPath = join(configDir, "opencode.jsonc")
|
|
||||||
|
|
||||||
if (existsSync(jsoncPath)) return jsoncPath
|
|
||||||
if (existsSync(jsonPath)) return jsonPath
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
function getOpenCodeConfigPathsToCheck(overrideConfigDir?: string, projectDir?: string): string[] {
|
|
||||||
if (overrideConfigDir) {
|
if (overrideConfigDir) {
|
||||||
const overridePath = getConfigPathFromDirectory(overrideConfigDir)
|
const jsonPath = join(overrideConfigDir, "opencode.json")
|
||||||
return overridePath ? [overridePath] : []
|
const jsoncPath = join(overrideConfigDir, "opencode.jsonc")
|
||||||
}
|
if (existsSync(jsoncPath)) return jsoncPath
|
||||||
|
if (existsSync(jsonPath)) return jsonPath
|
||||||
const configPaths: string[] = []
|
return null
|
||||||
|
|
||||||
if (projectDir) {
|
|
||||||
const projectConfigPath = getConfigPathFromDirectory(join(projectDir, ".opencode"))
|
|
||||||
if (projectConfigPath) {
|
|
||||||
configPaths.push(projectConfigPath)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { configJsonc, configJson } = getOpenCodeConfigPaths({ binary: "opencode", version: null })
|
const { configJsonc, configJson } = getOpenCodeConfigPaths({ binary: "opencode", version: null })
|
||||||
|
|
||||||
if (existsSync(configJsonc)) configPaths.push(configJsonc)
|
if (existsSync(configJsonc)) return configJsonc
|
||||||
else if (existsSync(configJson)) configPaths.push(configJson)
|
if (existsSync(configJson)) return configJson
|
||||||
|
return null
|
||||||
return configPaths
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isLegacyPluginEntry(entry: string): boolean {
|
function isLegacyPluginEntry(entry: string): boolean {
|
||||||
@@ -56,51 +40,29 @@ function isCanonicalPluginEntry(entry: string): boolean {
|
|||||||
return entry === PLUGIN_NAME || entry.startsWith(`${PLUGIN_NAME}@`)
|
return entry === PLUGIN_NAME || entry.startsWith(`${PLUGIN_NAME}@`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkForLegacyPluginEntry(
|
export function checkForLegacyPluginEntry(overrideConfigDir?: string): LegacyPluginCheckResult {
|
||||||
overrideConfigDir?: string,
|
const configPath = getOpenCodeConfigPath(overrideConfigDir)
|
||||||
projectDir?: string,
|
if (!configPath) {
|
||||||
): LegacyPluginCheckResult {
|
|
||||||
const configPaths = getOpenCodeConfigPathsToCheck(overrideConfigDir, projectDir)
|
|
||||||
if (configPaths.length === 0) {
|
|
||||||
return { hasLegacyEntry: false, hasCanonicalEntry: false, legacyEntries: [], configPath: null }
|
return { hasLegacyEntry: false, hasCanonicalEntry: false, legacyEntries: [], configPath: null }
|
||||||
}
|
}
|
||||||
|
|
||||||
let hasCanonicalEntry = false
|
try {
|
||||||
let detectedConfigPath: string | null = null
|
const content = readFileSync(configPath, "utf-8")
|
||||||
|
const parseResult = parseJsoncSafe<OpenCodeConfig>(content)
|
||||||
for (const configPath of configPaths) {
|
if (!parseResult.data) {
|
||||||
detectedConfigPath ??= configPath
|
return { hasLegacyEntry: false, hasCanonicalEntry: false, legacyEntries: [], configPath }
|
||||||
|
|
||||||
try {
|
|
||||||
const content = readFileSync(configPath, "utf-8")
|
|
||||||
const parseResult = parseJsoncSafe<OpenCodeConfig>(content)
|
|
||||||
if (!parseResult.data) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
const pluginEntries = parseResult.data.plugin ?? []
|
|
||||||
const legacyEntries = pluginEntries.filter(isLegacyPluginEntry)
|
|
||||||
const fileHasCanonicalEntry = pluginEntries.some(isCanonicalPluginEntry)
|
|
||||||
|
|
||||||
if (legacyEntries.length > 0) {
|
|
||||||
return {
|
|
||||||
hasLegacyEntry: true,
|
|
||||||
hasCanonicalEntry: fileHasCanonicalEntry,
|
|
||||||
legacyEntries,
|
|
||||||
configPath,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hasCanonicalEntry ||= fileHasCanonicalEntry
|
|
||||||
} catch {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
const legacyEntries = (parseResult.data.plugin ?? []).filter(isLegacyPluginEntry)
|
||||||
hasLegacyEntry: false,
|
const hasCanonicalEntry = (parseResult.data.plugin ?? []).some(isCanonicalPluginEntry)
|
||||||
hasCanonicalEntry,
|
|
||||||
legacyEntries: [],
|
return {
|
||||||
configPath: detectedConfigPath,
|
hasLegacyEntry: legacyEntries.length > 0,
|
||||||
|
hasCanonicalEntry,
|
||||||
|
legacyEntries,
|
||||||
|
configPath,
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return { hasLegacyEntry: false, hasCanonicalEntry: false, legacyEntries: [], configPath: null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const { describe, expect, test } = require("bun:test")
|
|||||||
import { createDelegateTask } from "./tools"
|
import { createDelegateTask } from "./tools"
|
||||||
|
|
||||||
describe("createDelegateTask schema", () => {
|
describe("createDelegateTask schema", () => {
|
||||||
test("#given category arg #when tool is created #then category is constrained to available enum values", () => {
|
test("#given category arg #when tool is created #then category accepts any string", () => {
|
||||||
//#given
|
//#given
|
||||||
const toolDefinition = createDelegateTask({ manager: {} as never, client: {} as never, directory: "/tmp/test" })
|
const toolDefinition = createDelegateTask({ manager: {} as never, client: {} as never, directory: "/tmp/test" })
|
||||||
|
|
||||||
@@ -13,16 +13,12 @@ import { createDelegateTask } from "./tools"
|
|||||||
type: string
|
type: string
|
||||||
innerType: {
|
innerType: {
|
||||||
def: { type: string }
|
def: { type: string }
|
||||||
options: string[]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#then
|
//#then
|
||||||
expect(categorySchema.def.type).toBe("optional")
|
expect(categorySchema.def.type).toBe("optional")
|
||||||
expect(categorySchema.def.innerType.def.type).toBe("enum")
|
expect(categorySchema.def.innerType.def.type).toBe("string")
|
||||||
expect(categorySchema.def.innerType.options).toContain("quick")
|
|
||||||
expect(categorySchema.def.innerType.options).toContain("deep")
|
|
||||||
expect(categorySchema.def.innerType.options).toContain("ultrabrain")
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -76,13 +76,13 @@ export function createDelegateTask(options: DelegateTaskToolOptions): ToolDefini
|
|||||||
- category: For task delegation (uses Sisyphus-Junior with category-optimized model)
|
- category: For task delegation (uses Sisyphus-Junior with category-optimized model)
|
||||||
- subagent_type: For direct agent invocation (explore, librarian, oracle, etc.)
|
- subagent_type: For direct agent invocation (explore, librarian, oracle, etc.)
|
||||||
|
|
||||||
**DO NOT provide both.** category and subagent_type are mutually exclusive.
|
**DO NOT provide both.** If category is provided, subagent_type is ignored.
|
||||||
|
|
||||||
- load_skills: ALWAYS REQUIRED. Pass [] if no skills needed, or ["skill-1", "skill-2"] for category tasks.
|
- load_skills: ALWAYS REQUIRED. Pass [] if no skills needed, or ["skill-1", "skill-2"] for category tasks.
|
||||||
- category: Use predefined category → Spawns Sisyphus-Junior with category config
|
- category: Use predefined category → Spawns Sisyphus-Junior with category config
|
||||||
Available categories:
|
Available categories:
|
||||||
${categoryList}
|
${categoryList}
|
||||||
- subagent_type: Use a specific callable non-primary agent directly (for example: explore, librarian, oracle, metis, momus)
|
- subagent_type: Use specific agent directly (explore, librarian, oracle, metis, momus)
|
||||||
- run_in_background: REQUIRED. true=async (returns task_id), false=sync (waits). Use background=true ONLY for parallel exploration with 5+ independent queries.
|
- run_in_background: REQUIRED. true=async (returns task_id), false=sync (waits). Use background=true ONLY for parallel exploration with 5+ independent queries.
|
||||||
- session_id: Existing Task session to continue (from previous task output). Continues agent with FULL CONTEXT PRESERVED - saves tokens, maintains continuity.
|
- session_id: Existing Task session to continue (from previous task output). Continues agent with FULL CONTEXT PRESERVED - saves tokens, maintains continuity.
|
||||||
- command: The command that triggered this task (optional, for slash command tracking).
|
- command: The command that triggered this task (optional, for slash command tracking).
|
||||||
@@ -101,19 +101,21 @@ export function createDelegateTask(options: DelegateTaskToolOptions): ToolDefini
|
|||||||
description: tool.schema.string().describe("Short task description (3-5 words)"),
|
description: tool.schema.string().describe("Short task description (3-5 words)"),
|
||||||
prompt: tool.schema.string().describe("Full detailed prompt for the agent"),
|
prompt: tool.schema.string().describe("Full detailed prompt for the agent"),
|
||||||
run_in_background: tool.schema.boolean().describe("REQUIRED. true=async (returns task_id), false=sync (waits). Use false for task delegation, true ONLY for parallel exploration."),
|
run_in_background: tool.schema.boolean().describe("REQUIRED. true=async (returns task_id), false=sync (waits). Use false for task delegation, true ONLY for parallel exploration."),
|
||||||
category: tool.schema.enum(categoryNames).optional().describe(`REQUIRED if subagent_type not provided. Do NOT provide both category and subagent_type.`),
|
category: tool.schema.string().optional().describe(`REQUIRED if subagent_type not provided. Do NOT provide both category and subagent_type.`),
|
||||||
subagent_type: tool.schema.string().optional().describe("REQUIRED if category not provided. Do NOT provide both category and subagent_type. Must be a callable non-primary agent name returned by app.agents()."),
|
subagent_type: tool.schema.string().optional().describe("REQUIRED if category not provided. Do NOT provide both category and subagent_type."),
|
||||||
session_id: tool.schema.string().optional().describe("Existing Task session to continue"),
|
session_id: tool.schema.string().optional().describe("Existing Task session to continue"),
|
||||||
command: tool.schema.string().optional().describe("The command that triggered this task"),
|
command: tool.schema.string().optional().describe("The command that triggered this task"),
|
||||||
},
|
},
|
||||||
async execute(args: DelegateTaskArgs, toolContext) {
|
async execute(args: DelegateTaskArgs, toolContext) {
|
||||||
const ctx = toolContext as ToolContextWithMetadata
|
const ctx = toolContext as ToolContextWithMetadata
|
||||||
|
|
||||||
let categoryOverrideNote: string | undefined
|
|
||||||
if (args.category && args.subagent_type) {
|
|
||||||
categoryOverrideNote = `[Note: You provided both category="${args.category}" and subagent_type="${args.subagent_type}". category takes precedence \u2014 subagent_type was ignored. Next time, provide ONLY category.]`
|
|
||||||
}
|
|
||||||
if (args.category) {
|
if (args.category) {
|
||||||
|
if (args.subagent_type && args.subagent_type !== SISYPHUS_JUNIOR_AGENT) {
|
||||||
|
log("[task] category provided - overriding subagent_type to sisyphus-junior", {
|
||||||
|
category: args.category,
|
||||||
|
subagent_type: args.subagent_type,
|
||||||
|
})
|
||||||
|
}
|
||||||
args.subagent_type = SISYPHUS_JUNIOR_AGENT
|
args.subagent_type = SISYPHUS_JUNIOR_AGENT
|
||||||
}
|
}
|
||||||
await ctx.metadata?.({
|
await ctx.metadata?.({
|
||||||
@@ -221,8 +223,7 @@ export function createDelegateTask(options: DelegateTaskToolOptions): ToolDefini
|
|||||||
availableCategories,
|
availableCategories,
|
||||||
availableSkills,
|
availableSkills,
|
||||||
})
|
})
|
||||||
const result = await executeUnstableAgentTask(args, ctx, options, parentContext, agentToUse, categoryModel, systemContent, actualModel)
|
return executeUnstableAgentTask(args, ctx, options, parentContext, agentToUse, categoryModel, systemContent, actualModel)
|
||||||
return categoryOverrideNote ? `${categoryOverrideNote}\n\n${result}` : result
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const resolution = await resolveSubagentExecution(args, options, parentContext.agent, categoryExamples)
|
const resolution = await resolveSubagentExecution(args, options, parentContext.agent, categoryExamples)
|
||||||
@@ -245,13 +246,11 @@ export function createDelegateTask(options: DelegateTaskToolOptions): ToolDefini
|
|||||||
availableSkills,
|
availableSkills,
|
||||||
})
|
})
|
||||||
|
|
||||||
const prependNote = (result: string) => categoryOverrideNote ? `${categoryOverrideNote}\n\n${result}` : result
|
|
||||||
|
|
||||||
if (runInBackground) {
|
if (runInBackground) {
|
||||||
return prependNote(await executeBackgroundTask(args, ctx, options, parentContext, agentToUse, categoryModel, systemContent, fallbackChain))
|
return executeBackgroundTask(args, ctx, options, parentContext, agentToUse, categoryModel, systemContent, fallbackChain)
|
||||||
}
|
}
|
||||||
|
|
||||||
return prependNote(await executeSyncTask(args, ctx, options, parentContext, agentToUse, categoryModel, systemContent, modelInfo, fallbackChain))
|
return executeSyncTask(args, ctx, options, parentContext, agentToUse, categoryModel, systemContent, modelInfo, fallbackChain)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user