pi-roundtable 0.53.6 → 0.54.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.
Files changed (91) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +6 -2
  3. package/README.zh-TW.md +6 -2
  4. package/docs/plugins.md +199 -7
  5. package/package.json +3 -1
  6. package/runner/Dockerfile +46 -0
  7. package/runner/Dockerfile.dockerignore +5 -0
  8. package/src/cli/checks/images.ts +3 -2
  9. package/src/cli/checks/preset.ts +20 -0
  10. package/src/cli/checks/runner.ts +45 -0
  11. package/src/cli/doctor.ts +7 -1
  12. package/src/core/agents/agent-claim.ts +7 -4
  13. package/src/core/agents/agent-prompt.ts +11 -2
  14. package/src/core/agents/helper-workspace.ts +72 -0
  15. package/src/core/agents/team-options.ts +2 -0
  16. package/src/core/agents/team-prompt.ts +12 -1
  17. package/src/core/builtin/agent-server.ts +8 -0
  18. package/src/core/builtin/polls.ts +67 -0
  19. package/src/core/builtin/runner.ts +139 -0
  20. package/src/core/config/config-schema.ts +4 -0
  21. package/src/core/config/config.ts +49 -185
  22. package/src/core/config/preset.ts +51 -0
  23. package/src/core/config/resolve-config.ts +175 -0
  24. package/src/core/config/runner-config.ts +80 -0
  25. package/src/core/contract/polls.ts +71 -0
  26. package/src/core/contract/runtime.ts +12 -0
  27. package/src/core/contract/surface.ts +13 -0
  28. package/src/core/discord/discord-polls.ts +156 -0
  29. package/src/core/discord/discord-replies.ts +55 -0
  30. package/src/core/discord/discord-surface.ts +13 -43
  31. package/src/core/domain/errors.ts +5 -0
  32. package/src/core/domain/sessions.ts +8 -1
  33. package/src/core/host/define-roundtable.ts +8 -0
  34. package/src/core/host/host-registration.ts +7 -0
  35. package/src/core/host/host.ts +8 -0
  36. package/src/core/i18n/schedules.ts +2 -0
  37. package/src/core/modules/polls/poll-result-turns.ts +124 -0
  38. package/src/core/modules/polls/poll-rules.ts +108 -0
  39. package/src/core/modules/polls/poll-service.ts +477 -0
  40. package/src/core/modules/polls/poll-store.ts +336 -0
  41. package/src/core/modules/polls/poll-tools.ts +118 -0
  42. package/src/core/modules/polls/poll-turn-text.ts +60 -0
  43. package/src/core/plugin-api/define.ts +9 -2
  44. package/src/core/plugin-api/holds.ts +2 -0
  45. package/src/core/plugin-api/plugin.ts +8 -0
  46. package/src/core/runner/protocol.ts +456 -0
  47. package/src/core/runner/runner-client.ts +450 -0
  48. package/src/core/runner/runner-drivers.ts +356 -0
  49. package/src/core/runner/runner-files.ts +102 -0
  50. package/src/core/runner/runner-holds.ts +76 -0
  51. package/src/core/runner/runner-port.ts +77 -0
  52. package/src/core/runner/runner-probe.ts +53 -0
  53. package/src/core/runner/runner-prompt.ts +36 -0
  54. package/src/core/runner/runner-session.ts +131 -0
  55. package/src/core/runner/runner-tiers.ts +20 -0
  56. package/src/core/runner/runner-tools.ts +325 -0
  57. package/src/core/runner/settings.ts +108 -0
  58. package/src/core/runtime/conversation-sessions.ts +73 -15
  59. package/src/core/runtime/extensions/approval-card.ts +29 -2
  60. package/src/core/runtime/extensions/confirmation-gate.ts +24 -63
  61. package/src/core/runtime/extensions/gate-card.ts +105 -0
  62. package/src/core/runtime/extensions/yolo.ts +17 -3
  63. package/src/core/runtime/pi-agent-runtime.ts +37 -68
  64. package/src/core/runtime/runtime-plugin.ts +9 -0
  65. package/src/core/runtime/runtime-types.ts +29 -1
  66. package/src/core/runtime/session-factory.ts +59 -62
  67. package/src/core/runtime/session-shell.ts +43 -0
  68. package/src/core/runtime/session-tool-names.ts +78 -0
  69. package/src/core/runtime/turn-selection.ts +97 -0
  70. package/src/core/shared/generate-image-tool.ts +4 -4
  71. package/src/core/shared/poll-target.ts +14 -0
  72. package/src/core/shared/workspace-files.ts +42 -4
  73. package/src/core/testing/fake-polls.ts +131 -0
  74. package/src/core/testing/fake-runner.ts +146 -0
  75. package/src/core/testing/surface-contract-approvals.ts +215 -0
  76. package/src/core/testing/surface-contract-polls.ts +142 -0
  77. package/src/core/testing/surface-contract.ts +32 -208
  78. package/src/core/tool-set.snapshot.json +8 -0
  79. package/src/index.ts +17 -0
  80. package/src/kit/index.ts +6 -0
  81. package/src/kit/polls.ts +8 -0
  82. package/src/runner-server/exec.ts +174 -0
  83. package/src/runner-server/file-helper.ts +208 -0
  84. package/src/runner-server/files.ts +93 -0
  85. package/src/runner-server/host.ts +65 -0
  86. package/src/runner-server/main.ts +89 -0
  87. package/src/runner-server/server.ts +318 -0
  88. package/src/runner-server/shared-dirs.ts +45 -0
  89. package/src/runner-server/state.ts +293 -0
  90. package/src/runner-server/transports.ts +187 -0
  91. package/src/testing.ts +7 -0
@@ -1,14 +1,10 @@
1
- import { tmpdir } from "node:os";
2
- import { join } from "node:path";
3
- import { CATALOG, type Hex } from "../../characters/index.ts";
1
+ import type { Hex } from "../../characters/index.ts";
4
2
  import type { AgentSeed } from "../agents/agent-rules.ts";
5
- import { ConfigError } from "../domain/errors.ts";
6
3
  import type { InterimTextMode } from "../domain/interim.ts";
7
- import {
8
- type EffortPolicy,
9
- type ModelRef,
10
- parseModelRef,
11
- type ThinkingLevel,
4
+ import type {
5
+ EffortPolicy,
6
+ ModelRef,
7
+ ThinkingLevel,
12
8
  } from "../domain/models.ts";
13
9
  import type { Locale } from "../i18n/index.ts";
14
10
  import type { AccessRules } from "../identity/access-policy.ts";
@@ -16,40 +12,26 @@ import type { OwnerIdentity } from "../identity/owner-identity.ts";
16
12
  import type { ProfileRules } from "../identity/profiles.ts";
17
13
  import type { Tier, TierMembers } from "../identity/speakers.ts";
18
14
  import type { AgentTools, RoundtablePlugin } from "../plugin-api/plugin.ts";
19
- import { PRIMARY_CHARS } from "../runtime/interim-text.ts";
15
+ import type { RunnerConfig, RunnerSettings } from "../runner/settings.ts";
20
16
  import type { ShellEnvConfig } from "../shared/child-env.ts";
21
17
  import type { PerPrincipalLimits } from "../shared/personal-target.ts";
22
- import { type AccessConfig, accessOf } from "./access.ts";
23
- import {
24
- type DiscordConfig,
25
- liftAdapters,
26
- type ResolvedDiscord,
27
- resolvedDiscord,
28
- } from "./adapters.ts";
29
- import {
30
- checkAgentGuild,
31
- checkAgentServerOff,
32
- checkAgentTeamKeys,
33
- } from "./agent-team.ts";
18
+ import type { AccessConfig } from "./access.ts";
19
+ import type { DiscordConfig, ResolvedDiscord } from "./adapters.ts";
34
20
  import type { AttachmentsConfig } from "./attachments.ts";
35
- import { configSchema, DRAIN_LIMIT_MS } from "./config-schema.ts";
36
21
  import type { ConversationsConfig } from "./conversations.ts";
37
- import {
38
- type HelpersConfig,
39
- helpersOf,
40
- type ResolvedHelpers,
41
- } from "./helpers.ts";
42
- import { type LimitsConfig, limitsOf, type ResolvedLimits } from "./limits.ts";
43
- import { opsOf, opsOfPlace, type ResolvedOps } from "./ops.ts";
44
- import { type ProfilesConfig, profileRulesOf } from "./profiles.ts";
45
- import {
46
- type ResolvedRouting,
47
- type RoutingConfig,
48
- routingOf,
49
- } from "./routing.ts";
22
+ import type { HelpersConfig, ResolvedHelpers } from "./helpers.ts";
23
+ import type { LimitsConfig, ResolvedLimits } from "./limits.ts";
24
+ import type { ResolvedOps } from "./ops.ts";
25
+ import type { ProfilesConfig } from "./profiles.ts";
26
+ import type { ResolvedRouting, RoutingConfig } from "./routing.ts";
50
27
  import type { SkillsConfig } from "./skills-config.ts";
51
- import { type ResolvedTeam, type TeamConfig, teamOf } from "./team.ts";
28
+ import type { ResolvedTeam, TeamConfig } from "./team.ts";
52
29
 
30
+ export {
31
+ AVATAR_DEPRECATION,
32
+ OPS_DEPRECATION,
33
+ resolveConfig,
34
+ } from "./resolve-config.ts";
53
35
  export type { DiscordConfig };
54
36
 
55
37
  /** How prompts refer back to the owner. */
@@ -85,6 +67,15 @@ export interface BackgroundConfig {
85
67
  export interface RoundtableConfig extends LimitsConfig, ShellEnvConfig {
86
68
  /** The assistant's display name; default "Roundtable". */
87
69
  name?: string;
70
+ /**
71
+ * Defaults for one kind of host, under every key the configuration writes itself. `"shared"`
72
+ * is a host many people talk to: it requires `runner`, so every conversation but the owner's
73
+ * own runs `bash`, `read`, `edit` and `write` in the runner's container (and a persona's
74
+ * selection may name them on a chat-only host), sets `imageTool: "selected"`, and gives
75
+ * `generate_image`, `poll_create` and `poll_end` the `member` tier in `toolTiers`. A selection
76
+ * still has to name each tool. Left out, nothing is preset.
77
+ */
78
+ preset?: "shared";
88
79
  /**
89
80
  * The one owner, as 0.8 wrote it: their id, which is both their principal and their Discord
90
81
  * user id, their name, and pronouns. Deprecated, going away in 0.10: write `access` instead,
@@ -164,6 +155,15 @@ export interface RoundtableConfig extends LimitsConfig, ShellEnvConfig {
164
155
  * `perPrincipal.delegations` running at once. Unset, only each conversation's, as in 0.8.
165
156
  */
166
157
  background?: BackgroundConfig;
158
+ imageTool?: "every-selection" | "selected";
159
+ /**
160
+ * The runner container where multi-user conversations' `bash`, `read`, `edit` and `write` run:
161
+ * `{ driver: "docker", image }` for a container the host runs with the docker CLI, or
162
+ * `{ driver: "socket", socket }` for a sidecar's socket. Every conversation but the owner's own
163
+ * then uses it, agents' included unless `agentServer.tools` is "chat-only"; it holds no
164
+ * credential and reaches no network. Without it every tool runs as before. See `RunnerConfig`.
165
+ */
166
+ runner?: RunnerConfig;
167
167
  toolTiers?: Record<string, Tier>;
168
168
  /** Prompt files, read once at start; `shared` starts every agent's prompt. */
169
169
  prompts?: { shared: string; guest?: string };
@@ -266,17 +266,18 @@ export interface RoundtableConfig extends LimitsConfig, ShellEnvConfig {
266
266
  plugins?: RoundtablePlugin[];
267
267
  }
268
268
 
269
- /** Logged once when the top-level `ops` is set: it is an alias of the `ops` place. */
270
- export const OPS_DEPRECATION =
271
- "`ops` is an alias of `routing.places.ops` since 0.27 and goes away in 1.0; move it there";
272
-
273
- /** Logged once when `avatar` is set: agents are composed characters and no picture is drawn from it. */
274
- export const AVATAR_DEPRECATION =
275
- "agents are composed characters since 0.23; `avatar` is ignored";
276
-
277
269
  /** The configuration with every default filled in. */
278
270
  export interface ResolvedConfig extends ResolvedLimits {
279
271
  name: string;
272
+ /**
273
+ * The preset the configuration chose, and each setting it filled in as `key: value`, such as
274
+ * `imageTool: "selected"`; a setting the configuration wrote itself is not listed, since it
275
+ * wins. Undefined without `preset`.
276
+ */
277
+ preset?: {
278
+ name: NonNullable<RoundtableConfig["preset"]>;
279
+ set: readonly string[];
280
+ };
280
281
  /**
281
282
  * The process's short name: the logger's and the scratch dir's, and the root slash command's
282
283
  * with Discord. `discord.rootCommand` when Discord is on, else the lowercase assistant name.
@@ -322,6 +323,9 @@ export interface ResolvedConfig extends ResolvedLimits {
322
323
  speakers: { admins?: TierMembers; members?: TierMembers };
323
324
  /** Each person's limits across their conversations; a limit left out is unset. */
324
325
  background: { perPrincipal: PerPrincipalLimits };
326
+ imageTool: NonNullable<RoundtableConfig["imageTool"]>;
327
+ /** The runner with its defaults; undefined when none is configured. */
328
+ runner?: RunnerSettings;
325
329
  toolTiers: Record<string, Tier>;
326
330
  prompts: { shared?: string; guest?: string };
327
331
  agents: AgentSeed[];
@@ -357,143 +361,3 @@ export interface ResolvedConfig extends ResolvedLimits {
357
361
  interimPrimaryChars: number;
358
362
  plugins: RoundtablePlugin[];
359
363
  }
360
-
361
- function modelOf(value: string, path: string): ModelRef {
362
- const parsed = parseModelRef(value);
363
- if (!parsed)
364
- throw new ConfigError(
365
- `config ${path}: expected <provider>/<id>, got ${JSON.stringify(value)}. Write it like anthropic/claude-sonnet-5-5.`,
366
- );
367
- return parsed;
368
- }
369
-
370
- /** The skin tones the configuration chose, or the package's own. */
371
- function skinsOf(skins: readonly string[] | undefined): readonly Hex[] {
372
- return (skins as readonly Hex[] | undefined) ?? CATALOG.skins;
373
- }
374
-
375
- /** The configuration checked against its schema, defaults filled; throws a ConfigError naming the key and the fix. */
376
- export function resolveConfig(input: unknown): ResolvedConfig {
377
- const config = configSchema.check(
378
- liftAdapters(input),
379
- "",
380
- ) as RoundtableConfig;
381
- const name = config.name ?? "Roundtable";
382
- const model = modelOf(config.model, "model");
383
- const thinking = config.thinking ?? "medium";
384
- const { discord, http } = config;
385
- const agentServer = config.agentServer !== false;
386
- if (!agentServer) checkAgentServerOff(config);
387
- // Whether the agents have Discord channels: with `discord.guild`, else they live in the app's rooms.
388
- const agentGuild = checkAgentGuild(config, agentServer);
389
- checkAgentTeamKeys(config, agentGuild);
390
- const slug =
391
- discord?.rootCommand ?? name.toLowerCase().replace(/[^a-z0-9-]+/g, "-");
392
- const routing = routingOf(config.routing, {
393
- withDiscord: agentGuild,
394
- agentServer:
395
- agentServer && (agentGuild || (config.agents?.length ?? 0) > 0),
396
- topLevelOps: config.ops !== undefined,
397
- });
398
- const ops = opsOf(config.ops, agentGuild) ?? opsOfPlace(routing?.places.ops);
399
- const access = accessOf(config, discord !== undefined);
400
- const { primaryOwner } = access;
401
- return {
402
- name,
403
- slug,
404
- ...access,
405
- profiles: profileRulesOf(config.profiles),
406
- deprecations: [
407
- ...access.deprecations,
408
- ...(config.avatar ? [AVATAR_DEPRECATION] : []),
409
- ...(config.ops ? [OPS_DEPRECATION] : []),
410
- ],
411
- owner: {
412
- id: primaryOwner.id,
413
- name: primaryOwner.name,
414
- pronouns: primaryOwner.pronouns,
415
- },
416
- ...(discord ? { discord: resolvedDiscord(discord, slug) } : {}),
417
- databaseUrl: config.database.url,
418
- dataDir: config.dataDir,
419
- attachments: config.attachments?.retention
420
- ? { retention: config.attachments.retention }
421
- : {},
422
- conversations: {
423
- keepDays: { ...config.conversations?.keepDays },
424
- ...(config.conversations?.keep
425
- ? { keep: config.conversations.keep }
426
- : {}),
427
- },
428
- agentDir: config.agentDir ?? `${config.dataDir}/pi`,
429
- model,
430
- thinking,
431
- judge: {
432
- model: config.judge?.model
433
- ? modelOf(config.judge.model, "judge.model")
434
- : model,
435
- threshold: config.judge?.threshold ?? 0.6,
436
- },
437
- ...(config.effortPolicy ? { effortPolicy: config.effortPolicy } : {}),
438
- delegation: {
439
- model: config.delegation?.model
440
- ? modelOf(config.delegation.model, "delegation.model")
441
- : model,
442
- thinking: config.delegation?.thinking ?? "medium",
443
- },
444
- locale: config.locale ?? "en",
445
- timeZone: config.timeZone ?? "UTC",
446
- speakers: {
447
- ...(config.speakers?.admins ? { admins: config.speakers.admins } : {}),
448
- ...(config.speakers?.members ? { members: config.speakers.members } : {}),
449
- },
450
- background: { perPrincipal: { ...config.background?.perPrincipal } },
451
- toolTiers: config.toolTiers ?? {},
452
- prompts: config.prompts ?? {},
453
- agents: config.agents ?? [],
454
- agentServer:
455
- agentServer && (agentGuild || (config.agents?.length ?? 0) > 0),
456
- agentTools:
457
- typeof config.agentServer === "object"
458
- ? config.agentServer.tools
459
- : "full",
460
- ...(!agentGuild && config.agents?.[0]
461
- ? { coordinator: config.coordinator ?? config.agents[0].name }
462
- : {}),
463
- team: teamOf(config.team),
464
- characters: {
465
- skins: skinsOf(config.characters?.skins),
466
- refreshAvatars: config.characters?.refreshAvatars ?? false,
467
- },
468
- ...(http
469
- ? {
470
- http: {
471
- ...(http.publicUrl ? { publicUrl: http.publicUrl } : {}),
472
- port: http.port ?? 3000,
473
- ...(http.hostname ? { hostname: http.hostname } : {}),
474
- ...(http.socketPath ? { socketPath: http.socketPath } : {}),
475
- ...(http.socketMode === undefined
476
- ? {}
477
- : { socketMode: http.socketMode }),
478
- },
479
- }
480
- : {}),
481
- ...(config.avatar ? { avatar: config.avatar } : {}),
482
- workDir: config.workDir ?? `${config.dataDir}/work`,
483
- scratchDir: config.scratchDir ?? join(tmpdir(), `${slug}-scratch`),
484
- // Without Discord and without agents there is no one to carry skills, so the addon is off.
485
- skills: agentServer
486
- ? (config.skills ?? (discord || config.agents?.length ? {} : false))
487
- : false,
488
- memory: config.memory ?? true,
489
- ...(ops ? { ops } : {}),
490
- opsKey: config.ops ? "ops" : "routing.places.ops",
491
- ...(routing ? { routing } : {}),
492
- helpers: agentServer ? helpersOf(config.helpers) : false,
493
- drainMs: (config.drainSeconds ?? DRAIN_LIMIT_MS / 1_000) * 1_000,
494
- ...limitsOf(config),
495
- interimText: config.interimText ?? "on",
496
- interimPrimaryChars: config.interimPrimaryChars ?? PRIMARY_CHARS,
497
- plugins: config.plugins ?? [],
498
- };
499
- }
@@ -0,0 +1,51 @@
1
+ import { ConfigError } from "../domain/errors.ts";
2
+ import type { Tier } from "../identity/speakers.ts";
3
+ import type { ResolvedConfig, RoundtableConfig } from "./config.ts";
4
+
5
+ /** The tiers `"shared"` gives the tools a selection opens to everyone it serves. */
6
+ export const SHARED_TOOL_TIERS: Readonly<Record<string, Tier>> = {
7
+ generate_image: "member",
8
+ poll_create: "member",
9
+ poll_end: "member",
10
+ };
11
+
12
+ /** The preset a configuration chose, and each setting it filled in. */
13
+ export type ResolvedPreset = NonNullable<ResolvedConfig["preset"]>;
14
+
15
+ /** The settings a preset may fill in. */
16
+ interface PresetValues {
17
+ imageTool: NonNullable<RoundtableConfig["imageTool"]>;
18
+ toolTiers: Record<string, Tier>;
19
+ preset?: ResolvedPreset;
20
+ }
21
+
22
+ /**
23
+ * The image tool's mode and the tool tiers, with the preset's defaults under what the
24
+ * configuration wrote; without `preset`, exactly what it wrote. `"shared"` is a host many people
25
+ * talk to, each in conversations of their own, so it needs `runner`: their shell and file tools
26
+ * must not run on the host. Its picture and poll tools are then theirs where a selection names them.
27
+ */
28
+ export function presetValues(config: RoundtableConfig): PresetValues {
29
+ const written = config.toolTiers ?? {};
30
+ if (config.preset !== "shared")
31
+ return {
32
+ imageTool: config.imageTool ?? "every-selection",
33
+ toolTiers: written,
34
+ };
35
+ if (!config.runner)
36
+ throw new ConfigError(
37
+ 'config runner: required by preset: "shared", whose conversations run bash, read, edit and write in the runner\'s container. Add runner: { driver: "socket", socket } beside a sidecar or { driver: "docker", image }, or remove preset.',
38
+ );
39
+ const set: string[] = [];
40
+ if (config.imageTool === undefined) set.push('imageTool: "selected"');
41
+ const tiers = Object.entries(SHARED_TOOL_TIERS).filter(
42
+ ([tool]) => written[tool] === undefined,
43
+ );
44
+ for (const [tool, tier] of tiers)
45
+ set.push(`toolTiers.${tool}: ${JSON.stringify(tier)}`);
46
+ return {
47
+ imageTool: config.imageTool ?? "selected",
48
+ toolTiers: { ...Object.fromEntries(tiers), ...written },
49
+ preset: { name: "shared", set },
50
+ };
51
+ }
@@ -0,0 +1,175 @@
1
+ import { tmpdir } from "node:os";
2
+ import { join } from "node:path";
3
+ import { CATALOG, type Hex } from "../../characters/index.ts";
4
+ import { ConfigError } from "../domain/errors.ts";
5
+ import { type ModelRef, parseModelRef } from "../domain/models.ts";
6
+ import { runnerSettings } from "../runner/settings.ts";
7
+ import { PRIMARY_CHARS } from "../runtime/interim-text.ts";
8
+ import { accessOf } from "./access.ts";
9
+ import { liftAdapters, resolvedDiscord } from "./adapters.ts";
10
+ import {
11
+ checkAgentGuild,
12
+ checkAgentServerOff,
13
+ checkAgentTeamKeys,
14
+ } from "./agent-team.ts";
15
+ import type { ResolvedConfig, RoundtableConfig } from "./config.ts";
16
+ import { configSchema, DRAIN_LIMIT_MS } from "./config-schema.ts";
17
+ import { helpersOf } from "./helpers.ts";
18
+ import { limitsOf } from "./limits.ts";
19
+ import { opsOf, opsOfPlace } from "./ops.ts";
20
+ import { presetValues } from "./preset.ts";
21
+ import { profileRulesOf } from "./profiles.ts";
22
+ import { routingOf } from "./routing.ts";
23
+ import { teamOf } from "./team.ts";
24
+
25
+ /** Logged once when the top-level `ops` is set: it is an alias of the `ops` place. */
26
+ export const OPS_DEPRECATION =
27
+ "`ops` is an alias of `routing.places.ops` since 0.27 and goes away in 1.0; move it there";
28
+
29
+ /** Logged once when `avatar` is set: agents are composed characters and no picture is drawn from it. */
30
+ export const AVATAR_DEPRECATION =
31
+ "agents are composed characters since 0.23; `avatar` is ignored";
32
+
33
+ function modelOf(value: string, path: string): ModelRef {
34
+ const parsed = parseModelRef(value);
35
+ if (!parsed)
36
+ throw new ConfigError(
37
+ `config ${path}: expected <provider>/<id>, got ${JSON.stringify(value)}. Write it like anthropic/claude-sonnet-5-5.`,
38
+ );
39
+ return parsed;
40
+ }
41
+
42
+ /** The skin tones the configuration chose, or the package's own. */
43
+ function skinsOf(skins: readonly string[] | undefined): readonly Hex[] {
44
+ return (skins as readonly Hex[] | undefined) ?? CATALOG.skins;
45
+ }
46
+
47
+ /** The configuration checked against its schema, defaults filled; throws a ConfigError naming the key and the fix. */
48
+ export function resolveConfig(input: unknown): ResolvedConfig {
49
+ const config = configSchema.check(
50
+ liftAdapters(input),
51
+ "",
52
+ ) as RoundtableConfig;
53
+ const name = config.name ?? "Roundtable";
54
+ const model = modelOf(config.model, "model");
55
+ const thinking = config.thinking ?? "medium";
56
+ const { discord, http } = config;
57
+ const agentServer = config.agentServer !== false;
58
+ if (!agentServer) checkAgentServerOff(config);
59
+ // Whether the agents have Discord channels: with `discord.guild`, else they live in the app's rooms.
60
+ const agentGuild = checkAgentGuild(config, agentServer);
61
+ checkAgentTeamKeys(config, agentGuild);
62
+ const slug =
63
+ discord?.rootCommand ?? name.toLowerCase().replace(/[^a-z0-9-]+/g, "-");
64
+ const routing = routingOf(config.routing, {
65
+ withDiscord: agentGuild,
66
+ agentServer:
67
+ agentServer && (agentGuild || (config.agents?.length ?? 0) > 0),
68
+ topLevelOps: config.ops !== undefined,
69
+ });
70
+ const ops = opsOf(config.ops, agentGuild) ?? opsOfPlace(routing?.places.ops);
71
+ const access = accessOf(config, discord !== undefined);
72
+ const { primaryOwner } = access;
73
+ const { imageTool, toolTiers, preset } = presetValues(config);
74
+ return {
75
+ name,
76
+ slug,
77
+ ...(preset ? { preset } : {}),
78
+ ...access,
79
+ profiles: profileRulesOf(config.profiles),
80
+ deprecations: [
81
+ ...access.deprecations,
82
+ ...(config.avatar ? [AVATAR_DEPRECATION] : []),
83
+ ...(config.ops ? [OPS_DEPRECATION] : []),
84
+ ],
85
+ owner: {
86
+ id: primaryOwner.id,
87
+ name: primaryOwner.name,
88
+ pronouns: primaryOwner.pronouns,
89
+ },
90
+ ...(discord ? { discord: resolvedDiscord(discord, slug) } : {}),
91
+ databaseUrl: config.database.url,
92
+ dataDir: config.dataDir,
93
+ attachments: config.attachments?.retention
94
+ ? { retention: config.attachments.retention }
95
+ : {},
96
+ conversations: {
97
+ keepDays: { ...config.conversations?.keepDays },
98
+ ...(config.conversations?.keep
99
+ ? { keep: config.conversations.keep }
100
+ : {}),
101
+ },
102
+ agentDir: config.agentDir ?? `${config.dataDir}/pi`,
103
+ model,
104
+ thinking,
105
+ judge: {
106
+ model: config.judge?.model
107
+ ? modelOf(config.judge.model, "judge.model")
108
+ : model,
109
+ threshold: config.judge?.threshold ?? 0.6,
110
+ },
111
+ ...(config.effortPolicy ? { effortPolicy: config.effortPolicy } : {}),
112
+ delegation: {
113
+ model: config.delegation?.model
114
+ ? modelOf(config.delegation.model, "delegation.model")
115
+ : model,
116
+ thinking: config.delegation?.thinking ?? "medium",
117
+ },
118
+ locale: config.locale ?? "en",
119
+ timeZone: config.timeZone ?? "UTC",
120
+ speakers: {
121
+ ...(config.speakers?.admins ? { admins: config.speakers.admins } : {}),
122
+ ...(config.speakers?.members ? { members: config.speakers.members } : {}),
123
+ },
124
+ background: { perPrincipal: { ...config.background?.perPrincipal } },
125
+ imageTool,
126
+ ...(config.runner ? { runner: runnerSettings(config.runner) } : {}),
127
+ toolTiers,
128
+ prompts: config.prompts ?? {},
129
+ agents: config.agents ?? [],
130
+ agentServer:
131
+ agentServer && (agentGuild || (config.agents?.length ?? 0) > 0),
132
+ agentTools:
133
+ typeof config.agentServer === "object"
134
+ ? config.agentServer.tools
135
+ : "full",
136
+ ...(!agentGuild && config.agents?.[0]
137
+ ? { coordinator: config.coordinator ?? config.agents[0].name }
138
+ : {}),
139
+ team: teamOf(config.team),
140
+ characters: {
141
+ skins: skinsOf(config.characters?.skins),
142
+ refreshAvatars: config.characters?.refreshAvatars ?? false,
143
+ },
144
+ ...(http
145
+ ? {
146
+ http: {
147
+ ...(http.publicUrl ? { publicUrl: http.publicUrl } : {}),
148
+ port: http.port ?? 3000,
149
+ ...(http.hostname ? { hostname: http.hostname } : {}),
150
+ ...(http.socketPath ? { socketPath: http.socketPath } : {}),
151
+ ...(http.socketMode === undefined
152
+ ? {}
153
+ : { socketMode: http.socketMode }),
154
+ },
155
+ }
156
+ : {}),
157
+ ...(config.avatar ? { avatar: config.avatar } : {}),
158
+ workDir: config.workDir ?? `${config.dataDir}/work`,
159
+ scratchDir: config.scratchDir ?? join(tmpdir(), `${slug}-scratch`),
160
+ // Without Discord and without agents there is no one to carry skills, so the addon is off.
161
+ skills: agentServer
162
+ ? (config.skills ?? (discord || config.agents?.length ? {} : false))
163
+ : false,
164
+ memory: config.memory ?? true,
165
+ ...(ops ? { ops } : {}),
166
+ opsKey: config.ops ? "ops" : "routing.places.ops",
167
+ ...(routing ? { routing } : {}),
168
+ helpers: agentServer ? helpersOf(config.helpers) : false,
169
+ drainMs: (config.drainSeconds ?? DRAIN_LIMIT_MS / 1_000) * 1_000,
170
+ ...limitsOf(config),
171
+ interimText: config.interimText ?? "on",
172
+ interimPrimaryChars: config.interimPrimaryChars ?? PRIMARY_CHARS,
173
+ plugins: config.plugins ?? [],
174
+ };
175
+ }
@@ -0,0 +1,80 @@
1
+ import { isAbsolute } from "node:path";
2
+ import { ConfigError } from "../domain/errors.ts";
3
+ import { TIERS } from "../identity/speakers.ts";
4
+ import { RUNNER_CEILINGS } from "../runner/protocol.ts";
5
+ import type { RunnerConfig } from "../runner/settings.ts";
6
+ import {
7
+ type Field,
8
+ guarded,
9
+ integer,
10
+ number,
11
+ oneOf,
12
+ optional,
13
+ shape,
14
+ } from "./schema.ts";
15
+
16
+ /** What every driver's `runner` setting may say of the limits. */
17
+ const limits = {
18
+ commandTimeoutMs: optional(integer(1_000, RUNNER_CEILINGS.commandTimeoutMs)),
19
+ maxOutputBytes: optional(integer(1_024, RUNNER_CEILINGS.maxOutputBytes)),
20
+ maxFileBytes: optional(integer(1_024, RUNNER_CEILINGS.maxFileBytes)),
21
+ keepDays: optional(integer(1, 3_650)),
22
+ minTier: optional(oneOf(...TIERS)),
23
+ };
24
+
25
+ /** An image reference docker takes as one argument; never one that reads as an option. */
26
+ const image = guarded(
27
+ "an image name, such as pi-roundtable-runner or registry/name:tag",
28
+ (value): value is string =>
29
+ typeof value === "string" && /^[A-Za-z0-9][\w./:@-]*$/.test(value),
30
+ );
31
+
32
+ /** A container name as docker accepts it. */
33
+ const containerName = guarded(
34
+ "a container name of letters, digits, _ . and -",
35
+ (value): value is string =>
36
+ typeof value === "string" && /^[A-Za-z0-9][\w.-]{0,127}$/.test(value),
37
+ );
38
+
39
+ const absolutePath = guarded(
40
+ "an absolute path",
41
+ (value): value is string =>
42
+ typeof value === "string" && value !== "" && isAbsolute(value),
43
+ );
44
+
45
+ const docker = shape({
46
+ driver: oneOf("docker" as const),
47
+ image,
48
+ name: optional(containerName),
49
+ memoryMb: optional(integer(64, 1_048_576)),
50
+ cpus: optional(number(0.1, 1_024)),
51
+ pids: optional(integer(16, 4_194_304)),
52
+ ...limits,
53
+ });
54
+
55
+ const socket = shape({
56
+ driver: oneOf("socket" as const),
57
+ socket: absolutePath,
58
+ ...limits,
59
+ });
60
+
61
+ const DESCRIBE =
62
+ '{ driver: "docker", image } or { driver: "socket", socket }, with optional limits';
63
+
64
+ /** The `runner` setting: a container the host runs, or a sidecar's socket; see `RunnerConfig`. */
65
+ export const runnerField: Field<RunnerConfig> = {
66
+ describe: DESCRIBE,
67
+ check: (value, path) => {
68
+ const driver =
69
+ typeof value === "object" && value !== null && !Array.isArray(value)
70
+ ? (value as { driver?: unknown }).driver
71
+ : undefined;
72
+ if (driver === "docker") return docker.check(value, path);
73
+ if (driver === "socket") return socket.check(value, path);
74
+ if (driver === undefined && (typeof value !== "object" || value === null))
75
+ return guarded(DESCRIBE, (_): _ is never => false).check(value, path);
76
+ throw new ConfigError(
77
+ `config ${path}.driver: expected "docker" or "socket", got ${JSON.stringify(driver) ?? "nothing"}. Fix the value in roundtable.config.ts.`,
78
+ );
79
+ },
80
+ };
@@ -0,0 +1,71 @@
1
+ import type { ChannelKey } from "../domain/sessions.ts";
2
+
3
+ /** What a surface's native polls hold: the most answers, characters, and time it takes. */
4
+ export interface PollLimits {
5
+ /** The most answers one poll offers; at least 2. */
6
+ answers: number;
7
+ /** The most characters of the question. */
8
+ questionChars: number;
9
+ /** The most characters of one answer. */
10
+ answerChars: number;
11
+ /** The longest a poll may stay open, in ms. */
12
+ maxDurationMs: number;
13
+ }
14
+
15
+ /** A poll to post: its question, its answers in order, and when it closes. */
16
+ export interface SurfacePoll {
17
+ question: string;
18
+ answers: readonly string[];
19
+ /** Whether a voter may pick more than one answer. */
20
+ multi: boolean;
21
+ /**
22
+ * When the poll should close. A surface that counts its time more coarsely, such as Discord in
23
+ * whole hours, keeps it open at least this long; the host ends it at this time with `end`.
24
+ */
25
+ closesAt: Date;
26
+ }
27
+
28
+ /** One person who voted, as the surface shows them: their id on the network and their display name. */
29
+ export interface PollVoter {
30
+ id: string;
31
+ name: string;
32
+ }
33
+
34
+ /** A poll's count once it ended, one entry per answer in the order the answers were posted. */
35
+ export interface PollResults {
36
+ answers: {
37
+ text: string;
38
+ votes: number;
39
+ /** Who chose it, as many as the surface lists (Discord lists at most 100). */
40
+ voters: PollVoter[];
41
+ /** True when `voters` lists fewer people than `votes` counts. */
42
+ votersCut: boolean;
43
+ }[];
44
+ /**
45
+ * How many people voted: the sum of the votes of a single-choice poll, and the distinct voters
46
+ * listed of a multiple-choice one, which undercounts when a list was cut.
47
+ */
48
+ totalVoters: number;
49
+ }
50
+
51
+ /**
52
+ * A surface's native polls, which an agent posts with `poll_create`: anyone who can see the channel
53
+ * votes, and the host reads the results once it ends. A surface without them makes the poll tools
54
+ * refuse.
55
+ */
56
+ export interface SurfacePolls {
57
+ readonly limits: PollLimits;
58
+ /**
59
+ * Posts the poll in the channel; resolves to the surface's own id of it, which `end` and
60
+ * `results` take. Rejects with a plain message when the surface refuses, such as for a missing
61
+ * permission.
62
+ */
63
+ post(channel: ChannelKey, poll: SurfacePoll): Promise<{ pollId: string }>;
64
+ /** Closes the poll to new votes; a poll already ended, or deleted, resolves as well. */
65
+ end(channel: ChannelKey, pollId: string): Promise<void>;
66
+ /**
67
+ * The poll's count, read after `end`; `"gone"` when its message was deleted or its channel is no
68
+ * longer there. Rejects when it cannot be read now, so the host tries again later.
69
+ */
70
+ results(channel: ChannelKey, pollId: string): Promise<PollResults | "gone">;
71
+ }
@@ -103,6 +103,18 @@ export interface AgentSessions {
103
103
  modelOf(name: string): { model: string; thinking: ThinkingSetting };
104
104
  /** The channel the scope's turns run in: the group's for a seat in one, else the agent's own. */
105
105
  turnChannel(scope: AgentTurnScope): ChannelKey;
106
+ /**
107
+ * The home whose workspace the scope's turns use when the runner serves them: a temp knight's
108
+ * origin's, so it shares its parent's files as it shares the workspace on the host; left out,
109
+ * the scope's own home.
110
+ */
111
+ runnerHome?(scope: AgentTurnScope): ChannelKey;
112
+ /**
113
+ * Whether only the owners reach the agent's conversation, such as its room on the web app, so
114
+ * its turns keep the host's shell and files on a host with a runner, as the owner's own
115
+ * conversations do. Left out, none is: every agent conversation the runner may serve, it serves.
116
+ */
117
+ ownersOnly?(scope: AgentTurnScope): boolean;
106
118
  /**
107
119
  * Whose turns in an agent's conversation load memory: `"everyone"` (the default) lets each
108
120
  * speaker read their own, `"owners"` only the owners, so a speaker below the owner tier gets no