ahead-pi 0.8.2 → 0.8.3
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.
- package/package.json +1 -1
- package/src/guidance.ts +30 -10
- package/src/index.ts +20 -8
package/package.json
CHANGED
package/src/guidance.ts
CHANGED
|
@@ -533,8 +533,10 @@ export function buildArtifactTemplate(
|
|
|
533
533
|
}
|
|
534
534
|
|
|
535
535
|
/**
|
|
536
|
-
* Insert inspiration-only example lines into each field as
|
|
537
|
-
*
|
|
536
|
+
* Insert inspiration-only example lines into each field as plain text with
|
|
537
|
+
* an "ex. - " prefix. Validation strips these lines for the emptiness
|
|
538
|
+
* check and rejects any saved form that still contains them, so no example
|
|
539
|
+
* line can ever persist in a recorded artifact.
|
|
538
540
|
*/
|
|
539
541
|
export function insertFieldExamples(template: string, perField: string[][]): string {
|
|
540
542
|
let updated = template;
|
|
@@ -548,16 +550,27 @@ export function insertFieldExamples(template: string, perField: string[][]): str
|
|
|
548
550
|
}
|
|
549
551
|
updated = updated.replace(
|
|
550
552
|
marker,
|
|
551
|
-
[
|
|
552
|
-
marker,
|
|
553
|
-
"<!-- Examples — inspiration only, not requirements. Delete them and write your own answer. -->",
|
|
554
|
-
...examples.map((example) => `<!-- ~ ${example} ~ -->`),
|
|
555
|
-
].join("\n"),
|
|
553
|
+
[marker, ...examples.map((example) => `ex. - ${example}`)].join("\n"),
|
|
556
554
|
);
|
|
557
555
|
}
|
|
558
556
|
return updated;
|
|
559
557
|
}
|
|
560
558
|
|
|
559
|
+
const EXAMPLE_LINE_PATTERN = /^\s*ex\.\s*-\s?/;
|
|
560
|
+
|
|
561
|
+
function stripExampleLines(text: string): { cleaned: string; hadExamples: boolean } {
|
|
562
|
+
const kept: string[] = [];
|
|
563
|
+
let hadExamples = false;
|
|
564
|
+
for (const line of text.split("\n")) {
|
|
565
|
+
if (EXAMPLE_LINE_PATTERN.test(line)) {
|
|
566
|
+
hadExamples = true;
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
kept.push(line);
|
|
570
|
+
}
|
|
571
|
+
return { cleaned: kept.join("\n").trim(), hadExamples };
|
|
572
|
+
}
|
|
573
|
+
|
|
561
574
|
export function validateArtifactForm(content: string, prompts: string[]): string[] {
|
|
562
575
|
const errors: string[] = [];
|
|
563
576
|
for (const [index, prompt] of prompts.entries()) {
|
|
@@ -575,11 +588,18 @@ export function validateArtifactForm(content: string, prompts: string[]): string
|
|
|
575
588
|
.slice(beginIndex + begin.length, endIndex)
|
|
576
589
|
.replace(/<!--[\s\S]*?-->/g, "")
|
|
577
590
|
.trim();
|
|
578
|
-
|
|
579
|
-
|
|
591
|
+
const { cleaned, hadExamples } = stripExampleLines(response);
|
|
592
|
+
if (!cleaned) {
|
|
593
|
+
errors.push(
|
|
594
|
+
hadExamples ? `${prompt} (replace the “ex. -” example lines with your own answer)` : prompt,
|
|
595
|
+
);
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
if (hadExamples) {
|
|
599
|
+
errors.push(`${prompt} (remove the leftover “ex. -” example lines)`);
|
|
580
600
|
continue;
|
|
581
601
|
}
|
|
582
|
-
if (/^(?:n\/?a|not applicable)\s*[.!]?$/i.test(
|
|
602
|
+
if (/^(?:n\/?a|not applicable)\s*[.!]?$/i.test(cleaned)) {
|
|
583
603
|
errors.push(`${prompt} (explain why it is not applicable)`);
|
|
584
604
|
}
|
|
585
605
|
}
|
package/src/index.ts
CHANGED
|
@@ -1617,15 +1617,27 @@ async function recordHumanArtifact(
|
|
|
1617
1617
|
const prompts = promptsForArtifact(state.workflow_id, state.phase.id, artifact.kind);
|
|
1618
1618
|
let template = await humanArtifactTemplate(store, state, run, artifact.kind, artifact.title);
|
|
1619
1619
|
if (ctx.hasUI && artifact.kind !== "review-disposition" && prompts.length > 0) {
|
|
1620
|
-
|
|
1621
|
-
|
|
1620
|
+
// Visible progress while drafting: the loader row and footer status show
|
|
1621
|
+
// until the call resolves, so the wait never looks like a hang.
|
|
1622
|
+
const showProgress = ctx.model !== undefined;
|
|
1623
|
+
if (showProgress) {
|
|
1624
|
+
ctx.ui.setWorkingMessage("Drafting example prompts (inspiration only)…");
|
|
1625
|
+
ctx.ui.setStatus("ahead-examples", "Drafting example prompts…");
|
|
1626
|
+
}
|
|
1627
|
+
let draft;
|
|
1628
|
+
try {
|
|
1629
|
+
draft = await draftFieldExamples(ctx, {
|
|
1630
|
+
workflowTitle: engine.getWorkflow(state.workflow_id).title,
|
|
1631
|
+
phaseTitle: state.phase.title,
|
|
1632
|
+
runTitle: run.title,
|
|
1633
|
+
fields: prompts,
|
|
1634
|
+
});
|
|
1635
|
+
} finally {
|
|
1636
|
+
if (showProgress) {
|
|
1637
|
+
ctx.ui.setWorkingMessage();
|
|
1638
|
+
ctx.ui.setStatus("ahead-examples", undefined);
|
|
1639
|
+
}
|
|
1622
1640
|
}
|
|
1623
|
-
const draft = await draftFieldExamples(ctx, {
|
|
1624
|
-
workflowTitle: engine.getWorkflow(state.workflow_id).title,
|
|
1625
|
-
phaseTitle: state.phase.title,
|
|
1626
|
-
runTitle: run.title,
|
|
1627
|
-
fields: prompts,
|
|
1628
|
-
});
|
|
1629
1641
|
if (draft.examples) {
|
|
1630
1642
|
template = insertFieldExamples(template, draft.examples);
|
|
1631
1643
|
} else if (draft.skipped === "no-auth") {
|