opencode-resolve 0.1.18 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/postinstall.mjs +260 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-resolve",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"description": "OpenCode plugin that adds a lightweight resolver/coder harness for continuous agentic coding.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://jshsakura.github.io/opencode-resolve/",
|
package/scripts/postinstall.mjs
CHANGED
|
@@ -20,9 +20,24 @@ const ADDITIVE_DEFAULTS = {
|
|
|
20
20
|
autoApprove: true,
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
23
|
+
// Heuristic strength scoring for an arbitrary provider/model id.
|
|
24
|
+
// Higher = "stronger" / more expensive in expected behavior. Heuristic-only.
|
|
25
|
+
const STRENGTH_BOOSTS = [
|
|
26
|
+
{ re: /\b(mini|flash|nano|lite|haiku|air|small)\b/i, score: -3 },
|
|
27
|
+
{ re: /\b(claude-3|gpt-3|gpt-4o-mini|o1-mini|o3-mini|4\.5)\b/i, score: -1 },
|
|
28
|
+
{ re: /\b(gpt-4o|opus|sonnet|gemini-1\.5)\b/i, score: 1 },
|
|
29
|
+
{ re: /\b(o1|o3|o4|reason|reasoning|pro|max|ultra|gold|sota)\b/i, score: 2 },
|
|
30
|
+
{ re: /\b(5\.5|5\.4|5\.3|5\.2|5\.1|sonnet-4|opus-4|opus-5|max-5|next|2026)\b/i, score: 2 },
|
|
31
|
+
{ re: /\b(codex|coder|code|coding)\b/i, score: 1 },
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
// Provider-neutral agents — safe to enable for everyone (no profile-specific model needed).
|
|
35
|
+
const DEFAULT_ENABLED_AGENTS = [
|
|
36
|
+
"coder", "resolver", "explorer", "reviewer", "deep-reviewer", "planner",
|
|
37
|
+
"architect", "debugger", "researcher",
|
|
38
|
+
]
|
|
39
|
+
const GPT_ENABLED_AGENTS = [...DEFAULT_ENABLED_AGENTS, "gpt", "gpt-coder", "codex"]
|
|
40
|
+
const GLM_ENABLED_AGENTS = [...DEFAULT_ENABLED_AGENTS, "glm"]
|
|
26
41
|
|
|
27
42
|
// ZAI local MCP server bootstrap for GLM users.
|
|
28
43
|
// Do not copy provider secrets from OpenCode's auth store into opencode.json.
|
|
@@ -293,11 +308,16 @@ async function chooseExistingResolveConfigAction(scriptedAnswers) {
|
|
|
293
308
|
const rl = createPromptInterface(scriptedAnswers)
|
|
294
309
|
try {
|
|
295
310
|
console.log("")
|
|
296
|
-
console.log(
|
|
297
|
-
console.log(
|
|
298
|
-
console.log(
|
|
299
|
-
console.log("
|
|
300
|
-
|
|
311
|
+
console.log("──────────────────────────────────────────────────────────────")
|
|
312
|
+
console.log(` opencode-resolve — existing config detected`)
|
|
313
|
+
console.log(` ${resolveConfigPath}`)
|
|
314
|
+
console.log("──────────────────────────────────────────────────────────────")
|
|
315
|
+
console.log("")
|
|
316
|
+
console.log("How do you want to handle it?")
|
|
317
|
+
console.log(" 1. keep — preserve existing settings, only add missing defaults (recommended)")
|
|
318
|
+
console.log(" 2. models — re-pick models only, keep the rest")
|
|
319
|
+
console.log(" 3. reset — back up the current file and run setup from scratch (model pins preserved)")
|
|
320
|
+
const answer = await askChoice(rl, "Choice [1=keep, 2=models, 3=reset, default 1]: ", ["1", "2", "3"], "1")
|
|
301
321
|
if (answer === "2") return "models"
|
|
302
322
|
return answer === "3" ? "fresh" : "update"
|
|
303
323
|
} finally {
|
|
@@ -337,7 +357,7 @@ async function createAdaptiveResolveConfig(opencodeConfig, scriptedAnswers, opti
|
|
|
337
357
|
(process.stdin.isTTY && process.stdout.isTTY) || forcePrompt,
|
|
338
358
|
)
|
|
339
359
|
const interactivePreset = canPrompt
|
|
340
|
-
? await buildInteractivePreset(currentModel, allModels, scriptedAnswers)
|
|
360
|
+
? await buildInteractivePreset(currentModel, allModels, scriptedAnswers, opencodeConfig)
|
|
341
361
|
: undefined
|
|
342
362
|
|
|
343
363
|
if (interactivePreset) {
|
|
@@ -413,7 +433,7 @@ async function reconfigureExistingModels(opencodeConfig, scriptedAnswers) {
|
|
|
413
433
|
const forcePrompt = readInstallerOption("force_prompt") === "1"
|
|
414
434
|
const canPrompt = Boolean((process.stdin.isTTY && process.stdout.isTTY) || forcePrompt)
|
|
415
435
|
const interactivePreset = canPrompt
|
|
416
|
-
? await buildInteractivePreset(currentModel, allModels, scriptedAnswers)
|
|
436
|
+
? await buildInteractivePreset(currentModel, allModels, scriptedAnswers, opencodeConfig)
|
|
417
437
|
: undefined
|
|
418
438
|
const preset = interactivePreset ?? {
|
|
419
439
|
label: getPresetLabel(currentModel),
|
|
@@ -582,7 +602,7 @@ function buildGPTOnlyPreset(model, gptModels) {
|
|
|
582
602
|
}
|
|
583
603
|
}
|
|
584
604
|
|
|
585
|
-
async function buildInteractivePreset(currentModel, allModels, scriptedAnswers) {
|
|
605
|
+
async function buildInteractivePreset(currentModel, allModels, scriptedAnswers, opencodeConfig) {
|
|
586
606
|
const choices = {
|
|
587
607
|
gpt: collectModelChoices(allModels, isGPTModel, OPENAI_MODEL_HINTS),
|
|
588
608
|
glm: collectModelChoices(allModels, isGLMModel, GLM_MODEL_HINTS),
|
|
@@ -592,6 +612,11 @@ async function buildInteractivePreset(currentModel, allModels, scriptedAnswers)
|
|
|
592
612
|
if (isGLMModel(currentModel)) choices.glm = unique([currentModel, ...choices.glm])
|
|
593
613
|
}
|
|
594
614
|
|
|
615
|
+
const hasGPTOrGLM = allModels.some((m) => isGPTModel(m) || isGLMModel(m))
|
|
616
|
+
const providerCount = opencodeConfig ? detectProvidersFromConfig(opencodeConfig).length : 0
|
|
617
|
+
const offerAuto = !hasGPTOrGLM && providerCount > 0
|
|
618
|
+
const defaultChoice = offerAuto ? "4" : "1"
|
|
619
|
+
|
|
595
620
|
const rl = createPromptInterface(scriptedAnswers)
|
|
596
621
|
try {
|
|
597
622
|
console.log("")
|
|
@@ -601,10 +626,22 @@ async function buildInteractivePreset(currentModel, allModels, scriptedAnswers)
|
|
|
601
626
|
console.log("──────────────────────────────────────────────────────────────")
|
|
602
627
|
console.log("")
|
|
603
628
|
console.log(`[${packageName}] Step 1/2 — Choose resolve profile:`)
|
|
604
|
-
console.log(
|
|
629
|
+
console.log(` 1. mix — neutral resolver plus optional Codex and GLM primary agents${offerAuto ? "" : " (recommended)"}`)
|
|
605
630
|
console.log(" 2. gpt — GPT/Codex-only, three-tier")
|
|
606
631
|
console.log(" 3. glm — GLM-only, three-tier")
|
|
607
|
-
|
|
632
|
+
if (offerAuto) {
|
|
633
|
+
console.log(` 4. auto — provider-agnostic tier setup from detected providers (recommended)`)
|
|
634
|
+
}
|
|
635
|
+
const validChoices = offerAuto ? ["1", "2", "3", "4"] : ["1", "2", "3"]
|
|
636
|
+
const profileAnswer = await askChoice(rl, `Profile [${validChoices.join(",")}, default ${defaultChoice}]: `, validChoices, defaultChoice)
|
|
637
|
+
|
|
638
|
+
if (profileAnswer === "4" && offerAuto) {
|
|
639
|
+
rl.close()
|
|
640
|
+
const generic = await buildGenericInteractivePreset(currentModel, opencodeConfig, scriptedAnswers)
|
|
641
|
+
if (generic) return generic
|
|
642
|
+
// fall through to mix if generic returned nothing
|
|
643
|
+
}
|
|
644
|
+
|
|
608
645
|
const profile = profileAnswer === "2" ? "gpt" : profileAnswer === "3" ? "glm" : "mix"
|
|
609
646
|
|
|
610
647
|
if (profile === "gpt") {
|
|
@@ -675,14 +712,22 @@ function createPromptInterface(scriptedAnswers) {
|
|
|
675
712
|
|
|
676
713
|
async function askThreeTier(rl, label, models) {
|
|
677
714
|
const choices = models.length > 0 ? models : (label.toLowerCase().includes("glm") ? GLM_MODEL_HINTS : OPENAI_MODEL_HINTS)
|
|
678
|
-
console.log("")
|
|
679
|
-
console.log(`[${packageName}] ${label} model choices:`)
|
|
680
|
-
choices.forEach((model, index) => console.log(` ${index + 1}. ${model}`))
|
|
681
715
|
const defaults = chooseThreeTier(choices, label.toLowerCase().includes("glm") ? "glm" : "gpt")
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
716
|
+
while (true) {
|
|
717
|
+
console.log("")
|
|
718
|
+
console.log(`[${packageName}] ${label} model choices:`)
|
|
719
|
+
choices.forEach((model, index) => console.log(` ${index + 1}. ${model}`))
|
|
720
|
+
const bronze = await askModel(rl, choices, `Pick ${label} bronze/scout [default ${defaults.bronze}]: `, defaults.bronze)
|
|
721
|
+
const silver = await askModel(rl, choices, `Pick ${label} silver/coder [default ${defaults.silver}]: `, defaults.silver)
|
|
722
|
+
const gold = await askModel(rl, choices, `Pick ${label} gold/reasoner [default ${defaults.gold}]: `, defaults.gold)
|
|
723
|
+
console.log("")
|
|
724
|
+
console.log(` → bronze: ${bronze}`)
|
|
725
|
+
console.log(` → silver: ${silver}`)
|
|
726
|
+
console.log(` → gold: ${gold}`)
|
|
727
|
+
const ok = await askYesNo(rl, `Confirm ${label} picks? [Y/n] (n re-asks all three): `, true)
|
|
728
|
+
if (ok) return { bronze, silver, gold }
|
|
729
|
+
console.log(`[${packageName}] re-asking ${label} picks…`)
|
|
730
|
+
}
|
|
686
731
|
}
|
|
687
732
|
|
|
688
733
|
async function askModel(rl, choices, question, defaultValue) {
|
|
@@ -853,6 +898,201 @@ function getPresetLabel(currentModel) {
|
|
|
853
898
|
return "inherited"
|
|
854
899
|
}
|
|
855
900
|
|
|
901
|
+
function inferModelStrength(modelId) {
|
|
902
|
+
if (typeof modelId !== "string") return 0
|
|
903
|
+
let score = 0
|
|
904
|
+
for (const { re, score: s } of STRENGTH_BOOSTS) {
|
|
905
|
+
if (re.test(modelId)) score += s
|
|
906
|
+
}
|
|
907
|
+
return score
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
function sortModelsByStrength(models) {
|
|
911
|
+
return [...models].sort((a, b) => inferModelStrength(a) - inferModelStrength(b))
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
function detectProvidersFromConfig(config) {
|
|
915
|
+
const providers = new Map()
|
|
916
|
+
const note = (providerId, modelId) => {
|
|
917
|
+
if (!providerId) return
|
|
918
|
+
const list = providers.get(providerId) ?? []
|
|
919
|
+
if (modelId && !list.includes(modelId)) list.push(modelId)
|
|
920
|
+
providers.set(providerId, list)
|
|
921
|
+
}
|
|
922
|
+
if (isObject(config.provider)) {
|
|
923
|
+
for (const [providerId, providerConfig] of Object.entries(config.provider)) {
|
|
924
|
+
providers.set(providerId, providers.get(providerId) ?? [])
|
|
925
|
+
if (isObject(providerConfig) && isObject(providerConfig.models)) {
|
|
926
|
+
for (const [modelKey, modelEntry] of Object.entries(providerConfig.models)) {
|
|
927
|
+
if (typeof modelKey === "string" && modelKey.length > 0) {
|
|
928
|
+
note(providerId, qualifyModelId(providerId, modelKey))
|
|
929
|
+
}
|
|
930
|
+
if (typeof modelEntry === "string") note(providerId, qualifyModelId(providerId, modelEntry))
|
|
931
|
+
else if (isObject(modelEntry) && typeof modelEntry.id === "string") {
|
|
932
|
+
note(providerId, qualifyModelId(providerId, modelEntry.id))
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
// Add implicit providers from top-level model and agent overrides
|
|
939
|
+
const additional = []
|
|
940
|
+
if (typeof config.model === "string" && config.model.includes("/")) additional.push(config.model)
|
|
941
|
+
if (isObject(config.agent)) {
|
|
942
|
+
for (const agent of Object.values(config.agent)) {
|
|
943
|
+
if (isObject(agent) && typeof agent.model === "string" && agent.model.includes("/")) {
|
|
944
|
+
additional.push(agent.model)
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
for (const fullId of additional) {
|
|
949
|
+
const slash = fullId.indexOf("/")
|
|
950
|
+
if (slash < 0) continue
|
|
951
|
+
note(fullId.slice(0, slash), fullId)
|
|
952
|
+
}
|
|
953
|
+
return [...providers.entries()]
|
|
954
|
+
.map(([id, models]) => ({ id, models: unique(models) }))
|
|
955
|
+
.filter((p) => p.models.length > 0)
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
function pickTierShapeForModelCount(count) {
|
|
959
|
+
if (count >= 3) return "three"
|
|
960
|
+
if (count === 2) return "two"
|
|
961
|
+
return "single"
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
function buildGenericResolveModels(tiers) {
|
|
965
|
+
if (tiers.shape === "three") {
|
|
966
|
+
return {
|
|
967
|
+
bronze: tiers.bronze,
|
|
968
|
+
silver: tiers.silver,
|
|
969
|
+
gold: tiers.gold,
|
|
970
|
+
explorer: "bronze",
|
|
971
|
+
coder: "silver",
|
|
972
|
+
resolver: "gold",
|
|
973
|
+
reviewer: "gold",
|
|
974
|
+
"deep-reviewer": "gold",
|
|
975
|
+
planner: "gold",
|
|
976
|
+
architect: "gold",
|
|
977
|
+
debugger: "silver",
|
|
978
|
+
researcher: "bronze",
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
if (tiers.shape === "two") {
|
|
982
|
+
return {
|
|
983
|
+
silver: tiers.silver,
|
|
984
|
+
gold: tiers.gold,
|
|
985
|
+
explorer: "silver",
|
|
986
|
+
coder: "silver",
|
|
987
|
+
resolver: "gold",
|
|
988
|
+
reviewer: "gold",
|
|
989
|
+
"deep-reviewer": "gold",
|
|
990
|
+
planner: "gold",
|
|
991
|
+
architect: "gold",
|
|
992
|
+
debugger: "silver",
|
|
993
|
+
researcher: "silver",
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return {
|
|
997
|
+
gold: tiers.gold,
|
|
998
|
+
explorer: "gold",
|
|
999
|
+
coder: "gold",
|
|
1000
|
+
resolver: "gold",
|
|
1001
|
+
reviewer: "gold",
|
|
1002
|
+
"deep-reviewer": "gold",
|
|
1003
|
+
planner: "gold",
|
|
1004
|
+
architect: "gold",
|
|
1005
|
+
debugger: "gold",
|
|
1006
|
+
researcher: "gold",
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
async function buildGenericInteractivePreset(currentModel, opencodeConfig, scriptedAnswers) {
|
|
1011
|
+
const providers = detectProvidersFromConfig(opencodeConfig)
|
|
1012
|
+
if (providers.length === 0) return undefined
|
|
1013
|
+
|
|
1014
|
+
const rl = createPromptInterface(scriptedAnswers)
|
|
1015
|
+
try {
|
|
1016
|
+
console.log("")
|
|
1017
|
+
console.log("──────────────────────────────────────────────────────────────")
|
|
1018
|
+
console.log(` opencode-resolve setup — provider-agnostic mode`)
|
|
1019
|
+
console.log(` ${providers.length} provider${providers.length === 1 ? "" : "s"} detected in opencode.json`)
|
|
1020
|
+
console.log("──────────────────────────────────────────────────────────────")
|
|
1021
|
+
|
|
1022
|
+
// 1. Pick provider
|
|
1023
|
+
let chosenProvider
|
|
1024
|
+
if (providers.length === 1) {
|
|
1025
|
+
chosenProvider = providers[0]
|
|
1026
|
+
console.log("")
|
|
1027
|
+
console.log(`[${packageName}] only one provider available — using "${chosenProvider.id}"`)
|
|
1028
|
+
} else {
|
|
1029
|
+
console.log("")
|
|
1030
|
+
console.log(`[${packageName}] Step 1/3 — Pick provider:`)
|
|
1031
|
+
providers.forEach((p, i) => {
|
|
1032
|
+
const marker = currentModel?.startsWith(`${p.id}/`) ? " ← top-level model" : ""
|
|
1033
|
+
console.log(` ${i + 1}. ${p.id} (${p.models.length} models)${marker}`)
|
|
1034
|
+
})
|
|
1035
|
+
const defaultIdx = Math.max(1, providers.findIndex((p) => currentModel?.startsWith(`${p.id}/`)) + 1)
|
|
1036
|
+
const valid = providers.map((_, i) => String(i + 1))
|
|
1037
|
+
const answer = await askChoice(rl, `Provider [1..${providers.length}, default ${defaultIdx}]: `, valid, String(defaultIdx))
|
|
1038
|
+
chosenProvider = providers[Number.parseInt(answer, 10) - 1]
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
const sorted = sortModelsByStrength(chosenProvider.models)
|
|
1042
|
+
const defaultShape = pickTierShapeForModelCount(sorted.length)
|
|
1043
|
+
|
|
1044
|
+
// 2. Pick tier shape
|
|
1045
|
+
console.log("")
|
|
1046
|
+
console.log(`[${packageName}] Step 2/3 — Choose tier shape:`)
|
|
1047
|
+
console.log(` 1. single — one model for every role (good for cost simplicity)`)
|
|
1048
|
+
console.log(` 2. two — fast + strong split (explorer/coder + resolver/reviewer/…)`)
|
|
1049
|
+
console.log(` 3. three — bronze + silver + gold full split (recommended when available)`)
|
|
1050
|
+
const shapeDefault = defaultShape === "three" ? "3" : defaultShape === "two" ? "2" : "1"
|
|
1051
|
+
const shapeAns = await askChoice(rl, `Tier shape [1,2,3, default ${shapeDefault}]: `, ["1", "2", "3"], shapeDefault)
|
|
1052
|
+
const shape = shapeAns === "3" ? "three" : shapeAns === "2" ? "two" : "single"
|
|
1053
|
+
|
|
1054
|
+
// 3. Pick models
|
|
1055
|
+
const weakest = sorted[0]
|
|
1056
|
+
const strongest = sorted[sorted.length - 1]
|
|
1057
|
+
const middle = sorted[Math.floor((sorted.length - 1) / 2)]
|
|
1058
|
+
console.log("")
|
|
1059
|
+
console.log(`[${packageName}] Step 3/3 — Pick models (defaults inferred from name strength):`)
|
|
1060
|
+
sorted.forEach((m, i) => console.log(` ${i + 1}. ${m}`))
|
|
1061
|
+
|
|
1062
|
+
while (true) {
|
|
1063
|
+
const tiers = { shape }
|
|
1064
|
+
if (shape === "three") {
|
|
1065
|
+
tiers.bronze = await askModel(rl, sorted, `Bronze (scout for explorer/researcher) [default ${weakest}]: `, weakest)
|
|
1066
|
+
tiers.silver = await askModel(rl, sorted, `Silver (coder/debugger) [default ${middle}]: `, middle)
|
|
1067
|
+
tiers.gold = await askModel(rl, sorted, `Gold (resolver/reviewer/deep-reviewer/planner/architect) [default ${strongest}]: `, strongest)
|
|
1068
|
+
} else if (shape === "two") {
|
|
1069
|
+
tiers.silver = await askModel(rl, sorted, `Silver (fast: coder/explorer/debugger/researcher) [default ${weakest}]: `, weakest)
|
|
1070
|
+
tiers.gold = await askModel(rl, sorted, `Gold (strong: resolver/reviewer/…/architect) [default ${strongest}]: `, strongest)
|
|
1071
|
+
} else {
|
|
1072
|
+
tiers.gold = await askModel(rl, sorted, `Model for all roles [default ${strongest}]: `, strongest)
|
|
1073
|
+
}
|
|
1074
|
+
console.log("")
|
|
1075
|
+
for (const [k, v] of Object.entries(tiers)) {
|
|
1076
|
+
if (k === "shape") continue
|
|
1077
|
+
console.log(` → ${k.padEnd(7)} ${v}`)
|
|
1078
|
+
}
|
|
1079
|
+
const ok = await askYesNo(rl, `Confirm picks? [Y/n] (n re-asks all): `, true)
|
|
1080
|
+
if (ok) {
|
|
1081
|
+
return {
|
|
1082
|
+
label: `generic-${shape}-tier`,
|
|
1083
|
+
profile: "mix",
|
|
1084
|
+
enabled: DEFAULT_ENABLED_AGENTS,
|
|
1085
|
+
models: buildGenericResolveModels(tiers),
|
|
1086
|
+
agents: {},
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
console.log(`[${packageName}] re-asking picks…`)
|
|
1090
|
+
}
|
|
1091
|
+
} finally {
|
|
1092
|
+
rl.close()
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
|
|
856
1096
|
function isGLMModel(currentModel) {
|
|
857
1097
|
if (!currentModel) return false
|
|
858
1098
|
const lower = currentModel.toLowerCase()
|