pi-roundtable 0.53.5 → 0.54.0
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/CHANGELOG.md +19 -0
- package/README.md +14 -2
- package/README.zh-TW.md +14 -2
- package/docs/plugins.md +201 -8
- package/package.json +3 -1
- package/runner/Dockerfile +46 -0
- package/runner/Dockerfile.dockerignore +5 -0
- package/src/cli/checks/images.ts +3 -2
- package/src/cli/checks/preset.ts +20 -0
- package/src/cli/checks/runner.ts +45 -0
- package/src/cli/doctor.ts +7 -1
- package/src/core/agents/agent-claim.ts +7 -4
- package/src/core/agents/agent-prompt.ts +11 -2
- package/src/core/agents/helper-workspace.ts +72 -0
- package/src/core/agents/team-options.ts +2 -0
- package/src/core/agents/team-prompt.ts +12 -1
- package/src/core/attachments/attachment-expiry.ts +12 -0
- package/src/core/attachments/attachment-store.ts +20 -5
- package/src/core/attachments/model-images.ts +3 -2
- package/src/core/builtin/agent-server.ts +8 -0
- package/src/core/builtin/polls.ts +67 -0
- package/src/core/builtin/runner.ts +139 -0
- package/src/core/config/config-schema.ts +4 -0
- package/src/core/config/config.ts +49 -185
- package/src/core/config/preset.ts +51 -0
- package/src/core/config/resolve-config.ts +175 -0
- package/src/core/config/runner-config.ts +80 -0
- package/src/core/contract/attachments.ts +2 -0
- package/src/core/contract/polls.ts +71 -0
- package/src/core/contract/runtime.ts +12 -0
- package/src/core/contract/surface.ts +13 -0
- package/src/core/discord/discord-polls.ts +156 -0
- package/src/core/discord/discord-replies.ts +55 -0
- package/src/core/discord/discord-surface.ts +13 -43
- package/src/core/domain/client.ts +6 -2
- package/src/core/domain/errors.ts +5 -0
- package/src/core/domain/sessions.ts +8 -1
- package/src/core/host/define-roundtable.ts +8 -0
- package/src/core/host/host-registration.ts +7 -0
- package/src/core/host/host.ts +8 -0
- package/src/core/i18n/schedules.ts +2 -0
- package/src/core/modules/polls/poll-result-turns.ts +124 -0
- package/src/core/modules/polls/poll-rules.ts +108 -0
- package/src/core/modules/polls/poll-service.ts +477 -0
- package/src/core/modules/polls/poll-store.ts +336 -0
- package/src/core/modules/polls/poll-tools.ts +118 -0
- package/src/core/modules/polls/poll-turn-text.ts +60 -0
- package/src/core/plugin-api/define.ts +9 -2
- package/src/core/plugin-api/holds.ts +2 -0
- package/src/core/plugin-api/plugin.ts +8 -0
- package/src/core/runner/protocol.ts +456 -0
- package/src/core/runner/runner-client.ts +450 -0
- package/src/core/runner/runner-drivers.ts +356 -0
- package/src/core/runner/runner-files.ts +102 -0
- package/src/core/runner/runner-holds.ts +76 -0
- package/src/core/runner/runner-port.ts +77 -0
- package/src/core/runner/runner-probe.ts +53 -0
- package/src/core/runner/runner-prompt.ts +36 -0
- package/src/core/runner/runner-session.ts +131 -0
- package/src/core/runner/runner-tiers.ts +20 -0
- package/src/core/runner/runner-tools.ts +325 -0
- package/src/core/runner/settings.ts +108 -0
- package/src/core/runtime/conversation-sessions.ts +73 -15
- package/src/core/runtime/extensions/approval-card.ts +29 -2
- package/src/core/runtime/extensions/confirmation-gate.ts +24 -63
- package/src/core/runtime/extensions/gate-card.ts +105 -0
- package/src/core/runtime/extensions/yolo.ts +17 -3
- package/src/core/runtime/pi-agent-runtime.ts +37 -68
- package/src/core/runtime/runtime-plugin.ts +9 -0
- package/src/core/runtime/runtime-types.ts +29 -1
- package/src/core/runtime/session-factory.ts +59 -62
- package/src/core/runtime/session-shell.ts +43 -0
- package/src/core/runtime/session-tool-names.ts +78 -0
- package/src/core/runtime/turn-selection.ts +97 -0
- package/src/core/shared/attachment-reader.ts +10 -1
- package/src/core/shared/generate-image-tool.ts +4 -4
- package/src/core/shared/poll-target.ts +14 -0
- package/src/core/shared/workspace-files.ts +42 -4
- package/src/core/testing/fake-polls.ts +131 -0
- package/src/core/testing/fake-runner.ts +146 -0
- package/src/core/testing/surface-contract-approvals.ts +215 -0
- package/src/core/testing/surface-contract-polls.ts +142 -0
- package/src/core/testing/surface-contract.ts +32 -208
- package/src/core/tool-set.snapshot.json +8 -0
- package/src/index.ts +17 -0
- package/src/kit/index.ts +6 -0
- package/src/kit/polls.ts +8 -0
- package/src/runner-server/exec.ts +174 -0
- package/src/runner-server/file-helper.ts +208 -0
- package/src/runner-server/files.ts +93 -0
- package/src/runner-server/host.ts +65 -0
- package/src/runner-server/main.ts +89 -0
- package/src/runner-server/server.ts +318 -0
- package/src/runner-server/shared-dirs.ts +45 -0
- package/src/runner-server/state.ts +293 -0
- package/src/runner-server/transports.ts +187 -0
- package/src/testing.ts +7 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { describe, test } from "bun:test";
|
|
2
|
+
import type { PollVoter, SurfacePolls } from "../contract/polls.ts";
|
|
3
|
+
import type { ChannelKey } from "../domain/sessions.ts";
|
|
4
|
+
import { expectThat } from "./surface-contract-support.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A surface's native polls under the contract, in one of its channels, and the hands of the people
|
|
8
|
+
* there: they vote, when the subject can make them, and delete a poll's message.
|
|
9
|
+
*/
|
|
10
|
+
export interface PollsContractSubject {
|
|
11
|
+
polls: SurfacePolls;
|
|
12
|
+
channel: ChannelKey;
|
|
13
|
+
/** Someone votes for the answer at `index` of an open poll; without it the counts are not checked. */
|
|
14
|
+
vote?(pollId: string, index: number, voter: PollVoter): Promise<void>;
|
|
15
|
+
/** Someone deletes the poll's message. */
|
|
16
|
+
remove(pollId: string): Promise<void>;
|
|
17
|
+
close?(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const HOUR_MS = 3_600_000;
|
|
21
|
+
|
|
22
|
+
const ask = (answers: readonly string[], hours = 1) => ({
|
|
23
|
+
question: "Which day?",
|
|
24
|
+
answers,
|
|
25
|
+
multi: false,
|
|
26
|
+
closesAt: new Date(Date.now() + hours * HOUR_MS),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/** The poll checks; each runs on a fresh subject. */
|
|
30
|
+
export const POLL_CHECKS: readonly {
|
|
31
|
+
name: string;
|
|
32
|
+
run(subject: PollsContractSubject): Promise<void>;
|
|
33
|
+
}[] = [
|
|
34
|
+
{
|
|
35
|
+
name: "posts a poll, and ends it twice without failing",
|
|
36
|
+
run: async ({ polls, channel }) => {
|
|
37
|
+
const { pollId } = await polls.post(channel, ask(["Mon", "Tue"]));
|
|
38
|
+
expectThat(pollId !== "", "a posted poll has an id");
|
|
39
|
+
await polls.end(channel, pollId);
|
|
40
|
+
await polls.end(channel, pollId);
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "reads the results after the end: every answer in order, with its votes and voters",
|
|
45
|
+
run: async ({ polls, channel, vote }) => {
|
|
46
|
+
const { pollId } = await polls.post(channel, ask(["Mon", "Tue", "Wed"]));
|
|
47
|
+
if (vote) {
|
|
48
|
+
await vote(pollId, 1, { id: "100000000000000001", name: "Ann" });
|
|
49
|
+
await vote(pollId, 1, { id: "100000000000000002", name: "Bob" });
|
|
50
|
+
await vote(pollId, 0, { id: "100000000000000003", name: "Cy" });
|
|
51
|
+
}
|
|
52
|
+
await polls.end(channel, pollId);
|
|
53
|
+
const results = await polls.results(channel, pollId);
|
|
54
|
+
expectThat(results !== "gone", "an ended poll still has its results");
|
|
55
|
+
if (results === "gone") return;
|
|
56
|
+
expectThat(
|
|
57
|
+
results.answers.map((answer) => answer.text).join() === "Mon,Tue,Wed",
|
|
58
|
+
`the answers read ${JSON.stringify(results.answers.map((a) => a.text))}`,
|
|
59
|
+
);
|
|
60
|
+
if (!vote) return;
|
|
61
|
+
expectThat(
|
|
62
|
+
results.answers.map((answer) => answer.votes).join() === "1,2,0",
|
|
63
|
+
`the votes read ${JSON.stringify(results.answers.map((a) => a.votes))}`,
|
|
64
|
+
);
|
|
65
|
+
expectThat(
|
|
66
|
+
results.answers[1]?.voters
|
|
67
|
+
.map((voter) => voter.name)
|
|
68
|
+
.sort()
|
|
69
|
+
.join() === "Ann,Bob",
|
|
70
|
+
"an answer lists who voted for it",
|
|
71
|
+
);
|
|
72
|
+
expectThat(
|
|
73
|
+
results.answers.every((answer) => !answer.votersCut),
|
|
74
|
+
"a short list of voters is not cut",
|
|
75
|
+
);
|
|
76
|
+
expectThat(
|
|
77
|
+
results.totalVoters === 3,
|
|
78
|
+
`${results.totalVoters} voters counted`,
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: "a deleted poll reads gone, and ending it does not fail",
|
|
84
|
+
run: async ({ polls, channel, remove }) => {
|
|
85
|
+
const { pollId } = await polls.post(channel, ask(["Mon", "Tue"]));
|
|
86
|
+
await remove(pollId);
|
|
87
|
+
await polls.end(channel, pollId);
|
|
88
|
+
expectThat(
|
|
89
|
+
(await polls.results(channel, pollId)) === "gone",
|
|
90
|
+
"a deleted poll reads gone",
|
|
91
|
+
);
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "takes a poll at its limits: the most answers, the longest texts, the longest time",
|
|
96
|
+
run: async ({ polls, channel }) => {
|
|
97
|
+
const { limits } = polls;
|
|
98
|
+
expectThat(limits.answers >= 2, "a poll offers at least two answers");
|
|
99
|
+
const answers = Array.from({ length: limits.answers }, (_, i) =>
|
|
100
|
+
`${i}`.padEnd(limits.answerChars, "x"),
|
|
101
|
+
);
|
|
102
|
+
const { pollId } = await polls.post(channel, {
|
|
103
|
+
question: "q".repeat(limits.questionChars),
|
|
104
|
+
answers,
|
|
105
|
+
multi: true,
|
|
106
|
+
closesAt: new Date(Date.now() + limits.maxDurationMs),
|
|
107
|
+
});
|
|
108
|
+
await polls.end(channel, pollId);
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
/** Runs one poll check on a fresh subject, and closes it. */
|
|
114
|
+
export async function runPollCheck(
|
|
115
|
+
check: (typeof POLL_CHECKS)[number],
|
|
116
|
+
make: () => Promise<PollsContractSubject>,
|
|
117
|
+
): Promise<void> {
|
|
118
|
+
const subject = await make();
|
|
119
|
+
try {
|
|
120
|
+
await check.run(subject);
|
|
121
|
+
} finally {
|
|
122
|
+
await subject.close?.();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Registers only the poll part of the surface contract, for a surface's `polls` tested apart from
|
|
128
|
+
* the surface, such as Discord's against an emulated Discord: a poll is posted, ended twice without
|
|
129
|
+
* failing, read after the end with every answer in order (and, where the subject can vote, the
|
|
130
|
+
* votes and voters), read `"gone"` once deleted, and taken at the surface's own limits.
|
|
131
|
+
*/
|
|
132
|
+
export function describePollsContract(
|
|
133
|
+
name: string,
|
|
134
|
+
make: () => Promise<PollsContractSubject>,
|
|
135
|
+
): void {
|
|
136
|
+
describe(`${name} keeps the poll contract`, () => {
|
|
137
|
+
for (const check of POLL_CHECKS)
|
|
138
|
+
test(check.name, async () => {
|
|
139
|
+
await runPollCheck(check, make);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
@@ -4,28 +4,29 @@ import { parseChannelKey } from "../contract/surface.ts";
|
|
|
4
4
|
import type { TurnProgress } from "../domain/progress.ts";
|
|
5
5
|
import type { ChannelKey } from "../domain/sessions.ts";
|
|
6
6
|
import type { Speaker } from "../identity/speakers.ts";
|
|
7
|
-
import type { Approval } from "../interactions/prompts.ts";
|
|
8
7
|
import type {
|
|
9
8
|
Questionnaire,
|
|
10
9
|
QuestionnaireAnswer,
|
|
11
10
|
} from "../interactions/questionnaire.ts";
|
|
11
|
+
import { APPROVAL_CHECKS } from "./surface-contract-approvals.ts";
|
|
12
12
|
import { BLOCK_CHECKS } from "./surface-contract-blocks.ts";
|
|
13
|
+
import {
|
|
14
|
+
POLL_CHECKS,
|
|
15
|
+
type PollsContractSubject,
|
|
16
|
+
} from "./surface-contract-polls.ts";
|
|
13
17
|
|
|
14
18
|
export { describeBlocksContract } from "./surface-contract-blocks.ts";
|
|
19
|
+
export {
|
|
20
|
+
describePollsContract,
|
|
21
|
+
type PollsContractSubject,
|
|
22
|
+
} from "./surface-contract-polls.ts";
|
|
15
23
|
|
|
16
24
|
import { QUESTIONNAIRE_CHECKS } from "./surface-contract-questionnaire.ts";
|
|
17
25
|
import {
|
|
18
|
-
answeredOnlyByThem,
|
|
19
|
-
approval,
|
|
20
|
-
ContractBroken,
|
|
21
26
|
expectThat,
|
|
22
|
-
namedApproverAnswers,
|
|
23
|
-
nextPrompt,
|
|
24
27
|
type Running,
|
|
25
28
|
runCheck,
|
|
26
|
-
scopeOf,
|
|
27
29
|
seen,
|
|
28
|
-
speakerOf,
|
|
29
30
|
until,
|
|
30
31
|
} from "./surface-contract-support.ts";
|
|
31
32
|
|
|
@@ -99,6 +100,12 @@ export interface SurfaceContractSubject {
|
|
|
99
100
|
* check and keeps the one that its person alone answers a private conversation's.
|
|
100
101
|
*/
|
|
101
102
|
privateOnly?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* The hands of the people in `channel` on the surface's polls: they delete a poll's message,
|
|
105
|
+
* and vote where the subject can make them. With it, a surface that has `polls` keeps the poll
|
|
106
|
+
* checks; without it they are skipped.
|
|
107
|
+
*/
|
|
108
|
+
polls?: Pick<PollsContractSubject, "vote" | "remove">;
|
|
102
109
|
close?(): Promise<void>;
|
|
103
110
|
}
|
|
104
111
|
|
|
@@ -121,14 +128,14 @@ export interface SurfaceContractFailure {
|
|
|
121
128
|
error: unknown;
|
|
122
129
|
}
|
|
123
130
|
|
|
124
|
-
interface
|
|
131
|
+
export interface SurfaceCheck {
|
|
125
132
|
name: string;
|
|
126
133
|
/** Whether the check applies to this subject; a check that does not is skipped. */
|
|
127
134
|
applies?(subject: SurfaceContractSubject): boolean;
|
|
128
135
|
run(running: Running): Promise<void>;
|
|
129
136
|
}
|
|
130
137
|
|
|
131
|
-
const CHECKS: readonly
|
|
138
|
+
const CHECKS: readonly SurfaceCheck[] = [
|
|
132
139
|
{
|
|
133
140
|
name: "names a surface prefix without a colon, and owns the subject's channel",
|
|
134
141
|
run: async ({ subject }) => {
|
|
@@ -248,205 +255,20 @@ const CHECKS: readonly Check[] = [
|
|
|
248
255
|
);
|
|
249
256
|
},
|
|
250
257
|
},
|
|
251
|
-
|
|
252
|
-
name: "an approval resolves as the person answers it, and closes",
|
|
253
|
-
applies: (subject) =>
|
|
254
|
-
subject.surface.prompts !== undefined && subject.answer !== undefined,
|
|
255
|
-
run: async (running) => {
|
|
256
|
-
const approved = await approval(running, true);
|
|
257
|
-
expectThat(approved === "approved", `approving answered ${approved}`);
|
|
258
|
-
const declined = await approval(running, false);
|
|
259
|
-
expectThat(declined === "declined", `declining answered ${declined}`);
|
|
260
|
-
await until(
|
|
261
|
-
() => seen(running, "prompt_closed").length >= 2,
|
|
262
|
-
"both approvals close",
|
|
263
|
-
);
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
name: "a stopped turn's approval resolves cancelled and closes",
|
|
268
|
-
applies: (subject) =>
|
|
269
|
-
subject.surface.prompts !== undefined && subject.answer !== undefined,
|
|
270
|
-
run: async (running) => {
|
|
271
|
-
const { surface, channel } = running.subject;
|
|
272
|
-
const prompts = surface.prompts?.(channel, scopeOf(running.subject));
|
|
273
|
-
if (!prompts) throw new ContractBroken("the surface shows no prompts");
|
|
274
|
-
const stop = new AbortController();
|
|
275
|
-
const before = seen(running, "prompt").length;
|
|
276
|
-
const result = prompts.confirm(
|
|
277
|
-
"Approve?",
|
|
278
|
-
"Send it.",
|
|
279
|
-
stop.signal,
|
|
280
|
-
speakerOf(running.subject).tier,
|
|
281
|
-
);
|
|
282
|
-
const id = await nextPrompt(running, before);
|
|
283
|
-
stop.abort();
|
|
284
|
-
const answer: Approval = await result;
|
|
285
|
-
expectThat(answer === "cancelled", `a stopped turn answered ${answer}`);
|
|
286
|
-
await until(
|
|
287
|
-
() =>
|
|
288
|
-
seen(running, "prompt_closed").some(
|
|
289
|
-
(o) => o.kind === "prompt_closed" && o.id === id,
|
|
290
|
-
),
|
|
291
|
-
"the stopped approval closes",
|
|
292
|
-
);
|
|
293
|
-
},
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
name: "an approval its plugin withdraws resolves cancelled and closes; one answered first stays answered",
|
|
297
|
-
applies: (subject) =>
|
|
298
|
-
subject.surface.prompts !== undefined && subject.answer !== undefined,
|
|
299
|
-
run: async (running) => {
|
|
300
|
-
const { surface, channel, answer } = running.subject;
|
|
301
|
-
const prompts = surface.prompts?.(channel, scopeOf(running.subject));
|
|
302
|
-
if (!prompts || !answer)
|
|
303
|
-
throw new ContractBroken("the surface shows no prompts");
|
|
304
|
-
const ask = (supersede: AbortSignal) =>
|
|
305
|
-
prompts.confirm(
|
|
306
|
-
"Approve?",
|
|
307
|
-
"Send it.",
|
|
308
|
-
undefined,
|
|
309
|
-
speakerOf(running.subject).tier,
|
|
310
|
-
undefined,
|
|
311
|
-
undefined,
|
|
312
|
-
{ supersede },
|
|
313
|
-
);
|
|
314
|
-
const closes = (id: string) =>
|
|
315
|
-
seen(running, "prompt_closed").filter(
|
|
316
|
-
(o) => o.kind === "prompt_closed" && o.id === id,
|
|
317
|
-
).length;
|
|
318
|
-
const withdrawn = new AbortController();
|
|
319
|
-
let before = seen(running, "prompt").length;
|
|
320
|
-
const first = ask(withdrawn.signal);
|
|
321
|
-
const firstId = await nextPrompt(running, before);
|
|
322
|
-
withdrawn.abort("replaced by a newer request");
|
|
323
|
-
const result = await Promise.race([
|
|
324
|
-
first,
|
|
325
|
-
Bun.sleep(1000).then(() => "still open" as const),
|
|
326
|
-
]);
|
|
327
|
-
expectThat(
|
|
328
|
-
result === "cancelled",
|
|
329
|
-
`a withdrawn approval answered ${result}`,
|
|
330
|
-
);
|
|
331
|
-
await until(() => closes(firstId) > 0, "the withdrawn approval closes");
|
|
332
|
-
// An answer to the closed approval changes nothing, as for any ended prompt.
|
|
333
|
-
await answer(firstId, true).catch(() => undefined);
|
|
334
|
-
expectThat(closes(firstId) === 1, "the withdrawn approval closed twice");
|
|
335
|
-
// An approval answered before the withdrawal stays answered.
|
|
336
|
-
const later = new AbortController();
|
|
337
|
-
before = seen(running, "prompt").length;
|
|
338
|
-
const second = ask(later.signal);
|
|
339
|
-
const secondId = await nextPrompt(running, before);
|
|
340
|
-
await answer(secondId, true);
|
|
341
|
-
later.abort();
|
|
342
|
-
const approved: Approval = await second;
|
|
343
|
-
expectThat(
|
|
344
|
-
approved === "approved",
|
|
345
|
-
`an answered approval came back ${approved}`,
|
|
346
|
-
);
|
|
347
|
-
await Bun.sleep(20);
|
|
348
|
-
expectThat(closes(secondId) === 1, "the answered approval closed twice");
|
|
349
|
-
// A signal that is already aborted shows nothing.
|
|
350
|
-
const gone = new AbortController();
|
|
351
|
-
gone.abort();
|
|
352
|
-
before = seen(running, "prompt").length;
|
|
353
|
-
const none: Approval = await ask(gone.signal);
|
|
354
|
-
expectThat(
|
|
355
|
-
none === "cancelled",
|
|
356
|
-
`an approval withdrawn before it opened came back ${none}`,
|
|
357
|
-
);
|
|
358
|
-
expectThat(
|
|
359
|
-
seen(running, "prompt").length === before,
|
|
360
|
-
"a withdrawn approval was shown",
|
|
361
|
-
);
|
|
362
|
-
},
|
|
363
|
-
},
|
|
364
|
-
{
|
|
365
|
-
name: "another person cannot answer the person's approval",
|
|
366
|
-
applies: (subject) =>
|
|
367
|
-
subject.surface.prompts !== undefined &&
|
|
368
|
-
subject.answer !== undefined &&
|
|
369
|
-
subject.stranger !== undefined,
|
|
370
|
-
run: (running) =>
|
|
371
|
-
answeredOnlyByThem(running, running.subject.stranger, "shared"),
|
|
372
|
-
},
|
|
373
|
-
{
|
|
374
|
-
name: "another principal cannot answer for the person in their private conversation, even an owner",
|
|
375
|
-
applies: (subject) =>
|
|
376
|
-
subject.surface.prompts !== undefined &&
|
|
377
|
-
subject.answer !== undefined &&
|
|
378
|
-
subject.owner !== undefined,
|
|
379
|
-
run: (running) =>
|
|
380
|
-
answeredOnlyByThem(running, running.subject.owner, "private"),
|
|
381
|
-
},
|
|
382
|
-
{
|
|
383
|
-
name: "an approval that is the speaker's alone is not answered by an owner in a shared conversation",
|
|
384
|
-
applies: (subject) =>
|
|
385
|
-
subject.surface.prompts !== undefined &&
|
|
386
|
-
subject.answer !== undefined &&
|
|
387
|
-
subject.owner !== undefined &&
|
|
388
|
-
subject.speakerOnly === true &&
|
|
389
|
-
subject.privateOnly !== true,
|
|
390
|
-
run: (running) =>
|
|
391
|
-
answeredOnlyByThem(
|
|
392
|
-
running,
|
|
393
|
-
running.subject.owner,
|
|
394
|
-
"shared",
|
|
395
|
-
undefined,
|
|
396
|
-
true,
|
|
397
|
-
),
|
|
398
|
-
},
|
|
399
|
-
{
|
|
400
|
-
name: "a named approver answers an approval instead of the person; the person and another person cannot",
|
|
401
|
-
applies: (subject) =>
|
|
402
|
-
subject.surface.prompts !== undefined &&
|
|
403
|
-
subject.answer !== undefined &&
|
|
404
|
-
subject.stranger !== undefined &&
|
|
405
|
-
subject.approver !== undefined &&
|
|
406
|
-
subject.privateOnly !== true,
|
|
407
|
-
run: namedApproverAnswers,
|
|
408
|
-
},
|
|
409
|
-
{
|
|
410
|
-
name: "a private conversation is answered by its person alone, whoever else a call names",
|
|
411
|
-
applies: (subject) =>
|
|
412
|
-
subject.surface.prompts !== undefined &&
|
|
413
|
-
subject.answer !== undefined &&
|
|
414
|
-
subject.approver !== undefined,
|
|
415
|
-
run: (running) =>
|
|
416
|
-
answeredOnlyByThem(running, running.subject.approver, "private", [
|
|
417
|
-
speakerOf(running.subject).principalId,
|
|
418
|
-
running.subject.approver?.principalId ?? "",
|
|
419
|
-
]),
|
|
420
|
-
},
|
|
421
|
-
{
|
|
422
|
-
name: "a private conversation's approval above the person's tier goes to no one: it comes back at once, unshown",
|
|
423
|
-
applies: (subject) =>
|
|
424
|
-
subject.surface.prompts !== undefined &&
|
|
425
|
-
speakerOf(subject).tier !== "owner",
|
|
426
|
-
run: async (running) => {
|
|
427
|
-
const { surface, channel } = running.subject;
|
|
428
|
-
const prompts = surface.prompts?.(
|
|
429
|
-
channel,
|
|
430
|
-
scopeOf(running.subject, "private"),
|
|
431
|
-
);
|
|
432
|
-
if (!prompts) throw new ContractBroken("the surface shows no prompts");
|
|
433
|
-
const before = seen(running, "prompt").length;
|
|
434
|
-
const answer = await Promise.race([
|
|
435
|
-
prompts.confirm("Approve?", "Delete the notes.", undefined, "owner"),
|
|
436
|
-
Bun.sleep(1000).then(() => "still open" as const),
|
|
437
|
-
]);
|
|
438
|
-
expectThat(
|
|
439
|
-
// `expired` is what surfaces answered before `unavailable` existed.
|
|
440
|
-
answer === "unavailable" || answer === "expired",
|
|
441
|
-
`an approval no one may answer came back ${answer}`,
|
|
442
|
-
);
|
|
443
|
-
expectThat(
|
|
444
|
-
seen(running, "prompt").length === before,
|
|
445
|
-
"an approval no one may answer was shown",
|
|
446
|
-
);
|
|
447
|
-
},
|
|
448
|
-
},
|
|
258
|
+
...APPROVAL_CHECKS,
|
|
449
259
|
...BLOCK_CHECKS,
|
|
260
|
+
...POLL_CHECKS.map(
|
|
261
|
+
(check): SurfaceCheck => ({
|
|
262
|
+
name: `polls: ${check.name}`,
|
|
263
|
+
applies: (subject) =>
|
|
264
|
+
subject.surface.polls !== undefined && subject.polls !== undefined,
|
|
265
|
+
run: async ({ subject }) => {
|
|
266
|
+
const { polls } = subject.surface;
|
|
267
|
+
if (!polls || !subject.polls) return;
|
|
268
|
+
await check.run({ polls, channel: subject.channel, ...subject.polls });
|
|
269
|
+
},
|
|
270
|
+
}),
|
|
271
|
+
),
|
|
450
272
|
...QUESTIONNAIRE_CHECKS,
|
|
451
273
|
];
|
|
452
274
|
|
|
@@ -482,6 +304,8 @@ export async function checkSurfaceContract(
|
|
|
482
304
|
* its person alone, whoever the call names besides them. A subject that gives
|
|
483
305
|
* `answerQuestionnaire` must declare `asks`, and then questionnaires keep the same rules. Each
|
|
484
306
|
* check gets a fresh subject from `make`; a check for an optional part the surface lacks passes.
|
|
307
|
+
* A surface with `polls`, whose subject gives the people's hands on them (`polls`), keeps the poll
|
|
308
|
+
* checks too (see `describePollsContract`).
|
|
485
309
|
*/
|
|
486
310
|
export function describeSurfaceContract(
|
|
487
311
|
name: string,
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
"memory_remove",
|
|
39
39
|
"memory_search",
|
|
40
40
|
"notify",
|
|
41
|
+
"poll_create",
|
|
42
|
+
"poll_end",
|
|
41
43
|
"schedule_cancel",
|
|
42
44
|
"schedule_create",
|
|
43
45
|
"schedule_list",
|
|
@@ -99,6 +101,8 @@
|
|
|
99
101
|
"memory_search",
|
|
100
102
|
"message_agent",
|
|
101
103
|
"notify",
|
|
104
|
+
"poll_create",
|
|
105
|
+
"poll_end",
|
|
102
106
|
"room_arrange",
|
|
103
107
|
"schedule_cancel",
|
|
104
108
|
"schedule_create",
|
|
@@ -200,6 +204,8 @@
|
|
|
200
204
|
"memory_remove",
|
|
201
205
|
"memory_search",
|
|
202
206
|
"notify",
|
|
207
|
+
"poll_create",
|
|
208
|
+
"poll_end",
|
|
203
209
|
"room_arrange",
|
|
204
210
|
"schedule_cancel",
|
|
205
211
|
"schedule_create",
|
|
@@ -302,6 +308,8 @@
|
|
|
302
308
|
"memory_search": "member",
|
|
303
309
|
"message_agent": "member",
|
|
304
310
|
"notify": "owner",
|
|
311
|
+
"poll_create": "member",
|
|
312
|
+
"poll_end": "member",
|
|
305
313
|
"read": "owner",
|
|
306
314
|
"read_attachment": "member",
|
|
307
315
|
"room_arrange": "admin",
|
package/src/index.ts
CHANGED
|
@@ -126,6 +126,13 @@ export type {
|
|
|
126
126
|
PlaceSpec,
|
|
127
127
|
ToolArgument,
|
|
128
128
|
} from "./core/contract/places.ts";
|
|
129
|
+
export type {
|
|
130
|
+
PollLimits,
|
|
131
|
+
PollResults,
|
|
132
|
+
PollVoter,
|
|
133
|
+
SurfacePoll,
|
|
134
|
+
SurfacePolls,
|
|
135
|
+
} from "./core/contract/polls.ts";
|
|
129
136
|
export type {
|
|
130
137
|
ImageDrawer,
|
|
131
138
|
Judge,
|
|
@@ -456,15 +463,25 @@ export type {
|
|
|
456
463
|
ConversationTurnInput,
|
|
457
464
|
ConversationTurns,
|
|
458
465
|
} from "./core/routing/conversation-turns.ts";
|
|
466
|
+
export type {
|
|
467
|
+
RunnerConfig,
|
|
468
|
+
RunnerDriverConfig,
|
|
469
|
+
RunnerSettings,
|
|
470
|
+
} from "./core/runner/settings.ts";
|
|
459
471
|
export type { ToolTiers, ToolTierTable } from "./core/runtime/tool-tiers.ts";
|
|
460
472
|
export type { ShellEnv, ShellEnvConfig } from "./core/shared/child-env.ts";
|
|
461
473
|
export {
|
|
462
474
|
PERSONAL_TARGET,
|
|
463
475
|
type PerPrincipalLimits,
|
|
464
476
|
} from "./core/shared/personal-target.ts";
|
|
477
|
+
export { POLL_TARGET } from "./core/shared/poll-target.ts";
|
|
465
478
|
export {
|
|
466
479
|
attachReplyFile,
|
|
467
480
|
REPLY_FILE_LIMITS,
|
|
468
481
|
ReplyFileError,
|
|
469
482
|
withReplyFiles,
|
|
470
483
|
} from "./core/shared/reply-files.ts";
|
|
484
|
+
export type {
|
|
485
|
+
WorkspaceFile,
|
|
486
|
+
WorkspaceFiles,
|
|
487
|
+
} from "./core/shared/workspace-files.ts";
|
package/src/kit/index.ts
CHANGED
|
@@ -132,6 +132,12 @@ export type {
|
|
|
132
132
|
OpsSink,
|
|
133
133
|
} from "./ops-alerts.ts";
|
|
134
134
|
export { OpsAlerts } from "./ops-alerts.ts";
|
|
135
|
+
export type {
|
|
136
|
+
PollResultAnswer,
|
|
137
|
+
PollResultTurns,
|
|
138
|
+
PollResultTurnsOptions,
|
|
139
|
+
} from "./polls.ts";
|
|
140
|
+
export { pollResultTurns } from "./polls.ts";
|
|
135
141
|
export {
|
|
136
142
|
type BlockSupport,
|
|
137
143
|
type ChannelSupport,
|
package/src/kit/polls.ts
ADDED