@danypops/papyrus 0.27.0 → 0.27.1
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.
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* registration, its own event emission, malformed-options recovery for other tools' schemas)
|
|
11
11
|
* removed since Discuss already owns its schema, persistence, and rendering.
|
|
12
12
|
*/
|
|
13
|
-
import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
13
|
+
import type { AgentToolUpdateCallback, ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
14
14
|
import { getMarkdownTheme } from "@earendil-works/pi-coding-agent";
|
|
15
15
|
import {
|
|
16
16
|
Container,
|
|
@@ -62,6 +62,16 @@ export interface AskQuestionParams {
|
|
|
62
62
|
allowComment?: boolean;
|
|
63
63
|
displayMode?: AskDisplayMode;
|
|
64
64
|
timeout?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Streamed once before blocking on the human. A live ask can legitimately sit pending far
|
|
67
|
+
* longer than a typical tool call (real human response time, not milliseconds) -- without any
|
|
68
|
+
* progress signal, a tool call sitting silent that long looks indistinguishable from a dead
|
|
69
|
+
* one to anything upstream watching for stalled calls. pi-ask-user's own original code (the
|
|
70
|
+
* prior art this view is adapted from) sent exactly this same heartbeat before presenting its
|
|
71
|
+
* UI; dropping it during the port was the regression that let two independent executions of
|
|
72
|
+
* the same live ask run concurrently, each opening its own picker for the same question.
|
|
73
|
+
*/
|
|
74
|
+
onUpdate?: AgentToolUpdateCallback;
|
|
65
75
|
}
|
|
66
76
|
|
|
67
77
|
export interface AskAnswer {
|
|
@@ -1081,6 +1091,8 @@ export async function askQuestion(ctx: ExtensionContext, params: AskQuestionPara
|
|
|
1081
1091
|
const displayMode: AskDisplayMode = params.displayMode ?? envDisplayMode ?? "overlay";
|
|
1082
1092
|
const normalizedContext = params.context?.trim() || undefined;
|
|
1083
1093
|
|
|
1094
|
+
params.onUpdate?.({ content: [{ type: "text", text: "Waiting for human input..." }], details: undefined });
|
|
1095
|
+
|
|
1084
1096
|
if (options.length === 0) {
|
|
1085
1097
|
const prompt = normalizedContext ? `${params.question}\n\nContext:\n${normalizedContext}` : params.question;
|
|
1086
1098
|
const answer = await ctx.ui.input(prompt, "Type your answer...", params.timeout ? { timeout: params.timeout } : undefined);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import type { AgentToolUpdateCallback, ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import type { Artifact } from "../../src/domain/artifact.ts";
|
|
4
4
|
import { PROOF_TYPES } from "../../src/domain/checklist.ts";
|
|
@@ -39,7 +39,7 @@ function text(message: string, details: unknown = {}) {
|
|
|
39
39
|
* is available, never throws -- an unanswered live prompt still leaves the round it already
|
|
40
40
|
* recorded intact.
|
|
41
41
|
*/
|
|
42
|
-
async function liveAnswer(ctx: ExtensionContext, discussion: Artifact): Promise<{ content: string; selected?: string[] } | undefined> {
|
|
42
|
+
async function liveAnswer(ctx: ExtensionContext, discussion: Artifact, onUpdate: AgentToolUpdateCallback | undefined): Promise<{ content: string; selected?: string[] } | undefined> {
|
|
43
43
|
if (!ctx.hasUI) return undefined;
|
|
44
44
|
const pending = (() => { try { return readDiscussionExtra(discussion.extra); } catch { return undefined; } })();
|
|
45
45
|
const question = `Reply to "${discussion.title}":`;
|
|
@@ -48,9 +48,10 @@ async function liveAnswer(ctx: ExtensionContext, discussion: Artifact): Promise<
|
|
|
48
48
|
question,
|
|
49
49
|
options: pending.pendingOptions.map((title) => ({ title })),
|
|
50
50
|
allowMultiple: pending.pendingOptionsMode === "multi",
|
|
51
|
+
onUpdate,
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
|
-
return askQuestion(ctx, { question });
|
|
54
|
+
return askQuestion(ctx, { question, onUpdate });
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
/**
|
|
@@ -697,9 +698,13 @@ export function registerDomainTools(pi: ExtensionAPI): void {
|
|
|
697
698
|
selected: Type.Optional(Type.Array(Type.String())),
|
|
698
699
|
live: Type.Optional(Type.Boolean()),
|
|
699
700
|
}),
|
|
701
|
+
// Blocks other tool calls in the same assistant turn until live:true's human answer comes
|
|
702
|
+
// back, same reasoning as pi-ask-user's own tool: the model must not batch a live ask with
|
|
703
|
+
// bash/edit/write and let those run before the human sees the prompt.
|
|
704
|
+
executionMode: "sequential",
|
|
700
705
|
renderCall(args, theme) { return renderPapyrusToolCall("Discuss", args, theme); },
|
|
701
706
|
renderResult(result, options, theme, context) { return renderPapyrusToolResult(result, options, theme, context); },
|
|
702
|
-
async execute(_id, rawParams, _signal,
|
|
707
|
+
async execute(_id, rawParams, _signal, onUpdate, ctx) {
|
|
703
708
|
try {
|
|
704
709
|
const params: Record<string, unknown> = { ...rawParams };
|
|
705
710
|
const action = params.action;
|
|
@@ -716,7 +721,7 @@ export function registerDomainTools(pi: ExtensionAPI): void {
|
|
|
716
721
|
? text(`Opened discussion ${artifactLine(result.discussion)}`, createArtifactDetails("discuss.open", result.discussion))
|
|
717
722
|
: text(`Round ${result.rounds[0]?.roundNumber} added to "${result.discussion.title}"`, createArtifactDetails("discuss.reply", result.discussion));
|
|
718
723
|
if (params.live !== true) return fallback;
|
|
719
|
-
const answer = await liveAnswer(ctx, result.discussion);
|
|
724
|
+
const answer = await liveAnswer(ctx, result.discussion, onUpdate);
|
|
720
725
|
if (!answer) return fallback;
|
|
721
726
|
const answered = await callService<Record<string, unknown>, DiscussionAndRounds>("discuss.reply", {
|
|
722
727
|
id: result.discussion.id, actor: "human", content: answer.content, ...(answer.selected ? { selected: answer.selected } : {}), source: "discuss-live",
|
package/package.json
CHANGED