iosm-cli 0.2.7 → 0.2.8
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.
- package/CHANGELOG.md +28 -1
- package/README.md +2 -2
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +7 -3
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-profiles.d.ts.map +1 -1
- package/dist/core/agent-profiles.js +10 -1
- package/dist/core/agent-profiles.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +26 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +3 -3
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +39 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +168 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/shadow-guard.js +1 -1
- package/dist/core/shadow-guard.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +78 -4
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/git-common.d.ts +45 -0
- package/dist/core/tools/git-common.d.ts.map +1 -0
- package/dist/core/tools/git-common.js +185 -0
- package/dist/core/tools/git-common.js.map +1 -0
- package/dist/core/tools/git-read.d.ts +15 -13
- package/dist/core/tools/git-read.d.ts.map +1 -1
- package/dist/core/tools/git-read.js +101 -153
- package/dist/core/tools/git-read.js.map +1 -1
- package/dist/core/tools/git-write.d.ts +75 -0
- package/dist/core/tools/git-write.d.ts.map +1 -0
- package/dist/core/tools/git-write.js +298 -0
- package/dist/core/tools/git-write.js.map +1 -0
- package/dist/core/tools/index.d.ts +47 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +10 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/task.js +1 -1
- package/dist/core/tools/task.js.map +1 -1
- package/dist/core/tools/web-search.d.ts +72 -0
- package/dist/core/tools/web-search.d.ts.map +1 -0
- package/dist/core/tools/web-search.js +702 -0
- package/dist/core/tools/web-search.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +7 -2
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/mcp-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/mcp-selector.js +3 -1
- package/dist/modes/interactive/components/mcp-selector.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +12 -2
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +11 -0
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +16 -5
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +4 -2
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +25 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +182 -2
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.js +7 -2
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/theme-selector.js +7 -2
- package/dist/modes/interactive/components/theme-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +7 -2
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +18 -3
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js +8 -0
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +4 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +128 -2
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/cli-reference.md +17 -2
- package/docs/configuration.md +11 -2
- package/docs/development-and-testing.md +1 -1
- package/docs/interactive-mode.md +2 -2
- package/docs/rpc-json-sdk.md +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAEhE,0CAA0C;AAC1C,MAAM,gBAAgB,GAA2B;IAChD,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,8CAA8C;IACpD,IAAI,EAAE,4DAA4D;IAClE,KAAK,EAAE,2BAA2B;IAClC,IAAI,EAAE,yDAAyD;IAC/D,IAAI,EAAE,kDAAkD;IACxD,EAAE,EAAE,yBAAyB;IAC7B,EAAE,EAAE,+FAA+F;IACnG,EAAE,EAAE,yCAAyC;IAC7C,QAAQ,EACP,uHAAuH;IACxH,KAAK,EACJ,wGAAwG;IACzG,EAAE,EAA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BAA2B,CAAC;QACtC,MAAM,IAAI,mDAAmD,CAAC;QAC9D,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;YACxD,MAAM,IAAI,MAAM,QAAQ,OAAO,OAAO,MAAM,CAAC;QAC9C,CAAC;IACF,CAAC;IAED,yDAAyD;IACzD,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,2CAA2C;IAC3C,MAAM,IAAI,4BAA4B,QAAQ,EAAE,CAAC;IACjD,MAAM,IAAI,gCAAgC,WAAW,EAAE,CAAC;IAExD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\n/** Tool descriptions for system prompt */\nconst toolDescriptions: Record<string, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents for patterns (respects .gitignore)\",\n\tfind: \"Find files by glob pattern (respects .gitignore)\",\n\tls: \"List directory contents\",\n\trg: \"Run ripgrep directly for advanced regex search (prefer explicit path args, e.g. -n pattern .)\",\n\tfd: \"Run fd directly for fast file discovery\",\n\tast_grep:\n\t\t\"Run ast-grep for AST/syntax-aware structural code search (prefer run --pattern; retry with scan/-p on older versions)\",\n\tcomby:\n\t\t\"Run comby for structural pattern search/rewrite previews (prefer explicit -matcher; no in-place edits)\",\n\tjq: \"Run jq for JSON querying/transformation\",\n\tyq: \"Run yq for YAML/JSON/TOML querying/transformation\",\n\tsemgrep: \"Run semgrep for structural/static security checks\",\n\tsed: \"Run sed for stream editing/extraction previews (no in-place edits)\",\n\tsemantic_search:\n\t\t\"Semantic embeddings search over the project index (actions: status, index, rebuild, query)\",\n\tfetch: \"Make HTTP requests with bounded response capture and manual redirect handling\",\n\tgit_read: \"Structured read-only git introspection (status, diff, log, blame)\",\n\tfs_ops: \"Structured filesystem mutations (mkdir, move, copy, delete) with recursive/force guards\",\n\ttask: \"Run a specialized subagent (supports profile, cwd, lock_key for optional write serialization, run_id/task_id, model override, background mode for detached runs, and agent=<custom name from .iosm/agents>)\",\n};\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. Default: process.cwd() */\n\tcwd?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t} = options;\n\tconst resolvedCwd = cwd ?? process.cwd();\n\n\tconst now = new Date();\n\tconst dateTime = now.toLocaleString(\"en-US\", {\n\t\tweekday: \"long\",\n\t\tyear: \"numeric\",\n\t\tmonth: \"long\",\n\t\tday: \"numeric\",\n\t\thour: \"2-digit\",\n\t\tminute: \"2-digit\",\n\t\tsecond: \"2-digit\",\n\t\ttimeZoneName: \"short\",\n\t});\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skills = providedSkills ?? [];\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Append skills section (only if read tool is available)\n\t\tconst customPromptHasRead = !selectedTools || selectedTools.includes(\"read\");\n\t\tif (customPromptHasRead && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Add date/time and working directory last\n\t\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\t\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\n\t// Build tools list based on selected tools.\n\t// Built-ins use toolDescriptions. Custom tools can provide one-line snippets.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst toolsList =\n\t\ttools.length > 0\n\t\t\t? tools\n\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\tconst snippet = toolSnippets?.[name] ?? toolDescriptions[name] ?? name;\n\t\t\t\t\t\treturn `- ${name}: ${snippet}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasEdit = tools.includes(\"edit\");\n\tconst hasWrite = tools.includes(\"write\");\n\tconst hasGrep = tools.includes(\"grep\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst hasRg = tools.includes(\"rg\");\n\tconst hasFd = tools.includes(\"fd\");\n\tconst hasAstGrep = tools.includes(\"ast_grep\");\n\tconst hasComby = tools.includes(\"comby\");\n\tconst hasJq = tools.includes(\"jq\");\n\tconst hasYq = tools.includes(\"yq\");\n\tconst hasSemgrep = tools.includes(\"semgrep\");\n\tconst hasSed = tools.includes(\"sed\");\n\tconst hasSemanticSearch = tools.includes(\"semantic_search\");\n\tconst hasFetch = tools.includes(\"fetch\");\n\tconst hasGitRead = tools.includes(\"git_read\");\n\tconst hasFsOps = tools.includes(\"fs_ops\");\n\tconst hasRead = tools.includes(\"read\");\n\n\t// File exploration guidelines\n\tif (hasBash && !hasGrep && !hasFind && !hasLs && !hasRg && !hasFd) {\n\t\taddGuideline(\"Use bash for file operations like ls, rg, find; prefer rg for targeted search when available\");\n\t} else if (hasBash && (hasGrep || hasFind || hasLs || hasRg || hasFd)) {\n\t\taddGuideline(\"Prefer grep/find/ls/rg/fd tools over bash for codebase exploration (faster and less noisy)\");\n\t}\n\tif (hasBash && hasGitRead) {\n\t\taddGuideline(\"Prefer git_read over bash for git status/diff/log/blame analysis in read-only workflows\");\n\t}\n\tif (hasBash && hasFetch) {\n\t\taddGuideline(\"Prefer fetch over bash curl/wget for HTTP retrieval when structured request parameters are sufficient\");\n\t}\n\n\tif (hasRg || hasFd || hasAstGrep || hasComby || hasJq || hasYq || hasSemgrep || hasSed || hasSemanticSearch || hasFetch || hasGitRead || hasFsOps) {\n\t\taddGuideline(\n\t\t\t\"Route work to specialized tools first: rg/fd (search/discovery), semantic_search (concept-level retrieval), ast_grep/comby (structural code queries), jq/yq (data/config transforms), semgrep (risk scans), sed (stream extraction), fetch (HTTP retrieval), git_read (git analysis), fs_ops (filesystem mutations)\",\n\t\t);\n\t}\n\n\tif (hasAstGrep || hasComby) {\n\t\taddGuideline(\"Use ast_grep/comby for syntax-aware structural queries before falling back to broad regex\");\n\t}\n\n\tif (hasComby) {\n\t\taddGuideline(\"Use comby to preview structural rewrite matches first, then apply final changes via edit/write\");\n\t}\n\n\tif (hasJq || hasYq) {\n\t\taddGuideline(\"Prefer jq/yq over ad-hoc shell parsing when extracting or transforming JSON/YAML/TOML\");\n\t}\n\n\tif (hasSemgrep) {\n\t\taddGuideline(\"Use semgrep for rule-based risk scans and structural security checks when relevant\");\n\t}\n\n\tif (hasSed) {\n\t\taddGuideline(\"Use sed for preview/extraction workflows only; perform final file edits with edit/write\");\n\t}\n\n\tif (hasSemanticSearch) {\n\t\taddGuideline(\n\t\t\t\"Use semantic_search for intent/meaning queries that are hard to express with regex; use rg/ast_grep for exact symbol and syntax matches\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"semantic_search query can auto-refresh stale indexes when semantic auto-index is enabled (default); if disabled or if provider/chunk/filter changes require it, run semantic_search index/rebuild explicitly\",\n\t\t);\n\t}\n\n\tif (hasRg || hasAstGrep || hasComby) {\n\t\taddGuideline(\n\t\t\t\"For rg/ast_grep/comby, pass explicit target paths to avoid cwd ambiguity; if syntax errors occur (especially ast_grep), retry once with version-compatible command forms before concluding no matches\",\n\t\t);\n\t}\n\n\tif (\n\t\thasBash &&\n\t\t(hasRg || hasFd || hasAstGrep || hasComby || hasJq || hasYq || hasSemgrep || hasSed || hasSemanticSearch)\n\t) {\n\t\taddGuideline(\n\t\t\t\"If a required CLI tool is missing, install it first when permitted (rg/fd can be auto-managed; others via brew/apt/pipx/npm), then continue with that tool instead of broad bash fallback. For semantic_search, configure provider/index first via /semantic setup.\",\n\t\t);\n\t}\n\n\t// Read before edit guideline\n\tif (hasRead && hasEdit) {\n\t\taddGuideline(\"Use read to examine files before editing. You must use this tool instead of cat or sed.\");\n\t}\n\n\t// Edit guideline\n\tif (hasEdit) {\n\t\taddGuideline(\"Use edit for precise changes (old text must match exactly)\");\n\t}\n\n\t// Write guideline\n\tif (hasWrite) {\n\t\taddGuideline(\"Use write only for new files or complete rewrites\");\n\t}\n\tif (hasFsOps) {\n\t\taddGuideline(\"Use fs_ops for mkdir/move/copy/delete workflows instead of broad bash file mutation commands\");\n\t}\n\n\t// Output guideline (only when actually writing or executing)\n\tif (hasEdit || hasWrite) {\n\t\taddGuideline(\n\t\t\t\"When summarizing your actions, output plain text directly - do NOT use cat or bash to display what you did\",\n\t\t);\n\t}\n\n\taddGuideline(\"Inspect the relevant files before editing and keep exploration bounded to the task\");\n\taddGuideline(\"Make reasonable assumptions and continue unless a risky ambiguity blocks the work\");\n\taddGuideline(\"Classify requests as simple vs complex: execute simple work immediately, use a step plan for complex work\");\n\taddGuideline(\"For complex work, publish a short step plan before edits and keep step statuses current while executing\");\n\taddGuideline(\"If a meaningful architecture or product fork changes implementation, ask a concise clarification before editing\");\n\taddGuideline(\"After changes, run the smallest relevant verification and report the concrete result\");\n\taddGuideline(\"Do not claim success without evidence; if you could not verify, say so explicitly\");\n\taddGuideline(\"Complete the requested task end-to-end when possible instead of stopping at analysis\");\n\taddGuideline(\"For code review requests, lead with findings and risks before summaries\");\n\taddGuideline(\n\t\t\"When an active engineering contract is present in context, treat its constraints, quality gates, and definition_of_done as execution requirements unless user overrides them.\",\n\t);\n\taddGuideline(\"For major feature forks, run a /singular feasibility pass before coding to compare implementation options.\");\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\t// Always include these\n\taddGuideline(\"Be concise in your responses\");\n\taddGuideline(\"Show file paths clearly when working with files\");\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tlet prompt = `You are a professional software engineering agent operating inside iosm-cli. Help users inspect systems, change code, run commands, maintain project artifacts when needed, and explain results clearly.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n\nOperating defaults:\n- Summarize work in standard engineering language first: what you inspected, what you changed, what you verified, and any remaining risk or blocker.\n- Do NOT start by reading documentation unless the user asks for documentation help, asks about harness internals, or implementation is blocked without it.\n- Start implementation turns with a quick repository scan of the files most likely to matter before proposing or editing.\n- Prefer targeted reads and searches over broad dumps; keep command output bounded and focused.\n- For complex tasks, include a machine-readable plan block before edits and update it when statuses change:\n <task_plan complexity=\"complex\">\n - [in_progress] Current step\n - [pending] Next step\n </task_plan>\n- Skip plan blocks for simple one-shot tasks.\n- When a material architecture fork exists, pause and ask one concise clarification (or use ask_user when available) before implementation.\n- Treat verification as mandatory after edits: tests, type checks, linters, or a precise explanation of why verification was not possible.\n- For complex requests, execute plan steps in order, close each step explicitly, and finish the full plan unless blocked.\n- If the user explicitly asks for subagents/agents orchestration, you MUST use the task tool rather than doing all work in the main agent.\n- For explicit subagent/orchestration requests, execute at least one task tool call before giving a final prose-only answer.\n- Do not expose internal orchestration scaffolding to the user (for example: [ORCHESTRATION_DIRECTIVE], pseudo tool-call JSON, or raw task arguments).\n- When invoking tools, call them directly without preambles like \"I will now call tool X\"; only report outcomes that matter to the user.\n\t- Respect orchestration constraints from the user exactly: count, parallel vs sequential execution, per-agent profile, and per-agent working directory (cwd) when provided.\n\t- Treat explicit orchestration requests in any language as constraints (including non-English text and minor typos).\n\t- For explicit parallel orchestration requests, issue multiple independent task tool calls to match the requested agent count; do not collapse to a single subagent unless the user asks for one.\n- For explicit parallel orchestration requests, emit independent task calls in a single assistant turn whenever possible so they can be launched together.\n- Runtime note: when parallel orchestration is requested, emit independent task calls in one assistant turn so they can run concurrently; avoid background mode unless the user explicitly asks for detached async runs.\n- If orchestration constraints are ambiguous or conflict, ask one concise clarification (or use ask_user when available) before launching subagents.\n- When the user provides an <orchestrate ...>...</orchestrate> block, treat it as an execution contract and follow its mode/agents/profile/cwd assignments strictly.\n- When orchestration assignments include run_id/task_id/lock_key or depends_on, enforce them in task calls (run_id/task_id for team tracking, lock_key for serialization domains, depends_on for ordering).\n- For delegated parallel runs, use shared_memory_* tools as the primary coordination channel: namespaced keys, read-before-write, and CAS (if_version) for contested updates; reserve append mode for timeline/log keys.\n- For write-heavy parallel orchestration, prefer isolation=worktree to reduce cross-agent interference when the repository is git-backed.\n- If the user message includes @<custom-agent-name>, treat it as an explicit agent selection and call task with agent set to that custom agent name.\n\niosm-cli reference docs (use when needed):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), package composition (docs/packages.md)\n- When working on harness internals, read the relevant docs/examples before implementing`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\t// Append skills section (only if read tool is available)\n\tif (hasRead && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date/time and working directory last\n\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\treturn prompt;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,eAAe,EAA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E,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;YACxD,MAAM,IAAI,MAAM,QAAQ,OAAO,OAAO,MAAM,CAAC;QAC9C,CAAC;IACF,CAAC;IAED,yDAAyD;IACzD,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,2CAA2C;IAC3C,MAAM,IAAI,4BAA4B,QAAQ,EAAE,CAAC;IACjD,MAAM,IAAI,gCAAgC,WAAW,EAAE,CAAC;IAExD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\n/** Tool descriptions for system prompt */\nconst toolDescriptions: Record<string, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents for patterns (respects .gitignore)\",\n\tfind: \"Find files by glob pattern (respects .gitignore)\",\n\tls: \"List directory contents\",\n\trg: \"Run ripgrep directly for advanced regex search (prefer explicit path args, e.g. -n pattern .)\",\n\tfd: \"Run fd directly for fast file discovery\",\n\tast_grep:\n\t\t\"Run ast-grep for AST/syntax-aware structural code search (prefer run --pattern; retry with scan/-p on older versions)\",\n\tcomby:\n\t\t\"Run comby for structural pattern search/rewrite previews (prefer explicit -matcher; no in-place edits)\",\n\tjq: \"Run jq for JSON querying/transformation\",\n\tyq: \"Run yq for YAML/JSON/TOML querying/transformation\",\n\tsemgrep: \"Run semgrep for structural/static security checks\",\n\tsed: \"Run sed for stream editing/extraction previews (no in-place edits)\",\n\tsemantic_search:\n\t\t\"Semantic embeddings search over the project index (actions: status, index, rebuild, query)\",\n\tfetch: \"Make HTTP requests with bounded response capture and manual redirect handling (including GitHub REST/Raw endpoints)\",\n\tweb_search: \"Discover relevant pages on the internet (Tavily with SearXNG/DuckDuckGo fallback)\",\n\tgit_read: \"Structured read-only git introspection (status, diff, log, blame, show, branch_list, remote_list, rev_parse)\",\n\tgit_write:\n\t\t\"Structured git mutation tool for local repository operations (add, restore, reset_index, commit, switch, branch_create, stash_*) plus optional network actions (fetch, pull, push) when enabled\",\n\tfs_ops: \"Structured filesystem mutations (mkdir, move, copy, delete) with recursive/force guards\",\n\ttodo_write:\n\t\t\"Create or update persistent task checklist state for the current workspace/session (pending, in_progress, completed)\",\n\ttodo_read: \"Read the current persistent task checklist state for the current workspace/session\",\n\ttask: \"Run a specialized subagent (supports profile, cwd, lock_key for optional write serialization, run_id/task_id, model override, background mode for detached runs, and agent=<custom name from .iosm/agents>)\",\n};\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. Default: process.cwd() */\n\tcwd?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t} = options;\n\tconst resolvedCwd = cwd ?? process.cwd();\n\n\tconst now = new Date();\n\tconst dateTime = now.toLocaleString(\"en-US\", {\n\t\tweekday: \"long\",\n\t\tyear: \"numeric\",\n\t\tmonth: \"long\",\n\t\tday: \"numeric\",\n\t\thour: \"2-digit\",\n\t\tminute: \"2-digit\",\n\t\tsecond: \"2-digit\",\n\t\ttimeZoneName: \"short\",\n\t});\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skills = providedSkills ?? [];\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Append skills section (only if read tool is available)\n\t\tconst customPromptHasRead = !selectedTools || selectedTools.includes(\"read\");\n\t\tif (customPromptHasRead && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Add date/time and working directory last\n\t\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\t\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\n\t// Build tools list based on selected tools.\n\t// Built-ins use toolDescriptions. Custom tools can provide one-line snippets.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst toolsList =\n\t\ttools.length > 0\n\t\t\t? tools\n\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\tconst snippet = toolSnippets?.[name] ?? toolDescriptions[name] ?? name;\n\t\t\t\t\t\treturn `- ${name}: ${snippet}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasEdit = tools.includes(\"edit\");\n\tconst hasWrite = tools.includes(\"write\");\n\tconst hasGrep = tools.includes(\"grep\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst hasRg = tools.includes(\"rg\");\n\tconst hasFd = tools.includes(\"fd\");\n\tconst hasAstGrep = tools.includes(\"ast_grep\");\n\tconst hasComby = tools.includes(\"comby\");\n\tconst hasJq = tools.includes(\"jq\");\n\tconst hasYq = tools.includes(\"yq\");\n\tconst hasSemgrep = tools.includes(\"semgrep\");\n\tconst hasSed = tools.includes(\"sed\");\n\tconst hasSemanticSearch = tools.includes(\"semantic_search\");\n\tconst hasFetch = tools.includes(\"fetch\");\n\tconst hasWebSearch = tools.includes(\"web_search\");\n\tconst hasGitRead = tools.includes(\"git_read\");\n\tconst hasGitWrite = tools.includes(\"git_write\");\n\tconst hasFsOps = tools.includes(\"fs_ops\");\n\tconst hasTodoWrite = tools.includes(\"todo_write\");\n\tconst hasTodoRead = tools.includes(\"todo_read\");\n\tconst hasTask = tools.includes(\"task\");\n\tconst hasRead = tools.includes(\"read\");\n\n\t// File exploration guidelines\n\tif (hasBash && !hasGrep && !hasFind && !hasLs && !hasRg && !hasFd) {\n\t\taddGuideline(\"Use bash for file operations like ls, rg, find; prefer rg for targeted search when available\");\n\t} else if (hasBash && (hasGrep || hasFind || hasLs || hasRg || hasFd)) {\n\t\taddGuideline(\"Prefer grep/find/ls/rg/fd tools over bash for codebase exploration (faster and less noisy)\");\n\t}\n\tif (hasBash && hasGitRead) {\n\t\taddGuideline(\"Prefer git_read over bash for git status/diff/log/blame analysis in read-only workflows\");\n\t}\n\tif (hasBash && hasGitWrite) {\n\t\taddGuideline(\"Prefer git_write over bash for git mutation workflows (add/commit/switch/stash/fetch/pull/push) when available\");\n\t}\n\tif (hasGitRead) {\n\t\taddGuideline(\n\t\t\t\"For repository diagnostics, start with git_read status, then use targeted diff/log/blame/show on affected files or refs instead of broad repository-wide output\",\n\t\t);\n\t}\n\tif (hasGitWrite) {\n\t\taddGuideline(\n\t\t\t\"For git_write mutations, prefer smallest scope first (targeted files, explicit branch/remote/message), and validate resulting state with git_read status/diff\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"For git_write network actions (fetch/pull/push), verify runtime network policy/token availability and specify remote/branch explicitly when known\",\n\t\t);\n\t}\n\tif (hasBash && hasFetch) {\n\t\taddGuideline(\"Prefer fetch over bash curl/wget for HTTP retrieval when structured request parameters are sufficient\");\n\t}\n\tif (hasFetch) {\n\t\taddGuideline(\n\t\t\t\"For remote repository analysis without a local clone, use fetch against GitHub API/Raw URLs (api.github.com, raw.githubusercontent.com) before falling back to shell-based cloning\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"For fetch against APIs, prefer response_format=json (or auto when content-type is JSON); use text mode for HTML/text pages and narrow requests when output truncates\",\n\t\t);\n\t}\n\tif (hasBash && hasWebSearch) {\n\t\taddGuideline(\"Prefer web_search over ad-hoc bash web scraping for internet discovery\");\n\t}\n\tif (hasWebSearch) {\n\t\taddGuideline(\n\t\t\t\"For web_search, constrain scope with include_domains/exclude_domains/days/topic when trust, recency, or domain focus matters\",\n\t\t);\n\t\taddGuideline(\"Treat web_search results as candidate leads; verify critical claims by fetching primary sources\");\n\t}\n\tif (hasWebSearch && hasFetch) {\n\t\taddGuideline(\"Use web_search for discovery and fetch for reading specific pages\");\n\t}\n\n\tif (\n\t\thasRg ||\n\t\thasFd ||\n\t\thasAstGrep ||\n\t\thasComby ||\n\t\thasJq ||\n\t\thasYq ||\n\t\thasSemgrep ||\n\t\thasSed ||\n\t\thasSemanticSearch ||\n\t\thasWebSearch ||\n\t\thasFetch ||\n\t\thasGitRead ||\n\t\thasGitWrite ||\n\t\thasFsOps ||\n\t\thasTask ||\n\t\thasTodoRead ||\n\t\thasTodoWrite\n\t) {\n\t\taddGuideline(\n\t\t\t\"Route work to specialized tools first: rg/fd (search/discovery), semantic_search (concept-level retrieval), ast_grep/comby (structural code queries), jq/yq (data/config transforms), semgrep (risk scans), sed (stream extraction), web_search (internet discovery), fetch (HTTP retrieval), git_read (git analysis), git_write (git mutations), fs_ops (filesystem mutations), task (delegated execution), todo_read/todo_write (task-state tracking)\",\n\t\t);\n\t}\n\n\tif (hasAstGrep || hasComby) {\n\t\taddGuideline(\"Use ast_grep/comby for syntax-aware structural queries before falling back to broad regex\");\n\t}\n\n\tif (hasComby) {\n\t\taddGuideline(\"Use comby to preview structural rewrite matches first, then apply final changes via edit/write\");\n\t}\n\n\tif (hasJq || hasYq) {\n\t\taddGuideline(\"Prefer jq/yq over ad-hoc shell parsing when extracting or transforming JSON/YAML/TOML\");\n\t\taddGuideline(\"Treat jq/yq output as a validated transform preview, then persist final changes via edit/write instead of in-place CLI mutation\");\n\t}\n\n\tif (hasSemgrep) {\n\t\taddGuideline(\"Use semgrep for rule-based risk scans and structural security checks when relevant\");\n\t}\n\n\tif (hasSed) {\n\t\taddGuideline(\"Use sed for preview/extraction workflows only; perform final file edits with edit/write\");\n\t}\n\n\tif (hasSemanticSearch) {\n\t\taddGuideline(\n\t\t\t\"Use semantic_search for intent/meaning queries that are hard to express with regex; use rg/ast_grep for exact symbol and syntax matches\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"semantic_search query can auto-refresh stale indexes when semantic auto-index is enabled (default); if disabled or if provider/chunk/filter changes require it, run semantic_search index/rebuild explicitly\",\n\t\t);\n\t\taddGuideline(\"When semantic relevance looks off, run semantic_search status first to confirm index freshness/provider before broad query retries\");\n\t}\n\n\tif (hasRg || hasAstGrep || hasComby) {\n\t\taddGuideline(\n\t\t\t\"For rg/ast_grep/comby, pass explicit target paths to avoid cwd ambiguity; if syntax errors occur (especially ast_grep), retry once with version-compatible command forms before concluding no matches\",\n\t\t);\n\t}\n\tif (hasRg) {\n\t\taddGuideline(\"For rg, include explicit path roots (for example '.') and line-number flags when results need precise follow-up edits\");\n\t}\n\tif (hasFd) {\n\t\taddGuideline(\"For fd, narrow scope with explicit roots/globs before widening search to avoid noisy full-repository listings\");\n\t}\n\tif (hasGrep || hasFind || hasLs) {\n\t\taddGuideline(\"For grep/find/ls, set path/glob/context/limit deliberately so exploration stays bounded and outputs remain actionable\");\n\t}\n\n\tif (\n\t\thasBash &&\n\t\t(hasRg || hasFd || hasAstGrep || hasComby || hasJq || hasYq || hasSemgrep || hasSed || hasSemanticSearch)\n\t) {\n\t\taddGuideline(\n\t\t\t\"If a required CLI tool is missing, install it first when permitted (rg/fd can be auto-managed; others via brew/apt/pipx/npm), then continue with that tool instead of broad bash fallback. For semantic_search, configure provider/index first via /semantic setup.\",\n\t\t);\n\t}\n\n\t// Read before edit guideline\n\tif (hasRead && hasEdit) {\n\t\taddGuideline(\"Use read to examine files before editing. You must use this tool instead of cat or sed.\");\n\t}\n\tif (hasRead) {\n\t\taddGuideline(\"For large files, page with read offset/limit and continue from the suggested next offset instead of rereading from the top\");\n\t}\n\n\t// Edit guideline\n\tif (hasEdit) {\n\t\taddGuideline(\"Use edit for precise changes (old text must match exactly)\");\n\t}\n\n\t// Write guideline\n\tif (hasWrite) {\n\t\taddGuideline(\"Use write only for new files or complete rewrites\");\n\t}\n\tif (hasFsOps) {\n\t\taddGuideline(\"Use fs_ops for mkdir/move/copy/delete workflows instead of broad bash file mutation commands\");\n\t\taddGuideline(\n\t\t\t\"For fs_ops safety, use force=true only when replacement/no-op semantics are intended, and require recursive=true before deleting directories\",\n\t\t);\n\t}\n\tif (hasTask) {\n\t\taddGuideline(\n\t\t\t\"Use task for parallelizable or isolated workstreams: keep each task prompt scoped, include expected outputs, and pass profile/cwd/lock_key/run_id/task_id when those constraints are known\",\n\t\t);\n\t\taddGuideline(\"Avoid task fan-out for trivial one-shot requests where direct execution is clearly faster and lower risk\");\n\t}\n\tif (hasTodoWrite || hasTodoRead) {\n\t\taddGuideline(\"Use todo_read at the start of multi-step turns to recover current task state before planning additional work\");\n\t}\n\tif (hasTodoWrite) {\n\t\taddGuideline(\n\t\t\t\"Maintain task state with todo_write during multi-step execution: keep a single in_progress item when possible and mark completed items promptly\",\n\t\t);\n\t}\n\n\t// Output guideline (only when actually writing or executing)\n\tif (hasEdit || hasWrite) {\n\t\taddGuideline(\n\t\t\t\"When summarizing your actions, output plain text directly - do NOT use cat or bash to display what you did\",\n\t\t);\n\t}\n\n\taddGuideline(\"Inspect the relevant files before editing and keep exploration bounded to the task\");\n\taddGuideline(\"Make reasonable assumptions and continue unless a risky ambiguity blocks the work\");\n\taddGuideline(\"Classify requests as simple vs complex: execute simple work immediately, use a step plan for complex work\");\n\taddGuideline(\"For complex work, publish a short step plan before edits and keep step statuses current while executing\");\n\taddGuideline(\"If a meaningful architecture or product fork changes implementation, ask a concise clarification before editing\");\n\taddGuideline(\"After changes, run the smallest relevant verification and report the concrete result\");\n\taddGuideline(\"Do not claim success without evidence; if you could not verify, say so explicitly\");\n\taddGuideline(\"Complete the requested task end-to-end when possible instead of stopping at analysis\");\n\taddGuideline(\"For code review requests, lead with findings and risks before summaries\");\n\taddGuideline(\n\t\t\"When an active engineering contract is present in context, treat its constraints, quality gates, and definition_of_done as execution requirements unless user overrides them.\",\n\t);\n\taddGuideline(\"For major feature forks, run a /singular feasibility pass before coding to compare implementation options.\");\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\t// Always include these\n\taddGuideline(\"Be concise in your responses\");\n\taddGuideline(\"Show file paths clearly when working with files\");\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tlet prompt = `You are a professional software engineering agent operating inside iosm-cli. Help users inspect systems, change code, run commands, maintain project artifacts when needed, and explain results clearly.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n\nOperating defaults:\n- Summarize work in standard engineering language first: what you inspected, what you changed, what you verified, and any remaining risk or blocker.\n- Do NOT start by reading documentation unless the user asks for documentation help, asks about harness internals, or implementation is blocked without it.\n- Start implementation turns with a quick repository scan of the files most likely to matter before proposing or editing.\n- Prefer targeted reads and searches over broad dumps; keep command output bounded and focused.\n- For complex tasks, include a machine-readable plan block before edits and update it when statuses change:\n <task_plan complexity=\"complex\">\n - [in_progress] Current step\n - [pending] Next step\n </task_plan>\n- Skip plan blocks for simple one-shot tasks.\n- When a material architecture fork exists, pause and ask one concise clarification (or use ask_user when available) before implementation.\n- Treat verification as mandatory after edits: tests, type checks, linters, or a precise explanation of why verification was not possible.\n- For complex requests, execute plan steps in order, close each step explicitly, and finish the full plan unless blocked.\n- If the user explicitly asks for subagents/agents orchestration, you MUST use the task tool rather than doing all work in the main agent.\n- For explicit subagent/orchestration requests, execute at least one task tool call before giving a final prose-only answer.\n- Do not expose internal orchestration scaffolding to the user (for example: [ORCHESTRATION_DIRECTIVE], pseudo tool-call JSON, or raw task arguments).\n- When invoking tools, call them directly without preambles like \"I will now call tool X\"; only report outcomes that matter to the user.\n\t- Respect orchestration constraints from the user exactly: count, parallel vs sequential execution, per-agent profile, and per-agent working directory (cwd) when provided.\n\t- Treat explicit orchestration requests in any language as constraints (including non-English text and minor typos).\n\t- For explicit parallel orchestration requests, issue multiple independent task tool calls to match the requested agent count; do not collapse to a single subagent unless the user asks for one.\n- For explicit parallel orchestration requests, emit independent task calls in a single assistant turn whenever possible so they can be launched together.\n- Runtime note: when parallel orchestration is requested, emit independent task calls in one assistant turn so they can run concurrently; avoid background mode unless the user explicitly asks for detached async runs.\n- If orchestration constraints are ambiguous or conflict, ask one concise clarification (or use ask_user when available) before launching subagents.\n- When the user provides an <orchestrate ...>...</orchestrate> block, treat it as an execution contract and follow its mode/agents/profile/cwd assignments strictly.\n- When orchestration assignments include run_id/task_id/lock_key or depends_on, enforce them in task calls (run_id/task_id for team tracking, lock_key for serialization domains, depends_on for ordering).\n- For delegated parallel runs, use shared_memory_* tools as the primary coordination channel: namespaced keys, read-before-write, and CAS (if_version) for contested updates; reserve append mode for timeline/log keys.\n- For write-heavy parallel orchestration, prefer isolation=worktree to reduce cross-agent interference when the repository is git-backed.\n- If the user message includes @<custom-agent-name>, treat it as an explicit agent selection and call task with agent set to that custom agent name.\n\niosm-cli reference docs (use when needed):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), package composition (docs/packages.md)\n- When working on harness internals, read the relevant docs/examples before implementing`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\t// Append skills section (only if read tool is available)\n\tif (hasRead && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date/time and working directory last\n\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\treturn prompt;\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type TruncationResult } from "./truncate.js";
|
|
2
|
+
export declare const DEFAULT_GIT_TIMEOUT_SECONDS = 30;
|
|
3
|
+
export declare const MAX_GIT_CAPTURE_BYTES: number;
|
|
4
|
+
export interface RunGitCommandResult {
|
|
5
|
+
stdout: string;
|
|
6
|
+
stderr: string;
|
|
7
|
+
exitCode: number;
|
|
8
|
+
captureTruncated: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface GitCommandExecutionOptions {
|
|
11
|
+
env?: NodeJS.ProcessEnv;
|
|
12
|
+
}
|
|
13
|
+
export type GitCommandExists = (command: string) => boolean;
|
|
14
|
+
export type RunGitCommand = (args: string[], cwd: string, timeoutMs: number, signal?: AbortSignal, executionOptions?: GitCommandExecutionOptions) => Promise<RunGitCommandResult>;
|
|
15
|
+
export interface GitCommandOptions {
|
|
16
|
+
commandExists?: GitCommandExists;
|
|
17
|
+
runCommand?: RunGitCommand;
|
|
18
|
+
}
|
|
19
|
+
export interface GitRunSummary {
|
|
20
|
+
output: string;
|
|
21
|
+
captureTruncated: boolean;
|
|
22
|
+
truncation?: TruncationResult;
|
|
23
|
+
exitCode: number;
|
|
24
|
+
}
|
|
25
|
+
export interface GitRunParams {
|
|
26
|
+
toolName: string;
|
|
27
|
+
action: string;
|
|
28
|
+
args: string[];
|
|
29
|
+
cwd: string;
|
|
30
|
+
timeoutSeconds: number;
|
|
31
|
+
runCommand: RunGitCommand;
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
env?: NodeJS.ProcessEnv;
|
|
34
|
+
}
|
|
35
|
+
export declare function resolveGitCommandOptions(options?: GitCommandOptions): {
|
|
36
|
+
hasCommand: GitCommandExists;
|
|
37
|
+
runCommand: RunGitCommand;
|
|
38
|
+
};
|
|
39
|
+
export declare function normalizePositiveInt(raw: number | undefined, fallback: number, field: string): number;
|
|
40
|
+
export declare function normalizeRefLike(raw: string | undefined, field: string): string | undefined;
|
|
41
|
+
export declare function requireRefLike(raw: string | undefined, field: string): string;
|
|
42
|
+
export declare function normalizeRequiredString(raw: string | undefined, field: string): string;
|
|
43
|
+
export declare function normalizeFiles(files: string[] | undefined, field: string): string[];
|
|
44
|
+
export declare function runGitAndFormatOutput(params: GitRunParams): Promise<GitRunSummary>;
|
|
45
|
+
//# sourceMappingURL=git-common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-common.d.ts","sourceRoot":"","sources":["../../../src/core/tools/git-common.ts"],"names":[],"mappings":"AACA,OAAO,EAIN,KAAK,gBAAgB,EAErB,MAAM,eAAe,CAAC;AAEvB,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAC9C,eAAO,MAAM,qBAAqB,QAAa,CAAC;AAEhD,MAAM,WAAW,mBAAmB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,0BAA0B;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACxB;AAED,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;AAE5D,MAAM,MAAM,aAAa,GAAG,CAC3B,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,WAAW,EACpB,gBAAgB,CAAC,EAAE,0BAA0B,KACzC,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAElC,MAAM,WAAW,iBAAiB;IACjC,aAAa,CAAC,EAAE,gBAAgB,CAAC;IACjC,UAAU,CAAC,EAAE,aAAa,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,aAAa,CAAC;IAC1B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACxB;AAuHD,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG;IACtE,UAAU,EAAE,gBAAgB,CAAC;IAC7B,UAAU,EAAE,aAAa,CAAC;CAC1B,CAKA;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAOrG;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAU3F;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAM7E;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAMtF;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAWnF;AAED,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAsCxF"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead, } from "./truncate.js";
|
|
3
|
+
export const DEFAULT_GIT_TIMEOUT_SECONDS = 30;
|
|
4
|
+
export const MAX_GIT_CAPTURE_BYTES = 512 * 1024;
|
|
5
|
+
function commandExists(command) {
|
|
6
|
+
try {
|
|
7
|
+
const result = spawnSync(command, ["--version"], { stdio: "pipe" });
|
|
8
|
+
const err = result.error;
|
|
9
|
+
return !err || err.code !== "ENOENT";
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function runGitCommand(args, cwd, timeoutMs, signal, executionOptions) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
if (signal?.aborted) {
|
|
18
|
+
reject(new Error("Operation aborted"));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const child = spawn("git", args, {
|
|
22
|
+
cwd,
|
|
23
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
24
|
+
env: executionOptions?.env ? { ...process.env, ...executionOptions.env } : process.env,
|
|
25
|
+
});
|
|
26
|
+
const stdoutChunks = [];
|
|
27
|
+
const stderrChunks = [];
|
|
28
|
+
let stdoutBytes = 0;
|
|
29
|
+
let stderrBytes = 0;
|
|
30
|
+
let captureTruncated = false;
|
|
31
|
+
let timedOut = false;
|
|
32
|
+
let aborted = false;
|
|
33
|
+
let settled = false;
|
|
34
|
+
const settle = (fn) => {
|
|
35
|
+
if (!settled) {
|
|
36
|
+
settled = true;
|
|
37
|
+
fn();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const captureChunk = (chunk, chunks, currentBytes) => {
|
|
41
|
+
if (currentBytes >= MAX_GIT_CAPTURE_BYTES) {
|
|
42
|
+
return { nextBytes: currentBytes, truncated: true };
|
|
43
|
+
}
|
|
44
|
+
const remaining = MAX_GIT_CAPTURE_BYTES - currentBytes;
|
|
45
|
+
if (chunk.length <= remaining) {
|
|
46
|
+
chunks.push(chunk);
|
|
47
|
+
return { nextBytes: currentBytes + chunk.length, truncated: false };
|
|
48
|
+
}
|
|
49
|
+
chunks.push(chunk.subarray(0, remaining));
|
|
50
|
+
return { nextBytes: MAX_GIT_CAPTURE_BYTES, truncated: true };
|
|
51
|
+
};
|
|
52
|
+
const timeoutHandle = setTimeout(() => {
|
|
53
|
+
timedOut = true;
|
|
54
|
+
child.kill("SIGTERM");
|
|
55
|
+
}, Math.max(1000, timeoutMs));
|
|
56
|
+
const onAbort = () => {
|
|
57
|
+
aborted = true;
|
|
58
|
+
child.kill("SIGTERM");
|
|
59
|
+
};
|
|
60
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
61
|
+
const cleanup = () => {
|
|
62
|
+
clearTimeout(timeoutHandle);
|
|
63
|
+
signal?.removeEventListener("abort", onAbort);
|
|
64
|
+
};
|
|
65
|
+
child.stdout.on("data", (chunk) => {
|
|
66
|
+
const captured = captureChunk(chunk, stdoutChunks, stdoutBytes);
|
|
67
|
+
stdoutBytes = captured.nextBytes;
|
|
68
|
+
captureTruncated = captureTruncated || captured.truncated;
|
|
69
|
+
});
|
|
70
|
+
child.stderr.on("data", (chunk) => {
|
|
71
|
+
const captured = captureChunk(chunk, stderrChunks, stderrBytes);
|
|
72
|
+
stderrBytes = captured.nextBytes;
|
|
73
|
+
captureTruncated = captureTruncated || captured.truncated;
|
|
74
|
+
});
|
|
75
|
+
child.on("error", (error) => {
|
|
76
|
+
cleanup();
|
|
77
|
+
settle(() => reject(new Error(`Failed to run git: ${error.message}`)));
|
|
78
|
+
});
|
|
79
|
+
child.on("close", (code) => {
|
|
80
|
+
cleanup();
|
|
81
|
+
if (aborted) {
|
|
82
|
+
settle(() => reject(new Error("Operation aborted")));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (timedOut) {
|
|
86
|
+
settle(() => reject(new Error(`Command timed out after ${Math.round(timeoutMs / 1000)}s`)));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
settle(() => resolve({
|
|
90
|
+
stdout: Buffer.concat(stdoutChunks).toString("utf-8"),
|
|
91
|
+
stderr: Buffer.concat(stderrChunks).toString("utf-8"),
|
|
92
|
+
exitCode: code ?? -1,
|
|
93
|
+
captureTruncated,
|
|
94
|
+
}));
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
export function resolveGitCommandOptions(options) {
|
|
99
|
+
return {
|
|
100
|
+
hasCommand: options?.commandExists ?? commandExists,
|
|
101
|
+
runCommand: options?.runCommand ?? runGitCommand,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function normalizePositiveInt(raw, fallback, field) {
|
|
105
|
+
if (raw === undefined)
|
|
106
|
+
return fallback;
|
|
107
|
+
const value = Math.floor(raw);
|
|
108
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
109
|
+
throw new Error(`${field} must be a positive number.`);
|
|
110
|
+
}
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
export function normalizeRefLike(raw, field) {
|
|
114
|
+
if (raw === undefined)
|
|
115
|
+
return undefined;
|
|
116
|
+
const normalized = raw.trim();
|
|
117
|
+
if (normalized.length === 0) {
|
|
118
|
+
throw new Error(`${field} must not be empty.`);
|
|
119
|
+
}
|
|
120
|
+
if (normalized.startsWith("-")) {
|
|
121
|
+
throw new Error(`${field} must not start with '-'.`);
|
|
122
|
+
}
|
|
123
|
+
return normalized;
|
|
124
|
+
}
|
|
125
|
+
export function requireRefLike(raw, field) {
|
|
126
|
+
const normalized = normalizeRefLike(raw, field);
|
|
127
|
+
if (!normalized) {
|
|
128
|
+
throw new Error(`${field} is required.`);
|
|
129
|
+
}
|
|
130
|
+
return normalized;
|
|
131
|
+
}
|
|
132
|
+
export function normalizeRequiredString(raw, field) {
|
|
133
|
+
const value = raw?.trim();
|
|
134
|
+
if (!value) {
|
|
135
|
+
throw new Error(`${field} is required.`);
|
|
136
|
+
}
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
export function normalizeFiles(files, field) {
|
|
140
|
+
if (!files || files.length === 0) {
|
|
141
|
+
throw new Error(`${field} is required.`);
|
|
142
|
+
}
|
|
143
|
+
const normalized = files
|
|
144
|
+
.map((file) => file.trim())
|
|
145
|
+
.filter((file) => file.length > 0);
|
|
146
|
+
if (normalized.length === 0) {
|
|
147
|
+
throw new Error(`${field} must include at least one non-empty path.`);
|
|
148
|
+
}
|
|
149
|
+
return normalized;
|
|
150
|
+
}
|
|
151
|
+
export async function runGitAndFormatOutput(params) {
|
|
152
|
+
const result = await params.runCommand(params.args, params.cwd, params.timeoutSeconds * 1000, params.signal, {
|
|
153
|
+
env: params.env,
|
|
154
|
+
});
|
|
155
|
+
if (result.exitCode !== 0) {
|
|
156
|
+
const errorText = result.stderr.trim() || result.stdout.trim() || `${params.toolName} ${params.action} failed with exit code ${result.exitCode}`;
|
|
157
|
+
throw new Error(errorText);
|
|
158
|
+
}
|
|
159
|
+
let output = result.stdout.trimEnd();
|
|
160
|
+
if (!output && result.stderr.trim().length > 0) {
|
|
161
|
+
output = result.stderr.trimEnd();
|
|
162
|
+
}
|
|
163
|
+
if (!output) {
|
|
164
|
+
output = "No output";
|
|
165
|
+
}
|
|
166
|
+
const truncation = truncateHead(output);
|
|
167
|
+
let finalOutput = truncation.content;
|
|
168
|
+
const notices = [];
|
|
169
|
+
if (truncation.truncated) {
|
|
170
|
+
notices.push(`${formatSize(DEFAULT_MAX_BYTES)} output limit reached`);
|
|
171
|
+
}
|
|
172
|
+
if (result.captureTruncated) {
|
|
173
|
+
notices.push(`capture limit reached (${formatSize(MAX_GIT_CAPTURE_BYTES)})`);
|
|
174
|
+
}
|
|
175
|
+
if (notices.length > 0) {
|
|
176
|
+
finalOutput += `\n\n[${notices.join(". ")} · showing up to ${DEFAULT_MAX_LINES} lines]`;
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
output: finalOutput,
|
|
180
|
+
captureTruncated: result.captureTruncated,
|
|
181
|
+
truncation: truncation.truncated ? truncation : undefined,
|
|
182
|
+
exitCode: result.exitCode,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
//# sourceMapping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C,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAClC,CAAC;IACD,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,GAAG,WAAW,CAAC;IACtB,CAAC;IAED,MAAM,UAAU,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACxC,IAAI,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;IACrC,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,iBAAiB,CAAC,uBAAuB,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,0BAA0B,UAAU,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;IAC9E,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,WAAW,IAAI,QAAQ,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,iBAAiB,SAAS,CAAC;IACzF,CAAC;IAED,OAAO;QACN,MAAM,EAAE,WAAW;QACnB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,UAAU,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;QACzD,QAAQ,EAAE,MAAM,CAAC,QAAQ;KACzB,CAAC;AACH,CAAC","sourcesContent":["import { spawn, spawnSync } from \"node:child_process\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationResult,\n\ttruncateHead,\n} from \"./truncate.js\";\n\nexport const DEFAULT_GIT_TIMEOUT_SECONDS = 30;\nexport const MAX_GIT_CAPTURE_BYTES = 512 * 1024;\n\nexport interface RunGitCommandResult {\n\tstdout: string;\n\tstderr: string;\n\texitCode: number;\n\tcaptureTruncated: boolean;\n}\n\nexport interface GitCommandExecutionOptions {\n\tenv?: NodeJS.ProcessEnv;\n}\n\nexport type GitCommandExists = (command: string) => boolean;\n\nexport type RunGitCommand = (\n\targs: string[],\n\tcwd: string,\n\ttimeoutMs: number,\n\tsignal?: AbortSignal,\n\texecutionOptions?: GitCommandExecutionOptions,\n) => Promise<RunGitCommandResult>;\n\nexport interface GitCommandOptions {\n\tcommandExists?: GitCommandExists;\n\trunCommand?: RunGitCommand;\n}\n\nexport interface GitRunSummary {\n\toutput: string;\n\tcaptureTruncated: boolean;\n\ttruncation?: TruncationResult;\n\texitCode: number;\n}\n\nexport interface GitRunParams {\n\ttoolName: string;\n\taction: string;\n\targs: string[];\n\tcwd: string;\n\ttimeoutSeconds: number;\n\trunCommand: RunGitCommand;\n\tsignal?: AbortSignal;\n\tenv?: NodeJS.ProcessEnv;\n}\n\nfunction commandExists(command: string): boolean {\n\ttry {\n\t\tconst result = spawnSync(command, [\"--version\"], { stdio: \"pipe\" });\n\t\tconst err = result.error as NodeJS.ErrnoException | undefined;\n\t\treturn !err || err.code !== \"ENOENT\";\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction runGitCommand(\n\targs: string[],\n\tcwd: string,\n\ttimeoutMs: number,\n\tsignal?: AbortSignal,\n\texecutionOptions?: GitCommandExecutionOptions,\n): Promise<RunGitCommandResult> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\treturn;\n\t\t}\n\n\t\tconst child = spawn(\"git\", args, {\n\t\t\tcwd,\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\tenv: executionOptions?.env ? { ...process.env, ...executionOptions.env } : process.env,\n\t\t});\n\n\t\tconst stdoutChunks: Buffer[] = [];\n\t\tconst stderrChunks: Buffer[] = [];\n\t\tlet stdoutBytes = 0;\n\t\tlet stderrBytes = 0;\n\t\tlet captureTruncated = false;\n\t\tlet timedOut = false;\n\t\tlet aborted = false;\n\t\tlet settled = false;\n\n\t\tconst settle = (fn: () => void) => {\n\t\t\tif (!settled) {\n\t\t\t\tsettled = true;\n\t\t\t\tfn();\n\t\t\t}\n\t\t};\n\n\t\tconst captureChunk = (\n\t\t\tchunk: Buffer,\n\t\t\tchunks: Buffer[],\n\t\t\tcurrentBytes: number,\n\t\t): { nextBytes: number; truncated: boolean } => {\n\t\t\tif (currentBytes >= MAX_GIT_CAPTURE_BYTES) {\n\t\t\t\treturn { nextBytes: currentBytes, truncated: true };\n\t\t\t}\n\t\t\tconst remaining = MAX_GIT_CAPTURE_BYTES - currentBytes;\n\t\t\tif (chunk.length <= remaining) {\n\t\t\t\tchunks.push(chunk);\n\t\t\t\treturn { nextBytes: currentBytes + chunk.length, truncated: false };\n\t\t\t}\n\t\t\tchunks.push(chunk.subarray(0, remaining));\n\t\t\treturn { nextBytes: MAX_GIT_CAPTURE_BYTES, truncated: true };\n\t\t};\n\n\t\tconst timeoutHandle = setTimeout(() => {\n\t\t\ttimedOut = true;\n\t\t\tchild.kill(\"SIGTERM\");\n\t\t}, Math.max(1000, timeoutMs));\n\n\t\tconst onAbort = () => {\n\t\t\taborted = true;\n\t\t\tchild.kill(\"SIGTERM\");\n\t\t};\n\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\tconst cleanup = () => {\n\t\t\tclearTimeout(timeoutHandle);\n\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t};\n\n\t\tchild.stdout.on(\"data\", (chunk: Buffer) => {\n\t\t\tconst captured = captureChunk(chunk, stdoutChunks, stdoutBytes);\n\t\t\tstdoutBytes = captured.nextBytes;\n\t\t\tcaptureTruncated = captureTruncated || captured.truncated;\n\t\t});\n\n\t\tchild.stderr.on(\"data\", (chunk: Buffer) => {\n\t\t\tconst captured = captureChunk(chunk, stderrChunks, stderrBytes);\n\t\t\tstderrBytes = captured.nextBytes;\n\t\t\tcaptureTruncated = captureTruncated || captured.truncated;\n\t\t});\n\n\t\tchild.on(\"error\", (error) => {\n\t\t\tcleanup();\n\t\t\tsettle(() => reject(new Error(`Failed to run git: ${error.message}`)));\n\t\t});\n\n\t\tchild.on(\"close\", (code) => {\n\t\t\tcleanup();\n\t\t\tif (aborted) {\n\t\t\t\tsettle(() => reject(new Error(\"Operation aborted\")));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (timedOut) {\n\t\t\t\tsettle(() => reject(new Error(`Command timed out after ${Math.round(timeoutMs / 1000)}s`)));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsettle(() =>\n\t\t\t\tresolve({\n\t\t\t\t\tstdout: Buffer.concat(stdoutChunks).toString(\"utf-8\"),\n\t\t\t\t\tstderr: Buffer.concat(stderrChunks).toString(\"utf-8\"),\n\t\t\t\t\texitCode: code ?? -1,\n\t\t\t\t\tcaptureTruncated,\n\t\t\t\t}),\n\t\t\t);\n\t\t});\n\t});\n}\n\nexport function resolveGitCommandOptions(options?: GitCommandOptions): {\n\thasCommand: GitCommandExists;\n\trunCommand: RunGitCommand;\n} {\n\treturn {\n\t\thasCommand: options?.commandExists ?? commandExists,\n\t\trunCommand: options?.runCommand ?? runGitCommand,\n\t};\n}\n\nexport function normalizePositiveInt(raw: number | undefined, fallback: number, field: string): number {\n\tif (raw === undefined) return fallback;\n\tconst value = Math.floor(raw);\n\tif (!Number.isFinite(value) || value <= 0) {\n\t\tthrow new Error(`${field} must be a positive number.`);\n\t}\n\treturn value;\n}\n\nexport function normalizeRefLike(raw: string | undefined, field: string): string | undefined {\n\tif (raw === undefined) return undefined;\n\tconst normalized = raw.trim();\n\tif (normalized.length === 0) {\n\t\tthrow new Error(`${field} must not be empty.`);\n\t}\n\tif (normalized.startsWith(\"-\")) {\n\t\tthrow new Error(`${field} must not start with '-'.`);\n\t}\n\treturn normalized;\n}\n\nexport function requireRefLike(raw: string | undefined, field: string): string {\n\tconst normalized = normalizeRefLike(raw, field);\n\tif (!normalized) {\n\t\tthrow new Error(`${field} is required.`);\n\t}\n\treturn normalized;\n}\n\nexport function normalizeRequiredString(raw: string | undefined, field: string): string {\n\tconst value = raw?.trim();\n\tif (!value) {\n\t\tthrow new Error(`${field} is required.`);\n\t}\n\treturn value;\n}\n\nexport function normalizeFiles(files: string[] | undefined, field: string): string[] {\n\tif (!files || files.length === 0) {\n\t\tthrow new Error(`${field} is required.`);\n\t}\n\tconst normalized = files\n\t\t.map((file) => file.trim())\n\t\t.filter((file) => file.length > 0);\n\tif (normalized.length === 0) {\n\t\tthrow new Error(`${field} must include at least one non-empty path.`);\n\t}\n\treturn normalized;\n}\n\nexport async function runGitAndFormatOutput(params: GitRunParams): Promise<GitRunSummary> {\n\tconst result = await params.runCommand(params.args, params.cwd, params.timeoutSeconds * 1000, params.signal, {\n\t\tenv: params.env,\n\t});\n\n\tif (result.exitCode !== 0) {\n\t\tconst errorText = result.stderr.trim() || result.stdout.trim() || `${params.toolName} ${params.action} failed with exit code ${result.exitCode}`;\n\t\tthrow new Error(errorText);\n\t}\n\n\tlet output = result.stdout.trimEnd();\n\tif (!output && result.stderr.trim().length > 0) {\n\t\toutput = result.stderr.trimEnd();\n\t}\n\tif (!output) {\n\t\toutput = \"No output\";\n\t}\n\n\tconst truncation = truncateHead(output);\n\tlet finalOutput = truncation.content;\n\tconst notices: string[] = [];\n\n\tif (truncation.truncated) {\n\t\tnotices.push(`${formatSize(DEFAULT_MAX_BYTES)} output limit reached`);\n\t}\n\tif (result.captureTruncated) {\n\t\tnotices.push(`capture limit reached (${formatSize(MAX_GIT_CAPTURE_BYTES)})`);\n\t}\n\tif (notices.length > 0) {\n\t\tfinalOutput += `\\n\\n[${notices.join(\". \")} · showing up to ${DEFAULT_MAX_LINES} lines]`;\n\t}\n\n\treturn {\n\t\toutput: finalOutput,\n\t\tcaptureTruncated: result.captureTruncated,\n\t\ttruncation: truncation.truncated ? truncation : undefined,\n\t\texitCode: result.exitCode,\n\t};\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
2
|
import { type Static } from "@sinclair/typebox";
|
|
3
|
-
import { type
|
|
3
|
+
import { type GitCommandOptions } from "./git-common.js";
|
|
4
|
+
import type { TruncationResult } from "./truncate.js";
|
|
4
5
|
declare const gitReadSchema: import("@sinclair/typebox").TObject<{
|
|
5
|
-
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"status">, import("@sinclair/typebox").TLiteral<"diff">, import("@sinclair/typebox").TLiteral<"log">, import("@sinclair/typebox").TLiteral<"blame">]>;
|
|
6
|
+
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"status">, import("@sinclair/typebox").TLiteral<"diff">, import("@sinclair/typebox").TLiteral<"log">, import("@sinclair/typebox").TLiteral<"blame">, import("@sinclair/typebox").TLiteral<"show">, import("@sinclair/typebox").TLiteral<"branch_list">, import("@sinclair/typebox").TLiteral<"remote_list">, import("@sinclair/typebox").TLiteral<"rev_parse">]>;
|
|
6
7
|
path: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
7
8
|
file: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
8
9
|
base: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
@@ -16,17 +17,16 @@ declare const gitReadSchema: import("@sinclair/typebox").TObject<{
|
|
|
16
17
|
ref: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
17
18
|
line_start: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
18
19
|
line_end: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
20
|
+
all: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
21
|
+
verbose: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
22
|
+
target: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
23
|
+
short: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
19
24
|
timeout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
20
25
|
}>;
|
|
21
26
|
export type GitReadToolInput = Static<typeof gitReadSchema>;
|
|
22
|
-
|
|
23
|
-
stdout: string;
|
|
24
|
-
stderr: string;
|
|
25
|
-
exitCode: number;
|
|
26
|
-
captureTruncated: boolean;
|
|
27
|
-
}
|
|
27
|
+
type GitReadAction = GitReadToolInput["action"];
|
|
28
28
|
export interface GitReadToolDetails {
|
|
29
|
-
action:
|
|
29
|
+
action: GitReadAction;
|
|
30
30
|
command: string;
|
|
31
31
|
args: string[];
|
|
32
32
|
cwd: string;
|
|
@@ -34,13 +34,11 @@ export interface GitReadToolDetails {
|
|
|
34
34
|
captureTruncated?: boolean;
|
|
35
35
|
truncation?: TruncationResult;
|
|
36
36
|
}
|
|
37
|
-
export interface GitReadToolOptions {
|
|
38
|
-
commandExists?: (command: string) => boolean;
|
|
39
|
-
runCommand?: (args: string[], cwd: string, timeoutMs: number, signal?: AbortSignal) => Promise<RunCommandResult>;
|
|
37
|
+
export interface GitReadToolOptions extends GitCommandOptions {
|
|
40
38
|
}
|
|
41
39
|
export declare function createGitReadTool(cwd: string, options?: GitReadToolOptions): AgentTool<typeof gitReadSchema>;
|
|
42
40
|
export declare const gitReadTool: AgentTool<import("@sinclair/typebox").TObject<{
|
|
43
|
-
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"status">, import("@sinclair/typebox").TLiteral<"diff">, import("@sinclair/typebox").TLiteral<"log">, import("@sinclair/typebox").TLiteral<"blame">]>;
|
|
41
|
+
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"status">, import("@sinclair/typebox").TLiteral<"diff">, import("@sinclair/typebox").TLiteral<"log">, import("@sinclair/typebox").TLiteral<"blame">, import("@sinclair/typebox").TLiteral<"show">, import("@sinclair/typebox").TLiteral<"branch_list">, import("@sinclair/typebox").TLiteral<"remote_list">, import("@sinclair/typebox").TLiteral<"rev_parse">]>;
|
|
44
42
|
path: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
45
43
|
file: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
46
44
|
base: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
@@ -54,6 +52,10 @@ export declare const gitReadTool: AgentTool<import("@sinclair/typebox").TObject<
|
|
|
54
52
|
ref: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
55
53
|
line_start: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
56
54
|
line_end: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
55
|
+
all: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
56
|
+
verbose: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
57
|
+
target: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
58
|
+
short: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
57
59
|
timeout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
58
60
|
}>, any>;
|
|
59
61
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/git-read.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"git-read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/git-read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAON,KAAK,iBAAiB,EACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;EAwCjB,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;AAK5D,KAAK,aAAa,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AAEhD,MAAM,WAAW,kBAAkB;IAClC,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;CAAG;AAiJhE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC,OAAO,aAAa,CAAC,CA2C5G;AAED,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;QAAmC,CAAC"}
|