poe-code 3.0.218 → 3.0.220

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/cli/commands/models.js +1 -1
  2. package/dist/index.js +20923 -18750
  3. package/dist/index.js.map +4 -4
  4. package/dist/providers/claude-code.js +1032 -698
  5. package/dist/providers/claude-code.js.map +4 -4
  6. package/dist/providers/codex.js +1032 -698
  7. package/dist/providers/codex.js.map +4 -4
  8. package/dist/providers/goose.js +3027 -2693
  9. package/dist/providers/goose.js.map +4 -4
  10. package/dist/providers/kimi.js +1032 -698
  11. package/dist/providers/kimi.js.map +4 -4
  12. package/dist/providers/opencode.js +1027 -693
  13. package/dist/providers/opencode.js.map +4 -4
  14. package/dist/providers/poe-agent.js +21316 -20880
  15. package/dist/providers/poe-agent.js.map +4 -4
  16. package/package.json +1 -1
  17. package/packages/config-mutations/dist/execution/apply-mutation.js +3 -3
  18. package/packages/config-mutations/dist/mutations/template-mutation.d.ts +3 -3
  19. package/packages/config-mutations/dist/template/render.d.ts +0 -1
  20. package/packages/config-mutations/dist/template/render.js +2 -22
  21. package/packages/design-system/dist/acp/components.js +15 -13
  22. package/packages/design-system/dist/components/color.d.ts +31 -0
  23. package/packages/design-system/dist/components/color.js +101 -0
  24. package/packages/design-system/dist/components/help-formatter-plain.d.ts +1 -0
  25. package/packages/design-system/dist/components/help-formatter-plain.js +1 -1
  26. package/packages/design-system/dist/components/index.d.ts +4 -0
  27. package/packages/design-system/dist/components/index.js +2 -0
  28. package/packages/design-system/dist/components/logger.js +2 -2
  29. package/packages/design-system/dist/components/symbols.js +3 -3
  30. package/packages/design-system/dist/components/table.js +191 -40
  31. package/packages/design-system/dist/components/template.d.ts +6 -0
  32. package/packages/design-system/dist/components/template.js +271 -0
  33. package/packages/design-system/dist/components/text.d.ts +1 -0
  34. package/packages/design-system/dist/components/text.js +11 -3
  35. package/packages/design-system/dist/dashboard/buffer.js +12 -12
  36. package/packages/design-system/dist/index.d.ts +4 -0
  37. package/packages/design-system/dist/index.js +2 -0
  38. package/packages/design-system/dist/internal/color-support.d.ts +9 -0
  39. package/packages/design-system/dist/internal/color-support.js +12 -0
  40. package/packages/design-system/dist/prompts/index.js +2 -2
  41. package/packages/design-system/dist/prompts/primitives/cancel.js +2 -2
  42. package/packages/design-system/dist/prompts/primitives/intro.js +2 -2
  43. package/packages/design-system/dist/prompts/primitives/log.js +4 -4
  44. package/packages/design-system/dist/prompts/primitives/note.js +5 -5
  45. package/packages/design-system/dist/prompts/primitives/outro.js +2 -2
  46. package/packages/design-system/dist/prompts/primitives/spinner.js +3 -3
  47. package/packages/design-system/dist/static/menu.js +5 -5
  48. package/packages/design-system/dist/static/spinner.js +8 -8
  49. package/packages/design-system/dist/tokens/colors.js +29 -29
  50. package/packages/design-system/dist/tokens/typography.js +6 -6
  51. package/packages/memory/dist/index.js +6329 -5995
  52. package/packages/memory/dist/index.js.map +4 -4
  53. package/packages/superintendent/dist/commands/superintendent-group.js +2 -2
  54. package/packages/superintendent/dist/templates/SKILL_superintendent.md +1 -1
@@ -1700,217 +1700,970 @@ function cloneValue(value) {
1700
1700
 
1701
1701
  // packages/config-extends/src/resolve.ts
1702
1702
  import path11 from "node:path";
1703
- var MAX_EXTENDS_DEPTH = 5;
1704
- var YIELD_TOKEN = "{{yield}}";
1705
- async function resolve(chain, options) {
1706
- const { baseLayers, documentIndex, documentLayer } = classifyChain(chain);
1707
- const parsedDocument = parseDocument3(documentLayer.content, documentLayer.filePath);
1708
- const resolvedBase = shouldResolveBase(parsedDocument, options.autoExtend) ? await resolveBaseChain({
1709
- name: documentLayer.baseName ?? getBaseName(documentLayer.filePath),
1710
- baseLayers,
1711
- options,
1712
- optional: !parsedDocument.extends,
1713
- visited: /* @__PURE__ */ new Set([documentLayer.filePath]),
1714
- depth: 1
1715
- }) : void 0;
1716
- const composedPrompt = composePromptChain(
1717
- {
1718
- source: documentLayer.source,
1719
- data: parsedDocument.data
1720
- },
1721
- resolvedBase?.layers ?? []
1722
- );
1723
- const merged = mergeLayers([
1724
- ...collectDataLayers(chain.slice(0, documentIndex)),
1725
- {
1726
- source: documentLayer.source,
1727
- data: withResolvedPrompt(parsedDocument.data, composedPrompt?.prompt)
1728
- },
1729
- ...stripResolvedBasePrompts(resolvedBase?.layers ?? [], composedPrompt?.consumedBaseIndexes ?? /* @__PURE__ */ new Set()),
1730
- ...collectDataLayers(chain.slice(documentIndex + 1))
1731
- ]);
1732
- if (composedPrompt !== void 0 && merged.sources.prompt === documentLayer.source && composedPrompt.source !== void 0) {
1733
- merged.sources.prompt = composedPrompt.source;
1703
+
1704
+ // packages/design-system/src/internal/color-support.ts
1705
+ function supportsColor(env = process.env, stream = process.stdout) {
1706
+ if (env.FORCE_COLOR !== void 0 && env.FORCE_COLOR !== "0") {
1707
+ return true;
1734
1708
  }
1735
- return {
1736
- data: merged.data,
1737
- sources: merged.sources,
1738
- chain: [documentLayer.filePath, ...resolvedBase?.chain ?? []]
1739
- };
1740
- }
1741
- function classifyChain(chain) {
1742
- const baseLayers = [];
1743
- const documentLayers = [];
1744
- for (const [index, layer] of chain.entries()) {
1745
- if (isDataLayer(layer)) {
1746
- continue;
1747
- }
1748
- if (isDocumentLayer(layer)) {
1749
- documentLayers.push({ index, layer });
1750
- continue;
1751
- }
1752
- if (isBaseLayer(layer)) {
1753
- baseLayers.push(layer);
1754
- }
1709
+ if (env.NO_COLOR !== void 0) {
1710
+ return false;
1755
1711
  }
1756
- if (documentLayers.length !== 1) {
1757
- throw new Error(`Exactly one document layer is required, received ${documentLayers.length}.`);
1712
+ if (stream.isTTY !== true) {
1713
+ return false;
1758
1714
  }
1715
+ return typeof env.TERM === "string" && env.TERM.length > 0 && env.TERM !== "dumb";
1716
+ }
1717
+
1718
+ // packages/design-system/src/components/color.ts
1719
+ var reset = "\x1B[0m";
1720
+ var ansiStyles = {
1721
+ reset: { open: reset },
1722
+ bold: { open: "\x1B[1m" },
1723
+ dim: { open: "\x1B[2m" },
1724
+ italic: { open: "\x1B[3m" },
1725
+ underline: { open: "\x1B[4m" },
1726
+ inverse: { open: "\x1B[7m" },
1727
+ strikethrough: { open: "\x1B[9m" },
1728
+ black: { open: "\x1B[30m" },
1729
+ red: { open: "\x1B[31m" },
1730
+ green: { open: "\x1B[32m" },
1731
+ yellow: { open: "\x1B[33m" },
1732
+ blue: { open: "\x1B[34m" },
1733
+ magenta: { open: "\x1B[35m" },
1734
+ cyan: { open: "\x1B[36m" },
1735
+ white: { open: "\x1B[37m" },
1736
+ gray: { open: "\x1B[90m" },
1737
+ magentaBright: { open: "\x1B[95m" },
1738
+ cyanBright: { open: "\x1B[96m" },
1739
+ bgRed: { open: "\x1B[41m" },
1740
+ bgGreen: { open: "\x1B[42m" },
1741
+ bgYellow: { open: "\x1B[43m" },
1742
+ bgBlue: { open: "\x1B[44m" },
1743
+ bgMagenta: { open: "\x1B[45m" }
1744
+ };
1745
+ var styleNames = Object.keys(ansiStyles);
1746
+ function replaceAll(value, search, replacement) {
1747
+ return value.split(search).join(replacement);
1748
+ }
1749
+ function applyStyles(text5, styles) {
1750
+ if (!supportsColor() || styles.length === 0) {
1751
+ return text5;
1752
+ }
1753
+ const open4 = styles.map((style) => style.open).join("");
1754
+ const output = text5.includes(reset) ? replaceAll(text5, reset, `${reset}${open4}`) : text5;
1755
+ return `${open4}${output}${reset}`;
1756
+ }
1757
+ function clampRgb(value) {
1758
+ if (Number.isNaN(value)) {
1759
+ return 0;
1760
+ }
1761
+ return Math.min(255, Math.max(0, Math.round(value)));
1762
+ }
1763
+ function hexChannel(value, offset) {
1764
+ return Number.parseInt(value.slice(offset, offset + 2), 16);
1765
+ }
1766
+ function normalizeHex(value) {
1767
+ const normalized = value.startsWith("#") ? value.slice(1) : value;
1768
+ if (normalized.length === 3) {
1769
+ const red = normalized[0];
1770
+ const green = normalized[1];
1771
+ const blue = normalized[2];
1772
+ return [
1773
+ Number.parseInt(`${red}${red}`, 16),
1774
+ Number.parseInt(`${green}${green}`, 16),
1775
+ Number.parseInt(`${blue}${blue}`, 16)
1776
+ ];
1777
+ }
1778
+ if (normalized.length === 6) {
1779
+ return [
1780
+ hexChannel(normalized, 0),
1781
+ hexChannel(normalized, 2),
1782
+ hexChannel(normalized, 4)
1783
+ ];
1784
+ }
1785
+ return [0, 0, 0];
1786
+ }
1787
+ function rgbStyle(red, green, blue) {
1759
1788
  return {
1760
- baseLayers,
1761
- documentIndex: documentLayers[0].index,
1762
- documentLayer: documentLayers[0].layer
1789
+ open: `\x1B[38;2;${clampRgb(red)};${clampRgb(green)};${clampRgb(blue)}m`
1763
1790
  };
1764
1791
  }
1765
- async function resolveBaseChain({
1766
- name,
1767
- baseLayers,
1768
- options,
1769
- optional,
1770
- visited,
1771
- depth
1772
- }) {
1773
- if (depth > MAX_EXTENDS_DEPTH) {
1774
- throw new Error(`Maximum extends depth exceeded (${MAX_EXTENDS_DEPTH}).`);
1775
- }
1776
- let discoveredBase;
1777
- try {
1778
- discoveredBase = await findBase(
1779
- name,
1780
- baseLayers.map((layer) => layer.path),
1781
- options.fs
1782
- );
1783
- } catch (error2) {
1784
- if (optional && isBaseNotFoundError(error2)) {
1785
- return void 0;
1786
- }
1787
- throw error2;
1788
- }
1789
- if (visited.has(discoveredBase.filePath)) {
1790
- if (optional) {
1791
- return void 0;
1792
- }
1793
- throw new Error(
1794
- `Circular extends detected.
1795
- Visited files:
1796
- - ${[...visited, discoveredBase.filePath].join("\n- ")}`
1797
- );
1798
- }
1799
- const matchedBaseIndex = baseLayers.findIndex(
1800
- (layer) => layer.path === path11.dirname(discoveredBase.filePath)
1801
- );
1802
- if (matchedBaseIndex === -1) {
1803
- throw new Error(`Resolved base is outside configured base paths: ${discoveredBase.filePath}`);
1804
- }
1805
- const parsedBase = parseDocument3(discoveredBase.content, discoveredBase.filePath);
1806
- const nextVisited = new Set(visited);
1807
- nextVisited.add(discoveredBase.filePath);
1808
- const nestedBase = parsedBase.extends ? await resolveBaseChain({
1809
- name: getBaseName(discoveredBase.filePath),
1810
- baseLayers: baseLayers.slice(matchedBaseIndex + 1),
1811
- options,
1812
- optional: false,
1813
- visited: nextVisited,
1814
- depth: depth + 1
1815
- }) : void 0;
1792
+ function bgRgbStyle(red, green, blue) {
1816
1793
  return {
1817
- layers: [
1818
- {
1819
- source: baseLayers[matchedBaseIndex].source,
1820
- data: parsedBase.data
1821
- },
1822
- ...nestedBase?.layers ?? []
1823
- ],
1824
- chain: [discoveredBase.filePath, ...nestedBase?.chain ?? []]
1794
+ open: `\x1B[48;2;${clampRgb(red)};${clampRgb(green)};${clampRgb(blue)}m`
1825
1795
  };
1826
1796
  }
1827
- function collectDataLayers(chain) {
1828
- return chain.filter(isDataLayer);
1797
+ function createColor(styles = []) {
1798
+ const builder = ((text5) => applyStyles(String(text5), styles));
1799
+ for (const name of styleNames) {
1800
+ Object.defineProperty(builder, name, {
1801
+ configurable: true,
1802
+ enumerable: true,
1803
+ get: () => createColor([...styles, ansiStyles[name]])
1804
+ });
1805
+ }
1806
+ builder.hex = (value) => {
1807
+ const [red, green, blue] = normalizeHex(value);
1808
+ return createColor([...styles, rgbStyle(red, green, blue)]);
1809
+ };
1810
+ builder.rgb = (red, green, blue) => createColor([...styles, rgbStyle(red, green, blue)]);
1811
+ builder.bgHex = (value) => {
1812
+ const [red, green, blue] = normalizeHex(value);
1813
+ return createColor([...styles, bgRgbStyle(red, green, blue)]);
1814
+ };
1815
+ builder.bgRgb = (red, green, blue) => createColor([...styles, bgRgbStyle(red, green, blue)]);
1816
+ return builder;
1829
1817
  }
1830
- function composePromptChain(documentLayer, baseLayers) {
1831
- const documentPrompt = documentLayer.data.prompt;
1832
- if (documentPrompt !== void 0 && typeof documentPrompt !== "string") {
1833
- return void 0;
1818
+ var color = createColor();
1819
+
1820
+ // packages/design-system/src/tokens/colors.ts
1821
+ var dark = {
1822
+ header: (text5) => color.magentaBright.bold(text5),
1823
+ divider: (text5) => color.dim(text5),
1824
+ prompt: (text5) => color.cyan(text5),
1825
+ number: (text5) => color.cyanBright(text5),
1826
+ intro: (text5) => color.bgMagenta.white(` Poe - ${text5} `),
1827
+ resolvedSymbol: color.magenta("\u25C7"),
1828
+ errorSymbol: color.red("\u25A0"),
1829
+ accent: (text5) => color.cyan(text5),
1830
+ muted: (text5) => color.dim(text5),
1831
+ success: (text5) => color.green(text5),
1832
+ warning: (text5) => color.yellow(text5),
1833
+ error: (text5) => color.red(text5),
1834
+ info: (text5) => color.magenta(text5),
1835
+ badge: (text5) => color.bgYellow.black(` ${text5} `)
1836
+ };
1837
+ var light = {
1838
+ header: (text5) => color.hex("#a200ff").bold(text5),
1839
+ divider: (text5) => color.hex("#666666")(text5),
1840
+ prompt: (text5) => color.hex("#006699").bold(text5),
1841
+ number: (text5) => color.hex("#0077cc").bold(text5),
1842
+ intro: (text5) => color.bgHex("#a200ff").white(` Poe - ${text5} `),
1843
+ resolvedSymbol: color.hex("#a200ff")("\u25C7"),
1844
+ errorSymbol: color.hex("#cc0000")("\u25A0"),
1845
+ accent: (text5) => color.hex("#006699").bold(text5),
1846
+ muted: (text5) => color.hex("#666666")(text5),
1847
+ success: (text5) => color.hex("#008800")(text5),
1848
+ warning: (text5) => color.hex("#cc6600")(text5),
1849
+ error: (text5) => color.hex("#cc0000")(text5),
1850
+ info: (text5) => color.hex("#a200ff")(text5),
1851
+ badge: (text5) => color.bgHex("#cc6600").white(` ${text5} `)
1852
+ };
1853
+
1854
+ // packages/design-system/src/internal/output-format.ts
1855
+ import { AsyncLocalStorage } from "node:async_hooks";
1856
+ var VALID_FORMATS = /* @__PURE__ */ new Set(["terminal", "markdown", "json"]);
1857
+ var formatStorage = new AsyncLocalStorage();
1858
+ var cached;
1859
+ function resolveOutputFormat(env = process.env) {
1860
+ const scoped = formatStorage.getStore();
1861
+ if (scoped) {
1862
+ return scoped;
1834
1863
  }
1835
- if (documentPrompt !== void 0) {
1836
- assertValidYieldCount(documentPrompt);
1864
+ if (cached) {
1865
+ return cached;
1837
1866
  }
1838
- let prompt = documentPrompt;
1839
- let source = prompt === void 0 || prompt === "" ? void 0 : documentLayer.source;
1840
- const consumedBaseIndexes = /* @__PURE__ */ new Set();
1841
- for (const [index, layer] of baseLayers.entries()) {
1842
- const candidate = layer.data.prompt;
1843
- if (candidate === void 0) {
1844
- continue;
1845
- }
1846
- if (typeof candidate !== "string") {
1847
- break;
1867
+ const raw = env.OUTPUT_FORMAT?.toLowerCase();
1868
+ cached = VALID_FORMATS.has(raw) ? raw : "terminal";
1869
+ return cached;
1870
+ }
1871
+
1872
+ // packages/design-system/src/internal/theme-detect.ts
1873
+ function detectThemeFromEnv(env) {
1874
+ const apple = env.APPLE_INTERFACE_STYLE;
1875
+ if (typeof apple === "string") {
1876
+ return apple.toLowerCase() === "dark" ? "dark" : "light";
1877
+ }
1878
+ const vscodeKind = env.VSCODE_COLOR_THEME_KIND;
1879
+ if (typeof vscodeKind === "string") {
1880
+ const normalized = vscodeKind.toLowerCase();
1881
+ if (normalized.includes("light")) {
1882
+ return "light";
1848
1883
  }
1849
- assertValidYieldCount(candidate);
1850
- consumedBaseIndexes.add(index);
1851
- prompt = composeAdjacentPrompts(prompt, candidate);
1852
- if (source === void 0 && candidate !== "") {
1853
- source = layer.source;
1884
+ if (normalized.includes("dark")) {
1885
+ return "dark";
1854
1886
  }
1855
1887
  }
1856
- if (prompt !== void 0 && prompt.includes(YIELD_TOKEN)) {
1857
- throw new Error('Final resolved prompt contains an unresolved "{{yield}}" token.');
1858
- }
1859
- if (prompt === void 0) {
1860
- return void 0;
1888
+ const colorFGBG = env.COLORFGBG;
1889
+ if (typeof colorFGBG === "string") {
1890
+ const parts = colorFGBG.split(";").map((part) => Number.parseInt(part, 10));
1891
+ const background = parts.at(-1);
1892
+ if (Number.isFinite(background)) {
1893
+ return background >= 8 ? "light" : "dark";
1894
+ }
1861
1895
  }
1862
- return {
1863
- consumedBaseIndexes,
1864
- prompt,
1865
- source
1866
- };
1896
+ return void 0;
1867
1897
  }
1868
- function composeAdjacentPrompts(high, low) {
1869
- if (high === void 0 || high === "") {
1870
- return low.includes(YIELD_TOKEN) ? replaceYield(low, "") : low;
1871
- }
1872
- if (high.includes(YIELD_TOKEN)) {
1873
- return replaceYield(high, low);
1874
- }
1875
- if (low.includes(YIELD_TOKEN)) {
1876
- return replaceYield(low, high);
1898
+ function resolveThemeName(env = process.env) {
1899
+ const raw = (env.POE_CODE_THEME ?? env.POE_THEME)?.toLowerCase();
1900
+ if (raw === "light" || raw === "dark") {
1901
+ return raw;
1877
1902
  }
1878
- return high;
1879
- }
1880
- function replaceYield(prompt, replacement) {
1881
- return prompt.replace(YIELD_TOKEN, replacement);
1882
- }
1883
- function assertValidYieldCount(prompt) {
1884
- if (countYieldTokens(prompt) > 1) {
1885
- throw new Error('Prompt composition supports exactly one "{{yield}}" token per prompt.');
1903
+ const detected = detectThemeFromEnv(env);
1904
+ if (detected) {
1905
+ return detected;
1886
1906
  }
1907
+ return "dark";
1887
1908
  }
1888
- function countYieldTokens(prompt) {
1889
- return prompt.split(YIELD_TOKEN).length - 1;
1890
- }
1891
- function withResolvedPrompt(data, prompt) {
1892
- if (prompt === void 0) {
1893
- return data;
1909
+ var cachedTheme;
1910
+ function getTheme(env) {
1911
+ if (cachedTheme) {
1912
+ return cachedTheme;
1894
1913
  }
1895
- return {
1896
- ...data,
1897
- prompt
1898
- };
1899
- }
1900
- function stripResolvedBasePrompts(layers, consumedBaseIndexes) {
1901
- return layers.map((layer, index) => {
1902
- if (!consumedBaseIndexes.has(index) || typeof layer.data.prompt !== "string") {
1903
- return layer;
1904
- }
1905
- const { prompt: ignoredPrompt, ...data } = layer.data;
1906
- void ignoredPrompt;
1907
- return {
1908
- source: layer.source,
1909
- data
1910
- };
1911
- });
1914
+ const themeName = resolveThemeName(env);
1915
+ cachedTheme = themeName === "light" ? light : dark;
1916
+ return cachedTheme;
1912
1917
  }
1913
- function getBaseName(filePath) {
1918
+
1919
+ // packages/design-system/src/components/symbols.ts
1920
+ var symbols = {
1921
+ get info() {
1922
+ const format = resolveOutputFormat();
1923
+ if (format === "json") return "info";
1924
+ if (format === "markdown") return "(i)";
1925
+ return color.magenta("\u25CF");
1926
+ },
1927
+ get success() {
1928
+ const format = resolveOutputFormat();
1929
+ if (format === "json") return "success";
1930
+ if (format === "markdown") return "[ok]";
1931
+ return color.magenta("\u25C6");
1932
+ },
1933
+ get resolved() {
1934
+ const format = resolveOutputFormat();
1935
+ if (format === "json") return "resolved";
1936
+ if (format === "markdown") return ">";
1937
+ return getTheme().resolvedSymbol;
1938
+ },
1939
+ get errorResolved() {
1940
+ const format = resolveOutputFormat();
1941
+ if (format === "json") return "error";
1942
+ if (format === "markdown") return "[!]";
1943
+ return getTheme().errorSymbol;
1944
+ },
1945
+ get bar() {
1946
+ const format = resolveOutputFormat();
1947
+ if (format === "json") return "";
1948
+ if (format === "markdown") return "|";
1949
+ return "\u2502";
1950
+ },
1951
+ cornerTopRight: "\u256E",
1952
+ cornerBottomRight: "\u256F",
1953
+ get warning() {
1954
+ const format = resolveOutputFormat();
1955
+ if (format === "json") return "warning";
1956
+ if (format === "markdown") return "[!]";
1957
+ return "\u25B2";
1958
+ },
1959
+ get active() {
1960
+ const format = resolveOutputFormat();
1961
+ if (format === "json") return "active";
1962
+ if (format === "markdown") return "[x]";
1963
+ return "\u25C6";
1964
+ },
1965
+ get inactive() {
1966
+ const format = resolveOutputFormat();
1967
+ if (format === "json") return "inactive";
1968
+ if (format === "markdown") return "[ ]";
1969
+ return "\u25CB";
1970
+ }
1971
+ };
1972
+
1973
+ // packages/design-system/src/internal/strip-ansi.ts
1974
+ function stripAnsi(value) {
1975
+ return value.replace(/\u001b\[[0-9;]*m/g, "");
1976
+ }
1977
+
1978
+ // packages/design-system/src/prompts/primitives/log.ts
1979
+ function writeTerminalMessage(msg, {
1980
+ symbol = color.gray("\u2502"),
1981
+ secondarySymbol = color.gray("\u2502"),
1982
+ spacing: spacing2 = 1,
1983
+ withGuide = true
1984
+ } = {}) {
1985
+ const lines = [];
1986
+ const showGuide = withGuide !== false;
1987
+ const contentLines = msg.split("\n");
1988
+ const prefix = showGuide ? `${symbol} ` : "";
1989
+ const continuationPrefix = showGuide ? `${secondarySymbol} ` : "";
1990
+ const emptyGuide = showGuide ? secondarySymbol : "";
1991
+ for (let index = 0; index < spacing2; index += 1) {
1992
+ lines.push(emptyGuide);
1993
+ }
1994
+ if (contentLines.length === 0) {
1995
+ process.stdout.write("\n");
1996
+ return;
1997
+ }
1998
+ const [firstLine = "", ...continuationLines] = contentLines;
1999
+ if (firstLine.length > 0) {
2000
+ lines.push(`${prefix}${firstLine}`);
2001
+ } else {
2002
+ lines.push(showGuide ? symbol : "");
2003
+ }
2004
+ for (const line of continuationLines) {
2005
+ if (line.length > 0) {
2006
+ lines.push(`${continuationPrefix}${line}`);
2007
+ continue;
2008
+ }
2009
+ lines.push(emptyGuide);
2010
+ }
2011
+ process.stdout.write(`${lines.join("\n")}
2012
+ `);
2013
+ }
2014
+ function message(msg, options) {
2015
+ const format = resolveOutputFormat();
2016
+ if (format === "markdown") {
2017
+ process.stdout.write(`- ${stripAnsi(msg)}
2018
+ `);
2019
+ return;
2020
+ }
2021
+ if (format === "json") {
2022
+ process.stdout.write(
2023
+ `${JSON.stringify({ level: "message", message: stripAnsi(msg) })}
2024
+ `
2025
+ );
2026
+ return;
2027
+ }
2028
+ writeTerminalMessage(msg, options);
2029
+ }
2030
+ function info(msg) {
2031
+ const format = resolveOutputFormat();
2032
+ if (format === "markdown") {
2033
+ process.stdout.write(`- **info:** ${stripAnsi(msg)}
2034
+ `);
2035
+ return;
2036
+ }
2037
+ if (format === "json") {
2038
+ process.stdout.write(
2039
+ `${JSON.stringify({ level: "info", message: stripAnsi(msg) })}
2040
+ `
2041
+ );
2042
+ return;
2043
+ }
2044
+ message(msg, { symbol: symbols.info });
2045
+ }
2046
+ function success(msg) {
2047
+ const format = resolveOutputFormat();
2048
+ if (format === "markdown") {
2049
+ process.stdout.write(`- **success:** ${stripAnsi(msg)}
2050
+ `);
2051
+ return;
2052
+ }
2053
+ if (format === "json") {
2054
+ process.stdout.write(
2055
+ `${JSON.stringify({ level: "success", message: stripAnsi(msg) })}
2056
+ `
2057
+ );
2058
+ return;
2059
+ }
2060
+ message(msg, { symbol: symbols.success });
2061
+ }
2062
+ function warn(msg) {
2063
+ const format = resolveOutputFormat();
2064
+ if (format === "markdown") {
2065
+ process.stdout.write(`- **warning:** ${stripAnsi(msg)}
2066
+ `);
2067
+ return;
2068
+ }
2069
+ if (format === "json") {
2070
+ process.stdout.write(
2071
+ `${JSON.stringify({ level: "warn", message: stripAnsi(msg) })}
2072
+ `
2073
+ );
2074
+ return;
2075
+ }
2076
+ message(msg, { symbol: color.yellow("\u25B2") });
2077
+ }
2078
+ function error(msg) {
2079
+ const format = resolveOutputFormat();
2080
+ if (format === "markdown") {
2081
+ process.stdout.write(`- **error:** ${stripAnsi(msg)}
2082
+ `);
2083
+ return;
2084
+ }
2085
+ if (format === "json") {
2086
+ process.stdout.write(
2087
+ `${JSON.stringify({ level: "error", message: stripAnsi(msg) })}
2088
+ `
2089
+ );
2090
+ return;
2091
+ }
2092
+ message(msg, { symbol: color.red("\u25A0") });
2093
+ }
2094
+ var log = {
2095
+ info,
2096
+ success,
2097
+ message,
2098
+ warn,
2099
+ error
2100
+ };
2101
+
2102
+ // packages/design-system/src/components/logger.ts
2103
+ function createLogger(emitter) {
2104
+ const emit = (level, message2) => {
2105
+ if (emitter) {
2106
+ emitter(message2);
2107
+ return;
2108
+ }
2109
+ if (level === "success") {
2110
+ log.success(message2);
2111
+ return;
2112
+ }
2113
+ if (level === "warn") {
2114
+ log.warn(message2);
2115
+ return;
2116
+ }
2117
+ if (level === "error") {
2118
+ log.error(message2);
2119
+ return;
2120
+ }
2121
+ log.info(message2);
2122
+ };
2123
+ return {
2124
+ info(message2) {
2125
+ emit("info", message2);
2126
+ },
2127
+ success(message2) {
2128
+ emit("success", message2);
2129
+ },
2130
+ warn(message2) {
2131
+ emit("warn", message2);
2132
+ },
2133
+ error(message2) {
2134
+ emit("error", message2);
2135
+ },
2136
+ resolved(label, value) {
2137
+ if (emitter) {
2138
+ emitter(`${label}: ${value}`);
2139
+ return;
2140
+ }
2141
+ log.message(`${label}
2142
+ ${value}`, { symbol: symbols.resolved });
2143
+ },
2144
+ errorResolved(label, value) {
2145
+ if (emitter) {
2146
+ emitter(`${label}: ${value}`);
2147
+ return;
2148
+ }
2149
+ log.message(`${label}
2150
+ ${value}`, { symbol: symbols.errorResolved });
2151
+ },
2152
+ message(message2, symbol) {
2153
+ if (emitter) {
2154
+ emitter(message2);
2155
+ return;
2156
+ }
2157
+ log.message(message2, { symbol: symbol ?? color.gray("\u2502") });
2158
+ }
2159
+ };
2160
+ }
2161
+ var logger = createLogger();
2162
+
2163
+ // packages/design-system/src/components/table.ts
2164
+ var graphemeSegmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
2165
+
2166
+ // packages/design-system/src/components/template.ts
2167
+ var HTML_ESCAPE = {
2168
+ "&": "&amp;",
2169
+ "<": "&lt;",
2170
+ ">": "&gt;",
2171
+ '"': "&quot;",
2172
+ "'": "&#39;",
2173
+ "/": "&#x2F;",
2174
+ "`": "&#x60;",
2175
+ "=": "&#x3D;"
2176
+ };
2177
+ function renderTemplate(template, view, options = {}) {
2178
+ const prepared = options.yield === void 0 ? template : template.split("{{yield}}").join(options.yield);
2179
+ const tokens = parseTemplate(prepared);
2180
+ const escape = options.escape === "none" ? String : escapeHtml;
2181
+ const preserveMissing = options.yield !== void 0 && options.escape === "none";
2182
+ return renderTokens(tokens, { view }, prepared, escape, preserveMissing);
2183
+ }
2184
+ function renderTemplateInContext(template, context, escape, preserveMissing) {
2185
+ return renderTokens(parseTemplate(template), context, template, escape, preserveMissing);
2186
+ }
2187
+ function parseTemplate(template) {
2188
+ const root = [];
2189
+ const stack = [];
2190
+ let tokens = root;
2191
+ let index = 0;
2192
+ while (index < template.length) {
2193
+ const open4 = template.indexOf("{{", index);
2194
+ if (open4 === -1) {
2195
+ appendText(tokens, template.slice(index), index);
2196
+ break;
2197
+ }
2198
+ appendText(tokens, template.slice(index, open4), index);
2199
+ const parsed = parseTag(template, open4);
2200
+ const standalone = getStandalone(template, open4, parsed.end, parsed.kind);
2201
+ if (standalone !== void 0) {
2202
+ trimTextAfter(tokens, standalone.lineStart);
2203
+ }
2204
+ if (parsed.kind === "comment") {
2205
+ index = standalone?.nextIndex ?? parsed.end;
2206
+ continue;
2207
+ }
2208
+ if (parsed.kind === "partial") {
2209
+ throw new Error(`Partials are not supported: "${parsed.name}"`);
2210
+ }
2211
+ if (parsed.kind === "delimiter") {
2212
+ throw new Error("Custom delimiters are not supported");
2213
+ }
2214
+ if (parsed.kind === "section" || parsed.kind === "inverted") {
2215
+ const token = {
2216
+ type: parsed.kind,
2217
+ name: parsed.name,
2218
+ children: [],
2219
+ rawStart: parsed.end,
2220
+ rawEnd: standalone?.lineStart ?? open4
2221
+ };
2222
+ tokens.push(token);
2223
+ stack.push({ token, parent: tokens });
2224
+ tokens = token.children;
2225
+ index = standalone?.nextIndex ?? parsed.end;
2226
+ continue;
2227
+ }
2228
+ if (parsed.kind === "close") {
2229
+ const frame2 = stack.pop();
2230
+ if (frame2 === void 0) {
2231
+ throw new Error(`Closing unopened section "${parsed.name}"`);
2232
+ }
2233
+ if (frame2.token.name !== parsed.name) {
2234
+ throw new Error(`Unclosed section "${frame2.token.name}" before closing "${parsed.name}"`);
2235
+ }
2236
+ frame2.token.rawEnd = open4;
2237
+ tokens = frame2.parent;
2238
+ index = standalone?.nextIndex ?? parsed.end;
2239
+ continue;
2240
+ }
2241
+ tokens.push({ type: parsed.kind, name: parsed.name, raw: template.slice(open4, parsed.end) });
2242
+ index = parsed.end;
2243
+ }
2244
+ const frame = stack.pop();
2245
+ if (frame !== void 0) {
2246
+ throw new Error(`Unclosed section "${frame.token.name}"`);
2247
+ }
2248
+ return root;
2249
+ }
2250
+ function parseTag(template, open4) {
2251
+ if (template.startsWith("{{{", open4)) {
2252
+ const close2 = template.indexOf("}}}", open4 + 3);
2253
+ if (close2 === -1) {
2254
+ throw new Error("Unclosed unescaped tag");
2255
+ }
2256
+ return { kind: "unescaped", name: template.slice(open4 + 3, close2).trim(), end: close2 + 3 };
2257
+ }
2258
+ const close = template.indexOf("}}", open4 + 2);
2259
+ if (close === -1) {
2260
+ throw new Error("Unclosed tag");
2261
+ }
2262
+ const raw = template.slice(open4 + 2, close).trim();
2263
+ const sigil = raw[0];
2264
+ const name = sigil === void 0 ? "" : raw.slice(1).trim();
2265
+ const end = close + 2;
2266
+ if (sigil === "#") return { kind: "section", name, end };
2267
+ if (sigil === "^") return { kind: "inverted", name, end };
2268
+ if (sigil === "/") return { kind: "close", name, end };
2269
+ if (sigil === "!") return { kind: "comment", name, end };
2270
+ if (sigil === "&") return { kind: "unescaped", name, end };
2271
+ if (sigil === ">") return { kind: "partial", name, end };
2272
+ if (sigil === "=" && raw.endsWith("=")) return { kind: "delimiter", name, end };
2273
+ return { kind: "name", name: raw, end };
2274
+ }
2275
+ function getStandalone(template, tagStart, tagEnd, kind) {
2276
+ if (!["section", "inverted", "close", "comment", "partial", "delimiter"].includes(kind)) {
2277
+ return void 0;
2278
+ }
2279
+ const lineStart = template.lastIndexOf("\n", tagStart - 1) + 1;
2280
+ if (!isWhitespace(template.slice(lineStart, tagStart))) {
2281
+ return void 0;
2282
+ }
2283
+ let cursor = tagEnd;
2284
+ while (cursor < template.length && (template[cursor] === " " || template[cursor] === " ")) {
2285
+ cursor += 1;
2286
+ }
2287
+ if (template.startsWith("\r\n", cursor)) {
2288
+ return { lineStart, nextIndex: cursor + 2 };
2289
+ }
2290
+ if (template[cursor] === "\n") {
2291
+ return { lineStart, nextIndex: cursor + 1 };
2292
+ }
2293
+ if (cursor === template.length) {
2294
+ return { lineStart, nextIndex: cursor };
2295
+ }
2296
+ return void 0;
2297
+ }
2298
+ function renderTokens(tokens, context, template, escape, preserveMissing) {
2299
+ let output = "";
2300
+ for (const token of tokens) {
2301
+ switch (token.type) {
2302
+ case "text":
2303
+ output += token.value;
2304
+ continue;
2305
+ case "name":
2306
+ case "unescaped": {
2307
+ const value = lookup2(context, token.name);
2308
+ if (value == null) {
2309
+ if (preserveMissing) {
2310
+ output += token.raw;
2311
+ }
2312
+ continue;
2313
+ }
2314
+ const rendered = String(value);
2315
+ output += token.type === "name" ? escape(rendered) : rendered;
2316
+ continue;
2317
+ }
2318
+ case "inverted": {
2319
+ const value = lookup2(context, token.name);
2320
+ if (!value || Array.isArray(value) && value.length === 0) {
2321
+ output += renderTokens(token.children, context, template, escape, preserveMissing);
2322
+ }
2323
+ continue;
2324
+ }
2325
+ case "section": {
2326
+ const value = lookup2(context, token.name);
2327
+ if (!value) {
2328
+ continue;
2329
+ }
2330
+ if (Array.isArray(value)) {
2331
+ for (const item of value) {
2332
+ output += renderTokens(token.children, pushContext(context, item), template, escape, preserveMissing);
2333
+ }
2334
+ continue;
2335
+ }
2336
+ if (typeof value === "function") {
2337
+ const raw = template.slice(token.rawStart, token.rawEnd);
2338
+ const rendered = value.call(
2339
+ context.view,
2340
+ raw,
2341
+ (nextTemplate) => renderTemplateInContext(nextTemplate, context, escape, preserveMissing)
2342
+ );
2343
+ if (rendered != null) {
2344
+ output += String(rendered);
2345
+ }
2346
+ continue;
2347
+ }
2348
+ if (typeof value === "object" || typeof value === "string" || typeof value === "number") {
2349
+ output += renderTokens(token.children, pushContext(context, value), template, escape, preserveMissing);
2350
+ continue;
2351
+ }
2352
+ output += renderTokens(token.children, context, template, escape, preserveMissing);
2353
+ }
2354
+ }
2355
+ }
2356
+ return output;
2357
+ }
2358
+ function lookup2(context, name) {
2359
+ if (name === ".") {
2360
+ return callLambda(context.view, context.view);
2361
+ }
2362
+ let cursor = context;
2363
+ while (cursor !== void 0) {
2364
+ const result = name.includes(".") ? lookupDotted(cursor.view, name) : lookupName(cursor.view, name);
2365
+ if (result.hit) {
2366
+ return callLambda(result.value, cursor.view);
2367
+ }
2368
+ cursor = cursor.parent;
2369
+ }
2370
+ return void 0;
2371
+ }
2372
+ function lookupName(view, name) {
2373
+ if (!isPropertyContainer(view) || !hasProperty(view, name)) {
2374
+ return { hit: false, value: void 0 };
2375
+ }
2376
+ return { hit: true, value: view[name] };
2377
+ }
2378
+ function lookupDotted(view, name) {
2379
+ const parts = name.split(".");
2380
+ let value = view;
2381
+ let hit = false;
2382
+ for (let index = 0; value != null && index < parts.length; index += 1) {
2383
+ const part = parts[index] ?? "";
2384
+ if (index === parts.length - 1) {
2385
+ hit = hasProperty(Object(value), part);
2386
+ }
2387
+ value = Object(value)[part];
2388
+ }
2389
+ return { hit, value };
2390
+ }
2391
+ function callLambda(value, view) {
2392
+ return typeof value === "function" ? value.call(view) : value;
2393
+ }
2394
+ function pushContext(parent, view) {
2395
+ return { view, parent };
2396
+ }
2397
+ function appendText(tokens, value, start) {
2398
+ if (value === "") {
2399
+ return;
2400
+ }
2401
+ const previous = tokens[tokens.length - 1];
2402
+ if (previous?.type === "text") {
2403
+ previous.value += value;
2404
+ return;
2405
+ }
2406
+ tokens.push({ type: "text", value, start });
2407
+ }
2408
+ function trimTextAfter(tokens, lineStart) {
2409
+ const previous = tokens[tokens.length - 1];
2410
+ if (previous?.type !== "text") {
2411
+ return;
2412
+ }
2413
+ const keep = Math.max(0, lineStart - previous.start);
2414
+ previous.value = previous.value.slice(0, keep);
2415
+ if (previous.value === "") {
2416
+ tokens.pop();
2417
+ }
2418
+ }
2419
+ function escapeHtml(value) {
2420
+ return value.replace(/[&<>"'`=/]/g, (char) => HTML_ESCAPE[char] ?? char);
2421
+ }
2422
+ function isWhitespace(value) {
2423
+ return value.trim() === "";
2424
+ }
2425
+ function isPropertyContainer(value) {
2426
+ return typeof value === "object" && value !== null || typeof value === "function";
2427
+ }
2428
+ function hasProperty(value, key) {
2429
+ return key in value;
2430
+ }
2431
+
2432
+ // packages/design-system/src/acp/writer.ts
2433
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
2434
+ var storage = new AsyncLocalStorage2();
2435
+
2436
+ // packages/design-system/src/dashboard/terminal.ts
2437
+ import readline from "node:readline";
2438
+ import { PassThrough } from "node:stream";
2439
+
2440
+ // packages/design-system/src/explorer/state.ts
2441
+ var REGION_HEADER = 1 << 0;
2442
+ var REGION_LIST = 1 << 1;
2443
+ var REGION_DETAIL = 1 << 2;
2444
+ var REGION_FOOTER = 1 << 3;
2445
+ var REGION_MODAL = 1 << 4;
2446
+ var REGION_TOAST = 1 << 5;
2447
+ var REGION_ALL = REGION_HEADER | REGION_LIST | REGION_DETAIL | REGION_FOOTER | REGION_MODAL | REGION_TOAST;
2448
+
2449
+ // packages/design-system/src/prompts/index.ts
2450
+ import * as clack from "@clack/prompts";
2451
+
2452
+ // packages/design-system/src/prompts/primitives/cancel.ts
2453
+ import { isCancel } from "@clack/prompts";
2454
+
2455
+ // packages/config-extends/src/resolve.ts
2456
+ var MAX_EXTENDS_DEPTH = 5;
2457
+ var YIELD_TOKEN = "{{yield}}";
2458
+ async function resolve(chain, options) {
2459
+ const { baseLayers, documentIndex, documentLayer } = classifyChain(chain);
2460
+ const parsedDocument = parseDocument3(documentLayer.content, documentLayer.filePath);
2461
+ const resolvedBase = shouldResolveBase(parsedDocument, options.autoExtend) ? await resolveBaseChain({
2462
+ name: documentLayer.baseName ?? getBaseName(documentLayer.filePath),
2463
+ baseLayers,
2464
+ options,
2465
+ optional: !parsedDocument.extends,
2466
+ visited: /* @__PURE__ */ new Set([documentLayer.filePath]),
2467
+ depth: 1
2468
+ }) : void 0;
2469
+ const composedPrompt = composePromptChain(
2470
+ {
2471
+ source: documentLayer.source,
2472
+ data: parsedDocument.data
2473
+ },
2474
+ resolvedBase?.layers ?? []
2475
+ );
2476
+ const merged = mergeLayers([
2477
+ ...collectDataLayers(chain.slice(0, documentIndex)),
2478
+ {
2479
+ source: documentLayer.source,
2480
+ data: withResolvedPrompt(parsedDocument.data, composedPrompt?.prompt)
2481
+ },
2482
+ ...stripResolvedBasePrompts(resolvedBase?.layers ?? [], composedPrompt?.consumedBaseIndexes ?? /* @__PURE__ */ new Set()),
2483
+ ...collectDataLayers(chain.slice(documentIndex + 1))
2484
+ ]);
2485
+ if (composedPrompt !== void 0 && merged.sources.prompt === documentLayer.source && composedPrompt.source !== void 0) {
2486
+ merged.sources.prompt = composedPrompt.source;
2487
+ }
2488
+ return {
2489
+ data: merged.data,
2490
+ sources: merged.sources,
2491
+ chain: [documentLayer.filePath, ...resolvedBase?.chain ?? []]
2492
+ };
2493
+ }
2494
+ function classifyChain(chain) {
2495
+ const baseLayers = [];
2496
+ const documentLayers = [];
2497
+ for (const [index, layer] of chain.entries()) {
2498
+ if (isDataLayer(layer)) {
2499
+ continue;
2500
+ }
2501
+ if (isDocumentLayer(layer)) {
2502
+ documentLayers.push({ index, layer });
2503
+ continue;
2504
+ }
2505
+ if (isBaseLayer(layer)) {
2506
+ baseLayers.push(layer);
2507
+ }
2508
+ }
2509
+ if (documentLayers.length !== 1) {
2510
+ throw new Error(`Exactly one document layer is required, received ${documentLayers.length}.`);
2511
+ }
2512
+ return {
2513
+ baseLayers,
2514
+ documentIndex: documentLayers[0].index,
2515
+ documentLayer: documentLayers[0].layer
2516
+ };
2517
+ }
2518
+ async function resolveBaseChain({
2519
+ name,
2520
+ baseLayers,
2521
+ options,
2522
+ optional,
2523
+ visited,
2524
+ depth
2525
+ }) {
2526
+ if (depth > MAX_EXTENDS_DEPTH) {
2527
+ throw new Error(`Maximum extends depth exceeded (${MAX_EXTENDS_DEPTH}).`);
2528
+ }
2529
+ let discoveredBase;
2530
+ try {
2531
+ discoveredBase = await findBase(
2532
+ name,
2533
+ baseLayers.map((layer) => layer.path),
2534
+ options.fs
2535
+ );
2536
+ } catch (error2) {
2537
+ if (optional && isBaseNotFoundError(error2)) {
2538
+ return void 0;
2539
+ }
2540
+ throw error2;
2541
+ }
2542
+ if (visited.has(discoveredBase.filePath)) {
2543
+ if (optional) {
2544
+ return void 0;
2545
+ }
2546
+ throw new Error(
2547
+ `Circular extends detected.
2548
+ Visited files:
2549
+ - ${[...visited, discoveredBase.filePath].join("\n- ")}`
2550
+ );
2551
+ }
2552
+ const matchedBaseIndex = baseLayers.findIndex(
2553
+ (layer) => layer.path === path11.dirname(discoveredBase.filePath)
2554
+ );
2555
+ if (matchedBaseIndex === -1) {
2556
+ throw new Error(`Resolved base is outside configured base paths: ${discoveredBase.filePath}`);
2557
+ }
2558
+ const parsedBase = parseDocument3(discoveredBase.content, discoveredBase.filePath);
2559
+ const nextVisited = new Set(visited);
2560
+ nextVisited.add(discoveredBase.filePath);
2561
+ const nestedBase = parsedBase.extends ? await resolveBaseChain({
2562
+ name: getBaseName(discoveredBase.filePath),
2563
+ baseLayers: baseLayers.slice(matchedBaseIndex + 1),
2564
+ options,
2565
+ optional: false,
2566
+ visited: nextVisited,
2567
+ depth: depth + 1
2568
+ }) : void 0;
2569
+ return {
2570
+ layers: [
2571
+ {
2572
+ source: baseLayers[matchedBaseIndex].source,
2573
+ data: parsedBase.data
2574
+ },
2575
+ ...nestedBase?.layers ?? []
2576
+ ],
2577
+ chain: [discoveredBase.filePath, ...nestedBase?.chain ?? []]
2578
+ };
2579
+ }
2580
+ function collectDataLayers(chain) {
2581
+ return chain.filter(isDataLayer);
2582
+ }
2583
+ function composePromptChain(documentLayer, baseLayers) {
2584
+ const documentPrompt = documentLayer.data.prompt;
2585
+ if (documentPrompt !== void 0 && typeof documentPrompt !== "string") {
2586
+ return void 0;
2587
+ }
2588
+ if (documentPrompt !== void 0) {
2589
+ assertValidYieldCount(documentPrompt);
2590
+ }
2591
+ let prompt = documentPrompt;
2592
+ let source = prompt === void 0 || prompt === "" ? void 0 : documentLayer.source;
2593
+ const consumedBaseIndexes = /* @__PURE__ */ new Set();
2594
+ for (const [index, layer] of baseLayers.entries()) {
2595
+ const candidate = layer.data.prompt;
2596
+ if (candidate === void 0) {
2597
+ continue;
2598
+ }
2599
+ if (typeof candidate !== "string") {
2600
+ break;
2601
+ }
2602
+ assertValidYieldCount(candidate);
2603
+ consumedBaseIndexes.add(index);
2604
+ prompt = composeAdjacentPrompts(prompt, candidate);
2605
+ if (source === void 0 && candidate !== "") {
2606
+ source = layer.source;
2607
+ }
2608
+ }
2609
+ if (prompt !== void 0 && prompt.includes(YIELD_TOKEN)) {
2610
+ throw new Error('Final resolved prompt contains an unresolved "{{yield}}" token.');
2611
+ }
2612
+ if (prompt === void 0) {
2613
+ return void 0;
2614
+ }
2615
+ return {
2616
+ consumedBaseIndexes,
2617
+ prompt,
2618
+ source
2619
+ };
2620
+ }
2621
+ function composeAdjacentPrompts(high, low) {
2622
+ if (high === void 0 || high === "") {
2623
+ return low.includes(YIELD_TOKEN) ? replaceYield(low, "") : low;
2624
+ }
2625
+ if (high.includes(YIELD_TOKEN)) {
2626
+ return replaceYield(high, low);
2627
+ }
2628
+ if (low.includes(YIELD_TOKEN)) {
2629
+ return replaceYield(low, high);
2630
+ }
2631
+ return high;
2632
+ }
2633
+ function replaceYield(prompt, replacement) {
2634
+ return renderTemplate(prompt, {}, { yield: replacement, escape: "none" });
2635
+ }
2636
+ function assertValidYieldCount(prompt) {
2637
+ if (countYieldTokens(prompt) > 1) {
2638
+ throw new Error('Prompt composition supports exactly one "{{yield}}" token per prompt.');
2639
+ }
2640
+ }
2641
+ function countYieldTokens(prompt) {
2642
+ return prompt.split(YIELD_TOKEN).length - 1;
2643
+ }
2644
+ function withResolvedPrompt(data, prompt) {
2645
+ if (prompt === void 0) {
2646
+ return data;
2647
+ }
2648
+ return {
2649
+ ...data,
2650
+ prompt
2651
+ };
2652
+ }
2653
+ function stripResolvedBasePrompts(layers, consumedBaseIndexes) {
2654
+ return layers.map((layer, index) => {
2655
+ if (!consumedBaseIndexes.has(index) || typeof layer.data.prompt !== "string") {
2656
+ return layer;
2657
+ }
2658
+ const { prompt: ignoredPrompt, ...data } = layer.data;
2659
+ void ignoredPrompt;
2660
+ return {
2661
+ source: layer.source,
2662
+ data
2663
+ };
2664
+ });
2665
+ }
2666
+ function getBaseName(filePath) {
1914
2667
  return path11.basename(filePath, path11.extname(filePath));
1915
2668
  }
1916
2669
  function shouldResolveBase(parsedDocument, autoExtend) {
@@ -2013,15 +2766,12 @@ var fileMutation = {
2013
2766
  backup
2014
2767
  };
2015
2768
 
2016
- // packages/config-mutations/src/execution/apply-mutation.ts
2017
- import Mustache from "mustache";
2018
-
2019
2769
  // packages/config-mutations/src/formats/json.ts
2020
2770
  import * as jsonc from "jsonc-parser";
2021
2771
  function isConfigObject(value) {
2022
2772
  return typeof value === "object" && value !== null && !Array.isArray(value);
2023
2773
  }
2024
- function parse2(content) {
2774
+ function parse3(content) {
2025
2775
  if (!content || content.trim() === "") {
2026
2776
  return {};
2027
2777
  }
@@ -2094,7 +2844,7 @@ function prune2(obj, shape) {
2094
2844
  return { changed, result };
2095
2845
  }
2096
2846
  var jsonFormat = {
2097
- parse: parse2,
2847
+ parse: parse3,
2098
2848
  serialize,
2099
2849
  merge: merge2,
2100
2850
  prune: prune2
@@ -2105,7 +2855,7 @@ import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
2105
2855
  function isConfigObject2(value) {
2106
2856
  return typeof value === "object" && value !== null && !Array.isArray(value);
2107
2857
  }
2108
- function parse3(content) {
2858
+ function parse4(content) {
2109
2859
  if (!content || content.trim() === "") {
2110
2860
  return {};
2111
2861
  }
@@ -2169,7 +2919,7 @@ function prune3(obj, shape) {
2169
2919
  return { changed, result };
2170
2920
  }
2171
2921
  var tomlFormat = {
2172
- parse: parse3,
2922
+ parse: parse4,
2173
2923
  serialize: serialize2,
2174
2924
  merge: merge3,
2175
2925
  prune: prune3
@@ -2180,7 +2930,7 @@ import { parse as parseYaml2, stringify as stringifyYaml } from "yaml";
2180
2930
  function isConfigObject3(value) {
2181
2931
  return typeof value === "object" && value !== null && !Array.isArray(value);
2182
2932
  }
2183
- function parse4(content) {
2933
+ function parse5(content) {
2184
2934
  if (!content || content.trim() === "") {
2185
2935
  return {};
2186
2936
  }
@@ -2244,7 +2994,7 @@ function prune4(obj, shape) {
2244
2994
  return { changed, result };
2245
2995
  }
2246
2996
  var yamlFormat = {
2247
- parse: parse4,
2997
+ parse: parse5,
2248
2998
  serialize: serialize3,
2249
2999
  merge: merge4,
2250
3000
  prune: prune4
@@ -2819,7 +3569,7 @@ async function applyTemplateWrite(mutation, context, options) {
2819
3569
  };
2820
3570
  const template = await context.templates(mutation.templateId);
2821
3571
  const templateContext = mutation.context ? resolveValue(mutation.context, options) : {};
2822
- const rendered = Mustache.render(template, templateContext);
3572
+ const rendered = renderTemplate(template, templateContext);
2823
3573
  const existed = await pathExists(context.fs, targetPath);
2824
3574
  if (!context.dryRun) {
2825
3575
  await context.fs.writeFile(targetPath, rendered, { encoding: "utf8" });
@@ -2849,7 +3599,7 @@ async function applyTemplateMerge(mutation, context, options, formatName) {
2849
3599
  const format = getConfigFormat(formatName);
2850
3600
  const template = await context.templates(mutation.templateId);
2851
3601
  const templateContext = mutation.context ? resolveValue(mutation.context, options) : {};
2852
- const rendered = Mustache.render(template, templateContext);
3602
+ const rendered = renderTemplate(template, templateContext);
2853
3603
  let templateDoc;
2854
3604
  try {
2855
3605
  templateDoc = format.parse(rendered);
@@ -2930,10 +3680,6 @@ async function executeMutation(mutation, context, options) {
2930
3680
  }
2931
3681
  }
2932
3682
 
2933
- // packages/config-mutations/src/template/render.ts
2934
- import Mustache2 from "mustache";
2935
- var originalEscape = Mustache2.escape;
2936
-
2937
3683
  // packages/poe-code-config/src/store.ts
2938
3684
  async function readMergedDocument(fs, globalPath, projectPath) {
2939
3685
  const globalDocument = await readStoredDocument(fs, globalPath);
@@ -3312,7 +4058,7 @@ import { mkdtempSync as mkdtempSync2, rmSync as rmSync2 } from "node:fs";
3312
4058
  import { readFile as readFile4, writeFile } from "node:fs/promises";
3313
4059
  import { tmpdir as tmpdir2 } from "node:os";
3314
4060
  import path20 from "node:path";
3315
- import { PassThrough, Writable as Writable2 } from "node:stream";
4061
+ import { PassThrough as PassThrough2, Writable as Writable2 } from "node:stream";
3316
4062
 
3317
4063
  // packages/runner-e2b/src/job-handle.ts
3318
4064
  import path19 from "node:path";
@@ -3559,8 +4305,8 @@ function createOpenedE2bEnv(input) {
3559
4305
  return env;
3560
4306
  }
3561
4307
  function runE2bCommand(sandbox, spec) {
3562
- const stdout = spec.stdout === "inherit" ? null : new PassThrough();
3563
- const stderr = spec.stderr === "inherit" ? null : new PassThrough();
4308
+ const stdout = spec.stdout === "inherit" ? null : new PassThrough2();
4309
+ const stderr = spec.stderr === "inherit" ? null : new PassThrough2();
3564
4310
  let e2bHandle = null;
3565
4311
  const command = shellCommand([spec.command, ...spec.args ?? []]);
3566
4312
  const started = sandbox.commands.run(command, {
@@ -3634,7 +4380,7 @@ function runE2bCommand(sandbox, spec) {
3634
4380
  };
3635
4381
  }
3636
4382
  function runE2bPty(sandbox, spec) {
3637
- const stdout = new PassThrough();
4383
+ const stdout = new PassThrough2();
3638
4384
  let handleRef = null;
3639
4385
  const stdin = new Writable2({
3640
4386
  write(chunk, _encoding, callback) {
@@ -4277,9 +5023,9 @@ var allSpawnConfigs = [
4277
5023
  kimiSpawnConfig,
4278
5024
  gooseSpawnConfig
4279
5025
  ];
4280
- var lookup2 = /* @__PURE__ */ new Map();
5026
+ var lookup3 = /* @__PURE__ */ new Map();
4281
5027
  for (const config of allSpawnConfigs) {
4282
- lookup2.set(config.agentId, config);
5028
+ lookup3.set(config.agentId, config);
4283
5029
  }
4284
5030
  var acpLookup = /* @__PURE__ */ new Map();
4285
5031
  acpLookup.set(openCodeAcpSpawnConfig.agentId, openCodeAcpSpawnConfig);
@@ -4290,7 +5036,7 @@ function getSpawnConfig(input) {
4290
5036
  if (!resolvedId) {
4291
5037
  return void 0;
4292
5038
  }
4293
- return lookup2.get(resolvedId);
5039
+ return lookup3.get(resolvedId);
4294
5040
  }
4295
5041
  function listMcpSupportedAgents() {
4296
5042
  const supported = [];
@@ -4355,511 +5101,99 @@ function stripModelNamespace(model) {
4355
5101
  }
4356
5102
 
4357
5103
  // packages/agent-spawn/src/spawn.ts
4358
- function resolveCliConfig(agentId) {
4359
- const resolved = resolveConfig(agentId);
4360
- if (!resolved.spawnConfig) {
4361
- throw new Error(`Agent "${resolved.agentId}" has no spawn config.`);
4362
- }
4363
- if (resolved.spawnConfig.kind !== "cli") {
4364
- throw new Error(`Agent "${resolved.agentId}" does not support CLI spawn.`);
4365
- }
4366
- if (!resolved.binaryName) {
4367
- throw new Error(`Agent "${resolved.agentId}" has no binaryName.`);
4368
- }
4369
- return {
4370
- agentId: resolved.agentId,
4371
- binaryName: resolved.binaryName,
4372
- spawnConfig: resolved.spawnConfig
4373
- };
4374
- }
4375
- function getDefaultArgsPosition(config) {
4376
- return config.defaultArgsPosition ?? "afterPrompt";
4377
- }
4378
- function getMcpArgsPosition(config) {
4379
- if (config.mcpArgsPosition) {
4380
- return config.mcpArgsPosition;
4381
- }
4382
- return config.mcpArgsBeforeCommand ? "beforeCommand" : "afterCommand";
4383
- }
4384
- function buildCliArgs(config, options, stdinMode) {
4385
- const mcpArgs = getMcpArgs(config, options.mcpServers);
4386
- const resumeArgs = getResumeArgs(config, options);
4387
- const defaultArgsPosition = getDefaultArgsPosition(config);
4388
- const mcpArgsPosition = getMcpArgsPosition(config);
4389
- const resumeArgsPosition = config.resume?.position ?? "afterPrompt";
4390
- const args = [];
4391
- if (mcpArgsPosition === "beforeCommand") {
4392
- args.push(...mcpArgs);
4393
- }
4394
- if (defaultArgsPosition === "beforePrompt") {
4395
- args.push(...config.defaultArgs);
4396
- }
4397
- if (mcpArgsPosition === "beforePrompt") {
4398
- args.push(...mcpArgs);
4399
- }
4400
- if (stdinMode) {
4401
- args.push(config.promptFlag);
4402
- if (resumeArgsPosition === "beforePrompt") {
4403
- args.push(...resumeArgs);
4404
- }
4405
- args.push(...stdinMode.omitPrompt ? [] : [options.prompt], ...stdinMode.extraArgs);
4406
- } else {
4407
- args.push(config.promptFlag);
4408
- if (resumeArgsPosition === "beforePrompt") {
4409
- args.push(...resumeArgs);
4410
- }
4411
- args.push(options.prompt);
4412
- }
4413
- if (options.model && config.modelFlag) {
4414
- let model = config.modelStripProviderPrefix ? stripModelNamespace(options.model) : options.model;
4415
- if (config.modelTransform) model = config.modelTransform(model);
4416
- args.push(config.modelFlag, model);
4417
- }
4418
- if (defaultArgsPosition === "afterPrompt") {
4419
- args.push(...config.defaultArgs);
4420
- }
4421
- if (mcpArgsPosition === "afterCommand") {
4422
- args.push(...mcpArgs);
4423
- }
4424
- const mode = resolveModeConfig(config.modes[options.mode ?? "yolo"]);
4425
- args.push(...mode.args);
4426
- if (options.args && options.args.length > 0) {
4427
- if (resumeArgsPosition === "afterPrompt") {
4428
- args.push(...resumeArgs);
4429
- }
4430
- args.push(...options.args);
4431
- } else if (resumeArgsPosition === "afterPrompt") {
4432
- args.push(...resumeArgs);
4433
- }
4434
- return { args, env: mode.env };
4435
- }
4436
- function getResumeArgs(config, options) {
4437
- if (!options.resumeThreadId) {
4438
- return [];
4439
- }
4440
- if (!config.resume) {
4441
- throw new Error(`Agent "${config.agentId}" does not support resumeThreadId.`);
4442
- }
4443
- return config.resume.args(options.resumeThreadId, options.cwd ?? process.cwd());
4444
- }
4445
- function buildSpawnArgs(agentId, options) {
4446
- const { binaryName, spawnConfig } = resolveCliConfig(agentId);
4447
- const stdinMode = options.useStdin && spawnConfig.stdinMode ? spawnConfig.stdinMode : void 0;
4448
- const result = buildCliArgs(spawnConfig, options, stdinMode);
4449
- return { binaryName, args: result.args, env: result.env };
4450
- }
4451
-
4452
- // packages/design-system/src/tokens/colors.ts
4453
- import chalk from "chalk";
4454
- var dark = {
4455
- header: (text5) => chalk.magentaBright.bold(text5),
4456
- divider: (text5) => chalk.dim(text5),
4457
- prompt: (text5) => chalk.cyan(text5),
4458
- number: (text5) => chalk.cyanBright(text5),
4459
- intro: (text5) => chalk.bgMagenta.white(` Poe - ${text5} `),
4460
- resolvedSymbol: chalk.magenta("\u25C7"),
4461
- errorSymbol: chalk.red("\u25A0"),
4462
- accent: (text5) => chalk.cyan(text5),
4463
- muted: (text5) => chalk.dim(text5),
4464
- success: (text5) => chalk.green(text5),
4465
- warning: (text5) => chalk.yellow(text5),
4466
- error: (text5) => chalk.red(text5),
4467
- info: (text5) => chalk.magenta(text5),
4468
- badge: (text5) => chalk.bgYellow.black(` ${text5} `)
4469
- };
4470
- var light = {
4471
- header: (text5) => chalk.hex("#a200ff").bold(text5),
4472
- divider: (text5) => chalk.hex("#666666")(text5),
4473
- prompt: (text5) => chalk.hex("#006699").bold(text5),
4474
- number: (text5) => chalk.hex("#0077cc").bold(text5),
4475
- intro: (text5) => chalk.bgHex("#a200ff").white(` Poe - ${text5} `),
4476
- resolvedSymbol: chalk.hex("#a200ff")("\u25C7"),
4477
- errorSymbol: chalk.hex("#cc0000")("\u25A0"),
4478
- accent: (text5) => chalk.hex("#006699").bold(text5),
4479
- muted: (text5) => chalk.hex("#666666")(text5),
4480
- success: (text5) => chalk.hex("#008800")(text5),
4481
- warning: (text5) => chalk.hex("#cc6600")(text5),
4482
- error: (text5) => chalk.hex("#cc0000")(text5),
4483
- info: (text5) => chalk.hex("#a200ff")(text5),
4484
- badge: (text5) => chalk.bgHex("#cc6600").white(` ${text5} `)
4485
- };
4486
-
4487
- // packages/design-system/src/tokens/typography.ts
4488
- import chalk2 from "chalk";
4489
-
4490
- // packages/design-system/src/components/text.ts
4491
- import chalk3 from "chalk";
4492
-
4493
- // packages/design-system/src/internal/output-format.ts
4494
- import { AsyncLocalStorage } from "node:async_hooks";
4495
- var VALID_FORMATS = /* @__PURE__ */ new Set(["terminal", "markdown", "json"]);
4496
- var formatStorage = new AsyncLocalStorage();
4497
- var cached;
4498
- function resolveOutputFormat(env = process.env) {
4499
- const scoped = formatStorage.getStore();
4500
- if (scoped) {
4501
- return scoped;
4502
- }
4503
- if (cached) {
4504
- return cached;
4505
- }
4506
- const raw = env.OUTPUT_FORMAT?.toLowerCase();
4507
- cached = VALID_FORMATS.has(raw) ? raw : "terminal";
4508
- return cached;
4509
- }
4510
-
4511
- // packages/design-system/src/internal/theme-detect.ts
4512
- function detectThemeFromEnv(env) {
4513
- const apple = env.APPLE_INTERFACE_STYLE;
4514
- if (typeof apple === "string") {
4515
- return apple.toLowerCase() === "dark" ? "dark" : "light";
4516
- }
4517
- const vscodeKind = env.VSCODE_COLOR_THEME_KIND;
4518
- if (typeof vscodeKind === "string") {
4519
- const normalized = vscodeKind.toLowerCase();
4520
- if (normalized.includes("light")) {
4521
- return "light";
4522
- }
4523
- if (normalized.includes("dark")) {
4524
- return "dark";
4525
- }
4526
- }
4527
- const colorFGBG = env.COLORFGBG;
4528
- if (typeof colorFGBG === "string") {
4529
- const parts = colorFGBG.split(";").map((part) => Number.parseInt(part, 10));
4530
- const background = parts.at(-1);
4531
- if (Number.isFinite(background)) {
4532
- return background >= 8 ? "light" : "dark";
4533
- }
4534
- }
4535
- return void 0;
4536
- }
4537
- function resolveThemeName(env = process.env) {
4538
- const raw = (env.POE_CODE_THEME ?? env.POE_THEME)?.toLowerCase();
4539
- if (raw === "light" || raw === "dark") {
4540
- return raw;
4541
- }
4542
- const detected = detectThemeFromEnv(env);
4543
- if (detected) {
4544
- return detected;
4545
- }
4546
- return "dark";
4547
- }
4548
- var cachedTheme;
4549
- function getTheme(env) {
4550
- if (cachedTheme) {
4551
- return cachedTheme;
4552
- }
4553
- const themeName = resolveThemeName(env);
4554
- cachedTheme = themeName === "light" ? light : dark;
4555
- return cachedTheme;
4556
- }
4557
-
4558
- // packages/design-system/src/components/symbols.ts
4559
- import chalk4 from "chalk";
4560
- var symbols = {
4561
- get info() {
4562
- const format = resolveOutputFormat();
4563
- if (format === "json") return "info";
4564
- if (format === "markdown") return "(i)";
4565
- return chalk4.magenta("\u25CF");
4566
- },
4567
- get success() {
4568
- const format = resolveOutputFormat();
4569
- if (format === "json") return "success";
4570
- if (format === "markdown") return "[ok]";
4571
- return chalk4.magenta("\u25C6");
4572
- },
4573
- get resolved() {
4574
- const format = resolveOutputFormat();
4575
- if (format === "json") return "resolved";
4576
- if (format === "markdown") return ">";
4577
- return getTheme().resolvedSymbol;
4578
- },
4579
- get errorResolved() {
4580
- const format = resolveOutputFormat();
4581
- if (format === "json") return "error";
4582
- if (format === "markdown") return "[!]";
4583
- return getTheme().errorSymbol;
4584
- },
4585
- get bar() {
4586
- const format = resolveOutputFormat();
4587
- if (format === "json") return "";
4588
- if (format === "markdown") return "|";
4589
- return "\u2502";
4590
- },
4591
- cornerTopRight: "\u256E",
4592
- cornerBottomRight: "\u256F",
4593
- get warning() {
4594
- const format = resolveOutputFormat();
4595
- if (format === "json") return "warning";
4596
- if (format === "markdown") return "[!]";
4597
- return "\u25B2";
4598
- },
4599
- get active() {
4600
- const format = resolveOutputFormat();
4601
- if (format === "json") return "active";
4602
- if (format === "markdown") return "[x]";
4603
- return "\u25C6";
4604
- },
4605
- get inactive() {
4606
- const format = resolveOutputFormat();
4607
- if (format === "json") return "inactive";
4608
- if (format === "markdown") return "[ ]";
4609
- return "\u25CB";
4610
- }
4611
- };
4612
-
4613
- // packages/design-system/src/components/logger.ts
4614
- import chalk6 from "chalk";
4615
-
4616
- // packages/design-system/src/prompts/primitives/log.ts
4617
- import chalk5 from "chalk";
4618
-
4619
- // packages/design-system/src/internal/strip-ansi.ts
4620
- function stripAnsi(value) {
4621
- return value.replace(/\u001b\[[0-9;]*m/g, "");
4622
- }
4623
-
4624
- // packages/design-system/src/prompts/primitives/log.ts
4625
- function writeTerminalMessage(msg, {
4626
- symbol = chalk5.gray("\u2502"),
4627
- secondarySymbol = chalk5.gray("\u2502"),
4628
- spacing: spacing2 = 1,
4629
- withGuide = true
4630
- } = {}) {
4631
- const lines = [];
4632
- const showGuide = withGuide !== false;
4633
- const contentLines = msg.split("\n");
4634
- const prefix = showGuide ? `${symbol} ` : "";
4635
- const continuationPrefix = showGuide ? `${secondarySymbol} ` : "";
4636
- const emptyGuide = showGuide ? secondarySymbol : "";
4637
- for (let index = 0; index < spacing2; index += 1) {
4638
- lines.push(emptyGuide);
5104
+ function resolveCliConfig(agentId) {
5105
+ const resolved = resolveConfig(agentId);
5106
+ if (!resolved.spawnConfig) {
5107
+ throw new Error(`Agent "${resolved.agentId}" has no spawn config.`);
4639
5108
  }
4640
- if (contentLines.length === 0) {
4641
- process.stdout.write("\n");
4642
- return;
5109
+ if (resolved.spawnConfig.kind !== "cli") {
5110
+ throw new Error(`Agent "${resolved.agentId}" does not support CLI spawn.`);
4643
5111
  }
4644
- const [firstLine = "", ...continuationLines] = contentLines;
4645
- if (firstLine.length > 0) {
4646
- lines.push(`${prefix}${firstLine}`);
4647
- } else {
4648
- lines.push(showGuide ? symbol : "");
5112
+ if (!resolved.binaryName) {
5113
+ throw new Error(`Agent "${resolved.agentId}" has no binaryName.`);
4649
5114
  }
4650
- for (const line of continuationLines) {
4651
- if (line.length > 0) {
4652
- lines.push(`${continuationPrefix}${line}`);
4653
- continue;
4654
- }
4655
- lines.push(emptyGuide);
5115
+ return {
5116
+ agentId: resolved.agentId,
5117
+ binaryName: resolved.binaryName,
5118
+ spawnConfig: resolved.spawnConfig
5119
+ };
5120
+ }
5121
+ function getDefaultArgsPosition(config) {
5122
+ return config.defaultArgsPosition ?? "afterPrompt";
5123
+ }
5124
+ function getMcpArgsPosition(config) {
5125
+ if (config.mcpArgsPosition) {
5126
+ return config.mcpArgsPosition;
4656
5127
  }
4657
- process.stdout.write(`${lines.join("\n")}
4658
- `);
5128
+ return config.mcpArgsBeforeCommand ? "beforeCommand" : "afterCommand";
4659
5129
  }
4660
- function message(msg, options) {
4661
- const format = resolveOutputFormat();
4662
- if (format === "markdown") {
4663
- process.stdout.write(`- ${stripAnsi(msg)}
4664
- `);
4665
- return;
5130
+ function buildCliArgs(config, options, stdinMode) {
5131
+ const mcpArgs = getMcpArgs(config, options.mcpServers);
5132
+ const resumeArgs = getResumeArgs(config, options);
5133
+ const defaultArgsPosition = getDefaultArgsPosition(config);
5134
+ const mcpArgsPosition = getMcpArgsPosition(config);
5135
+ const resumeArgsPosition = config.resume?.position ?? "afterPrompt";
5136
+ const args = [];
5137
+ if (mcpArgsPosition === "beforeCommand") {
5138
+ args.push(...mcpArgs);
4666
5139
  }
4667
- if (format === "json") {
4668
- process.stdout.write(
4669
- `${JSON.stringify({ level: "message", message: stripAnsi(msg) })}
4670
- `
4671
- );
4672
- return;
5140
+ if (defaultArgsPosition === "beforePrompt") {
5141
+ args.push(...config.defaultArgs);
4673
5142
  }
4674
- writeTerminalMessage(msg, options);
4675
- }
4676
- function info(msg) {
4677
- const format = resolveOutputFormat();
4678
- if (format === "markdown") {
4679
- process.stdout.write(`- **info:** ${stripAnsi(msg)}
4680
- `);
4681
- return;
5143
+ if (mcpArgsPosition === "beforePrompt") {
5144
+ args.push(...mcpArgs);
4682
5145
  }
4683
- if (format === "json") {
4684
- process.stdout.write(
4685
- `${JSON.stringify({ level: "info", message: stripAnsi(msg) })}
4686
- `
4687
- );
4688
- return;
5146
+ if (stdinMode) {
5147
+ args.push(config.promptFlag);
5148
+ if (resumeArgsPosition === "beforePrompt") {
5149
+ args.push(...resumeArgs);
5150
+ }
5151
+ args.push(...stdinMode.omitPrompt ? [] : [options.prompt], ...stdinMode.extraArgs);
5152
+ } else {
5153
+ args.push(config.promptFlag);
5154
+ if (resumeArgsPosition === "beforePrompt") {
5155
+ args.push(...resumeArgs);
5156
+ }
5157
+ args.push(options.prompt);
4689
5158
  }
4690
- message(msg, { symbol: symbols.info });
4691
- }
4692
- function success(msg) {
4693
- const format = resolveOutputFormat();
4694
- if (format === "markdown") {
4695
- process.stdout.write(`- **success:** ${stripAnsi(msg)}
4696
- `);
4697
- return;
5159
+ if (options.model && config.modelFlag) {
5160
+ let model = config.modelStripProviderPrefix ? stripModelNamespace(options.model) : options.model;
5161
+ if (config.modelTransform) model = config.modelTransform(model);
5162
+ args.push(config.modelFlag, model);
4698
5163
  }
4699
- if (format === "json") {
4700
- process.stdout.write(
4701
- `${JSON.stringify({ level: "success", message: stripAnsi(msg) })}
4702
- `
4703
- );
4704
- return;
5164
+ if (defaultArgsPosition === "afterPrompt") {
5165
+ args.push(...config.defaultArgs);
4705
5166
  }
4706
- message(msg, { symbol: symbols.success });
4707
- }
4708
- function warn(msg) {
4709
- const format = resolveOutputFormat();
4710
- if (format === "markdown") {
4711
- process.stdout.write(`- **warning:** ${stripAnsi(msg)}
4712
- `);
4713
- return;
5167
+ if (mcpArgsPosition === "afterCommand") {
5168
+ args.push(...mcpArgs);
4714
5169
  }
4715
- if (format === "json") {
4716
- process.stdout.write(
4717
- `${JSON.stringify({ level: "warn", message: stripAnsi(msg) })}
4718
- `
4719
- );
4720
- return;
5170
+ const mode = resolveModeConfig(config.modes[options.mode ?? "yolo"]);
5171
+ args.push(...mode.args);
5172
+ if (options.args && options.args.length > 0) {
5173
+ if (resumeArgsPosition === "afterPrompt") {
5174
+ args.push(...resumeArgs);
5175
+ }
5176
+ args.push(...options.args);
5177
+ } else if (resumeArgsPosition === "afterPrompt") {
5178
+ args.push(...resumeArgs);
4721
5179
  }
4722
- message(msg, { symbol: chalk5.yellow("\u25B2") });
5180
+ return { args, env: mode.env };
4723
5181
  }
4724
- function error(msg) {
4725
- const format = resolveOutputFormat();
4726
- if (format === "markdown") {
4727
- process.stdout.write(`- **error:** ${stripAnsi(msg)}
4728
- `);
4729
- return;
5182
+ function getResumeArgs(config, options) {
5183
+ if (!options.resumeThreadId) {
5184
+ return [];
4730
5185
  }
4731
- if (format === "json") {
4732
- process.stdout.write(
4733
- `${JSON.stringify({ level: "error", message: stripAnsi(msg) })}
4734
- `
4735
- );
4736
- return;
5186
+ if (!config.resume) {
5187
+ throw new Error(`Agent "${config.agentId}" does not support resumeThreadId.`);
4737
5188
  }
4738
- message(msg, { symbol: chalk5.red("\u25A0") });
5189
+ return config.resume.args(options.resumeThreadId, options.cwd ?? process.cwd());
4739
5190
  }
4740
- var log = {
4741
- info,
4742
- success,
4743
- message,
4744
- warn,
4745
- error
4746
- };
4747
-
4748
- // packages/design-system/src/components/logger.ts
4749
- function createLogger(emitter) {
4750
- const emit = (level, message2) => {
4751
- if (emitter) {
4752
- emitter(message2);
4753
- return;
4754
- }
4755
- if (level === "success") {
4756
- log.success(message2);
4757
- return;
4758
- }
4759
- if (level === "warn") {
4760
- log.warn(message2);
4761
- return;
4762
- }
4763
- if (level === "error") {
4764
- log.error(message2);
4765
- return;
4766
- }
4767
- log.info(message2);
4768
- };
4769
- return {
4770
- info(message2) {
4771
- emit("info", message2);
4772
- },
4773
- success(message2) {
4774
- emit("success", message2);
4775
- },
4776
- warn(message2) {
4777
- emit("warn", message2);
4778
- },
4779
- error(message2) {
4780
- emit("error", message2);
4781
- },
4782
- resolved(label, value) {
4783
- if (emitter) {
4784
- emitter(`${label}: ${value}`);
4785
- return;
4786
- }
4787
- log.message(`${label}
4788
- ${value}`, { symbol: symbols.resolved });
4789
- },
4790
- errorResolved(label, value) {
4791
- if (emitter) {
4792
- emitter(`${label}: ${value}`);
4793
- return;
4794
- }
4795
- log.message(`${label}
4796
- ${value}`, { symbol: symbols.errorResolved });
4797
- },
4798
- message(message2, symbol) {
4799
- if (emitter) {
4800
- emitter(message2);
4801
- return;
4802
- }
4803
- log.message(message2, { symbol: symbol ?? chalk6.gray("\u2502") });
4804
- }
4805
- };
5191
+ function buildSpawnArgs(agentId, options) {
5192
+ const { binaryName, spawnConfig } = resolveCliConfig(agentId);
5193
+ const stdinMode = options.useStdin && spawnConfig.stdinMode ? spawnConfig.stdinMode : void 0;
5194
+ const result = buildCliArgs(spawnConfig, options, stdinMode);
5195
+ return { binaryName, args: result.args, env: result.env };
4806
5196
  }
4807
- var logger = createLogger();
4808
-
4809
- // packages/design-system/src/components/table.ts
4810
- import { Table } from "console-table-printer";
4811
-
4812
- // packages/design-system/src/acp/components.ts
4813
- import chalk7 from "chalk";
4814
-
4815
- // packages/design-system/src/acp/writer.ts
4816
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
4817
- var storage = new AsyncLocalStorage2();
4818
-
4819
- // packages/design-system/src/acp/components.ts
4820
- var AGENT_PREFIX = `${chalk7.green.bold("\u2713")} agent: `;
4821
-
4822
- // packages/design-system/src/dashboard/buffer.ts
4823
- import chalk8 from "chalk";
4824
-
4825
- // packages/design-system/src/dashboard/terminal.ts
4826
- import readline from "node:readline";
4827
- import { PassThrough as PassThrough2 } from "node:stream";
4828
-
4829
- // packages/design-system/src/explorer/state.ts
4830
- var REGION_HEADER = 1 << 0;
4831
- var REGION_LIST = 1 << 1;
4832
- var REGION_DETAIL = 1 << 2;
4833
- var REGION_FOOTER = 1 << 3;
4834
- var REGION_MODAL = 1 << 4;
4835
- var REGION_TOAST = 1 << 5;
4836
- var REGION_ALL = REGION_HEADER | REGION_LIST | REGION_DETAIL | REGION_FOOTER | REGION_MODAL | REGION_TOAST;
4837
-
4838
- // packages/design-system/src/prompts/index.ts
4839
- import chalk15 from "chalk";
4840
- import * as clack from "@clack/prompts";
4841
-
4842
- // packages/design-system/src/prompts/primitives/cancel.ts
4843
- import chalk9 from "chalk";
4844
- import { isCancel } from "@clack/prompts";
4845
-
4846
- // packages/design-system/src/prompts/primitives/intro.ts
4847
- import chalk10 from "chalk";
4848
-
4849
- // packages/design-system/src/prompts/primitives/note.ts
4850
- import chalk11 from "chalk";
4851
-
4852
- // packages/design-system/src/prompts/primitives/outro.ts
4853
- import chalk12 from "chalk";
4854
-
4855
- // packages/design-system/src/prompts/primitives/spinner.ts
4856
- import chalk14 from "chalk";
4857
-
4858
- // packages/design-system/src/static/spinner.ts
4859
- import chalk13 from "chalk";
4860
-
4861
- // packages/design-system/src/static/menu.ts
4862
- import chalk16 from "chalk";
4863
5197
 
4864
5198
  // packages/agent-spawn/src/autonomous.ts
4865
5199
  var DEFAULT_ACTIVITY_TIMEOUT_MS = 10 * 60 * 1e3;