@sourcegraph/amp 0.0.1749254507-g977549 → 0.0.1749256326-gf8b1cf

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 +1 -2
  2. package/dist/client-D82aFqMl.js +0 -1
  3. package/dist/console-RPzEsLY0.js +0 -1
  4. package/dist/create_file.node-Dg6SfP0E.js +0 -1
  5. package/dist/edit_file.node-DOTivrdL.js +0 -1
  6. package/dist/executable-Cvv6G9ik.js +0 -1
  7. package/dist/files-DrSncnX3.js +0 -1
  8. package/dist/fuzzy-server.js +0 -1
  9. package/dist/glob.node-Betywdle.js +0 -1
  10. package/dist/index-C1JH-cfZ.js +0 -1
  11. package/dist/list_directory.node-B8bOIV1q.js +0 -1
  12. package/dist/load-profile-CgexvkzB.js +0 -1
  13. package/dist/{main-CSw2Cx-a.js → main-8KUolY-x.js} +10 -11
  14. package/dist/node-BIJw0rpH.js +0 -1
  15. package/dist/{node-CaahOEeV.js → node-BSnweH9G.js} +1 -2
  16. package/dist/node-CQsX6uby.js +0 -1
  17. package/dist/node-DeN3f1CH.js +0 -1
  18. package/dist/node-cSLqYAQI.js +0 -1
  19. package/dist/node-l0bjR3wx.js +0 -1
  20. package/dist/read_file.node-Cf-KhpsY.js +0 -1
  21. package/dist/{stdio-De_F_RHg.js → stdio-KJwwMQUN.js} +1 -2
  22. package/dist/storybook.js +0 -1
  23. package/dist/undo_edit.node-CCYYuJ4U.js +0 -1
  24. package/package.json +2 -1
  25. package/dist/amp.js.map +0 -1
  26. package/dist/client-D82aFqMl.js.map +0 -1
  27. package/dist/console-RPzEsLY0.js.map +0 -1
  28. package/dist/create_file.node-Dg6SfP0E.js.map +0 -1
  29. package/dist/edit_file.node-DOTivrdL.js.map +0 -1
  30. package/dist/executable-Cvv6G9ik.js.map +0 -1
  31. package/dist/files-DrSncnX3.js.map +0 -1
  32. package/dist/fuzzy-server.js.map +0 -1
  33. package/dist/glob.node-Betywdle.js.map +0 -1
  34. package/dist/index-C1JH-cfZ.js.map +0 -1
  35. package/dist/list_directory.node-B8bOIV1q.js.map +0 -1
  36. package/dist/load-profile-CgexvkzB.js.map +0 -1
  37. package/dist/main-CSw2Cx-a.js.map +0 -1
  38. package/dist/node-BIJw0rpH.js.map +0 -1
  39. package/dist/node-CQsX6uby.js.map +0 -1
  40. package/dist/node-CaahOEeV.js.map +0 -1
  41. package/dist/node-DeN3f1CH.js.map +0 -1
  42. package/dist/node-cSLqYAQI.js.map +0 -1
  43. package/dist/node-l0bjR3wx.js.map +0 -1
  44. package/dist/read_file.node-Cf-KhpsY.js.map +0 -1
  45. package/dist/stdio-De_F_RHg.js.map +0 -1
  46. package/dist/storybook.js.map +0 -1
  47. package/dist/undo_edit.node-CCYYuJ4U.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-BIJw0rpH.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,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SAAS;AAEvC;AAMA,eAAsBU,EAAaD,GAAgC;AAC9D,MAAA;AACG,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 +0,0 @@
1
- {"version":3,"file":"node-CQsX6uby.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,EAAaH,GAAaF,GAAsD;AAC/F,QAAMY,IAAwB;AAAA,IAC7B;AAAA,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G;AAAA,QACb,QAAQ;AAAA,QACR,UAAU,CAAC;AAAA,QACX,OAAO,EAAE,SAAS,OAAOjB,CAAK,EAAE;AAAA,MAChC,CAAA;AAAA,IAAA;AAAA,EAEH;AACD;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-CaahOEeV.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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