Read named capture groups by name

This commit is contained in:
Danny Kim
2026-10-20 01:53:32 +09:00
parent bcb0e0cc70
commit 98138fc7a1
2 changed files with 7 additions and 6 deletions
+2 -2
View File
@@ -6,8 +6,8 @@ import { isNotFound } from "#common";
import type { RuntimeProfile } from "#runtime";
export function isRunnableProfileProcess(status: string, uid: number): boolean {
const owner = /^Uid:\s+(?<uid>\d+)/mu.exec(status)?.[1];
const state = /^State:\s+(?<state>\w)/mu.exec(status)?.[1];
const owner = /^Uid:\s+(?<uid>\d+)/mu.exec(status)?.groups?.["uid"];
const state = /^State:\s+(?<state>\w)/mu.exec(status)?.groups?.["state"];
return owner !== undefined && Number(owner) === uid && state !== "Z";
}
+5 -4
View File
@@ -211,10 +211,11 @@ async function renderPrompt(profile: RuntimeProfile): Promise<RenderedPrompt> {
]);
const template = await readFile(new URL("../../prompt.md", import.meta.url), "utf8");
return {
prompt: template.replaceAll(
/\$\{(?<name>\w+)\}/gu,
(match: string, name: string) => values.get(name) ?? match,
),
prompt: template.replaceAll(/\$\{(?<name>\w+)\}/gu, (match: string, ...args: unknown[]) => {
const groups = args.at(-1);
const name = isObject(groups) ? field(groups, "name") : undefined;
return typeof name === "string" ? (values.get(name) ?? match) : match;
}),
reviewPath,
anchorsPath,
};