@bastani/atomic 0.8.19 → 0.8.20
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 +19 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/CHANGELOG.md +10 -0
- package/dist/builtin/mcp/package.json +2 -2
- package/dist/builtin/subagents/CHANGELOG.md +17 -2
- package/dist/builtin/subagents/agents/code-simplifier.md +1 -1
- package/dist/builtin/subagents/agents/codebase-analyzer.md +1 -1
- package/dist/builtin/subagents/agents/codebase-online-researcher.md +1 -1
- package/dist/builtin/subagents/agents/codebase-research-analyzer.md +1 -1
- package/dist/builtin/subagents/agents/debugger.md +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/subagent/SKILL.md +12 -12
- package/dist/builtin/subagents/src/agents/agent-management.ts +16 -11
- package/dist/builtin/subagents/src/agents/skills.ts +13 -1
- package/dist/builtin/subagents/src/extension/index.ts +14 -3
- package/dist/builtin/subagents/src/runs/background/async-execution.ts +8 -0
- package/dist/builtin/subagents/src/runs/background/run-status.ts +2 -3
- package/dist/builtin/subagents/src/runs/background/subagent-runner.ts +11 -1
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify.ts +2 -2
- package/dist/builtin/subagents/src/runs/foreground/chain-execution.ts +31 -23
- package/dist/builtin/subagents/src/runs/foreground/execution.ts +13 -7
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor.ts +160 -93
- package/dist/builtin/subagents/src/runs/shared/parallel-utils.ts +1 -0
- package/dist/builtin/subagents/src/runs/shared/run-history.ts +1 -1
- package/dist/builtin/subagents/src/shared/settings.ts +1 -0
- package/dist/builtin/subagents/src/shared/types.ts +78 -4
- package/dist/builtin/subagents/src/tui/render.ts +203 -19
- package/dist/builtin/web-access/CHANGELOG.md +10 -0
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +25 -0
- package/dist/builtin/workflows/README.md +22 -3
- package/dist/builtin/workflows/builtin/deep-research-codebase.ts +1 -1
- package/dist/builtin/workflows/builtin/open-claude-design.ts +12 -4
- package/dist/builtin/workflows/builtin/ralph.ts +2 -2
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/config-loader.ts +68 -0
- package/dist/builtin/workflows/src/extension/index.ts +246 -55
- package/dist/builtin/workflows/src/extension/lifecycle-notifications.ts +372 -0
- package/dist/builtin/workflows/src/extension/render-call.ts +1 -1
- package/dist/builtin/workflows/src/extension/wiring.ts +32 -3
- package/dist/builtin/workflows/src/runs/background/status.ts +14 -74
- package/dist/builtin/workflows/src/shared/persistence-restore.ts +5 -3
- package/dist/builtin/workflows/src/tui/chat-surface-message.ts +3 -13
- package/dist/builtin/workflows/src/tui/inline-form-overlay.ts +2 -10
- package/dist/builtin/workflows/src/tui/overlay-adapter.ts +5 -5
- package/dist/builtin/workflows/src/tui/session-confirm.ts +6 -7
- package/dist/builtin/workflows/src/tui/session-picker.ts +18 -14
- package/dist/builtin/workflows/src/tui/status-list.ts +2 -2
- package/dist/builtin/workflows/src/tui/store-widget-installer.ts +125 -30
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +4 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +2 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/atomic-guide-command.d.ts.map +1 -1
- package/dist/core/atomic-guide-command.js +3 -2
- package/dist/core/atomic-guide-command.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +3 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +6 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +13 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +63 -17
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/output-guard.d.ts.map +1 -1
- package/dist/core/output-guard.js +29 -0
- package/dist/core/output-guard.js.map +1 -1
- package/dist/core/sdk.d.ts +3 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +1 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +1 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +46 -13
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js +2 -1
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +1 -1
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +3 -5
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/models.md +52 -52
- package/docs/quickstart.md +2 -2
- package/docs/workflows.md +22 -5
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-user-agent.d.ts","sourceRoot":"","sources":["../../src/utils/pi-user-agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pi-user-agent.d.ts","sourceRoot":"","sources":["../../src/utils/pi-user-agent.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGtD","sourcesContent":["import { APP_NAME } from \"../config.ts\";\n\nexport function getPiUserAgent(version: string): string {\n\tconst runtime = process.versions.bun ? `bun/${process.versions.bun}` : `node/${process.version}`;\n\treturn `${APP_NAME}/${version} (${process.platform}; ${runtime}; ${process.arch})`;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { APP_NAME } from "../config.js";
|
|
1
2
|
export function getPiUserAgent(version) {
|
|
2
3
|
const runtime = process.versions.bun ? `bun/${process.versions.bun}` : `node/${process.version}`;
|
|
3
|
-
return
|
|
4
|
+
return `${APP_NAME}/${version} (${process.platform}; ${runtime}; ${process.arch})`;
|
|
4
5
|
}
|
|
5
6
|
//# sourceMappingURL=pi-user-agent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-user-agent.js","sourceRoot":"","sources":["../../src/utils/pi-user-agent.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAAC,OAAe;IAC7C,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,OAAO,CAAC,OAAO,EAAE,CAAC;IACjG,OAAO,
|
|
1
|
+
{"version":3,"file":"pi-user-agent.js","sourceRoot":"","sources":["../../src/utils/pi-user-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,MAAM,UAAU,cAAc,CAAC,OAAe;IAC7C,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,OAAO,CAAC,OAAO,EAAE,CAAC;IACjG,OAAO,GAAG,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,QAAQ,KAAK,OAAO,KAAK,OAAO,CAAC,IAAI,GAAG,CAAC;AACpF,CAAC","sourcesContent":["import { APP_NAME } from \"../config.ts\";\n\nexport function getPiUserAgent(version: string): string {\n\tconst runtime = process.versions.bun ? `bun/${process.versions.bun}` : `node/${process.version}`;\n\treturn `${APP_NAME}/${version} (${process.platform}; ${runtime}; ${process.arch})`;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax-highlight.d.ts","sourceRoot":"","sources":["../../src/utils/syntax-highlight.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;AAC1D,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAEzE,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,cAAc,CAAC;CACvB;AAoED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,cAAmB,GAAG,MAAM,CAoDtF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAQ9E;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD","sourcesContent":["import hljs from \"highlight.js
|
|
1
|
+
{"version":3,"file":"syntax-highlight.d.ts","sourceRoot":"","sources":["../../src/utils/syntax-highlight.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;AAC1D,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAEzE,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,cAAc,CAAC;CACvB;AAoED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,cAAmB,GAAG,MAAM,CAoDtF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAQ9E;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD","sourcesContent":["import hljs from \"highlight.js\";\nimport { decodeHtmlEntityAt } from \"./html.ts\";\n\nexport type HighlightFormatter = (text: string) => string;\nexport type HighlightTheme = Partial<Record<string, HighlightFormatter>>;\n\nexport interface HighlightOptions {\n\tlanguage?: string;\n\tignoreIllegals?: boolean;\n\tlanguageSubset?: string[];\n\ttheme?: HighlightTheme;\n}\n\nconst SPAN_CLOSE = \"</span>\";\nconst HIGHLIGHT_CLASS_PREFIX = \"hljs-\";\n\nfunction getScopeFromSpanTag(tag: string): string | undefined {\n\tconst match = /\\sclass\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)')/.exec(tag);\n\tconst classValue = match?.[1] ?? match?.[2];\n\tif (!classValue) {\n\t\treturn undefined;\n\t}\n\n\tfor (const className of classValue.split(/\\s+/)) {\n\t\tif (className.startsWith(HIGHLIGHT_CLASS_PREFIX)) {\n\t\t\treturn className.slice(HIGHLIGHT_CLASS_PREFIX.length);\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction getScopeFormatter(scope: string, theme: HighlightTheme): HighlightFormatter | undefined {\n\tconst exact = theme[scope];\n\tif (exact) {\n\t\treturn exact;\n\t}\n\n\tconst dotIndex = scope.indexOf(\".\");\n\tif (dotIndex !== -1) {\n\t\tconst prefixFormatter = theme[scope.slice(0, dotIndex)];\n\t\tif (prefixFormatter) {\n\t\t\treturn prefixFormatter;\n\t\t}\n\t}\n\n\tconst dashIndex = scope.indexOf(\"-\");\n\tif (dashIndex !== -1) {\n\t\tconst prefixFormatter = theme[scope.slice(0, dashIndex)];\n\t\tif (prefixFormatter) {\n\t\t\treturn prefixFormatter;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction getActiveFormatter(scopes: Array<string | undefined>, theme: HighlightTheme): HighlightFormatter | undefined {\n\tfor (let i = scopes.length - 1; i >= 0; i--) {\n\t\tconst scope = scopes[i];\n\t\tif (!scope) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst formatter = getScopeFormatter(scope, theme);\n\t\tif (formatter) {\n\t\t\treturn formatter;\n\t\t}\n\t}\n\treturn theme.default;\n}\n\nfunction isSpanOpenTagStart(html: string, index: number): boolean {\n\tif (!html.startsWith(\"<span\", index)) {\n\t\treturn false;\n\t}\n\tconst nextChar = html[index + \"<span\".length];\n\treturn nextChar === \">\" || nextChar === \" \" || nextChar === \"\\t\" || nextChar === \"\\n\" || nextChar === \"\\r\";\n}\n\nexport function renderHighlightedHtml(html: string, theme: HighlightTheme = {}): string {\n\tlet output = \"\";\n\tlet textBuffer = \"\";\n\tconst scopes: Array<string | undefined> = [];\n\n\tconst flushText = () => {\n\t\tif (!textBuffer) {\n\t\t\treturn;\n\t\t}\n\t\tconst formatter = getActiveFormatter(scopes, theme);\n\t\toutput += formatter ? formatter(textBuffer) : textBuffer;\n\t\ttextBuffer = \"\";\n\t};\n\n\tlet index = 0;\n\twhile (index < html.length) {\n\t\tif (isSpanOpenTagStart(html, index)) {\n\t\t\tconst tagEndIndex = html.indexOf(\">\", index + 5);\n\t\t\tif (tagEndIndex !== -1) {\n\t\t\t\tflushText();\n\t\t\t\tconst tag = html.slice(index, tagEndIndex + 1);\n\t\t\t\tconst scope = getScopeFromSpanTag(tag);\n\t\t\t\tscopes.push(scope);\n\t\t\t\tindex = tagEndIndex + 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tif (html.startsWith(SPAN_CLOSE, index)) {\n\t\t\tflushText();\n\t\t\tif (scopes.length > 0) {\n\t\t\t\tscopes.pop();\n\t\t\t}\n\t\t\tindex += SPAN_CLOSE.length;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (html[index] === \"&\") {\n\t\t\tconst decoded = decodeHtmlEntityAt(html, index);\n\t\t\tif (decoded) {\n\t\t\t\ttextBuffer += decoded.text;\n\t\t\t\tindex += decoded.length;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\ttextBuffer += html[index];\n\t\tindex++;\n\t}\n\n\tflushText();\n\treturn output;\n}\n\nexport function highlight(code: string, options: HighlightOptions = {}): string {\n\tconst html = options.language\n\t\t? hljs.highlight(code, {\n\t\t\t\tlanguage: options.language,\n\t\t\t\tignoreIllegals: options.ignoreIllegals,\n\t\t\t}).value\n\t\t: hljs.highlightAuto(code, options.languageSubset).value;\n\treturn renderHighlightedHtml(html, options.theme);\n}\n\nexport function supportsLanguage(name: string): boolean {\n\treturn hljs.getLanguage(name) !== undefined;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax-highlight.js","sourceRoot":"","sources":["../../src/utils/syntax-highlight.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"syntax-highlight.js","sourceRoot":"","sources":["../../src/utils/syntax-highlight.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,cAAc,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAY/C,MAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAEvC,SAAS,mBAAmB,CAAC,GAAW;IACvC,MAAM,KAAK,GAAG,uCAAuC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChE,MAAM,UAAU,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,C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AAE,CAAC;IACZ,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,OAAO,GAAqB,EAAE;IACrE,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ;QAC5B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;YACrB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,cAAc,EAAE,OAAO,CAAC,cAAc;SACtC,CAAC,CAAC,KAAK;QACT,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC;IAC1D,OAAO,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC;AAC7C,CAAC","sourcesContent":["import hljs from \"highlight.js\";\nimport { decodeHtmlEntityAt } from \"./html.ts\";\n\nexport type HighlightFormatter = (text: string) => string;\nexport type HighlightTheme = Partial<Record<string, HighlightFormatter>>;\n\nexport interface HighlightOptions {\n\tlanguage?: string;\n\tignoreIllegals?: boolean;\n\tlanguageSubset?: string[];\n\ttheme?: HighlightTheme;\n}\n\nconst SPAN_CLOSE = \"</span>\";\nconst HIGHLIGHT_CLASS_PREFIX = \"hljs-\";\n\nfunction getScopeFromSpanTag(tag: string): string | undefined {\n\tconst match = /\\sclass\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)')/.exec(tag);\n\tconst classValue = match?.[1] ?? match?.[2];\n\tif (!classValue) {\n\t\treturn undefined;\n\t}\n\n\tfor (const className of classValue.split(/\\s+/)) {\n\t\tif (className.startsWith(HIGHLIGHT_CLASS_PREFIX)) {\n\t\t\treturn className.slice(HIGHLIGHT_CLASS_PREFIX.length);\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction getScopeFormatter(scope: string, theme: HighlightTheme): HighlightFormatter | undefined {\n\tconst exact = theme[scope];\n\tif (exact) {\n\t\treturn exact;\n\t}\n\n\tconst dotIndex = scope.indexOf(\".\");\n\tif (dotIndex !== -1) {\n\t\tconst prefixFormatter = theme[scope.slice(0, dotIndex)];\n\t\tif (prefixFormatter) {\n\t\t\treturn prefixFormatter;\n\t\t}\n\t}\n\n\tconst dashIndex = scope.indexOf(\"-\");\n\tif (dashIndex !== -1) {\n\t\tconst prefixFormatter = theme[scope.slice(0, dashIndex)];\n\t\tif (prefixFormatter) {\n\t\t\treturn prefixFormatter;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction getActiveFormatter(scopes: Array<string | undefined>, theme: HighlightTheme): HighlightFormatter | undefined {\n\tfor (let i = scopes.length - 1; i >= 0; i--) {\n\t\tconst scope = scopes[i];\n\t\tif (!scope) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst formatter = getScopeFormatter(scope, theme);\n\t\tif (formatter) {\n\t\t\treturn formatter;\n\t\t}\n\t}\n\treturn theme.default;\n}\n\nfunction isSpanOpenTagStart(html: string, index: number): boolean {\n\tif (!html.startsWith(\"<span\", index)) {\n\t\treturn false;\n\t}\n\tconst nextChar = html[index + \"<span\".length];\n\treturn nextChar === \">\" || nextChar === \" \" || nextChar === \"\\t\" || nextChar === \"\\n\" || nextChar === \"\\r\";\n}\n\nexport function renderHighlightedHtml(html: string, theme: HighlightTheme = {}): string {\n\tlet output = \"\";\n\tlet textBuffer = \"\";\n\tconst scopes: Array<string | undefined> = [];\n\n\tconst flushText = () => {\n\t\tif (!textBuffer) {\n\t\t\treturn;\n\t\t}\n\t\tconst formatter = getActiveFormatter(scopes, theme);\n\t\toutput += formatter ? formatter(textBuffer) : textBuffer;\n\t\ttextBuffer = \"\";\n\t};\n\n\tlet index = 0;\n\twhile (index < html.length) {\n\t\tif (isSpanOpenTagStart(html, index)) {\n\t\t\tconst tagEndIndex = html.indexOf(\">\", index + 5);\n\t\t\tif (tagEndIndex !== -1) {\n\t\t\t\tflushText();\n\t\t\t\tconst tag = html.slice(index, tagEndIndex + 1);\n\t\t\t\tconst scope = getScopeFromSpanTag(tag);\n\t\t\t\tscopes.push(scope);\n\t\t\t\tindex = tagEndIndex + 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tif (html.startsWith(SPAN_CLOSE, index)) {\n\t\t\tflushText();\n\t\t\tif (scopes.length > 0) {\n\t\t\t\tscopes.pop();\n\t\t\t}\n\t\t\tindex += SPAN_CLOSE.length;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (html[index] === \"&\") {\n\t\t\tconst decoded = decodeHtmlEntityAt(html, index);\n\t\t\tif (decoded) {\n\t\t\t\ttextBuffer += decoded.text;\n\t\t\t\tindex += decoded.length;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\ttextBuffer += html[index];\n\t\tindex++;\n\t}\n\n\tflushText();\n\treturn output;\n}\n\nexport function highlight(code: string, options: HighlightOptions = {}): string {\n\tconst html = options.language\n\t\t? hljs.highlight(code, {\n\t\t\t\tlanguage: options.language,\n\t\t\t\tignoreIllegals: options.ignoreIllegals,\n\t\t\t}).value\n\t\t: hljs.highlightAuto(code, options.languageSubset).value;\n\treturn renderHighlightedHtml(html, options.theme);\n}\n\nexport function supportsLanguage(name: string): boolean {\n\treturn hljs.getLanguage(name) !== undefined;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools-manager.d.ts","sourceRoot":"","sources":["../../src/utils/tools-manager.ts"],"names":[],"mappings":"AAoGA,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAsB5D;AAwQD,wBAAsB,UAAU,CAC9B,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,MAAM,GAAE,OAAe,GACtB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAuD7B","sourcesContent":["import chalk from \"chalk\";\nimport { type SpawnSyncReturns, spawnSync } from \"child_process\";\nimport {\n chmodSync,\n createWriteStream,\n existsSync,\n mkdirSync,\n readdirSync,\n renameSync,\n rmSync,\n} from \"fs\";\nimport { arch, platform } from \"os\";\nimport { join } from \"path\";\nimport { Readable } from \"stream\";\nimport { pipeline } from \"stream/promises\";\nimport { APP_NAME, ENV_OFFLINE, getBinDir, getEnvValue } from \"../config.ts\";\n\nconst TOOLS_DIR = getBinDir();\nconst NETWORK_TIMEOUT_MS = 10_000;\nconst DOWNLOAD_TIMEOUT_MS = 120_000;\n\nfunction isOfflineModeEnabled(): boolean {\n const value = getEnvValue(ENV_OFFLINE);\n if (!value) return false;\n return (\n value === \"1\" ||\n value.toLowerCase() === \"true\" ||\n value.toLowerCase() === \"yes\"\n );\n}\n\ninterface ToolConfig {\n name: string;\n repo: string; // GitHub repo (e.g., \"sharkdp/fd\")\n binaryName: string; // Name of the binary inside the archive\n systemBinaryNames?: string[]; // Alternative system command names to try before downloading\n tagPrefix: string; // Prefix for tags (e.g., \"v\" for v1.0.0, \"\" for 1.0.0)\n getAssetName: (\n version: string,\n plat: string,\n architecture: string,\n ) => string | null;\n}\n\nconst TOOLS: Record<string, ToolConfig> = {\n fd: {\n name: \"fd\",\n repo: \"sharkdp/fd\",\n binaryName: \"fd\",\n systemBinaryNames: [\"fd\", \"fdfind\"],\n tagPrefix: \"v\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-unknown-linux-gnu.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n rg: {\n name: \"ripgrep\",\n repo: \"BurntSushi/ripgrep\",\n binaryName: \"rg\",\n tagPrefix: \"\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n if (architecture === \"arm64\") {\n return `ripgrep-${version}-aarch64-unknown-linux-gnu.tar.gz`;\n }\n return `ripgrep-${version}-x86_64-unknown-linux-musl.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n};\n\n// Check if a command exists in PATH by trying to run it\nfunction commandExists(cmd: string): boolean {\n try {\n const result = spawnSync(cmd, [\"--version\"], { stdio: \"pipe\" });\n // Check for ENOENT error (command not found)\n return result.error === undefined || result.error === null;\n } catch {\n return false;\n }\n}\n\n// Get the path to a tool (system-wide or in our tools dir)\nexport function getToolPath(tool: \"fd\" | \"rg\"): string | null {\n const config = TOOLS[tool];\n if (!config) return null;\n\n // Check our tools directory first\n const localPath = join(\n TOOLS_DIR,\n config.binaryName + (platform() === \"win32\" ? \".exe\" : \"\"),\n );\n if (existsSync(localPath)) {\n return localPath;\n }\n\n // Check system PATH - if found, just return the command name (it's in PATH)\n const systemBinaryNames = config.systemBinaryNames ?? [config.binaryName];\n for (const systemBinaryName of systemBinaryNames) {\n if (commandExists(systemBinaryName)) {\n return systemBinaryName;\n }\n }\n\n return null;\n}\n\n// Fetch latest release version from GitHub\nasync function getLatestVersion(repo: string): Promise<string> {\n const response = await fetch(\n `https://api.github.com/repos/${repo}/releases/latest`,\n {\n headers: { \"User-Agent\": APP_NAME },\n signal: AbortSignal.timeout(NETWORK_TIMEOUT_MS),\n },\n );\n\n if (!response.ok) {\n throw new Error(`GitHub API error: ${response.status}`);\n }\n\n const data = (await response.json()) as { tag_name: string };\n return data.tag_name.replace(/^v/, \"\");\n}\n\n// Download a file from URL\nasync function downloadFile(url: string, dest: string): Promise<void> {\n const response = await fetch(url, {\n signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to download: ${response.status}`);\n }\n\n if (!response.body) {\n throw new Error(\"No response body\");\n }\n\n const fileStream = createWriteStream(dest);\n await pipeline(Readable.fromWeb(response.body), fileStream);\n}\n\nfunction findBinaryRecursively(\n rootDir: string,\n binaryFileName: string,\n): string | null {\n const stack: string[] = [rootDir];\n\n while (stack.length > 0) {\n const currentDir = stack.pop();\n if (!currentDir) continue;\n\n const entries = readdirSync(currentDir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(currentDir, entry.name);\n if (entry.isFile() && entry.name === binaryFileName) {\n return fullPath;\n }\n if (entry.isDirectory()) {\n stack.push(fullPath);\n }\n }\n }\n\n return null;\n}\n\nfunction formatSpawnFailure(result: SpawnSyncReturns<Buffer>): string {\n if (result.error?.message) {\n return result.error.message;\n }\n const stderr = result.stderr?.toString().trim();\n if (stderr) {\n return stderr;\n }\n const stdout = result.stdout?.toString().trim();\n if (stdout) {\n return stdout;\n }\n return `exit status ${result.status ?? \"unknown\"}`;\n}\n\nfunction runExtractionCommand(command: string, args: string[]): string | null {\n const result = spawnSync(command, args, { stdio: \"pipe\" });\n if (!result.error && result.status === 0) {\n return null;\n }\n return `${command}: ${formatSpawnFailure(result)}`;\n}\n\nfunction extractTarGzArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failure = runExtractionCommand(\"tar\", [\n \"xzf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (failure) {\n throw new Error(`Failed to extract ${assetName}: ${failure}`);\n }\n}\n\nfunction getWindowsTarCommand(): string {\n const systemRoot = process.env.SystemRoot ?? process.env.WINDIR;\n if (systemRoot) {\n const systemTar = join(systemRoot, \"System32\", \"tar.exe\");\n if (existsSync(systemTar)) {\n return systemTar;\n }\n }\n return \"tar.exe\";\n}\n\nfunction extractZipArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failures: string[] = [];\n\n if (platform() === \"win32\") {\n // Windows ships bsdtar as tar.exe, which supports zip files. Prefer the\n // System32 binary over Git Bash's GNU tar, which does not handle zip archives.\n const tarFailure = runExtractionCommand(getWindowsTarCommand(), [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n\n const script =\n \"& { param($archive, $destination) $ErrorActionPreference = 'Stop'; Expand-Archive -LiteralPath $archive -DestinationPath $destination -Force }\";\n const powershellFailure = runExtractionCommand(\"powershell.exe\", [\n \"-NoLogo\",\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-ExecutionPolicy\",\n \"Bypass\",\n \"-Command\",\n script,\n archivePath,\n extractDir,\n ]);\n if (!powershellFailure) return;\n failures.push(powershellFailure);\n } else {\n const unzipFailure = runExtractionCommand(\"unzip\", [\n \"-q\",\n archivePath,\n \"-d\",\n extractDir,\n ]);\n if (!unzipFailure) return;\n failures.push(unzipFailure);\n\n const tarFailure = runExtractionCommand(\"tar\", [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n }\n\n throw new Error(`Failed to extract ${assetName}: ${failures.join(\"; \")}`);\n}\n\n// Download and install a tool\nasync function downloadTool(tool: \"fd\" | \"rg\"): Promise<string> {\n const config = TOOLS[tool];\n if (!config) throw new Error(`Unknown tool: ${tool}`);\n\n const plat = platform();\n const architecture = arch();\n\n // Get latest version\n const version = await getLatestVersion(config.repo);\n\n // Get asset name for this platform\n const assetName = config.getAssetName(version, plat, architecture);\n if (!assetName) {\n throw new Error(`Unsupported platform: ${plat}/${architecture}`);\n }\n\n // Create tools directory\n mkdirSync(TOOLS_DIR, { recursive: true });\n\n const downloadUrl = `https://github.com/${config.repo}/releases/download/${config.tagPrefix}${version}/${assetName}`;\n const archivePath = join(TOOLS_DIR, assetName);\n const binaryExt = plat === \"win32\" ? \".exe\" : \"\";\n const binaryPath = join(TOOLS_DIR, config.binaryName + binaryExt);\n\n // Download\n await downloadFile(downloadUrl, archivePath);\n\n // Extract into a unique temp directory. fd and rg downloads can run concurrently\n // during startup, so sharing a fixed directory causes races.\n const extractDir = join(\n TOOLS_DIR,\n `extract_tmp_${config.binaryName}_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`,\n );\n mkdirSync(extractDir, { recursive: true });\n\n try {\n if (assetName.endsWith(\".tar.gz\")) {\n extractTarGzArchive(archivePath, extractDir, assetName);\n } else if (assetName.endsWith(\".zip\")) {\n extractZipArchive(archivePath, extractDir, assetName);\n } else {\n throw new Error(`Unsupported archive format: ${assetName}`);\n }\n\n // Find the binary in extracted files. Some archives contain files directly\n // at root, others nest under a versioned subdirectory.\n const binaryFileName = config.binaryName + binaryExt;\n const extractedDir = join(\n extractDir,\n assetName.replace(/\\.(tar\\.gz|zip)$/, \"\"),\n );\n const extractedBinaryCandidates = [\n join(extractedDir, binaryFileName),\n join(extractDir, binaryFileName),\n ];\n let extractedBinary = extractedBinaryCandidates.find((candidate) =>\n existsSync(candidate),\n );\n\n if (!extractedBinary) {\n extractedBinary =\n findBinaryRecursively(extractDir, binaryFileName) ?? undefined;\n }\n\n if (extractedBinary) {\n renameSync(extractedBinary, binaryPath);\n } else {\n throw new Error(\n `Binary not found in archive: expected ${binaryFileName} under ${extractDir}`,\n );\n }\n\n // Make executable (Unix only)\n if (plat !== \"win32\") {\n chmodSync(binaryPath, 0o755);\n }\n } finally {\n // Cleanup\n rmSync(archivePath, { force: true });\n rmSync(extractDir, { recursive: true, force: true });\n }\n\n return binaryPath;\n}\n\n// Termux package names for tools\nconst TERMUX_PACKAGES: Record<string, string> = {\n fd: \"fd\",\n rg: \"ripgrep\",\n};\n\n// Ensure a tool is available, downloading if necessary\n// Returns the path to the tool, or null if unavailable\nexport async function ensureTool(\n tool: \"fd\" | \"rg\",\n silent: boolean = false,\n): Promise<string | undefined> {\n const existingPath = getToolPath(tool);\n if (existingPath) {\n return existingPath;\n }\n\n const config = TOOLS[tool];\n if (!config) return undefined;\n\n if (isOfflineModeEnabled()) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Offline mode enabled, skipping download.`,\n ),\n );\n }\n return undefined;\n }\n\n // On Android/Termux, Linux binaries don't work due to Bionic libc incompatibility.\n // Users must install via pkg.\n if (platform() === \"android\") {\n const pkgName = TERMUX_PACKAGES[tool] ?? tool;\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Install with: pkg install ${pkgName}`,\n ),\n );\n }\n return undefined;\n }\n\n // Tool not found - download it\n if (!silent) {\n console.log(chalk.dim(`${config.name} not found. Downloading...`));\n }\n\n try {\n const path = await downloadTool(tool);\n if (!silent) {\n console.log(chalk.dim(`${config.name} installed to ${path}`));\n }\n return path;\n } catch (e) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `Failed to download ${config.name}: ${e instanceof Error ? e.message : e}`,\n ),\n );\n }\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tools-manager.d.ts","sourceRoot":"","sources":["../../src/utils/tools-manager.ts"],"names":[],"mappings":"AAkGA,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAsB5D;AAuQD,wBAAsB,UAAU,CAC9B,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,MAAM,GAAE,OAAe,GACtB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAuD7B","sourcesContent":["import chalk from \"chalk\";\nimport { type SpawnSyncReturns, spawnSync } from \"child_process\";\nimport {\n chmodSync,\n existsSync,\n mkdirSync,\n readdirSync,\n renameSync,\n rmSync,\n} from \"fs\";\nimport { writeFile } from \"fs/promises\";\nimport { arch, platform } from \"os\";\nimport { join } from \"path\";\nimport { APP_NAME, ENV_OFFLINE, getBinDir, getEnvValue } from \"../config.ts\";\n\nconst TOOLS_DIR = getBinDir();\nconst NETWORK_TIMEOUT_MS = 10_000;\nconst DOWNLOAD_TIMEOUT_MS = 120_000;\n\nfunction isOfflineModeEnabled(): boolean {\n const value = getEnvValue(ENV_OFFLINE);\n if (!value) return false;\n return (\n value === \"1\" ||\n value.toLowerCase() === \"true\" ||\n value.toLowerCase() === \"yes\"\n );\n}\n\ninterface ToolConfig {\n name: string;\n repo: string; // GitHub repo (e.g., \"sharkdp/fd\")\n binaryName: string; // Name of the binary inside the archive\n systemBinaryNames?: string[]; // Alternative system command names to try before downloading\n tagPrefix: string; // Prefix for tags (e.g., \"v\" for v1.0.0, \"\" for 1.0.0)\n getAssetName: (\n version: string,\n plat: string,\n architecture: string,\n ) => string | null;\n}\n\nconst TOOLS: Record<string, ToolConfig> = {\n fd: {\n name: \"fd\",\n repo: \"sharkdp/fd\",\n binaryName: \"fd\",\n systemBinaryNames: [\"fd\", \"fdfind\"],\n tagPrefix: \"v\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-unknown-linux-gnu.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n rg: {\n name: \"ripgrep\",\n repo: \"BurntSushi/ripgrep\",\n binaryName: \"rg\",\n tagPrefix: \"\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n if (architecture === \"arm64\") {\n return `ripgrep-${version}-aarch64-unknown-linux-gnu.tar.gz`;\n }\n return `ripgrep-${version}-x86_64-unknown-linux-musl.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n};\n\n// Check if a command exists in PATH by trying to run it\nfunction commandExists(cmd: string): boolean {\n try {\n const result = spawnSync(cmd, [\"--version\"], { stdio: \"pipe\" });\n // Check for ENOENT error (command not found)\n return result.error === undefined || result.error === null;\n } catch {\n return false;\n }\n}\n\n// Get the path to a tool (system-wide or in our tools dir)\nexport function getToolPath(tool: \"fd\" | \"rg\"): string | null {\n const config = TOOLS[tool];\n if (!config) return null;\n\n // Check our tools directory first\n const localPath = join(\n TOOLS_DIR,\n config.binaryName + (platform() === \"win32\" ? \".exe\" : \"\"),\n );\n if (existsSync(localPath)) {\n return localPath;\n }\n\n // Check system PATH - if found, just return the command name (it's in PATH)\n const systemBinaryNames = config.systemBinaryNames ?? [config.binaryName];\n for (const systemBinaryName of systemBinaryNames) {\n if (commandExists(systemBinaryName)) {\n return systemBinaryName;\n }\n }\n\n return null;\n}\n\n// Fetch latest release version from GitHub\nasync function getLatestVersion(repo: string): Promise<string> {\n const response = await fetch(\n `https://api.github.com/repos/${repo}/releases/latest`,\n {\n headers: { \"User-Agent\": APP_NAME },\n signal: AbortSignal.timeout(NETWORK_TIMEOUT_MS),\n },\n );\n\n if (!response.ok) {\n throw new Error(`GitHub API error: ${response.status}`);\n }\n\n const data = (await response.json()) as { tag_name: string };\n return data.tag_name.replace(/^v/, \"\");\n}\n\n// Download a file from URL\nasync function downloadFile(url: string, dest: string): Promise<void> {\n const response = await fetch(url, {\n signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to download: ${response.status}`);\n }\n\n if (!response.body) {\n throw new Error(\"No response body\");\n }\n\n await writeFile(dest, Buffer.from(await response.arrayBuffer()));\n}\n\nfunction findBinaryRecursively(\n rootDir: string,\n binaryFileName: string,\n): string | null {\n const stack: string[] = [rootDir];\n\n while (stack.length > 0) {\n const currentDir = stack.pop();\n if (!currentDir) continue;\n\n const entries = readdirSync(currentDir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(currentDir, entry.name);\n if (entry.isFile() && entry.name === binaryFileName) {\n return fullPath;\n }\n if (entry.isDirectory()) {\n stack.push(fullPath);\n }\n }\n }\n\n return null;\n}\n\nfunction formatSpawnFailure(result: SpawnSyncReturns<Buffer>): string {\n if (result.error?.message) {\n return result.error.message;\n }\n const stderr = result.stderr?.toString().trim();\n if (stderr) {\n return stderr;\n }\n const stdout = result.stdout?.toString().trim();\n if (stdout) {\n return stdout;\n }\n return `exit status ${result.status ?? \"unknown\"}`;\n}\n\nfunction runExtractionCommand(command: string, args: string[]): string | null {\n const result = spawnSync(command, args, { stdio: \"pipe\" });\n if (!result.error && result.status === 0) {\n return null;\n }\n return `${command}: ${formatSpawnFailure(result)}`;\n}\n\nfunction extractTarGzArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failure = runExtractionCommand(\"tar\", [\n \"xzf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (failure) {\n throw new Error(`Failed to extract ${assetName}: ${failure}`);\n }\n}\n\nfunction getWindowsTarCommand(): string {\n const systemRoot = process.env.SystemRoot ?? process.env.WINDIR;\n if (systemRoot) {\n const systemTar = join(systemRoot, \"System32\", \"tar.exe\");\n if (existsSync(systemTar)) {\n return systemTar;\n }\n }\n return \"tar.exe\";\n}\n\nfunction extractZipArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failures: string[] = [];\n\n if (platform() === \"win32\") {\n // Windows ships bsdtar as tar.exe, which supports zip files. Prefer the\n // System32 binary over Git Bash's GNU tar, which does not handle zip archives.\n const tarFailure = runExtractionCommand(getWindowsTarCommand(), [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n\n const script =\n \"& { param($archive, $destination) $ErrorActionPreference = 'Stop'; Expand-Archive -LiteralPath $archive -DestinationPath $destination -Force }\";\n const powershellFailure = runExtractionCommand(\"powershell.exe\", [\n \"-NoLogo\",\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-ExecutionPolicy\",\n \"Bypass\",\n \"-Command\",\n script,\n archivePath,\n extractDir,\n ]);\n if (!powershellFailure) return;\n failures.push(powershellFailure);\n } else {\n const unzipFailure = runExtractionCommand(\"unzip\", [\n \"-q\",\n archivePath,\n \"-d\",\n extractDir,\n ]);\n if (!unzipFailure) return;\n failures.push(unzipFailure);\n\n const tarFailure = runExtractionCommand(\"tar\", [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n }\n\n throw new Error(`Failed to extract ${assetName}: ${failures.join(\"; \")}`);\n}\n\n// Download and install a tool\nasync function downloadTool(tool: \"fd\" | \"rg\"): Promise<string> {\n const config = TOOLS[tool];\n if (!config) throw new Error(`Unknown tool: ${tool}`);\n\n const plat = platform();\n const architecture = arch();\n\n // Get latest version\n const version = await getLatestVersion(config.repo);\n\n // Get asset name for this platform\n const assetName = config.getAssetName(version, plat, architecture);\n if (!assetName) {\n throw new Error(`Unsupported platform: ${plat}/${architecture}`);\n }\n\n // Create tools directory\n mkdirSync(TOOLS_DIR, { recursive: true });\n\n const downloadUrl = `https://github.com/${config.repo}/releases/download/${config.tagPrefix}${version}/${assetName}`;\n const archivePath = join(TOOLS_DIR, assetName);\n const binaryExt = plat === \"win32\" ? \".exe\" : \"\";\n const binaryPath = join(TOOLS_DIR, config.binaryName + binaryExt);\n\n // Download\n await downloadFile(downloadUrl, archivePath);\n\n // Extract into a unique temp directory. fd and rg downloads can run concurrently\n // during startup, so sharing a fixed directory causes races.\n const extractDir = join(\n TOOLS_DIR,\n `extract_tmp_${config.binaryName}_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`,\n );\n mkdirSync(extractDir, { recursive: true });\n\n try {\n if (assetName.endsWith(\".tar.gz\")) {\n extractTarGzArchive(archivePath, extractDir, assetName);\n } else if (assetName.endsWith(\".zip\")) {\n extractZipArchive(archivePath, extractDir, assetName);\n } else {\n throw new Error(`Unsupported archive format: ${assetName}`);\n }\n\n // Find the binary in extracted files. Some archives contain files directly\n // at root, others nest under a versioned subdirectory.\n const binaryFileName = config.binaryName + binaryExt;\n const extractedDir = join(\n extractDir,\n assetName.replace(/\\.(tar\\.gz|zip)$/, \"\"),\n );\n const extractedBinaryCandidates = [\n join(extractedDir, binaryFileName),\n join(extractDir, binaryFileName),\n ];\n let extractedBinary = extractedBinaryCandidates.find((candidate) =>\n existsSync(candidate),\n );\n\n if (!extractedBinary) {\n extractedBinary =\n findBinaryRecursively(extractDir, binaryFileName) ?? undefined;\n }\n\n if (extractedBinary) {\n renameSync(extractedBinary, binaryPath);\n } else {\n throw new Error(\n `Binary not found in archive: expected ${binaryFileName} under ${extractDir}`,\n );\n }\n\n // Make executable (Unix only)\n if (plat !== \"win32\") {\n chmodSync(binaryPath, 0o755);\n }\n } finally {\n // Cleanup\n rmSync(archivePath, { force: true });\n rmSync(extractDir, { recursive: true, force: true });\n }\n\n return binaryPath;\n}\n\n// Termux package names for tools\nconst TERMUX_PACKAGES: Record<string, string> = {\n fd: \"fd\",\n rg: \"ripgrep\",\n};\n\n// Ensure a tool is available, downloading if necessary\n// Returns the path to the tool, or null if unavailable\nexport async function ensureTool(\n tool: \"fd\" | \"rg\",\n silent: boolean = false,\n): Promise<string | undefined> {\n const existingPath = getToolPath(tool);\n if (existingPath) {\n return existingPath;\n }\n\n const config = TOOLS[tool];\n if (!config) return undefined;\n\n if (isOfflineModeEnabled()) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Offline mode enabled, skipping download.`,\n ),\n );\n }\n return undefined;\n }\n\n // On Android/Termux, Linux binaries don't work due to Bionic libc incompatibility.\n // Users must install via pkg.\n if (platform() === \"android\") {\n const pkgName = TERMUX_PACKAGES[tool] ?? tool;\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Install with: pkg install ${pkgName}`,\n ),\n );\n }\n return undefined;\n }\n\n // Tool not found - download it\n if (!silent) {\n console.log(chalk.dim(`${config.name} not found. Downloading...`));\n }\n\n try {\n const path = await downloadTool(tool);\n if (!silent) {\n console.log(chalk.dim(`${config.name} installed to ${path}`));\n }\n return path;\n } catch (e) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `Failed to download ${config.name}: ${e instanceof Error ? e.message : e}`,\n ),\n );\n }\n return undefined;\n }\n}\n"]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { spawnSync } from "child_process";
|
|
3
|
-
import { chmodSync,
|
|
3
|
+
import { chmodSync, existsSync, mkdirSync, readdirSync, renameSync, rmSync, } from "fs";
|
|
4
|
+
import { writeFile } from "fs/promises";
|
|
4
5
|
import { arch, platform } from "os";
|
|
5
6
|
import { join } from "path";
|
|
6
|
-
import { Readable } from "stream";
|
|
7
|
-
import { pipeline } from "stream/promises";
|
|
8
7
|
import { APP_NAME, ENV_OFFLINE, getBinDir, getEnvValue } from "../config.js";
|
|
9
8
|
const TOOLS_DIR = getBinDir();
|
|
10
9
|
const NETWORK_TIMEOUT_MS = 10_000;
|
|
@@ -117,8 +116,7 @@ async function downloadFile(url, dest) {
|
|
|
117
116
|
if (!response.body) {
|
|
118
117
|
throw new Error("No response body");
|
|
119
118
|
}
|
|
120
|
-
|
|
121
|
-
await pipeline(Readable.fromWeb(response.body), fileStream);
|
|
119
|
+
await writeFile(dest, Buffer.from(await response.arrayBuffer()));
|
|
122
120
|
}
|
|
123
121
|
function findBinaryRecursively(rootDir, binaryFileName) {
|
|
124
122
|
const stack = [rootDir];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools-manager.js","sourceRoot":"","sources":["../../src/utils/tools-manager.ts"],"names":[],"mappings":"AAAA,OAAO,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O,SAAS,CAAC;IACnB,CAAC;IAED,+BAA+B;IAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,4BAA4B,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,iBAAiB,IAAI,EAAE,CAAC,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,MAAM,CACV,sBAAsB,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAC3E,CACF,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import chalk from \"chalk\";\nimport { type SpawnSyncReturns, spawnSync } from \"child_process\";\nimport {\n chmodSync,\n createWriteStream,\n existsSync,\n mkdirSync,\n readdirSync,\n renameSync,\n rmSync,\n} from \"fs\";\nimport { arch, platform } from \"os\";\nimport { join } from \"path\";\nimport { Readable } from \"stream\";\nimport { pipeline } from \"stream/promises\";\nimport { APP_NAME, ENV_OFFLINE, getBinDir, getEnvValue } from \"../config.ts\";\n\nconst TOOLS_DIR = getBinDir();\nconst NETWORK_TIMEOUT_MS = 10_000;\nconst DOWNLOAD_TIMEOUT_MS = 120_000;\n\nfunction isOfflineModeEnabled(): boolean {\n const value = getEnvValue(ENV_OFFLINE);\n if (!value) return false;\n return (\n value === \"1\" ||\n value.toLowerCase() === \"true\" ||\n value.toLowerCase() === \"yes\"\n );\n}\n\ninterface ToolConfig {\n name: string;\n repo: string; // GitHub repo (e.g., \"sharkdp/fd\")\n binaryName: string; // Name of the binary inside the archive\n systemBinaryNames?: string[]; // Alternative system command names to try before downloading\n tagPrefix: string; // Prefix for tags (e.g., \"v\" for v1.0.0, \"\" for 1.0.0)\n getAssetName: (\n version: string,\n plat: string,\n architecture: string,\n ) => string | null;\n}\n\nconst TOOLS: Record<string, ToolConfig> = {\n fd: {\n name: \"fd\",\n repo: \"sharkdp/fd\",\n binaryName: \"fd\",\n systemBinaryNames: [\"fd\", \"fdfind\"],\n tagPrefix: \"v\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-unknown-linux-gnu.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n rg: {\n name: \"ripgrep\",\n repo: \"BurntSushi/ripgrep\",\n binaryName: \"rg\",\n tagPrefix: \"\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n if (architecture === \"arm64\") {\n return `ripgrep-${version}-aarch64-unknown-linux-gnu.tar.gz`;\n }\n return `ripgrep-${version}-x86_64-unknown-linux-musl.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n};\n\n// Check if a command exists in PATH by trying to run it\nfunction commandExists(cmd: string): boolean {\n try {\n const result = spawnSync(cmd, [\"--version\"], { stdio: \"pipe\" });\n // Check for ENOENT error (command not found)\n return result.error === undefined || result.error === null;\n } catch {\n return false;\n }\n}\n\n// Get the path to a tool (system-wide or in our tools dir)\nexport function getToolPath(tool: \"fd\" | \"rg\"): string | null {\n const config = TOOLS[tool];\n if (!config) return null;\n\n // Check our tools directory first\n const localPath = join(\n TOOLS_DIR,\n config.binaryName + (platform() === \"win32\" ? \".exe\" : \"\"),\n );\n if (existsSync(localPath)) {\n return localPath;\n }\n\n // Check system PATH - if found, just return the command name (it's in PATH)\n const systemBinaryNames = config.systemBinaryNames ?? [config.binaryName];\n for (const systemBinaryName of systemBinaryNames) {\n if (commandExists(systemBinaryName)) {\n return systemBinaryName;\n }\n }\n\n return null;\n}\n\n// Fetch latest release version from GitHub\nasync function getLatestVersion(repo: string): Promise<string> {\n const response = await fetch(\n `https://api.github.com/repos/${repo}/releases/latest`,\n {\n headers: { \"User-Agent\": APP_NAME },\n signal: AbortSignal.timeout(NETWORK_TIMEOUT_MS),\n },\n );\n\n if (!response.ok) {\n throw new Error(`GitHub API error: ${response.status}`);\n }\n\n const data = (await response.json()) as { tag_name: string };\n return data.tag_name.replace(/^v/, \"\");\n}\n\n// Download a file from URL\nasync function downloadFile(url: string, dest: string): Promise<void> {\n const response = await fetch(url, {\n signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to download: ${response.status}`);\n }\n\n if (!response.body) {\n throw new Error(\"No response body\");\n }\n\n const fileStream = createWriteStream(dest);\n await pipeline(Readable.fromWeb(response.body), fileStream);\n}\n\nfunction findBinaryRecursively(\n rootDir: string,\n binaryFileName: string,\n): string | null {\n const stack: string[] = [rootDir];\n\n while (stack.length > 0) {\n const currentDir = stack.pop();\n if (!currentDir) continue;\n\n const entries = readdirSync(currentDir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(currentDir, entry.name);\n if (entry.isFile() && entry.name === binaryFileName) {\n return fullPath;\n }\n if (entry.isDirectory()) {\n stack.push(fullPath);\n }\n }\n }\n\n return null;\n}\n\nfunction formatSpawnFailure(result: SpawnSyncReturns<Buffer>): string {\n if (result.error?.message) {\n return result.error.message;\n }\n const stderr = result.stderr?.toString().trim();\n if (stderr) {\n return stderr;\n }\n const stdout = result.stdout?.toString().trim();\n if (stdout) {\n return stdout;\n }\n return `exit status ${result.status ?? \"unknown\"}`;\n}\n\nfunction runExtractionCommand(command: string, args: string[]): string | null {\n const result = spawnSync(command, args, { stdio: \"pipe\" });\n if (!result.error && result.status === 0) {\n return null;\n }\n return `${command}: ${formatSpawnFailure(result)}`;\n}\n\nfunction extractTarGzArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failure = runExtractionCommand(\"tar\", [\n \"xzf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (failure) {\n throw new Error(`Failed to extract ${assetName}: ${failure}`);\n }\n}\n\nfunction getWindowsTarCommand(): string {\n const systemRoot = process.env.SystemRoot ?? process.env.WINDIR;\n if (systemRoot) {\n const systemTar = join(systemRoot, \"System32\", \"tar.exe\");\n if (existsSync(systemTar)) {\n return systemTar;\n }\n }\n return \"tar.exe\";\n}\n\nfunction extractZipArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failures: string[] = [];\n\n if (platform() === \"win32\") {\n // Windows ships bsdtar as tar.exe, which supports zip files. Prefer the\n // System32 binary over Git Bash's GNU tar, which does not handle zip archives.\n const tarFailure = runExtractionCommand(getWindowsTarCommand(), [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n\n const script =\n \"& { param($archive, $destination) $ErrorActionPreference = 'Stop'; Expand-Archive -LiteralPath $archive -DestinationPath $destination -Force }\";\n const powershellFailure = runExtractionCommand(\"powershell.exe\", [\n \"-NoLogo\",\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-ExecutionPolicy\",\n \"Bypass\",\n \"-Command\",\n script,\n archivePath,\n extractDir,\n ]);\n if (!powershellFailure) return;\n failures.push(powershellFailure);\n } else {\n const unzipFailure = runExtractionCommand(\"unzip\", [\n \"-q\",\n archivePath,\n \"-d\",\n extractDir,\n ]);\n if (!unzipFailure) return;\n failures.push(unzipFailure);\n\n const tarFailure = runExtractionCommand(\"tar\", [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n }\n\n throw new Error(`Failed to extract ${assetName}: ${failures.join(\"; \")}`);\n}\n\n// Download and install a tool\nasync function downloadTool(tool: \"fd\" | \"rg\"): Promise<string> {\n const config = TOOLS[tool];\n if (!config) throw new Error(`Unknown tool: ${tool}`);\n\n const plat = platform();\n const architecture = arch();\n\n // Get latest version\n const version = await getLatestVersion(config.repo);\n\n // Get asset name for this platform\n const assetName = config.getAssetName(version, plat, architecture);\n if (!assetName) {\n throw new Error(`Unsupported platform: ${plat}/${architecture}`);\n }\n\n // Create tools directory\n mkdirSync(TOOLS_DIR, { recursive: true });\n\n const downloadUrl = `https://github.com/${config.repo}/releases/download/${config.tagPrefix}${version}/${assetName}`;\n const archivePath = join(TOOLS_DIR, assetName);\n const binaryExt = plat === \"win32\" ? \".exe\" : \"\";\n const binaryPath = join(TOOLS_DIR, config.binaryName + binaryExt);\n\n // Download\n await downloadFile(downloadUrl, archivePath);\n\n // Extract into a unique temp directory. fd and rg downloads can run concurrently\n // during startup, so sharing a fixed directory causes races.\n const extractDir = join(\n TOOLS_DIR,\n `extract_tmp_${config.binaryName}_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`,\n );\n mkdirSync(extractDir, { recursive: true });\n\n try {\n if (assetName.endsWith(\".tar.gz\")) {\n extractTarGzArchive(archivePath, extractDir, assetName);\n } else if (assetName.endsWith(\".zip\")) {\n extractZipArchive(archivePath, extractDir, assetName);\n } else {\n throw new Error(`Unsupported archive format: ${assetName}`);\n }\n\n // Find the binary in extracted files. Some archives contain files directly\n // at root, others nest under a versioned subdirectory.\n const binaryFileName = config.binaryName + binaryExt;\n const extractedDir = join(\n extractDir,\n assetName.replace(/\\.(tar\\.gz|zip)$/, \"\"),\n );\n const extractedBinaryCandidates = [\n join(extractedDir, binaryFileName),\n join(extractDir, binaryFileName),\n ];\n let extractedBinary = extractedBinaryCandidates.find((candidate) =>\n existsSync(candidate),\n );\n\n if (!extractedBinary) {\n extractedBinary =\n findBinaryRecursively(extractDir, binaryFileName) ?? undefined;\n }\n\n if (extractedBinary) {\n renameSync(extractedBinary, binaryPath);\n } else {\n throw new Error(\n `Binary not found in archive: expected ${binaryFileName} under ${extractDir}`,\n );\n }\n\n // Make executable (Unix only)\n if (plat !== \"win32\") {\n chmodSync(binaryPath, 0o755);\n }\n } finally {\n // Cleanup\n rmSync(archivePath, { force: true });\n rmSync(extractDir, { recursive: true, force: true });\n }\n\n return binaryPath;\n}\n\n// Termux package names for tools\nconst TERMUX_PACKAGES: Record<string, string> = {\n fd: \"fd\",\n rg: \"ripgrep\",\n};\n\n// Ensure a tool is available, downloading if necessary\n// Returns the path to the tool, or null if unavailable\nexport async function ensureTool(\n tool: \"fd\" | \"rg\",\n silent: boolean = false,\n): Promise<string | undefined> {\n const existingPath = getToolPath(tool);\n if (existingPath) {\n return existingPath;\n }\n\n const config = TOOLS[tool];\n if (!config) return undefined;\n\n if (isOfflineModeEnabled()) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Offline mode enabled, skipping download.`,\n ),\n );\n }\n return undefined;\n }\n\n // On Android/Termux, Linux binaries don't work due to Bionic libc incompatibility.\n // Users must install via pkg.\n if (platform() === \"android\") {\n const pkgName = TERMUX_PACKAGES[tool] ?? tool;\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Install with: pkg install ${pkgName}`,\n ),\n );\n }\n return undefined;\n }\n\n // Tool not found - download it\n if (!silent) {\n console.log(chalk.dim(`${config.name} not found. Downloading...`));\n }\n\n try {\n const path = await downloadTool(tool);\n if (!silent) {\n console.log(chalk.dim(`${config.name} installed to ${path}`));\n }\n return path;\n } catch (e) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `Failed to download ${config.name}: ${e instanceof Error ? e.message : e}`,\n ),\n );\n }\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tools-manager.js","sourceRoot":"","sources":["../../src/utils/tools-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAyB,SAAS,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,MAAM,GACP,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE7E,MAAM,SAAS,GAAG,SAAS,EAAE,CAAC;AAC9B,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,mBAAmB,GAAG,OAAO,CAAC;AAEpC,SAAS,oBAAoB;IAC3B,MAAM,KAAK,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;IACvC,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,OAAO,CACL,KAAK,KAAK,GAAG;QACb,KAAK,CAAC,WAAW,EAAE,KAAK,MAAM;QAC9B,KAAK,CAAC,WAAW,EAAE,KAAK,KAAK,CAC9B,CAAC;AACJ,CAAC;AAeD,MAAM,KAAK,GAA+B;IACxC,EAAE,EAAE;QACF,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,YAAY;QACl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Ae,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;QAC9C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,MAAM,CACV,GAAG,MAAM,CAAC,IAAI,yCAAyC,OAAO,EAAE,CACjE,CACF,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,+BAA+B;IAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,4BAA4B,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,iBAAiB,IAAI,EAAE,CAAC,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,MAAM,CACV,sBAAsB,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAC3E,CACF,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import chalk from \"chalk\";\nimport { type SpawnSyncReturns, spawnSync } from \"child_process\";\nimport {\n chmodSync,\n existsSync,\n mkdirSync,\n readdirSync,\n renameSync,\n rmSync,\n} from \"fs\";\nimport { writeFile } from \"fs/promises\";\nimport { arch, platform } from \"os\";\nimport { join } from \"path\";\nimport { APP_NAME, ENV_OFFLINE, getBinDir, getEnvValue } from \"../config.ts\";\n\nconst TOOLS_DIR = getBinDir();\nconst NETWORK_TIMEOUT_MS = 10_000;\nconst DOWNLOAD_TIMEOUT_MS = 120_000;\n\nfunction isOfflineModeEnabled(): boolean {\n const value = getEnvValue(ENV_OFFLINE);\n if (!value) return false;\n return (\n value === \"1\" ||\n value.toLowerCase() === \"true\" ||\n value.toLowerCase() === \"yes\"\n );\n}\n\ninterface ToolConfig {\n name: string;\n repo: string; // GitHub repo (e.g., \"sharkdp/fd\")\n binaryName: string; // Name of the binary inside the archive\n systemBinaryNames?: string[]; // Alternative system command names to try before downloading\n tagPrefix: string; // Prefix for tags (e.g., \"v\" for v1.0.0, \"\" for 1.0.0)\n getAssetName: (\n version: string,\n plat: string,\n architecture: string,\n ) => string | null;\n}\n\nconst TOOLS: Record<string, ToolConfig> = {\n fd: {\n name: \"fd\",\n repo: \"sharkdp/fd\",\n binaryName: \"fd\",\n systemBinaryNames: [\"fd\", \"fdfind\"],\n tagPrefix: \"v\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-unknown-linux-gnu.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `fd-v${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n rg: {\n name: \"ripgrep\",\n repo: \"BurntSushi/ripgrep\",\n binaryName: \"rg\",\n tagPrefix: \"\",\n getAssetName: (version, plat, architecture) => {\n if (plat === \"darwin\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-apple-darwin.tar.gz`;\n } else if (plat === \"linux\") {\n if (architecture === \"arm64\") {\n return `ripgrep-${version}-aarch64-unknown-linux-gnu.tar.gz`;\n }\n return `ripgrep-${version}-x86_64-unknown-linux-musl.tar.gz`;\n } else if (plat === \"win32\") {\n const archStr = architecture === \"arm64\" ? \"aarch64\" : \"x86_64\";\n return `ripgrep-${version}-${archStr}-pc-windows-msvc.zip`;\n }\n return null;\n },\n },\n};\n\n// Check if a command exists in PATH by trying to run it\nfunction commandExists(cmd: string): boolean {\n try {\n const result = spawnSync(cmd, [\"--version\"], { stdio: \"pipe\" });\n // Check for ENOENT error (command not found)\n return result.error === undefined || result.error === null;\n } catch {\n return false;\n }\n}\n\n// Get the path to a tool (system-wide or in our tools dir)\nexport function getToolPath(tool: \"fd\" | \"rg\"): string | null {\n const config = TOOLS[tool];\n if (!config) return null;\n\n // Check our tools directory first\n const localPath = join(\n TOOLS_DIR,\n config.binaryName + (platform() === \"win32\" ? \".exe\" : \"\"),\n );\n if (existsSync(localPath)) {\n return localPath;\n }\n\n // Check system PATH - if found, just return the command name (it's in PATH)\n const systemBinaryNames = config.systemBinaryNames ?? [config.binaryName];\n for (const systemBinaryName of systemBinaryNames) {\n if (commandExists(systemBinaryName)) {\n return systemBinaryName;\n }\n }\n\n return null;\n}\n\n// Fetch latest release version from GitHub\nasync function getLatestVersion(repo: string): Promise<string> {\n const response = await fetch(\n `https://api.github.com/repos/${repo}/releases/latest`,\n {\n headers: { \"User-Agent\": APP_NAME },\n signal: AbortSignal.timeout(NETWORK_TIMEOUT_MS),\n },\n );\n\n if (!response.ok) {\n throw new Error(`GitHub API error: ${response.status}`);\n }\n\n const data = (await response.json()) as { tag_name: string };\n return data.tag_name.replace(/^v/, \"\");\n}\n\n// Download a file from URL\nasync function downloadFile(url: string, dest: string): Promise<void> {\n const response = await fetch(url, {\n signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to download: ${response.status}`);\n }\n\n if (!response.body) {\n throw new Error(\"No response body\");\n }\n\n await writeFile(dest, Buffer.from(await response.arrayBuffer()));\n}\n\nfunction findBinaryRecursively(\n rootDir: string,\n binaryFileName: string,\n): string | null {\n const stack: string[] = [rootDir];\n\n while (stack.length > 0) {\n const currentDir = stack.pop();\n if (!currentDir) continue;\n\n const entries = readdirSync(currentDir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(currentDir, entry.name);\n if (entry.isFile() && entry.name === binaryFileName) {\n return fullPath;\n }\n if (entry.isDirectory()) {\n stack.push(fullPath);\n }\n }\n }\n\n return null;\n}\n\nfunction formatSpawnFailure(result: SpawnSyncReturns<Buffer>): string {\n if (result.error?.message) {\n return result.error.message;\n }\n const stderr = result.stderr?.toString().trim();\n if (stderr) {\n return stderr;\n }\n const stdout = result.stdout?.toString().trim();\n if (stdout) {\n return stdout;\n }\n return `exit status ${result.status ?? \"unknown\"}`;\n}\n\nfunction runExtractionCommand(command: string, args: string[]): string | null {\n const result = spawnSync(command, args, { stdio: \"pipe\" });\n if (!result.error && result.status === 0) {\n return null;\n }\n return `${command}: ${formatSpawnFailure(result)}`;\n}\n\nfunction extractTarGzArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failure = runExtractionCommand(\"tar\", [\n \"xzf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (failure) {\n throw new Error(`Failed to extract ${assetName}: ${failure}`);\n }\n}\n\nfunction getWindowsTarCommand(): string {\n const systemRoot = process.env.SystemRoot ?? process.env.WINDIR;\n if (systemRoot) {\n const systemTar = join(systemRoot, \"System32\", \"tar.exe\");\n if (existsSync(systemTar)) {\n return systemTar;\n }\n }\n return \"tar.exe\";\n}\n\nfunction extractZipArchive(\n archivePath: string,\n extractDir: string,\n assetName: string,\n): void {\n const failures: string[] = [];\n\n if (platform() === \"win32\") {\n // Windows ships bsdtar as tar.exe, which supports zip files. Prefer the\n // System32 binary over Git Bash's GNU tar, which does not handle zip archives.\n const tarFailure = runExtractionCommand(getWindowsTarCommand(), [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n\n const script =\n \"& { param($archive, $destination) $ErrorActionPreference = 'Stop'; Expand-Archive -LiteralPath $archive -DestinationPath $destination -Force }\";\n const powershellFailure = runExtractionCommand(\"powershell.exe\", [\n \"-NoLogo\",\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-ExecutionPolicy\",\n \"Bypass\",\n \"-Command\",\n script,\n archivePath,\n extractDir,\n ]);\n if (!powershellFailure) return;\n failures.push(powershellFailure);\n } else {\n const unzipFailure = runExtractionCommand(\"unzip\", [\n \"-q\",\n archivePath,\n \"-d\",\n extractDir,\n ]);\n if (!unzipFailure) return;\n failures.push(unzipFailure);\n\n const tarFailure = runExtractionCommand(\"tar\", [\n \"xf\",\n archivePath,\n \"-C\",\n extractDir,\n ]);\n if (!tarFailure) return;\n failures.push(tarFailure);\n }\n\n throw new Error(`Failed to extract ${assetName}: ${failures.join(\"; \")}`);\n}\n\n// Download and install a tool\nasync function downloadTool(tool: \"fd\" | \"rg\"): Promise<string> {\n const config = TOOLS[tool];\n if (!config) throw new Error(`Unknown tool: ${tool}`);\n\n const plat = platform();\n const architecture = arch();\n\n // Get latest version\n const version = await getLatestVersion(config.repo);\n\n // Get asset name for this platform\n const assetName = config.getAssetName(version, plat, architecture);\n if (!assetName) {\n throw new Error(`Unsupported platform: ${plat}/${architecture}`);\n }\n\n // Create tools directory\n mkdirSync(TOOLS_DIR, { recursive: true });\n\n const downloadUrl = `https://github.com/${config.repo}/releases/download/${config.tagPrefix}${version}/${assetName}`;\n const archivePath = join(TOOLS_DIR, assetName);\n const binaryExt = plat === \"win32\" ? \".exe\" : \"\";\n const binaryPath = join(TOOLS_DIR, config.binaryName + binaryExt);\n\n // Download\n await downloadFile(downloadUrl, archivePath);\n\n // Extract into a unique temp directory. fd and rg downloads can run concurrently\n // during startup, so sharing a fixed directory causes races.\n const extractDir = join(\n TOOLS_DIR,\n `extract_tmp_${config.binaryName}_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`,\n );\n mkdirSync(extractDir, { recursive: true });\n\n try {\n if (assetName.endsWith(\".tar.gz\")) {\n extractTarGzArchive(archivePath, extractDir, assetName);\n } else if (assetName.endsWith(\".zip\")) {\n extractZipArchive(archivePath, extractDir, assetName);\n } else {\n throw new Error(`Unsupported archive format: ${assetName}`);\n }\n\n // Find the binary in extracted files. Some archives contain files directly\n // at root, others nest under a versioned subdirectory.\n const binaryFileName = config.binaryName + binaryExt;\n const extractedDir = join(\n extractDir,\n assetName.replace(/\\.(tar\\.gz|zip)$/, \"\"),\n );\n const extractedBinaryCandidates = [\n join(extractedDir, binaryFileName),\n join(extractDir, binaryFileName),\n ];\n let extractedBinary = extractedBinaryCandidates.find((candidate) =>\n existsSync(candidate),\n );\n\n if (!extractedBinary) {\n extractedBinary =\n findBinaryRecursively(extractDir, binaryFileName) ?? undefined;\n }\n\n if (extractedBinary) {\n renameSync(extractedBinary, binaryPath);\n } else {\n throw new Error(\n `Binary not found in archive: expected ${binaryFileName} under ${extractDir}`,\n );\n }\n\n // Make executable (Unix only)\n if (plat !== \"win32\") {\n chmodSync(binaryPath, 0o755);\n }\n } finally {\n // Cleanup\n rmSync(archivePath, { force: true });\n rmSync(extractDir, { recursive: true, force: true });\n }\n\n return binaryPath;\n}\n\n// Termux package names for tools\nconst TERMUX_PACKAGES: Record<string, string> = {\n fd: \"fd\",\n rg: \"ripgrep\",\n};\n\n// Ensure a tool is available, downloading if necessary\n// Returns the path to the tool, or null if unavailable\nexport async function ensureTool(\n tool: \"fd\" | \"rg\",\n silent: boolean = false,\n): Promise<string | undefined> {\n const existingPath = getToolPath(tool);\n if (existingPath) {\n return existingPath;\n }\n\n const config = TOOLS[tool];\n if (!config) return undefined;\n\n if (isOfflineModeEnabled()) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Offline mode enabled, skipping download.`,\n ),\n );\n }\n return undefined;\n }\n\n // On Android/Termux, Linux binaries don't work due to Bionic libc incompatibility.\n // Users must install via pkg.\n if (platform() === \"android\") {\n const pkgName = TERMUX_PACKAGES[tool] ?? tool;\n if (!silent) {\n console.log(\n chalk.yellow(\n `${config.name} not found. Install with: pkg install ${pkgName}`,\n ),\n );\n }\n return undefined;\n }\n\n // Tool not found - download it\n if (!silent) {\n console.log(chalk.dim(`${config.name} not found. Downloading...`));\n }\n\n try {\n const path = await downloadTool(tool);\n if (!silent) {\n console.log(chalk.dim(`${config.name} installed to ${path}`));\n }\n return path;\n } catch (e) {\n if (!silent) {\n console.log(\n chalk.yellow(\n `Failed to download ${config.name}: ${e instanceof Error ? e.message : e}`,\n ),\n );\n }\n return undefined;\n }\n}\n"]}
|
package/docs/models.md
CHANGED
|
@@ -120,26 +120,26 @@ The `baseUrl` is required when adding custom models to the `google-generative-ai
|
|
|
120
120
|
|
|
121
121
|
## Supported APIs
|
|
122
122
|
|
|
123
|
-
| API
|
|
124
|
-
|
|
125
|
-
| `openai-completions`
|
|
126
|
-
| `openai-responses`
|
|
127
|
-
| `anthropic-messages`
|
|
128
|
-
| `google-generative-ai` | Google Generative AI
|
|
123
|
+
| API | Description |
|
|
124
|
+
| ---------------------- | ----------------------------------------- |
|
|
125
|
+
| `openai-completions` | OpenAI Chat Completions (most compatible) |
|
|
126
|
+
| `openai-responses` | OpenAI Responses API |
|
|
127
|
+
| `anthropic-messages` | Anthropic Messages API |
|
|
128
|
+
| `google-generative-ai` | Google Generative AI |
|
|
129
129
|
|
|
130
130
|
Set `api` at provider level (default for all models) or model level (override per model).
|
|
131
131
|
|
|
132
132
|
## Provider Configuration
|
|
133
133
|
|
|
134
|
-
| Field
|
|
135
|
-
|
|
136
|
-
| `baseUrl`
|
|
137
|
-
| `api`
|
|
138
|
-
| `apiKey`
|
|
139
|
-
| `headers`
|
|
140
|
-
| `authHeader`
|
|
141
|
-
| `models`
|
|
142
|
-
| `modelOverrides` | Per-model overrides for built-in models on this provider
|
|
134
|
+
| Field | Description |
|
|
135
|
+
| ---------------- | ---------------------------------------------------------------- |
|
|
136
|
+
| `baseUrl` | API endpoint URL |
|
|
137
|
+
| `api` | API type (see above) |
|
|
138
|
+
| `apiKey` | API key (see value resolution below) |
|
|
139
|
+
| `headers` | Custom headers (see value resolution below) |
|
|
140
|
+
| `authHeader` | Set `true` to add `Authorization: Bearer <apiKey>` automatically |
|
|
141
|
+
| `models` | Array of model configurations |
|
|
142
|
+
| `modelOverrides` | Per-model overrides for built-in models on this provider |
|
|
143
143
|
|
|
144
144
|
### Value Resolution
|
|
145
145
|
|
|
@@ -186,18 +186,18 @@ If your command is slow, expensive, rate-limited, or should keep using a previou
|
|
|
186
186
|
|
|
187
187
|
## Model Configuration
|
|
188
188
|
|
|
189
|
-
| Field
|
|
190
|
-
|
|
191
|
-
| `id`
|
|
192
|
-
| `name`
|
|
193
|
-
| `api`
|
|
194
|
-
| `reasoning`
|
|
195
|
-
| `thinkingLevelMap` | No
|
|
196
|
-
| `input`
|
|
197
|
-
| `contextWindow`
|
|
198
|
-
| `maxTokens`
|
|
199
|
-
| `cost`
|
|
200
|
-
| `compat`
|
|
189
|
+
| Field | Required | Default | Description |
|
|
190
|
+
| ------------------ | -------- | ----------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
191
|
+
| `id` | Yes | — | Model identifier (passed to the API) |
|
|
192
|
+
| `name` | No | `id` | Human-readable model label. Used for matching (`--model` patterns) and shown in model details/status text. |
|
|
193
|
+
| `api` | No | provider's `api` | Override provider's API for this model |
|
|
194
|
+
| `reasoning` | No | `false` | Supports extended thinking |
|
|
195
|
+
| `thinkingLevelMap` | No | omitted | Maps Atomic thinking levels to provider values and marks unsupported levels (see below) |
|
|
196
|
+
| `input` | No | `["text"]` | Input types: `["text"]` or `["text", "image"]` |
|
|
197
|
+
| `contextWindow` | No | `128000` | Context window size in tokens |
|
|
198
|
+
| `maxTokens` | No | `16384` | Maximum output tokens |
|
|
199
|
+
| `cost` | No | all zeros | `{"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0}` (per million tokens) |
|
|
200
|
+
| `compat` | No | provider `compat` | Provider compatibility overrides. Merged with provider-level `compat` when both are set. |
|
|
201
201
|
|
|
202
202
|
Current behavior:
|
|
203
203
|
- `/model` and `--list-models` list entries by model `id`.
|
|
@@ -209,11 +209,11 @@ Use `thinkingLevelMap` on a model to describe model-specific thinking controls.
|
|
|
209
209
|
|
|
210
210
|
Values are tristate:
|
|
211
211
|
|
|
212
|
-
| Value
|
|
213
|
-
|
|
212
|
+
| Value | Meaning |
|
|
213
|
+
| ------- | ---------------------------------------------------------- |
|
|
214
214
|
| omitted | Level is supported and uses the provider's default mapping |
|
|
215
|
-
| string
|
|
216
|
-
| `null`
|
|
215
|
+
| string | Level is supported and this value is sent to the provider |
|
|
216
|
+
| `null` | Level is unsupported and hidden/skipped/clamped away |
|
|
217
217
|
|
|
218
218
|
Example for a model that only supports off, high, and max reasoning:
|
|
219
219
|
|
|
@@ -332,7 +332,7 @@ By default, Atomic sends per-tool `eager_input_streaming: true`. If a proxy or A
|
|
|
332
332
|
},
|
|
333
333
|
"models": [
|
|
334
334
|
{
|
|
335
|
-
"id": "claude-opus-4-
|
|
335
|
+
"id": "claude-opus-4-8",
|
|
336
336
|
"reasoning": true,
|
|
337
337
|
"input": ["text", "image"]
|
|
338
338
|
}
|
|
@@ -342,10 +342,10 @@ By default, Atomic sends per-tool `eager_input_streaming: true`. If a proxy or A
|
|
|
342
342
|
}
|
|
343
343
|
```
|
|
344
344
|
|
|
345
|
-
| Field
|
|
346
|
-
|
|
345
|
+
| Field | Description |
|
|
346
|
+
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
347
347
|
| `supportsEagerToolInputStreaming` | Whether the provider accepts per-tool `eager_input_streaming`. Default: `true`. Set to `false` to omit that field and use the legacy fine-grained tool streaming beta header on tool-enabled requests. |
|
|
348
|
-
| `supportsLongCacheRetention`
|
|
348
|
+
| `supportsLongCacheRetention` | Whether the provider accepts Anthropic long cache retention (`cache_control.ttl: "1h"`) when cache retention is `long`. Default: `true`. |
|
|
349
349
|
|
|
350
350
|
## OpenAI Compatibility
|
|
351
351
|
|
|
@@ -370,23 +370,23 @@ For providers with partial OpenAI compatibility, use the `compat` field.
|
|
|
370
370
|
}
|
|
371
371
|
```
|
|
372
372
|
|
|
373
|
-
| Field
|
|
374
|
-
|
|
375
|
-
| `supportsStore`
|
|
376
|
-
| `supportsDeveloperRole`
|
|
377
|
-
| `supportsReasoningEffort`
|
|
378
|
-
| `supportsUsageInStreaming`
|
|
379
|
-
| `maxTokensField`
|
|
380
|
-
| `requiresToolResultName`
|
|
381
|
-
| `requiresAssistantAfterToolResult`
|
|
382
|
-
| `requiresThinkingAsText`
|
|
383
|
-
| `requiresReasoningContentOnAssistantMessages` | Include empty `reasoning_content` on all replayed assistant messages when reasoning is enabled
|
|
384
|
-
| `thinkingFormat`
|
|
385
|
-
| `cacheControlFormat`
|
|
386
|
-
| `supportsStrictMode`
|
|
387
|
-
| `supportsLongCacheRetention`
|
|
388
|
-
| `openRouterRouting`
|
|
389
|
-
| `vercelGatewayRouting`
|
|
373
|
+
| Field | Description |
|
|
374
|
+
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
375
|
+
| `supportsStore` | Provider supports `store` field |
|
|
376
|
+
| `supportsDeveloperRole` | Use `developer` vs `system` role |
|
|
377
|
+
| `supportsReasoningEffort` | Support for `reasoning_effort` parameter |
|
|
378
|
+
| `supportsUsageInStreaming` | Supports `stream_options: { include_usage: true }` (default: `true`) |
|
|
379
|
+
| `maxTokensField` | Use `max_completion_tokens` or `max_tokens` |
|
|
380
|
+
| `requiresToolResultName` | Include `name` on tool result messages |
|
|
381
|
+
| `requiresAssistantAfterToolResult` | Insert an assistant message before a user message after tool results |
|
|
382
|
+
| `requiresThinkingAsText` | Convert thinking blocks to plain text |
|
|
383
|
+
| `requiresReasoningContentOnAssistantMessages` | Include empty `reasoning_content` on all replayed assistant messages when reasoning is enabled |
|
|
384
|
+
| `thinkingFormat` | Use `reasoning_effort`, `openrouter`, `deepseek`, `together`, `zai`, `qwen`, or `qwen-chat-template` thinking parameters |
|
|
385
|
+
| `cacheControlFormat` | Use Anthropic-style `cache_control` markers on the system prompt, last tool definition, and last user/assistant text content. Currently only `anthropic` is supported. |
|
|
386
|
+
| `supportsStrictMode` | Include the `strict` field in tool definitions |
|
|
387
|
+
| `supportsLongCacheRetention` | Whether the provider accepts long cache retention when cache retention is `long`: `prompt_cache_retention: "24h"` for OpenAI prompt caching, or `cache_control.ttl: "1h"` when `cacheControlFormat` is `anthropic`. Default: `true`. |
|
|
388
|
+
| `openRouterRouting` | OpenRouter provider routing preferences. This object is sent as-is in the `provider` field of the [OpenRouter API request](https://openrouter.ai/docs/guides/routing/provider-selection). |
|
|
389
|
+
| `vercelGatewayRouting` | Vercel AI Gateway routing config for provider selection (`only`, `order`) |
|
|
390
390
|
|
|
391
391
|
`openrouter` uses `reasoning: { effort }`. `together` uses `reasoning: { enabled }` and also `reasoning_effort` when `supportsReasoningEffort` is enabled. `qwen` uses top-level `enable_thinking`. Use `qwen-chat-template` for local Qwen-compatible servers that require `chat_template_kwargs.enable_thinking`.
|
|
392
392
|
|
package/docs/quickstart.md
CHANGED
|
@@ -102,12 +102,12 @@ Keep using `ralph` for larger migrations, broad refactors, multi-package changes
|
|
|
102
102
|
Named workflow runs execute in the background. After launch you get a run id; use it to inspect, attach, pause, or resume:
|
|
103
103
|
|
|
104
104
|
```text
|
|
105
|
-
/workflow status # list
|
|
105
|
+
/workflow status # list this session's active and terminal runs
|
|
106
106
|
/workflow connect <run-id> # open the graph viewer (F2 also opens the latest)
|
|
107
107
|
/workflow attach <run-id> <stage> # chat with one stage
|
|
108
108
|
/workflow interrupt <run-id> # pause resumably
|
|
109
109
|
/workflow resume <run-id> "go" # send a steer message and resume
|
|
110
|
-
/workflow kill <run-id> #
|
|
110
|
+
/workflow kill <run-id> # abort and retain for inspection
|
|
111
111
|
```
|
|
112
112
|
|
|
113
113
|
Human-in-the-loop prompts (`ctx.ui.input`, `confirm`, `select`, `editor`) surface in the graph viewer, not as chat modals — connect to the run to answer them. See [Workflows](/workflows) for the full reference and authoring guide.
|
package/docs/workflows.md
CHANGED
|
@@ -30,6 +30,7 @@ Use a workflow when a task should be repeatable, inspectable, resumable, or spli
|
|
|
30
30
|
- [Quick Start](#quick-start)
|
|
31
31
|
- [Built-in Workflows](#built-in-workflows)
|
|
32
32
|
- [When to Use Workflows](#when-to-use-workflows)
|
|
33
|
+
- [Atomic vs Claude Code Dynamic Workflows](#atomic-vs-claude-code-dynamic-workflows)
|
|
33
34
|
- [Workflow Locations](#workflow-locations)
|
|
34
35
|
- [Workflow Configuration](#workflow-configuration)
|
|
35
36
|
- [Package Setup](#package-setup)
|
|
@@ -314,12 +315,12 @@ If required inputs are missing or ambiguous, Atomic will either ask or open the
|
|
|
314
315
|
Named runs go to the background. Common controls:
|
|
315
316
|
|
|
316
317
|
```text
|
|
317
|
-
/workflow status # list
|
|
318
|
-
/workflow connect <run-id> # graph viewer
|
|
318
|
+
/workflow status # list retained active and terminal runs
|
|
319
|
+
/workflow connect <run-id> # graph viewer, including terminal runs
|
|
319
320
|
/workflow attach <run-id> <stage> # chat with a single stage
|
|
320
321
|
/workflow interrupt <run-id> # pause resumably
|
|
321
322
|
/workflow resume <run-id> [stage] msg # forward a steer message and resume
|
|
322
|
-
/workflow kill <run-id> #
|
|
323
|
+
/workflow kill <run-id> # abort and retain for inspection
|
|
323
324
|
```
|
|
324
325
|
|
|
325
326
|
Human-in-the-loop prompts from `ctx.ui.input`, `ctx.ui.confirm`, `ctx.ui.select`, and `ctx.ui.editor` appear as awaiting-input nodes in the workflow graph viewer, not as chat modals — use `/workflow connect <run-id>` (or F2), focus the node, and press Enter to answer them locally.
|
|
@@ -349,6 +350,22 @@ If the task is only deterministic TypeScript with no LLM/session stage, use a sc
|
|
|
349
350
|
| Track one-off work without saving a workflow file | direct `workflow({ task })`, `workflow({ tasks })`, or `workflow({ chain })` calls |
|
|
350
351
|
| Make a workflow robust | design the stage graph, context handoffs, artifacts, validation gates, model fallbacks, and human approval points before coding |
|
|
351
352
|
|
|
353
|
+
## Atomic vs Claude Code Dynamic Workflows
|
|
354
|
+
|
|
355
|
+
Claude Code Dynamic Workflows and Atomic are trying to solve a similar class of problem: important software engineering work is too large for one agent pass, so the system should split the job into stages, run agents in parallel, verify the result, and keep enough state to finish long-running work.
|
|
356
|
+
|
|
357
|
+
The difference is where control lives.
|
|
358
|
+
|
|
359
|
+
| Dimension | Atomic | Claude Code Dynamic Workflows |
|
|
360
|
+
| --- | --- | --- |
|
|
361
|
+
| Core idea | Open-source, repo-native workflow automation for coding agents. You can run built-ins, tell the coding agent to use a workflow for a task, describe new workflows in natural language for Atomic to scaffold dynamically, or version them as explicit TypeScript files. | Claude dynamically creates orchestration scripts for a task and fans work out to many parallel Claude subagents. |
|
|
362
|
+
| Best fit | Teams that want repeatable software engineering workflows they can inspect, version, extend, and run across providers. | Claude Code users who want Claude to decide when a task needs a larger dynamic workflow and orchestrate it automatically. |
|
|
363
|
+
| Workflow control | The process is explicit: stages, inputs, handoffs, retries, artifacts, model choices, and human gates are part of the workflow definition. | The process is generated dynamically by Claude for the current task, with confirmation before the first workflow run. |
|
|
364
|
+
| Models | Model-agnostic. Atomic connects directly to supported API-key and subscription providers, and workflows can use model fallback chains. | Claude-first. Availability is tied to Claude Code, Claude plans, and Anthropic-supported API/cloud channels. |
|
|
365
|
+
| Extensibility | Built on Pi extensions: add tools, TUI, MCP, web access, intercom, skills, prompt templates, themes, custom providers, and packaged workflows. | Optimized for Claude Code's built-in dynamic orchestration experience rather than an open extension SDK you own in-repo. |
|
|
366
|
+
| Artifacts and auditability | Research docs, specs, logs, transcripts, reviewer notes, check output, and final summaries can live in the repo or workflow run directory. | Progress is saved and resumable, but the orchestration is primarily a Claude Code runtime behavior. |
|
|
367
|
+
| Cost/scale posture | You choose the graph and concurrency. Atomic can be small and deterministic, or broad when you intentionally design a larger workflow. | Designed for large fan-outs, including tens to hundreds of subagents; Anthropic notes it can consume substantially more tokens than a typical Claude Code session. |
|
|
368
|
+
|
|
352
369
|
## Workflow Locations
|
|
353
370
|
|
|
354
371
|
Atomic discovers workflow definitions in this order:
|
|
@@ -547,7 +564,7 @@ In the TUI, `/workflow <name>` opens an input picker when the workflow declares
|
|
|
547
564
|
/workflow reload
|
|
548
565
|
```
|
|
549
566
|
|
|
550
|
-
Use `connect` for the workflow graph. Use `attach` when you want a chat pane for a specific stage. Use `interrupt`, `pause`, and `resume` for resumable live work; `resume` on a non-paused run reopens the saved snapshot or overlay. Use `kill` only when the run should be terminated
|
|
567
|
+
Use `connect` for the workflow graph. Use `attach` when you want a chat pane for a specific stage. Use `interrupt`, `pause`, and `resume` for resumable live work; `resume` on a non-paused run reopens the saved snapshot or overlay. Use `kill` only when the run should be terminated; killed runs are retained in live history/status for read-only inspection. Use `/workflow reload` after adding, editing, installing, or removing workflow resources and you want Atomic to rediscover them in-process. `/workflow status` lists all retained active and terminal runs by default; `/workflow status --all` is retained as a compatibility alias.
|
|
551
568
|
|
|
552
569
|
<p align="center"><img src="images/workflow-graph.png" alt="Workflow Graph Viewer" width="600" /></p>
|
|
553
570
|
|
|
@@ -595,7 +612,7 @@ Control behavior:
|
|
|
595
612
|
- `interrupt` is resumable: it pauses live work when pausable stages exist and keeps the run in live history/status.
|
|
596
613
|
- `pause` is useful for pausing a live run or a single live stage without treating it as a destructive abort.
|
|
597
614
|
- `resume` can target a stage with `stageId`; the target may be a stage id, unique prefix, or stage name. `message` is forwarded to paused work.
|
|
598
|
-
- `kill`
|
|
615
|
+
- `kill` aborts in-flight work, marks the run `killed`, and retains it in live history/status for inspection.
|
|
599
616
|
- `reload` refreshes discovered workflow resources in-process; the optional `reason` is echoed in the result.
|
|
600
617
|
|
|
601
618
|
Use slash commands for graph connect and stage attach because those are interactive TUI surfaces. When a run needs user input or attention, surface that to the user instead of polling silently.
|