generated from Cumulo/calcium-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
prototyped #1
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
Merged
prototyped #1
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
197edc7
making tool prototype in typescript
tiye d00afad
install locally
tiye ae6f720
simplify code a bit. better interactions
tiye fde8d7a
fix loop branching of nextQuestion
tiye 6a2a1c7
Update model name to gemini-2.0-flash-lite
tiye 015d85d
wrap code that going to be excuted in box
tiye b9e00a8
include system info in early prompt
tiye fa3281a
steaming stdout output
tiye d62398b
insert context reminder
tiye ef8d6d9
some abstract over tool in order to add more file tools
tiye 561208d
include newer google ai sdk to use ground search
tiye 87dfe83
clear exec tmp file earlier
tiye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,4 @@ storage.cirru | |
| backups/ | ||
|
|
||
| .DS_Store | ||
| lib | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
|
|
||
|
|
||
| .compact-inc.cirru | ||
| .calcit-error.cirru | ||
|
|
||
| js-out/ | ||
| dist/ | ||
|
|
||
| yarn-error.log | ||
|
|
||
| storage.cirru | ||
|
|
||
| backups/ | ||
|
|
||
| .DS_Store | ||
|
|
||
| *.cirru | ||
|
|
||
| .github | ||
|
|
||
| tsconfig.json | ||
|
|
||
| index.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "files.exclude": { | ||
| "lib/**": true, | ||
| "js-out/**": true, | ||
| "node_modules/**": true, | ||
| "**/.git": true, | ||
| "**/.svn": true, | ||
| "**/.hg": true, | ||
| "**/.DS_Store": true, | ||
| "**/Thumbs.db": true | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,26 @@ | ||
|
|
||
| Macrophylla | ||
| ---- | ||
| ## Macrophylla | ||
|
|
||
| > try smarter CLI tools, still experimenting... | ||
|
|
||
| Macrophylla 是一个命令行助手,它使用 Gemini API 与用户交互,并能够执行 Bash 命令和 Node.js 代码。 | ||
|
|
||
| ### 使用方式 | ||
|
|
||
| 1. **准备 Gemini API Key:** 确保你已经设置了 `GEMINI_API_KEY` 环境变量。 | ||
|
|
||
| 2. **运行工具:** 直接运行该工具。 | ||
|
|
||
| 3. **与助手交互:** 工具会提示你输入任务描述。 你可以使用自然语言描述你的需求。 | ||
|
|
||
| 4. **执行 Bash 命令和 Node.js 代码:** 工具会根据你的描述,自动判断是否需要执行 Bash 命令或 Node.js 代码来完成任务。 如果需要执行,会先向你确认,然后执行并将结果返回。 | ||
|
|
||
| 5. **示例:** | ||
|
|
||
| - 用户: 读取当前目录下的 `README.md` 文件内容。 | ||
| - 助手: (判断需要执行 Bash 命令) Bash command to execute: `cat README.md` Execute this Bash command? (y/n): | ||
| - 用户: y | ||
| - 助手: (执行命令,并将结果返回) | ||
|
|
||
| ### License | ||
|
|
||
| MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import "./lib/main.mjs"; | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,30 @@ | ||
| { | ||
| "name": "macrophylla", | ||
| "dependencies": { | ||
| "@calcit/procs": "^0.9.9" | ||
| "@calcit/procs": "^0.9.9", | ||
| "@google/genai": "^0.8.0", | ||
| "@google/generative-ai": "^0.24.0", | ||
| "chalk": "^5.4.1", | ||
| "string-width": "^7.2.0" | ||
| }, | ||
| "scripts": { | ||
| "compile-page": "cr --once js", | ||
| "release-page": "vite build --base=./", | ||
| "watch-page": "cr js" | ||
| "watch-page": "cr js", | ||
| "tool": "tsc && node lib/main.mjs" | ||
| }, | ||
| "bin": { | ||
| "mcpl": "./bin.mjs" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^22.14.0", | ||
| "bottom-tip": "^0.1.5", | ||
| "typescript": "^5.8.3", | ||
| "url-parse": "^1.5.10", | ||
| "vite": "^6.2.5" | ||
| }, | ||
| "version": "0.0.1" | ||
| "version": "0.0.1", | ||
| "cirruInfo": { | ||
| "calcitVersion": "0.9.9" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import { exec, execFile } from "child_process"; | ||
| import path from "path"; | ||
| import fs from "fs/promises"; | ||
|
|
||
| // Define function to execute Node.js code | ||
| export const executeNodeJsCode = async ( | ||
| code: string, | ||
| tempDir: string | ||
| ): Promise<{ | ||
| stdout: string; | ||
| stderr: string; | ||
| }> => { | ||
| // Create temp directory if it doesn't exist | ||
| try { | ||
| await fs.mkdir(tempDir, { recursive: true }); | ||
| } catch (err) { | ||
| // Directory might already exist | ||
| } | ||
|
|
||
| // Create a temporary file with the code | ||
| const tempFilePath = path.join(tempDir, `exec_${Date.now()}.mjs`); | ||
| await fs.writeFile(tempFilePath, code); | ||
| // Execute the file as an ES module | ||
| const child = execFile("node", ["--experimental-modules", tempFilePath], { | ||
| encoding: "utf8", | ||
| maxBuffer: 10 * 1024 * 1024, // 10MB buffer to handle large outputs | ||
| }); | ||
|
|
||
| let stdout = ""; | ||
| let stderr = ""; | ||
|
|
||
| // Stream stdout in real-time while preserving color | ||
| child.stdout?.on("data", (data) => { | ||
| process.stdout.write(data); | ||
| stdout += data; | ||
| }); | ||
|
|
||
| // Stream stderr in real-time while preserving color | ||
| child.stderr?.on("data", (data) => { | ||
| process.stderr.write(data); | ||
| stderr += data; | ||
| }); | ||
|
|
||
| // Wait for process to complete | ||
| const result = await new Promise<{ stdout: string; stderr: string }>( | ||
| (resolve, reject) => { | ||
| child.on("close", (code) => { | ||
| // Clean up the temporary file, asynchronously | ||
| fs.unlink(tempFilePath).catch((err) => | ||
| console.error("Failed to delete temp file:", err) | ||
| ); | ||
|
|
||
| if (code === 0 || code === null) { | ||
| resolve({ stdout, stderr }); | ||
| } else { | ||
| reject(new Error(`Process exited with code ${code}\n${stderr}`)); | ||
| } | ||
| }); | ||
|
|
||
| child.on("error", reject); | ||
| } | ||
| ); | ||
|
|
||
| return result; | ||
| }; | ||
|
|
||
| export let execBash = async ( | ||
| command: string | ||
| ): Promise<{ stdout: string; stderr: string }> => { | ||
| // Execute the command | ||
| const child = exec(command, { | ||
| encoding: "utf8", | ||
| maxBuffer: 10 * 1024 * 1024, // 10MB buffer to handle large outputs | ||
| }); | ||
|
|
||
| let stdout = ""; | ||
| let stderr = ""; | ||
|
|
||
| // Stream stdout in real-time while preserving colors | ||
| child.stdout?.on("data", (data) => { | ||
| process.stdout.write(data); | ||
| stdout += data; | ||
| }); | ||
|
|
||
| // Stream stderr in real-time while preserving colors | ||
| child.stderr?.on("data", (data) => { | ||
| process.stderr.write(data); | ||
| stderr += data; | ||
| }); | ||
|
|
||
| // Wait for process to complete | ||
| return new Promise<{ stdout: string; stderr: string }>((resolve, reject) => { | ||
| child.on("close", (code) => { | ||
| if (code === 0 || code === null) { | ||
| resolve({ stdout, stderr }); | ||
| } else { | ||
| reject(new Error(`Process exited with code ${code}\n${stderr}`)); | ||
| } | ||
| }); | ||
|
|
||
| child.on("error", reject); | ||
| }); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import path in bin.mjs points to './lib/main.mjs' while the main module is defined in 'src/main.mts'. Update the import path to correctly reference the intended module.