{"record":{"id":"1e62c288faf44666","repo":"can1357/oh-my-pi","slug":"trusted-extension-must-be-a-module-file-not-a-dir","errorCode":null,"errorMessage":"Trusted extension must be a module file, not a directory: ${trustedPath}","messagePattern":"Trusted extension must be a module file, not a directory: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/main.ts","lineNumber":398,"sourceCode":"\trawArgs: string[];\n\tcreateSession: (options: CreateAgentSessionOptions) => Promise<CreateAgentSessionResult>;\n}\n\nasync function loadTrustedSessionExtensions(\n\toptions: Pick<CreateAgentSessionOptions, \"additionalExtensionPaths\">,\n\tcwd: string,\n\teventBus: EventBus,\n) {\n\tconst paths = options.additionalExtensionPaths ?? [];\n\tfor (const trustedPath of paths) {\n\t\tlet stat: fsSync.Stats;\n\t\ttry {\n\t\t\tstat = fsSync.statSync(trustedPath);\n\t\t} catch {\n\t\t\tthrow new Error(`Trusted extension must be an existing module file: ${trustedPath}`);\n\t\t}\n\t\tif (!stat.isFile()) {\n\t\t\tthrow new Error(`Trusted extension must be a module file, not a directory: ${trustedPath}`);\n\t\t}\n\t}\n\treturn loadExtensions(paths, cwd, eventBus);\n}\n\n/**\n * Build the per-`session/new` factory used by ACP mode.\n *\n * MCP servers in ACP sessions are owned exclusively by the ACP client, which\n * supplies them through `session/new.mcpServers` and re-applies them via\n * {@link AcpAgent#configureMcpServers}. We therefore force `enableMCP: false`\n * on every session created here so {@link createAgentSession} skips the on-disk\n * `.mcp.json` discovery path — otherwise host MCP tools land in the session's\n * tool registry and shadow the client-supplied servers (issue #1234).\n */\nexport function createAcpSessionFactory(args: AcpSessionFactoryOptions): AcpSessionFactory {\n\treturn async (cwd, factoryOptions) => {\n\t\tconst nextSettings = await args.settings.cloneForCwd(cwd);","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/main.ts#L380-L416","documentation":"loadTrustedSessionExtensions validates every path passed via --trusted-extension before loading it. After confirming the path exists (a missing path raises the sibling 'must be an existing module file' error), it stats the path and throws if it is not a regular file — e.g. a directory was supplied. Extensions are ES modules loaded via import, so only module files are valid.","triggerScenarios":"Running omp with --trusted-extension pointing at a directory that exists (e.g. --trusted-extension ./extensions or ~/.omp/extensions), instead of a concrete .ts/.js module file.","commonSituations":"Users assume extensions can be given as a folder to auto-load all files inside; shell tab-completion fills in a directory; docs or dotfiles point at an extension package directory rather than its entry file.","solutions":["Pass the extension's module entry file (e.g. ~/.omp/extensions/my-ext/index.ts), not its directory.","Check the path with ls: if it lists a directory, append the entry file name (index.ts/index.js or whatever package exports).","If you want a directory of extensions loaded, list each module file explicitly as separate --trusted-extension flags."],"exampleFix":"// before\nomp --trusted-extension ~/.omp/extensions/my-ext\n// after\nomp --trusted-extension ~/.omp/extensions/my-ext/index.ts","handlingStrategy":"validation","validationCode":"import * as fsSync from \"node:fs\";\nconst trustedPath = process.argv[/* ... */];\nconst stat = fsSync.statSync(trustedPath);\nif (!stat.isFile()) throw new Error(`--trusted-extension must be a file: ${trustedPath}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always point --trusted-extension at the entry module file, never a folder.","Use tab-completion carefully: append /index.ts when a directory is completed.","Script launchers should stat the path and assert isFile() before exec."],"tags":["cli","extensions","path-validation"],"backgroundTag":"extension-path-is-directory","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}