|
| 1 | +You are a senior software developer, you code like Donald Knuth. |
| 2 | + |
| 3 | +# Task |
| 4 | + |
| 5 | +Implement the following feature! |
| 6 | + |
| 7 | +- Create a plan! |
| 8 | +- Create new files when needed! |
| 9 | + |
| 10 | +Requirements: |
| 11 | + |
| 12 | +The install script fails to decide correctly if it runs directly or not because differences in paths: |
| 13 | + |
| 14 | +file:///C:/work/tmp/Junior/scripts/installBashIfWindows.js vs file://C:\work\tmp\Junior\scripts\installBashIfWindows.js |
| 15 | + |
| 16 | +Remove this check, the file should only export the fn, not run it. Instead, move it to a newly created scripts/postinstall/ dir and import it from the postinstall script. Also update package.json accordingly. |
| 17 | + |
| 18 | + |
| 19 | +## Project Specifics |
| 20 | + |
| 21 | +- Every js file should *only export a single function or signal*! eg.: in createGitRepo.js: export function createGitRepo ( .... |
| 22 | +- Use *ES6 imports*! |
| 23 | +- Prefer *async/await* over promises! |
| 24 | +- The frontend uses *Solidjs* and Tailwind, edit .jsx files accordingly! |
| 25 | + |
| 26 | +Write concise, self-documenting and idiomatic ES6 code! |
| 27 | + |
| 28 | +# Output Format |
| 29 | + |
| 30 | +Encode and enclose your results as ./change.sh, a shell script that creates and changes files and does everything to solve the task. |
| 31 | +Avoid using sed. Always heredoc full files. |
| 32 | + |
| 33 | +OS: Debian |
| 34 | + |
| 35 | + |
| 36 | +Installed tools: npm, jq |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +EXAMPLE START |
| 42 | +```sh |
| 43 | +#!/bin/sh |
| 44 | +set -e |
| 45 | +goal=[Task description, max 9 words] |
| 46 | +echo "Plan:" |
| 47 | +echo "1. [...]" |
| 48 | + |
| 49 | +# Always provide the complete contents for the modified files without omitting any parts! |
| 50 | +cat > x.js << EOF |
| 51 | + let i = 1 |
| 52 | + console.log(\`i: \${i}\`) |
| 53 | +EOF |
| 54 | +echo "\033[32mDone: $goal\033[0m\n" |
| 55 | +``` |
| 56 | +EXAMPLE END |
| 57 | + |
| 58 | +Before starting, check if you need more files or info to solve the task. |
| 59 | + |
| 60 | +If the task is not clear: |
| 61 | + |
| 62 | +EXAMPLE START |
| 63 | +I need more information to solve the task. [Description of the missing info] |
| 64 | +EXAMPLE END |
| 65 | + |
| 66 | +Do not edit files not provided in the working set! |
| 67 | +If you need more files: |
| 68 | + |
| 69 | +EXAMPLE START |
| 70 | +`filepath1` is needed to solve the task but is not in the working set. |
| 71 | +EXAMPLE END |
| 72 | + |
| 73 | +# Working set |
| 74 | + |
| 75 | +package.json: |
| 76 | +``` |
| 77 | +{ |
| 78 | + "name": "@aijunior/dev", |
| 79 | + "version": "0.3.22", |
| 80 | + "description": "Your AI Contributor which codes itself", |
| 81 | + "type": "module", |
| 82 | + "main": "src/main.js", |
| 83 | + "bin": { |
| 84 | + "junior": "dist/bin/web.js", |
| 85 | + "junior-web": "dist/bin/web.js", |
| 86 | + "junior-cli": "dist/bin/cli.js", |
| 87 | + "junior-init": "dist/bin/init.js", |
| 88 | + "junior-rollback": "dist/bin/rollback.js", |
| 89 | + "junior-news": "dist/bin/readGitHistoryToMd.js" |
| 90 | + }, |
| 91 | + "scripts": { |
| 92 | + "cli": "node scripts/cli.js", |
| 93 | + "start": "node scripts/dev.js", |
| 94 | + "update-logo": "node ./scripts/updateLogo.js", |
| 95 | + "clear-branches": "node ./scripts/clearBranchesCommand.js $@", |
| 96 | + "test": "cypress open", |
| 97 | + "rollback": "node scripts/junior-rollback.js", |
| 98 | + "build:frontend": "cd ./src/frontend/ && vite build --emptyOutDir", |
| 99 | + "build:backend": "cd src/backend && rollup --config rollup.config.js", |
| 100 | + "dev": "npm run start", |
| 101 | + "build": "npm run build:frontend && npm run build:backend", |
| 102 | + "postinstall": "node scripts/installBashIfWindows.js && node scripts/postinstall.js" |
| 103 | + }, |
| 104 | + "keywords": [ |
| 105 | + "cli", |
| 106 | + "uppercase" |
| 107 | + ], |
| 108 | + "author": "", |
| 109 | + "license": "MIT", |
| 110 | + "dependencies": { |
| 111 | + "@homebridge/node-pty-prebuilt-multiarch": "^0.11.14", |
| 112 | + "@types/js-yaml": "^4.0.5", |
| 113 | + "autoprefixer": "^10.4.14", |
| 114 | + "chatgpt": "^5.2.4", |
| 115 | + "cors": "^2.8.5", |
| 116 | + "ejs": "^3.1.9", |
| 117 | + "express": "^4.18.2", |
| 118 | + "highlight.js": "^11.8.0", |
| 119 | + "js-yaml": "^4.1.0", |
| 120 | + "markdown-it": "^13.0.1", |
| 121 | + "marked": "^5.1.0", |
| 122 | + "sanitize-filename": "^1.6.3", |
| 123 | + "sharp": "^0.32.4", |
| 124 | + "simple-git": "^3.19.1", |
| 125 | + "solid-js": "^1.7.7", |
| 126 | + "tailwindcss": "^3.3.3", |
| 127 | + "ws": "^8.13.0", |
| 128 | + "xterm": "^5.3.0" |
| 129 | + }, |
| 130 | + "directories": { |
| 131 | + "doc": "docs" |
| 132 | + }, |
| 133 | + "repository": { |
| 134 | + "type": "git", |
| 135 | + "url": "git+https://github.com/tisztamo/Junior.git" |
| 136 | + }, |
| 137 | + "bugs": { |
| 138 | + "url": "https://github.com/tisztamo/Junior/issues" |
| 139 | + }, |
| 140 | + "homepage": "https://github.com/tisztamo/Junior#readme", |
| 141 | + "devDependencies": { |
| 142 | + "@rollup/plugin-node-resolve": "^15.2.3", |
| 143 | + "postcss": "^8.4.26", |
| 144 | + "postcss-nested": "^6.0.1", |
| 145 | + "rollup-plugin-preserve-shebang": "^1.0.1", |
| 146 | + "vite": "^4", |
| 147 | + "vite-plugin-solid": "^2" |
| 148 | + }, |
| 149 | + "files": [ |
| 150 | + "dist/", |
| 151 | + "prompt/", |
| 152 | + "scripts/" |
| 153 | + ] |
| 154 | +} |
| 155 | +
|
| 156 | +``` |
| 157 | +scripts/installBashIfWindows.js: |
| 158 | +``` |
| 159 | +import { execSync } from 'child_process'; |
| 160 | +import readline from 'readline'; |
| 161 | +
|
| 162 | +function installBashIfWindows() { |
| 163 | + if (process.platform !== 'win32') { |
| 164 | + console.log("Not on Windows, skipping bash installation check."); |
| 165 | + return; |
| 166 | + } |
| 167 | +
|
| 168 | + // Try "where bash" |
| 169 | + try { |
| 170 | + execSync('where bash', { stdio: 'ignore' }); |
| 171 | + console.log("Bash found in PATH. No installation needed."); |
| 172 | + } catch (err) { |
| 173 | + // We did not find bash -> prompt user |
| 174 | + console.log("\nWe need Git Bash on Windows to execute changesets generated by the LLM.\n"); |
| 175 | + console.log("Bash was not found on this system.\n"); |
| 176 | +
|
| 177 | + const rl = readline.createInterface({ |
| 178 | + input: process.stdin, |
| 179 | + output: process.stdout |
| 180 | + }); |
| 181 | +
|
| 182 | + const question = ` |
| 183 | +Choose one of the following options to install Git Bash: |
| 184 | + 1) winget |
| 185 | + 2) choco |
| 186 | + 3) Install manually |
| 187 | +Enter your choice (1,2 or 3): `; |
| 188 | +
|
| 189 | + rl.question(question, (answer) => { |
| 190 | + rl.close(); |
| 191 | + if (answer === '1') { |
| 192 | + // Try winget install |
| 193 | + console.log("\nAttempting to install Git (with Bash) via winget...\n"); |
| 194 | + try { |
| 195 | + execSync('winget install --id Git.Git -e --source winget', { stdio: 'inherit' }); |
| 196 | + console.log("\nGit (with Bash) installed successfully via winget!\n"); |
| 197 | + } catch (e) { |
| 198 | + console.log("\nFailed to install Git via winget. You may try the other options.\n"); |
| 199 | + process.exit(1); |
| 200 | + } |
| 201 | + } else if (answer === '2') { |
| 202 | + // Try choco install |
| 203 | + console.log("\nAttempting to install Git (with Bash) via choco...\n"); |
| 204 | + try { |
| 205 | + execSync('choco install git -y', { stdio: 'inherit' }); |
| 206 | + console.log("\nGit (with Bash) installed successfully via choco!\n"); |
| 207 | + } catch (e) { |
| 208 | + console.log("\nFailed to install Git via choco. You may try the other options.\n"); |
| 209 | + process.exit(1); |
| 210 | + } |
| 211 | + } else { |
| 212 | + // Manual instructions |
| 213 | + console.log("\nPlease install Git for Windows manually from: https://git-scm.com/download/win"); |
| 214 | + console.log("Once Git is installed, 'bash' should be in your PATH.\n"); |
| 215 | + process.exit(1); |
| 216 | + } |
| 217 | + }); |
| 218 | + } |
| 219 | +} |
| 220 | +
|
| 221 | +// If called directly |
| 222 | +if (import.meta.url === `file://${process.argv[1]}`) { |
| 223 | + installBashIfWindows(); |
| 224 | +} |
| 225 | +
|
| 226 | +export { installBashIfWindows }; |
| 227 | +
|
| 228 | +``` |
| 229 | +scripts/postinstall.js: |
| 230 | +``` |
| 231 | +import { execSync } from 'child_process'; |
| 232 | +
|
| 233 | +/** |
| 234 | + * Validates the prebuilt binaries for node-pty-prebuilt-multiarch. |
| 235 | + * Exits the process if validation fails. |
| 236 | + */ |
| 237 | +export async function validateNodePty() { |
| 238 | + try { |
| 239 | + console.log('Validating prebuilt binaries for node-pty...'); |
| 240 | + execSync('node -e "require(\'@homebridge/node-pty-prebuilt-multiarch\')"', { stdio: 'inherit' }); |
| 241 | + console.log('Validation successful.'); |
| 242 | + } catch (error) { |
| 243 | + console.error('Validation failed. Please check your setup.'); |
| 244 | + process.exit(1); |
| 245 | + } |
| 246 | +} |
| 247 | +
|
| 248 | +validateNodePty(); |
| 249 | +
|
| 250 | +``` |
0 commit comments