This commit is contained in:
Dax Raad
2025-09-27 02:53:20 -04:00
parent 26ebf85b0e
commit d0043a4a78
8 changed files with 483 additions and 188 deletions

View File

@@ -48,6 +48,7 @@ import { ulid } from "ulid"
import { spawn } from "child_process"
import { Command } from "../command"
import { $ } from "bun"
import { ConfigMarkdown } from "../config/markdown"
export namespace SessionPrompt {
const log = Log.create({ service: "session.prompt" })
@@ -1364,7 +1365,6 @@ export namespace SessionPrompt {
* Matches @ followed by file paths, excluding commas, periods at end of sentences, and backticks
* Does not match when preceded by word characters or backticks (to avoid email addresses and quoted references)
*/
export const fileRegex = /(?<![\w`])@(\.?[^\s`,.]*(?:\.[^\s`,.]+)*)/g
export async function command(input: CommandInput) {
log.info("command", input)
@@ -1373,10 +1373,10 @@ export namespace SessionPrompt {
let template = command.template.replace("$ARGUMENTS", input.arguments)
const bash = Array.from(template.matchAll(bashRegex))
if (bash.length > 0) {
const shell = ConfigMarkdown.shell(template)
if (shell.length > 0) {
const results = await Promise.all(
bash.map(async ([, cmd]) => {
shell.map(async ([, cmd]) => {
try {
return await $`${{ raw: cmd }}`.nothrow().text()
} catch (error) {
@@ -1395,9 +1395,9 @@ export namespace SessionPrompt {
},
] as PromptInput["parts"]
const matches = Array.from(template.matchAll(fileRegex))
const files = ConfigMarkdown.files(template)
await Promise.all(
matches.map(async (match) => {
files.map(async (match) => {
const name = match[1]
const filepath = name.startsWith("~/")
? path.join(os.homedir(), name.slice(2))