Skip to content

Commit 66c3efb

Browse files
authored
Merge pull request #91 from AltimateAI/fix/test-failures-v2
fix: resolve all test failures from fork restructure
1 parent f5df101 commit 66c3efb

17 files changed

Lines changed: 299 additions & 65 deletions
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
#!/usr/bin/env node
2+
3+
const childProcess = require("child_process")
4+
const fs = require("fs")
5+
const path = require("path")
6+
const os = require("os")
7+
8+
function run(target) {
9+
const result = childProcess.spawnSync(target, process.argv.slice(2), {
10+
stdio: "inherit",
11+
})
12+
if (result.error) {
13+
console.error(result.error.message)
14+
process.exit(1)
15+
}
16+
const code = typeof result.status === "number" ? result.status : 0
17+
process.exit(code)
18+
}
19+
20+
const envPath = process.env.ALTIMATE_CODE_BIN_PATH
21+
if (envPath) {
22+
run(envPath)
23+
}
24+
25+
const scriptPath = fs.realpathSync(__filename)
26+
const scriptDir = path.dirname(scriptPath)
27+
28+
//
29+
const cached = path.join(scriptDir, ".altimate-code")
30+
if (fs.existsSync(cached)) {
31+
run(cached)
32+
}
33+
34+
const platformMap = {
35+
darwin: "darwin",
36+
linux: "linux",
37+
win32: "windows",
38+
}
39+
const archMap = {
40+
x64: "x64",
41+
arm64: "arm64",
42+
arm: "arm",
43+
}
44+
45+
let platform = platformMap[os.platform()]
46+
if (!platform) {
47+
platform = os.platform()
48+
}
49+
let arch = archMap[os.arch()]
50+
if (!arch) {
51+
arch = os.arch()
52+
}
53+
const scope = "@altimateai"
54+
const base = "altimate-code-" + platform + "-" + arch
55+
const binary = platform === "windows" ? "altimate-code.exe" : "altimate-code"
56+
57+
function supportsAvx2() {
58+
if (arch !== "x64") return false
59+
60+
if (platform === "linux") {
61+
try {
62+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
63+
} catch {
64+
return false
65+
}
66+
}
67+
68+
if (platform === "darwin") {
69+
try {
70+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
71+
encoding: "utf8",
72+
timeout: 1500,
73+
})
74+
if (result.status !== 0) return false
75+
return (result.stdout || "").trim() === "1"
76+
} catch {
77+
return false
78+
}
79+
}
80+
81+
if (platform === "windows") {
82+
const cmd =
83+
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
84+
85+
for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
86+
try {
87+
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
88+
encoding: "utf8",
89+
timeout: 3000,
90+
windowsHide: true,
91+
})
92+
if (result.status !== 0) continue
93+
const out = (result.stdout || "").trim().toLowerCase()
94+
if (out === "true" || out === "1") return true
95+
if (out === "false" || out === "0") return false
96+
} catch {
97+
continue
98+
}
99+
}
100+
101+
return false
102+
}
103+
104+
return false
105+
}
106+
107+
const names = (() => {
108+
const avx2 = supportsAvx2()
109+
const baseline = arch === "x64" && !avx2
110+
111+
if (platform === "linux") {
112+
const musl = (() => {
113+
try {
114+
if (fs.existsSync("/etc/alpine-release")) return true
115+
} catch {
116+
// ignore
117+
}
118+
119+
try {
120+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
121+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
122+
if (text.includes("musl")) return true
123+
} catch {
124+
// ignore
125+
}
126+
127+
return false
128+
})()
129+
130+
if (musl) {
131+
if (arch === "x64") {
132+
if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
133+
return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
134+
}
135+
return [`${base}-musl`, base]
136+
}
137+
138+
if (arch === "x64") {
139+
if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
140+
return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
141+
}
142+
return [base, `${base}-musl`]
143+
}
144+
145+
if (arch === "x64") {
146+
if (baseline) return [`${base}-baseline`, base]
147+
return [base, `${base}-baseline`]
148+
}
149+
return [base]
150+
})()
151+
152+
function findBinary(startDir) {
153+
let current = startDir
154+
for (;;) {
155+
const modules = path.join(current, "node_modules")
156+
if (fs.existsSync(modules)) {
157+
for (const name of names) {
158+
const candidate = path.join(modules, scope, name, "bin", binary)
159+
if (fs.existsSync(candidate)) return candidate
160+
}
161+
}
162+
const parent = path.dirname(current)
163+
if (parent === current) {
164+
return
165+
}
166+
current = parent
167+
}
168+
}
169+
170+
const resolved = findBinary(scriptDir)
171+
if (!resolved) {
172+
console.error(
173+
"It seems that your package manager failed to install the right version of the altimate-code CLI for your platform. You can try manually installing " +
174+
names.map((n) => `\"${scope}/${n}\"`).join(" or ") +
175+
" package",
176+
)
177+
process.exit(1)
178+
}
179+
180+
run(resolved)

packages/opencode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"bin": {
1616
"opencode": "./bin/opencode",
1717
"altimate": "./bin/altimate",
18-
"altimate-code": "./bin/altimate"
18+
"altimate-code": "./bin/altimate-code"
1919
},
2020
"exports": {
2121
"./*": "./src/*.ts"

packages/opencode/src/acp/agent.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export namespace ACP {
137137
private eventAbort = new AbortController()
138138
private eventStarted = false
139139
private bashSnapshots = new Map<string, string>()
140+
private pendingEmitted = new Set<string>()
140141
private permissionQueues = new Map<string, Promise<void>>()
141142
private permissionOptions: PermissionOption[] = [
142143
{ optionId: "once", kind: "allow_once", name: "Allow once" },
@@ -290,6 +291,8 @@ export namespace ACP {
290291
if (part.type === "tool") {
291292
switch (part.state.status) {
292293
case "pending":
294+
this.bashSnapshots.delete(part.callID)
295+
this.pendingEmitted.add(part.callID)
293296
await this.connection
294297
.sessionUpdate({
295298
sessionId,
@@ -309,6 +312,25 @@ export namespace ACP {
309312
return
310313

311314
case "running":
315+
if (!this.pendingEmitted.has(part.callID)) {
316+
this.pendingEmitted.add(part.callID)
317+
await this.connection
318+
.sessionUpdate({
319+
sessionId,
320+
update: {
321+
sessionUpdate: "tool_call",
322+
toolCallId: part.callID,
323+
title: part.tool,
324+
kind: toToolKind(part.tool),
325+
status: "pending",
326+
locations: [],
327+
rawInput: {},
328+
},
329+
})
330+
.catch((error) => {
331+
log.error("failed to send synthetic tool pending to ACP", { error })
332+
})
333+
}
312334
const output = this.bashOutput(part)
313335
const content: ToolCallContent[] = []
314336
if (output) {
@@ -354,6 +376,7 @@ export namespace ACP {
354376
title: part.tool,
355377
locations: toLocations(part.tool, part.state.input),
356378
rawInput: part.state.input,
379+
...(content.length > 0 && { content }),
357380
},
358381
})
359382
.catch((error) => {
@@ -838,6 +861,7 @@ export namespace ACP {
838861
if (part.type === "tool") {
839862
switch (part.state.status) {
840863
case "pending":
864+
this.pendingEmitted.add(part.callID)
841865
await this.connection
842866
.sessionUpdate({
843867
sessionId,
@@ -856,6 +880,25 @@ export namespace ACP {
856880
})
857881
break
858882
case "running":
883+
if (!this.pendingEmitted.has(part.callID)) {
884+
this.pendingEmitted.add(part.callID)
885+
await this.connection
886+
.sessionUpdate({
887+
sessionId,
888+
update: {
889+
sessionUpdate: "tool_call",
890+
toolCallId: part.callID,
891+
title: part.tool,
892+
kind: toToolKind(part.tool),
893+
status: "pending",
894+
locations: [],
895+
rawInput: {},
896+
},
897+
})
898+
.catch((err) => {
899+
log.error("failed to send synthetic tool pending to ACP", { error: err })
900+
})
901+
}
859902
await this.connection
860903
.sessionUpdate({
861904
sessionId,

packages/opencode/src/provider/error.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export namespace ProviderError {
2020
/exceeded model token limit/i, // Kimi For Coding, Moonshot
2121
/context[_ ]length[_ ]exceeded/i, // Generic fallback
2222
/request entity too large/i, // HTTP 413
23+
/the request was too long/i, // Azure OpenAI
24+
/maximum tokens for requested operation/i, // Azure OpenAI
2325
]
2426

2527
function isOpenAiErrorRetryable(e: APICallError) {

0 commit comments

Comments
 (0)