Skip to content

Fix blocking (Fixes #51) #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { Claude } from '../index.js';
import inquirer from 'inquirer';
import readline from 'readline'
import chalk from 'chalk';
import ora from 'ora';
import * as marked from 'marked';
Expand All @@ -16,6 +17,7 @@ import "isomorphic-fetch";
import { File } from "@web-std/file";
import { exec } from 'child_process';
import open from 'open';
import fetch from './tls.js';

marked.setOptions({ headerIds: false, mangle: false })
marked.setOptions({
Expand Down Expand Up @@ -116,7 +118,7 @@ const WELCOME_MESSAGE = chalk.bold.green('Welcome to the Claude CLI!');
let MODEL = 'claude-2'
const claude = new Claude({
sessionKey: getKey(),
fetch: globalThis.fetch
fetch: fetch,
});

async function main() {
Expand Down Expand Up @@ -782,7 +784,6 @@ async function getPrompt(template, variables = {}) {
} catch (e) {
return { value: '', body: '' };
}
console.log("GOT SHELL RESULT", { result });
if (['shd', 'shelld', 'shelldisplay'].includes(command)) {
return {
value: result,
Expand All @@ -795,12 +796,28 @@ async function getPrompt(template, variables = {}) {
}
}
if (command === 'js' || ['jsdisplay', 'jsd'].includes(command)) {
if (SPINNER) { SPINNER.stop() }
let pr;
const BLACKLIST = ['void', 'var', 'let', 'const', 'private', 'public', 'window', 'body', 'document', 'globalThis', 'globals', 'import', 'class', 'async', 'function', 'this', 'return', 'yield', 'throw', 'catch', 'break', 'case', 'continue', 'default', 'do', 'else', 'finally', 'if', 'in', 'return', 'switch', 'throw', 'try', 'while', 'with', 'yield'];
let p = new Promise(resolve => (pr = resolve));
const EVAL_STR = (`((async ({${Object.keys(variables).filter(i => !BLACKLIST.includes(i)).join(', ')}}) => {
${arg.split('\n').length === 1 ? `return ${arg}` : arg}
})(${JSON.stringify(variables)})).then(result => {
const ask = (q) => {
return new Promise(resolve => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
rl.question(q, (a) => {
resolve(a);
})
})
}
const EVAL_STR = (`
const tempFunc = async ({${Object.keys(variables).filter(i => !BLACKLIST.includes(i)).join(', ')}}) => {
${arg.split('\n').length === 1 ? `return ${arg}` : arg}
}
debugger;
tempFunc(${JSON.stringify({ variables })}).then(result => {
debugger;
pr(result);
})`);
eval(EVAL_STR);
Expand Down
1 change: 1 addition & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@web-std/file": "^3.0.2",
"chalk": "^5.3.0",
"claude-ai": "^1.2.0",
"cycletls": "^1.0.21",
"dotenv": "^16.3.1",
"inquirer": "^9.2.7",
"isomorphic-fetch": "^3.0.0",
Expand Down
30 changes: 30 additions & 0 deletions cli/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cli/templates/code.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
You are an expert software engineer at Google. Be concise! Your job is to implement the code designed and detailed in the uploaded file requirements.txt. This project is {prompt}

Make sure to use the latest syntax (e.g. ESM/ES6 imports and syntax in JavaScript, HTML5, CSS3), don't include debug or comments or empty lines. Include error handling to make sure it works properly. Make sure your code is readable and does not include any placeholders or psuedocode.
Make sure to use the latest syntax (e.g., ESM/ES6 imports and syntax in JavaScript, HTML5, CSS3), don't include debug or comments or empty lines. Include error handling to make sure it works properly. Make sure your code is readable and does not include any placeholders or pseudocode.

DONT INCLUDE ANY TODO COMMENTS. DONT INCLUDE PSUEDOCODE. DONT INCLUDE PLACEHOLDERS. Adhere to the user's request as closely as possible. Your code's output, variables and function should match the example output given in the design document exactly.
DON'T INCLUDE ANY TODO COMMENTS. DON'T INCLUDE PSUEDOCODE. DON'T INCLUDE PLACEHOLDERS. Adhere to the user's request as closely as possible. Your code's output, variables, and function should match the example output given in the design document exactly.

First write you initial implementation of the requirements, then write out 4 criticisms of it. Finally write your final code. Begin the final code with "FINAL:"
First write your initial implementation of the requirements, then write out 4 criticisms of it. Finally, write your final code. Begin the final code with "FINAL:"

The requirements and design details of this project are located in the uploaded file requirements.txt

Expand Down
Loading