pi-roundtable 0.8.0 → 0.9.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.
Files changed (150) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +35 -11
  3. package/README.zh-TW.md +27 -10
  4. package/docs/migration-0.9.md +247 -0
  5. package/docs/plugins.md +606 -78
  6. package/examples/channel-context.test.ts +88 -0
  7. package/examples/channel-context.ts +62 -0
  8. package/examples/echo-runtime.test.ts +1 -0
  9. package/examples/fake-surface.test.ts +69 -6
  10. package/examples/fake-surface.ts +73 -7
  11. package/examples/headless.ts +5 -1
  12. package/examples/prechecks.test.ts +1 -0
  13. package/examples/principals.test.ts +60 -0
  14. package/examples/principals.ts +48 -0
  15. package/examples/prompt.test.ts +1 -1
  16. package/examples/study-room.test.ts +29 -1
  17. package/examples/study-room.ts +16 -19
  18. package/examples/support-desk.test.ts +3 -1
  19. package/examples/tools.test.ts +6 -1
  20. package/package.json +5 -2
  21. package/src/cli/checks/database.ts +11 -0
  22. package/src/cli/checks/identity.ts +225 -0
  23. package/src/cli/checks/model.ts +21 -3
  24. package/src/cli/cli.ts +115 -1
  25. package/src/cli/config-edit.ts +83 -13
  26. package/src/cli/doctor.ts +7 -0
  27. package/src/cli/line-diff.ts +72 -0
  28. package/src/cli/principal.ts +412 -0
  29. package/src/cli/project.ts +5 -0
  30. package/src/cli/report.ts +12 -3
  31. package/src/cli/upgrade-rewrite.ts +102 -0
  32. package/src/cli/upgrade-source.ts +430 -0
  33. package/src/cli/upgrade.ts +176 -0
  34. package/src/core/agents/agent-claim.ts +56 -34
  35. package/src/core/agents/team-turns.ts +8 -4
  36. package/src/core/builtin/agent-server.ts +9 -7
  37. package/src/core/builtin/discord-admin.ts +4 -1
  38. package/src/core/builtin/discord.ts +71 -13
  39. package/src/core/builtin/modules.ts +140 -85
  40. package/src/core/builtin/stores.ts +40 -21
  41. package/src/core/config/access.ts +229 -0
  42. package/src/core/config/adapters.ts +64 -1
  43. package/src/core/config/config.ts +78 -41
  44. package/src/core/contract/channel-context.ts +53 -0
  45. package/src/core/contract/channels.ts +77 -9
  46. package/src/core/contract/runtime.ts +23 -7
  47. package/src/core/contract/surface.ts +22 -6
  48. package/src/core/conversations/conversation-registry.ts +14 -0
  49. package/src/core/conversations/conversation-store.ts +13 -0
  50. package/src/core/define-roundtable.ts +41 -11
  51. package/src/core/discord/agent-panel.ts +2 -2
  52. package/src/core/discord/card-audience.ts +148 -0
  53. package/src/core/discord/channel-context.ts +348 -0
  54. package/src/core/discord/connection.ts +15 -3
  55. package/src/core/discord/direct-channel.ts +54 -0
  56. package/src/core/discord/discord-owners.ts +133 -0
  57. package/src/core/discord/discord-surface.ts +69 -14
  58. package/src/core/discord/fresh-marker.ts +24 -0
  59. package/src/core/discord/inbound-message.ts +21 -7
  60. package/src/core/discord/interaction-module.ts +11 -1
  61. package/src/core/discord/owner-cards-fixture.ts +80 -0
  62. package/src/core/discord/owner-cards.ts +58 -97
  63. package/src/core/discord/owner-command.ts +27 -13
  64. package/src/core/discord/stop-button.ts +4 -4
  65. package/src/core/domain/conversation.ts +7 -2
  66. package/src/core/domain/errors.ts +5 -0
  67. package/src/core/domain/ports.ts +27 -2
  68. package/src/core/host.ts +27 -8
  69. package/src/core/i18n/cards.ts +8 -4
  70. package/src/core/identity/access-policy.ts +227 -0
  71. package/src/core/identity/actor-facts.ts +65 -0
  72. package/src/core/identity/caching-principal-store.ts +111 -0
  73. package/src/core/identity/config-owner.ts +145 -0
  74. package/src/core/identity/contact.ts +27 -0
  75. package/src/core/identity/identity-plugin.ts +56 -0
  76. package/src/core/identity/identity-schema.ts +282 -0
  77. package/src/core/identity/identity-service.ts +489 -0
  78. package/src/core/identity/identity-view.ts +77 -0
  79. package/src/core/identity/plugin-identities.ts +109 -0
  80. package/src/core/identity/principal-reads.ts +38 -0
  81. package/src/core/identity/principal-store.ts +478 -0
  82. package/src/core/identity/principal-tables.ts +53 -0
  83. package/src/core/identity/seen-throttle.ts +57 -0
  84. package/src/core/identity/ulid.ts +36 -0
  85. package/src/core/identity.ts +34 -5
  86. package/src/core/interactions/prompts.ts +127 -0
  87. package/src/core/modules/background/background-turns.ts +56 -17
  88. package/src/core/modules/background/personal-target.ts +50 -0
  89. package/src/core/modules/delegation/delegate.ts +28 -14
  90. package/src/core/modules/delegation/delegator.ts +23 -7
  91. package/src/core/modules/memory/owner-memory.ts +123 -50
  92. package/src/core/modules/notify/notify.ts +53 -13
  93. package/src/core/modules/notify/session-notify.ts +110 -0
  94. package/src/core/modules/schedules/prechecks.ts +8 -2
  95. package/src/core/modules/schedules/schedule-prechecks.ts +4 -1
  96. package/src/core/modules/schedules/schedule-store.ts +51 -20
  97. package/src/core/modules/schedules/schedule-tools.ts +122 -12
  98. package/src/core/modules/schedules/scheduler.ts +43 -2
  99. package/src/core/modules/schedules/schedules.ts +43 -14
  100. package/src/core/plugin.ts +48 -0
  101. package/src/core/presence/direct-channels.ts +104 -0
  102. package/src/core/registry/contributions.ts +63 -3
  103. package/src/core/routing/channel-router.ts +218 -17
  104. package/src/core/routing/conversation-turns.ts +38 -8
  105. package/src/core/routing/surface-port.ts +32 -2
  106. package/src/core/routing/system-turns.ts +29 -0
  107. package/src/core/runtime/bridge-guard.ts +225 -0
  108. package/src/core/runtime/compaction-tiers.ts +5 -1
  109. package/src/core/runtime/conversation-sessions.ts +124 -12
  110. package/src/core/runtime/extensions/ask-user.ts +1 -1
  111. package/src/core/runtime/extensions/confirmation-gate.ts +28 -14
  112. package/src/core/runtime/extensions/private-memory.ts +447 -0
  113. package/src/core/runtime/pending-confirmation-store.ts +30 -5
  114. package/src/core/runtime/pi-agent-runtime.ts +135 -134
  115. package/src/core/runtime/preflight-tools.ts +47 -0
  116. package/src/core/runtime/prompt-slot.ts +4 -4
  117. package/src/core/runtime/reader-history.ts +129 -0
  118. package/src/core/runtime/runtime-plugin.ts +50 -5
  119. package/src/core/runtime/runtime-types.ts +40 -12
  120. package/src/core/runtime/session-conversation.ts +143 -0
  121. package/src/core/runtime/session-factory.ts +115 -15
  122. package/src/core/runtime/session-scope.ts +78 -0
  123. package/src/core/runtime/steerable-run.ts +9 -0
  124. package/src/core/runtime/tool-call-scope.ts +43 -0
  125. package/src/core/runtime/turn-answer.ts +30 -1
  126. package/src/core/services.ts +27 -1
  127. package/src/core/sessions.ts +30 -0
  128. package/src/core/speakers.ts +21 -19
  129. package/src/core/testing/background.ts +31 -0
  130. package/src/core/testing/fixture-database.ts +55 -0
  131. package/src/core/testing/map-identity.ts +76 -0
  132. package/src/core/testing/module-sessions.ts +134 -0
  133. package/src/core/testing/modules.ts +108 -21
  134. package/src/core/testing/owner.ts +17 -0
  135. package/src/core/testing/surface-contract.ts +118 -41
  136. package/src/core/testing/test-host.ts +79 -16
  137. package/src/core/testing/tool-set.ts +32 -0
  138. package/src/core/tool-set.snapshot.json +4 -4
  139. package/src/core/tool-tiers.ts +57 -3
  140. package/src/discord/index.ts +8 -0
  141. package/src/index.ts +47 -8
  142. package/src/kit/compaction.ts +13 -0
  143. package/src/kit/index.ts +10 -0
  144. package/src/kit/support.ts +1 -1
  145. package/src/testing.ts +55 -16
  146. package/templates/.env.example +1 -1
  147. package/templates/adapters/web/README.md +7 -0
  148. package/templates/adapters/web/roundtable.config.ts +14 -10
  149. package/templates/roundtable.config.ts +12 -1
  150. package/src/core/domain/owner-prompts.ts +0 -45
@@ -1,3 +1,5 @@
1
+ import type { ChannelKey } from "../domain/conversation.ts";
2
+ import type { RoundtablePlugin } from "../plugin.ts";
1
3
  import { ASK_USER_TOOL } from "../runtime/extensions/ask-user.ts";
2
4
  import { COMPACT_TOOL } from "../runtime/extensions/self-compact-guard.ts";
3
5
  import { AGENTS } from "../services.ts";
@@ -16,6 +18,36 @@ export const seat: AgentTurnScope = {
16
18
  group: "war-room",
17
19
  };
18
20
 
21
+ /**
22
+ * The conversations the recorded sessions live in, served as a host serves them: the owner's
23
+ * direct messages by an app's claim, such as one that answers the owner there, and the agent's
24
+ * channel by the agent server; both answer background turns, so their sessions schedule and
25
+ * delegate. Give it to the test host the tool set is captured on.
26
+ */
27
+ export function servedConversations(
28
+ ownerChannel: ChannelKey,
29
+ ): RoundtablePlugin {
30
+ const served = new Set<ChannelKey>([ownerChannel, scout.home, seat.home]);
31
+ return {
32
+ name: "served-conversations",
33
+ setup: () => ({
34
+ channels: [
35
+ {
36
+ name: "served-conversations",
37
+ priority: 0,
38
+ owns: (channel) => served.has(channel),
39
+ admit: () => undefined,
40
+ background: async () => ({
41
+ status: "skipped",
42
+ reason: "the tool set's host runs no background turns",
43
+ }),
44
+ startFresh: async () => "owner",
45
+ },
46
+ ],
47
+ }),
48
+ };
49
+ }
50
+
19
51
  /** Tools the core's own extensions and pi-web-access register, which no fake session here loads. */
20
52
  const NAMED_ELSEWHERE = [
21
53
  ASK_USER_TOOL,
@@ -37,7 +37,7 @@
37
37
  "memory_add",
38
38
  "memory_remove",
39
39
  "memory_search",
40
- "notify_owner",
40
+ "notify",
41
41
  "schedule_cancel",
42
42
  "schedule_create",
43
43
  "schedule_list",
@@ -92,7 +92,7 @@
92
92
  "memory_remove",
93
93
  "memory_search",
94
94
  "message_agent",
95
- "notify_owner",
95
+ "notify",
96
96
  "schedule_cancel",
97
97
  "schedule_create",
98
98
  "schedule_list",
@@ -179,7 +179,7 @@
179
179
  "memory_add",
180
180
  "memory_remove",
181
181
  "memory_search",
182
- "notify_owner",
182
+ "notify",
183
183
  "schedule_cancel",
184
184
  "schedule_create",
185
185
  "schedule_list",
@@ -272,7 +272,7 @@
272
272
  "memory_remove": "member",
273
273
  "memory_search": "member",
274
274
  "message_agent": "member",
275
- "notify_owner": "owner",
275
+ "notify": "owner",
276
276
  "read": "owner",
277
277
  "read_attachment": "member",
278
278
  "schedule_cancel": "admin",
@@ -1,4 +1,5 @@
1
1
  import { PluginError } from "./errors.ts";
2
+ import type { Logger } from "./log.ts";
2
3
  import { ASK_USER_TOOL } from "./runtime/extensions/ask-user.ts";
3
4
  import { COMPACT_TOOL } from "./runtime/extensions/self-compact-guard.ts";
4
5
  import { type Tier, tierAtLeast } from "./speakers.ts";
@@ -27,6 +28,40 @@ export const CORE_TOOL_TIERS: Readonly<Record<string, Tier>> = set("member", [
27
28
  "read_attachment",
28
29
  ]);
29
30
 
31
+ /**
32
+ * Tools renamed since 0.8, by their old name: until 1.0 the old name still names the tool in a
33
+ * selection, a task's `exclude`, a plugin's `requiredTools`, and the operator's and plugins'
34
+ * `toolTiers`, where the new name's own setting wins.
35
+ */
36
+ export const RENAMED_TOOLS: Readonly<Record<string, string>> = {
37
+ notify_owner: "notify",
38
+ };
39
+
40
+ const warnedAliases = new WeakMap<Logger, Set<string>>();
41
+
42
+ /** Each logger warns once for an old name used in tiers or selections. */
43
+ function warnAliases(tools: readonly string[], logger: Logger): void {
44
+ const warned = warnedAliases.get(logger) ?? new Set<string>();
45
+ warnedAliases.set(logger, warned);
46
+ for (const tool of tools) {
47
+ const renamed = RENAMED_TOOLS[tool];
48
+ if (!renamed || warned.has(tool)) continue;
49
+ warned.add(tool);
50
+ logger.warn(
51
+ `deprecated: ${tool} is now ${renamed}; update selections and toolTiers before 1.0`,
52
+ );
53
+ }
54
+ }
55
+
56
+ /** The tools named, each by its current name and once, in order. */
57
+ export function currentToolNames(
58
+ tools: readonly string[],
59
+ logger?: Logger,
60
+ ): string[] {
61
+ if (logger) warnAliases(tools, logger);
62
+ return [...new Set(tools.map((tool) => RENAMED_TOOLS[tool] ?? tool))];
63
+ }
64
+
30
65
  /**
31
66
  * What each tool needs: the operator's setting first, then the tier its plugin declared, then
32
67
  * the core's default, and the owner for a tool nobody named. Plugins declare theirs when the
@@ -38,7 +73,15 @@ export class ToolTierTable implements ToolTiers {
38
73
  readonly #core = new Map(Object.entries(CORE_TOOL_TIERS));
39
74
 
40
75
  constructor(operator: Readonly<Record<string, Tier>> = {}) {
41
- this.#operator = new Map(Object.entries(operator));
76
+ const entries = Object.entries(operator);
77
+ // An old name first, so the new name's own setting overrides it.
78
+ this.#operator = new Map([
79
+ ...entries.flatMap(([tool, tier]) => {
80
+ const renamed = RENAMED_TOOLS[tool];
81
+ return renamed ? [[renamed, tier] as const] : [];
82
+ }),
83
+ ...entries,
84
+ ]);
42
85
  }
43
86
 
44
87
  /**
@@ -46,7 +89,16 @@ export class ToolTierTable implements ToolTiers {
46
89
  * plugin declaring its own tool again, as when the host retries its start, replaces it.
47
90
  */
48
91
  declare(plugin: string, tiers: Readonly<Record<string, Tier>>): void {
49
- for (const [tool, tier] of Object.entries(tiers)) {
92
+ const entries = Object.entries(tiers);
93
+ // An old name is the new name's, declared first so the new name's own tier wins.
94
+ const named = [
95
+ ...entries.flatMap(([tool, tier]) => {
96
+ const renamed = RENAMED_TOOLS[tool];
97
+ return renamed ? [[renamed, tier] as const] : [];
98
+ }),
99
+ ...entries.filter(([tool]) => !RENAMED_TOOLS[tool]),
100
+ ];
101
+ for (const [tool, tier] of named) {
50
102
  const other = this.#declared.get(tool);
51
103
  if (other && other.plugin !== plugin)
52
104
  throw new PluginError(
@@ -73,11 +125,13 @@ export class ToolTierTable implements ToolTiers {
73
125
  /** The core's tiers with the operator's on top; plugins add theirs through `declare`. */
74
126
  export function toolTiers(
75
127
  operator: Readonly<Record<string, Tier>> = {},
128
+ logger?: Logger,
76
129
  ): ToolTierTable {
130
+ if (logger) warnAliases(Object.keys(operator), logger);
77
131
  return new ToolTierTable(operator);
78
132
  }
79
133
 
80
- /** The tools a tier may use, in order; a turn nobody spoke in has the owner's tier. */
134
+ /** The tools a tier may use, in order; a turn's tier is its speaker's, and a turn without one is refused. */
81
135
  export function toolsForTier(
82
136
  tools: readonly string[],
83
137
  tier: Tier,
@@ -4,12 +4,19 @@
4
4
  export type { DiscordServices } from "../core/builtin/discord.ts";
5
5
  export { DISCORD } from "../core/builtin/discord.ts";
6
6
  export type { DiscordAdapterConfig } from "../core/config/config.ts";
7
+ export type {
8
+ ChannelContext,
9
+ ChannelContextMessage,
10
+ ChannelContextOptions,
11
+ } from "../core/contract/channel-context.ts";
12
+ export { withChannelContext } from "../core/contract/channel-context.ts";
7
13
  export type { AgentPanelMessage } from "../core/discord/agent-commands.ts";
8
14
  export type {
9
15
  AgentPanel,
10
16
  AgentPanelOptions,
11
17
  } from "../core/discord/agent-panel.ts";
12
18
  export { agentPanel } from "../core/discord/agent-panel.ts";
19
+ export { CHANNEL_CONTEXT_DEFAULTS } from "../core/discord/channel-context.ts";
13
20
  export type { ManagedChannel } from "../core/discord/channel-executor.ts";
14
21
  export {
15
22
  fetchManagedChannel,
@@ -35,6 +42,7 @@ export type {
35
42
  DiscordConnection,
36
43
  } from "../core/discord/connection.ts";
37
44
  export { discord } from "../core/discord/discord-adapter.ts";
45
+ export type { DiscordActor } from "../core/discord/discord-owners.ts";
38
46
  export type {
39
47
  CommandGuard,
40
48
  CommandRegistrar,
package/src/index.ts CHANGED
@@ -20,8 +20,14 @@ export {
20
20
  AGENT_SERVER_PLUGIN,
21
21
  AGENT_TEAM_SERVICE,
22
22
  } from "./core/builtin/agent-server.ts";
23
+ export type {
24
+ AccessConfig,
25
+ AccessOwnerConfig,
26
+ AccessTierConfig,
27
+ } from "./core/config/access.ts";
23
28
  export type {
24
29
  AdapterConfig,
30
+ BackgroundConfig,
25
31
  DiscordConfig,
26
32
  Pronouns,
27
33
  RoundtableConfig,
@@ -30,6 +36,7 @@ export type {
30
36
  export type {
31
37
  Admission,
32
38
  AttachmentRef,
39
+ BackgroundRunsAs,
33
40
  BackgroundTarget,
34
41
  BackgroundTurn,
35
42
  ChannelClaim,
@@ -93,6 +100,7 @@ export {
93
100
  AgentRunError,
94
101
  ConfigError,
95
102
  DelegationError,
103
+ IdentityError,
96
104
  MemoryError,
97
105
  ScheduleError,
98
106
  } from "./core/domain/errors.ts";
@@ -101,14 +109,7 @@ export type {
101
109
  InterimPosts,
102
110
  InterimTextMode,
103
111
  } from "./core/domain/interim.ts";
104
- export type {
105
- Approval,
106
- AskOption,
107
- OwnerAnswer,
108
- OwnerPrompts,
109
- OwnerQuestion,
110
- } from "./core/domain/owner-prompts.ts";
111
- export type { TurnRequest } from "./core/domain/ports.ts";
112
+ export type { TurnConversation, TurnRequest } from "./core/domain/ports.ts";
112
113
  export type { TurnProgress } from "./core/domain/progress.ts";
113
114
  export type { DrainOptions } from "./core/drain.ts";
114
115
  export {
@@ -133,9 +134,39 @@ export type {
133
134
  WebSocketSendResult,
134
135
  } from "./core/http/websocket.ts";
135
136
  export type { Locale } from "./core/i18n/index.ts";
137
+ export type {
138
+ AccessOwner,
139
+ AccessRules,
140
+ AccessTier,
141
+ } from "./core/identity/access-policy.ts";
142
+ export type { ActorFacts } from "./core/identity/actor-facts.ts";
143
+ export type { IdentityService } from "./core/identity/identity-service.ts";
144
+ export type {
145
+ IdentityLink,
146
+ IdentityRef,
147
+ LinkSource,
148
+ Principal,
149
+ RoleGrant,
150
+ RoleSource,
151
+ } from "./core/identity/principal-store.ts";
152
+ export { SYSTEM_PRINCIPAL } from "./core/identity/principal-store.ts";
153
+ export type {
154
+ Approval,
155
+ AskOption,
156
+ OwnerAnswer,
157
+ OwnerPrompts,
158
+ OwnerQuestion,
159
+ PromptScope,
160
+ Prompts,
161
+ } from "./core/interactions/prompts.ts";
162
+ export { promptScope } from "./core/interactions/prompts.ts";
136
163
  export type { JudgeModel } from "./core/judging/model-judge.ts";
137
164
  export type { LogEntry, LogFn, Logger } from "./core/log.ts";
138
165
  export type { ThinkingLevel, ThinkingSetting } from "./core/models.ts";
166
+ export {
167
+ PERSONAL_TARGET,
168
+ type PerPrincipalLimits,
169
+ } from "./core/modules/background/personal-target.ts";
139
170
  export type {
140
171
  DelegationJob,
141
172
  DelegationOutcome,
@@ -184,6 +215,7 @@ export type {
184
215
  LinkedSessions,
185
216
  Persona,
186
217
  PluginContext,
218
+ PluginIdentity,
187
219
  PromptSection,
188
220
  PromptTurn,
189
221
  RoundtablePlugin,
@@ -194,6 +226,11 @@ export type {
194
226
  TurnEvent,
195
227
  TurnProgressEvent,
196
228
  } from "./core/plugin.ts";
229
+ export type {
230
+ DirectChannelProvider,
231
+ DirectChannels,
232
+ DirectReach,
233
+ } from "./core/presence/direct-channels.ts";
197
234
  export {
198
235
  attachReplyFile,
199
236
  REPLY_FILE_LIMITS,
@@ -223,6 +260,7 @@ export {
223
260
  BACKGROUND_TURNS,
224
261
  CONVERSATIONS,
225
262
  DELEGATION,
263
+ IDENTITY,
226
264
  MEMORY,
227
265
  PRECHECKS,
228
266
  RUNTIME,
@@ -233,6 +271,7 @@ export type {
233
271
  AgentTurnScope,
234
272
  ChannelKey,
235
273
  SessionContext,
274
+ SessionConversation,
236
275
  SessionPlan,
237
276
  SessionTool,
238
277
  SessionToolSnapshot,
@@ -12,3 +12,16 @@ export {
12
12
  HARD_COMPACT_TOKENS,
13
13
  SOFT_COMPACT_TOKENS,
14
14
  } from "../core/runtime/compaction-tiers.ts";
15
+ export type { MemoryView } from "../core/runtime/extensions/private-memory.ts";
16
+ export {
17
+ hidesPrivateExchange,
18
+ memoryProjection,
19
+ privateCompaction,
20
+ summaryProjection,
21
+ } from "../core/runtime/extensions/private-memory.ts";
22
+ export {
23
+ bridgeHistoryHidesMemory,
24
+ carriesMemory,
25
+ MEMORY_TURN_ENTRY,
26
+ recordMemoryTurn,
27
+ } from "../core/runtime/reader-history.ts";
package/src/kit/index.ts CHANGED
@@ -18,13 +18,22 @@ export type {
18
18
  CompactionEngine,
19
19
  CompactionHistory,
20
20
  LatestCompaction,
21
+ MemoryView,
21
22
  } from "./compaction.ts";
22
23
  export {
24
+ bridgeHistoryHidesMemory,
23
25
  COMPACT_HEADROOM_TOKENS,
24
26
  CompactionTiers,
27
+ carriesMemory,
25
28
  compactionEngine,
26
29
  HARD_COMPACT_TOKENS,
30
+ hidesPrivateExchange,
31
+ MEMORY_TURN_ENTRY,
32
+ memoryProjection,
33
+ privateCompaction,
34
+ recordMemoryTurn,
27
35
  SOFT_COMPACT_TOKENS,
36
+ summaryProjection,
28
37
  } from "./compaction.ts";
29
38
  export { scrubDiagnostic } from "./diagnostics.ts";
30
39
  export type {
@@ -122,6 +131,7 @@ export type {
122
131
  DashboardBoard,
123
132
  DelegationWorker,
124
133
  GroupMessage,
134
+ Notifier,
125
135
  OwnerNotifier,
126
136
  SpeakerFacts,
127
137
  SpeakerPolicy,
@@ -13,7 +13,7 @@ export type {
13
13
  export type { Backlog, GroupMessage } from "../core/agents/agent-rules.ts";
14
14
  export type { AgentOps } from "../core/agents/agent-tools.ts";
15
15
  export type { ThreadHost } from "../core/discord/dispatch-threads.ts";
16
- export type { OwnerNotifier } from "../core/domain/ports.ts";
16
+ export type { Notifier, OwnerNotifier } from "../core/domain/ports.ts";
17
17
  export type { ThinkingPicker } from "../core/models.ts";
18
18
  export type { DelegationWorker } from "../core/modules/delegation/delegator.ts";
19
19
  export type { AgentChannelLookup } from "../core/modules/schedules/schedules.ts";
package/src/testing.ts CHANGED
@@ -3,8 +3,8 @@ import { tmpdir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
5
5
  import type { SQL } from "bun";
6
- import { agentClaim, OWNER_TARGET } from "./core/agents/agent-claim.ts";
7
- import { DISCORD } from "./core/builtin/discord.ts";
6
+ import { agentClaim } from "./core/agents/agent-claim.ts";
7
+ import { DISCORD, type DiscordServices } from "./core/builtin/discord.ts";
8
8
  import type {
9
9
  ConversationPort,
10
10
  InboundMessage,
@@ -24,7 +24,10 @@ import type {
24
24
  CommandRegistrar,
25
25
  InteractionContribution,
26
26
  } from "./core/discord/interaction-module.ts";
27
- import { OwnerGuard, ownerRootCommand } from "./core/discord/owner-command.ts";
27
+ import {
28
+ commandGuard,
29
+ ownerRootCommand,
30
+ } from "./core/discord/owner-command.ts";
28
31
  import type {
29
32
  PendingConfirmation,
30
33
  ReplyFile,
@@ -32,10 +35,12 @@ import type {
32
35
  import { NotLinkedError, PluginError } from "./core/errors.ts";
33
36
  import { EventBus } from "./core/events.ts";
34
37
  import type { HoldCheck } from "./core/holds.ts";
38
+ import { contactsOf } from "./core/identity/identity-view.ts";
35
39
  import type { OwnerIdentity } from "./core/identity.ts";
36
40
  import { ConfirmationJudge } from "./core/judging/confirmation-judge.ts";
37
41
  import { silentLogger } from "./core/log.ts";
38
42
  import { ConversationBackgroundTurns } from "./core/modules/background/background-turns.ts";
43
+ import { PERSONAL_TARGET } from "./core/modules/background/personal-target.ts";
39
44
  import type {
40
45
  Contribution,
41
46
  HostEnv,
@@ -69,10 +74,12 @@ import {
69
74
  type AgentServer,
70
75
  BACKGROUND_TURNS,
71
76
  CONVERSATIONS,
77
+ IDENTITY,
72
78
  RUNTIME,
73
79
  } from "./core/services.ts";
74
80
  import type { ChannelKey, SessionContext } from "./core/sessions.ts";
75
- import { type Speaker, speakerPolicy } from "./core/speakers.ts";
81
+ import { type Speaker, THE_SPEAKER } from "./core/speakers.ts";
82
+ import { mapIdentity } from "./core/testing/map-identity.ts";
76
83
  import { type ToolTierTable, toolTiers } from "./core/tool-tiers.ts";
77
84
 
78
85
  // Fixtures for plugin tests.
@@ -107,6 +114,7 @@ export type {
107
114
  } from "./core/testing/recording-logger.ts";
108
115
  export { recordingLogger } from "./core/testing/recording-logger.ts";
109
116
  export type {
117
+ SurfaceContractAnswerer,
110
118
  SurfaceContractFailure,
111
119
  SurfaceContractSubject,
112
120
  SurfaceObservation,
@@ -155,20 +163,30 @@ export interface FakeDiscord {
155
163
  /**
156
164
  * A `DISCORD` service for a plugin that adds slash commands, without a Discord connection: the
157
165
  * plugin's `commands.add` calls are recorded, and `compose()` shows the tree Discord would get.
158
- * `rootCommand` is the root command's name, `roundtable` by default. Only `commands` and `guard` are given; reading another member throws.
166
+ * `rootCommand` is the root command's name, `roundtable` by default. `channelContext` is what
167
+ * `DISCORD.channelContext` answers, by default no context, as on a host with it off. Only
168
+ * `commands`, `guard`, and `channelContext` are given; reading another member throws.
159
169
  */
160
170
  export function fakeDiscord(
161
- options: { ownerId?: string; rootCommand?: string } = {},
171
+ options: {
172
+ ownerId?: string;
173
+ rootCommand?: string;
174
+ channelContext?: DiscordServices["channelContext"];
175
+ } = {},
162
176
  ): FakeDiscord {
163
177
  const collection = new CommandCollection();
164
178
  const { rootCommand = "roundtable" } = options;
165
- const guard = new OwnerGuard(
166
- options.ownerId ?? "owner",
167
- silentLogger(),
168
- rootCommand,
169
- );
179
+ const guard = commandGuard({
180
+ ownerId: options.ownerId ?? "owner",
181
+ root: rootCommand,
182
+ logger: silentLogger(),
183
+ });
170
184
  return {
171
- service: servicePair(DISCORD, { commands: collection.registrar, guard }),
185
+ service: servicePair(DISCORD, {
186
+ commands: collection.registrar,
187
+ guard,
188
+ channelContext: options.channelContext ?? (async () => undefined),
189
+ }),
172
190
  commands: collection.registrar,
173
191
  guard,
174
192
  added: () => collection.added(),
@@ -201,7 +219,9 @@ export interface TestPluginOptions {
201
219
  * host supplies anyway: `BACKGROUND_TURNS`, the real background turns over the test's router,
202
220
  * and, once `AGENTS` is given, its `approvals` (the real confirmation judge over
203
221
  * `providers.judge`, when the test gives a judge). Giving `AGENTS` a `team` adds the agent
204
- * server's own claim to the router, answering as the host's would for the `owner`.
222
+ * server's own claim to the router, answering as the host's would for the `owner`. The router
223
+ * resolves who wrote each message through a given `IDENTITY`; without one only the `owner` is
224
+ * anyone, at the owner tier, their principal their id.
205
225
  */
206
226
  services?: readonly ServicePair[];
207
227
  /**
@@ -333,6 +353,7 @@ export async function testPlugin(
333
353
  (router ?? unlinked("conversations")).handle(message),
334
354
  background: async (turn) =>
335
355
  (router ?? unlinked("conversations")).background(turn),
356
+ runsAs: async (turn) => (router ?? unlinked("conversations")).runsAs(turn),
336
357
  target: (name) => (router ?? unlinked("conversations")).target(name),
337
358
  startFresh: async (channel) =>
338
359
  (router ?? unlinked("conversations")).startFresh(channel),
@@ -344,6 +365,8 @@ export async function testPlugin(
344
365
  owns: (channel) => (router ?? unlinked("conversations")).owns(channel),
345
366
  takesBackground: (channel) =>
346
367
  (router ?? unlinked("conversations")).takesBackground(channel),
368
+ takesSystemReports: (channel) =>
369
+ (router ?? unlinked("conversations")).takesSystemReports(channel),
347
370
  ...options.conversations,
348
371
  };
349
372
  const surfaces = surfacePort(() =>
@@ -463,7 +486,7 @@ export async function testPlugin(
463
486
  }),
464
487
  );
465
488
  services.checkRequires();
466
- const context: Omit<PluginContext, "services"> = {
489
+ const context: Omit<PluginContext, "services" | "directChannels"> = {
467
490
  logger,
468
491
  env,
469
492
  sessions: () => linked ?? unlinked("sessions"),
@@ -496,13 +519,17 @@ export async function testPlugin(
496
519
  const team = given.get(AGENTS.id)?.given;
497
520
  const agentServer = team && "team" in team ? services.get(AGENTS) : undefined;
498
521
  const attachmentDir = mkdtempSync(join(tmpdir(), "roundtable-test-plugin-"));
522
+ const identity = services.find(IDENTITY);
523
+ // Who wrote a message, and whom a background turn runs as: by the given IDENTITY, else the owner alone, at the owner tier.
524
+ const people = mapIdentity({ owners: [owner.id] });
499
525
  router = new ChannelRouter({
526
+ contacts: identity ? contactsOf(identity) : people,
527
+ principals: identity ?? people,
500
528
  claims: [
501
529
  ...(agentServer
502
530
  ? [
503
531
  agentClaim({
504
532
  owner,
505
- speakers: speakerPolicy({ owners: [owner.id] }),
506
533
  // SAFETY: the claim reads the concrete team's members (guildId, owns, answerOwner, answerGroup, answerBackground, startFresh), which a test that gives a team for it supplies.
507
534
  team: agentServer.team as unknown as Parameters<
508
535
  typeof agentClaim
@@ -514,6 +541,13 @@ export async function testPlugin(
514
541
  surface: surfaces,
515
542
  attachmentDir: () => attachmentDir,
516
543
  logger,
544
+ // As on a host: the given DISCORD's channel context, when the test gives one.
545
+ channelContext: async (message) =>
546
+ (
547
+ given.get(DISCORD.id)?.given as
548
+ | Partial<DiscordServices>
549
+ | undefined
550
+ )?.channelContext?.(message),
517
551
  }),
518
552
  ]
519
553
  : []),
@@ -521,7 +555,9 @@ export async function testPlugin(
521
555
  ],
522
556
  targets: (name) =>
523
557
  registry.backgroundTargets.find((t) => t.name === name) ??
524
- (agentServer && name === OWNER_TARGET.name ? OWNER_TARGET : undefined),
558
+ (agentServer && name === PERSONAL_TARGET.name
559
+ ? PERSONAL_TARGET
560
+ : undefined),
525
561
  queue,
526
562
  logger,
527
563
  ...(options.forwardJoinMs === undefined
@@ -586,6 +622,9 @@ export async function testPlugin(
586
622
  homeChannel: channel,
587
623
  turnChannel: channel,
588
624
  compaction: { wrap: (factory) => factory },
625
+ conversation: { visibility: "shared" },
626
+ addressee: THE_SPEAKER,
627
+ memory: "speaker",
589
628
  speaker: () => runOptions?.speaker,
590
629
  runTask: async () => {
591
630
  throw new Error("test session cannot run tasks");
@@ -7,7 +7,7 @@ DISCORD_TOKEN=
7
7
  DISCORD_GUILD_ID=
8
8
  DISCORD_ENTRY_CHANNEL_ID=
9
9
 
10
- # You: the one owner who can change everything (right-click your name, Copy User ID).
10
+ # You: the owner, who can change everything; OWNER_ID is your Discord user id (right-click your name, Copy User ID).
11
11
  OWNER_ID=
12
12
  OWNER_NAME=
13
13
 
@@ -9,6 +9,13 @@ People your OpenID Connect provider signs in chat with the assistant in private
9
9
 
10
10
  The chat is under `/chat`: a web page gets a one-time ticket from `POST /chat/tickets` with the person's token, and opens `/chat/socket` with it.
11
11
  The protocol is in `node_modules/pi-roundtable-webchat/README.md`.
12
+ Core `access` in `roundtable.config.ts` decides admission; token roles are prefixed with `web:role:` there.
13
+ New admitted users get principals, and linked Discord/web identities share private memory and quotas.
14
+ Link identities with `bunx roundtable principal link <principal> <identity>`; use `principal list` to inspect them.
15
+
16
+ The private inbox is `GET /chat/notices`, with `POST /chat/notices/<id>/read` to acknowledge an entry.
17
+ Online connections also receive additive `notice` frames.
18
+ Schedules and delegated reports can answer in their creator's private conversation; enable their tools in the persona selection only where intended and allowed by tier.
12
19
 
13
20
  `roundtable.config.ts` holds the settings and lists the plugins; `plugins/` holds yours, and `persona/assistant.md` is the assistant's prompt.
14
21
  Add another plugin with `bunx roundtable add plugin <name>`, and test it with `bun test`.
@@ -14,8 +14,17 @@ const list = (name: string): string[] =>
14
14
 
15
15
  export default {
16
16
  name: "Roundtable",
17
- // The operator who runs this host. People sign in through your OpenID Connect provider instead.
18
- owner: { id: "operator", name: env("OWNER_NAME") },
17
+ // The operator who runs this host, as the host's owner. People sign in through your OpenID
18
+ // Connect provider instead; core access maps their verified, surface-prefixed roles to tiers.
19
+ access: {
20
+ owners: [{ name: env("OWNER_NAME"), principal: "operator" }],
21
+ members: {
22
+ roles: list("CHAT_MEMBER_ROLES").map((role) => `web:role:${role}`),
23
+ },
24
+ admins: {
25
+ roles: list("CHAT_ADMIN_ROLES").map((role) => `web:role:${role}`),
26
+ },
27
+ },
19
28
  database: { url: env("DATABASE_URL") },
20
29
  // Paths are relative to the project directory, where the roundtable command runs.
21
30
  dataDir: "./data",
@@ -33,20 +42,15 @@ export default {
33
42
  issuers: [env("OIDC_ISSUER")],
34
43
  audiences: [env("OIDC_AUDIENCE")],
35
44
  }),
36
- // Members and admins come from the token's roles; owners only from speaker ids you list.
37
- access: {
38
- members: { roles: list("CHAT_MEMBER_ROLES") },
39
- admins: { roles: list("CHAT_ADMIN_ROLES") },
40
- },
41
45
  origins: list("CHAT_ORIGINS"),
42
46
  personas: [
43
47
  {
44
48
  kind: "assistant",
45
49
  label: "Assistant",
46
50
  prompt: () => readFileSync("./persona/assistant.md", "utf8"),
47
- // The tools of its turns, by name. Leave out schedule_* and delegate_task, which a web
48
- // conversation cannot hear back from, and web_search and fetch_content unless people
49
- // may make this server fetch any address, internal ones included.
51
+ // The tools of its turns, by name. Schedules, delegated reports and notify can reach
52
+ // this private conversation; add those tools only where intended and permitted by tier.
53
+ // Leave out web_search and fetch_content unless people may make the server fetch any address.
50
54
  selection: { tools: ["hello_greet"], groups: [] },
51
55
  },
52
56
  ],
@@ -8,7 +8,18 @@ const env = (name: string): string => process.env[name] ?? "";
8
8
 
9
9
  export default {
10
10
  name: "Roundtable",
11
- owner: { id: env("OWNER_ID"), name: env("OWNER_NAME") },
11
+ // Who the host serves. You are the owner: your principal and your Discord identity are your
12
+ // Discord user id. Add admins and members by Discord user or role, such as
13
+ // members: { roles: ["discord:role:<role id>"] }.
14
+ access: {
15
+ owners: [
16
+ {
17
+ name: env("OWNER_NAME"),
18
+ principal: env("OWNER_ID"),
19
+ identities: [`discord:${env("OWNER_ID")}`],
20
+ },
21
+ ],
22
+ },
12
23
  discord: {
13
24
  token: env("DISCORD_TOKEN"),
14
25
  guild: env("DISCORD_GUILD_ID"),