@humanlayer/agentlayer-justbash 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +630 -0
  4. package/dist/index.js.map +22 -0
  5. package/dist/prompts/index.d.ts +29 -0
  6. package/dist/prompts/index.d.ts.map +1 -0
  7. package/dist/prompts/index.js +123 -0
  8. package/dist/prompts/index.js.map +10 -0
  9. package/dist/tools/apply-patch.d.ts +9 -0
  10. package/dist/tools/apply-patch.d.ts.map +1 -0
  11. package/dist/tools/bash.d.ts +8 -0
  12. package/dist/tools/bash.d.ts.map +1 -0
  13. package/dist/tools/code-search.d.ts +12 -0
  14. package/dist/tools/code-search.d.ts.map +1 -0
  15. package/dist/tools/edit.d.ts +12 -0
  16. package/dist/tools/edit.d.ts.map +1 -0
  17. package/dist/tools/glob.d.ts +6 -0
  18. package/dist/tools/glob.d.ts.map +1 -0
  19. package/dist/tools/grep.d.ts +8 -0
  20. package/dist/tools/grep.d.ts.map +1 -0
  21. package/dist/tools/index.d.ts +13 -0
  22. package/dist/tools/index.d.ts.map +1 -0
  23. package/dist/tools/index.js +510 -0
  24. package/dist/tools/index.js.map +21 -0
  25. package/dist/tools/list.d.ts +7 -0
  26. package/dist/tools/list.d.ts.map +1 -0
  27. package/dist/tools/read.d.ts +7 -0
  28. package/dist/tools/read.d.ts.map +1 -0
  29. package/dist/tools/skill.d.ts +10 -0
  30. package/dist/tools/skill.d.ts.map +1 -0
  31. package/dist/tools/web-fetch.d.ts +7 -0
  32. package/dist/tools/web-fetch.d.ts.map +1 -0
  33. package/dist/tools/web-search.d.ts +16 -0
  34. package/dist/tools/web-search.d.ts.map +1 -0
  35. package/dist/tools/write.d.ts +6 -0
  36. package/dist/tools/write.d.ts.map +1 -0
  37. package/package.json +59 -0
  38. package/src/index.ts +2 -0
  39. package/src/prompts/index.ts +161 -0
  40. package/src/tools/apply-patch.ts +121 -0
  41. package/src/tools/apply-patch.txt +35 -0
  42. package/src/tools/bash.ts +20 -0
  43. package/src/tools/bash.txt +114 -0
  44. package/src/tools/code-search.ts +119 -0
  45. package/src/tools/edit.ts +58 -0
  46. package/src/tools/edit.txt +10 -0
  47. package/src/tools/glob.ts +33 -0
  48. package/src/tools/glob.txt +6 -0
  49. package/src/tools/grep.ts +53 -0
  50. package/src/tools/grep.txt +8 -0
  51. package/src/tools/index.ts +12 -0
  52. package/src/tools/list.ts +41 -0
  53. package/src/tools/list.txt +5 -0
  54. package/src/tools/read.ts +16 -0
  55. package/src/tools/read.txt +14 -0
  56. package/src/tools/skill.ts +49 -0
  57. package/src/tools/web-fetch.ts +97 -0
  58. package/src/tools/web-fetch.txt +10 -0
  59. package/src/tools/web-search.ts +59 -0
  60. package/src/tools/write.ts +26 -0
  61. package/src/tools/write.txt +8 -0
@@ -0,0 +1,7 @@
1
+ import type { Bash } from 'just-bash';
2
+ export declare function createWebFetchTool(bash: Bash): import("@humanlayer/agentlayer-core").Tool<{
3
+ url: string;
4
+ format: "text" | "markdown" | "html";
5
+ timeout: number;
6
+ }, string>;
7
+ //# sourceMappingURL=web-fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-fetch.d.ts","sourceRoot":"","sources":["../../src/tools/web-fetch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAwBrC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI;;;;WAsE5C"}
@@ -0,0 +1,16 @@
1
+ import type { Bash } from 'just-bash';
2
+ export interface JustBashWebSearchOptions {
3
+ exaApiKey: string;
4
+ timeoutSec?: number;
5
+ }
6
+ export declare function createWebSearchTool(bash: Bash, opts: JustBashWebSearchOptions): import("@humanlayer/agentlayer-core").Tool<{
7
+ query: string;
8
+ numResults: number;
9
+ }, {
10
+ results: {
11
+ title: string;
12
+ url: string;
13
+ snippet: string;
14
+ }[];
15
+ }>;
16
+ //# sourceMappingURL=web-search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-search.d.ts","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAIrC,MAAM,WAAW,wBAAwB;IACxC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,wBAAwB;;;;;;;;;GA8C7E"}
@@ -0,0 +1,6 @@
1
+ import type { Bash } from 'just-bash';
2
+ export declare function createWriteTool(bash: Bash): import("@humanlayer/agentlayer-core").Tool<{
3
+ file_path: string;
4
+ content: string;
5
+ }, string>;
6
+ //# sourceMappingURL=write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../src/tools/write.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAErC,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI;;;WAqBzC"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@humanlayer/agentlayer-justbash",
3
+ "source": "./src/index.ts",
4
+ "type": "module",
5
+ "version": "0.0.7",
6
+ "private": false,
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "files": [
14
+ "src",
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "typecheck": "tsgo --noEmit",
19
+ "build": "bun run build:js && bunx tsc -p tsconfig.build.json",
20
+ "build:js": "bun run build.ts",
21
+ "build:types": "bunx tsc -p tsconfig.build.json"
22
+ },
23
+ "devDependencies": {
24
+ "@ai-sdk/anthropic": "3.0.69",
25
+ "@ai-sdk/provider": "3.0.8",
26
+ "@types/bun": "latest",
27
+ "@types/turndown": "5.0.6",
28
+ "ai": "6.0.159",
29
+ "zod": "4.3.6"
30
+ },
31
+ "peerDependencies": {
32
+ "typescript": "^5",
33
+ "just-bash": "^2.0.0"
34
+ },
35
+ "exports": {
36
+ ".": {
37
+ "source": "./src/index.ts",
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/index.js",
40
+ "default": "./dist/index.js"
41
+ },
42
+ "./prompts": {
43
+ "source": "./src/prompts/index.ts",
44
+ "types": "./dist/prompts/index.d.ts",
45
+ "import": "./dist/prompts/index.js",
46
+ "default": "./dist/prompts/index.js"
47
+ },
48
+ "./tools": {
49
+ "source": "./src/tools/index.ts",
50
+ "types": "./dist/tools/index.d.ts",
51
+ "import": "./dist/tools/index.js",
52
+ "default": "./dist/tools/index.js"
53
+ }
54
+ },
55
+ "dependencies": {
56
+ "@humanlayer/agentlayer-core": "0.0.7",
57
+ "turndown": "7.2.4"
58
+ }
59
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './prompts/index'
2
+ export * from './tools'
@@ -0,0 +1,161 @@
1
+ import { resolve } from 'node:path'
2
+ import {
3
+ type CodingPromptKey,
4
+ type EnvironmentPromptOptions as CoreEnvironmentPromptOptions,
5
+ createAgentSystemPrompt as createCoreAgentSystemPrompt,
6
+ environmentPrompt as createEnvironmentPrompt,
7
+ repoInstructionsPrompt as createRepoInstructionsPrompt,
8
+ } from '@humanlayer/agentlayer-core/prompts'
9
+ import type { Bash } from 'just-bash'
10
+
11
+ export {
12
+ buildCodingProviderOptions,
13
+ type CodingModelFamily,
14
+ type CodingPromptKey,
15
+ detectModelFamily,
16
+ getSystemPromptForModel,
17
+ resolveCodingModelPrompt,
18
+ systemPrompts,
19
+ tarsPersona,
20
+ } from '@humanlayer/agentlayer-core/prompts'
21
+
22
+ const DEFAULT_REPO_INSTRUCTION_CANDIDATES = ['CLAUDE.md', 'AGENTS.md', 'CONTEXT.md']
23
+
24
+ async function getRepoRoot(bash: Bash, cwd: string): Promise<string | undefined> {
25
+ const result = await bash.exec(`git -C "${cwd}" rev-parse --show-toplevel 2>/dev/null`)
26
+ if (result.exitCode !== 0) return undefined
27
+ const root = result.stdout.trim()
28
+ return root.length > 0 ? root : undefined
29
+ }
30
+
31
+ async function readFileIfExists(bash: Bash, filePath: string): Promise<string | undefined> {
32
+ const result = await bash.exec(`cat "${filePath}" 2>/dev/null`)
33
+ if (result.exitCode !== 0) return undefined
34
+ return result.stdout
35
+ }
36
+
37
+ async function firstExistingCandidate(bash: Bash, cwd: string, candidates: string[]): Promise<string | undefined> {
38
+ for (const candidate of candidates) {
39
+ const filePath = `${cwd}/${candidate}`
40
+ const contents = await readFileIfExists(bash, filePath)
41
+ if (contents !== undefined) return filePath
42
+ }
43
+
44
+ return undefined
45
+ }
46
+
47
+ async function findRepoInstructions(
48
+ bash: Bash,
49
+ startCwd: string,
50
+ candidates: string[],
51
+ skipRepoRootFallback: boolean,
52
+ ): Promise<{ path: string; contents: string } | undefined> {
53
+ const cwdPath = await firstExistingCandidate(bash, startCwd, candidates)
54
+ if (cwdPath) {
55
+ const contents = await readFileIfExists(bash, cwdPath)
56
+ if (contents?.trim()) {
57
+ return { path: cwdPath, contents }
58
+ }
59
+ }
60
+
61
+ if (!skipRepoRootFallback) {
62
+ const repoRoot = await getRepoRoot(bash, startCwd)
63
+ if (repoRoot && repoRoot !== startCwd) {
64
+ const rootPath = await firstExistingCandidate(bash, repoRoot, candidates)
65
+ if (rootPath) {
66
+ const contents = await readFileIfExists(bash, rootPath)
67
+ if (contents?.trim()) {
68
+ return { path: rootPath, contents }
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ return undefined
75
+ }
76
+
77
+ export interface EnvironmentPromptOptions extends Omit<CoreEnvironmentPromptOptions, 'isGitRepo'> {
78
+ isGitRepo?: boolean
79
+ }
80
+
81
+ export async function environmentPrompt(bash: Bash, opts: EnvironmentPromptOptions): Promise<string> {
82
+ const isGitRepo = opts.isGitRepo ?? (await getRepoRoot(bash, opts.cwd)) !== undefined
83
+ return createEnvironmentPrompt({
84
+ cwd: opts.cwd,
85
+ isGitRepo,
86
+ platform: opts.platform,
87
+ date: opts.date,
88
+ })
89
+ }
90
+
91
+ export interface RepoInstructionsPromptOptions {
92
+ cwd: string
93
+ filePath?: string
94
+ candidates?: string[]
95
+ allowMissing?: boolean
96
+ _skipRepoRootFallback?: boolean
97
+ }
98
+
99
+ export async function repoInstructionsPrompt(
100
+ bash: Bash,
101
+ opts: RepoInstructionsPromptOptions,
102
+ ): Promise<string | undefined> {
103
+ if (opts.filePath) {
104
+ const filePath = opts.filePath.startsWith('/') ? opts.filePath : resolve(opts.cwd, opts.filePath)
105
+ const contents = await readFileIfExists(bash, filePath)
106
+ if (!contents?.trim()) {
107
+ if (opts.allowMissing) return undefined
108
+ throw new Error(`Repo instructions file is empty: ${filePath}`)
109
+ }
110
+ return createRepoInstructionsPrompt({ path: filePath, contents })
111
+ }
112
+
113
+ const candidates = opts.candidates ?? DEFAULT_REPO_INSTRUCTION_CANDIDATES
114
+ const found = await findRepoInstructions(bash, opts.cwd, candidates, opts._skipRepoRootFallback ?? false)
115
+
116
+ if (!found) {
117
+ if (opts.allowMissing) return undefined
118
+ const repoRoot = await getRepoRoot(bash, opts.cwd)
119
+ const searched = repoRoot ? [`${opts.cwd} (cwd)`, `${repoRoot} (repo root)`] : [opts.cwd]
120
+ throw new Error(`No repo instructions found. Searched for ${candidates.join(', ')} in: ${searched.join(', ')}`)
121
+ }
122
+
123
+ return createRepoInstructionsPrompt(found)
124
+ }
125
+
126
+ export interface CreateAgentSystemPromptOptions {
127
+ bash: Bash
128
+ cwd: string
129
+ model: CodingPromptKey | string
130
+ filePath?: string
131
+ candidates?: string[]
132
+ allowMissingRepoInstructions?: boolean
133
+ includeEnvironment?: boolean
134
+ platform?: string
135
+ date?: Date
136
+ systemPromptAdditions?: string[]
137
+ }
138
+
139
+ export async function createAgentSystemPrompt(opts: CreateAgentSystemPromptOptions): Promise<string[]> {
140
+ const repoInstructions = await repoInstructionsPrompt(opts.bash, {
141
+ cwd: opts.cwd,
142
+ filePath: opts.filePath,
143
+ candidates: opts.candidates,
144
+ allowMissing: opts.allowMissingRepoInstructions ?? true,
145
+ })
146
+ const environment =
147
+ opts.includeEnvironment === false
148
+ ? undefined
149
+ : await environmentPrompt(opts.bash, {
150
+ cwd: opts.cwd,
151
+ platform: opts.platform,
152
+ date: opts.date,
153
+ })
154
+
155
+ return createCoreAgentSystemPrompt({
156
+ model: opts.model,
157
+ repoInstructions,
158
+ environment,
159
+ systemPromptAdditions: opts.systemPromptAdditions,
160
+ })
161
+ }
@@ -0,0 +1,121 @@
1
+ import { isAbsolute, resolve } from 'node:path'
2
+ import { ApplyPatchTool } from '@humanlayer/agentlayer-core/interfaces'
3
+ import { APPLY_PATCH_DESCRIPTION } from '@humanlayer/agentlayer-core/prompts'
4
+ import { applyUpdateChunks, type PatchOperation, parsePatch, validateHunks } from '@humanlayer/agentlayer-core/utils'
5
+ import type { Bash } from 'just-bash'
6
+
7
+ export interface ApplyPatchOptions {
8
+ /** Working directory for resolving relative paths. If not provided, paths are resolved by bash's cwd. */
9
+ cwd?: string
10
+ }
11
+
12
+ export function createApplyPatchTool(bash: Bash, opts: ApplyPatchOptions = {}) {
13
+ const { cwd } = opts
14
+
15
+ /**
16
+ * Resolve a file path to absolute if cwd is provided and path is relative.
17
+ * Note: bash.exec already uses bash's cwd, but this ensures consistency
18
+ * when passing paths to commands.
19
+ */
20
+ const _resolvePath = (filePath: string): string => {
21
+ if (!cwd || isAbsolute(filePath)) {
22
+ return filePath
23
+ }
24
+ return resolve(cwd, filePath)
25
+ }
26
+ return ApplyPatchTool.define(
27
+ async (input) => {
28
+ const { patch_text } = input
29
+
30
+ if (!patch_text || !patch_text.trim()) {
31
+ throw new Error('patch_text is required')
32
+ }
33
+
34
+ let ops: PatchOperation[]
35
+ try {
36
+ ops = parsePatch(patch_text)
37
+ } catch (err) {
38
+ throw new Error(`apply_patch verification failed: ${err}`)
39
+ }
40
+
41
+ if (ops.length === 0) {
42
+ throw new Error('patch rejected: empty patch')
43
+ }
44
+
45
+ const hasHunks = ops.some((op) => op.type === 'add' || op.chunks.length > 0 || op.type === 'delete')
46
+ if (!hasHunks) {
47
+ throw new Error('apply_patch verification failed: no hunks found')
48
+ }
49
+
50
+ // Read helper via bash
51
+ const readFile = async (filePath: string): Promise<string> => {
52
+ const result = await bash.exec(`cat "${filePath}"`)
53
+ if (result.exitCode !== 0) {
54
+ throw new Error(`File not found: ${filePath}`)
55
+ }
56
+ return result.stdout
57
+ }
58
+
59
+ // Validation phase — reads only, no writes
60
+ await validateHunks(ops, readFile)
61
+
62
+ // Apply phase
63
+ const results: string[] = []
64
+
65
+ for (const op of ops) {
66
+ if (op.type === 'add') {
67
+ const filePath = op.filePath
68
+ // Ensure parent directory exists
69
+ const mkdirResult = await bash.exec(`mkdir -p "$(dirname "${filePath}")"`)
70
+ if (mkdirResult.exitCode !== 0) {
71
+ throw new Error(`Failed to create parent directory for ${filePath}: ${mkdirResult.stderr}`)
72
+ }
73
+ // Write content using a heredoc
74
+ const DELIM = 'PATCHEOF_8f3a2b1c'
75
+ const content = op.addContent ?? ''
76
+ const writeResult = await bash.exec(`cat > "${filePath}" <<'${DELIM}'\n${content}\n${DELIM}`)
77
+ if (writeResult.exitCode !== 0) {
78
+ throw new Error(`Failed to write file ${filePath}: ${writeResult.stderr}`)
79
+ }
80
+ results.push(`Added ${filePath}`)
81
+ } else if (op.type === 'update') {
82
+ const content = await readFile(op.filePath)
83
+ const updated = applyUpdateChunks(content, op.chunks)
84
+ const DELIM = 'PATCHEOF_8f3a2b1c'
85
+ const writeResult = await bash.exec(`cat > "${op.filePath}" <<'${DELIM}'\n${updated}\n${DELIM}`)
86
+ if (writeResult.exitCode !== 0) {
87
+ throw new Error(`Failed to write file ${op.filePath}: ${writeResult.stderr}`)
88
+ }
89
+ results.push(`Updated ${op.filePath}`)
90
+ } else if (op.type === 'move') {
91
+ const content = await readFile(op.filePath)
92
+ const updated = applyUpdateChunks(content, op.chunks)
93
+ const targetPath = op.targetPath!
94
+ const mkdirResult = await bash.exec(`mkdir -p "$(dirname "${targetPath}")"`)
95
+ if (mkdirResult.exitCode !== 0) {
96
+ throw new Error(`Failed to create parent directory for ${targetPath}: ${mkdirResult.stderr}`)
97
+ }
98
+ const DELIM = 'PATCHEOF_8f3a2b1c'
99
+ const writeResult = await bash.exec(`cat > "${targetPath}" <<'${DELIM}'\n${updated}\n${DELIM}`)
100
+ if (writeResult.exitCode !== 0) {
101
+ throw new Error(`Failed to write file ${targetPath}: ${writeResult.stderr}`)
102
+ }
103
+ const rmResult = await bash.exec(`rm "${op.filePath}"`)
104
+ if (rmResult.exitCode !== 0) {
105
+ throw new Error(`Failed to remove original file ${op.filePath}: ${rmResult.stderr}`)
106
+ }
107
+ results.push(`Moved ${op.filePath} → ${targetPath}`)
108
+ } else if (op.type === 'delete') {
109
+ const rmResult = await bash.exec(`rm "${op.filePath}"`)
110
+ if (rmResult.exitCode !== 0) {
111
+ throw new Error(`Failed to delete file ${op.filePath}: ${rmResult.stderr}`)
112
+ }
113
+ results.push(`Deleted ${op.filePath}`)
114
+ }
115
+ }
116
+
117
+ return results.join('\n')
118
+ },
119
+ { description: APPLY_PATCH_DESCRIPTION },
120
+ )
121
+ }
@@ -0,0 +1,35 @@
1
+ Apply a patch to edit one or more files. The patch language is a stripped-down, file-oriented diff format designed to be easy to parse and safe to apply.
2
+
3
+ Format:
4
+ *** Begin Patch
5
+ [ one or more file sections ]
6
+ *** End Patch
7
+
8
+ Each file section starts with one of three headers:
9
+ - *** Add File: <path> - Create a new file. Every following line is a + line (the initial contents).
10
+ - *** Delete File: <path> - Remove an existing file. Nothing follows.
11
+ - *** Update File: <path> - Modify an existing file in place (optionally with a rename via *** Move to: <path>).
12
+
13
+ For Update File sections, include context lines (prefixed with space) and change lines (prefixed with - for removals, + for additions).
14
+
15
+ Example patch:
16
+
17
+ ```
18
+ *** Begin Patch
19
+ *** Add File: hello.txt
20
+ +Hello world
21
+ *** Update File: src/app.py
22
+ *** Move to: src/main.py
23
+ @@ def greet():
24
+ -print("Hi")
25
+ +print("Hello, world!")
26
+ *** Delete File: obsolete.txt
27
+ *** End Patch
28
+ ```
29
+
30
+ Rules:
31
+ - Every patch must begin with *** Begin Patch and end with *** End Patch
32
+ - You must include a header with your intended action (Add/Delete/Update)
33
+ - New lines must be prefixed with +
34
+ - Removed lines must be prefixed with -
35
+ - Context lines must be prefixed with a space
@@ -0,0 +1,20 @@
1
+ import { BashTool } from '@humanlayer/agentlayer-core/interfaces'
2
+ import { BASH_DESCRIPTION } from '@humanlayer/agentlayer-core/prompts'
3
+ import { truncateOutput } from '@humanlayer/agentlayer-core/utils'
4
+ import type { Bash } from 'just-bash'
5
+
6
+ export function createJustBashTool(bash: Bash) {
7
+ return BashTool.define(
8
+ async (input) => {
9
+ const result = await bash.exec(input.command, {
10
+ ...(input.workdir ? { cwd: input.workdir } : {}),
11
+ })
12
+ let output = result.stdout
13
+ if (result.stderr) {
14
+ output += `\nSTDERR: ${result.stderr}`
15
+ }
16
+ return truncateOutput(`Exit code: ${result.exitCode}\n${output}`)
17
+ },
18
+ { description: BASH_DESCRIPTION },
19
+ )
20
+ }
@@ -0,0 +1,114 @@
1
+ Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
2
+
3
+ All commands run in ${directory} by default. Use the `workdir` parameter if you need to run a command in a different directory. AVOID using `cd <directory> && <command>` patterns - use the `workdir` instead.
4
+
5
+ IMPORTANT: This tool is for terminal operations like git, npm, docker, etc. DO NOT use it for file operations (reading, writing, editing, searching, finding files) - use the specialized tools for this instead.
6
+
7
+ Before executing the command, please follow these steps:
8
+
9
+ 1. Directory Verification:
10
+ - If the command will create new directories or files, first use `ls` to verify the parent directory exists and is the correct location
11
+ - For example, before running "mkdir foo/bar", first use `ls foo` to check that "foo" exists and is the intended parent directory
12
+
13
+ 2. Command Execution:
14
+ - Always quote file paths that contain spaces with double quotes (e.g., rm "path with spaces/file.txt")
15
+ - Examples of proper quoting:
16
+ - mkdir "/Users/name/My Documents" (correct)
17
+ - mkdir /Users/name/My Documents (incorrect - will fail)
18
+ - python "/path/with spaces/script.py" (correct)
19
+ - python /path/with spaces/script.py (incorrect - will fail)
20
+ - After ensuring proper quoting, execute the command.
21
+ - Capture the output of the command.
22
+
23
+ Usage notes:
24
+ - The command argument is required.
25
+ - You can specify an optional timeout in milliseconds. If not specified, commands will time out after 120000ms (2 minutes).
26
+ - It is very helpful if you write a clear, concise description of what this command does in 5-10 words.
27
+ - If the output exceeds ${maxLines} lines or ${maxBytes} bytes, it will be truncated and the full output will be written to a file. You can use Read with offset/limit to read specific sections or Grep to search the full content. Do NOT use `head`, `tail`, or other truncation commands to limit output; the full output will already be captured to a file for more precise searching.
28
+
29
+ - Avoid using Bash with the `find`, `grep`, `cat`, `head`, `tail`, `sed`, `awk`, or `echo` commands, unless explicitly instructed or when these commands are truly necessary for the task. Instead, always prefer using the dedicated tools for these commands:
30
+ - File search: Use Glob (NOT find or ls)
31
+ - Content search: Use Grep (NOT grep or rg)
32
+ - Read files: Use Read (NOT cat/head/tail)
33
+ - Edit files: Use Edit (NOT sed/awk)
34
+ - Write files: Use Write (NOT echo >/cat <<EOF)
35
+ - Communication: Output text directly (NOT echo/printf)
36
+ - When issuing multiple commands:
37
+ - If the commands are independent and can run in parallel, make multiple Bash tool calls in a single message. For example, if you need to run "git status" and "git diff", send a single message with two Bash tool calls in parallel.
38
+ - If the commands depend on each other and must run sequentially, use a single Bash call with '&&' to chain them together (e.g., `git add . && git commit -m "message" && git push`). For instance, if one operation must complete before another starts (like mkdir before cp, Write before Bash for git operations, or git add before git commit), run these operations sequentially instead.
39
+ - Use ';' only when you need to run commands sequentially but don't care if earlier commands fail
40
+ - DO NOT use newlines to separate commands (newlines are ok in quoted strings)
41
+ - AVOID using `cd <directory> && <command>`. Use the `workdir` parameter to change directories instead.
42
+ <good-example>
43
+ Use workdir="/foo/bar" with command: pytest tests
44
+ </good-example>
45
+ <bad-example>
46
+ cd /foo/bar && pytest tests
47
+ </bad-example>
48
+
49
+ # Committing changes with git
50
+
51
+ Only create commits when requested by the user. If unclear, ask first. When the user asks you to create a new git commit, follow these steps carefully:
52
+
53
+ Git Safety Protocol:
54
+ - NEVER update the git config
55
+ - NEVER run destructive/irreversible git commands (like push --force, hard reset, etc) unless the user explicitly requests them
56
+ - NEVER skip hooks (--no-verify, --no-gpg-sign, etc) unless the user explicitly requests it
57
+ - Avoid git commit --amend. ONLY use --amend when ALL conditions are met:
58
+ (1) User explicitly requested amend, OR commit SUCCEEDED but pre-commit hook auto-modified files that need including
59
+ (2) HEAD commit was created by you in this conversation (verify: git log -1 --format='%an %ae')
60
+ (3) Commit has NOT been pushed to remote (verify: git status shows "Your branch is ahead")
61
+ - CRITICAL: If commit FAILED or was REJECTED by hook, NEVER amend - fix the issue and create a NEW commit
62
+ - CRITICAL: If you already pushed to remote, NEVER amend unless user explicitly requests it (requires force push)
63
+ - NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive.
64
+
65
+ 1. You can call multiple tools in a single response. When multiple independent pieces of information are requested and all commands are likely to succeed, run multiple Bash tool calls in parallel for optimal performance. run the following bash commands in parallel, each using the Bash tool:
66
+ - Run a git status command to see all untracked files.
67
+ - Run a git diff command to see both staged and unstaged changes that will be committed.
68
+ - Run a git log command to see recent commit messages, so that you can follow this repository's commit message style.
69
+ 2. Analyze all staged changes (both previously staged and newly added) and draft a commit message:
70
+ - Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.). Ensure the message accurately reflects the changes and their purpose (i.e. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.)
71
+ - Do not commit files that likely contain secrets (.env, credentials.json, etc.). Warn the user if they specifically request to commit those files
72
+ - Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what"
73
+ - Ensure it accurately reflects the changes and their purpose
74
+ 3. You can call multiple tools in a single response. When multiple independent pieces of information are requested and all commands are likely to succeed, run multiple Bash tool calls in parallel for optimal performance. run the following commands:
75
+ - Add relevant untracked files to the staging area.
76
+ - Create the commit with a message
77
+ - Run git status after the commit completes to verify success.
78
+ Note: git status depends on the commit completing, so run it sequentially after the commit.
79
+ 4. If the commit fails due to pre-commit hook, fix the issue and create a NEW commit (see amend rules above)
80
+
81
+ Important notes:
82
+ - NEVER run additional commands to read or explore code, besides git bash commands
83
+ - NEVER use the TodoWrite or Task tools
84
+ - DO NOT push to the remote repository unless the user explicitly asks you to do so
85
+ - IMPORTANT: Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported.
86
+ - If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit
87
+
88
+ # Creating pull requests
89
+ Use the gh command via the Bash tool for ALL GitHub-related tasks including working with issues, pull requests, checks, and releases. If given a GitHub URL use the gh command to get the information needed.
90
+
91
+ IMPORTANT: When the user asks you to create a pull request, follow these steps carefully:
92
+
93
+ 1. You can call multiple tools in a single response. When multiple independent pieces of information are requested and all commands are likely to succeed, run multiple tool calls in parallel for optimal performance. run the following bash commands in parallel using the Bash tool, in order to understand the current state of the branch since it diverged from the main branch:
94
+ - Run a git status command to see all untracked files
95
+ - Run a git diff command to see both staged and unstaged changes that will be committed
96
+ - Check if the current branch tracks a remote branch and is up to date with the remote, so you know if you need to push to the remote
97
+ - Run a git log command and `git diff [base-branch]...HEAD` to understand the full commit history for the current branch (from the time it diverged from the base branch)
98
+ 2. Analyze all changes that will be included in the pull request, making sure to look at all relevant commits (NOT just the latest commit, but ALL commits that will be included in the pull request!!!), and draft a pull request summary
99
+ 3. You can call multiple tools in a single response. When multiple independent works are likely to succeed, run multiple tool calls in parallel for optimal performance. run the following commands in parallel:
100
+ - Create new branch if needed
101
+ - Push to remote with -u flag if needed
102
+ - Create PR using gh pr create with the format below. Use a HEREDOC to pass the body to ensure correct formatting.
103
+ <example>
104
+ gh pr create --title "the pr title" --body "$(cat <<'EOF'
105
+ ## Summary
106
+ <1-3 bullet points>
107
+ </example>
108
+
109
+ Important:
110
+ - DO NOT use the TodoWrite or Task tools
111
+ - Return the PR URL when you're done, so the user can see it
112
+
113
+ # Other common operations
114
+ - View comments on a GitHub PR: gh api repos/foo/bar/pulls/123/comments