forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-agent-deps.mjs
More file actions
102 lines (95 loc) · 4.44 KB
/
Copy pathcheck-agent-deps.mjs
File metadata and controls
102 lines (95 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env node
// Fails LOUD, at install/build time, when a runtime dependency the coding-agent
// (ACP) system needs is missing from node_modules.
//
// The failure mode this guards against: `@agentclientprotocol/claude-agent-acp`
// was present in pnpm-lock.yaml but absent from node_modules on a fresh
// checkout. Nothing caught it at build time because it is loaded two different
// ways that a bundler never resolution-checks:
// - src/main/codingAgent/claude-acp-entry.mjs pulls it in via a dynamic
// `await import(...)` (deliberately, so its module-load console noise never
// hits stdout before the console redirect — see that file's header comment).
// - src/main/codingAgent/claudeCode.ts imports its own entry script via a
// `?asset` import, which electron-vite treats as an opaque path string, not
// a module to bundle.
// Every agent task failed ERR_MODULE_NOT_FOUND at runtime with zero build-time
// signal. `better-sqlite3` and `koffi` are native addons that electron-vite
// externalizes rather than bundles, so they have the same blind spot.
//
// Run automatically via `postinstall`; also runnable standalone:
// pnpm check:agent-deps
import { existsSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { checkClaudeBinary } from './claude-binary-check.mjs'
const CRITICAL_DEPS = [
'@agentclientprotocol/claude-agent-acp', // dynamically imported by src/main/codingAgent/claude-acp-entry.mjs
// The pi CLI (spawned by src/main/codingAgent/piMono.ts under
// ELECTRON_RUN_AS_NODE) and its runtime peer. Resolved by createRequire at
// runtime, so a bundler never resolution-checks them — same ERR_MODULE_NOT_FOUND
// blind spot as the ACP entry.
'@earendil-works/pi-coding-agent',
'@earendil-works/pi-ai',
'better-sqlite3', // native addon — src/main/ipc/db.ts, kgWorker.ts, integrations/stickyNotes.ts
'koffi' // native addon — src/main/bar/keyState.ts, meeting/processSnapshot.ts, meeting/micConsentStore.ts, usage/*
]
const missing = []
for (const dep of CRITICAL_DEPS) {
try {
import.meta.resolve(dep)
} catch (err) {
missing.push({ dep, message: err instanceof Error ? err.message : String(err) })
}
}
// pi-mono spawns the CLI file directly (bin.pi = dist/cli.js). The package's
// exports map does not expose that subpath, so piMono.ts resolves the package
// root and derives the sibling cli.js — mirror that here so a missing/renamed
// cli.js fails loud at install/build, not at first agent turn.
try {
const indexPath = fileURLToPath(import.meta.resolve('@earendil-works/pi-coding-agent'))
const cliPath = join(dirname(indexPath), 'cli.js')
if (!existsSync(cliPath)) {
missing.push({
dep: '@earendil-works/pi-coding-agent/dist/cli.js',
message: `resolved package root but cli.js is absent at ${cliPath}`
})
}
} catch (err) {
// A failure here is already reported by the '@earendil-works/pi-coding-agent'
// entry above; only add detail if that somehow resolved.
if (!missing.some((m) => m.dep === '@earendil-works/pi-coding-agent')) {
missing.push({
dep: '@earendil-works/pi-coding-agent/dist/cli.js',
message: err instanceof Error ? err.message : String(err)
})
}
}
// The Claude Code EXECUTABLE (claude.exe, from the binary-only optional
// package @anthropic-ai/claude-agent-sdk-win32-x64) can be silently absent or
// truncated after a failed optional download — pnpm still exits 0 and
// import.meta.resolve() can't see a binary-only package. Without it, agent
// tasks pass the ACP handshake and then have nothing to spawn. See
// claude-binary-check.mjs (validated against a real failed install in
// PR #9304 review).
const binaryCheck = checkClaudeBinary(join(dirname(fileURLToPath(import.meta.url)), '..'))
if (!binaryCheck.ok) {
missing.push({
dep: '@anthropic-ai/claude-agent-sdk-win32-x64/claude.exe',
message: binaryCheck.reason
})
}
if (missing.length > 0) {
console.error(
'\n[check-agent-deps] Missing runtime dependencies — the app WILL crash at runtime ' +
'(ERR_MODULE_NOT_FOUND) with no build-time warning otherwise:\n'
)
for (const { dep, message } of missing) {
console.error(` - ${dep}\n ${message}`)
}
console.error(
'\nFix: run `pnpm install` from desktop/windows/. If the problem persists, delete ' +
'node_modules and reinstall.\n'
)
process.exit(1)
}
console.log(`[check-agent-deps] OK — resolved: ${CRITICAL_DEPS.join(', ')}`)