@@ -16,11 +16,27 @@ const packageRoot = getPackageRoot(import.meta.url)
1616const AGENTS_SOURCE_DIR = getAgentsSourceDir ( packageRoot )
1717
1818/**
19- * Returns a user-friendly error message based on the error code
20- * @param {Error & {code?: string} } error - The error object
19+ * Returns a user-friendly error message based on the error code.
20+ *
21+ * Translates Node.js filesystem error codes into human-readable messages
22+ * that help users understand and resolve installation issues.
23+ *
24+ * @param {Error & {code?: string} } error - The error object from a failed fs operation
2125 * @param {string } file - The filename being copied
2226 * @param {string } targetPath - The target path for the file
23- * @returns {string } A helpful error message
27+ * @returns {string } A helpful error message describing the issue and potential solution
28+ *
29+ * @example
30+ * // Permission denied error
31+ * const err = Object.assign(new Error(), { code: 'EACCES' })
32+ * getErrorMessage(err, 'agent.md', '/home/user/.config/opencode/agents/agent.md')
33+ * // Returns: "Permission denied. Check write permissions for /home/user/.config/opencode/agents"
34+ *
35+ * @example
36+ * // File not found error
37+ * const err = Object.assign(new Error(), { code: 'ENOENT' })
38+ * getErrorMessage(err, 'missing.md', '/target/missing.md')
39+ * // Returns: "Source file not found: missing.md"
2440 */
2541function getErrorMessage ( error , file , targetPath ) {
2642 const code = error . code
@@ -41,6 +57,25 @@ function getErrorMessage(error, file, targetPath) {
4157 }
4258}
4359
60+ /**
61+ * Main entry point for the postinstall script.
62+ *
63+ * Copies all agent markdown files from the package's agents/ directory
64+ * to the OpenCode configuration directory (~/.config/opencode/agents/).
65+ * This enables OpenCode to discover and use the installed agents.
66+ *
67+ * The function handles partial failures gracefully, installing as many
68+ * agents as possible and reporting individual failures.
69+ *
70+ * @returns {void }
71+ *
72+ * @throws {never } Does not throw - uses process.exit() for error conditions
73+ *
74+ * Exit codes:
75+ * - 0: All agents installed successfully, or partial success with some failures
76+ * - 1: Complete failure - source directory missing, no agent files found,
77+ * or all file copies failed
78+ */
4479function main ( ) {
4580 console . log ( "opencode-plugin-opencoder: Installing agents..." )
4681
0 commit comments