@sourcegraph/amp 0.0.1749196899-g16ba82 → 0.0.1749225700-gc8788d

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 (47) hide show
  1. package/dist/amp.js +3 -3
  2. package/dist/{client-D1Pmx669.js → client-D0gbNDFf.js} +2 -2
  3. package/dist/{client-D1Pmx669.js.map → client-D0gbNDFf.js.map} +1 -1
  4. package/dist/{console-DZmALLuA.js → console-CDi5rFHv.js} +55 -44
  5. package/dist/console-CDi5rFHv.js.map +1 -0
  6. package/dist/{create_file.node-CygrebBY.js → create_file.node-DL2WuEa4.js} +2 -2
  7. package/dist/{create_file.node-CygrebBY.js.map → create_file.node-DL2WuEa4.js.map} +1 -1
  8. package/dist/{edit_file.node-D_cMkiLI.js → edit_file.node-SSEQ1h3o.js} +3 -3
  9. package/dist/{edit_file.node-D_cMkiLI.js.map → edit_file.node-SSEQ1h3o.js.map} +1 -1
  10. package/dist/{executable-C8qYZU1W.js → executable-CxioKGk7.js} +2 -2
  11. package/dist/{executable-C8qYZU1W.js.map → executable-CxioKGk7.js.map} +1 -1
  12. package/dist/{files--h2VjD8F.js → files-BQmddBey.js} +2 -2
  13. package/dist/{files--h2VjD8F.js.map → files-BQmddBey.js.map} +1 -1
  14. package/dist/fuzzy-server.js +116 -113
  15. package/dist/fuzzy-server.js.map +1 -1
  16. package/dist/{glob.node-AB34HaNl.js → glob.node-C8xrYICA.js} +4 -4
  17. package/dist/{glob.node-AB34HaNl.js.map → glob.node-C8xrYICA.js.map} +1 -1
  18. package/dist/{index-nQBDDlvh.js → index-BY5vhogw.js} +2 -2
  19. package/dist/{index-nQBDDlvh.js.map → index-BY5vhogw.js.map} +1 -1
  20. package/dist/{list_directory.node-DZamBwOx.js → list_directory.node-p_ArdqyT.js} +2 -2
  21. package/dist/{list_directory.node-DZamBwOx.js.map → list_directory.node-p_ArdqyT.js.map} +1 -1
  22. package/dist/{load-profile-DzDzDOIq.js → load-profile-DxrviVkC.js} +2 -2
  23. package/dist/{load-profile-DzDzDOIq.js.map → load-profile-DxrviVkC.js.map} +1 -1
  24. package/dist/{main-WXbdYG4Z.js → main-DIn8dJ9L.js} +409 -398
  25. package/dist/{main-WXbdYG4Z.js.map → main-DIn8dJ9L.js.map} +1 -1
  26. package/dist/{node-CBRPqFin.js → node-C9D1REPh.js} +374 -320
  27. package/dist/node-C9D1REPh.js.map +1 -0
  28. package/dist/{node-D2Ho0W-v.js → node-CHCdepF2.js} +3 -3
  29. package/dist/{node-D2Ho0W-v.js.map → node-CHCdepF2.js.map} +1 -1
  30. package/dist/{node-B9XNCq_w.js → node-CU0lZEVr.js} +2 -2
  31. package/dist/{node-B9XNCq_w.js.map → node-CU0lZEVr.js.map} +1 -1
  32. package/dist/{node-CUCcBUhU.js → node-CrPwEb6e.js} +4 -4
  33. package/dist/{node-CUCcBUhU.js.map → node-CrPwEb6e.js.map} +1 -1
  34. package/dist/{node-Cs3K2AKs.js → node-D-xGtMhE.js} +3 -3
  35. package/dist/{node-Cs3K2AKs.js.map → node-D-xGtMhE.js.map} +1 -1
  36. package/dist/{node-SvjAOtkw.js → node-DQLcKPbG.js} +2 -2
  37. package/dist/{node-SvjAOtkw.js.map → node-DQLcKPbG.js.map} +1 -1
  38. package/dist/{read_file.node-CveQp78z.js → read_file.node-DTbjOJwN.js} +2 -2
  39. package/dist/{read_file.node-CveQp78z.js.map → read_file.node-DTbjOJwN.js.map} +1 -1
  40. package/dist/{stdio-CRvROLK4.js → stdio-DuUbi3RX.js} +3 -3
  41. package/dist/{stdio-CRvROLK4.js.map → stdio-DuUbi3RX.js.map} +1 -1
  42. package/dist/storybook.js +1 -1
  43. package/dist/{undo_edit.node-C3I02TEE.js → undo_edit.node-qujh3sgI.js} +2 -2
  44. package/dist/{undo_edit.node-C3I02TEE.js.map → undo_edit.node-qujh3sgI.js.map} +1 -1
  45. package/package.json +1 -1
  46. package/dist/console-DZmALLuA.js.map +0 -1
  47. package/dist/node-CBRPqFin.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { p as f } from "./index-nQBDDlvh.js";
3
- import { aC as m, g, m as c, aN as h, aO as d, aP as b, aQ as E, c as S, O as _ } from "./console-DZmALLuA.js";
4
- import { r as v } from "./executable-C8qYZU1W.js";
2
+ import { p as f } from "./index-BY5vhogw.js";
3
+ import { aC as m, g, m as c, aN as h, aO as d, aP as b, aQ as E, c as S, O as _ } from "./console-CDi5rFHv.js";
4
+ import { r as v } from "./executable-CxioKGk7.js";
5
5
  const O = ({ args: a }, { dirs: s }) => {
6
6
  for (const e of s)
7
7
  m(e);
@@ -82,4 +82,4 @@ export {
82
82
  O as nodeGrepTool,
83
83
  P as ripgrepFiles
84
84
  };
85
- //# sourceMappingURL=node-CUCcBUhU.js.map
85
+ //# sourceMappingURL=node-CrPwEb6e.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-CUCcBUhU.js","sources":["../../core/src/tools/builtin/grep/node.ts"],"sourcesContent":["import { catchError, combineLatest, map, Observable } from '@sourcegraph/observable'\nimport pm from 'picomatch'\nimport type { ToolRun } from '../../tool-service'\nimport { checkArgSafety, checkDirURIIsFile, spawnAndObserveChildProcess } from '../node-helpers'\nimport type { GrepToolArgs } from './common'\nimport {\n\tGREP_MAX_COLUMN_LENGTH,\n\tGREP_MAX_RESULTS_PER_FILE,\n\ttype GrepToolDef,\n\ttype grepToolReg,\n} from './common'\nimport { ripgrepExecutable } from './executable'\n\nexport const nodeGrepTool: NonNullable<(typeof grepToolReg)['fn']> = ({ args }, { dirs }) => {\n\tfor (const dir of dirs) {\n\t\tcheckDirURIIsFile(dir)\n\t}\n\treturn combineLatest(...dirs.map((dir) => ripgrepFiles(dir.fsPath, args))).pipe(\n\t\tmap<ToolRun<GrepToolDef>[], ToolRun<GrepToolDef>>((results) => {\n\t\t\tconst progress: string[] = []\n\t\t\tfor (const result of results) {\n\t\t\t\tif (result.status === 'in-progress') {\n\t\t\t\t\tprogress.push(...(result?.progress ?? []))\n\t\t\t\t} else if (result.status === 'done') {\n\t\t\t\t\tprogress.push(...result.result)\n\t\t\t\t} else if (result.status === 'cancelled') {\n\t\t\t\t\tprogress.push(...(result.progress ?? []))\n\t\t\t\t} else if (result.status === 'error') {\n\t\t\t\t\tprogress.push(...(result.progress ?? []))\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst errors = results.filter((result) => result.status === 'error')\n\t\t\tif (errors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: 'error',\n\t\t\t\t\tprogress,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tmessage: errors\n\t\t\t\t\t\t\t.map<string>((error) => error?.error?.message ?? '')\n\t\t\t\t\t\t\t.join('\\n'),\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst status = results.every((result) => result.status === 'done')\n\t\t\t\t? 'done'\n\t\t\t\t: results.some((result) => result.status === 'cancelled')\n\t\t\t\t\t? 'cancelled'\n\t\t\t\t\t: 'in-progress'\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tprogress,\n\t\t\t\tresult: progress,\n\t\t\t}\n\t\t}),\n\t)\n}\n\nexport function ripgrepFiles(dir: string, args: GrepToolArgs): Observable<ToolRun<GrepToolDef>> {\n\tconst ripgrepArgs: string[] = [\n\t\t'--with-filename',\n\t\t'--line-number',\n\t\t'--no-heading',\n\t\t'--no-require-git',\n\t\t'--max-columns',\n\t\tGREP_MAX_COLUMN_LENGTH.toString(),\n\t\t'--trim',\n\t\t'--max-count',\n\t\tGREP_MAX_RESULTS_PER_FILE.toString(),\n\t]\n\tif (!args.caseSensitive) {\n\t\tripgrepArgs.push('-i')\n\t}\n\tripgrepArgs.push('--regexp', args.pattern)\n\tif (args.path) {\n\t\tcheckArgSafety(args.path)\n\t\tripgrepArgs.push(args.path)\n\t}\n\n\t// Interpret the `glob` property in TypeScript instead of using the ripgrep\n\t// option `--glob` because using `--glob` disables the built-in gitignore\n\t// feature. We do the same thing in the Glob tool.\n\tconst matchesGlobPattern = args?.glob\n\t\t? pm(args.glob, { nocase: !args.caseSensitive, dot: true })\n\t\t: undefined\n\n\treturn spawnAndObserveChildProcess(ripgrepExecutable(), ripgrepArgs, {\n\t\tcwd: dir,\n\t\tstdio: ['ignore', 'pipe', 'pipe'],\n\t}).pipe(\n\t\tmap(({ stdout, stderr: _stderr, exitCode, exited }): ToolRun<GrepToolDef> => {\n\t\t\tconst matches = stdout\n\t\t\t\t.trim()\n\t\t\t\t.split('\\n')\n\t\t\t\t.filter((line) => {\n\t\t\t\t\tif (line.length === 0) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tif (matchesGlobPattern) {\n\t\t\t\t\t\tconst [filename] = line.split(':', 1)\n\t\t\t\t\t\tif (filename && !matchesGlobPattern(filename)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn true\n\t\t\t\t})\n\n\t\t\tif (!exited) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: 'in-progress',\n\t\t\t\t\tprogress: matches,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ripgrep exit code 1 means \"no matches found\"\n\t\t\tif (exited && exitCode && exitCode >= 2) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: 'error',\n\t\t\t\t\tprogress: matches,\n\t\t\t\t\terror: { message: `ripgrep exited with code ${exitCode}` },\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tstatus: 'done',\n\t\t\t\tprogress: matches,\n\t\t\t\tresult: matches,\n\t\t\t}\n\t\t}),\n\t\tcatchError((error) =>\n\t\t\tObservable.of({\n\t\t\t\tstatus: 'error',\n\t\t\t\tprogress: [],\n\t\t\t\terror: { message: String(error) },\n\t\t\t}),\n\t\t),\n\t)\n}\n"],"names":["nodeGrepTool","args","dirs","dir","checkDirURIIsFile","combineLatest","ripgrepFiles","map","results","progress","result","errors","error","ripgrepArgs","GREP_MAX_COLUMN_LENGTH","GREP_MAX_RESULTS_PER_FILE","checkArgSafety","matchesGlobPattern","pm","spawnAndObserveChildProcess","ripgrepExecutable","stdout","_stderr","exitCode","exited","matches","line","filename","catchError","Observable"],"mappings":";;;;AAaO,MAAMA,IAAwD,CAAC,EAAE,MAAAC,KAAQ,EAAE,MAAAC,QAAW;AAC5F,aAAWC,KAAOD;AACjB,IAAAE,EAAkBD,CAAG;AAEtB,SAAOE,EAAc,GAAGH,EAAK,IAAI,CAACC,MAAQG,EAAaH,EAAI,QAAQF,CAAI,CAAC,CAAC,EAAE;AAAA,IAC1EM,EAAkD,CAACC,MAAY;AAC9D,YAAMC,IAAqB,CAAC;AAC5B,iBAAWC,KAAUF;AAChB,QAAAE,EAAO,WAAW,gBACrBD,EAAS,KAAK,GAAIC,GAAQ,YAAY,CAAA,CAAG,IAC/BA,EAAO,WAAW,SACnBD,EAAA,KAAK,GAAGC,EAAO,MAAM,IACpBA,EAAO,WAAW,cAC5BD,EAAS,KAAK,GAAIC,EAAO,YAAY,CAAA,CAAG,IAC9BA,EAAO,WAAW,WAC5BD,EAAS,KAAK,GAAIC,EAAO,YAAY,CAAA,CAAG;AAG1C,YAAMC,IAASH,EAAQ,OAAO,CAACE,MAAWA,EAAO,WAAW,OAAO;AAC/D,aAAAC,EAAO,SAAS,IACZ;AAAA,QACN,QAAQ;AAAA,QACR,UAAAF;AAAA,QACA,OAAO;AAAA,UACN,SAASE,EACP,IAAY,CAACC,MAAUA,GAAO,OAAO,WAAW,EAAE,EAClD,KAAK;AAAA,CAAI;AAAA,QAAA;AAAA,MAEb,IAOM;AAAA,QACN,QANcJ,EAAQ,MAAM,CAACE,MAAWA,EAAO,WAAW,MAAM,IAC9D,SACAF,EAAQ,KAAK,CAACE,MAAWA,EAAO,WAAW,WAAW,IACrD,cACA;AAAA,QAGH,UAAAD;AAAA,QACA,QAAQA;AAAA,MACT;AAAA,IACA,CAAA;AAAA,EACF;AACD;AAEgB,SAAAH,EAAa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gBD,CACA;AAAA,IACDG;AAAA,MAAW,CAAChB,MACXiB,EAAW,GAAG;AAAA,QACb,QAAQ;AAAA,QACR,UAAU,CAAC;AAAA,QACX,OAAO,EAAE,SAAS,OAAOjB,CAAK,EAAE;AAAA,MAChC,CAAA;AAAA,IAAA;AAAA,EAEH;AACD;"}
1
+ {"version":3,"file":"node-CrPwEb6e.js","sources":["../../core/src/tools/builtin/grep/node.ts"],"sourcesContent":["import { catchError, combineLatest, map, Observable } from '@sourcegraph/observable'\nimport pm from 'picomatch'\nimport type { ToolRun } from '../../tool-service'\nimport { checkArgSafety, checkDirURIIsFile, spawnAndObserveChildProcess } from '../node-helpers'\nimport type { GrepToolArgs } from './common'\nimport {\n\tGREP_MAX_COLUMN_LENGTH,\n\tGREP_MAX_RESULTS_PER_FILE,\n\ttype GrepToolDef,\n\ttype grepToolReg,\n} from './common'\nimport { ripgrepExecutable } from './executable'\n\nexport const nodeGrepTool: NonNullable<(typeof grepToolReg)['fn']> = ({ args }, { dirs }) => {\n\tfor (const dir of dirs) {\n\t\tcheckDirURIIsFile(dir)\n\t}\n\treturn combineLatest(...dirs.map((dir) => ripgrepFiles(dir.fsPath, args))).pipe(\n\t\tmap<ToolRun<GrepToolDef>[], ToolRun<GrepToolDef>>((results) => {\n\t\t\tconst progress: string[] = []\n\t\t\tfor (const result of results) {\n\t\t\t\tif (result.status === 'in-progress') {\n\t\t\t\t\tprogress.push(...(result?.progress ?? []))\n\t\t\t\t} else if (result.status === 'done') {\n\t\t\t\t\tprogress.push(...result.result)\n\t\t\t\t} else if (result.status === 'cancelled') {\n\t\t\t\t\tprogress.push(...(result.progress ?? []))\n\t\t\t\t} else if (result.status === 'error') {\n\t\t\t\t\tprogress.push(...(result.progress ?? []))\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst errors = results.filter((result) => result.status === 'error')\n\t\t\tif (errors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: 'error',\n\t\t\t\t\tprogress,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tmessage: errors\n\t\t\t\t\t\t\t.map<string>((error) => error?.error?.message ?? '')\n\t\t\t\t\t\t\t.join('\\n'),\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst status = results.every((result) => result.status === 'done')\n\t\t\t\t? 'done'\n\t\t\t\t: results.some((result) => result.status === 'cancelled')\n\t\t\t\t\t? 'cancelled'\n\t\t\t\t\t: 'in-progress'\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tprogress,\n\t\t\t\tresult: progress,\n\t\t\t}\n\t\t}),\n\t)\n}\n\nexport function ripgrepFiles(dir: string, args: GrepToolArgs): Observable<ToolRun<GrepToolDef>> {\n\tconst ripgrepArgs: string[] = [\n\t\t'--with-filename',\n\t\t'--line-number',\n\t\t'--no-heading',\n\t\t'--no-require-git',\n\t\t'--max-columns',\n\t\tGREP_MAX_COLUMN_LENGTH.toString(),\n\t\t'--trim',\n\t\t'--max-count',\n\t\tGREP_MAX_RESULTS_PER_FILE.toString(),\n\t]\n\tif (!args.caseSensitive) {\n\t\tripgrepArgs.push('-i')\n\t}\n\tripgrepArgs.push('--regexp', args.pattern)\n\tif (args.path) {\n\t\tcheckArgSafety(args.path)\n\t\tripgrepArgs.push(args.path)\n\t}\n\n\t// Interpret the `glob` property in TypeScript instead of using the ripgrep\n\t// option `--glob` because using `--glob` disables the built-in gitignore\n\t// feature. We do the same thing in the Glob tool.\n\tconst matchesGlobPattern = args?.glob\n\t\t? pm(args.glob, { nocase: !args.caseSensitive, dot: true })\n\t\t: undefined\n\n\treturn spawnAndObserveChildProcess(ripgrepExecutable(), ripgrepArgs, {\n\t\tcwd: dir,\n\t\tstdio: ['ignore', 'pipe', 'pipe'],\n\t}).pipe(\n\t\tmap(({ stdout, stderr: _stderr, exitCode, exited }): ToolRun<GrepToolDef> => {\n\t\t\tconst matches = stdout\n\t\t\t\t.trim()\n\t\t\t\t.split('\\n')\n\t\t\t\t.filter((line) => {\n\t\t\t\t\tif (line.length === 0) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tif (matchesGlobPattern) {\n\t\t\t\t\t\tconst [filename] = line.split(':', 1)\n\t\t\t\t\t\tif (filename && !matchesGlobPattern(filename)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn true\n\t\t\t\t})\n\n\t\t\tif (!exited) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: 'in-progress',\n\t\t\t\t\tprogress: matches,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ripgrep exit code 1 means \"no matches found\"\n\t\t\tif (exited && exitCode && exitCode >= 2) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: 'error',\n\t\t\t\t\tprogress: matches,\n\t\t\t\t\terror: { message: `ripgrep exited with code ${exitCode}` },\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tstatus: 'done',\n\t\t\t\tprogress: matches,\n\t\t\t\tresult: matches,\n\t\t\t}\n\t\t}),\n\t\tcatchError((error) =>\n\t\t\tObservable.of({\n\t\t\t\tstatus: 'error',\n\t\t\t\tprogress: [],\n\t\t\t\terror: { message: String(error) },\n\t\t\t}),\n\t\t),\n\t)\n}\n"],"names":["nodeGrepTool","args","dirs","dir","checkDirURIIsFile","combineLatest","ripgrepFiles","map","results","progress","result","errors","error","ripgrepArgs","GREP_MAX_COLUMN_LENGTH","GREP_MAX_RESULTS_PER_FILE","checkArgSafety","matchesGlobPattern","pm","spawnAndObserveChildProcess","ripgrepExecutable","stdout","_stderr","exitCode","exited","matches","line","filename","catchError","Observable"],"mappings":";;;;AAaO,MAAMA,IAAwD,CAAC,EAAE,MAAAC,KAAQ,EAAE,MAAAC,QAAW;AAC5F,aAAWC,KAAOD;AACjB,IAAAE,EAAkBD,CAAG;AAEtB,SAAOE,EAAc,GAAGH,EAAK,IAAI,CAACC,MAAQG,EAAaH,EAAI,QAAQF,CAAI,CAA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BhB,GAAM,OAC9BiB,EAAGjB,EAAK,MAAM,EAAE,QAAQ,CAACA,EAAK,eAAe,KAAK,GAAA,CAAM,IACxD;AAEI,SAAAkB,EAA4BC,EAAkB,GAAGP,GAAa;AAAA,IACpE,KAAKV;AAAA,IACL,OAAO,CAAC,UAAU,QAAQ,MAAM;AAAA,EAChC,CAAA,EAAE;AAAA,IACFI,EAAI,CAAC,EAAE,QAAAc,GAAQ,QAAQC,GAAS,UAAAC,GAAU,QAAAC,QAAmC;AACtE,YAAAC,IAAUJ,EACd,KAAK,EACL,MAAM;AAAA,CAAI,EACV,OAAO,CAACK,MAAS;AACb,YAAAA,EAAK,WAAW;AACZ,iBAAA;AAER,YAAIT,GAAoB;AACvB,gBAAM,CAACU,CAAQ,IAAID,EAAK,MAAM,KAAK,CAAC;AACpC,cAAIC,KAAY,CAACV,EAAmBU,CAAQ;AACpC,mBAAA;AAAA,QACR;AAEM,eAAA;AAAA,MAAA,CACP;AAEF,aAAKH,IAQDA,KAAUD,KAAYA,KAAY,IAC9B;AAAA,QACN,QAAQ;AAAA,QACR,UAAUE;AAAA,QACV,OAAO,EAAE,SAAS,4BAA4BF,CAAQ,GAAG;AAAA,MAC1D,IAGM;AAAA,QACN,QAAQ;AAAA,QACR,UAAUE;AAAA,QACV,QAAQA;AAAA,MACT,IAnBQ;AAAA,QACN,QAAQ;AAAA,QACR,UAAUA;AAAA,MACX;AAAA,IAgBD,CACA;AAAA,IACDG;AAAA,MAAW,CAAChB,MACXiB,EAAW,GAAG;AAAA,QACb,QAAQ;AAAA,QACR,UAAU,CAAC;AAAA,QACX,OAAO,EAAE,SAAS,OAAOjB,CAAK,EAAE;AAAA,MAChC,CAAA;AAAA,IAAA;AAAA,EAEH;AACD;"}
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { q as x, o as A, n as g, y as B, r as j, l as h, x as I, u as J, w as V, A as k, aY as z, aZ as W, a_ as Z, a$ as C, b0 as L, b1 as _, b2 as D, ax as M, f as q, b3 as G, b4 as H, b5 as F, b6 as K, O as Q, b7 as N, _ as X, av as ee, C as te } from "./console-DZmALLuA.js";
3
- import { r as se } from "./main-WXbdYG4Z.js";
2
+ import { q as x, o as A, n as g, y as B, r as j, l as h, x as I, u as J, w as V, A as k, aY as z, aZ as W, a_ as Z, a$ as C, b0 as L, b1 as _, b2 as D, ax as M, f as q, b3 as G, b4 as H, b5 as F, b6 as K, O as Q, b7 as N, _ as X, av as ee, C as te } from "./console-CDi5rFHv.js";
3
+ import { r as se } from "./main-DIn8dJ9L.js";
4
4
  const v = A({
5
5
  context: V(["continue", "none"]).optional().default("continue"),
6
6
  tools: J([h("all"), x(g())]).optional(),
@@ -365,4 +365,4 @@ async function he(r, e, t, s) {
365
365
  export {
366
366
  Te as runRoutine
367
367
  };
368
- //# sourceMappingURL=node-Cs3K2AKs.js.map
368
+ //# sourceMappingURL=node-D-xGtMhE.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-Cs3K2AKs.js","sources":["../../core/src/tools/builtin/run_routine/types.ts","../../core/src/tools/builtin/run_routine/serialization.ts","../../core/src/tools/builtin/run_routine/util.ts","../../core/src/tools/builtin/run_routine/step.ts","../../core/src/tools/builtin/run_routine/node.ts"],"sourcesContent":["import { z } from 'zod'\n\n// Base Step interface\nconst BaseStep = z.object({\n\tcontext: z.enum(['continue', 'none']).optional().default('continue'),\n\ttools: z.union([z.literal('all'), z.array(z.string())]).optional(),\n\tprompt: z.string(),\n\tverify: z.record(z.any()).optional(),\n}) satisfies z.ZodType<{\n\tcontext?: 'continue' | 'none'\n\ttools?: 'all' | string[]\n\tprompt: string\n\tverify?: Record<string, any>\n}>\n\n// Agent Step\nconst AgentStep = BaseStep.extend({\n\ttype: z.literal('agent'),\n\tmodel: z.string().optional(), // Default could be set in implementation\n\tinteractive_confirmation: z.boolean().optional(),\n})\n\n// LLM Step\nconst LLMStep = BaseStep.extend({\n\ttype: z.literal('llm'),\n\tmodel: z.string().optional(),\n})\n\n// Loop Agent Step\nconst LoopAgentStep = BaseStep.extend({\n\ttype: z.literal('loop_agent'),\n\tmodel: z.string().optional(),\n\tinput_file: z.string(),\n})\n\n// Loop LLM Step\nconst LoopLLMStep = BaseStep.extend({\n\ttype: z.literal('loop_llm'),\n\tmodel: z.string().optional(),\n\tinput_file: z.string(),\n})\n\n// Tool Call Step\nconst ToolCallStep = z.object({\n\ttype: z.literal('tool_call'),\n\ttool: z.string(),\n\tparameters: z.record(z.any()).optional(),\n})\n\n// Bash Step\nconst BashStep = z.object({\n\ttype: z.literal('bash'),\n\tcommand: z.string(),\n})\n\n// Union of all step types\nconst Step = z.discriminatedUnion('type', [\n\tAgentStep,\n\tLLMStep,\n\tLoopAgentStep,\n\tLoopLLMStep,\n\tToolCallStep,\n\tBashStep,\n])\n\n// Routine Block\nconst RoutineBlock = z.object({\n\tid: z.string(),\n\tsteps: z.array(Step),\n})\n\n// Routine (array of RoutineBlocks)\nconst Routine = z.array(RoutineBlock)\n\nconst Routines = z.array(Routine)\n\nexport type RoutineSchema = z.infer<typeof Routine>\nexport type RoutinesSchema = z.infer<typeof Routines>\nexport type RoutineBlockSchema = z.infer<typeof RoutineBlock>\nexport type StepSchema = z.infer<typeof Step>\nexport type AgentStepSchema = z.infer<typeof AgentStep>\nexport type LLMStepSchema = z.infer<typeof LLMStep>\nexport type LoopAgentStepSchema = z.infer<typeof LoopAgentStep>\nexport type LoopLLMStepSchema = z.infer<typeof LoopLLMStep>\nexport type ToolCallStepSchema = z.infer<typeof ToolCallStep>\nexport type BashStepSchema = z.infer<typeof BashStep>\n\nexport { Routine, RoutineBlock, Routines, Step }\n","import { parse } from 'yaml'\nimport { z } from 'zod'\nimport type { RoutineSchema } from './types'\nimport { Routine } from './types'\n\n/**\n * Deserialize a YAML string into a Routine\n * @param yamlString The YAML string representation of a Routine\n * @returns The parsed and validated Routine\n * @throws Error if the YAML is invalid or doesn't match the Routine schema\n */\nexport function deserializeRoutineFromYAML(yamlString: string): RoutineSchema {\n\ttry {\n\t\t// Parse the YAML string to a JavaScript object\n\t\tconst parsedYaml = parse(yamlString)\n\n\t\t// Validate and transform the parsed YAML against the Routine schema\n\t\tconst validatedRoutine = Routine.parse(parsedYaml)\n\n\t\treturn validatedRoutine\n\t} catch (error) {\n\t\tif (error instanceof z.ZodError) {\n\t\t\t// Enhance Zod validation errors with better context\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid routine format: ${error.errors\n\t\t\t\t\t.map((err) => `${err.path.join('.')} - ${err.message}`)\n\t\t\t\t\t.join(', ')}`,\n\t\t\t)\n\t\t} else if (error instanceof Error) {\n\t\t\t// Handle YAML parsing errors\n\t\t\tthrow new Error(`Failed to parse YAML: ${error.message}`)\n\t\t} else {\n\t\t\tthrow new Error(`Unknown error during routine deserialization: ${String(error)}`)\n\t\t}\n\t}\n}\n","import type { SubscriptionObserver } from '@sourcegraph/observable'\nimport type { ToolRun } from '../../tool-service'\nimport type { RunRoutineProgressMessage, RunRoutineToolDef } from './common'\n\n/**\n * Class that maintains state for status messages in run_routine implementation.\n * Keeps track of all status messages and reports them through the observer.\n */\nexport class ProgressReporter {\n\tprivate progressMessages: RunRoutineProgressMessage[] = []\n\n\tconstructor(\n\t\tprivate observer: SubscriptionObserver<ToolRun<RunRoutineToolDef>>,\n\t\tprivate signal: AbortSignal,\n\t) {}\n\n\t/**\n\t * Adds the latest message to the list of all status updates and then invokes the observer\n\t * with the updated 'in-progress' status.\n\t */\n\tupdate(update: ToolRun<RunRoutineToolDef>): void {\n\t\tthis.signal.throwIfAborted()\n\t\tif ('progress' in update && update.progress) {\n\t\t\tif (Array.isArray(update.progress)) {\n\t\t\t\tthis.progressMessages.push(...update.progress)\n\t\t\t} else {\n\t\t\t\tthis.progressMessages.push(update.progress)\n\t\t\t}\n\t\t\tthis.observer.next({\n\t\t\t\t...update,\n\t\t\t\tprogress: this.progressMessages,\n\t\t\t})\n\t\t} else {\n\t\t\tthis.observer.next(update)\n\t\t}\n\t}\n\n\terror(error: unknown): void {\n\t\tthis.observer.error(error)\n\t}\n\n\tcomplete(): void {\n\t\tthis.observer.complete()\n\t}\n}\n\n/**\n * Apply variable substitutions to a prompt string\n */\nexport function substitutePromptVars(prompt: string, vars: { userInput?: string }): string {\n\tlet result = prompt\n\n\t// Replace {{userInput}} with the actual user input if provided\n\tif (vars.userInput) {\n\t\tresult = result.replace(/\\{\\{\\s*userInput\\s*\\}\\}/g, vars.userInput)\n\t\tresult = result.replace(/\\{\\{\\s*user_input\\s*\\}\\}/g, vars.userInput)\n\t}\n\n\treturn result\n}\n","import { firstValueFrom } from '@sourcegraph/observable'\nimport {\n\tACTIVE_MODEL,\n\tAnthropicConverters,\n\tfromAnthropicResultToThreadDelta,\n\trunAnthropicSync,\n} from '../../../inference/backends/anthropic'\nimport { buildSystemPrompt, DefaultSystemPromptService } from '../../../threads/system-prompt'\nimport type { ToolUseBlock } from '../../../threads/thread'\nimport {\n\ttoolResultBlocks,\n\ttype Thread,\n\ttype ThreadAssistantMessage,\n\ttype ToolRunUserInput,\n} from '../../../threads/thread'\nimport type { ThreadDelta } from '../../../threads/thread-delta'\nimport { applyThreadDelta } from '../../../threads/thread-delta'\nimport type {\n\tToolDefinition,\n\tToolRun,\n\tToolRunEnvironment,\n\tToolService,\n} from '../../../tools/tool-service'\nimport { createToolService, isToolRunTerminalState } from '../../../tools/tool-service'\nimport { registerBuiltinToolsToToolService } from '../../tools'\nimport type { AgentStepSchema, LLMStepSchema, StepSchema } from './types'\nimport { substitutePromptVars, type ProgressReporter } from './util'\n\n/**\n * Run a step with the given conversation\n */\nexport function runStep(\n\tstep: StepSchema,\n\tconversation: Thread,\n\tenv: ToolRunEnvironment,\n\tprogressReporter: ProgressReporter,\n\tvars: { userInput?: string },\n\tsignal: AbortSignal = new AbortController().signal,\n): Promise<Thread> {\n\tswitch (step.type) {\n\t\tcase 'agent':\n\t\t\treturn runStepAgent(step, conversation, env, progressReporter, vars, signal)\n\t\t\tbreak\n\t\tcase 'llm':\n\t\t\treturn runStepLLM(step, conversation, progressReporter, vars, signal)\n\t\t\tbreak\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown step type: ${(step as any).type}`)\n\t}\n}\n\n/**\n * Run an agent step that implements a full agentic loop\n * Follows the pattern: inference -> tool calls -> tool results -> inference\n * until there are no more tool calls or the process is complete\n */\nasync function runStepAgent(\n\tstep: AgentStepSchema,\n\torigConversation: Thread,\n\tenv: ToolRunEnvironment,\n\tprogressReporter: ProgressReporter,\n\tvars: { userInput?: string },\n\tsignal: AbortSignal,\n): Promise<Thread> {\n\tconst toolService = createToolService()\n\tawait registerBuiltinToolsToToolService(toolService)\n\n\t// Process prompt template with variables if provided\n\tconst promptText = substitutePromptVars(step.prompt, vars)\n\n\t// Clone convo\n\tlet conversation = origConversation\n\tconst recordThreadDelta = (delta: ThreadDelta) => {\n\t\tconversation = applyThreadDelta(conversation, delta)\n\t}\n\n\trecordThreadDelta({\n\t\ttype: 'user:message',\n\t\tmessage: {\n\t\t\tcontent: [{ type: 'text', text: promptText }],\n\t\t\tmeta: {\n\t\t\t\tsentAt: Date.now(),\n\t\t\t},\n\t\t},\n\t})\n\n\t// Update progress with user message added\n\tprogressReporter.update({\n\t\tstatus: 'in-progress',\n\t\tprogress: { type: 'message', speaker: 'user', message: promptText },\n\t})\n\n\t// Get enabled tools from toolService (all tools for now)\n\tconst enabledToolSpecs = (await firstValueFrom(toolService.tools, signal)).map((t) => t.spec)\n\n\t// Set up parameters for the initial API call\n\tconst model = ACTIVE_MODEL\n\n\t// The agent loop will continue until there are no more tool calls needed\n\tlet loopCount = 0\n\tconst maxLoops = 100 // Prevent infinite loops\n\n\twhile (loopCount < maxLoops) {\n\t\tsignal.throwIfAborted()\n\t\tloopCount++\n\n\t\t// Get system prompt blocks from the main system prompt builder\n\t\tconst systemPromptService = new DefaultSystemPromptService()\n\t\t// Get the main system prompt blocks\n\t\tconst systemPromptBlocks = await buildSystemPrompt(systemPromptService, {\n\t\t\tenabledTodos: false,\n\t\t\tthreadEnv: env.threadEnvironment,\n\t\t})\n\n\t\t// Add the subagent-specific instruction as the final block\n\t\tsystemPromptBlocks.push({\n\t\t\ttype: 'text' as const,\n\t\t\ttext: 'You are a helpful AI assistant running as a subagent within a larger system. Your task is to handle this specific step in a routine. You can use tools to complete your task. When you are completely done, do not ask to use more tools.',\n\t\t})\n\n\t\t// Use the combined system prompt\n\t\tconst systemPrompt = systemPromptBlocks\n\n\t\tsignal.throwIfAborted()\n\n\t\t// Use runAnthropicSync to get a response\n\t\tlet result\n\t\ttry {\n\t\t\tconst anthropicMessages = AnthropicConverters.fromNativeThread(conversation)\n\t\t\tresult = await runAnthropicSync(\n\t\t\t\tanthropicMessages,\n\t\t\t\tenabledToolSpecs,\n\t\t\t\tsystemPrompt,\n\t\t\t\tmodel,\n\t\t\t\tsignal,\n\t\t\t)\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Anthropic API error: ${error}`)\n\t\t}\n\n\t\tif (!result.message || !('content' in result.message)) {\n\t\t\tthrow new Error('Unexpected response format from Anthropic')\n\t\t}\n\t\tif (result.message.content.length === 0) {\n\t\t\tbreak\n\t\t}\n\n\t\tconst assistantResponseDelta = fromAnthropicResultToThreadDelta(result.message)\n\t\trecordThreadDelta(assistantResponseDelta)\n\n\t\t// Extract text for progress reporting\n\t\tconst assistantText = result.message.content\n\t\t\t.filter((item) => item.type === 'text')\n\t\t\t.map((item) => ('text' in item ? item.text : ''))\n\t\t\t.join(' ')\n\t\t\t.trim()\n\t\tif (assistantText) {\n\t\t\t// Show assistant message\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: { type: 'message', speaker: 'assistant', message: assistantText },\n\t\t\t})\n\t\t}\n\n\t\tif (assistantResponseDelta.type !== 'assistant:message') {\n\t\t\t// No tool calls\n\t\t\tbreak\n\t\t}\n\n\t\tconst toolCalls = findToolUsesNeedingInvocation(\n\t\t\tconversation,\n\t\t\tassistantResponseDelta.message,\n\t\t)\n\t\tfor (const toolCall of toolCalls) {\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: {\n\t\t\t\t\tid: toolCall.id,\n\t\t\t\t\ttype: 'toolCall',\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\targs: JSON.stringify(toolCall.input),\n\t\t\t\t},\n\t\t\t})\n\n\t\t\tlet toolResult\n\t\t\ttry {\n\t\t\t\ttoolResult = await invokeToolAndWaitForResult(\n\t\t\t\t\ttoolService,\n\t\t\t\t\ttoolCall.name,\n\t\t\t\t\ttoolCall.input,\n\t\t\t\t\tenv,\n\t\t\t\t\tsignal,\n\t\t\t\t)\n\t\t\t\tsignal.throwIfAborted()\n\t\t\t\tif (toolResult.status !== 'done') {\n\t\t\t\t\tthrow new Error(JSON.stringify(toolResult))\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\trecordThreadDelta({\n\t\t\t\t\ttype: 'tool:data',\n\t\t\t\t\ttoolUse: toolCall.id,\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tstatus: 'error',\n\t\t\t\t\t\terror: { message: `Tool call error: ${error}` },\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tprogressReporter.update({\n\t\t\t\t\tstatus: 'in-progress',\n\t\t\t\t\tprogress: {\n\t\t\t\t\t\tid: toolCall.id,\n\t\t\t\t\t\ttype: 'toolResult',\n\t\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\t\tresult: `Tool call error: ${error}`,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\trecordThreadDelta({\n\t\t\t\ttype: 'tool:data',\n\t\t\t\ttoolUse: toolCall.id,\n\t\t\t\tdata: toolResult,\n\t\t\t})\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: {\n\t\t\t\t\tid: toolCall.id,\n\t\t\t\t\ttype: 'toolResult',\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\tresult:\n\t\t\t\t\t\ttypeof toolResult.result === 'string'\n\t\t\t\t\t\t\t? toolResult.result\n\t\t\t\t\t\t\t: JSON.stringify(toolResult.result),\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t}\n\treturn conversation\n}\n\n/**\n * Mock implementation of tool execution for the subagent\n * In a real implementation, this would connect to the actual tool execution system\n */\n// Removed mock implementation in favor of actual toolService\n\n/**\n * Run an LLM step\n */\nasync function runStepLLM(\n\tstep: LLMStepSchema,\n\torigConversation: Thread,\n\tprogressReporter: ProgressReporter,\n\tvars: { userInput?: string },\n\tsignal: AbortSignal,\n): Promise<Thread> {\n\t// Process prompt template with variables if provided\n\tconst promptText = substitutePromptVars(step.prompt, vars)\n\n\t// Create a copy of the conversation to avoid mutating the original\n\tlet conversation = origConversation\n\tconst recordThreadDelta = (delta: ThreadDelta) => {\n\t\tconversation = applyThreadDelta(conversation, delta)\n\t}\n\n\trecordThreadDelta({\n\t\ttype: 'user:message',\n\t\tmessage: {\n\t\t\tcontent: [{ type: 'text', text: promptText }],\n\t\t\tmeta: {\n\t\t\t\tsentAt: Date.now(),\n\t\t\t},\n\t\t},\n\t})\n\n\t// Update progress with user message added\n\tprogressReporter.update({\n\t\tstatus: 'in-progress',\n\t\tprogress: { type: 'message', speaker: 'user', message: promptText },\n\t})\n\n\t// Use runAnthropicSync to get a response\n\tconst anthropicMessages = AnthropicConverters.fromNativeThread(conversation)\n\tconst model = step.model || ACTIVE_MODEL\n\tconst result = await runAnthropicSync(\n\t\tanthropicMessages,\n\t\t[], // No tools for LLM-only step\n\t\t[], // No system prompt\n\t\tmodel,\n\t\tsignal,\n\t)\n\n\tif (!result.message) {\n\t\tthrow new Error('Failed to get response from Anthropic')\n\t}\n\n\tconst assistantResponseDelta = fromAnthropicResultToThreadDelta(result.message)\n\trecordThreadDelta(assistantResponseDelta)\n\n\t// Display message\n\tconst assistantText = result.message.content\n\t\t.filter((item) => item.type === 'text')\n\t\t.map((item) => (item.type === 'text' ? item.text : ''))\n\t\t.join(' ')\n\t\t.trim()\n\tprogressReporter.update({\n\t\tstatus: 'in-progress',\n\t\tprogress: { type: 'message', speaker: 'assistant', message: assistantText },\n\t})\n\treturn conversation\n}\n\nfunction findToolUsesNeedingInvocation(\n\tthread: Thread,\n\tmessage: ThreadAssistantMessage,\n): ToolUseBlock[] {\n\tconst toolResults = toolResultBlocks(thread)\n\treturn message.content\n\t\t.filter((block): block is ToolUseBlock => block.type === 'tool_use')\n\t\t.filter((block) => !block.inputPartialJSON)\n\t\t.filter(\n\t\t\t(block) =>\n\t\t\t\t// Only include tools that haven't been invoked yet.\n\t\t\t\t!toolResults.has(block.id),\n\t\t)\n}\n\n/**\n * Helper function that invokes a tool and returns a Promise with the final result\n */\nexport async function invokeToolAndWaitForResult<T extends ToolDefinition>(\n\ttoolService: ToolService,\n\ttoolName: string,\n\tinput: unknown,\n\tenv: ToolRunEnvironment,\n\tsignal: AbortSignal = new AbortController().signal,\n\tuserInput?: ToolRunUserInput,\n): Promise<ToolRun<T>> {\n\treturn new Promise((resolve, reject) => {\n\t\tlet settled = false\n\t\tconst sub = toolService\n\t\t\t.invokeTool(toolName, { args: input as any, userInput }, env)\n\t\t\t.subscribe({\n\t\t\t\tnext: (run: ToolRun) => {\n\t\t\t\t\tif (isToolRunTerminalState(run)) {\n\t\t\t\t\t\tsub.unsubscribe()\n\t\t\t\t\t\tif (!settled) {\n\t\t\t\t\t\t\tsettled = true\n\t\t\t\t\t\t\tresolve(run)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\terror: (error) => {\n\t\t\t\t\tif (!settled) {\n\t\t\t\t\t\tsettled = true\n\t\t\t\t\t\treject(error)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tcomplete: () => {},\n\t\t\t})\n\n\t\t// Handle abort signal\n\t\tsignal.addEventListener('abort', () => {\n\t\t\tsub.unsubscribe()\n\t\t\tif (!settled) {\n\t\t\t\tsettled = true\n\t\t\t\treject(new Error('Tool execution was aborted'))\n\t\t\t}\n\t\t})\n\t})\n}\n","import { Observable } from '@sourcegraph/observable'\nimport { isAbortError } from '../../../common/abort'\nimport logger from '../../../common/logger'\nimport type { Thread } from '../../../threads/thread'\nimport { newThreadID } from '../../../threads/thread'\nimport type { ToolRunEnvironment } from '../../tool-service'\nimport { createToolService } from '../../tool-service'\nimport type { ReadFileToolDef } from '../filesystem/read_file.common'\nimport { readFileToolReg } from '../filesystem/read_file.common'\nimport type { runRoutineToolReg } from './common'\nimport { deserializeRoutineFromYAML } from './serialization'\nimport { invokeToolAndWaitForResult, runStep } from './step'\nimport { ProgressReporter } from './util'\n\nexport const runRoutine: NonNullable<(typeof runRoutineToolReg)['fn']> = ({ args }, env) => {\n\treturn new Observable((observer) => {\n\t\tconst abortController = new AbortController()\n\t\tconst progressReporter = new ProgressReporter(observer, abortController.signal)\n\n\t\trunRoutineImpl(args, env, progressReporter, abortController.signal).catch((error) => {\n\t\t\t// Don't report AbortError as an error - it's expected when cancelling\n\t\t\tif (!isAbortError(error)) {\n\t\t\t\tprogressReporter.error(error)\n\t\t\t} else {\n\t\t\t\tprogressReporter.update({\n\t\t\t\t\tstatus: 'cancelled' as const,\n\t\t\t\t\tprogress: { type: 'meta', message: 'Operation cancelled' },\n\t\t\t\t})\n\t\t\t\tprogressReporter.complete()\n\t\t\t}\n\t\t})\n\n\t\treturn () => {\n\t\t\tabortController.abort()\n\t\t}\n\t})\n}\n\nasync function runRoutineImpl(\n\targs: { id: string; file?: string; userInput?: string },\n\tenv: ToolRunEnvironment,\n\tprogressReporter: ProgressReporter,\n\tsignal: AbortSignal,\n) {\n\ttry {\n\t\tconst { id, file } = args\n\t\tconst routineFile = file || 'routines.amp.yaml'\n\n\t\t// Report initial progress\n\t\tprogressReporter.update({\n\t\t\tstatus: 'in-progress',\n\t\t\tprogress: { type: 'meta', message: `Loading routine: ${id} from ${routineFile}` },\n\t\t})\n\n\t\t// Create a tool service and register the read_file tool\n\t\tconst toolService = createToolService()\n\t\ttoolService.registerTool(readFileToolReg)\n\n\t\t// Read the routine file using the tool service\n\t\tconst readFileResult = await invokeToolAndWaitForResult<ReadFileToolDef>(\n\t\t\ttoolService,\n\t\t\t'read_file',\n\t\t\t{ path: routineFile },\n\t\t\tenv,\n\t\t\tsignal,\n\t\t)\n\n\t\t// Process the file content by removing line numbers that read_file adds\n\t\tif (readFileResult.status !== 'done') {\n\t\t\tthrow new Error(`Failed to read routine file: ${routineFile}`)\n\t\t}\n\t\t// At this point TypeScript knows readFileResult has a 'result' property\n\t\tconst fileContents =\n\t\t\ttypeof readFileResult.result === 'string'\n\t\t\t\t? readFileResult.result\n\t\t\t\t: readFileResult.result.content\n\t\tconst routineContent = String(fileContents)\n\t\t\t.split('\\n')\n\t\t\t.map((line: string) => line.replace(/^\\d+:\\s/, ''))\n\t\t\t.join('\\n')\n\n\t\tsignal.throwIfAborted()\n\n\t\t// Parse the routines\n\t\tconst routines = deserializeRoutineFromYAML(routineContent)\n\t\tsignal.throwIfAborted()\n\n\t\t// Find the requested routine\n\t\tconst routine = routines.find((routine) => routine.id === id)\n\t\tif (!routine) {\n\t\t\tthrow new Error(`Routine with id \"${id}\" not found in ${routineFile}`)\n\t\t}\n\n\t\t// Initialize a Thread for the conversation\n\t\tlet conversation: Thread = {\n\t\t\tid: newThreadID(),\n\t\t\tcreated: Date.now(),\n\t\t\tv: 0,\n\t\t\tmessages: [],\n\t\t}\n\n\t\t// Report progress before executing steps\n\t\tprogressReporter.update({\n\t\t\tstatus: 'in-progress',\n\t\t\tprogress: [\n\t\t\t\t{\n\t\t\t\t\ttype: 'meta',\n\t\t\t\t\tmessage: `Executing routine ${id}`,\n\t\t\t\t},\n\t\t\t],\n\t\t})\n\n\t\t// Execute each step in the routine\n\t\tfor (let i = 0; i < routine.steps.length; i++) {\n\t\t\tconst step = routine.steps[i]\n\t\t\tif (!step) continue // Skip undefined steps\n\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'meta',\n\t\t\t\t\t\tmessage: `Executing step ${i + 1}/${routine.steps.length}: ${step.type}`,\n\t\t\t\t\t\tvariant: 'header',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t})\n\n\t\t\tsignal.throwIfAborted()\n\n\t\t\t// Execute the step and update the conversation\n\t\t\tconversation = await runStep(step, conversation, env, progressReporter, {\n\t\t\t\tuserInput: args.userInput,\n\t\t\t})\n\t\t}\n\n\t\tprogressReporter.update({\n\t\t\tstatus: 'done' as const,\n\t\t\tprogress: {\n\t\t\t\ttype: 'meta',\n\t\t\t\tmessage: `Finished executing all ${routine.steps.length} steps of routine: ${id}.`,\n\t\t\t\tvariant: 'header',\n\t\t\t},\n\t\t\tresult: '', // No output for now\n\t\t})\n\n\t\tprogressReporter.complete()\n\t} catch (error) {\n\t\tif (isAbortError(error)) {\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'cancelled' as const,\n\t\t\t\tprogress: {\n\t\t\t\t\ttype: 'meta',\n\t\t\t\t\tmessage: 'Operation cancelled',\n\t\t\t\t},\n\t\t\t})\n\t\t\tprogressReporter.complete()\n\t\t} else {\n\t\t\tlogger.error('Error in run_routine', {\n\t\t\t\terror,\n\t\t\t\tstack: error instanceof Error ? error.stack : '',\n\t\t\t})\n\t\t\tprogressReporter.error(error)\n\t\t}\n\t}\n}\n"],"names":["BaseStep","z.object","z.enum","z.union","z.literal","z.array","z.string","z.record","z.any","AgentStep","z.boolean","LLMStep","LoopAgentStep","LoopLLMStep","ToolCallStep","BashStep","Step","z.discriminatedUnion","RoutineBlock","Routine","deserializeRoutineFromYAML","yamlString","parsedYaml","parse","error","z.ZodError","err","ProgressReporter","observer","signal","update","substitutePromptVars","prompt","vars","result","runStep","step","conversation","env","progressReporter","runStepAgent","runStepLLM","origConversation","toolService","createToolService","registerBuiltinToolsToToolService","promptText","recordThreadDelta","delta","applyThreadDelta","enabledToolSpecs","firstValueFrom","t","model","ACTIVE_MODEL","loopCount","maxLoops","systemPromptService","DefaultSystemPromptService","systemPromptBlocks","buildSystemPrompt","systemPrompt","anthropicMessages","AnthropicConverters","runAnthropicSync","assistantResponseDelta","fromAnthropicResultToThreadDelta","assistantText","item","toolCalls","findToolUsesNeedingInvocation","toolCall","toolResult","invokeToolAndWaitForResult","thread","message","toolResults","toolResultBlocks","block","toolName","input","userInput","resolve","reject","settled","sub","run","isToolRunTerminalState","runRoutine","args","Observable","abortController","runRoutineImpl","isAbortError","id","file","routineFile","readFileToolReg","readFileResult","fileContents","routineContent","line","routines","routine","newThreadID","i","logger"],"mappings":";;;AAGA,MAAMA,IAAWC,EAAS;AAAA,EACzB,SAASC,EAAO,CAAC,YAAY,MAAM,CAAC,EAAE,SAAA,EAAW,QAAQ,UAAU;AAAA,EACnE,OAAOC,EAAQ,CAACC,EAAU,KAAK,GAAGC,EAAQC,EAAU,CAAA,CAAC,CAAC,EAAE,SAAS;AAAA,EACjE,QAAQA,EAAS;AAAA,EACjB,QAAQC,EAASC,EAAO,CAAA,EAAE,SAAS;AACpC,CAAC,GAQKC,KAAYT,EAAS,OAAO;AAAA,EACjC,MAAMI,EAAU,OAAO;AAAA,EACvB,OAAOE,EAAS,EAAE,SAAS;AAAA;AAAA,EAC3B,0BAA0BI,EAAU,EAAE,SAAS;AAChD,CAAC,GAGKC,KAAUX,EAAS,OAAO;AAAA,EAC/B,MAAMI,EAAU,KAAK;AAAA,EACrB,OAAOE,EAAS,EAAE,SAAS;AAC5B,CAAC,GAGKM,KAAgBZ,EAAS,OAAO;AAAA,EACrC,MAAMI,EAAU,YAAY;AAAA,EAC5B,OAAOE,EAAS,EAAE,SAAS;AAAA,EAC3B,YAAYA,EAAS;AACtB,CAAC,GAGKO,KAAcb,EAAS,OAAO;AAAA,EACnC,MAAMI,EAAU,UAAU;AAAA,EAC1B,OAAOE,EAAS,EAAE,SAAS;AAAA,EAC3B,YAAYA,EAAS;AACtB,CAAC,GAGKQ,KAAeb,EA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qE,EAAarE,CAAK,KACrBe,EAAiB,OAAO;AAAA,MACvB,QAAQ;AAAA,MACR,UAAU;AAAA,QACT,MAAM;AAAA,QACN,SAAS;AAAA,MAAA;AAAA,IACV,CACA,GACDA,EAAiB,SAAS,MAE1BmE,GAAO,MAAM,wBAAwB;AAAA,MACpC,OAAAlF;AAAA,MACA,OAAOA,aAAiB,QAAQA,EAAM,QAAQ;AAAA,IAAA,CAC9C,GACDe,EAAiB,MAAMf,CAAK;AAAA,EAC7B;AAEF;"}
1
+ {"version":3,"file":"node-D-xGtMhE.js","sources":["../../core/src/tools/builtin/run_routine/types.ts","../../core/src/tools/builtin/run_routine/serialization.ts","../../core/src/tools/builtin/run_routine/util.ts","../../core/src/tools/builtin/run_routine/step.ts","../../core/src/tools/builtin/run_routine/node.ts"],"sourcesContent":["import { z } from 'zod'\n\n// Base Step interface\nconst BaseStep = z.object({\n\tcontext: z.enum(['continue', 'none']).optional().default('continue'),\n\ttools: z.union([z.literal('all'), z.array(z.string())]).optional(),\n\tprompt: z.string(),\n\tverify: z.record(z.any()).optional(),\n}) satisfies z.ZodType<{\n\tcontext?: 'continue' | 'none'\n\ttools?: 'all' | string[]\n\tprompt: string\n\tverify?: Record<string, any>\n}>\n\n// Agent Step\nconst AgentStep = BaseStep.extend({\n\ttype: z.literal('agent'),\n\tmodel: z.string().optional(), // Default could be set in implementation\n\tinteractive_confirmation: z.boolean().optional(),\n})\n\n// LLM Step\nconst LLMStep = BaseStep.extend({\n\ttype: z.literal('llm'),\n\tmodel: z.string().optional(),\n})\n\n// Loop Agent Step\nconst LoopAgentStep = BaseStep.extend({\n\ttype: z.literal('loop_agent'),\n\tmodel: z.string().optional(),\n\tinput_file: z.string(),\n})\n\n// Loop LLM Step\nconst LoopLLMStep = BaseStep.extend({\n\ttype: z.literal('loop_llm'),\n\tmodel: z.string().optional(),\n\tinput_file: z.string(),\n})\n\n// Tool Call Step\nconst ToolCallStep = z.object({\n\ttype: z.literal('tool_call'),\n\ttool: z.string(),\n\tparameters: z.record(z.any()).optional(),\n})\n\n// Bash Step\nconst BashStep = z.object({\n\ttype: z.literal('bash'),\n\tcommand: z.string(),\n})\n\n// Union of all step types\nconst Step = z.discriminatedUnion('type', [\n\tAgentStep,\n\tLLMStep,\n\tLoopAgentStep,\n\tLoopLLMStep,\n\tToolCallStep,\n\tBashStep,\n])\n\n// Routine Block\nconst RoutineBlock = z.object({\n\tid: z.string(),\n\tsteps: z.array(Step),\n})\n\n// Routine (array of RoutineBlocks)\nconst Routine = z.array(RoutineBlock)\n\nconst Routines = z.array(Routine)\n\nexport type RoutineSchema = z.infer<typeof Routine>\nexport type RoutinesSchema = z.infer<typeof Routines>\nexport type RoutineBlockSchema = z.infer<typeof RoutineBlock>\nexport type StepSchema = z.infer<typeof Step>\nexport type AgentStepSchema = z.infer<typeof AgentStep>\nexport type LLMStepSchema = z.infer<typeof LLMStep>\nexport type LoopAgentStepSchema = z.infer<typeof LoopAgentStep>\nexport type LoopLLMStepSchema = z.infer<typeof LoopLLMStep>\nexport type ToolCallStepSchema = z.infer<typeof ToolCallStep>\nexport type BashStepSchema = z.infer<typeof BashStep>\n\nexport { Routine, RoutineBlock, Routines, Step }\n","import { parse } from 'yaml'\nimport { z } from 'zod'\nimport type { RoutineSchema } from './types'\nimport { Routine } from './types'\n\n/**\n * Deserialize a YAML string into a Routine\n * @param yamlString The YAML string representation of a Routine\n * @returns The parsed and validated Routine\n * @throws Error if the YAML is invalid or doesn't match the Routine schema\n */\nexport function deserializeRoutineFromYAML(yamlString: string): RoutineSchema {\n\ttry {\n\t\t// Parse the YAML string to a JavaScript object\n\t\tconst parsedYaml = parse(yamlString)\n\n\t\t// Validate and transform the parsed YAML against the Routine schema\n\t\tconst validatedRoutine = Routine.parse(parsedYaml)\n\n\t\treturn validatedRoutine\n\t} catch (error) {\n\t\tif (error instanceof z.ZodError) {\n\t\t\t// Enhance Zod validation errors with better context\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid routine format: ${error.errors\n\t\t\t\t\t.map((err) => `${err.path.join('.')} - ${err.message}`)\n\t\t\t\t\t.join(', ')}`,\n\t\t\t)\n\t\t} else if (error instanceof Error) {\n\t\t\t// Handle YAML parsing errors\n\t\t\tthrow new Error(`Failed to parse YAML: ${error.message}`)\n\t\t} else {\n\t\t\tthrow new Error(`Unknown error during routine deserialization: ${String(error)}`)\n\t\t}\n\t}\n}\n","import type { SubscriptionObserver } from '@sourcegraph/observable'\nimport type { ToolRun } from '../../tool-service'\nimport type { RunRoutineProgressMessage, RunRoutineToolDef } from './common'\n\n/**\n * Class that maintains state for status messages in run_routine implementation.\n * Keeps track of all status messages and reports them through the observer.\n */\nexport class ProgressReporter {\n\tprivate progressMessages: RunRoutineProgressMessage[] = []\n\n\tconstructor(\n\t\tprivate observer: SubscriptionObserver<ToolRun<RunRoutineToolDef>>,\n\t\tprivate signal: AbortSignal,\n\t) {}\n\n\t/**\n\t * Adds the latest message to the list of all status updates and then invokes the observer\n\t * with the updated 'in-progress' status.\n\t */\n\tupdate(update: ToolRun<RunRoutineToolDef>): void {\n\t\tthis.signal.throwIfAborted()\n\t\tif ('progress' in update && update.progress) {\n\t\t\tif (Array.isArray(update.progress)) {\n\t\t\t\tthis.progressMessages.push(...update.progress)\n\t\t\t} else {\n\t\t\t\tthis.progressMessages.push(update.progress)\n\t\t\t}\n\t\t\tthis.observer.next({\n\t\t\t\t...update,\n\t\t\t\tprogress: this.progressMessages,\n\t\t\t})\n\t\t} else {\n\t\t\tthis.observer.next(update)\n\t\t}\n\t}\n\n\terror(error: unknown): void {\n\t\tthis.observer.error(error)\n\t}\n\n\tcomplete(): void {\n\t\tthis.observer.complete()\n\t}\n}\n\n/**\n * Apply variable substitutions to a prompt string\n */\nexport function substitutePromptVars(prompt: string, vars: { userInput?: string }): string {\n\tlet result = prompt\n\n\t// Replace {{userInput}} with the actual user input if provided\n\tif (vars.userInput) {\n\t\tresult = result.replace(/\\{\\{\\s*userInput\\s*\\}\\}/g, vars.userInput)\n\t\tresult = result.replace(/\\{\\{\\s*user_input\\s*\\}\\}/g, vars.userInput)\n\t}\n\n\treturn result\n}\n","import { firstValueFrom } from '@sourcegraph/observable'\nimport {\n\tACTIVE_MODEL,\n\tAnthropicConverters,\n\tfromAnthropicResultToThreadDelta,\n\trunAnthropicSync,\n} from '../../../inference/backends/anthropic'\nimport { buildSystemPrompt, DefaultSystemPromptService } from '../../../threads/system-prompt'\nimport type { ToolUseBlock } from '../../../threads/thread'\nimport {\n\ttoolResultBlocks,\n\ttype Thread,\n\ttype ThreadAssistantMessage,\n\ttype ToolRunUserInput,\n} from '../../../threads/thread'\nimport type { ThreadDelta } from '../../../threads/thread-delta'\nimport { applyThreadDelta } from '../../../threads/thread-delta'\nimport type {\n\tToolDefinition,\n\tToolRun,\n\tToolRunEnvironment,\n\tToolService,\n} from '../../../tools/tool-service'\nimport { createToolService, isToolRunTerminalState } from '../../../tools/tool-service'\nimport { registerBuiltinToolsToToolService } from '../../tools'\nimport type { AgentStepSchema, LLMStepSchema, StepSchema } from './types'\nimport { substitutePromptVars, type ProgressReporter } from './util'\n\n/**\n * Run a step with the given conversation\n */\nexport function runStep(\n\tstep: StepSchema,\n\tconversation: Thread,\n\tenv: ToolRunEnvironment,\n\tprogressReporter: ProgressReporter,\n\tvars: { userInput?: string },\n\tsignal: AbortSignal = new AbortController().signal,\n): Promise<Thread> {\n\tswitch (step.type) {\n\t\tcase 'agent':\n\t\t\treturn runStepAgent(step, conversation, env, progressReporter, vars, signal)\n\t\t\tbreak\n\t\tcase 'llm':\n\t\t\treturn runStepLLM(step, conversation, progressReporter, vars, signal)\n\t\t\tbreak\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown step type: ${(step as any).type}`)\n\t}\n}\n\n/**\n * Run an agent step that implements a full agentic loop\n * Follows the pattern: inference -> tool calls -> tool results -> inference\n * until there are no more tool calls or the process is complete\n */\nasync function runStepAgent(\n\tstep: AgentStepSchema,\n\torigConversation: Thread,\n\tenv: ToolRunEnvironment,\n\tprogressReporter: ProgressReporter,\n\tvars: { userInput?: string },\n\tsignal: AbortSignal,\n): Promise<Thread> {\n\tconst toolService = createToolService()\n\tawait registerBuiltinToolsToToolService(toolService)\n\n\t// Process prompt template with variables if provided\n\tconst promptText = substitutePromptVars(step.prompt, vars)\n\n\t// Clone convo\n\tlet conversation = origConversation\n\tconst recordThreadDelta = (delta: ThreadDelta) => {\n\t\tconversation = applyThreadDelta(conversation, delta)\n\t}\n\n\trecordThreadDelta({\n\t\ttype: 'user:message',\n\t\tmessage: {\n\t\t\tcontent: [{ type: 'text', text: promptText }],\n\t\t\tmeta: {\n\t\t\t\tsentAt: Date.now(),\n\t\t\t},\n\t\t},\n\t})\n\n\t// Update progress with user message added\n\tprogressReporter.update({\n\t\tstatus: 'in-progress',\n\t\tprogress: { type: 'message', speaker: 'user', message: promptText },\n\t})\n\n\t// Get enabled tools from toolService (all tools for now)\n\tconst enabledToolSpecs = (await firstValueFrom(toolService.tools, signal)).map((t) => t.spec)\n\n\t// Set up parameters for the initial API call\n\tconst model = ACTIVE_MODEL\n\n\t// The agent loop will continue until there are no more tool calls needed\n\tlet loopCount = 0\n\tconst maxLoops = 100 // Prevent infinite loops\n\n\twhile (loopCount < maxLoops) {\n\t\tsignal.throwIfAborted()\n\t\tloopCount++\n\n\t\t// Get system prompt blocks from the main system prompt builder\n\t\tconst systemPromptService = new DefaultSystemPromptService()\n\t\t// Get the main system prompt blocks\n\t\tconst systemPromptBlocks = await buildSystemPrompt(systemPromptService, {\n\t\t\tenabledTodos: false,\n\t\t\tthreadEnv: env.threadEnvironment,\n\t\t})\n\n\t\t// Add the subagent-specific instruction as the final block\n\t\tsystemPromptBlocks.push({\n\t\t\ttype: 'text' as const,\n\t\t\ttext: 'You are a helpful AI assistant running as a subagent within a larger system. Your task is to handle this specific step in a routine. You can use tools to complete your task. When you are completely done, do not ask to use more tools.',\n\t\t})\n\n\t\t// Use the combined system prompt\n\t\tconst systemPrompt = systemPromptBlocks\n\n\t\tsignal.throwIfAborted()\n\n\t\t// Use runAnthropicSync to get a response\n\t\tlet result\n\t\ttry {\n\t\t\tconst anthropicMessages = AnthropicConverters.fromNativeThread(conversation)\n\t\t\tresult = await runAnthropicSync(\n\t\t\t\tanthropicMessages,\n\t\t\t\tenabledToolSpecs,\n\t\t\t\tsystemPrompt,\n\t\t\t\tmodel,\n\t\t\t\tsignal,\n\t\t\t)\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Anthropic API error: ${error}`)\n\t\t}\n\n\t\tif (!result.message || !('content' in result.message)) {\n\t\t\tthrow new Error('Unexpected response format from Anthropic')\n\t\t}\n\t\tif (result.message.content.length === 0) {\n\t\t\tbreak\n\t\t}\n\n\t\tconst assistantResponseDelta = fromAnthropicResultToThreadDelta(result.message)\n\t\trecordThreadDelta(assistantResponseDelta)\n\n\t\t// Extract text for progress reporting\n\t\tconst assistantText = result.message.content\n\t\t\t.filter((item) => item.type === 'text')\n\t\t\t.map((item) => ('text' in item ? item.text : ''))\n\t\t\t.join(' ')\n\t\t\t.trim()\n\t\tif (assistantText) {\n\t\t\t// Show assistant message\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: { type: 'message', speaker: 'assistant', message: assistantText },\n\t\t\t})\n\t\t}\n\n\t\tif (assistantResponseDelta.type !== 'assistant:message') {\n\t\t\t// No tool calls\n\t\t\tbreak\n\t\t}\n\n\t\tconst toolCalls = findToolUsesNeedingInvocation(\n\t\t\tconversation,\n\t\t\tassistantResponseDelta.message,\n\t\t)\n\t\tfor (const toolCall of toolCalls) {\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: {\n\t\t\t\t\tid: toolCall.id,\n\t\t\t\t\ttype: 'toolCall',\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\targs: JSON.stringify(toolCall.input),\n\t\t\t\t},\n\t\t\t})\n\n\t\t\tlet toolResult\n\t\t\ttry {\n\t\t\t\ttoolResult = await invokeToolAndWaitForResult(\n\t\t\t\t\ttoolService,\n\t\t\t\t\ttoolCall.name,\n\t\t\t\t\ttoolCall.input,\n\t\t\t\t\tenv,\n\t\t\t\t\tsignal,\n\t\t\t\t)\n\t\t\t\tsignal.throwIfAborted()\n\t\t\t\tif (toolResult.status !== 'done') {\n\t\t\t\t\tthrow new Error(JSON.stringify(toolResult))\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\trecordThreadDelta({\n\t\t\t\t\ttype: 'tool:data',\n\t\t\t\t\ttoolUse: toolCall.id,\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tstatus: 'error',\n\t\t\t\t\t\terror: { message: `Tool call error: ${error}` },\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tprogressReporter.update({\n\t\t\t\t\tstatus: 'in-progress',\n\t\t\t\t\tprogress: {\n\t\t\t\t\t\tid: toolCall.id,\n\t\t\t\t\t\ttype: 'toolResult',\n\t\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\t\tresult: `Tool call error: ${error}`,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\trecordThreadDelta({\n\t\t\t\ttype: 'tool:data',\n\t\t\t\ttoolUse: toolCall.id,\n\t\t\t\tdata: toolResult,\n\t\t\t})\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: {\n\t\t\t\t\tid: toolCall.id,\n\t\t\t\t\ttype: 'toolResult',\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\tresult:\n\t\t\t\t\t\ttypeof toolResult.result === 'string'\n\t\t\t\t\t\t\t? toolResult.result\n\t\t\t\t\t\t\t: JSON.stringify(toolResult.result),\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t}\n\treturn conversation\n}\n\n/**\n * Mock implementation of tool execution for the subagent\n * In a real implementation, this would connect to the actual tool execution system\n */\n// Removed mock implementation in favor of actual toolService\n\n/**\n * Run an LLM step\n */\nasync function runStepLLM(\n\tstep: LLMStepSchema,\n\torigConversation: Thread,\n\tprogressReporter: ProgressReporter,\n\tvars: { userInput?: string },\n\tsignal: AbortSignal,\n): Promise<Thread> {\n\t// Process prompt template with variables if provided\n\tconst promptText = substitutePromptVars(step.prompt, vars)\n\n\t// Create a copy of the conversation to avoid mutating the original\n\tlet conversation = origConversation\n\tconst recordThreadDelta = (delta: ThreadDelta) => {\n\t\tconversation = applyThreadDelta(conversation, delta)\n\t}\n\n\trecordThreadDelta({\n\t\ttype: 'user:message',\n\t\tmessage: {\n\t\t\tcontent: [{ type: 'text', text: promptText }],\n\t\t\tmeta: {\n\t\t\t\tsentAt: Date.now(),\n\t\t\t},\n\t\t},\n\t})\n\n\t// Update progress with user message added\n\tprogressReporter.update({\n\t\tstatus: 'in-progress',\n\t\tprogress: { type: 'message', speaker: 'user', message: promptText },\n\t})\n\n\t// Use runAnthropicSync to get a response\n\tconst anthropicMessages = AnthropicConverters.fromNativeThread(conversation)\n\tconst model = step.model || ACTIVE_MODEL\n\tconst result = await runAnthropicSync(\n\t\tanthropicMessages,\n\t\t[], // No tools for LLM-only step\n\t\t[], // No system prompt\n\t\tmodel,\n\t\tsignal,\n\t)\n\n\tif (!result.message) {\n\t\tthrow new Error('Failed to get response from Anthropic')\n\t}\n\n\tconst assistantResponseDelta = fromAnthropicResultToThreadDelta(result.message)\n\trecordThreadDelta(assistantResponseDelta)\n\n\t// Display message\n\tconst assistantText = result.message.content\n\t\t.filter((item) => item.type === 'text')\n\t\t.map((item) => (item.type === 'text' ? item.text : ''))\n\t\t.join(' ')\n\t\t.trim()\n\tprogressReporter.update({\n\t\tstatus: 'in-progress',\n\t\tprogress: { type: 'message', speaker: 'assistant', message: assistantText },\n\t})\n\treturn conversation\n}\n\nfunction findToolUsesNeedingInvocation(\n\tthread: Thread,\n\tmessage: ThreadAssistantMessage,\n): ToolUseBlock[] {\n\tconst toolResults = toolResultBlocks(thread)\n\treturn message.content\n\t\t.filter((block): block is ToolUseBlock => block.type === 'tool_use')\n\t\t.filter((block) => !block.inputPartialJSON)\n\t\t.filter(\n\t\t\t(block) =>\n\t\t\t\t// Only include tools that haven't been invoked yet.\n\t\t\t\t!toolResults.has(block.id),\n\t\t)\n}\n\n/**\n * Helper function that invokes a tool and returns a Promise with the final result\n */\nexport async function invokeToolAndWaitForResult<T extends ToolDefinition>(\n\ttoolService: ToolService,\n\ttoolName: string,\n\tinput: unknown,\n\tenv: ToolRunEnvironment,\n\tsignal: AbortSignal = new AbortController().signal,\n\tuserInput?: ToolRunUserInput,\n): Promise<ToolRun<T>> {\n\treturn new Promise((resolve, reject) => {\n\t\tlet settled = false\n\t\tconst sub = toolService\n\t\t\t.invokeTool(toolName, { args: input as any, userInput }, env)\n\t\t\t.subscribe({\n\t\t\t\tnext: (run: ToolRun) => {\n\t\t\t\t\tif (isToolRunTerminalState(run)) {\n\t\t\t\t\t\tsub.unsubscribe()\n\t\t\t\t\t\tif (!settled) {\n\t\t\t\t\t\t\tsettled = true\n\t\t\t\t\t\t\tresolve(run)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\terror: (error) => {\n\t\t\t\t\tif (!settled) {\n\t\t\t\t\t\tsettled = true\n\t\t\t\t\t\treject(error)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tcomplete: () => {},\n\t\t\t})\n\n\t\t// Handle abort signal\n\t\tsignal.addEventListener('abort', () => {\n\t\t\tsub.unsubscribe()\n\t\t\tif (!settled) {\n\t\t\t\tsettled = true\n\t\t\t\treject(new Error('Tool execution was aborted'))\n\t\t\t}\n\t\t})\n\t})\n}\n","import { Observable } from '@sourcegraph/observable'\nimport { isAbortError } from '../../../common/abort'\nimport logger from '../../../common/logger'\nimport type { Thread } from '../../../threads/thread'\nimport { newThreadID } from '../../../threads/thread'\nimport type { ToolRunEnvironment } from '../../tool-service'\nimport { createToolService } from '../../tool-service'\nimport type { ReadFileToolDef } from '../filesystem/read_file.common'\nimport { readFileToolReg } from '../filesystem/read_file.common'\nimport type { runRoutineToolReg } from './common'\nimport { deserializeRoutineFromYAML } from './serialization'\nimport { invokeToolAndWaitForResult, runStep } from './step'\nimport { ProgressReporter } from './util'\n\nexport const runRoutine: NonNullable<(typeof runRoutineToolReg)['fn']> = ({ args }, env) => {\n\treturn new Observable((observer) => {\n\t\tconst abortController = new AbortController()\n\t\tconst progressReporter = new ProgressReporter(observer, abortController.signal)\n\n\t\trunRoutineImpl(args, env, progressReporter, abortController.signal).catch((error) => {\n\t\t\t// Don't report AbortError as an error - it's expected when cancelling\n\t\t\tif (!isAbortError(error)) {\n\t\t\t\tprogressReporter.error(error)\n\t\t\t} else {\n\t\t\t\tprogressReporter.update({\n\t\t\t\t\tstatus: 'cancelled' as const,\n\t\t\t\t\tprogress: { type: 'meta', message: 'Operation cancelled' },\n\t\t\t\t})\n\t\t\t\tprogressReporter.complete()\n\t\t\t}\n\t\t})\n\n\t\treturn () => {\n\t\t\tabortController.abort()\n\t\t}\n\t})\n}\n\nasync function runRoutineImpl(\n\targs: { id: string; file?: string; userInput?: string },\n\tenv: ToolRunEnvironment,\n\tprogressReporter: ProgressReporter,\n\tsignal: AbortSignal,\n) {\n\ttry {\n\t\tconst { id, file } = args\n\t\tconst routineFile = file || 'routines.amp.yaml'\n\n\t\t// Report initial progress\n\t\tprogressReporter.update({\n\t\t\tstatus: 'in-progress',\n\t\t\tprogress: { type: 'meta', message: `Loading routine: ${id} from ${routineFile}` },\n\t\t})\n\n\t\t// Create a tool service and register the read_file tool\n\t\tconst toolService = createToolService()\n\t\ttoolService.registerTool(readFileToolReg)\n\n\t\t// Read the routine file using the tool service\n\t\tconst readFileResult = await invokeToolAndWaitForResult<ReadFileToolDef>(\n\t\t\ttoolService,\n\t\t\t'read_file',\n\t\t\t{ path: routineFile },\n\t\t\tenv,\n\t\t\tsignal,\n\t\t)\n\n\t\t// Process the file content by removing line numbers that read_file adds\n\t\tif (readFileResult.status !== 'done') {\n\t\t\tthrow new Error(`Failed to read routine file: ${routineFile}`)\n\t\t}\n\t\t// At this point TypeScript knows readFileResult has a 'result' property\n\t\tconst fileContents =\n\t\t\ttypeof readFileResult.result === 'string'\n\t\t\t\t? readFileResult.result\n\t\t\t\t: readFileResult.result.content\n\t\tconst routineContent = String(fileContents)\n\t\t\t.split('\\n')\n\t\t\t.map((line: string) => line.replace(/^\\d+:\\s/, ''))\n\t\t\t.join('\\n')\n\n\t\tsignal.throwIfAborted()\n\n\t\t// Parse the routines\n\t\tconst routines = deserializeRoutineFromYAML(routineContent)\n\t\tsignal.throwIfAborted()\n\n\t\t// Find the requested routine\n\t\tconst routine = routines.find((routine) => routine.id === id)\n\t\tif (!routine) {\n\t\t\tthrow new Error(`Routine with id \"${id}\" not found in ${routineFile}`)\n\t\t}\n\n\t\t// Initialize a Thread for the conversation\n\t\tlet conversation: Thread = {\n\t\t\tid: newThreadID(),\n\t\t\tcreated: Date.now(),\n\t\t\tv: 0,\n\t\t\tmessages: [],\n\t\t}\n\n\t\t// Report progress before executing steps\n\t\tprogressReporter.update({\n\t\t\tstatus: 'in-progress',\n\t\t\tprogress: [\n\t\t\t\t{\n\t\t\t\t\ttype: 'meta',\n\t\t\t\t\tmessage: `Executing routine ${id}`,\n\t\t\t\t},\n\t\t\t],\n\t\t})\n\n\t\t// Execute each step in the routine\n\t\tfor (let i = 0; i < routine.steps.length; i++) {\n\t\t\tconst step = routine.steps[i]\n\t\t\tif (!step) continue // Skip undefined steps\n\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'meta',\n\t\t\t\t\t\tmessage: `Executing step ${i + 1}/${routine.steps.length}: ${step.type}`,\n\t\t\t\t\t\tvariant: 'header',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t})\n\n\t\t\tsignal.throwIfAborted()\n\n\t\t\t// Execute the step and update the conversation\n\t\t\tconversation = await runStep(step, conversation, env, progressReporter, {\n\t\t\t\tuserInput: args.userInput,\n\t\t\t})\n\t\t}\n\n\t\tprogressReporter.update({\n\t\t\tstatus: 'done' as const,\n\t\t\tprogress: {\n\t\t\t\ttype: 'meta',\n\t\t\t\tmessage: `Finished executing all ${routine.steps.length} steps of routine: ${id}.`,\n\t\t\t\tvariant: 'header',\n\t\t\t},\n\t\t\tresult: '', // No output for now\n\t\t})\n\n\t\tprogressReporter.complete()\n\t} catch (error) {\n\t\tif (isAbortError(error)) {\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'cancelled' as const,\n\t\t\t\tprogress: {\n\t\t\t\t\ttype: 'meta',\n\t\t\t\t\tmessage: 'Operation cancelled',\n\t\t\t\t},\n\t\t\t})\n\t\t\tprogressReporter.complete()\n\t\t} else {\n\t\t\tlogger.error('Error in run_routine', {\n\t\t\t\terror,\n\t\t\t\tstack: error instanceof Error ? error.stack : '',\n\t\t\t})\n\t\t\tprogressReporter.error(error)\n\t\t}\n\t}\n}\n"],"names":["BaseStep","z.object","z.enum","z.union","z.literal","z.array","z.string","z.record","z.any","AgentStep","z.boolean","LLMStep","LoopAgentStep","LoopLLMStep","ToolCallStep","BashStep","Step","z.discriminatedUnion","RoutineBlock","Routine","deserializeRoutineFromYAML","yamlString","parsedYaml","parse","error","z.ZodError","err","ProgressReporter","observer","signal","update","substitutePromptVars","prompt","vars","result","runStep","step","conversation","env","progressReporter","runStepAgent","runStepLLM","origConversation","toolService","createToolService","registerBuiltinToolsToToolService","promptText","recordThreadDelta","delta","applyThreadDelta","enabledToolSpecs","firstValueFrom","t","model","ACTIVE_MODEL","loopCount","maxLoops","systemPromptService","DefaultSystemPromptService","systemPromptBlocks","buildSystemPrompt","systemPrompt","anthropicMessages","AnthropicConverters","runAnthropicSync","assistantResponseDelta","fromAnthropicResultToThreadDelta","assistantText","item","toolCalls","findToolUsesNeedingInvocation","toolCall","toolResult","invokeToolAndWaitForResult","thread","message","toolResults","toolResultBlocks","block","toolName","input","userInput","resolve","reject","settled","sub","run","isToolRunTerminalState","runRoutine","args","Observable","abortController","runRoutineImpl","isAbortError","id","file","routineFile","readFileToolReg","readFileResult","fileContents","routineContent","line","routines","routine","newThreadID","i","logger"],"mappings":";;;AAGA,MAAMA,IAAWC,EAAS;AAAA,EACzB,SAASC,EAAO,CAAC,YAAY,MAAM,CAAC,EAAE,SAAA,EAAW,QAAQ,UAAU;AAAA,EACnE,OAAOC,EAAQ,CAACC,EAAU,KAAK,GAAGC,EAAQC,EAAU,CAAA,CAAC,CAAC,EAAE,SAAS;AAAA,EACjE,QAAQA,EAAS;AAAA,EACjB,QAAQC,EAASC,EAAO,CAAA,EAAE,SAAS;AACpC,CAAC,GAQKC,KAAYT,EAAS,OAAO;AAAA,EACjC,MAAMI,EAAU,OAAO;AAAA,EACvB,OAAOE,EAAS,EAAE,SAAS;AAAA;AAAA,EAC3B,0BAA0BI,EAAU,EAAE,SAAS;AAChD,CAAC,GAGKC,KAAUX,EAAS,OAAO;AAAA,EAC/B,MAAMI,EAAU,KAAK;AAAA,EACrB,OAAOE,EAAS,EAAE,SAAS;AAC5B,CAAC,GAGKM,KAAgBZ,EAAS,OAAO;AAAA,EACrC,MAAMI,EAAU,YAAY;AAAA,EAC5B,OAAOE,EAAS,EAAE,SAAS;AAAA,EAC3B,YAAYA,EAAS;AACtB,CAAC,GAGKO,KAAcb,EAAS,OAAO;AAAA,EACnC,MAAMI,EAAU,UAAU;AAAA,EAC1B,OAAOE,EAAS,EAAE,SAAS;AAAA,EAC3B,YAAYA,EAAS;AACtB,CAAC,GAGKQ,KAAeb,EAAS;AAAA,EAC7B,MAAMG,EAAU,WAAW;AAAA,EAC3B,MAAME,EAAS;AAAA,EACf,YAAYC,EAASC,EAAO,CAAA,EAAE,SAAS;AACxC,CAAC,GAGKO,KAAWd,EAAS;AAAA,EACzB,MAAMG,EAAU,MAAM;AAAA,EACtB,SAASE,EAAS;AACnB,CAAC,GAGKU,KAAOC,EAAqB,QAAQ;AAAA,EACzCR;AAAA,EACA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,CAC9C,GACDe,EAAiB,MAAMf,CAAK;AAAA,EAC7B;AAEF;"}
@@ -4,7 +4,7 @@ import * as i from "node:fs";
4
4
  import * as o from "node:path";
5
5
  import { join as f } from "node:path";
6
6
  import { promisify as p } from "node:util";
7
- import { C as l, aJ as n } from "./console-DZmALLuA.js";
7
+ import { C as l, aJ as n } from "./console-CDi5rFHv.js";
8
8
  import { homedir as w } from "node:os";
9
9
  const d = f(w(), ".amp", "file-changes"), u = p(m);
10
10
  function b(a) {
@@ -110,4 +110,4 @@ export {
110
110
  y as listFilesGit,
111
111
  b as nodeFileSystem
112
112
  };
113
- //# sourceMappingURL=node-SvjAOtkw.js.map
113
+ //# sourceMappingURL=node-DQLcKPbG.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-SvjAOtkw.js","sources":["../../core/src/platform/fs/backups.node.ts","../../core/src/platform/fs/node.ts"],"sourcesContent":["import { homedir } from 'node:os'\nimport { join } from 'node:path'\n\nexport const BACKUP_DIR_NODE = join(homedir(), '.amp', 'file-changes')\n","import { execFile } from 'node:child_process'\nimport * as fs from 'node:fs'\nimport * as path from 'node:path'\nimport { promisify } from 'node:util'\nimport logger from '../../common/logger'\nimport { type FileChangeRecord } from '../../threads/file-tracking/common'\nimport type { ThreadID } from '../../threads/thread'\nimport { BACKUP_DIR_NODE } from './backups.node'\nimport { FileNotExistError, type FileSystem } from './fs'\n\nconst execFileAsync = promisify(execFile)\n\nexport function nodeFileSystem(threadID: ThreadID): FileSystem {\n\tconst backupDir = path.join(BACKUP_DIR_NODE, threadID)\n\treturn {\n\t\trelativePath: (a: string, b: string) => path.relative(a, b),\n\t\tjoinPath: (...paths: string[]) => path.join(...paths),\n\n\t\treadFile: async (path: string, signal?: AbortSignal) => {\n\t\t\ttry {\n\t\t\t\treturn await fs.promises.readFile(path, { encoding: 'utf8', signal })\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\treadBinaryFile: async (path: string, signal?: AbortSignal) => {\n\t\t\ttry {\n\t\t\t\t// Read as Buffer without encoding\n\t\t\t\treturn await fs.promises.readFile(path, { signal })\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\tgetMtime: async (path: string, signal?: AbortSignal) => {\n\t\t\ttry {\n\t\t\t\t// Node.js stat doesn't support AbortSignal directly\n\t\t\t\tconst stats = await fs.promises.stat(path)\n\t\t\t\treturn stats.mtimeMs\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\tstat: async (path: string) => {\n\t\t\ttry {\n\t\t\t\tconst stats = await fs.promises.stat(path)\n\t\t\t\treturn {\n\t\t\t\t\tsize: stats.size,\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\twriteFile: async (path, content, signal) => {\n\t\t\tawait fs.promises.writeFile(path, content, { encoding: 'utf-8', signal })\n\t\t},\n\t\tdeleteFile: async (path, signal?: AbortSignal) => {\n\t\t\ttry {\n\t\t\t\tawait fs.promises.unlink(path)\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\tmkdirp: async (path) => {\n\t\t\tawait fs.promises.mkdir(path, { recursive: true })\n\t\t},\n\t\tstoreFileChange: async (backupFileName: string, fileChange: FileChangeRecord) => {\n\t\t\tconst backupPath = path.join(backupDir, backupFileName)\n\t\t\tawait fs.promises.writeFile(backupPath, JSON.stringify(fileChange, null, 2), 'utf8')\n\t\t},\n\t\tlistBackupFiles: async () => {\n\t\t\ttry {\n\t\t\t\t// Ensure backup directory exists\n\t\t\t\tif (\n\t\t\t\t\t!(await fs.promises\n\t\t\t\t\t\t.stat(backupDir)\n\t\t\t\t\t\t.then((s) => s.isDirectory())\n\t\t\t\t\t\t.catch(() => false))\n\t\t\t\t) {\n\t\t\t\t\tawait fs.promises.mkdir(backupDir, { recursive: true })\n\t\t\t\t\treturn []\n\t\t\t\t}\n\t\t\t\treturn await fs.promises.readdir(backupDir)\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error('Error listing backup files:', error)\n\t\t\t\treturn []\n\t\t\t}\n\t\t},\n\t\tloadFileChange: async (backupFileName: string) => {\n\t\t\ttry {\n\t\t\t\tconst backupPath = path.join(backupDir, backupFileName)\n\t\t\t\tconst content = await fs.promises.readFile(backupPath, 'utf8')\n\t\t\t\treturn JSON.parse(content) as FileChangeRecord\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(`Error loading backup file ${backupFileName}:`, error)\n\t\t\t\treturn null\n\t\t\t}\n\t\t},\n\t\tcleanupBackupFiles: async () => {\n\t\t\ttry {\n\t\t\t\tif (\n\t\t\t\t\tawait fs.promises\n\t\t\t\t\t\t.stat(backupDir)\n\t\t\t\t\t\t.then((s) => s.isDirectory())\n\t\t\t\t\t\t.catch(() => false)\n\t\t\t\t) {\n\t\t\t\t\tawait fs.promises.rm(backupDir, { recursive: true, force: true })\n\t\t\t\t\tlogger.debug(`Cleaned up backup directory: ${backupDir}`)\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(`Error cleaning up backup files in ${backupDir}:`, error)\n\t\t\t}\n\t\t},\n\t\tlistFiles: async (dir: string) => listFilesGit(dir),\n\t\texclusiveWriter: false,\n\t}\n}\n\nfunction isNodeFSNotExistError(error: unknown): boolean {\n\treturn (\n\t\terror !== null &&\n\t\ttypeof error === 'object' &&\n\t\t'code' in error &&\n\t\t(error as { code: string }).code === 'ENOENT'\n\t)\n}\n\n/**\n * Lists files in a directory using git ls-files.\n * Exported for reuse by other filesystem implementations.\n */\nexport async function listFilesGit(dir: string): Promise<string[]> {\n\ttry {\n\t\tconst { stdout: trackedFiles } = await execFileAsync('git', ['ls-files'], {\n\t\t\tcwd: dir,\n\t\t})\n\n\t\tconst { stdout: untrackedFiles } = await execFileAsync(\n\t\t\t'git',\n\t\t\t['ls-files', '--others', '--exclude-standard'],\n\t\t\t{\n\t\t\t\tcwd: dir,\n\t\t\t},\n\t\t)\n\n\t\treturn [...trackedFiles.split('\\n'), ...untrackedFiles.split('\\n')].filter(Boolean)\n\t} catch {\n\t\treturn []\n\t}\n}\n"],"names":["BACKUP_DIR_NODE","join","homedir","execFileAsync","promisify","execFile","nodeFileSystem","threadID","backupDir","path","a","b","paths","signal","fs","error","isNodeFSNotExistError","FileNotExistError","content","backupFileName","fileChange","backupPath","s","logger","dir","listFilesGit","trackedFiles","untrackedFiles"],"mappings":";;;;;;;;AAGO,MAAMA,IAAkBC,EAAKC,KAAW,QAAQ,cAAc,GCO/DC,IAAgBC,EAAUC,CAAQ;AAEjC,SAASC,EAAeC,GAAgC;AAC9D,QAAMC,IAAYC,EAAK,KAAKT,GAAiBO,CAAQ;AAC9C,SAAA;AAAA,IACN,cAAc,CAACG,GAAWC,MAAcF,EAAK,SAASC,GAAGC,CAAC;AAAA,IAC1D,UAAU,IAAIC,MAAoBH,EAAK,KAAK,GAAGG,CAAK;AAAA,IAEpD,UAAU,OAAOH,GAAcI,MAAyB;AACnD,UAAA;AACI,eAAA,MAAMC,EAAG,SAAS,SAASL,GAAM,EAAE,UAAU,QAAQ,QAAAI,GAAQ;AAAA,eAC5DE,GAAO;AACX,cAAAC,EAAsBD,CAAK,IACxB,IAAIE,EAAkBR,CAAI,IAE3BM;AAAA,MAAA;AAAA,IAER;AAAA,IACA,gBAAgB,OAA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UAAA,EAAE,QAAQE,EAAa,IAAI,MAAMvB,EAAc,OAAO,CAAC,UAAU,GAAG;AAAA,MACzE,KAAKqB;AAAA,IAAA,CACL,GAEK,EAAE,QAAQG,EAAe,IAAI,MAAMxB;AAAA,MACxC;AAAA,MACA,CAAC,YAAY,YAAY,oBAAoB;AAAA,MAC7C;AAAA,QACC,KAAKqB;AAAA,MAAA;AAAA,IAEP;AAEA,WAAO,CAAC,GAAGE,EAAa,MAAM;AAAA,CAAI,GAAG,GAAGC,EAAe,MAAM;AAAA,CAAI,CAAC,EAAE,OAAO,OAAO;AAAA,EAAA,QAC3E;AACP,WAAO,CAAC;AAAA,EAAA;AAEV;"}
1
+ {"version":3,"file":"node-DQLcKPbG.js","sources":["../../core/src/platform/fs/backups.node.ts","../../core/src/platform/fs/node.ts"],"sourcesContent":["import { homedir } from 'node:os'\nimport { join } from 'node:path'\n\nexport const BACKUP_DIR_NODE = join(homedir(), '.amp', 'file-changes')\n","import { execFile } from 'node:child_process'\nimport * as fs from 'node:fs'\nimport * as path from 'node:path'\nimport { promisify } from 'node:util'\nimport logger from '../../common/logger'\nimport { type FileChangeRecord } from '../../threads/file-tracking/common'\nimport type { ThreadID } from '../../threads/thread'\nimport { BACKUP_DIR_NODE } from './backups.node'\nimport { FileNotExistError, type FileSystem } from './fs'\n\nconst execFileAsync = promisify(execFile)\n\nexport function nodeFileSystem(threadID: ThreadID): FileSystem {\n\tconst backupDir = path.join(BACKUP_DIR_NODE, threadID)\n\treturn {\n\t\trelativePath: (a: string, b: string) => path.relative(a, b),\n\t\tjoinPath: (...paths: string[]) => path.join(...paths),\n\n\t\treadFile: async (path: string, signal?: AbortSignal) => {\n\t\t\ttry {\n\t\t\t\treturn await fs.promises.readFile(path, { encoding: 'utf8', signal })\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\treadBinaryFile: async (path: string, signal?: AbortSignal) => {\n\t\t\ttry {\n\t\t\t\t// Read as Buffer without encoding\n\t\t\t\treturn await fs.promises.readFile(path, { signal })\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\tgetMtime: async (path: string, signal?: AbortSignal) => {\n\t\t\ttry {\n\t\t\t\t// Node.js stat doesn't support AbortSignal directly\n\t\t\t\tconst stats = await fs.promises.stat(path)\n\t\t\t\treturn stats.mtimeMs\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\tstat: async (path: string) => {\n\t\t\ttry {\n\t\t\t\tconst stats = await fs.promises.stat(path)\n\t\t\t\treturn {\n\t\t\t\t\tsize: stats.size,\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\twriteFile: async (path, content, signal) => {\n\t\t\tawait fs.promises.writeFile(path, content, { encoding: 'utf-8', signal })\n\t\t},\n\t\tdeleteFile: async (path, signal?: AbortSignal) => {\n\t\t\ttry {\n\t\t\t\tawait fs.promises.unlink(path)\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\tmkdirp: async (path) => {\n\t\t\tawait fs.promises.mkdir(path, { recursive: true })\n\t\t},\n\t\tstoreFileChange: async (backupFileName: string, fileChange: FileChangeRecord) => {\n\t\t\tconst backupPath = path.join(backupDir, backupFileName)\n\t\t\tawait fs.promises.writeFile(backupPath, JSON.stringify(fileChange, null, 2), 'utf8')\n\t\t},\n\t\tlistBackupFiles: async () => {\n\t\t\ttry {\n\t\t\t\t// Ensure backup directory exists\n\t\t\t\tif (\n\t\t\t\t\t!(await fs.promises\n\t\t\t\t\t\t.stat(backupDir)\n\t\t\t\t\t\t.then((s) => s.isDirectory())\n\t\t\t\t\t\t.catch(() => false))\n\t\t\t\t) {\n\t\t\t\t\tawait fs.promises.mkdir(backupDir, { recursive: true })\n\t\t\t\t\treturn []\n\t\t\t\t}\n\t\t\t\treturn await fs.promises.readdir(backupDir)\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error('Error listing backup files:', error)\n\t\t\t\treturn []\n\t\t\t}\n\t\t},\n\t\tloadFileChange: async (backupFileName: string) => {\n\t\t\ttry {\n\t\t\t\tconst backupPath = path.join(backupDir, backupFileName)\n\t\t\t\tconst content = await fs.promises.readFile(backupPath, 'utf8')\n\t\t\t\treturn JSON.parse(content) as FileChangeRecord\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(`Error loading backup file ${backupFileName}:`, error)\n\t\t\t\treturn null\n\t\t\t}\n\t\t},\n\t\tcleanupBackupFiles: async () => {\n\t\t\ttry {\n\t\t\t\tif (\n\t\t\t\t\tawait fs.promises\n\t\t\t\t\t\t.stat(backupDir)\n\t\t\t\t\t\t.then((s) => s.isDirectory())\n\t\t\t\t\t\t.catch(() => false)\n\t\t\t\t) {\n\t\t\t\t\tawait fs.promises.rm(backupDir, { recursive: true, force: true })\n\t\t\t\t\tlogger.debug(`Cleaned up backup directory: ${backupDir}`)\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(`Error cleaning up backup files in ${backupDir}:`, error)\n\t\t\t}\n\t\t},\n\t\tlistFiles: async (dir: string) => listFilesGit(dir),\n\t\texclusiveWriter: false,\n\t}\n}\n\nfunction isNodeFSNotExistError(error: unknown): boolean {\n\treturn (\n\t\terror !== null &&\n\t\ttypeof error === 'object' &&\n\t\t'code' in error &&\n\t\t(error as { code: string }).code === 'ENOENT'\n\t)\n}\n\n/**\n * Lists files in a directory using git ls-files.\n * Exported for reuse by other filesystem implementations.\n */\nexport async function listFilesGit(dir: string): Promise<string[]> {\n\ttry {\n\t\tconst { stdout: trackedFiles } = await execFileAsync('git', ['ls-files'], {\n\t\t\tcwd: dir,\n\t\t})\n\n\t\tconst { stdout: untrackedFiles } = await execFileAsync(\n\t\t\t'git',\n\t\t\t['ls-files', '--others', '--exclude-standard'],\n\t\t\t{\n\t\t\t\tcwd: dir,\n\t\t\t},\n\t\t)\n\n\t\treturn [...trackedFiles.split('\\n'), ...untrackedFiles.split('\\n')].filter(Boolean)\n\t} catch {\n\t\treturn []\n\t}\n}\n"],"names":["BACKUP_DIR_NODE","join","homedir","execFileAsync","promisify","execFile","nodeFileSystem","threadID","backupDir","path","a","b","paths","signal","fs","error","isNodeFSNotExistError","FileNotExistError","content","backupFileName","fileChange","backupPath","s","logger","dir","listFilesGit","trackedFiles","untrackedFiles"],"mappings":";;;;;;;;AAGO,MAAMA,IAAkBC,EAAKC,KAAW,QAAQ,cAAc,GCO/DC,IAAgBC,EAAUC,CAAQ;AAEjC,SAASC,EAAeC,GAAgC;AAC9D,QAAMC,IAAYC,EAAK,KAAKT,GAAiBO,CAAQ;AAC9C,SAAA;AAAA,IACN,cAAc,CAACG,GAAWC,MAAcF,EAAK,SAASC,GAAGC,CAAC;AAAA,IAC1D,UAAU,IAAIC,MAAoBH,EAAK,KAAK,GAAGG,CAAK;AAAA,IAEpD,UAAU,OAAOH,GAAcI,MAAyB;AACnD,UAAA;AACI,eAAA,MAAMC,EAAG,SAAS,SAASL,GAAM,EAAE,UAAU,QAAQ,QAAAI,GAAQ;AAAA,eAC5DE,GAAO;AACX,cAAAC,EAAsBD,CAAK,IACxB,IAAIE,EAAkBR,CAAI,IAE3BM;AAAA,MAAA;AAAA,IAER;AAAA,IACA,gBAAgB,OAAON,GAAcI,MAAyB;AACzD,UAAA;AAEH,eAAO,M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Ac,OAAO,CAAC,UAAU,GAAG;AAAA,MACzE,KAAKqB;AAAA,IAAA,CACL,GAEK,EAAE,QAAQG,EAAe,IAAI,MAAMxB;AAAA,MACxC;AAAA,MACA,CAAC,YAAY,YAAY,oBAAoB;AAAA,MAC7C;AAAA,QACC,KAAKqB;AAAA,MAAA;AAAA,IAEP;AAEA,WAAO,CAAC,GAAGE,EAAa,MAAM;AAAA,CAAI,GAAG,GAAGC,EAAe,MAAM;AAAA,CAAI,CAAC,EAAE,OAAO,OAAO;AAAA,EAAA,QAC3E;AACP,WAAO,CAAC;AAAA,EAAA;AAEV;"}
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { aK as F, p as d } from "./console-DZmALLuA.js";
2
+ import { aK as F, p as d } from "./console-CDi5rFHv.js";
3
3
  const s = ({ args: n }, { dir: o, dirs: r, threadID: a, filesystem: e }) => {
4
4
  const t = F({ readFileFn: e.readFile });
5
5
  return d(
@@ -9,4 +9,4 @@ const s = ({ args: n }, { dir: o, dirs: r, threadID: a, filesystem: e }) => {
9
9
  export {
10
10
  s as nodeReadFileTool
11
11
  };
12
- //# sourceMappingURL=read_file.node-CveQp78z.js.map
12
+ //# sourceMappingURL=read_file.node-DTbjOJwN.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"read_file.node-CveQp78z.js","sources":["../../core/src/tools/builtin/filesystem/read_file.node.ts"],"sourcesContent":["import { promiseFactoryToObservable } from '@sourcegraph/observable'\nimport { type readFileToolReg } from './read_file.common'\nimport { readFileContentWith } from './read_file.util'\n\nexport const nodeReadFileTool: NonNullable<typeof readFileToolReg.fn> = (\n\t{ args },\n\t{ dir, dirs, threadID, filesystem },\n) => {\n\tconst readFileContentFn = readFileContentWith({ readFileFn: filesystem.readFile })\n\treturn promiseFactoryToObservable(async (signal) =>\n\t\treadFileContentFn({ args }, { dir, dirs, threadID, filesystem }, signal),\n\t)\n}\n"],"names":["nodeReadFileTool","args","dir","dirs","threadID","filesystem","readFileContentFn","readFileContentWith","promiseFactoryToObservable","signal"],"mappings":";;AAIa,MAAAA,IAA2D,CACvE,EAAE,MAAAC,KACF,EAAE,KAAAC,GAAK,MAAAC,GAAM,UAAAC,GAAU,YAAAC,QACnB;AACJ,QAAMC,IAAoBC,EAAoB,EAAE,YAAYF,EAAW,UAAU;AAC1E,SAAAG;AAAA,IAA2B,OAAOC,MACxCH,EAAkB,EAAE,MAAAL,EAAK,GAAG,EAAE,KAAAC,GAAK,MAAAC,GAAM,UAAAC,GAAU,YAAAC,EAAW,GAAGI,CAAM;AAAA,EACxE;AACD;"}
1
+ {"version":3,"file":"read_file.node-DTbjOJwN.js","sources":["../../core/src/tools/builtin/filesystem/read_file.node.ts"],"sourcesContent":["import { promiseFactoryToObservable } from '@sourcegraph/observable'\nimport { type readFileToolReg } from './read_file.common'\nimport { readFileContentWith } from './read_file.util'\n\nexport const nodeReadFileTool: NonNullable<typeof readFileToolReg.fn> = (\n\t{ args },\n\t{ dir, dirs, threadID, filesystem },\n) => {\n\tconst readFileContentFn = readFileContentWith({ readFileFn: filesystem.readFile })\n\treturn promiseFactoryToObservable(async (signal) =>\n\t\treadFileContentFn({ args }, { dir, dirs, threadID, filesystem }, signal),\n\t)\n}\n"],"names":["nodeReadFileTool","args","dir","dirs","threadID","filesystem","readFileContentFn","readFileContentWith","promiseFactoryToObservable","signal"],"mappings":";;AAIa,MAAAA,IAA2D,CACvE,EAAE,MAAAC,KACF,EAAE,KAAAC,GAAK,MAAAC,GAAM,UAAAC,GAAU,YAAAC,QACnB;AACJ,QAAMC,IAAoBC,EAAoB,EAAE,YAAYF,EAAW,UAAU;AAC1E,SAAAG;AAAA,IAA2B,OAAOC,MACxCH,EAAkB,EAAE,MAAAL,EAAK,GAAG,EAAE,KAAAC,GAAK,MAAAC,GAAM,UAAAC,GAAU,YAAAC,EAAW,GAAGI,CAAM;AAAA,EACxE;AACD;"}
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { a9 as ee, z as re } from "./console-DZmALLuA.js";
2
+ import { a9 as ee, z as re } from "./console-CDi5rFHv.js";
3
3
  import ne from "node:child_process";
4
4
  import D from "node:path";
5
5
  import L from "node:fs";
6
6
  import R from "node:process";
7
7
  import { PassThrough as te } from "node:stream";
8
- import { J as se } from "./main-WXbdYG4Z.js";
8
+ import { J as se } from "./main-DIn8dJ9L.js";
9
9
  var S = { exports: {} }, T, k;
10
10
  function oe() {
11
11
  if (k) return T;
@@ -464,4 +464,4 @@ export {
464
464
  $e as StdioClientTransport,
465
465
  be as getDefaultEnvironment
466
466
  };
467
- //# sourceMappingURL=stdio-CRvROLK4.js.map
467
+ //# sourceMappingURL=stdio-DuUbi3RX.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stdio-CRvROLK4.js","sources":["../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js","../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js","../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js","../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js","../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js","../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js","../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js","../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js","../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js","../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js","../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js","../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js","../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js","../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.12.0/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js","../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.12.0/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js"],"sourcesContent":["module.exports = isexe\nisexe.sync = sync\n\nvar fs = require('fs')\n\nfunction checkPathExt (path, options) {\n var pathext = options.pathExt !== undefined ?\n options.pathExt : process.env.PATHEXT\n\n if (!pathext) {\n return true\n }\n\n pathext = pathext.split(';')\n if (pathext.indexOf('') !== -1) {\n return true\n }\n for (var i = 0; i < pathext.length; i++) {\n var p = pathext[i].toLowerCase()\n if (p && path.substr(-p.length).toLowerCase() === p) {\n return true\n }\n }\n return false\n}\n\nfunction checkStat (stat, path, options) {\n if (!stat.isSymbolicLink() && !stat.isFile()) {\n return false\n }\n return checkPathExt(path, options)\n}\n\nfunction isexe (path, options, cb) {\n fs.stat(path, function (er, stat) {\n cb(er, er ? false : checkStat(stat, path, options))\n })\n}\n\nfunction sync (path, options) {\n return checkStat(fs.statSync(path), path, options)\n}\n","module.exports = isexe\nisexe.sync = sync\n\nvar fs = require('fs')\n\nfunction isexe (path, options, cb) {\n fs.stat(path, function (er, stat) {\n cb(er, er ? false : checkStat(stat, options))\n })\n}\n\nfunction sync (path, options) {\n return checkStat(fs.statSync(path), options)\n}\n\nfunction checkStat (stat, options) {\n return stat.isFile() && checkMode(stat, options)\n}\n\nfunction checkMode (stat, options) {\n var mod = stat.mode\n var uid = stat.uid\n var gid = stat.gid\n\n var myUid = options.uid !== undefined ?\n options.uid : process.getuid && process.getuid()\n var myGid = options.gid !== undefined ?\n options.gid : process.getgid && process.getgid()\n\n var u = parseInt('100', 8)\n var g = parseInt('010', 8)\n var o = parseInt('001', 8)\n var ug = u | g\n\n var ret = (mod & o) ||\n (mod & g) && gid === myGid ||\n (mod & u) && uid === myUid ||\n (mod & ug) && myUid === 0\n\n return ret\n}\n","var fs = require('fs')\nvar core\nif (process.platform === 'win32' || global.TESTING_WINDOWS) {\n core = require('./windows.js')\n} else {\n core = require('./mode.js')\n}\n\nmodule.exports = isexe\nisexe.sync = sync\n\nfunction isexe (path, options, cb) {\n if (typeof options === 'function') {\n cb = options\n options = {}\n }\n\n if (!cb) {\n if (typeof Promise !== 'function') {\n throw new TypeError('callback not provided')\n }\n\n return new Promise(function (resolve, reject) {\n isexe(path, options || {}, function (er, is) {\n if (er) {\n reject(er)\n } else {\n resolve(is)\n }\n })\n })\n }\n\n core(path, options || {}, function (er, is) {\n // ignore EACCES because that just means we aren't allowed to run it\n if (er) {\n if (er.code === 'EACCES' || options && options.ignoreErrors) {\n er = null\n is = false\n }\n }\n cb(er, is)\n })\n}\n\nfunction sync (path, options) {\n // my kingdom for a filtered catch\n try {\n return core.sync(path, options || {})\n } catch (er) {\n if (options && options.ignoreErrors || er.code === 'EACCES') {\n return false\n } else {\n throw er\n }\n }\n}\n","const isWindows = process.platform === 'win32' ||\n process.env.OSTYPE === 'cygwin' ||\n process.env.OSTYPE === 'msys'\n\nconst path = require('path')\nconst COLON = isWindows ? ';' : ':'\nconst isexe = require('isexe')\n\nconst getNotFoundError = (cmd) =>\n Object.assign(new Error(`not found: ${cmd}`), { code: 'ENOENT' })\n\nconst getPathInfo = (cmd, opt) => {\n const colon = opt.colon || COLON\n\n // If it has a slash, then we don't bother searching the pathenv.\n // just check the file itself, and that's it.\n const pathEnv = cmd.match(/\\//) || isWindows && cmd.match(/\\\\/) ? ['']\n : (\n [\n // windows always checks the cwd first\n ...(isWindows ? [process.cwd()] : []),\n ...(opt.path || process.env.PATH ||\n /* istanbul ignore next: very unusual */ '').split(colon),\n ]\n )\n const pathExtExe = isWindows\n ? opt.pathExt || process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM'\n : ''\n const pathExt = isWindows ? pathExtExe.split(colon) : ['']\n\n if (isWindows) {\n if (cmd.indexOf('.') !== -1 && pathExt[0] !== '')\n pathExt.unshift('')\n }\n\n return {\n pathEnv,\n pathExt,\n pathExtExe,\n }\n}\n\nconst which = (cmd, opt, cb) => {\n if (typeof opt === 'function') {\n cb = opt\n opt = {}\n }\n if (!opt)\n opt = {}\n\n const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt)\n const found = []\n\n const step = i => new Promise((resolve, reject) => {\n if (i === pathEnv.length)\n return opt.all && found.length ? resolve(found)\n : reject(getNotFoundError(cmd))\n\n const ppRaw = pathEnv[i]\n const pathPart = /^\".*\"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw\n\n const pCmd = path.join(pathPart, cmd)\n const p = !pathPart && /^\\.[\\\\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd\n : pCmd\n\n resolve(subStep(p, i, 0))\n })\n\n const subStep = (p, i, ii) => new Promise((resolve, reject) => {\n if (ii === pathExt.length)\n return resolve(step(i + 1))\n const ext = pathExt[ii]\n isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {\n if (!er && is) {\n if (opt.all)\n found.push(p + ext)\n else\n return resolve(p + ext)\n }\n return resolve(subStep(p, i, ii + 1))\n })\n })\n\n return cb ? step(0).then(res => cb(null, res), cb) : step(0)\n}\n\nconst whichSync = (cmd, opt) => {\n opt = opt || {}\n\n const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt)\n const found = []\n\n for (let i = 0; i < pathEnv.length; i ++) {\n const ppRaw = pathEnv[i]\n const pathPart = /^\".*\"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw\n\n const pCmd = path.join(pathPart, cmd)\n const p = !pathPart && /^\\.[\\\\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd\n : pCmd\n\n for (let j = 0; j < pathExt.length; j ++) {\n const cur = p + pathExt[j]\n try {\n const is = isexe.sync(cur, { pathExt: pathExtExe })\n if (is) {\n if (opt.all)\n found.push(cur)\n else\n return cur\n }\n } catch (ex) {}\n }\n }\n\n if (opt.all && found.length)\n return found\n\n if (opt.nothrow)\n return null\n\n throw getNotFoundError(cmd)\n}\n\nmodule.exports = which\nwhich.sync = whichSync\n","'use strict';\n\nconst pathKey = (options = {}) => {\n\tconst environment = options.env || process.env;\n\tconst platform = options.platform || process.platform;\n\n\tif (platform !== 'win32') {\n\t\treturn 'PATH';\n\t}\n\n\treturn Object.keys(environment).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path';\n};\n\nmodule.exports = pathKey;\n// TODO: Remove this for the next major release\nmodule.exports.default = pathKey;\n","'use strict';\n\nconst path = require('path');\nconst which = require('which');\nconst getPathKey = require('path-key');\n\nfunction resolveCommandAttempt(parsed, withoutPathExt) {\n const env = parsed.options.env || process.env;\n const cwd = process.cwd();\n const hasCustomCwd = parsed.options.cwd != null;\n // Worker threads do not have process.chdir()\n const shouldSwitchCwd = hasCustomCwd && process.chdir !== undefined && !process.chdir.disabled;\n\n // If a custom `cwd` was specified, we need to change the process cwd\n // because `which` will do stat calls but does not support a custom cwd\n if (shouldSwitchCwd) {\n try {\n process.chdir(parsed.options.cwd);\n } catch (err) {\n /* Empty */\n }\n }\n\n let resolved;\n\n try {\n resolved = which.sync(parsed.command, {\n path: env[getPathKey({ env })],\n pathExt: withoutPathExt ? path.delimiter : undefined,\n });\n } catch (e) {\n /* Empty */\n } finally {\n if (shouldSwitchCwd) {\n process.chdir(cwd);\n }\n }\n\n // If we successfully resolved, ensure that an absolute path is returned\n // Note that when a custom `cwd` was used, we need to resolve to an absolute path based on it\n if (resolved) {\n resolved = path.resolve(hasCustomCwd ? parsed.options.cwd : '', resolved);\n }\n\n return resolved;\n}\n\nfunction resolveCommand(parsed) {\n return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);\n}\n\nmodule.exports = resolveCommand;\n","'use strict';\n\n// See http://www.robvanderwoude.com/escapechars.php\nconst metaCharsRegExp = /([()\\][%!^\"`<>&|;, *?])/g;\n\nfunction escapeCommand(arg) {\n // Escape meta chars\n arg = arg.replace(metaCharsRegExp, '^$1');\n\n return arg;\n}\n\nfunction escapeArgument(arg, doubleEscapeMetaChars) {\n // Convert to string\n arg = `${arg}`;\n\n // Algorithm below is based on https://qntm.org/cmd\n // It's slightly altered to disable JS backtracking to avoid hanging on specially crafted input\n // Please see https://github.com/moxystudio/node-cross-spawn/pull/160 for more information\n\n // Sequence of backslashes followed by a double quote:\n // double up all the backslashes and escape the double quote\n arg = arg.replace(/(?=(\\\\+?)?)\\1\"/g, '$1$1\\\\\"');\n\n // Sequence of backslashes followed by the end of the string\n // (which will become a double quote later):\n // double up all the backslashes\n arg = arg.replace(/(?=(\\\\+?)?)\\1$/, '$1$1');\n\n // All other backslashes occur literally\n\n // Quote the whole thing:\n arg = `\"${arg}\"`;\n\n // Escape meta chars\n arg = arg.replace(metaCharsRegExp, '^$1');\n\n // Double escape meta chars if necessary\n if (doubleEscapeMetaChars) {\n arg = arg.replace(metaCharsRegExp, '^$1');\n }\n\n return arg;\n}\n\nmodule.exports.command = escapeCommand;\nmodule.exports.argument = escapeArgument;\n","'use strict';\nmodule.exports = /^#!(.*)/;\n","'use strict';\nconst shebangRegex = require('shebang-regex');\n\nmodule.exports = (string = '') => {\n\tconst match = string.match(shebangRegex);\n\n\tif (!match) {\n\t\treturn null;\n\t}\n\n\tconst [path, argument] = match[0].replace(/#! ?/, '').split(' ');\n\tconst binary = path.split('/').pop();\n\n\tif (binary === 'env') {\n\t\treturn argument;\n\t}\n\n\treturn argument ? `${binary} ${argument}` : binary;\n};\n","'use strict';\n\nconst fs = require('fs');\nconst shebangCommand = require('shebang-command');\n\nfunction readShebang(command) {\n // Read the first 150 bytes from the file\n const size = 150;\n const buffer = Buffer.alloc(size);\n\n let fd;\n\n try {\n fd = fs.openSync(command, 'r');\n fs.readSync(fd, buffer, 0, size, 0);\n fs.closeSync(fd);\n } catch (e) { /* Empty */ }\n\n // Attempt to extract shebang (null is returned if not a shebang)\n return shebangCommand(buffer.toString());\n}\n\nmodule.exports = readShebang;\n","'use strict';\n\nconst path = require('path');\nconst resolveCommand = require('./util/resolveCommand');\nconst escape = require('./util/escape');\nconst readShebang = require('./util/readShebang');\n\nconst isWin = process.platform === 'win32';\nconst isExecutableRegExp = /\\.(?:com|exe)$/i;\nconst isCmdShimRegExp = /node_modules[\\\\/].bin[\\\\/][^\\\\/]+\\.cmd$/i;\n\nfunction detectShebang(parsed) {\n parsed.file = resolveCommand(parsed);\n\n const shebang = parsed.file && readShebang(parsed.file);\n\n if (shebang) {\n parsed.args.unshift(parsed.file);\n parsed.command = shebang;\n\n return resolveCommand(parsed);\n }\n\n return parsed.file;\n}\n\nfunction parseNonShell(parsed) {\n if (!isWin) {\n return parsed;\n }\n\n // Detect & add support for shebangs\n const commandFile = detectShebang(parsed);\n\n // We don't need a shell if the command filename is an executable\n const needsShell = !isExecutableRegExp.test(commandFile);\n\n // If a shell is required, use cmd.exe and take care of escaping everything correctly\n // Note that `forceShell` is an hidden option used only in tests\n if (parsed.options.forceShell || needsShell) {\n // Need to double escape meta chars if the command is a cmd-shim located in `node_modules/.bin/`\n // The cmd-shim simply calls execute the package bin file with NodeJS, proxying any argument\n // Because the escape of metachars with ^ gets interpreted when the cmd.exe is first called,\n // we need to double escape them\n const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);\n\n // Normalize posix paths into OS compatible paths (e.g.: foo/bar -> foo\\bar)\n // This is necessary otherwise it will always fail with ENOENT in those cases\n parsed.command = path.normalize(parsed.command);\n\n // Escape command & arguments\n parsed.command = escape.command(parsed.command);\n parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));\n\n const shellCommand = [parsed.command].concat(parsed.args).join(' ');\n\n parsed.args = ['/d', '/s', '/c', `\"${shellCommand}\"`];\n parsed.command = process.env.comspec || 'cmd.exe';\n parsed.options.windowsVerbatimArguments = true; // Tell node's spawn that the arguments are already escaped\n }\n\n return parsed;\n}\n\nfunction parse(command, args, options) {\n // Normalize arguments, similar to nodejs\n if (args && !Array.isArray(args)) {\n options = args;\n args = null;\n }\n\n args = args ? args.slice(0) : []; // Clone array to avoid changing the original\n options = Object.assign({}, options); // Clone object to avoid changing the original\n\n // Build our parsed object\n const parsed = {\n command,\n args,\n options,\n file: undefined,\n original: {\n command,\n args,\n },\n };\n\n // Delegate further parsing to shell or non-shell\n return options.shell ? parsed : parseNonShell(parsed);\n}\n\nmodule.exports = parse;\n","'use strict';\n\nconst isWin = process.platform === 'win32';\n\nfunction notFoundError(original, syscall) {\n return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {\n code: 'ENOENT',\n errno: 'ENOENT',\n syscall: `${syscall} ${original.command}`,\n path: original.command,\n spawnargs: original.args,\n });\n}\n\nfunction hookChildProcess(cp, parsed) {\n if (!isWin) {\n return;\n }\n\n const originalEmit = cp.emit;\n\n cp.emit = function (name, arg1) {\n // If emitting \"exit\" event and exit code is 1, we need to check if\n // the command exists and emit an \"error\" instead\n // See https://github.com/IndigoUnited/node-cross-spawn/issues/16\n if (name === 'exit') {\n const err = verifyENOENT(arg1, parsed);\n\n if (err) {\n return originalEmit.call(cp, 'error', err);\n }\n }\n\n return originalEmit.apply(cp, arguments); // eslint-disable-line prefer-rest-params\n };\n}\n\nfunction verifyENOENT(status, parsed) {\n if (isWin && status === 1 && !parsed.file) {\n return notFoundError(parsed.original, 'spawn');\n }\n\n return null;\n}\n\nfunction verifyENOENTSync(status, parsed) {\n if (isWin && status === 1 && !parsed.file) {\n return notFoundError(parsed.original, 'spawnSync');\n }\n\n return null;\n}\n\nmodule.exports = {\n hookChildProcess,\n verifyENOENT,\n verifyENOENTSync,\n notFoundError,\n};\n","'use strict';\n\nconst cp = require('child_process');\nconst parse = require('./lib/parse');\nconst enoent = require('./lib/enoent');\n\nfunction spawn(command, args, options) {\n // Parse the arguments\n const parsed = parse(command, args, options);\n\n // Spawn the child process\n const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);\n\n // Hook into child process \"exit\" event to emit an error if the command\n // does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16\n enoent.hookChildProcess(spawned, parsed);\n\n return spawned;\n}\n\nfunction spawnSync(command, args, options) {\n // Parse the arguments\n const parsed = parse(command, args, options);\n\n // Spawn the child process\n const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);\n\n // Analyze if the command does not exist, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16\n result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);\n\n return result;\n}\n\nmodule.exports = spawn;\nmodule.exports.spawn = spawn;\nmodule.exports.sync = spawnSync;\n\nmodule.exports._parse = parse;\nmodule.exports._enoent = enoent;\n","import { JSONRPCMessageSchema } from \"../types.js\";\n/**\n * Buffers a continuous stdio stream into discrete JSON-RPC messages.\n */\nexport class ReadBuffer {\n append(chunk) {\n this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;\n }\n readMessage() {\n if (!this._buffer) {\n return null;\n }\n const index = this._buffer.indexOf(\"\\n\");\n if (index === -1) {\n return null;\n }\n const line = this._buffer.toString(\"utf8\", 0, index).replace(/\\r$/, '');\n this._buffer = this._buffer.subarray(index + 1);\n return deserializeMessage(line);\n }\n clear() {\n this._buffer = undefined;\n }\n}\nexport function deserializeMessage(line) {\n return JSONRPCMessageSchema.parse(JSON.parse(line));\n}\nexport function serializeMessage(message) {\n return JSON.stringify(message) + \"\\n\";\n}\n//# sourceMappingURL=stdio.js.map","import spawn from \"cross-spawn\";\nimport process from \"node:process\";\nimport { PassThrough } from \"node:stream\";\nimport { ReadBuffer, serializeMessage } from \"../shared/stdio.js\";\n/**\n * Environment variables to inherit by default, if an environment is not explicitly given.\n */\nexport const DEFAULT_INHERITED_ENV_VARS = process.platform === \"win32\"\n ? [\n \"APPDATA\",\n \"HOMEDRIVE\",\n \"HOMEPATH\",\n \"LOCALAPPDATA\",\n \"PATH\",\n \"PROCESSOR_ARCHITECTURE\",\n \"SYSTEMDRIVE\",\n \"SYSTEMROOT\",\n \"TEMP\",\n \"USERNAME\",\n \"USERPROFILE\",\n ]\n : /* list inspired by the default env inheritance of sudo */\n [\"HOME\", \"LOGNAME\", \"PATH\", \"SHELL\", \"TERM\", \"USER\"];\n/**\n * Returns a default environment object including only environment variables deemed safe to inherit.\n */\nexport function getDefaultEnvironment() {\n const env = {};\n for (const key of DEFAULT_INHERITED_ENV_VARS) {\n const value = process.env[key];\n if (value === undefined) {\n continue;\n }\n if (value.startsWith(\"()\")) {\n // Skip functions, which are a security risk.\n continue;\n }\n env[key] = value;\n }\n return env;\n}\n/**\n * Client transport for stdio: this will connect to a server by spawning a process and communicating with it over stdin/stdout.\n *\n * This transport is only available in Node.js environments.\n */\nexport class StdioClientTransport {\n constructor(server) {\n this._abortController = new AbortController();\n this._readBuffer = new ReadBuffer();\n this._stderrStream = null;\n this._serverParams = server;\n if (server.stderr === \"pipe\" || server.stderr === \"overlapped\") {\n this._stderrStream = new PassThrough();\n }\n }\n /**\n * Starts the server process and prepares to communicate with it.\n */\n async start() {\n if (this._process) {\n throw new Error(\"StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.\");\n }\n return new Promise((resolve, reject) => {\n var _a, _b, _c, _d, _e, _f;\n this._process = spawn(this._serverParams.command, (_a = this._serverParams.args) !== null && _a !== void 0 ? _a : [], {\n env: (_b = this._serverParams.env) !== null && _b !== void 0 ? _b : getDefaultEnvironment(),\n stdio: [\"pipe\", \"pipe\", (_c = this._serverParams.stderr) !== null && _c !== void 0 ? _c : \"inherit\"],\n shell: false,\n signal: this._abortController.signal,\n windowsHide: process.platform === \"win32\" && isElectron(),\n cwd: this._serverParams.cwd,\n });\n this._process.on(\"error\", (error) => {\n var _a, _b;\n if (error.name === \"AbortError\") {\n // Expected when close() is called.\n (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);\n return;\n }\n reject(error);\n (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);\n });\n this._process.on(\"spawn\", () => {\n resolve();\n });\n this._process.on(\"close\", (_code) => {\n var _a;\n this._process = undefined;\n (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);\n });\n (_d = this._process.stdin) === null || _d === void 0 ? void 0 : _d.on(\"error\", (error) => {\n var _a;\n (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);\n });\n (_e = this._process.stdout) === null || _e === void 0 ? void 0 : _e.on(\"data\", (chunk) => {\n this._readBuffer.append(chunk);\n this.processReadBuffer();\n });\n (_f = this._process.stdout) === null || _f === void 0 ? void 0 : _f.on(\"error\", (error) => {\n var _a;\n (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);\n });\n if (this._stderrStream && this._process.stderr) {\n this._process.stderr.pipe(this._stderrStream);\n }\n });\n }\n /**\n * The stderr stream of the child process, if `StdioServerParameters.stderr` was set to \"pipe\" or \"overlapped\".\n *\n * If stderr piping was requested, a PassThrough stream is returned _immediately_, allowing callers to\n * attach listeners before the start method is invoked. This prevents loss of any early\n * error output emitted by the child process.\n */\n get stderr() {\n var _a, _b;\n if (this._stderrStream) {\n return this._stderrStream;\n }\n return (_b = (_a = this._process) === null || _a === void 0 ? void 0 : _a.stderr) !== null && _b !== void 0 ? _b : null;\n }\n processReadBuffer() {\n var _a, _b;\n while (true) {\n try {\n const message = this._readBuffer.readMessage();\n if (message === null) {\n break;\n }\n (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);\n }\n catch (error) {\n (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);\n }\n }\n }\n async close() {\n this._abortController.abort();\n this._process = undefined;\n this._readBuffer.clear();\n }\n send(message) {\n return new Promise((resolve) => {\n var _a;\n if (!((_a = this._process) === null || _a === void 0 ? void 0 : _a.stdin)) {\n throw new Error(\"Not connected\");\n }\n const json = serializeMessage(message);\n if (this._process.stdin.write(json)) {\n resolve();\n }\n else {\n this._process.stdin.once(\"drain\", resolve);\n }\n });\n }\n}\nfunction isElectron() {\n return \"type\" in process;\n}\n//# sourceMappingURL=stdio.js.map"],"names":["windows","isexe","sync","fs","require$$0","checkPathExt","path","options","pathext","p","checkStat","stat","cb","er","mode","checkMode","mod","uid","gid","myUid","myGid","u","g","o","ug","ret","core","global","require$$1","require$$2","isexe_1","resolve","reject","is","isWindows","COLON","getNotFoundError","cmd","getPathInfo","opt","colon","pathEnv","pathExtExe","pathExt","which","found","step","i","ppRaw","pathPart","pCmd","subStep","ii","ext","res","whichSync","j","cur","which_1","pathKey","environment","key","pathKeyModule","getPathKey","resolveCommandAttempt","parsed","withoutPathExt","env","cwd","hasCustomCwd","shouldSwitchCwd","resolved","resolveCommand","resolveCommand_1","metaCharsRegExp","escapeCommand","arg","escapeArgument","doubleEscapeMetaChars","_escape","shebangRegex","shebangCommand","string","match","argument","binary","readShebang","command","buffer","fd","readShebang_1","escape","require$$3","isWin","isExecutableRegExp","isCmdShimRegExp","detectShebang","shebang","parseNonShell","commandFile","needsShell","needsDoubleEscapeMetaChars","shellCommand","parse","args","parse_1","notFoundError","original","syscall","hookChildProcess","cp","originalEmit","name","arg1","err","verifyENOENT","status","verifyENOENTSync","enoent","spawn","spawned","spawnSync","result","crossSpawnModule","ReadBuffer","chunk","index","line","deserializeMessage","JSONRPCMessageSchema","serializeMessage","message","DEFAULT_INHERITED_ENV_VARS","process","getDefaultEnvironment","value","StdioClientTransport","server","PassThrough","_a","_b","_c","_d","_e","_f","isElectron","error","_code","json"],"mappings":";;;;;;;;;;;SAAAA,IAAiBC,GACjBA,EAAM,OAAOC;AAEb,MAAIC,IAAKC;AAET,WAASC,EAAcC,GAAMC,GAAS;AACpC,QAAIC,IAAUD,EAAQ,YAAY,SAChCA,EAAQ,UAAU,QAAQ,IAAI;AAOhC,QALI,CAACC,MAILA,IAAUA,EAAQ,MAAM,GAAG,GACvBA,EAAQ,QAAQ,EAAE,MAAM;AAC1B,aAAO;AAET,aAAS,IAAI,GAAG,IAAIA,EAAQ,QAAQ,KAAK;AACvC,UAAIC,IAAID,EAAQ,CAAC,EAAE,YAAW;AAC9B,UAAIC,KAAKH,EAAK,OAAO,CAACG,EAAE,MAAM,EAAE,YAAa,MAAKA;AAChD,eAAO;AAAA,IAEb;AACE,WAAO;AAAA,EACT;AAEA,WAASC,EAAWC,GAAML,GAAMC,GAAS;AACvC,WAAI,CAACI,EAAK,eAAc,KAAM,CAACA,EAA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K,KAAK,aAAa,QAAQA,MAAO,UAAkBA,EAAG,KAAK,MAAMM,CAAK;AAAA,MAC5F;AAAA,EAEA;AAAA,EACI,MAAM,QAAQ;AACV,SAAK,iBAAiB,MAAO,GAC7B,KAAK,WAAW,QAChB,KAAK,YAAY,MAAO;AAAA,EAChC;AAAA,EACI,KAAKf,GAAS;AACV,WAAO,IAAI,QAAQ,CAACpG,MAAY;AAC5B,UAAI4G;AACJ,UAAI,EAAG,GAAAA,IAAK,KAAK,cAAc,QAAQA,MAAO,WAAkBA,EAAG;AAC/D,cAAM,IAAI,MAAM,eAAe;AAEnC,YAAMS,IAAOlB,GAAiBC,CAAO;AACrC,MAAI,KAAK,SAAS,MAAM,MAAMiB,CAAI,IAC9BrH,EAAS,IAGT,KAAK,SAAS,MAAM,KAAK,SAASA,CAAO;AAAA,IAEzD,CAAS;AAAA,EACT;AACA;AACA,SAASkH,KAAa;AAClB,SAAO,UAAUZ;AACrB;","x_google_ignoreList":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]}
1
+ {"version":3,"file":"stdio-DuUbi3RX.js","sources":["../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js","../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js","../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js","../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js","../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js","../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js","../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js","../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js","../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js","../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js","../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js","../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js","../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js","../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.12.0/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js","../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.12.0/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js"],"sourcesContent":["module.exports = isexe\nisexe.sync = sync\n\nvar fs = require('fs')\n\nfunction checkPathExt (path, options) {\n var pathext = options.pathExt !== undefined ?\n options.pathExt : process.env.PATHEXT\n\n if (!pathext) {\n return true\n }\n\n pathext = pathext.split(';')\n if (pathext.indexOf('') !== -1) {\n return true\n }\n for (var i = 0; i < pathext.length; i++) {\n var p = pathext[i].toLowerCase()\n if (p && path.substr(-p.length).toLowerCase() === p) {\n return true\n }\n }\n return false\n}\n\nfunction checkStat (stat, path, options) {\n if (!stat.isSymbolicLink() && !stat.isFile()) {\n return false\n }\n return checkPathExt(path, options)\n}\n\nfunction isexe (path, options, cb) {\n fs.stat(path, function (er, stat) {\n cb(er, er ? false : checkStat(stat, path, options))\n })\n}\n\nfunction sync (path, options) {\n return checkStat(fs.statSync(path), path, options)\n}\n","module.exports = isexe\nisexe.sync = sync\n\nvar fs = require('fs')\n\nfunction isexe (path, options, cb) {\n fs.stat(path, function (er, stat) {\n cb(er, er ? false : checkStat(stat, options))\n })\n}\n\nfunction sync (path, options) {\n return checkStat(fs.statSync(path), options)\n}\n\nfunction checkStat (stat, options) {\n return stat.isFile() && checkMode(stat, options)\n}\n\nfunction checkMode (stat, options) {\n var mod = stat.mode\n var uid = stat.uid\n var gid = stat.gid\n\n var myUid = options.uid !== undefined ?\n options.uid : process.getuid && process.getuid()\n var myGid = options.gid !== undefined ?\n options.gid : process.getgid && process.getgid()\n\n var u = parseInt('100', 8)\n var g = parseInt('010', 8)\n var o = parseInt('001', 8)\n var ug = u | g\n\n var ret = (mod & o) ||\n (mod & g) && gid === myGid ||\n (mod & u) && uid === myUid ||\n (mod & ug) && myUid === 0\n\n return ret\n}\n","var fs = require('fs')\nvar core\nif (process.platform === 'win32' || global.TESTING_WINDOWS) {\n core = require('./windows.js')\n} else {\n core = require('./mode.js')\n}\n\nmodule.exports = isexe\nisexe.sync = sync\n\nfunction isexe (path, options, cb) {\n if (typeof options === 'function') {\n cb = options\n options = {}\n }\n\n if (!cb) {\n if (typeof Promise !== 'function') {\n throw new TypeError('callback not provided')\n }\n\n return new Promise(function (resolve, reject) {\n isexe(path, options || {}, function (er, is) {\n if (er) {\n reject(er)\n } else {\n resolve(is)\n }\n })\n })\n }\n\n core(path, options || {}, function (er, is) {\n // ignore EACCES because that just means we aren't allowed to run it\n if (er) {\n if (er.code === 'EACCES' || options && options.ignoreErrors) {\n er = null\n is = false\n }\n }\n cb(er, is)\n })\n}\n\nfunction sync (path, options) {\n // my kingdom for a filtered catch\n try {\n return core.sync(path, options || {})\n } catch (er) {\n if (options && options.ignoreErrors || er.code === 'EACCES') {\n return false\n } else {\n throw er\n }\n }\n}\n","const isWindows = process.platform === 'win32' ||\n process.env.OSTYPE === 'cygwin' ||\n process.env.OSTYPE === 'msys'\n\nconst path = require('path')\nconst COLON = isWindows ? ';' : ':'\nconst isexe = require('isexe')\n\nconst getNotFoundError = (cmd) =>\n Object.assign(new Error(`not found: ${cmd}`), { code: 'ENOENT' })\n\nconst getPathInfo = (cmd, opt) => {\n const colon = opt.colon || COLON\n\n // If it has a slash, then we don't bother searching the pathenv.\n // just check the file itself, and that's it.\n const pathEnv = cmd.match(/\\//) || isWindows && cmd.match(/\\\\/) ? ['']\n : (\n [\n // windows always checks the cwd first\n ...(isWindows ? [process.cwd()] : []),\n ...(opt.path || process.env.PATH ||\n /* istanbul ignore next: very unusual */ '').split(colon),\n ]\n )\n const pathExtExe = isWindows\n ? opt.pathExt || process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM'\n : ''\n const pathExt = isWindows ? pathExtExe.split(colon) : ['']\n\n if (isWindows) {\n if (cmd.indexOf('.') !== -1 && pathExt[0] !== '')\n pathExt.unshift('')\n }\n\n return {\n pathEnv,\n pathExt,\n pathExtExe,\n }\n}\n\nconst which = (cmd, opt, cb) => {\n if (typeof opt === 'function') {\n cb = opt\n opt = {}\n }\n if (!opt)\n opt = {}\n\n const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt)\n const found = []\n\n const step = i => new Promise((resolve, reject) => {\n if (i === pathEnv.length)\n return opt.all && found.length ? resolve(found)\n : reject(getNotFoundError(cmd))\n\n const ppRaw = pathEnv[i]\n const pathPart = /^\".*\"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw\n\n const pCmd = path.join(pathPart, cmd)\n const p = !pathPart && /^\\.[\\\\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd\n : pCmd\n\n resolve(subStep(p, i, 0))\n })\n\n const subStep = (p, i, ii) => new Promise((resolve, reject) => {\n if (ii === pathExt.length)\n return resolve(step(i + 1))\n const ext = pathExt[ii]\n isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {\n if (!er && is) {\n if (opt.all)\n found.push(p + ext)\n else\n return resolve(p + ext)\n }\n return resolve(subStep(p, i, ii + 1))\n })\n })\n\n return cb ? step(0).then(res => cb(null, res), cb) : step(0)\n}\n\nconst whichSync = (cmd, opt) => {\n opt = opt || {}\n\n const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt)\n const found = []\n\n for (let i = 0; i < pathEnv.length; i ++) {\n const ppRaw = pathEnv[i]\n const pathPart = /^\".*\"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw\n\n const pCmd = path.join(pathPart, cmd)\n const p = !pathPart && /^\\.[\\\\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd\n : pCmd\n\n for (let j = 0; j < pathExt.length; j ++) {\n const cur = p + pathExt[j]\n try {\n const is = isexe.sync(cur, { pathExt: pathExtExe })\n if (is) {\n if (opt.all)\n found.push(cur)\n else\n return cur\n }\n } catch (ex) {}\n }\n }\n\n if (opt.all && found.length)\n return found\n\n if (opt.nothrow)\n return null\n\n throw getNotFoundError(cmd)\n}\n\nmodule.exports = which\nwhich.sync = whichSync\n","'use strict';\n\nconst pathKey = (options = {}) => {\n\tconst environment = options.env || process.env;\n\tconst platform = options.platform || process.platform;\n\n\tif (platform !== 'win32') {\n\t\treturn 'PATH';\n\t}\n\n\treturn Object.keys(environment).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path';\n};\n\nmodule.exports = pathKey;\n// TODO: Remove this for the next major release\nmodule.exports.default = pathKey;\n","'use strict';\n\nconst path = require('path');\nconst which = require('which');\nconst getPathKey = require('path-key');\n\nfunction resolveCommandAttempt(parsed, withoutPathExt) {\n const env = parsed.options.env || process.env;\n const cwd = process.cwd();\n const hasCustomCwd = parsed.options.cwd != null;\n // Worker threads do not have process.chdir()\n const shouldSwitchCwd = hasCustomCwd && process.chdir !== undefined && !process.chdir.disabled;\n\n // If a custom `cwd` was specified, we need to change the process cwd\n // because `which` will do stat calls but does not support a custom cwd\n if (shouldSwitchCwd) {\n try {\n process.chdir(parsed.options.cwd);\n } catch (err) {\n /* Empty */\n }\n }\n\n let resolved;\n\n try {\n resolved = which.sync(parsed.command, {\n path: env[getPathKey({ env })],\n pathExt: withoutPathExt ? path.delimiter : undefined,\n });\n } catch (e) {\n /* Empty */\n } finally {\n if (shouldSwitchCwd) {\n process.chdir(cwd);\n }\n }\n\n // If we successfully resolved, ensure that an absolute path is returned\n // Note that when a custom `cwd` was used, we need to resolve to an absolute path based on it\n if (resolved) {\n resolved = path.resolve(hasCustomCwd ? parsed.options.cwd : '', resolved);\n }\n\n return resolved;\n}\n\nfunction resolveCommand(parsed) {\n return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);\n}\n\nmodule.exports = resolveCommand;\n","'use strict';\n\n// See http://www.robvanderwoude.com/escapechars.php\nconst metaCharsRegExp = /([()\\][%!^\"`<>&|;, *?])/g;\n\nfunction escapeCommand(arg) {\n // Escape meta chars\n arg = arg.replace(metaCharsRegExp, '^$1');\n\n return arg;\n}\n\nfunction escapeArgument(arg, doubleEscapeMetaChars) {\n // Convert to string\n arg = `${arg}`;\n\n // Algorithm below is based on https://qntm.org/cmd\n // It's slightly altered to disable JS backtracking to avoid hanging on specially crafted input\n // Please see https://github.com/moxystudio/node-cross-spawn/pull/160 for more information\n\n // Sequence of backslashes followed by a double quote:\n // double up all the backslashes and escape the double quote\n arg = arg.replace(/(?=(\\\\+?)?)\\1\"/g, '$1$1\\\\\"');\n\n // Sequence of backslashes followed by the end of the string\n // (which will become a double quote later):\n // double up all the backslashes\n arg = arg.replace(/(?=(\\\\+?)?)\\1$/, '$1$1');\n\n // All other backslashes occur literally\n\n // Quote the whole thing:\n arg = `\"${arg}\"`;\n\n // Escape meta chars\n arg = arg.replace(metaCharsRegExp, '^$1');\n\n // Double escape meta chars if necessary\n if (doubleEscapeMetaChars) {\n arg = arg.replace(metaCharsRegExp, '^$1');\n }\n\n return arg;\n}\n\nmodule.exports.command = escapeCommand;\nmodule.exports.argument = escapeArgument;\n","'use strict';\nmodule.exports = /^#!(.*)/;\n","'use strict';\nconst shebangRegex = require('shebang-regex');\n\nmodule.exports = (string = '') => {\n\tconst match = string.match(shebangRegex);\n\n\tif (!match) {\n\t\treturn null;\n\t}\n\n\tconst [path, argument] = match[0].replace(/#! ?/, '').split(' ');\n\tconst binary = path.split('/').pop();\n\n\tif (binary === 'env') {\n\t\treturn argument;\n\t}\n\n\treturn argument ? `${binary} ${argument}` : binary;\n};\n","'use strict';\n\nconst fs = require('fs');\nconst shebangCommand = require('shebang-command');\n\nfunction readShebang(command) {\n // Read the first 150 bytes from the file\n const size = 150;\n const buffer = Buffer.alloc(size);\n\n let fd;\n\n try {\n fd = fs.openSync(command, 'r');\n fs.readSync(fd, buffer, 0, size, 0);\n fs.closeSync(fd);\n } catch (e) { /* Empty */ }\n\n // Attempt to extract shebang (null is returned if not a shebang)\n return shebangCommand(buffer.toString());\n}\n\nmodule.exports = readShebang;\n","'use strict';\n\nconst path = require('path');\nconst resolveCommand = require('./util/resolveCommand');\nconst escape = require('./util/escape');\nconst readShebang = require('./util/readShebang');\n\nconst isWin = process.platform === 'win32';\nconst isExecutableRegExp = /\\.(?:com|exe)$/i;\nconst isCmdShimRegExp = /node_modules[\\\\/].bin[\\\\/][^\\\\/]+\\.cmd$/i;\n\nfunction detectShebang(parsed) {\n parsed.file = resolveCommand(parsed);\n\n const shebang = parsed.file && readShebang(parsed.file);\n\n if (shebang) {\n parsed.args.unshift(parsed.file);\n parsed.command = shebang;\n\n return resolveCommand(parsed);\n }\n\n return parsed.file;\n}\n\nfunction parseNonShell(parsed) {\n if (!isWin) {\n return parsed;\n }\n\n // Detect & add support for shebangs\n const commandFile = detectShebang(parsed);\n\n // We don't need a shell if the command filename is an executable\n const needsShell = !isExecutableRegExp.test(commandFile);\n\n // If a shell is required, use cmd.exe and take care of escaping everything correctly\n // Note that `forceShell` is an hidden option used only in tests\n if (parsed.options.forceShell || needsShell) {\n // Need to double escape meta chars if the command is a cmd-shim located in `node_modules/.bin/`\n // The cmd-shim simply calls execute the package bin file with NodeJS, proxying any argument\n // Because the escape of metachars with ^ gets interpreted when the cmd.exe is first called,\n // we need to double escape them\n const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);\n\n // Normalize posix paths into OS compatible paths (e.g.: foo/bar -> foo\\bar)\n // This is necessary otherwise it will always fail with ENOENT in those cases\n parsed.command = path.normalize(parsed.command);\n\n // Escape command & arguments\n parsed.command = escape.command(parsed.command);\n parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));\n\n const shellCommand = [parsed.command].concat(parsed.args).join(' ');\n\n parsed.args = ['/d', '/s', '/c', `\"${shellCommand}\"`];\n parsed.command = process.env.comspec || 'cmd.exe';\n parsed.options.windowsVerbatimArguments = true; // Tell node's spawn that the arguments are already escaped\n }\n\n return parsed;\n}\n\nfunction parse(command, args, options) {\n // Normalize arguments, similar to nodejs\n if (args && !Array.isArray(args)) {\n options = args;\n args = null;\n }\n\n args = args ? args.slice(0) : []; // Clone array to avoid changing the original\n options = Object.assign({}, options); // Clone object to avoid changing the original\n\n // Build our parsed object\n const parsed = {\n command,\n args,\n options,\n file: undefined,\n original: {\n command,\n args,\n },\n };\n\n // Delegate further parsing to shell or non-shell\n return options.shell ? parsed : parseNonShell(parsed);\n}\n\nmodule.exports = parse;\n","'use strict';\n\nconst isWin = process.platform === 'win32';\n\nfunction notFoundError(original, syscall) {\n return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {\n code: 'ENOENT',\n errno: 'ENOENT',\n syscall: `${syscall} ${original.command}`,\n path: original.command,\n spawnargs: original.args,\n });\n}\n\nfunction hookChildProcess(cp, parsed) {\n if (!isWin) {\n return;\n }\n\n const originalEmit = cp.emit;\n\n cp.emit = function (name, arg1) {\n // If emitting \"exit\" event and exit code is 1, we need to check if\n // the command exists and emit an \"error\" instead\n // See https://github.com/IndigoUnited/node-cross-spawn/issues/16\n if (name === 'exit') {\n const err = verifyENOENT(arg1, parsed);\n\n if (err) {\n return originalEmit.call(cp, 'error', err);\n }\n }\n\n return originalEmit.apply(cp, arguments); // eslint-disable-line prefer-rest-params\n };\n}\n\nfunction verifyENOENT(status, parsed) {\n if (isWin && status === 1 && !parsed.file) {\n return notFoundError(parsed.original, 'spawn');\n }\n\n return null;\n}\n\nfunction verifyENOENTSync(status, parsed) {\n if (isWin && status === 1 && !parsed.file) {\n return notFoundError(parsed.original, 'spawnSync');\n }\n\n return null;\n}\n\nmodule.exports = {\n hookChildProcess,\n verifyENOENT,\n verifyENOENTSync,\n notFoundError,\n};\n","'use strict';\n\nconst cp = require('child_process');\nconst parse = require('./lib/parse');\nconst enoent = require('./lib/enoent');\n\nfunction spawn(command, args, options) {\n // Parse the arguments\n const parsed = parse(command, args, options);\n\n // Spawn the child process\n const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);\n\n // Hook into child process \"exit\" event to emit an error if the command\n // does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16\n enoent.hookChildProcess(spawned, parsed);\n\n return spawned;\n}\n\nfunction spawnSync(command, args, options) {\n // Parse the arguments\n const parsed = parse(command, args, options);\n\n // Spawn the child process\n const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);\n\n // Analyze if the command does not exist, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16\n result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);\n\n return result;\n}\n\nmodule.exports = spawn;\nmodule.exports.spawn = spawn;\nmodule.exports.sync = spawnSync;\n\nmodule.exports._parse = parse;\nmodule.exports._enoent = enoent;\n","import { JSONRPCMessageSchema } from \"../types.js\";\n/**\n * Buffers a continuous stdio stream into discrete JSON-RPC messages.\n */\nexport class ReadBuffer {\n append(chunk) {\n this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;\n }\n readMessage() {\n if (!this._buffer) {\n return null;\n }\n const index = this._buffer.indexOf(\"\\n\");\n if (index === -1) {\n return null;\n }\n const line = this._buffer.toString(\"utf8\", 0, index).replace(/\\r$/, '');\n this._buffer = this._buffer.subarray(index + 1);\n return deserializeMessage(line);\n }\n clear() {\n this._buffer = undefined;\n }\n}\nexport function deserializeMessage(line) {\n return JSONRPCMessageSchema.parse(JSON.parse(line));\n}\nexport function serializeMessage(message) {\n return JSON.stringify(message) + \"\\n\";\n}\n//# sourceMappingURL=stdio.js.map","import spawn from \"cross-spawn\";\nimport process from \"node:process\";\nimport { PassThrough } from \"node:stream\";\nimport { ReadBuffer, serializeMessage } from \"../shared/stdio.js\";\n/**\n * Environment variables to inherit by default, if an environment is not explicitly given.\n */\nexport const DEFAULT_INHERITED_ENV_VARS = process.platform === \"win32\"\n ? [\n \"APPDATA\",\n \"HOMEDRIVE\",\n \"HOMEPATH\",\n \"LOCALAPPDATA\",\n \"PATH\",\n \"PROCESSOR_ARCHITECTURE\",\n \"SYSTEMDRIVE\",\n \"SYSTEMROOT\",\n \"TEMP\",\n \"USERNAME\",\n \"USERPROFILE\",\n ]\n : /* list inspired by the default env inheritance of sudo */\n [\"HOME\", \"LOGNAME\", \"PATH\", \"SHELL\", \"TERM\", \"USER\"];\n/**\n * Returns a default environment object including only environment variables deemed safe to inherit.\n */\nexport function getDefaultEnvironment() {\n const env = {};\n for (const key of DEFAULT_INHERITED_ENV_VARS) {\n const value = process.env[key];\n if (value === undefined) {\n continue;\n }\n if (value.startsWith(\"()\")) {\n // Skip functions, which are a security risk.\n continue;\n }\n env[key] = value;\n }\n return env;\n}\n/**\n * Client transport for stdio: this will connect to a server by spawning a process and communicating with it over stdin/stdout.\n *\n * This transport is only available in Node.js environments.\n */\nexport class StdioClientTransport {\n constructor(server) {\n this._abortController = new AbortController();\n this._readBuffer = new ReadBuffer();\n this._stderrStream = null;\n this._serverParams = server;\n if (server.stderr === \"pipe\" || server.stderr === \"overlapped\") {\n this._stderrStream = new PassThrough();\n }\n }\n /**\n * Starts the server process and prepares to communicate with it.\n */\n async start() {\n if (this._process) {\n throw new Error(\"StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.\");\n }\n return new Promise((resolve, reject) => {\n var _a, _b, _c, _d, _e, _f;\n this._process = spawn(this._serverParams.command, (_a = this._serverParams.args) !== null && _a !== void 0 ? _a : [], {\n env: (_b = this._serverParams.env) !== null && _b !== void 0 ? _b : getDefaultEnvironment(),\n stdio: [\"pipe\", \"pipe\", (_c = this._serverParams.stderr) !== null && _c !== void 0 ? _c : \"inherit\"],\n shell: false,\n signal: this._abortController.signal,\n windowsHide: process.platform === \"win32\" && isElectron(),\n cwd: this._serverParams.cwd,\n });\n this._process.on(\"error\", (error) => {\n var _a, _b;\n if (error.name === \"AbortError\") {\n // Expected when close() is called.\n (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);\n return;\n }\n reject(error);\n (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);\n });\n this._process.on(\"spawn\", () => {\n resolve();\n });\n this._process.on(\"close\", (_code) => {\n var _a;\n this._process = undefined;\n (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);\n });\n (_d = this._process.stdin) === null || _d === void 0 ? void 0 : _d.on(\"error\", (error) => {\n var _a;\n (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);\n });\n (_e = this._process.stdout) === null || _e === void 0 ? void 0 : _e.on(\"data\", (chunk) => {\n this._readBuffer.append(chunk);\n this.processReadBuffer();\n });\n (_f = this._process.stdout) === null || _f === void 0 ? void 0 : _f.on(\"error\", (error) => {\n var _a;\n (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);\n });\n if (this._stderrStream && this._process.stderr) {\n this._process.stderr.pipe(this._stderrStream);\n }\n });\n }\n /**\n * The stderr stream of the child process, if `StdioServerParameters.stderr` was set to \"pipe\" or \"overlapped\".\n *\n * If stderr piping was requested, a PassThrough stream is returned _immediately_, allowing callers to\n * attach listeners before the start method is invoked. This prevents loss of any early\n * error output emitted by the child process.\n */\n get stderr() {\n var _a, _b;\n if (this._stderrStream) {\n return this._stderrStream;\n }\n return (_b = (_a = this._process) === null || _a === void 0 ? void 0 : _a.stderr) !== null && _b !== void 0 ? _b : null;\n }\n processReadBuffer() {\n var _a, _b;\n while (true) {\n try {\n const message = this._readBuffer.readMessage();\n if (message === null) {\n break;\n }\n (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);\n }\n catch (error) {\n (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);\n }\n }\n }\n async close() {\n this._abortController.abort();\n this._process = undefined;\n this._readBuffer.clear();\n }\n send(message) {\n return new Promise((resolve) => {\n var _a;\n if (!((_a = this._process) === null || _a === void 0 ? void 0 : _a.stdin)) {\n throw new Error(\"Not connected\");\n }\n const json = serializeMessage(message);\n if (this._process.stdin.write(json)) {\n resolve();\n }\n else {\n this._process.stdin.once(\"drain\", resolve);\n }\n });\n }\n}\nfunction isElectron() {\n return \"type\" in process;\n}\n//# sourceMappingURL=stdio.js.map"],"names":["windows","isexe","sync","fs","require$$0","checkPathExt","path","options","pathext","p","checkStat","stat","cb","er","mode","checkMode","mod","uid","gid","myUid","myGid","u","g","o","ug","ret","core","global","require$$1","require$$2","isexe_1","resolve","reject","is","isWindows","COLON","getNotFoundError","cmd","getPathInfo","opt","colon","pathEnv","pathExtExe","pathExt","which","found","step","i","ppRaw","pathPart","pCmd","subStep","ii","ext","res","whichSync","j","cur","which_1","pathKey","environment","key","pathKeyModule","getPathKey","resolveCommandAttempt","parsed","withoutPathExt","env","cwd","hasCustomCwd","shouldSwitchCwd","resolved","resolveCommand","resolveCommand_1","metaCharsRegExp","escapeCommand","arg","escapeArgument","doubleEscapeMetaChars","_escape","shebangRegex","shebangCommand","string","match","argument","binary","readShebang","command","buffer","fd","readShebang_1","escape","require$$3","isWin","isExecutableRegExp","isCmdShimRegExp","detectShebang","shebang","parseNonShell","commandFile","needsShell","needsDoubleEscapeMetaChars","shellCommand","parse","args","parse_1","notFoundError","original","syscall","hookChildProcess","cp","originalEmit","name","arg1","err","verifyENOENT","status","verifyENOENTSync","enoent","spawn","spawned","spawnSync","result","crossSpawnModule","ReadBuffer","chunk","index","line","deserializeMessage","JSONRPCMessageSchema","serializeMessage","message","DEFAULT_INHERITED_ENV_VARS","process","getDefaultEnvironment","value","StdioClientTransport","server","PassThrough","_a","_b","_c","_d","_e","_f","isElectron","error","_code","json"],"mappings":";;;;;;;;;;;SAAAA,IAAiBC,GACjBA,EAAM,OAAOC;AAEb,MAAIC,IAAKC;AAET,WAASC,EAAcC,GAAMC,GAAS;AACpC,QAAIC,IAAUD,EAAQ,YAAY,SAChCA,EAAQ,UAAU,QAAQ,IAAI;AAOhC,QALI,CAACC,MAILA,IAAUA,EAAQ,MAAM,GAAG,GACvBA,EAAQ,QAAQ,EAAE,MAAM;AAC1B,aAAO;AAET,aAAS,IAAI,GAAG,IAAIA,EAAQ,QAAQ,KAAK;AACvC,UAAIC,IAAID,EAAQ,CAAC,EAA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B,aADID,GAAIC;AAEJ,UAAI;AACA,cAAMT,IAAU,KAAK,YAAY,YAAa;AAC9C,YAAIA,MAAY;AACZ;AAEJ,SAACQ,IAAK,KAAK,eAAe,QAAQA,MAAO,UAAkBA,EAAG,KAAK,MAAMR,CAAO;AAAA,MAChG,SACmBe,GAAO;AACV,SAACN,IAAK,KAAK,aAAa,QAAQA,MAAO,UAAkBA,EAAG,KAAK,MAAMM,CAAK;AAAA,MAC5F;AAAA,EAEA;AAAA,EACI,MAAM,QAAQ;AACV,SAAK,iBAAiB,MAAO,GAC7B,KAAK,WAAW,QAChB,KAAK,YAAY,MAAO;AAAA,EAChC;AAAA,EACI,KAAKf,GAAS;AACV,WAAO,IAAI,QAAQ,CAACpG,MAAY;AAC5B,UAAI4G;AACJ,UAAI,EAAG,GAAAA,IAAK,KAAK,cAAc,QAAQA,MAAO,WAAkBA,EAAG;AAC/D,cAAM,IAAI,MAAM,eAAe;AAEnC,YAAMS,IAAOlB,GAAiBC,CAAO;AACrC,MAAI,KAAK,SAAS,MAAM,MAAMiB,CAAI,IAC9BrH,EAAS,IAGT,KAAK,SAAS,MAAM,KAAK,SAASA,CAAO;AAAA,IAEzD,CAAS;AAAA,EACT;AACA;AACA,SAASkH,KAAa;AAClB,SAAO,UAAUZ;AACrB;","x_google_ignoreList":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]}
package/dist/storybook.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { av as r, aA as a, an as c, aB as d, at as f, au as x, af as b, as as I } from "./console-DZmALLuA.js";
2
+ import { av as r, aA as a, an as c, aB as d, at as f, au as x, af as b, as as I } from "./console-CDi5rFHv.js";
3
3
  import { stdout as s } from "node:process";
4
4
  import { parseArgs as w } from "node:util";
5
5
  function D() {
@@ -3,7 +3,7 @@ import E from "node:crypto";
3
3
  import d, { writeFile as D } from "node:fs/promises";
4
4
  import g from "node:os";
5
5
  import a from "node:path";
6
- import { C as p, p as C, aC as F, aL as b, aM as _ } from "./console-DZmALLuA.js";
6
+ import { C as p, p as C, aC as F, aL as b, aM as _ } from "./console-CDi5rFHv.js";
7
7
  class v {
8
8
  MAX_TRACKED_EDITS = 50;
9
9
  editQueue = [];
@@ -99,4 +99,4 @@ export {
99
99
  A as nodeUndoEditTool,
100
100
  N as recordEdit
101
101
  };
102
- //# sourceMappingURL=undo_edit.node-C3I02TEE.js.map
102
+ //# sourceMappingURL=undo_edit.node-qujh3sgI.js.map