@openadapter/koda 1.0.0-beta.3
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 +4448 -0
- package/README.md +665 -0
- package/dist/bun/cli.d.ts +2 -0
- package/dist/bun/cli.js +2 -0
- package/dist/bun/register-bedrock.d.ts +1 -0
- package/dist/bun/register-bedrock.js +1 -0
- package/dist/bun/restore-sandbox-env.d.ts +12 -0
- package/dist/bun/restore-sandbox-env.js +1 -0
- package/dist/cli/args.d.ts +55 -0
- package/dist/cli/args.js +167 -0
- package/dist/cli/config-selector.d.ts +13 -0
- package/dist/cli/config-selector.js +1 -0
- package/dist/cli/file-processor.d.ts +14 -0
- package/dist/cli/file-processor.js +7 -0
- package/dist/cli/import-sessions.d.ts +34 -0
- package/dist/cli/import-sessions.js +6 -0
- package/dist/cli/initial-message.d.ts +17 -0
- package/dist/cli/initial-message.js +1 -0
- package/dist/cli/list-models.d.ts +8 -0
- package/dist/cli/list-models.js +2 -0
- package/dist/cli/openadapter-setup.d.ts +29 -0
- package/dist/cli/openadapter-setup.js +3 -0
- package/dist/cli/session-picker.d.ts +8 -0
- package/dist/cli/session-picker.js +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +2 -0
- package/dist/config.d.ts +92 -0
- package/dist/config.js +1 -0
- package/dist/core/agent-session-runtime.d.ts +116 -0
- package/dist/core/agent-session-runtime.js +1 -0
- package/dist/core/agent-session-services.d.ts +86 -0
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session.d.ts +747 -0
- package/dist/core/agent-session.js +32 -0
- package/dist/core/auth-guidance.d.ts +4 -0
- package/dist/core/auth-guidance.js +8 -0
- package/dist/core/auth-storage.d.ts +140 -0
- package/dist/core/auth-storage.js +1 -0
- package/dist/core/bash-executor.d.ts +31 -0
- package/dist/core/bash-executor.js +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +89 -0
- package/dist/core/compaction/branch-summarization.js +38 -0
- package/dist/core/compaction/compaction.d.ts +120 -0
- package/dist/core/compaction/compaction.js +104 -0
- package/dist/core/compaction/index.d.ts +6 -0
- package/dist/core/compaction/index.js +1 -0
- package/dist/core/compaction/utils.d.ts +37 -0
- package/dist/core/compaction/utils.js +19 -0
- package/dist/core/defaults.d.ts +2 -0
- package/dist/core/defaults.js +1 -0
- package/dist/core/diagnostics.d.ts +14 -0
- package/dist/core/diagnostics.js +0 -0
- package/dist/core/event-bus.d.ts +8 -0
- package/dist/core/event-bus.js +1 -0
- package/dist/core/exec.d.ts +28 -0
- package/dist/core/exec.js +1 -0
- package/dist/core/export-html/ansi-to-html.d.ts +21 -0
- package/dist/core/export-html/ansi-to-html.js +1 -0
- package/dist/core/export-html/index.d.ts +36 -0
- package/dist/core/export-html/index.js +2 -0
- package/dist/core/export-html/template.css +1066 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +72 -0
- package/dist/core/export-html/tool-renderer.d.ts +33 -0
- package/dist/core/export-html/tool-renderer.js +1 -0
- package/dist/core/export-html/vendor/highlight.min.js +8 -0
- package/dist/core/export-html/vendor/marked.min.js +56 -0
- package/dist/core/extensions/index.d.ts +11 -0
- package/dist/core/extensions/index.js +1 -0
- package/dist/core/extensions/loader.d.ts +23 -0
- package/dist/core/extensions/loader.js +1 -0
- package/dist/core/extensions/runner.d.ts +160 -0
- package/dist/core/extensions/runner.js +1 -0
- package/dist/core/extensions/types.d.ts +1180 -0
- package/dist/core/extensions/types.js +1 -0
- package/dist/core/extensions/wrapper.d.ts +19 -0
- package/dist/core/extensions/wrapper.js +1 -0
- package/dist/core/footer-data-provider.d.ts +53 -0
- package/dist/core/footer-data-provider.js +1 -0
- package/dist/core/http-dispatcher.d.ts +20 -0
- package/dist/core/http-dispatcher.js +1 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.js +1 -0
- package/dist/core/keybindings.d.ts +352 -0
- package/dist/core/keybindings.js +1 -0
- package/dist/core/messages.d.ts +76 -0
- package/dist/core/messages.js +17 -0
- package/dist/core/model-registry.d.ts +149 -0
- package/dist/core/model-registry.js +9 -0
- package/dist/core/model-resolver.d.ts +109 -0
- package/dist/core/model-resolver.js +1 -0
- package/dist/core/output-guard.d.ts +6 -0
- package/dist/core/output-guard.js +1 -0
- package/dist/core/package-manager.d.ts +203 -0
- package/dist/core/package-manager.js +3 -0
- package/dist/core/prompt-templates.d.ts +51 -0
- package/dist/core/prompt-templates.js +2 -0
- package/dist/core/provider-attribution.d.ts +3 -0
- package/dist/core/provider-attribution.js +1 -0
- package/dist/core/provider-display-names.d.ts +1 -0
- package/dist/core/provider-display-names.js +1 -0
- package/dist/core/resolve-config-value.d.ts +30 -0
- package/dist/core/resolve-config-value.js +1 -0
- package/dist/core/resource-loader.d.ts +193 -0
- package/dist/core/resource-loader.js +1 -0
- package/dist/core/sdk.d.ts +108 -0
- package/dist/core/sdk.js +1 -0
- package/dist/core/session-cwd.d.ts +18 -0
- package/dist/core/session-cwd.js +7 -0
- package/dist/core/session-manager.d.ts +331 -0
- package/dist/core/session-manager.js +11 -0
- package/dist/core/settings-manager.d.ts +265 -0
- package/dist/core/settings-manager.js +1 -0
- package/dist/core/skills.d.ts +59 -0
- package/dist/core/skills.js +4 -0
- package/dist/core/slash-commands.d.ts +13 -0
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/source-info.d.ts +17 -0
- package/dist/core/source-info.js +1 -0
- package/dist/core/system-prompt.d.ts +27 -0
- package/dist/core/system-prompt.js +52 -0
- package/dist/core/telemetry.d.ts +2 -0
- package/dist/core/telemetry.js +1 -0
- package/dist/core/timings.d.ts +7 -0
- package/dist/core/timings.js +3 -0
- package/dist/core/tools/bash.d.ts +67 -0
- package/dist/core/tools/bash.js +18 -0
- package/dist/core/tools/edit-diff.d.ts +86 -0
- package/dist/core/tools/edit-diff.js +16 -0
- package/dist/core/tools/edit.d.ts +50 -0
- package/dist/core/tools/edit.js +2 -0
- package/dist/core/tools/file-mutation-queue.d.ts +5 -0
- package/dist/core/tools/file-mutation-queue.js +1 -0
- package/dist/core/tools/find.d.ts +34 -0
- package/dist/core/tools/find.js +13 -0
- package/dist/core/tools/grep.d.ts +36 -0
- package/dist/core/tools/grep.js +13 -0
- package/dist/core/tools/index.d.ts +39 -0
- package/dist/core/tools/index.js +1 -0
- package/dist/core/tools/ls.d.ts +36 -0
- package/dist/core/tools/ls.js +9 -0
- package/dist/core/tools/output-accumulator.d.ts +51 -0
- package/dist/core/tools/output-accumulator.js +4 -0
- package/dist/core/tools/path-utils.d.ts +9 -0
- package/dist/core/tools/path-utils.js +1 -0
- package/dist/core/tools/read.d.ts +34 -0
- package/dist/core/tools/read.js +22 -0
- package/dist/core/tools/render-utils.d.ts +23 -0
- package/dist/core/tools/render-utils.js +4 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +13 -0
- package/dist/core/tools/tool-definition-wrapper.js +1 -0
- package/dist/core/tools/truncate.d.ts +69 -0
- package/dist/core/tools/truncate.js +5 -0
- package/dist/core/tools/write.d.ts +25 -0
- package/dist/core/tools/write.js +13 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +1 -0
- package/dist/main.d.ts +11 -0
- package/dist/main.js +1 -0
- package/dist/migrations.d.ts +32 -0
- package/dist/migrations.js +8 -0
- package/dist/modes/index.d.ts +8 -0
- package/dist/modes/index.js +1 -0
- package/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/modes/interactive/components/armin.d.ts +33 -0
- package/dist/modes/interactive/components/armin.js +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +19 -0
- package/dist/modes/interactive/components/assistant-message.js +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +33 -0
- package/dist/modes/interactive/components/bash-execution.js +13 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +15 -0
- package/dist/modes/interactive/components/bordered-loader.js +1 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +15 -0
- package/dist/modes/interactive/components/branch-summary-message.js +3 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +15 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +3 -0
- package/dist/modes/interactive/components/config-selector.d.ts +70 -0
- package/dist/modes/interactive/components/config-selector.js +1 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +13 -0
- package/dist/modes/interactive/components/countdown-timer.js +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +20 -0
- package/dist/modes/interactive/components/custom-editor.js +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +19 -0
- package/dist/modes/interactive/components/custom-message.js +2 -0
- package/dist/modes/interactive/components/daxnuts.d.ts +22 -0
- package/dist/modes/interactive/components/daxnuts.js +1 -0
- package/dist/modes/interactive/components/diff.d.ts +11 -0
- package/dist/modes/interactive/components/diff.js +3 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +14 -0
- package/dist/modes/interactive/components/dynamic-border.js +1 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts +4 -0
- package/dist/modes/interactive/components/earendil-announcement.js +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +19 -0
- package/dist/modes/interactive/components/extension-editor.js +3 -0
- package/dist/modes/interactive/components/extension-input.d.ts +22 -0
- package/dist/modes/interactive/components/extension-input.js +2 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +25 -0
- package/dist/modes/interactive/components/extension-selector.js +2 -0
- package/dist/modes/interactive/components/footer.d.ts +27 -0
- package/dist/modes/interactive/components/footer.js +1 -0
- package/dist/modes/interactive/components/index.d.ts +31 -0
- package/dist/modes/interactive/components/index.js +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +12 -0
- package/dist/modes/interactive/components/keybinding-hints.js +1 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +51 -0
- package/dist/modes/interactive/components/login-dialog.js +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +46 -0
- package/dist/modes/interactive/components/model-selector.js +2 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +30 -0
- package/dist/modes/interactive/components/oauth-selector.js +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +41 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +22 -0
- package/dist/modes/interactive/components/session-selector-search.js +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +95 -0
- package/dist/modes/interactive/components/session-selector.js +2 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +68 -0
- package/dist/modes/interactive/components/settings-selector.js +1 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +9 -0
- package/dist/modes/interactive/components/show-images-selector.js +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +16 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +3 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +10 -0
- package/dist/modes/interactive/components/theme-selector.js +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +10 -0
- package/dist/modes/interactive/components/thinking-selector.js +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +62 -0
- package/dist/modes/interactive/components/tool-execution.js +4 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +88 -0
- package/dist/modes/interactive/components/tree-selector.js +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +29 -0
- package/dist/modes/interactive/components/user-message-selector.js +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +9 -0
- package/dist/modes/interactive/components/user-message.js +1 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +23 -0
- package/dist/modes/interactive/components/visual-truncate.js +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +417 -0
- package/dist/modes/interactive/interactive-mode.js +116 -0
- package/dist/modes/interactive/theme/dark.json +86 -0
- package/dist/modes/interactive/theme/light.json +85 -0
- package/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/dist/modes/interactive/theme/theme.d.ts +101 -0
- package/dist/modes/interactive/theme/theme.js +18 -0
- package/dist/modes/print-mode.d.ts +27 -0
- package/dist/modes/print-mode.js +4 -0
- package/dist/modes/rpc/jsonl.d.ts +16 -0
- package/dist/modes/rpc/jsonl.js +3 -0
- package/dist/modes/rpc/rpc-client.d.ts +226 -0
- package/dist/modes/rpc/rpc-client.js +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts +19 -0
- package/dist/modes/rpc/rpc-mode.js +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +419 -0
- package/dist/modes/rpc/rpc-types.js +0 -0
- package/dist/package-manager-cli.d.ts +3 -0
- package/dist/package-manager-cli.js +49 -0
- package/dist/utils/ansi.d.ts +1 -0
- package/dist/utils/ansi.js +1 -0
- package/dist/utils/auto-update.d.ts +13 -0
- package/dist/utils/auto-update.js +1 -0
- package/dist/utils/changelog.d.ts +20 -0
- package/dist/utils/changelog.js +4 -0
- package/dist/utils/child-process.d.ts +14 -0
- package/dist/utils/child-process.js +1 -0
- package/dist/utils/clipboard-image.d.ts +10 -0
- package/dist/utils/clipboard-image.js +1 -0
- package/dist/utils/clipboard-native.d.ts +9 -0
- package/dist/utils/clipboard-native.js +1 -0
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.js +1 -0
- package/dist/utils/deprecation.d.ts +3 -0
- package/dist/utils/deprecation.js +1 -0
- package/dist/utils/exif-orientation.d.ts +4 -0
- package/dist/utils/exif-orientation.js +1 -0
- package/dist/utils/frontmatter.d.ts +7 -0
- package/dist/utils/frontmatter.js +4 -0
- package/dist/utils/fs-watch.d.ts +4 -0
- package/dist/utils/fs-watch.js +1 -0
- package/dist/utils/git.d.ts +25 -0
- package/dist/utils/git.js +1 -0
- package/dist/utils/html.d.ts +6 -0
- package/dist/utils/html.js +1 -0
- package/dist/utils/image-convert.d.ts +8 -0
- package/dist/utils/image-convert.js +1 -0
- package/dist/utils/image-resize-core.d.ts +29 -0
- package/dist/utils/image-resize-core.js +1 -0
- package/dist/utils/image-resize-worker.d.ts +1 -0
- package/dist/utils/image-resize-worker.js +1 -0
- package/dist/utils/image-resize.d.ts +15 -0
- package/dist/utils/image-resize.js +1 -0
- package/dist/utils/json.d.ts +2 -0
- package/dist/utils/json.js +1 -0
- package/dist/utils/koda-user-agent.d.ts +1 -0
- package/dist/utils/koda-user-agent.js +1 -0
- package/dist/utils/mime.d.ts +2 -0
- package/dist/utils/mime.js +1 -0
- package/dist/utils/paths.d.ts +30 -0
- package/dist/utils/paths.js +1 -0
- package/dist/utils/photon.d.ts +20 -0
- package/dist/utils/photon.js +1 -0
- package/dist/utils/shell.d.ts +29 -0
- package/dist/utils/shell.js +8 -0
- package/dist/utils/sleep.d.ts +4 -0
- package/dist/utils/sleep.js +1 -0
- package/dist/utils/syntax-highlight.d.ts +11 -0
- package/dist/utils/syntax-highlight.js +2 -0
- package/dist/utils/tools-manager.d.ts +2 -0
- package/dist/utils/tools-manager.js +1 -0
- package/dist/utils/version-check.d.ts +14 -0
- package/dist/utils/version-check.js +1 -0
- package/dist/utils/windows-self-update.d.ts +2 -0
- package/dist/utils/windows-self-update.js +1 -0
- package/docs/compaction.md +394 -0
- package/docs/custom-provider.md +736 -0
- package/docs/development.md +71 -0
- package/docs/docs.json +148 -0
- package/docs/extensions.md +2626 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/exy.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/index.md +80 -0
- package/docs/json.md +82 -0
- package/docs/keybindings.md +197 -0
- package/docs/models.md +493 -0
- package/docs/packages.md +226 -0
- package/docs/prompt-templates.md +88 -0
- package/docs/providers.md +253 -0
- package/docs/quickstart.md +165 -0
- package/docs/rpc.md +1408 -0
- package/docs/sdk.md +1137 -0
- package/docs/session-format.md +412 -0
- package/docs/sessions.md +145 -0
- package/docs/settings.md +281 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +231 -0
- package/docs/terminal-setup.md +114 -0
- package/docs/termux.md +127 -0
- package/docs/themes.md +295 -0
- package/docs/tmux.md +61 -0
- package/docs/tui.md +927 -0
- package/docs/usage.md +288 -0
- package/docs/windows.md +17 -0
- package/npm-shrinkwrap.json +1792 -0
- package/openadapter/extensions/koda-ask.js +12 -0
- package/openadapter/extensions/koda-bg.js +14 -0
- package/openadapter/extensions/koda-commands.mjs +15 -0
- package/openadapter/extensions/koda-help.js +8 -0
- package/openadapter/extensions/koda-memory.js +16 -0
- package/openadapter/extensions/koda-status.js +1 -0
- package/openadapter/extensions/koda-todo.js +4 -0
- package/openadapter/extensions/koda-vision.js +4 -0
- package/openadapter/extensions/koda-web.js +7 -0
- package/openadapter/setup.mjs +173 -0
- package/openadapter/skills/code-review/SKILL.md +22 -0
- package/openadapter/skills/debugging/SKILL.md +28 -0
- package/openadapter/skills/frontend/SKILL.md +38 -0
- package/package.json +108 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var J=Object.defineProperty;var d=(r,s)=>J(r,"name",{value:s,configurable:!0});import{createInterface as Q}from"node:readline";import{Text as H}from"@openadapter/koda-tui";import{spawn as V}from"child_process";import N from"path";import{Type as O}from"typebox";import{keyHint as Z}from"../../modes/interactive/components/keybinding-hints.js";import{ensureTool as tt}from"../../utils/tools-manager.js";import{pathExists as et,resolveToCwd as nt}from"./path-utils.js";import{getTextOutput as rt,invalidArgText as it,shortenPath as ot,str as j}from"./render-utils.js";import{wrapToolDefinition as st}from"./tool-definition-wrapper.js";import{DEFAULT_MAX_BYTES as F,formatSize as W,truncateHead as q}from"./truncate.js";function M(r){return r.split(N.sep).join("/")}d(M,"toPosixPath");const at=O.Object({pattern:O.String({description:"Glob pattern to match files, e.g. '*.ts', '**/*.json', or 'src/**/*.spec.ts'"}),path:O.Optional(O.String({description:"Directory to search in (default: current directory)"})),limit:O.Optional(O.Number({description:"Maximum number of results (default: 1000)"}))}),K=1e3,lt={exists:et,glob:d(()=>[],"glob")};function ut(r,s){const f=j(r?.pattern),p=j(r?.path),e=p!==null?ot(p||"."):null,l=r?.limit,a=it(s);let t=s.fg("toolTitle",s.bold("find"))+" "+(f===null?a:s.fg("accent",f||""))+s.fg("toolOutput",` in ${e===null?a:e}`);return l!==void 0&&(t+=s.fg("toolOutput",` (limit ${l})`)),t}d(ut,"formatFindCall");function ct(r,s,f,p){const e=rt(r,p).trim();let l="";if(e){const h=e.split(`
|
|
2
|
+
`),R=s.expanded?h.length:20,w=h.slice(0,R),i=h.length-R;l+=`
|
|
3
|
+
${w.map(S=>f.fg("toolOutput",S)).join(`
|
|
4
|
+
`)}`,i>0&&(l+=`${f.fg("muted",`
|
|
5
|
+
... (${i} more lines,`)} ${Z("app.tools.expand","to expand")})`)}const a=r.details?.resultLimitReached,t=r.details?.truncation;if(a||t?.truncated){const h=[];a&&h.push(`${a} results limit`),t?.truncated&&h.push(`${W(t.maxBytes??F)} limit`),l+=`
|
|
6
|
+
${f.fg("warning",`[Truncated: ${h.join(", ")}]`)}`}return l}d(ct,"formatFindResult");function dt(r,s){const f=s?.operations;return{name:"find",label:"find",description:`Search for files by glob pattern. Returns matching file paths relative to the search directory. Respects .gitignore. Output is truncated to ${K} results or ${F/1024}KB (whichever is hit first).`,promptSnippet:"Find files by glob pattern (respects .gitignore)",parameters:at,async execute(p,{pattern:e,path:l,limit:a},t,h,R){return new Promise((w,i)=>{if(t?.aborted){i(new Error("Operation aborted"));return}let S=!1,_;const o=d(n=>{S||(S=!0,t?.removeEventListener("abort",k),_=void 0,n())},"settle"),k=d(()=>{_?.(),o(()=>i(new Error("Operation aborted")))},"onAbort");t?.addEventListener("abort",k,{once:!0}),(async()=>{try{const n=nt(l||".",r),u=a??K,D=f??lt;if(f?.glob){if(!await D.exists(n)){o(()=>i(new Error(`Path not found: ${n}`)));return}if(t?.aborted){o(()=>i(new Error("Operation aborted")));return}const c=await D.glob(e,n,{ignore:["**/node_modules/**","**/.git/**"],limit:u});if(t?.aborted){o(()=>i(new Error("Operation aborted")));return}if(c.length===0){o(()=>w({content:[{type:"text",text:"No files found matching pattern"}],details:void 0}));return}const T=c.map(g=>g.startsWith(n)?M(g.slice(n.length+1)):M(N.relative(n,g))),y=T.length>=u,C=T.join(`
|
|
7
|
+
`),L=q(C,{maxLines:Number.MAX_SAFE_INTEGER});let $=L.content;const b={},m=[];y&&(m.push(`${u} results limit reached`),b.resultLimitReached=u),L.truncated&&(m.push(`${W(F)} limit reached`),b.truncation=L),m.length>0&&($+=`
|
|
8
|
+
|
|
9
|
+
[${m.join(". ")}]`),o(()=>w({content:[{type:"text",text:$}],details:Object.keys(b).length>0?b:void 0}));return}const U=await tt("fd",!0);if(t?.aborted){o(()=>i(new Error("Operation aborted")));return}if(!U){o(()=>i(new Error("fd is not available and could not be downloaded")));return}const A=["--glob","--color=never","--hidden","--no-require-git","--max-results",String(u)];let z=e;e.includes("/")&&(A.push("--full-path"),!e.startsWith("/")&&!e.startsWith("**/")&&e!=="**"&&(z=`**/${e}`)),A.push("--",z,n);const E=V(U,A,{stdio:["ignore","pipe","pipe"]}),B=Q({input:E.stdout});let G="";const P=[];_=d(()=>{E.killed||E.kill()},"stopChild");const X=d(()=>{B.close()},"cleanup");E.stderr?.on("data",c=>{G+=c.toString()}),B.on("line",c=>{P.push(c)}),E.on("error",c=>{X(),o(()=>i(new Error(`Failed to run fd: ${c.message}`)))}),E.on("close",c=>{if(X(),t?.aborted){o(()=>i(new Error("Operation aborted")));return}const T=P.join(`
|
|
10
|
+
`);if(c!==0){const I=G.trim()||`fd exited with code ${c}`;if(!T){o(()=>i(new Error(I)));return}}if(!T){o(()=>w({content:[{type:"text",text:"No files found matching pattern"}],details:void 0}));return}const y=[];for(const I of P){const x=I.replace(/\r$/,"").trim();if(!x)continue;const Y=x.endsWith("/")||x.endsWith("\\");let v=x;x.startsWith(n)?v=x.slice(n.length+1):v=N.relative(n,x),Y&&!v.endsWith("/")&&(v+="/"),y.push(M(v))}const C=y.length>=u,L=y.join(`
|
|
11
|
+
`),$=q(L,{maxLines:Number.MAX_SAFE_INTEGER});let b=$.content;const m={},g=[];C&&(g.push(`${u} results limit reached. Use limit=${u*2} for more, or refine pattern`),m.resultLimitReached=u),$.truncated&&(g.push(`${W(F)} limit reached`),m.truncation=$),g.length>0&&(b+=`
|
|
12
|
+
|
|
13
|
+
[${g.join(". ")}]`),o(()=>w({content:[{type:"text",text:b}],details:Object.keys(m).length>0?m:void 0}))})}catch(n){if(t?.aborted){o(()=>i(new Error("Operation aborted")));return}const u=n instanceof Error?n:new Error(String(n));o(()=>i(u))}})()})},renderCall(p,e,l){const a=l.lastComponent??new H("",0,0);return a.setText(ut(p,e)),a},renderResult(p,e,l,a){const t=a.lastComponent??new H("",0,0);return t.setText(ct(p,e,l,a.showImages)),t}}}d(dt,"createFindToolDefinition");function yt(r,s){return st(dt(r,s))}d(yt,"createFindTool");export{yt as createFindTool,dt as createFindToolDefinition};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AgentTool } from "@openadapter/koda-agent-core";
|
|
2
|
+
import { type Static, Type } from "typebox";
|
|
3
|
+
import type { ToolDefinition } from "../extensions/types.ts";
|
|
4
|
+
import { type TruncationResult } from "./truncate.ts";
|
|
5
|
+
declare const grepSchema: Type.TObject<{
|
|
6
|
+
pattern: Type.TString;
|
|
7
|
+
path: Type.TOptional<Type.TString>;
|
|
8
|
+
glob: Type.TOptional<Type.TString>;
|
|
9
|
+
ignoreCase: Type.TOptional<Type.TBoolean>;
|
|
10
|
+
literal: Type.TOptional<Type.TBoolean>;
|
|
11
|
+
context: Type.TOptional<Type.TNumber>;
|
|
12
|
+
limit: Type.TOptional<Type.TNumber>;
|
|
13
|
+
}>;
|
|
14
|
+
export type GrepToolInput = Static<typeof grepSchema>;
|
|
15
|
+
export interface GrepToolDetails {
|
|
16
|
+
truncation?: TruncationResult;
|
|
17
|
+
matchLimitReached?: number;
|
|
18
|
+
linesTruncated?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Pluggable operations for the grep tool.
|
|
22
|
+
* Override these to delegate search to remote systems (for example SSH).
|
|
23
|
+
*/
|
|
24
|
+
export interface GrepOperations {
|
|
25
|
+
/** Check if path is a directory. Throws if path does not exist. */
|
|
26
|
+
isDirectory: (absolutePath: string) => Promise<boolean> | boolean;
|
|
27
|
+
/** Read file contents for context lines */
|
|
28
|
+
readFile: (absolutePath: string) => Promise<string> | string;
|
|
29
|
+
}
|
|
30
|
+
export interface GrepToolOptions {
|
|
31
|
+
/** Custom operations for grep. Default: local filesystem plus ripgrep */
|
|
32
|
+
operations?: GrepOperations;
|
|
33
|
+
}
|
|
34
|
+
export declare function createGrepToolDefinition(cwd: string, options?: GrepToolOptions): ToolDefinition<typeof grepSchema, GrepToolDetails | undefined>;
|
|
35
|
+
export declare function createGrepTool(cwd: string, options?: GrepToolOptions): AgentTool<typeof grepSchema>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var ut=Object.defineProperty;var o=(n,r)=>ut(n,"name",{value:r,configurable:!0});import{readFile as ft,stat as dt}from"node:fs/promises";import{createInterface as mt}from"node:readline";import{Text as nt}from"@openadapter/koda-tui";import{spawn as ht}from"child_process";import rt from"path";import{Type as a}from"typebox";import{keyHint as gt}from"../../modes/interactive/components/keybinding-hints.js";import{ensureTool as xt}from"../../utils/tools-manager.js";import{resolveToCwd as $t}from"./path-utils.js";import{getTextOutput as Tt,invalidArgText as wt,shortenPath as bt,str as k}from"./render-utils.js";import{wrapToolDefinition as yt}from"./tool-definition-wrapper.js";import{DEFAULT_MAX_BYTES as G,formatSize as it,GREP_MAX_LINE_LENGTH as ot,truncateHead as Lt,truncateLine as at}from"./truncate.js";const Ot=a.Object({pattern:a.String({description:"Search pattern (regex or literal string)"}),path:a.Optional(a.String({description:"Directory or file to search (default: current directory)"})),glob:a.Optional(a.String({description:"Filter files by glob pattern, e.g. '*.ts' or '**/*.spec.ts'"})),ignoreCase:a.Optional(a.Boolean({description:"Case-insensitive search (default: false)"})),literal:a.Optional(a.Boolean({description:"Treat pattern as literal string instead of regex (default: false)"})),context:a.Optional(a.Number({description:"Number of lines to show before and after each match (default: 0)"})),limit:a.Optional(a.Number({description:"Maximum number of matches to return (default: 100)"}))}),st=100,Et={isDirectory:o(async n=>(await dt(n)).isDirectory(),"isDirectory"),readFile:o(n=>ft(n,"utf-8"),"readFile")};function vt(n,r){const x=k(n?.pattern),h=k(n?.path),l=h!==null?bt(h||"."):null,s=k(n?.glob),i=n?.limit,p=wt(r);let $=r.fg("toolTitle",r.bold("grep"))+" "+(x===null?p:r.fg("accent",`/${x||""}/`))+r.fg("toolOutput",` in ${l===null?p:l}`);return s&&($+=r.fg("toolOutput",` (${s})`)),i!==void 0&&($+=r.fg("toolOutput",` limit ${i}`)),$}o(vt,"formatGrepCall");function St(n,r,x,h){const l=Tt(n,h).trim();let s="";if(l){const c=l.split(`
|
|
2
|
+
`),_=r.expanded?c.length:15,O=c.slice(0,_),D=c.length-_;s+=`
|
|
3
|
+
${O.map(I=>x.fg("toolOutput",I)).join(`
|
|
4
|
+
`)}`,D>0&&(s+=`${x.fg("muted",`
|
|
5
|
+
... (${D} more lines,`)} ${gt("app.tools.expand","to expand")})`)}const i=n.details?.matchLimitReached,p=n.details?.truncation,$=n.details?.linesTruncated;if(i||p?.truncated||$){const c=[];i&&c.push(`${i} matches limit`),p?.truncated&&c.push(`${it(p.maxBytes??G)} limit`),$&&c.push("some lines truncated"),s+=`
|
|
6
|
+
${x.fg("warning",`[Truncated: ${c.join(", ")}]`)}`}return s}o(St,"formatGrepResult");function _t(n,r){const x=r?.operations;return{name:"grep",label:"grep",description:`Search file contents for a pattern. Returns matching lines with file paths and line numbers. Respects .gitignore. Output is truncated to ${st} matches or ${G/1024}KB (whichever is hit first). Long lines are truncated to ${ot} chars.`,promptSnippet:"Search file contents for patterns (respects .gitignore)",parameters:Ot,async execute(h,{pattern:l,path:s,glob:i,ignoreCase:p,literal:$,context:c,limit:_},O,D,I){return new Promise((N,w)=>{if(O?.aborted){w(new Error("Operation aborted"));return}let B=!1;const T=o(y=>{B||(B=!0,y())},"settle");(async()=>{try{const y=await xt("rg",!0);if(!y){T(()=>w(new Error("ripgrep (rg) is not available and could not be downloaded")));return}const C=$t(s||".",n),U=x??Et;let z;try{z=await U.isDirectory(C)}catch{T(()=>w(new Error(`Path not found: ${C}`)));return}const E=c&&c>0?c:0,v=Math.max(1,_??st),H=o(e=>{if(z){const t=rt.relative(C,e);if(t&&!t.startsWith(".."))return t.replace(/\\/g,"/")}return rt.basename(e)},"formatPath"),X=new Map,ct=o(async e=>{let t=X.get(e);if(!t){try{t=(await U.readFile(e)).replace(/\r\n/g,`
|
|
7
|
+
`).replace(/\r/g,`
|
|
8
|
+
`).split(`
|
|
9
|
+
`)}catch{t=[]}X.set(e,t)}return t},"getFileLines"),S=["--json","--line-number","--color=never","--hidden"];p&&S.push("--ignore-case"),$&&S.push("--fixed-strings"),i&&S.push("--glob",i),S.push("--",l,C);const L=ht(y,S,{stdio:["ignore","pipe","pipe"]}),j=mt({input:L.stdout});let J="",M=0,K=!1,F=!1,V=!1,W=!1;const R=[],Y=o(()=>{j.close(),O?.removeEventListener("abort",Q)},"cleanup"),q=o((e=!1)=>{L.killed||(W=e,L.kill())},"stopChild"),Q=o(()=>{V=!0,q()},"onAbort");O?.addEventListener("abort",Q,{once:!0}),L.stderr?.on("data",e=>{J+=e.toString()});const lt=o(async(e,t)=>{const u=H(e),g=await ct(e);if(!g.length)return[`${u}:${t}: (unable to read file)`];const f=[],b=E>0?Math.max(1,t-E):t,d=E>0?Math.min(g.length,t+E):t;for(let m=b;m<=d;m++){const A=(g[m-1]??"").replace(/\r/g,""),P=m===t,{text:et,wasTruncated:pt}=at(A);pt&&(F=!0),P?f.push(`${u}:${m}: ${et}`):f.push(`${u}-${m}- ${et}`)}return f},"formatBlock"),Z=[];j.on("line",e=>{if(!e.trim()||M>=v)return;let t;try{t=JSON.parse(e)}catch{return}if(t.type==="match"){M++;const u=t.data?.path?.text,g=t.data?.line_number,f=t.data?.lines?.text;u&&typeof g=="number"&&Z.push({filePath:u,lineNumber:g,lineText:f}),M>=v&&(K=!0,q(!0))}}),L.on("error",e=>{Y(),T(()=>w(new Error(`Failed to run ripgrep: ${e.message}`)))}),L.on("close",async e=>{if(Y(),V){T(()=>w(new Error("Operation aborted")));return}if(!W&&e!==0&&e!==1){const d=J.trim()||`ripgrep exited with code ${e}`;T(()=>w(new Error(d)));return}if(M===0){T(()=>N({content:[{type:"text",text:"No matches found"}],details:void 0}));return}for(const d of Z)if(E===0&&d.lineText!==void 0){const m=H(d.filePath),tt=d.lineText.replace(/\r\n/g,`
|
|
10
|
+
`).replace(/\r/g,"").replace(/\n$/,""),{text:A,wasTruncated:P}=at(tt);P&&(F=!0),R.push(`${m}:${d.lineNumber}: ${A}`)}else{const m=await lt(d.filePath,d.lineNumber);R.push(...m)}const t=R.join(`
|
|
11
|
+
`),u=Lt(t,{maxLines:Number.MAX_SAFE_INTEGER});let g=u.content;const f={},b=[];K&&(b.push(`${v} matches limit reached. Use limit=${v*2} for more, or refine pattern`),f.matchLimitReached=v),u.truncated&&(b.push(`${it(G)} limit reached`),f.truncation=u),F&&(b.push(`Some lines truncated to ${ot} chars. Use read tool to see full lines`),f.linesTruncated=!0),b.length>0&&(g+=`
|
|
12
|
+
|
|
13
|
+
[${b.join(". ")}]`),T(()=>N({content:[{type:"text",text:g}],details:Object.keys(f).length>0?f:void 0}))})}catch(y){T(()=>w(y))}})()})},renderCall(h,l,s){const i=s.lastComponent??new nt("",0,0);return i.setText(vt(h,l)),i},renderResult(h,l,s,i){const p=i.lastComponent??new nt("",0,0);return p.setText(St(h,l,s,i.showImages)),p}}}o(_t,"createGrepToolDefinition");function zt(n,r){return yt(_t(n,r))}o(zt,"createGrepTool");export{zt as createGrepTool,_t as createGrepToolDefinition};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export { type BashOperations, type BashSpawnContext, type BashSpawnHook, type BashToolDetails, type BashToolInput, type BashToolOptions, createBashTool, createBashToolDefinition, createLocalBashOperations, } from "./bash.ts";
|
|
2
|
+
export { createEditTool, createEditToolDefinition, type EditOperations, type EditToolDetails, type EditToolInput, type EditToolOptions, } from "./edit.ts";
|
|
3
|
+
export { withFileMutationQueue } from "./file-mutation-queue.ts";
|
|
4
|
+
export { createFindTool, createFindToolDefinition, type FindOperations, type FindToolDetails, type FindToolInput, type FindToolOptions, } from "./find.ts";
|
|
5
|
+
export { createGrepTool, createGrepToolDefinition, type GrepOperations, type GrepToolDetails, type GrepToolInput, type GrepToolOptions, } from "./grep.ts";
|
|
6
|
+
export { createLsTool, createLsToolDefinition, type LsOperations, type LsToolDetails, type LsToolInput, type LsToolOptions, } from "./ls.ts";
|
|
7
|
+
export { createReadTool, createReadToolDefinition, type ReadOperations, type ReadToolDetails, type ReadToolInput, type ReadToolOptions, } from "./read.ts";
|
|
8
|
+
export { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationOptions, type TruncationResult, truncateHead, truncateLine, truncateTail, } from "./truncate.ts";
|
|
9
|
+
export { createWriteTool, createWriteToolDefinition, type WriteOperations, type WriteToolInput, type WriteToolOptions, } from "./write.ts";
|
|
10
|
+
import type { AgentTool } from "@openadapter/koda-agent-core";
|
|
11
|
+
import type { ToolDefinition } from "../extensions/types.ts";
|
|
12
|
+
import { type BashToolOptions } from "./bash.ts";
|
|
13
|
+
import { type EditToolOptions } from "./edit.ts";
|
|
14
|
+
import { type FindToolOptions } from "./find.ts";
|
|
15
|
+
import { type GrepToolOptions } from "./grep.ts";
|
|
16
|
+
import { type LsToolOptions } from "./ls.ts";
|
|
17
|
+
import { type ReadToolOptions } from "./read.ts";
|
|
18
|
+
import { type WriteToolOptions } from "./write.ts";
|
|
19
|
+
export type Tool = AgentTool<any>;
|
|
20
|
+
export type ToolDef = ToolDefinition<any, any>;
|
|
21
|
+
export type ToolName = "read" | "bash" | "edit" | "write" | "grep" | "find" | "ls";
|
|
22
|
+
export declare const allToolNames: Set<ToolName>;
|
|
23
|
+
export interface ToolsOptions {
|
|
24
|
+
read?: ReadToolOptions;
|
|
25
|
+
bash?: BashToolOptions;
|
|
26
|
+
write?: WriteToolOptions;
|
|
27
|
+
edit?: EditToolOptions;
|
|
28
|
+
grep?: GrepToolOptions;
|
|
29
|
+
find?: FindToolOptions;
|
|
30
|
+
ls?: LsToolOptions;
|
|
31
|
+
}
|
|
32
|
+
export declare function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef;
|
|
33
|
+
export declare function createTool(toolName: ToolName, cwd: string, options?: ToolsOptions): Tool;
|
|
34
|
+
export declare function createCodingToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[];
|
|
35
|
+
export declare function createReadOnlyToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[];
|
|
36
|
+
export declare function createAllToolDefinitions(cwd: string, options?: ToolsOptions): Record<ToolName, ToolDef>;
|
|
37
|
+
export declare function createCodingTools(cwd: string, options?: ToolsOptions): Tool[];
|
|
38
|
+
export declare function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[];
|
|
39
|
+
export declare function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var g=Object.defineProperty;var a=(r,e)=>g(r,"name",{value:e,configurable:!0});import{createBashTool as $,createBashToolDefinition as z,createLocalBashOperations as H}from"./bash.js";import{createEditTool as Q,createEditToolDefinition as Y}from"./edit.js";import{withFileMutationQueue as q}from"./file-mutation-queue.js";import{createFindTool as J,createFindToolDefinition as K}from"./find.js";import{createGrepTool as P,createGrepToolDefinition as V}from"./grep.js";import{createLsTool as w,createLsToolDefinition as ee}from"./ls.js";import{createReadTool as te,createReadToolDefinition as ae}from"./read.js";import{DEFAULT_MAX_BYTES as oe,DEFAULT_MAX_LINES as ne,formatSize as le,truncateHead as fe,truncateLine as Te,truncateTail as ue}from"./truncate.js";import{createWriteTool as me,createWriteToolDefinition as he}from"./write.js";import{createBashTool as n,createBashToolDefinition as l}from"./bash.js";import{createEditTool as f,createEditToolDefinition as T}from"./edit.js";import{createFindTool as u,createFindToolDefinition as c}from"./find.js";import{createGrepTool as m,createGrepToolDefinition as h}from"./grep.js";import{createLsTool as s,createLsToolDefinition as D}from"./ls.js";import{createReadTool as i,createReadToolDefinition as o}from"./read.js";import{createWriteTool as d,createWriteToolDefinition as x}from"./write.js";const G=new Set(["read","bash","edit","write","grep","find","ls"]);function S(r,e,t){switch(r){case"read":return o(e,t?.read);case"bash":return l(e,t?.bash);case"edit":return T(e,t?.edit);case"write":return x(e,t?.write);case"grep":return h(e,t?.grep);case"find":return c(e,t?.find);case"ls":return D(e,t?.ls);default:throw new Error(`Unknown tool name: ${r}`)}}a(S,"createToolDefinition");function U(r,e,t){switch(r){case"read":return i(e,t?.read);case"bash":return n(e,t?.bash);case"edit":return f(e,t?.edit);case"write":return d(e,t?.write);case"grep":return m(e,t?.grep);case"find":return u(e,t?.find);case"ls":return s(e,t?.ls);default:throw new Error(`Unknown tool name: ${r}`)}}a(U,"createTool");function W(r,e){return[o(r,e?.read),l(r,e?.bash),T(r,e?.edit),x(r,e?.write)]}a(W,"createCodingToolDefinitions");function _(r,e){return[o(r,e?.read),h(r,e?.grep),c(r,e?.find),D(r,e?.ls)]}a(_,"createReadOnlyToolDefinitions");function M(r,e){return{read:o(r,e?.read),bash:l(r,e?.bash),edit:T(r,e?.edit),write:x(r,e?.write),grep:h(r,e?.grep),find:c(r,e?.find),ls:D(r,e?.ls)}}a(M,"createAllToolDefinitions");function O(r,e){return[i(r,e?.read),n(r,e?.bash),f(r,e?.edit),d(r,e?.write)]}a(O,"createCodingTools");function k(r,e){return[i(r,e?.read),m(r,e?.grep),u(r,e?.find),s(r,e?.ls)]}a(k,"createReadOnlyTools");function y(r,e){return{read:i(r,e?.read),bash:n(r,e?.bash),edit:f(r,e?.edit),write:d(r,e?.write),grep:m(r,e?.grep),find:u(r,e?.find),ls:s(r,e?.ls)}}a(y,"createAllTools");export{oe as DEFAULT_MAX_BYTES,ne as DEFAULT_MAX_LINES,G as allToolNames,M as createAllToolDefinitions,y as createAllTools,$ as createBashTool,z as createBashToolDefinition,W as createCodingToolDefinitions,O as createCodingTools,Q as createEditTool,Y as createEditToolDefinition,J as createFindTool,K as createFindToolDefinition,P as createGrepTool,V as createGrepToolDefinition,H as createLocalBashOperations,w as createLsTool,ee as createLsToolDefinition,_ as createReadOnlyToolDefinitions,k as createReadOnlyTools,te as createReadTool,ae as createReadToolDefinition,U as createTool,S as createToolDefinition,me as createWriteTool,he as createWriteToolDefinition,le as formatSize,fe as truncateHead,Te as truncateLine,ue as truncateTail,q as withFileMutationQueue};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AgentTool } from "@openadapter/koda-agent-core";
|
|
2
|
+
import { type Static, Type } from "typebox";
|
|
3
|
+
import type { ToolDefinition } from "../extensions/types.ts";
|
|
4
|
+
import { type TruncationResult } from "./truncate.ts";
|
|
5
|
+
declare const lsSchema: Type.TObject<{
|
|
6
|
+
path: Type.TOptional<Type.TString>;
|
|
7
|
+
limit: Type.TOptional<Type.TNumber>;
|
|
8
|
+
}>;
|
|
9
|
+
export type LsToolInput = Static<typeof lsSchema>;
|
|
10
|
+
export interface LsToolDetails {
|
|
11
|
+
truncation?: TruncationResult;
|
|
12
|
+
entryLimitReached?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Pluggable operations for the ls tool.
|
|
16
|
+
* Override these to delegate directory listing to remote systems (for example SSH).
|
|
17
|
+
*/
|
|
18
|
+
export interface LsOperations {
|
|
19
|
+
/** Check if path exists */
|
|
20
|
+
exists: (absolutePath: string) => Promise<boolean> | boolean;
|
|
21
|
+
/** Get file or directory stats. Throws if not found. */
|
|
22
|
+
stat: (absolutePath: string) => Promise<{
|
|
23
|
+
isDirectory: () => boolean;
|
|
24
|
+
}> | {
|
|
25
|
+
isDirectory: () => boolean;
|
|
26
|
+
};
|
|
27
|
+
/** Read directory entries */
|
|
28
|
+
readdir: (absolutePath: string) => Promise<string[]> | string[];
|
|
29
|
+
}
|
|
30
|
+
export interface LsToolOptions {
|
|
31
|
+
/** Custom operations for directory listing. Default: local filesystem */
|
|
32
|
+
operations?: LsOperations;
|
|
33
|
+
}
|
|
34
|
+
export declare function createLsToolDefinition(cwd: string, options?: LsToolOptions): ToolDefinition<typeof lsSchema, LsToolDetails | undefined>;
|
|
35
|
+
export declare function createLsTool(cwd: string, options?: LsToolOptions): AgentTool<typeof lsSchema>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var v=Object.defineProperty;var p=(n,r)=>v(n,"name",{value:r,configurable:!0});import{readdir as A,stat as I}from"node:fs/promises";import{Text as S}from"@openadapter/koda-tui";import P from"path";import{Type as y}from"typebox";import{keyHint as k}from"../../modes/interactive/components/keybinding-hints.js";import{pathExists as F,resolveToCwd as M}from"./path-utils.js";import{getTextOutput as N,renderToolPath as U,str as B}from"./render-utils.js";import{wrapToolDefinition as j}from"./tool-definition-wrapper.js";import{DEFAULT_MAX_BYTES as E,formatSize as D,truncateHead as H}from"./truncate.js";const X=y.Object({path:y.Optional(y.String({description:"Directory to list (default: current directory)"})),limit:y.Optional(y.Number({description:"Maximum number of entries to return (default: 500)"}))}),R=500,z={exists:F,stat:I,readdir:A};function G(n,r,o){const a=n?.limit,i=U(B(n?.path),r,o,{emptyFallback:"."});let t=`${r.fg("toolTitle",r.bold("ls"))} ${i}`;return a!==void 0&&(t+=r.fg("toolOutput",` (limit ${a})`)),t}p(G,"formatLsCall");function K(n,r,o,a){const i=N(n,a).trim();let t="";if(i){const c=i.split(`
|
|
2
|
+
`),m=r.expanded?c.length:20,l=c.slice(0,m),u=c.length-m;t+=`
|
|
3
|
+
${l.map(s=>o.fg("toolOutput",s)).join(`
|
|
4
|
+
`)}`,u>0&&(t+=`${o.fg("muted",`
|
|
5
|
+
... (${u} more lines,`)} ${k("app.tools.expand","to expand")})`)}const e=n.details?.entryLimitReached,d=n.details?.truncation;if(e||d?.truncated){const c=[];e&&c.push(`${e} entries limit`),d?.truncated&&c.push(`${D(d.maxBytes??E)} limit`),t+=`
|
|
6
|
+
${o.fg("warning",`[Truncated: ${c.join(", ")}]`)}`}return t}p(K,"formatLsResult");function Y(n,r){const o=r?.operations??z;return{name:"ls",label:"ls",description:`List directory contents. Returns entries sorted alphabetically, with '/' suffix for directories. Includes dotfiles. Output is truncated to ${R} entries or ${E/1024}KB (whichever is hit first).`,promptSnippet:"List directory contents",parameters:X,async execute(a,{path:i,limit:t},e,d,c){return new Promise((m,l)=>{if(e?.aborted){l(new Error("Operation aborted"));return}const u=p(()=>l(new Error("Operation aborted")),"onAbort");e?.addEventListener("abort",u,{once:!0}),(async()=>{try{const s=M(i||".",n),h=t??R;if(!await o.exists(s)){l(new Error(`Path not found: ${s}`));return}if(!(await o.stat(s)).isDirectory()){l(new Error(`Not a directory: ${s}`));return}let $;try{$=await o.readdir(s)}catch(f){l(new Error(`Cannot read directory: ${f.message}`));return}$.sort((f,T)=>f.toLowerCase().localeCompare(T.toLowerCase()));const x=[];let g=!1;for(const f of $){if(x.length>=h){g=!0;break}const T=P.join(s,f);let C="";try{(await o.stat(T)).isDirectory()&&(C="/")}catch{continue}x.push(f+C)}if(e?.removeEventListener("abort",u),x.length===0){m({content:[{type:"text",text:"(empty directory)"}],details:void 0});return}const _=x.join(`
|
|
7
|
+
`),b=H(_,{maxLines:Number.MAX_SAFE_INTEGER});let O=b.content;const w={},L=[];g&&(L.push(`${h} entries limit reached. Use limit=${h*2} for more`),w.entryLimitReached=h),b.truncated&&(L.push(`${D(E)} limit reached`),w.truncation=b),L.length>0&&(O+=`
|
|
8
|
+
|
|
9
|
+
[${L.join(". ")}]`),m({content:[{type:"text",text:O}],details:Object.keys(w).length>0?w:void 0})}catch(s){e?.removeEventListener("abort",u),l(s)}})()})},renderCall(a,i,t){const e=t.lastComponent??new S("",0,0);return e.setText(G(a,i,t.cwd)),e},renderResult(a,i,t,e){const d=e.lastComponent??new S("",0,0);return d.setText(K(a,i,t,e.showImages)),d}}}p(Y,"createLsToolDefinition");function st(n,r){return j(Y(n,r))}p(st,"createLsTool");export{st as createLsTool,Y as createLsToolDefinition};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type TruncationResult } from "./truncate.ts";
|
|
2
|
+
export interface OutputAccumulatorOptions {
|
|
3
|
+
maxLines?: number;
|
|
4
|
+
maxBytes?: number;
|
|
5
|
+
tempFilePrefix?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface OutputSnapshot {
|
|
8
|
+
content: string;
|
|
9
|
+
truncation: TruncationResult;
|
|
10
|
+
fullOutputPath?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Incrementally tracks streaming output with bounded memory.
|
|
14
|
+
*
|
|
15
|
+
* Appends decode chunks with a streaming UTF-8 decoder, keeps only a decoded
|
|
16
|
+
* tail for display snapshots, and opens a temp file when the full output needs
|
|
17
|
+
* to be preserved.
|
|
18
|
+
*/
|
|
19
|
+
export declare class OutputAccumulator {
|
|
20
|
+
private readonly maxLines;
|
|
21
|
+
private readonly maxBytes;
|
|
22
|
+
private readonly maxRollingBytes;
|
|
23
|
+
private readonly tempFilePrefix;
|
|
24
|
+
private readonly decoder;
|
|
25
|
+
private rawChunks;
|
|
26
|
+
private tailText;
|
|
27
|
+
private tailBytes;
|
|
28
|
+
private tailStartsAtLineBoundary;
|
|
29
|
+
private totalRawBytes;
|
|
30
|
+
private totalDecodedBytes;
|
|
31
|
+
private completedLines;
|
|
32
|
+
private totalLines;
|
|
33
|
+
private currentLineBytes;
|
|
34
|
+
private hasOpenLine;
|
|
35
|
+
private finished;
|
|
36
|
+
private tempFilePath;
|
|
37
|
+
private tempFileStream;
|
|
38
|
+
constructor(options?: OutputAccumulatorOptions);
|
|
39
|
+
append(data: Buffer): void;
|
|
40
|
+
finish(): void;
|
|
41
|
+
snapshot(options?: {
|
|
42
|
+
persistIfTruncated?: boolean;
|
|
43
|
+
}): OutputSnapshot;
|
|
44
|
+
closeTempFile(): Promise<void>;
|
|
45
|
+
getLastLineBytes(): number;
|
|
46
|
+
private appendDecodedText;
|
|
47
|
+
private trimTail;
|
|
48
|
+
private getSnapshotText;
|
|
49
|
+
private shouldUseTempFile;
|
|
50
|
+
private ensureTempFile;
|
|
51
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var o=Object.defineProperty;var r=(a,t)=>o(a,"name",{value:t,configurable:!0});import{randomBytes as m}from"node:crypto";import{createWriteStream as u}from"node:fs";import{tmpdir as c}from"node:os";import{join as d}from"node:path";import{DEFAULT_MAX_BYTES as f,DEFAULT_MAX_LINES as p,truncateTail as y}from"./truncate.js";function x(a){const t=m(8).toString("hex");return d(c(),`${a}-${t}.log`)}r(x,"defaultTempFilePath");function h(a){return Buffer.byteLength(a,"utf-8")}r(h,"byteLength");class w{static{r(this,"OutputAccumulator")}maxLines;maxBytes;maxRollingBytes;tempFilePrefix;decoder=new TextDecoder;rawChunks=[];tailText="";tailBytes=0;tailStartsAtLineBoundary=!0;totalRawBytes=0;totalDecodedBytes=0;completedLines=0;totalLines=0;currentLineBytes=0;hasOpenLine=!1;finished=!1;tempFilePath;tempFileStream;constructor(t={}){this.maxLines=t.maxLines??p,this.maxBytes=t.maxBytes??f,this.maxRollingBytes=Math.max(this.maxBytes*2,1),this.tempFilePrefix=t.tempFilePrefix??"koda-output"}append(t){if(this.finished)throw new Error("Cannot append to a finished output accumulator");this.totalRawBytes+=t.length,this.appendDecodedText(this.decoder.decode(t,{stream:!0})),this.tempFileStream||this.shouldUseTempFile()?(this.ensureTempFile(),this.tempFileStream?.write(t)):t.length>0&&this.rawChunks.push(t)}finish(){this.finished||(this.finished=!0,this.appendDecodedText(this.decoder.decode()),this.shouldUseTempFile()&&this.ensureTempFile())}snapshot(t={}){const e=y(this.getSnapshotText(),{maxLines:this.maxLines,maxBytes:this.maxBytes}),s=this.totalLines>this.maxLines||this.totalDecodedBytes>this.maxBytes,n=s?e.truncatedBy??(this.totalDecodedBytes>this.maxBytes?"bytes":"lines"):null,i={...e,truncated:s,truncatedBy:n,totalLines:this.totalLines,totalBytes:this.totalDecodedBytes,maxLines:this.maxLines,maxBytes:this.maxBytes};return t.persistIfTruncated&&i.truncated&&this.ensureTempFile(),{content:i.content,truncation:i,fullOutputPath:this.tempFilePath}}async closeTempFile(){if(!this.tempFileStream)return;const t=this.tempFileStream;this.tempFileStream=void 0,await new Promise((e,s)=>{const n=r(l=>{t.off("finish",i),s(l)},"onError"),i=r(()=>{t.off("error",n),e()},"onFinish");t.once("error",n),t.once("finish",i),t.end()})}getLastLineBytes(){return this.currentLineBytes}appendDecodedText(t){if(t.length===0)return;const e=h(t);this.totalDecodedBytes+=e,this.tailText+=t,this.tailBytes+=e,this.tailBytes>this.maxRollingBytes*2&&this.trimTail();let s=0,n=-1;for(let i=t.indexOf(`
|
|
2
|
+
`);i!==-1;i=t.indexOf(`
|
|
3
|
+
`,i+1))s++,n=i;if(s===0)this.currentLineBytes+=e,this.hasOpenLine=!0;else{this.completedLines+=s;const i=t.slice(n+1);this.currentLineBytes=h(i),this.hasOpenLine=i.length>0}this.totalLines=this.completedLines+(this.hasOpenLine?1:0)}trimTail(){const t=Buffer.from(this.tailText,"utf-8");if(t.length<=this.maxRollingBytes){this.tailBytes=t.length;return}let e=t.length-this.maxRollingBytes;for(;e<t.length&&(t[e]&192)===128;)e++;this.tailStartsAtLineBoundary=e===0?this.tailStartsAtLineBoundary:t[e-1]===10,this.tailText=t.subarray(e).toString("utf-8"),this.tailBytes=h(this.tailText)}getSnapshotText(){if(this.tailStartsAtLineBoundary)return this.tailText;const t=this.tailText.indexOf(`
|
|
4
|
+
`);return t===-1?this.tailText:this.tailText.slice(t+1)}shouldUseTempFile(){return this.totalRawBytes>this.maxBytes||this.totalDecodedBytes>this.maxBytes||this.totalLines>this.maxLines}ensureTempFile(){if(!this.tempFilePath){this.tempFilePath=x(this.tempFilePrefix),this.tempFileStream=u(this.tempFilePath);for(const t of this.rawChunks)this.tempFileStream.write(t);this.rawChunks=[]}}}export{w as OutputAccumulator};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function pathExists(filePath: string): Promise<boolean>;
|
|
2
|
+
export declare function expandPath(filePath: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Resolve a path relative to the given cwd.
|
|
5
|
+
* Handles ~ expansion and absolute paths.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveToCwd(filePath: string, cwd: string): string;
|
|
8
|
+
export declare function resolveReadPath(filePath: string, cwd: string): string;
|
|
9
|
+
export declare function resolveReadPathAsync(filePath: string, cwd: string): Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var d=Object.defineProperty;var n=(t,a)=>d(t,"name",{value:a,configurable:!0});import{accessSync as P,constants as l}from"node:fs";import{access as h}from"node:fs/promises";import{normalizePath as x,resolvePath as V}from"../../utils/paths.js";const w="\u202F";function p(t){return t.replace(/ (AM|PM)\./gi,`${w}$1.`)}n(p,"tryMacOSScreenshotPath");function m(t){return t.normalize("NFD")}n(m,"tryNFDVariant");function f(t){return t.replace(/'/g,"\u2019")}n(f,"tryCurlyQuoteVariant");function c(t){try{return P(t,l.F_OK),!0}catch{return!1}}n(c,"fileExists");async function s(t){try{return await h(t,l.F_OK),!0}catch{return!1}}n(s,"pathExists");function F(t){return x(t,{normalizeUnicodeSpaces:!0,stripAtPrefix:!0})}n(F,"expandPath");function y(t,a){return V(t,a,{normalizeUnicodeSpaces:!0,stripAtPrefix:!0})}n(y,"resolveToCwd");function O(t,a){const r=y(t,a);if(c(r))return r;const i=p(r);if(i!==r&&c(i))return i;const e=m(r);if(e!==r&&c(e))return e;const o=f(r);if(o!==r&&c(o))return o;const u=f(e);return u!==r&&c(u)?u:r}n(O,"resolveReadPath");async function R(t,a){const r=y(t,a);if(await s(r))return r;const i=p(r);if(i!==r&&await s(i))return i;const e=m(r);if(e!==r&&await s(e))return e;const o=f(r);if(o!==r&&await s(o))return o;const u=f(e);return u!==r&&await s(u)?u:r}n(R,"resolveReadPathAsync");export{F as expandPath,s as pathExists,O as resolveReadPath,R as resolveReadPathAsync,y as resolveToCwd};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AgentTool } from "@openadapter/koda-agent-core";
|
|
2
|
+
import { type Static, Type } from "typebox";
|
|
3
|
+
import type { ToolDefinition } from "../extensions/types.ts";
|
|
4
|
+
import { type TruncationResult } from "./truncate.ts";
|
|
5
|
+
declare const readSchema: Type.TObject<{
|
|
6
|
+
path: Type.TString;
|
|
7
|
+
offset: Type.TOptional<Type.TNumber>;
|
|
8
|
+
limit: Type.TOptional<Type.TNumber>;
|
|
9
|
+
}>;
|
|
10
|
+
export type ReadToolInput = Static<typeof readSchema>;
|
|
11
|
+
export interface ReadToolDetails {
|
|
12
|
+
truncation?: TruncationResult;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Pluggable operations for the read tool.
|
|
16
|
+
* Override these to delegate file reading to remote systems (for example SSH).
|
|
17
|
+
*/
|
|
18
|
+
export interface ReadOperations {
|
|
19
|
+
/** Read file contents as a Buffer */
|
|
20
|
+
readFile: (absolutePath: string) => Promise<Buffer>;
|
|
21
|
+
/** Check if file is readable (throw if not) */
|
|
22
|
+
access: (absolutePath: string) => Promise<void>;
|
|
23
|
+
/** Detect image MIME type, return null or undefined for non-images */
|
|
24
|
+
detectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;
|
|
25
|
+
}
|
|
26
|
+
export interface ReadToolOptions {
|
|
27
|
+
/** Whether to auto-resize images to 2000x2000 max. Default: true */
|
|
28
|
+
autoResizeImages?: boolean;
|
|
29
|
+
/** Custom operations for file reading. Default: local filesystem */
|
|
30
|
+
operations?: ReadOperations;
|
|
31
|
+
}
|
|
32
|
+
export declare function createReadToolDefinition(cwd: string, options?: ReadToolOptions): ToolDefinition<typeof readSchema, ReadToolDetails | undefined>;
|
|
33
|
+
export declare function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var H=Object.defineProperty;var s=(e,t)=>H(e,"name",{value:t,configurable:!0});import{basename as k,dirname as z,isAbsolute as K,relative as V,resolve as B,sep as j}from"node:path";import{Text as W}from"@openadapter/koda-tui";import{constants as X}from"fs";import{access as q,readFile as Y}from"fs/promises";import{Type as R}from"typebox";import{getReadmePath as J}from"../../config.js";import{keyHint as Q,keyText as Z}from"../../modes/interactive/components/keybinding-hints.js";import{getLanguageFromPath as ee,highlightCode as te}from"../../modes/interactive/theme/theme.js";import{formatDimensionNote as ne,resizeImage as ie}from"../../utils/image-resize.js";import{detectSupportedImageMimeTypeFromFile as oe}from"../../utils/mime.js";import{formatPathRelativeToCwdOrAbsolute as re}from"../../utils/paths.js";import{resolveReadPathAsync as se,resolveToCwd as ae}from"./path-utils.js";import{getTextOutput as le,renderToolPath as fe,replaceTabs as F,str as _}from"./render-utils.js";import{wrapToolDefinition as de}from"./tool-definition-wrapper.js";import{DEFAULT_MAX_BYTES as E,DEFAULT_MAX_LINES as G,formatSize as A,truncateHead as ce}from"./truncate.js";const me=R.Object({path:R.String({description:"Path to the file to read (relative or absolute)"}),offset:R.Optional(R.Number({description:"Line number to start reading from (1-indexed)"})),limit:R.Optional(R.Number({description:"Maximum number of lines to read"}))}),ue=new Set(["AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"]),pe={readFile:s(e=>Y(e),"readFile"),access:s(e=>q(e,X.R_OK),"access"),detectImageMimeType:oe};function U(e,t){if(e?.offset===void 0&&e?.limit===void 0)return"";const i=e.offset??1,n=e.limit!==void 0?i+e.limit-1:"";return t.fg("warning",`:${i}${n?`-${n}`:""}`)}s(U,"formatReadLineRange");function ge(e,t,i){const n=fe(_(e?.file_path??e?.path),t,i);return`${t.fg("toolTitle",t.bold("read"))} ${n}${U(e,t)}`}s(ge,"formatReadCall");function $e(e){let t=e.length;for(;t>0&&e[t-1]==="";)t--;return e.slice(0,t)}s($e,"trimTrailingEmptyLines");function he(e){if(!(!e||e.input.includes("image")))return"[Current model does not support images. The image will be omitted from this request.]"}s(he,"getNonVisionImageNote");function xe(e){return e.split(j).join("/")}s(xe,"toPosixPath");function be(e){const t=z(J()),i=V(B(t),B(e));if(i===""||i===".."||i.startsWith(`..${j}`)||K(i))return;const n=xe(i);if(n==="README.md"||n.startsWith("docs/")||n.startsWith("examples/"))return{kind:"docs",label:n}}s(be,"getPiDocsClassification");function Le(e,t){const i=_(e?.file_path??e?.path);if(!i)return;const n=ae(i,t),f=k(n);if(f==="SKILL.md")return{kind:"skill",label:k(z(n))||f};const m=be(n);if(m)return m;if(ue.has(f))return{kind:"resource",label:re(n,t)}}s(Le,"getCompactReadClassification");function we(e,t,i){const n=i.fg("dim",` (${Z("app.tools.expand")} to expand)`);return e.kind==="skill"?i.fg("customMessageLabel","\x1B[1m[skill]\x1B[22m ")+i.fg("customMessageText",e.label)+U(t,i)+n:i.fg("toolTitle",i.bold(`read ${e.kind}`))+" "+i.fg("accent",e.label)+U(t,i)+n}s(we,"formatCompactReadCall");function Te(e,t,i,n,f,m,d){if(!i.expanded&&!d)return"";const a=_(e?.file_path??e?.path),l=le(t,f),I=a?ee(a):void 0,N=I?te(F(l),I):l.split(`
|
|
2
|
+
`),C=$e(N),L=i.expanded?C.length:10,x=C.slice(0,L),w=C.length-L;let c=`
|
|
3
|
+
${x.map(h=>I?F(h):n.fg("toolOutput",F(h))).join(`
|
|
4
|
+
`)}`;w>0&&(c+=`${n.fg("muted",`
|
|
5
|
+
... (${w} more lines,`)} ${Q("app.tools.expand","to expand")})`);const o=t.details?.truncation;return o?.truncated&&(o.firstLineExceedsLimit?c+=`
|
|
6
|
+
${n.fg("warning",`[First line exceeds ${A(o.maxBytes??E)} limit]`)}`:o.truncatedBy==="lines"?c+=`
|
|
7
|
+
${n.fg("warning",`[Truncated: showing ${o.outputLines} of ${o.totalLines} lines (${o.maxLines??G} line limit)]`)}`:c+=`
|
|
8
|
+
${n.fg("warning",`[Truncated: ${o.outputLines} lines shown (${A(o.maxBytes??E)} limit)]`)}`),c}s(Te,"formatReadResult");function ye(e,t){const i=t?.autoResizeImages??!0,n=t?.operations??pe;return{name:"read",label:"read",description:`Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${G} lines or ${E/1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,promptSnippet:"Read file contents",promptGuidelines:["Use read to examine files instead of cat or sed."],parameters:me,async execute(f,{path:m,offset:d,limit:a},l,I,N){return new Promise((C,L)=>{if(l?.aborted){L(new Error("Operation aborted"));return}let x=!1;const w=s(()=>{x=!0,L(new Error("Operation aborted"))},"onAbort");l?.addEventListener("abort",w,{once:!0}),(async()=>{try{const c=await se(m,e);if(x||(await n.access(c),x))return;const o=n.detectImageMimeType?await n.detectImageMimeType(c):void 0;let h,O;const T=he(N?.model);if(o){const v=await n.readFile(c);if(i){const g=await ie(v,o);if(g){const r=ne(g);let y=`Read image file [${g.mimeType}]`;r&&(y+=`
|
|
9
|
+
${r}`),T&&(y+=`
|
|
10
|
+
${T}`),h=[{type:"text",text:y},{type:"image",data:g.data,mimeType:g.mimeType}]}else{let r=`Read image file [${o}]
|
|
11
|
+
[Image omitted: could not be resized below the inline image size limit.]`;T&&(r+=`
|
|
12
|
+
${T}`),h=[{type:"text",text:r}]}}else{let g=`Read image file [${o}]`;T&&(g+=`
|
|
13
|
+
${T}`),h=[{type:"text",text:g},{type:"image",data:v.toString("base64"),mimeType:o}]}}else{const r=(await n.readFile(c)).toString("utf-8").split(`
|
|
14
|
+
`),y=r.length,u=d?Math.max(0,d-1):0,S=u+1;if(u>=r.length)throw new Error(`Offset ${d} is beyond end of file (${r.length} lines total)`);let D,P;if(a!==void 0){const p=Math.min(u+a,r.length);D=r.slice(u,p).join(`
|
|
15
|
+
`),P=p-u}else D=r.slice(u).join(`
|
|
16
|
+
`);const $=ce(D);let b;if($.firstLineExceedsLimit){const p=A(Buffer.byteLength(r[u],"utf-8"));b=`[Line ${S} is ${p}, exceeds ${A(E)} limit. Use bash: sed -n '${S}p' ${m} | head -c ${E}]`,O={truncation:$}}else if($.truncated){const p=S+$.outputLines-1,M=p+1;b=$.content,$.truncatedBy==="lines"?b+=`
|
|
17
|
+
|
|
18
|
+
[Showing lines ${S}-${p} of ${y}. Use offset=${M} to continue.]`:b+=`
|
|
19
|
+
|
|
20
|
+
[Showing lines ${S}-${p} of ${y} (${A(E)} limit). Use offset=${M} to continue.]`,O={truncation:$}}else if(P!==void 0&&u+P<r.length){const p=r.length-(u+P),M=u+P+1;b=`${$.content}
|
|
21
|
+
|
|
22
|
+
[${p} more lines in file. Use offset=${M} to continue.]`}else b=$.content;h=[{type:"text",text:b}]}if(x)return;l?.removeEventListener("abort",w),C({content:h,details:O})}catch(c){l?.removeEventListener("abort",w),x||L(c)}})()})},renderCall(f,m,d){const a=d.lastComponent??new W("",0,0),l=d.expanded?void 0:Le(f,d.cwd);return a.setText(l?we(l,f,m):ge(f,m,d.cwd)),a},renderResult(f,m,d,a){const l=a.lastComponent??new W("",0,0);return l.setText(Te(a.args,f,m,d,a.showImages,a.cwd,a.isError)),l}}}s(ye,"createReadToolDefinition");function ze(e,t){return de(ye(e,t))}s(ze,"createReadTool");export{ze as createReadTool,ye as createReadToolDefinition};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ImageContent, TextContent } from "@openadapter/koda-ai";
|
|
2
|
+
import type { Theme } from "../../modes/interactive/theme/theme.ts";
|
|
3
|
+
export declare function shortenPath(path: unknown): string;
|
|
4
|
+
export declare function linkPath(styledText: string, rawPath: string, cwd: string): string;
|
|
5
|
+
export declare function str(value: unknown): string | null;
|
|
6
|
+
export declare function replaceTabs(text: string): string;
|
|
7
|
+
export declare function normalizeDisplayText(text: string): string;
|
|
8
|
+
export declare function getTextOutput(result: {
|
|
9
|
+
content: Array<{
|
|
10
|
+
type: string;
|
|
11
|
+
text?: string;
|
|
12
|
+
data?: string;
|
|
13
|
+
mimeType?: string;
|
|
14
|
+
}>;
|
|
15
|
+
} | undefined, showImages: boolean): string;
|
|
16
|
+
export type ToolRenderResultLike<TDetails> = {
|
|
17
|
+
content: (TextContent | ImageContent)[];
|
|
18
|
+
details: TDetails;
|
|
19
|
+
};
|
|
20
|
+
export declare function invalidArgText(theme: Theme): string;
|
|
21
|
+
export declare function renderToolPath(rawPath: string | null, theme: Theme, cwd: string, options?: {
|
|
22
|
+
emptyFallback?: string;
|
|
23
|
+
}): string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var l=Object.defineProperty;var n=(t,e)=>l(t,"name",{value:e,configurable:!0});import*as m from"node:os";import{pathToFileURL as g}from"node:url";import{getCapabilities as u,getImageDimensions as x,hyperlink as y,imageFallback as d}from"@openadapter/koda-tui";import{stripAnsi as h}from"../../utils/ansi.js";import{resolvePath as T}from"../../utils/paths.js";import{sanitizeBinaryOutput as k}from"../../utils/shell.js";function b(t){if(typeof t!="string")return"";const e=m.homedir();return t.startsWith(e)?`~${t.slice(e.length)}`:t}n(b,"shortenPath");function P(t,e,a){if(!u().hyperlinks)return t;const o=T(e,a);return y(t,g(o).href)}n(P,"linkPath");function A(t){return typeof t=="string"?t:t==null?"":null}n(A,"str");function D(t){return t.replace(/\t/g," ")}n(D,"replaceTabs");function I(t){return t.replace(/\r/g,"")}n(I,"normalizeDisplayText");function C(t,e){if(!t)return"";const a=t.content.filter(i=>i.type==="text"),o=t.content.filter(i=>i.type==="image");let r=a.map(i=>k(h(i.text||"")).replace(/\r/g,"")).join(`
|
|
2
|
+
`);const f=u();if(o.length>0&&(!f.images||!e)){const i=o.map(p=>{const c=p.mimeType??"image/unknown",s=p.data&&p.mimeType?x(p.data,p.mimeType)??void 0:void 0;return d(c,s)}).join(`
|
|
3
|
+
`);r=r?`${r}
|
|
4
|
+
${i}`:i}return r}n(C,"getTextOutput");function B(t){return t.fg("error","[invalid arg]")}n(B,"invalidArgText");function L(t,e,a,o){if(t===null)return B(e);const r=t||o?.emptyFallback;return r?P(e.fg("accent",b(r)),r,a):e.fg("toolOutput","...")}n(L,"renderToolPath");export{C as getTextOutput,B as invalidArgText,P as linkPath,I as normalizeDisplayText,L as renderToolPath,D as replaceTabs,b as shortenPath,A as str};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AgentTool } from "@openadapter/koda-agent-core";
|
|
2
|
+
import type { ExtensionContext, ToolDefinition } from "../extensions/types.ts";
|
|
3
|
+
/** Wrap a ToolDefinition into an AgentTool for the core runtime. */
|
|
4
|
+
export declare function wrapToolDefinition<TDetails = unknown>(definition: ToolDefinition<any, TDetails>, ctxFactory?: () => ExtensionContext): AgentTool<any, TDetails>;
|
|
5
|
+
/** Wrap multiple ToolDefinitions into AgentTools for the core runtime. */
|
|
6
|
+
export declare function wrapToolDefinitions(definitions: ToolDefinition<any, any>[], ctxFactory?: () => ExtensionContext): AgentTool<any>[];
|
|
7
|
+
/**
|
|
8
|
+
* Synthesize a minimal ToolDefinition from an AgentTool.
|
|
9
|
+
*
|
|
10
|
+
* This keeps AgentSession's internal registry definition-first even when a caller
|
|
11
|
+
* provides plain AgentTool overrides that do not include prompt metadata or renderers.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createToolDefinitionFromAgentTool(tool: AgentTool<any>): ToolDefinition<any, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var c=Object.defineProperty;var a=(e,r)=>c(e,"name",{value:r,configurable:!0});function m(e,r){return{name:e.name,label:e.label,description:e.description,parameters:e.parameters,prepareArguments:e.prepareArguments,executionMode:e.executionMode,execute:a((p,t,n,u)=>e.execute(p,t,n,u,r?.()),"execute")}}a(m,"wrapToolDefinition");function o(e,r){return e.map(p=>m(p,r))}a(o,"wrapToolDefinitions");function x(e){return{name:e.name,label:e.label,description:e.description,parameters:e.parameters,prepareArguments:e.prepareArguments,executionMode:e.executionMode,execute:a(async(r,p,t,n)=>e.execute(r,p,t,n),"execute")}}a(x,"createToolDefinitionFromAgentTool");export{x as createToolDefinitionFromAgentTool,m as wrapToolDefinition,o as wrapToolDefinitions};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared truncation utilities for tool outputs.
|
|
3
|
+
*
|
|
4
|
+
* Truncation is based on two independent limits - whichever is hit first wins:
|
|
5
|
+
* - Line limit (default: 2000 lines)
|
|
6
|
+
* - Byte limit (default: 50KB)
|
|
7
|
+
*
|
|
8
|
+
* Never returns partial lines (except bash tail truncation edge case).
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_MAX_LINES = 800;
|
|
11
|
+
export declare const DEFAULT_MAX_BYTES: number;
|
|
12
|
+
export declare const GREP_MAX_LINE_LENGTH = 500;
|
|
13
|
+
export interface TruncationResult {
|
|
14
|
+
/** The truncated content */
|
|
15
|
+
content: string;
|
|
16
|
+
/** Whether truncation occurred */
|
|
17
|
+
truncated: boolean;
|
|
18
|
+
/** Which limit was hit: "lines", "bytes", or null if not truncated */
|
|
19
|
+
truncatedBy: "lines" | "bytes" | null;
|
|
20
|
+
/** Total number of lines in the original content */
|
|
21
|
+
totalLines: number;
|
|
22
|
+
/** Total number of bytes in the original content */
|
|
23
|
+
totalBytes: number;
|
|
24
|
+
/** Number of complete lines in the truncated output */
|
|
25
|
+
outputLines: number;
|
|
26
|
+
/** Number of bytes in the truncated output */
|
|
27
|
+
outputBytes: number;
|
|
28
|
+
/** Whether the last line was partially truncated (only for tail truncation edge case) */
|
|
29
|
+
lastLinePartial: boolean;
|
|
30
|
+
/** Whether the first line exceeded the byte limit (for head truncation) */
|
|
31
|
+
firstLineExceedsLimit: boolean;
|
|
32
|
+
/** The max lines limit that was applied */
|
|
33
|
+
maxLines: number;
|
|
34
|
+
/** The max bytes limit that was applied */
|
|
35
|
+
maxBytes: number;
|
|
36
|
+
}
|
|
37
|
+
export interface TruncationOptions {
|
|
38
|
+
/** Maximum number of lines (default: 2000) */
|
|
39
|
+
maxLines?: number;
|
|
40
|
+
/** Maximum number of bytes (default: 50KB) */
|
|
41
|
+
maxBytes?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Format bytes as human-readable size.
|
|
45
|
+
*/
|
|
46
|
+
export declare function formatSize(bytes: number): string;
|
|
47
|
+
/**
|
|
48
|
+
* Truncate content from the head (keep first N lines/bytes).
|
|
49
|
+
* Suitable for file reads where you want to see the beginning.
|
|
50
|
+
*
|
|
51
|
+
* Never returns partial lines. If first line exceeds byte limit,
|
|
52
|
+
* returns empty content with firstLineExceedsLimit=true.
|
|
53
|
+
*/
|
|
54
|
+
export declare function truncateHead(content: string, options?: TruncationOptions): TruncationResult;
|
|
55
|
+
/**
|
|
56
|
+
* Truncate content from the tail (keep last N lines/bytes).
|
|
57
|
+
* Suitable for bash output where you want to see the end (errors, final results).
|
|
58
|
+
*
|
|
59
|
+
* May return partial first line if the last line of original content exceeds byte limit.
|
|
60
|
+
*/
|
|
61
|
+
export declare function truncateTail(content: string, options?: TruncationOptions): TruncationResult;
|
|
62
|
+
/**
|
|
63
|
+
* Truncate a single line to max characters, adding [truncated] suffix.
|
|
64
|
+
* Used for grep match lines.
|
|
65
|
+
*/
|
|
66
|
+
export declare function truncateLine(line: string, maxChars?: number): {
|
|
67
|
+
text: string;
|
|
68
|
+
wasTruncated: boolean;
|
|
69
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var x=Object.defineProperty;var c=(t,u)=>x(t,"name",{value:u,configurable:!0});const A=800,T=51200,m=500;function d(t){if(t.length===0)return[];const u=t.split(`
|
|
2
|
+
`);return t.endsWith(`
|
|
3
|
+
`)&&u.pop(),u}c(d,"splitLinesForCounting");function b(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/(1024*1024)).toFixed(1)}MB`}c(b,"formatSize");function F(t,u={}){const n=u.maxLines??800,e=u.maxBytes??51200,s=Buffer.byteLength(t,"utf-8"),o=d(t),i=o.length;if(i<=n&&s<=e)return{content:t,truncated:!1,truncatedBy:null,totalLines:i,totalBytes:s,outputLines:i,outputBytes:s,lastLinePartial:!1,firstLineExceedsLimit:!1,maxLines:n,maxBytes:e};if(Buffer.byteLength(o[0],"utf-8")>e)return{content:"",truncated:!0,truncatedBy:"bytes",totalLines:i,totalBytes:s,outputLines:0,outputBytes:0,lastLinePartial:!1,firstLineExceedsLimit:!0,maxLines:n,maxBytes:e};const f=[];let a=0,L="lines";for(let l=0;l<o.length&&l<n;l++){const B=o[l],h=Buffer.byteLength(B,"utf-8")+(l>0?1:0);if(a+h>e){L="bytes";break}f.push(B),a+=h}f.length>=n&&a<=e&&(L="lines");const y=f.join(`
|
|
4
|
+
`),p=Buffer.byteLength(y,"utf-8");return{content:y,truncated:!0,truncatedBy:L,totalLines:i,totalBytes:s,outputLines:f.length,outputBytes:p,lastLinePartial:!1,firstLineExceedsLimit:!1,maxLines:n,maxBytes:e}}c(F,"truncateHead");function M(t,u={}){const n=u.maxLines??800,e=u.maxBytes??51200,s=Buffer.byteLength(t,"utf-8"),o=d(t),i=o.length;if(i<=n&&s<=e)return{content:t,truncated:!1,truncatedBy:null,totalLines:i,totalBytes:s,outputLines:i,outputBytes:s,lastLinePartial:!1,firstLineExceedsLimit:!1,maxLines:n,maxBytes:e};const r=[];let f=0,a="lines",L=!1;for(let l=o.length-1;l>=0&&r.length<n;l--){const B=o[l],h=Buffer.byteLength(B,"utf-8")+(r.length>0?1:0);if(f+h>e){if(a="bytes",r.length===0){const g=E(B,e);r.unshift(g),f=Buffer.byteLength(g,"utf-8"),L=!0}break}r.unshift(B),f+=h}r.length>=n&&f<=e&&(a="lines");const y=r.join(`
|
|
5
|
+
`),p=Buffer.byteLength(y,"utf-8");return{content:y,truncated:!0,truncatedBy:a,totalLines:i,totalBytes:s,outputLines:r.length,outputBytes:p,lastLinePartial:L,firstLineExceedsLimit:!1,maxLines:n,maxBytes:e}}c(M,"truncateTail");function E(t,u){const n=Buffer.from(t,"utf-8");if(n.length<=u)return t;let e=n.length-u;for(;e<n.length&&(n[e]&192)===128;)e++;return n.slice(e).toString("utf-8")}c(E,"truncateStringToBytesFromEnd");function S(t,u=500){return t.length<=u?{text:t,wasTruncated:!1}:{text:`${t.slice(0,u)}... [truncated]`,wasTruncated:!0}}c(S,"truncateLine");export{T as DEFAULT_MAX_BYTES,A as DEFAULT_MAX_LINES,m as GREP_MAX_LINE_LENGTH,b as formatSize,F as truncateHead,S as truncateLine,M as truncateTail};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AgentTool } from "@openadapter/koda-agent-core";
|
|
2
|
+
import { type Static, Type } from "typebox";
|
|
3
|
+
import type { ToolDefinition } from "../extensions/types.ts";
|
|
4
|
+
declare const writeSchema: Type.TObject<{
|
|
5
|
+
path: Type.TString;
|
|
6
|
+
content: Type.TString;
|
|
7
|
+
}>;
|
|
8
|
+
export type WriteToolInput = Static<typeof writeSchema>;
|
|
9
|
+
/**
|
|
10
|
+
* Pluggable operations for the write tool.
|
|
11
|
+
* Override these to delegate file writing to remote systems (for example SSH).
|
|
12
|
+
*/
|
|
13
|
+
export interface WriteOperations {
|
|
14
|
+
/** Write content to a file */
|
|
15
|
+
writeFile: (absolutePath: string, content: string) => Promise<void>;
|
|
16
|
+
/** Create directory recursively */
|
|
17
|
+
mkdir: (dir: string) => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export interface WriteToolOptions {
|
|
20
|
+
/** Custom operations for file writing. Default: local filesystem */
|
|
21
|
+
operations?: WriteOperations;
|
|
22
|
+
}
|
|
23
|
+
export declare function createWriteToolDefinition(cwd: string, options?: WriteToolOptions): ToolDefinition<typeof writeSchema, undefined>;
|
|
24
|
+
export declare function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var _=Object.defineProperty;var d=(t,e)=>_(t,"name",{value:e,configurable:!0});import{Container as I,Text as W}from"@openadapter/koda-tui";import{mkdir as F,writeFile as H}from"fs/promises";import{dirname as S}from"path";import{Type as L}from"typebox";import{keyHint as E}from"../../modes/interactive/components/keybinding-hints.js";import{getLanguageFromPath as x,highlightCode as f}from"../../modes/interactive/theme/theme.js";import{withFileMutationQueue as v}from"./file-mutation-queue.js";import{resolveToCwd as R}from"./path-utils.js";import{normalizeDisplayText as g,renderToolPath as k,replaceTabs as m,str as h}from"./render-utils.js";import{wrapToolDefinition as A}from"./tool-definition-wrapper.js";const D=L.Object({path:L.String({description:"Path to the file to write (relative or absolute)"}),content:L.String({description:"Content to write to the file"})}),j={writeFile:d((t,e)=>H(t,e,"utf-8"),"writeFile"),mkdir:d(t=>F(t,{recursive:!0}).then(()=>{}),"mkdir")};class O extends W{static{d(this,"WriteCallRenderComponent")}cache;constructor(){super("",0,0)}}const P=50;function C(t,e){return f(t,e)[0]??""}d(C,"highlightSingleLine");function G(t){const e=Math.min(P,t.normalizedLines.length);if(e===0)return;const n=t.normalizedLines.slice(0,e).join(`
|
|
2
|
+
`),o=f(n,t.lang);for(let r=0;r<e;r++)t.highlightedLines[r]=o[r]??C(t.normalizedLines[r]??"",t.lang)}d(G,"refreshWriteHighlightPrefix");function c(t,e){const n=t?x(t):void 0;if(!n)return;const o=g(e),r=m(o);return{rawPath:t,lang:n,rawContent:e,normalizedLines:r.split(`
|
|
3
|
+
`),highlightedLines:f(r,n)}}d(c,"rebuildWriteHighlightCacheFull");function M(t,e,n){const o=e?x(e):void 0;if(!o)return;if(!t||t.lang!==o||t.rawPath!==e||!n.startsWith(t.rawContent))return c(e,n);if(n.length===t.rawContent.length)return t;const r=n.slice(t.rawContent.length),l=g(r),s=m(l);t.rawContent=n,t.normalizedLines.length===0&&(t.normalizedLines.push(""),t.highlightedLines.push(""));const p=s.split(`
|
|
4
|
+
`),a=t.normalizedLines.length-1;t.normalizedLines[a]+=p[0],t.highlightedLines[a]=C(t.normalizedLines[a],t.lang);for(let i=1;i<p.length;i++)t.normalizedLines.push(p[i]),t.highlightedLines.push(C(p[i],t.lang));return G(t),t}d(M,"updateWriteHighlightCacheIncremental");function U(t){let e=t.length;for(;e>0&&t[e-1]==="";)e--;return t.slice(0,e)}d(U,"trimTrailingEmptyLines");function N(t,e,n,o,r){const l=h(t?.file_path??t?.path),s=h(t?.content),p=k(l,n,r);let a=`${n.fg("toolTitle",n.bold("write"))} ${p}`;if(s===null)a+=`
|
|
5
|
+
|
|
6
|
+
${n.fg("error","[invalid content arg - expected string]")}`;else if(s){const i=l?x(l):void 0,w=i?o?.highlightedLines??f(m(g(s)),i):g(s).split(`
|
|
7
|
+
`),u=U(w),b=u.length,y=e.expanded?u.length:10,$=u.slice(0,y),T=u.length-y;a+=`
|
|
8
|
+
|
|
9
|
+
${$.map(z=>i?z:n.fg("toolOutput",m(z))).join(`
|
|
10
|
+
`)}`,T>0&&(a+=`${n.fg("muted",`
|
|
11
|
+
... (${T} more lines, ${b} total,`)} ${E("app.tools.expand","to expand")})`)}return a}d(N,"formatWriteCall");function Q(t,e){if(!t.isError)return;const n=t.content.filter(o=>o.type==="text").map(o=>o.text||"").join(`
|
|
12
|
+
`);if(n)return`
|
|
13
|
+
${e.fg("error",n)}`}d(Q,"formatWriteResult");function q(t,e){const n=e?.operations??j;return{name:"write",label:"write",description:"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.",promptSnippet:"Create or overwrite files",promptGuidelines:["Use write only for new files or complete rewrites."],parameters:D,async execute(o,{path:r,content:l},s,p,a){const i=R(r,t),w=S(i);return v(i,async()=>{const u=d(()=>{if(s?.aborted)throw new Error("Operation aborted")},"throwIfAborted");return u(),await n.mkdir(w),u(),await n.writeFile(i,l),u(),{content:[{type:"text",text:`Successfully wrote ${l.length} bytes to ${r}`}],details:void 0}})},renderCall(o,r,l){const s=o,p=h(s?.file_path??s?.path),a=h(s?.content),i=l.lastComponent??new O;return a!==null?i.cache=l.argsComplete?c(p,a):M(i.cache,p,a):i.cache=void 0,i.setText(N(s,{expanded:l.expanded,isPartial:l.isPartial},r,i.cache,l.cwd)),i},renderResult(o,r,l,s){const p=Q({...o,isError:s.isError},l);if(!p){const i=s.lastComponent??new I;return i.clear(),i}const a=s.lastComponent??new W("",0,0);return a.setText(p),a}}}d(q,"createWriteToolDefinition");function rt(t,e){return A(q(t,e))}d(rt,"createWriteTool");export{rt as createWriteTool,q as createWriteToolDefinition};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { type Args, parseArgs } from "./cli/args.ts";
|
|
2
|
+
export { getAgentDir, VERSION } from "./config.ts";
|
|
3
|
+
export { AgentSession, type AgentSessionConfig, type AgentSessionEvent, type AgentSessionEventListener, type ModelCycleResult, type ParsedSkillBlock, type PromptOptions, parseSkillBlock, type SessionStats, } from "./core/agent-session.ts";
|
|
4
|
+
export { type ApiKeyCredential, type AuthCredential, type AuthStatus, AuthStorage, type AuthStorageBackend, FileAuthStorageBackend, InMemoryAuthStorageBackend, type OAuthCredential, } from "./core/auth-storage.ts";
|
|
5
|
+
export { type BranchPreparation, type BranchSummaryResult, type CollectEntriesResult, type CompactionResult, type CutPointResult, calculateContextTokens, collectEntriesForBranchSummary, compact, DEFAULT_COMPACTION_SETTINGS, estimateTokens, type FileOperations, findCutPoint, findTurnStartIndex, type GenerateBranchSummaryOptions, generateBranchSummary, generateSummary, getLastAssistantUsage, prepareBranchEntries, serializeConversation, shouldCompact, } from "./core/compaction/index.ts";
|
|
6
|
+
export { createEventBus, type EventBus, type EventBusController } from "./core/event-bus.ts";
|
|
7
|
+
export type { AgentEndEvent, AgentStartEvent, AgentToolResult, AgentToolUpdateCallback, AppKeybinding, AutocompleteProviderFactory, BashToolCallEvent, BeforeAgentStartEvent, BeforeAgentStartEventResult, BeforeProviderRequestEvent, BeforeProviderRequestEventResult, BuildSystemPromptOptions, CompactOptions, ContextEvent, ContextUsage, CustomToolCallEvent, EditToolCallEvent, ExecOptions, ExecResult, Extension, ExtensionActions, ExtensionAPI, ExtensionCommandContext, ExtensionCommandContextActions, ExtensionContext, ExtensionContextActions, ExtensionError, ExtensionEvent, ExtensionFactory, ExtensionFlag, ExtensionHandler, ExtensionRuntime, ExtensionShortcut, ExtensionUIContext, ExtensionUIDialogOptions, ExtensionWidgetOptions, FindToolCallEvent, GrepToolCallEvent, InputEvent, InputEventResult, InputSource, KeybindingsManager, LoadExtensionsResult, LsToolCallEvent, MessageRenderer, MessageRenderOptions, ProviderConfig, ProviderModelConfig, ReadToolCallEvent, RegisteredCommand, RegisteredTool, ResolvedCommand, SessionBeforeCompactEvent, SessionBeforeForkEvent, SessionBeforeSwitchEvent, SessionBeforeTreeEvent, SessionCompactEvent, SessionShutdownEvent, SessionStartEvent, SessionTreeEvent, SlashCommandInfo, SlashCommandSource, SourceInfo, TerminalInputHandler, ToolCallEvent, ToolCallEventResult, ToolDefinition, ToolExecutionMode, ToolInfo, ToolRenderResultOptions, ToolResultEvent, TurnEndEvent, TurnStartEvent, UserBashEvent, UserBashEventResult, WidgetPlacement, WorkingIndicatorOptions, WriteToolCallEvent, } from "./core/extensions/index.ts";
|
|
8
|
+
export { createExtensionRuntime, defineTool, discoverAndLoadExtensions, ExtensionRunner, isBashToolResult, isEditToolResult, isFindToolResult, isGrepToolResult, isLsToolResult, isReadToolResult, isToolCallEventType, isWriteToolResult, wrapRegisteredTool, wrapRegisteredTools, } from "./core/extensions/index.ts";
|
|
9
|
+
export type { ReadonlyFooterDataProvider } from "./core/footer-data-provider.ts";
|
|
10
|
+
export { convertToLlm } from "./core/messages.ts";
|
|
11
|
+
export { ModelRegistry } from "./core/model-registry.ts";
|
|
12
|
+
export type { PackageManager, PathMetadata, ProgressCallback, ProgressEvent, ResolvedPaths, ResolvedResource, } from "./core/package-manager.ts";
|
|
13
|
+
export { DefaultPackageManager } from "./core/package-manager.ts";
|
|
14
|
+
export type { ResourceCollision, ResourceDiagnostic, ResourceLoader } from "./core/resource-loader.ts";
|
|
15
|
+
export { DefaultResourceLoader, loadProjectContextFiles } from "./core/resource-loader.ts";
|
|
16
|
+
export { AgentSessionRuntime, type AgentSessionRuntimeDiagnostic, type AgentSessionServices, type CreateAgentSessionFromServicesOptions, type CreateAgentSessionOptions, type CreateAgentSessionResult, type CreateAgentSessionRuntimeFactory, type CreateAgentSessionRuntimeResult, type CreateAgentSessionServicesOptions, createAgentSession, createAgentSessionFromServices, createAgentSessionRuntime, createAgentSessionServices, createBashTool, createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createReadOnlyTools, createReadTool, createWriteTool, type PromptTemplate, } from "./core/sdk.ts";
|
|
17
|
+
export { type BranchSummaryEntry, buildSessionContext, type CompactionEntry, CURRENT_SESSION_VERSION, type CustomEntry, type CustomMessageEntry, type FileEntry, getLatestCompactionEntry, type ModelChangeEntry, migrateSessionEntries, type NewSessionOptions, parseSessionEntries, type SessionContext, type SessionEntry, type SessionEntryBase, type SessionHeader, type SessionInfo, type SessionInfoEntry, SessionManager, type SessionMessageEntry, type ThinkingLevelChangeEntry, } from "./core/session-manager.ts";
|
|
18
|
+
export { type CompactionSettings, type ImageSettings, type PackageSource, type RetrySettings, SettingsManager, } from "./core/settings-manager.ts";
|
|
19
|
+
export { formatSkillsForPrompt, type LoadSkillsFromDirOptions, type LoadSkillsResult, loadSkills, loadSkillsFromDir, type Skill, type SkillFrontmatter, } from "./core/skills.ts";
|
|
20
|
+
export { createSyntheticSourceInfo } from "./core/source-info.ts";
|
|
21
|
+
export { type BashOperations, type BashSpawnContext, type BashSpawnHook, type BashToolDetails, type BashToolInput, type BashToolOptions, createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLocalBashOperations, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition, DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type EditOperations, type EditToolDetails, type EditToolInput, type EditToolOptions, type FindOperations, type FindToolDetails, type FindToolInput, type FindToolOptions, formatSize, type GrepOperations, type GrepToolDetails, type GrepToolInput, type GrepToolOptions, type LsOperations, type LsToolDetails, type LsToolInput, type LsToolOptions, type ReadOperations, type ReadToolDetails, type ReadToolInput, type ReadToolOptions, type ToolsOptions, type TruncationOptions, type TruncationResult, truncateHead, truncateLine, truncateTail, type WriteOperations, type WriteToolInput, type WriteToolOptions, withFileMutationQueue, } from "./core/tools/index.ts";
|
|
22
|
+
export { type MainOptions, main } from "./main.ts";
|
|
23
|
+
export { InteractiveMode, type InteractiveModeOptions, type ModelInfo, type PrintModeOptions, RpcClient, type RpcClientOptions, type RpcCommand, type RpcEventListener, type RpcResponse, type RpcSessionState, runPrintMode, runRpcMode, } from "./modes/index.ts";
|
|
24
|
+
export { ArminComponent, AssistantMessageComponent, BashExecutionComponent, BorderedLoader, BranchSummaryMessageComponent, CompactionSummaryMessageComponent, CustomEditor, CustomMessageComponent, DynamicBorder, ExtensionEditorComponent, ExtensionInputComponent, ExtensionSelectorComponent, FooterComponent, keyHint, keyText, LoginDialogComponent, ModelSelectorComponent, OAuthSelectorComponent, type RenderDiffOptions, rawKeyHint, renderDiff, SessionSelectorComponent, type SettingsCallbacks, type SettingsConfig, SettingsSelectorComponent, ShowImagesSelectorComponent, SkillInvocationMessageComponent, ThemeSelectorComponent, ThinkingSelectorComponent, ToolExecutionComponent, type ToolExecutionOptions, TreeSelectorComponent, truncateToVisualLines, UserMessageComponent, UserMessageSelectorComponent, type VisualTruncateResult, } from "./modes/interactive/components/index.ts";
|
|
25
|
+
export { getLanguageFromPath, getMarkdownTheme, getSelectListTheme, getSettingsListTheme, highlightCode, initTheme, Theme, type ThemeColor, } from "./modes/interactive/theme/theme.ts";
|
|
26
|
+
export { copyToClipboard } from "./utils/clipboard.ts";
|
|
27
|
+
export { parseFrontmatter, stripFrontmatter } from "./utils/frontmatter.ts";
|
|
28
|
+
export { convertToPng } from "./utils/image-convert.ts";
|
|
29
|
+
export { formatDimensionNote, type ResizedImage, resizeImage } from "./utils/image-resize.ts";
|
|
30
|
+
export { getShellConfig } from "./utils/shell.ts";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parseArgs as t}from"./cli/args.js";import{getAgentDir as n,VERSION as i}from"./config.js";import{AgentSession as s,parseSkillBlock as m}from"./core/agent-session.js";import{AuthStorage as c,FileAuthStorageBackend as p,InMemoryAuthStorageBackend as S}from"./core/auth-storage.js";import{calculateContextTokens as g,collectEntriesForBranchSummary as u,compact as f,DEFAULT_COMPACTION_SETTINGS as d,estimateTokens as C,findCutPoint as x,findTurnStartIndex as E,generateBranchSummary as h,generateSummary as R,getLastAssistantUsage as A,prepareBranchEntries as M,serializeConversation as L,shouldCompact as D}from"./core/compaction/index.js";import{createEventBus as y}from"./core/event-bus.js";import{createExtensionRuntime as k,defineTool as I,discoverAndLoadExtensions as v,ExtensionRunner as N,isBashToolResult as O,isEditToolResult as P,isFindToolResult as _,isGrepToolResult as U,isLsToolResult as w,isReadToolResult as G,isToolCallEventType as z,isWriteToolResult as H,wrapRegisteredTool as V,wrapRegisteredTools as W}from"./core/extensions/index.js";import{convertToLlm as X}from"./core/messages.js";import{ModelRegistry as K}from"./core/model-registry.js";import{DefaultPackageManager as Y}from"./core/package-manager.js";import{DefaultResourceLoader as J,loadProjectContextFiles as Z}from"./core/resource-loader.js";import{AgentSessionRuntime as ee,createAgentSession as oe,createAgentSessionFromServices as te,createAgentSessionRuntime as re,createAgentSessionServices as ne,createBashTool as ie,createCodingTools as ae,createEditTool as se,createFindTool as me,createGrepTool as le,createLsTool as ce,createReadOnlyTools as pe,createReadTool as Se,createWriteTool as Te}from"./core/sdk.js";import{buildSessionContext as ue,CURRENT_SESSION_VERSION as fe,getLatestCompactionEntry as de,migrateSessionEntries as Ce,parseSessionEntries as xe,SessionManager as Ee}from"./core/session-manager.js";import{SettingsManager as Re}from"./core/settings-manager.js";import{formatSkillsForPrompt as Me,loadSkills as Le,loadSkillsFromDir as De}from"./core/skills.js";import{createSyntheticSourceInfo as ye}from"./core/source-info.js";import{createBashToolDefinition as ke,createEditToolDefinition as Ie,createFindToolDefinition as ve,createGrepToolDefinition as Ne,createLocalBashOperations as Oe,createLsToolDefinition as Pe,createReadToolDefinition as _e,createWriteToolDefinition as Ue,DEFAULT_MAX_BYTES as we,DEFAULT_MAX_LINES as Ge,formatSize as ze,truncateHead as He,truncateLine as Ve,truncateTail as We,withFileMutationQueue as be}from"./core/tools/index.js";import{main as je}from"./main.js";import{InteractiveMode as Qe,RpcClient as Ye,runPrintMode as qe,runRpcMode as Je}from"./modes/index.js";import{ArminComponent as $e,AssistantMessageComponent as eo,BashExecutionComponent as oo,BorderedLoader as to,BranchSummaryMessageComponent as ro,CompactionSummaryMessageComponent as no,CustomEditor as io,CustomMessageComponent as ao,DynamicBorder as so,ExtensionEditorComponent as mo,ExtensionInputComponent as lo,ExtensionSelectorComponent as co,FooterComponent as po,keyHint as So,keyText as To,LoginDialogComponent as go,ModelSelectorComponent as uo,OAuthSelectorComponent as fo,rawKeyHint as Co,renderDiff as xo,SessionSelectorComponent as Eo,SettingsSelectorComponent as ho,ShowImagesSelectorComponent as Ro,SkillInvocationMessageComponent as Ao,ThemeSelectorComponent as Mo,ThinkingSelectorComponent as Lo,ToolExecutionComponent as Do,TreeSelectorComponent as Fo,truncateToVisualLines as yo,UserMessageComponent as Bo,UserMessageSelectorComponent as ko}from"./modes/interactive/components/index.js";import{getLanguageFromPath as vo,getMarkdownTheme as No,getSelectListTheme as Oo,getSettingsListTheme as Po,highlightCode as _o,initTheme as Uo,Theme as wo}from"./modes/interactive/theme/theme.js";import{copyToClipboard as zo}from"./utils/clipboard.js";import{parseFrontmatter as Vo,stripFrontmatter as Wo}from"./utils/frontmatter.js";import{convertToPng as Xo}from"./utils/image-convert.js";import{formatDimensionNote as Ko,resizeImage as Qo}from"./utils/image-resize.js";import{getShellConfig as qo}from"./utils/shell.js";export{s as AgentSession,ee as AgentSessionRuntime,$e as ArminComponent,eo as AssistantMessageComponent,c as AuthStorage,oo as BashExecutionComponent,to as BorderedLoader,ro as BranchSummaryMessageComponent,fe as CURRENT_SESSION_VERSION,no as CompactionSummaryMessageComponent,io as CustomEditor,ao as CustomMessageComponent,d as DEFAULT_COMPACTION_SETTINGS,we as DEFAULT_MAX_BYTES,Ge as DEFAULT_MAX_LINES,Y as DefaultPackageManager,J as DefaultResourceLoader,so as DynamicBorder,mo as ExtensionEditorComponent,lo as ExtensionInputComponent,N as ExtensionRunner,co as ExtensionSelectorComponent,p as FileAuthStorageBackend,po as FooterComponent,S as InMemoryAuthStorageBackend,Qe as InteractiveMode,go as LoginDialogComponent,K as ModelRegistry,uo as ModelSelectorComponent,fo as OAuthSelectorComponent,Ye as RpcClient,Ee as SessionManager,Eo as SessionSelectorComponent,Re as SettingsManager,ho as SettingsSelectorComponent,Ro as ShowImagesSelectorComponent,Ao as SkillInvocationMessageComponent,wo as Theme,Mo as ThemeSelectorComponent,Lo as ThinkingSelectorComponent,Do as ToolExecutionComponent,Fo as TreeSelectorComponent,Bo as UserMessageComponent,ko as UserMessageSelectorComponent,i as VERSION,ue as buildSessionContext,g as calculateContextTokens,u as collectEntriesForBranchSummary,f as compact,X as convertToLlm,Xo as convertToPng,zo as copyToClipboard,oe as createAgentSession,te as createAgentSessionFromServices,re as createAgentSessionRuntime,ne as createAgentSessionServices,ie as createBashTool,ke as createBashToolDefinition,ae as createCodingTools,se as createEditTool,Ie as createEditToolDefinition,y as createEventBus,k as createExtensionRuntime,me as createFindTool,ve as createFindToolDefinition,le as createGrepTool,Ne as createGrepToolDefinition,Oe as createLocalBashOperations,ce as createLsTool,Pe as createLsToolDefinition,pe as createReadOnlyTools,Se as createReadTool,_e as createReadToolDefinition,ye as createSyntheticSourceInfo,Te as createWriteTool,Ue as createWriteToolDefinition,I as defineTool,v as discoverAndLoadExtensions,C as estimateTokens,x as findCutPoint,E as findTurnStartIndex,Ko as formatDimensionNote,ze as formatSize,Me as formatSkillsForPrompt,h as generateBranchSummary,R as generateSummary,n as getAgentDir,vo as getLanguageFromPath,A as getLastAssistantUsage,de as getLatestCompactionEntry,No as getMarkdownTheme,Oo as getSelectListTheme,Po as getSettingsListTheme,qo as getShellConfig,_o as highlightCode,Uo as initTheme,O as isBashToolResult,P as isEditToolResult,_ as isFindToolResult,U as isGrepToolResult,w as isLsToolResult,G as isReadToolResult,z as isToolCallEventType,H as isWriteToolResult,So as keyHint,To as keyText,Z as loadProjectContextFiles,Le as loadSkills,De as loadSkillsFromDir,je as main,Ce as migrateSessionEntries,t as parseArgs,Vo as parseFrontmatter,xe as parseSessionEntries,m as parseSkillBlock,M as prepareBranchEntries,Co as rawKeyHint,xo as renderDiff,Qo as resizeImage,qe as runPrintMode,Je as runRpcMode,L as serializeConversation,D as shouldCompact,Wo as stripFrontmatter,He as truncateHead,Ve as truncateLine,We as truncateTail,yo as truncateToVisualLines,be as withFileMutationQueue,V as wrapRegisteredTool,W as wrapRegisteredTools};
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main entry point for the coding agent CLI.
|
|
3
|
+
*
|
|
4
|
+
* This file handles CLI argument parsing and translates them into
|
|
5
|
+
* createAgentSession() options. The SDK does the heavy lifting.
|
|
6
|
+
*/
|
|
7
|
+
import type { ExtensionFactory } from "./core/extensions/types.ts";
|
|
8
|
+
export interface MainOptions {
|
|
9
|
+
extensionFactories?: ExtensionFactory[];
|
|
10
|
+
}
|
|
11
|
+
export declare function main(args: string[], options?: MainOptions): Promise<void>;
|