@sentry/junior 0.301.0 → 0.302.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 (79) hide show
  1. package/dist/adapter-context-Cx9fn9B3.js +43 -0
  2. package/dist/{admin-CRJHvCGg.js → admin-_poE5NKL.js} +2 -2
  3. package/dist/{agent-runner-H4YhvNBj.js → agent-runner-CY9RvsTX.js} +1380 -10601
  4. package/dist/api/schema.d.ts +2 -2
  5. package/dist/api/schema.js +4 -5
  6. package/dist/api.d.ts +1 -1
  7. package/dist/api.js +91 -68
  8. package/dist/{app-HDZglaIu.d.ts → app-BpY3wtRP.d.ts} +2 -2
  9. package/dist/app.d.ts +1 -1
  10. package/dist/app.js +66 -296
  11. package/dist/{background-compaction-queue-CNrZ3QcU.js → background-compaction-queue-CXFq1_Cz.js} +94 -203
  12. package/dist/{briefs-x6Mzwxmg.js → briefs-B3NG-pid.js} +2 -2
  13. package/dist/{catalog-runtime-BEY6EGRi.js → catalog-runtime-Dss0lSV6.js} +1 -1
  14. package/dist/cli/chat.js +15 -15
  15. package/dist/cli/check.js +3 -3
  16. package/dist/cli/main.js +3 -3
  17. package/dist/cli/plugins.js +4 -4
  18. package/dist/cli/snapshot-create.js +4 -4
  19. package/dist/cli/upgrade.d.ts +1 -1
  20. package/dist/cli/upgrade.js +3 -3
  21. package/dist/{config-CmjhyqgB.js → config-CzeZiMKs.js} +2 -2
  22. package/dist/{connections-CfIRm0xv.js → connections-CDYhMfrs.js} +6 -6
  23. package/dist/{continue-in-slack-DPoABVkB.js → continue-in-slack-7Uf05ndC.js} +5 -6
  24. package/dist/{conversation-feed-CfpyFMHP.js → conversation-feed-Clf_cv0n.js} +1 -0
  25. package/dist/{conversation-privacy-0CM0V2qK.js → conversation-privacy-D9xnM5mK.js} +1 -1
  26. package/dist/{conversation-turn-C0sxyvS-.js → conversation-turn-D7SEZgTG.js} +15 -16
  27. package/dist/{credential-sync-tEMKZ_8M.js → credential-sync-DoD0gW-j.js} +13 -15
  28. package/dist/{db-Czra10QW.js → db-B-gtnNjr.js} +314 -5
  29. package/dist/{db-BdUHQhrC.d.ts → db-BdsCzytP.d.ts} +1 -1
  30. package/dist/{executor-D_023K0H.js → executor-DZg20EqU.js} +39 -4
  31. package/dist/install-t1KQyTUs.js +228 -0
  32. package/dist/instrumentation.js +2 -2
  33. package/dist/{state-CEbZuZD6.js → legacy-web-actor-id-C-cEeWqL.js} +33 -4
  34. package/dist/{lineage-DmMIE0VL.js → lineage-C79GjoQr.js} +2 -2
  35. package/dist/{logging-DcjLDDqi.js → logging-C9oDAg4M.js} +7 -3
  36. package/dist/{message-C0JY9RJP.js → message-BLUCzJXN.js} +8 -8
  37. package/dist/{model-input-CBp-p24N.js → model-input-5jwNC45G.js} +3 -3
  38. package/dist/nitro.d.ts +1 -1
  39. package/dist/nitro.js +4 -3
  40. package/dist/{oauth-callback-server-BRq9QNhU.js → oauth-callback-server-BBl66vCb.js} +2 -2
  41. package/dist/{projection-CQNDOi82.js → projection-CIBwgD3s.js} +282 -64
  42. package/dist/{prompt-DLUB5m72.js → prompt-CRQbzp5e.js} +14 -4
  43. package/dist/queue-DtCDaIct.js +115 -0
  44. package/dist/{registry-Dj377ADs.js → registry-DdFQHZ_d.js} +1 -1
  45. package/dist/{resolve-DJkh9Fky.js → resolve-CdW4BdrK.js} +4 -229
  46. package/dist/{result-C8iIpDl1.js → result-oOMv1t4O.js} +9 -9
  47. package/dist/{runner-DZqrOy8C.js → runner-DqitLtm-.js} +8 -8
  48. package/dist/{sandbox-egress-signals-CGwH86S9.js → sandbox-egress-signals-Bw9I0yfJ.js} +1 -1
  49. package/dist/{schema-CdZFn7Qd.d.ts → schema-BIFM-U1a.d.ts} +441 -30
  50. package/dist/{schema-DyHXiQKI.js → schema-DnVQepWP.js} +66 -29
  51. package/dist/{service-account-D6jGR4a1.js → service-account-B6mKAPVo.js} +3 -3
  52. package/dist/{service-account-suY004dx.js → service-account-CrZftRTb.js} +257 -6
  53. package/dist/{session-stop-BLmfFI3d.js → session-stop-DW63Z3kj.js} +543 -548
  54. package/dist/{skills-CmNG0dHb.js → skills-C16fz60Z.js} +2 -2
  55. package/dist/{slack-conversation-unfurl-Bty-DlHe.js → slack-conversation-unfurl-BHhefEb7.js} +8 -7
  56. package/dist/{spawn-CNjkpXpk.js → spawn-D_RnFYfy.js} +6 -6
  57. package/dist/{stop-Bjy2-K4H.js → stop-7p1i08CY.js} +724 -106
  58. package/dist/{store-DmV4CoNr.js → store-C28I0CVW.js} +5 -5
  59. package/dist/{task-queue-AhG1tSXR.js → task-queue-BVUJbQ28.js} +3 -3
  60. package/dist/{task-runner-BMxZI3o7.js → task-runner-CWi8j7Z6.js} +6 -8
  61. package/dist/{thread-context-CXLnbg7g.js → thread-context-D3-yYUd0.js} +7 -7
  62. package/dist/{store-Epv6t4vV.js → turn-session-routing-BFMS9ATF.js} +381 -10
  63. package/dist/{turn-user-message-DsUZi9gn.js → turn-user-message-C3-O8Omt.js} +3 -3
  64. package/dist/{validation-DOz8X9BU.js → validation-BSFKUIb4.js} +1 -1
  65. package/dist/{version-CGMRmMPK.js → version-BHHXNi-0.js} +1 -1
  66. package/dist/version.js +1 -1
  67. package/dist/{viewer-H3EsMWtJ.js → viewer-B1SO21Qa.js} +3 -3
  68. package/dist/warmup-Bz9bzkzN.js +13927 -0
  69. package/dist/{statuses-Hn-HsOph.js → web-message-id-lNodcCOI.js} +136 -1
  70. package/dist/{worker-ClphajjD.js → worker-BspReIIK.js} +7 -7
  71. package/migrations/0108_conversation_embeddings.sql +13 -0
  72. package/migrations/meta/0108_snapshot.json +4688 -0
  73. package/migrations/meta/_journal.json +7 -0
  74. package/package.json +8 -6
  75. package/dist/adapter-CNjGEJO9.js +0 -303
  76. package/dist/reporting-window-DopzcOHh.js +0 -137
  77. package/dist/turn-session-routing-BD3-jJl7.js +0 -380
  78. package/dist/users-BxvYclQg.js +0 -424
  79. package/dist/warmup-CdU5hR49.js +0 -3715
@@ -1,18 +1,17 @@
1
1
  import { v as __exportAll } from "./sentry-BRTJqumy.js";
2
- import { Bn as SCRIPT_TOOLS_SECTION_TAG, Da as postSlackMessage, Di as verifyTimerWatchCredentialSubject, Fn as retainRuntimeTurnContext, Hn as TURN_CONTEXT_TAG, In as stripRuntimeTurnContext, Io as buildSentryConversationUrl, Jn as renderUntrustedTag, Ki as listWorkspaces, Kn as renderChildTag, M as normalizeConversationText, Nn as latestTurnContextSection, Nr as getReviewItem, Oi as JUNIOR_THREAD_STATE_TTL_MS, Rn as CAPABILITY_SECTION_TAG, Tn as hasRuntimeTurnContext, Un as escapeClosingTags, Vn as SESSION_CONTEXT_SECTION_TAG, Wn as escapeTagText, Yn as tagJson, _a as slackMention, cr as getPluginSlackConversationLink, ct as listTurnSummaries, di as cancelSubscriptions, do as sandboxSkillFile, dr as getPluginUserPromptContributions, eo as ToolInputError, fn as NO_REPLY_TOOL_NAME, fo as sandboxSkillPathResolution, fr as getPlugins, ha as normalizeSlackReplyMarkdown, in as REPLY_TOOL_NAME, ji as getDashboardObjectIconLink, ki as getDashboardConversationLink, lo as SANDBOX_WORKSPACE_ROOT, lr as getPluginSystemPromptContributions, ma as formatSlackLink, oo as SANDBOX_DATA_ROOT, ot as getStoredTurnFields, pa as escapeSlackMrkdwnText, qn as renderTag$1, so as SANDBOX_REPOS_ROOT, st as getTurnRecord, uo as sandboxSkillDir, vn as REPORT_BLOCKED_TOOL_NAME, x as toStoredConversationMessage, zn as REQUEST_CONTEXT_SECTION_TAG } from "./projection-CQNDOi82.js";
3
- import { I as renderCurrentInstruction, R as escapeXml, n as botConfig, z as escapeXmlText } from "./config-CmjhyqgB.js";
4
- import { W as normalizeIdentityEmail, h as logWarn, m as logInfo, p as logException, v as serializeGenAiAttribute } from "./logging-DcjLDDqi.js";
2
+ import { Bn as SCRIPT_TOOLS_SECTION_TAG, Da as postSlackMessage, Di as verifyTimerWatchCredentialSubject, Fn as retainRuntimeTurnContext, Hn as TURN_CONTEXT_TAG, In as stripRuntimeTurnContext, Io as buildSentryConversationUrl, Jn as renderUntrustedTag, Ki as listWorkspaces, Kn as renderChildTag, M as normalizeConversationText, Nn as latestTurnContextSection, Nr as getReviewItem, Oi as JUNIOR_THREAD_STATE_TTL_MS, Rn as CAPABILITY_SECTION_TAG, Tn as hasRuntimeTurnContext, Un as escapeClosingTags, Vn as SESSION_CONTEXT_SECTION_TAG, Wn as escapeTagText, Yn as tagJson, _a as slackMention, ct as listTurnSummaries, di as cancelSubscriptions, do as sandboxSkillFile, eo as ToolInputError, fn as NO_REPLY_TOOL_NAME, fo as sandboxSkillPathResolution, ha as normalizeSlackReplyMarkdown, in as REPLY_TOOL_NAME, ji as getDashboardObjectIconLink, ki as getDashboardConversationLink, lo as SANDBOX_WORKSPACE_ROOT, lr as getPluginUserPromptContributions, ma as formatSlackLink, oo as SANDBOX_DATA_ROOT, or as getPluginSlackConversationLink, ot as getStoredTurnFields, pa as escapeSlackMrkdwnText, qn as renderTag$1, so as SANDBOX_REPOS_ROOT, sr as getPluginSystemPromptContributions, st as getTurnRecord, uo as sandboxSkillDir, ur as getPlugins, vn as REPORT_BLOCKED_TOOL_NAME, x as toStoredConversationMessage, zn as REQUEST_CONTEXT_SECTION_TAG } from "./projection-CIBwgD3s.js";
3
+ import { I as renderCurrentInstruction, R as escapeXml, n as botConfig, z as escapeXmlText } from "./config-CzeZiMKs.js";
4
+ import { G as normalizeIdentityEmail, h as logWarn, m as logInfo, p as logException, v as serializeGenAiAttribute } from "./logging-C9oDAg4M.js";
5
5
  import { o as isUserActor, t as createActor } from "./actor-D2iXzvlN.js";
6
- import { C as isPersonInput, a as getConversationStore, j as SYSTEM_IDENTITY_ID, nt as nextDetailVersion, o as getDb, r as getConversationEventStore, s as getSqlExecutor } from "./db-Czra10QW.js";
7
- import { M as juniorIdentities, N as juniorUsers, j as juniorConversations } from "./executor-D_023K0H.js";
8
- import { r as getStateAdapter } from "./adapter-CNjGEJO9.js";
6
+ import { C as isPersonInput, J as getStateAdapter, M as SYSTEM_IDENTITY_ID, a as getConversationStore, ft as nextDetailVersion, o as getDb, r as getConversationEventStore, s as getSqlExecutor } from "./db-B-gtnNjr.js";
7
+ import { M as juniorConversations, N as juniorIdentities, P as juniorUsers } from "./executor-DZg20EqU.js";
9
8
  import { a as listReferenceFiles, c as soulPathCandidates, l as worldPathCandidates } from "./package-discovery-DJhGdS4c.js";
10
- import { h as credentialSubjectSchema } from "./registry-Dj377ADs.js";
11
- import { i as parseSkillFile } from "./skills-CmNG0dHb.js";
12
- import { a as EVENT_SYSTEM_ACTOR, d as JUNIOR_NATIVE_EVENT_NAMESPACE, h as conversationNoteEvent, i as EVENT_MESSAGE_AUTHOR, o as isEventConversationMessage, r as EVENT_AUTHOR_ID } from "./prompt-DLUB5m72.js";
13
- import { r as appendAndEnqueueInboundMessage } from "./store-DmV4CoNr.js";
14
- import { f as eventCatalogEntry, l as CORE_EVENT_NAMESPACE, p as eventGuidance } from "./turn-session-routing-BD3-jJl7.js";
15
- import { _ as userCustomizationTextSchema, m as isVisionImageMediaType, s as formatUserInputAnswer } from "./statuses-Hn-HsOph.js";
9
+ import { h as credentialSubjectSchema } from "./registry-DdFQHZ_d.js";
10
+ import { i as parseSkillFile } from "./skills-C16fz60Z.js";
11
+ import { a as EVENT_SYSTEM_ACTOR, f as JUNIOR_NATIVE_EVENT_NAMESPACE, g as conversationNoteEvent, i as EVENT_MESSAGE_AUTHOR, o as isEventConversationMessage, r as EVENT_AUTHOR_ID } from "./prompt-CRQbzp5e.js";
12
+ import { bt as eventGuidance, gt as CORE_EVENT_NAMESPACE, yt as eventCatalogEntry } from "./turn-session-routing-BFMS9ATF.js";
13
+ import { c as formatUserInputAnswer, h as isVisionImageMediaType, v as userCustomizationTextSchema } from "./web-message-id-lNodcCOI.js";
14
+ import { r as appendAndEnqueueInboundMessage } from "./store-C28I0CVW.js";
16
15
  import * as z from "zod";
17
16
  import path from "node:path";
18
17
  import { isDeepStrictEqual } from "node:util";
@@ -1115,9 +1114,311 @@ async function buildDeploymentSystemPrompt(platform, mode) {
1115
1114
  const pluginSystemPrompt = buildPluginSystemPromptContributions(await getPluginSystemPromptContributions(platform));
1116
1115
  return [buildSystemPrompt(platform, mode), pluginSystemPrompt].filter((section) => Boolean(section)).join("\n\n");
1117
1116
  }
1118
- /** Hash a system prompt, to compare prompts without storing their text. */
1119
- function systemPromptHash(systemPrompt) {
1120
- return createHash("sha256").update(systemPrompt).digest("hex").slice(0, 16);
1117
+ // src/chat/sandbox/snapshot/events.ts
1118
+ const WORKSPACE_SNAPSHOT_NAMESPACE = CORE_EVENT_NAMESPACE;
1119
+ const WORKSPACE_SNAPSHOT_RESOURCE_TYPE = "workspace_snapshot";
1120
+ const WORKSPACE_SNAPSHOT_READY_EVENT = "workspace_snapshot.ready";
1121
+ const WORKSPACE_SNAPSHOT_FAILED_EVENT = "workspace_snapshot.failed";
1122
+ /**
1123
+ * Core catalog entry for Workspace snapshot ready and failed events.
1124
+ *
1125
+ * Uses the same registration shape as plugins so search, guidance, and tool
1126
+ * schemas treat these events like any other resource type. Snapshot finish
1127
+ * does not run event-automation ingest, so only watches can use these events.
1128
+ */
1129
+ function workspaceSnapshotEvents() {
1130
+ return {
1131
+ resourceTypes: [{
1132
+ type: WORKSPACE_SNAPSHOT_RESOURCE_TYPE,
1133
+ supportedEvents: [WORKSPACE_SNAPSHOT_READY_EVENT, WORKSPACE_SNAPSHOT_FAILED_EVENT],
1134
+ suggestedEvents: []
1135
+ }],
1136
+ events: {
1137
+ [WORKSPACE_SNAPSHOT_READY_EVENT]: {
1138
+ reach: "resource",
1139
+ guidance: "Call switchWorkspace again with the same Workspace name. Do not create another watch when switchWorkspace already returned a subscription."
1140
+ },
1141
+ [WORKSPACE_SNAPSHOT_FAILED_EVENT]: {
1142
+ reach: "resource",
1143
+ guidance: "Report the snapshot failure. Do not keep waiting for this Workspace unless the user asks to retry."
1144
+ }
1145
+ },
1146
+ limits: { [WORKSPACE_SNAPSHOT_RESOURCE_TYPE]: { automation: false } }
1147
+ };
1148
+ }
1149
+ /** Describe the events that report when a snapshot build ends. */
1150
+ function workspaceSnapshotWatch(input) {
1151
+ return {
1152
+ identifier: input.workspaceId,
1153
+ label: `Workspace ${input.workspaceName} snapshot`,
1154
+ namespace: WORKSPACE_SNAPSHOT_NAMESPACE,
1155
+ supported_events: [WORKSPACE_SNAPSHOT_READY_EVENT, WORKSPACE_SNAPSHOT_FAILED_EVENT],
1156
+ suggested_events: [],
1157
+ type: WORKSPACE_SNAPSHOT_RESOURCE_TYPE
1158
+ };
1159
+ }
1160
+ /** Report that a Workspace snapshot build is ready or failed. */
1161
+ function workspaceSnapshotFinishedEvent(input) {
1162
+ const occurredAtMs = input.occurredAtMs ?? Date.now();
1163
+ const eventType = input.status === "ready" ? WORKSPACE_SNAPSHOT_READY_EVENT : WORKSPACE_SNAPSHOT_FAILED_EVENT;
1164
+ const trustedSummary = input.status === "ready" ? "Workspace snapshot is ready." : "Workspace snapshot build failed.";
1165
+ const event = {
1166
+ eventKey: `${WORKSPACE_SNAPSHOT_NAMESPACE}:${input.workspaceId}:${input.resultId}:${input.status}`,
1167
+ eventType,
1168
+ identifier: input.workspaceId,
1169
+ namespace: WORKSPACE_SNAPSHOT_NAMESPACE,
1170
+ occurredAtMs,
1171
+ terminal: true,
1172
+ trustedSummary,
1173
+ data: {
1174
+ workspaceId: input.workspaceId,
1175
+ status: input.status
1176
+ }
1177
+ };
1178
+ if (input.status === "failed" && input.error) event.untrustedText = input.error;
1179
+ return event;
1180
+ }
1181
+ // src/chat/slack/channel-message-events.ts
1182
+ /**
1183
+ * Slack channel-message Events for Event automations.
1184
+ *
1185
+ * Core publishes these Events from Slack ingress, so the `slack` namespace is
1186
+ * core owned, like `junior`. Anyone in the channel writes the Event text, so an
1187
+ * automation can watch only its own channel and always uses system credentials.
1188
+ */
1189
+ /** Core-owned event namespace for Slack Events. Not a plugin publisher. */
1190
+ const SLACK_EVENT_NAMESPACE = "slack";
1191
+ /** The trigger identifier that names the channel of the automation. */
1192
+ const SLACK_CURRENT_CHANNEL_IDENTIFIER = "current_channel";
1193
+ const CHANNEL_RESOURCE_TYPE = "channel";
1194
+ const MESSAGE_POSTED_EVENT = "message.posted";
1195
+ const CHANNEL_ID_PATTERN = /^[CG][A-Z0-9]{2,}$/;
1196
+ const CHANNEL_LOCATION = "channel";
1197
+ const THREAD_LOCATION = "thread";
1198
+ const CHANNEL_MESSAGE_MATCH_FIELDS = eventMatchFieldsSchema.parse({
1199
+ channelId: {
1200
+ kind: "string",
1201
+ description: "Slack channel ID of the message. It is always the channel where the automation posts.",
1202
+ events: [MESSAGE_POSTED_EVENT]
1203
+ },
1204
+ userId: {
1205
+ kind: "string",
1206
+ description: "Slack user ID of the message author, or the bot ID (B…) of a bot post that has no user, such as an app integration. Required to run on bot posts."
1207
+ },
1208
+ location: {
1209
+ kind: "string",
1210
+ enum: [CHANNEL_LOCATION, THREAD_LOCATION],
1211
+ description: "channel for a top-level message, thread for a thread reply. Leave out for top-level only; thread replies run only when this names thread."
1212
+ }
1213
+ });
1214
+ /**
1215
+ * Event registration for new Slack channel messages and thread replies. Only
1216
+ * event automations can use it, so watchEvents rejects it.
1217
+ */
1218
+ function slackChannelMessageEvents() {
1219
+ return {
1220
+ resourceTypes: [{
1221
+ type: CHANNEL_RESOURCE_TYPE,
1222
+ identifier: {
1223
+ format: `"${SLACK_CURRENT_CHANNEL_IDENTIFIER}" for the channel where the automation is created`,
1224
+ pattern: String.raw`^(?:current_channel|[CG][A-Z0-9]{2,})$`
1225
+ },
1226
+ supportedEvents: [MESSAGE_POSTED_EVENT],
1227
+ suggestedEvents: [],
1228
+ matchFields: CHANNEL_MESSAGE_MATCH_FIELDS
1229
+ }],
1230
+ events: { [MESSAGE_POSTED_EVENT]: {
1231
+ reach: { anyOf: ["channelId"] },
1232
+ guidance: "A person or bot posted a new message in this channel. A bot post runs the automation only when match names the bot in user_id, by its user ID or, for a post with no user, its bot ID. A thread reply runs it only when match.location names thread. A reply goes in the message's Slack thread. If the instructions do not apply to this message, end with no action."
1233
+ } },
1234
+ limits: { [CHANNEL_RESOURCE_TYPE]: {
1235
+ watch: false,
1236
+ watchUnavailableMessage: "Slack channel messages can trigger only an event automation in that channel. Use createAutomation with an event trigger."
1237
+ } }
1238
+ };
1239
+ }
1240
+ /**
1241
+ * Set the `channelId` filter of a Slack channel-message trigger to the
1242
+ * channel where the automation posts. A trigger that names another channel,
1243
+ * or a saved trigger with an identifier, stays as it is for
1244
+ * `requireSlackChannelMessageScope` to check.
1245
+ */
1246
+ function slackChannelMessageTrigger(trigger, channelId) {
1247
+ if (trigger.namespace !== "slack") return trigger;
1248
+ if (trigger.identifier != null || trigger.match?.channelId !== void 0) return trigger;
1249
+ return {
1250
+ ...trigger,
1251
+ match: {
1252
+ ...trigger.match,
1253
+ channelId
1254
+ }
1255
+ };
1256
+ }
1257
+ /**
1258
+ * Bind a Slack channel-message automation to its own channel.
1259
+ *
1260
+ * The trigger names the channel with a `channelId` filter. A saved trigger
1261
+ * can name it with an identifier instead, where `current_channel` means the
1262
+ * destination channel. Reject other channels, so private channel text cannot
1263
+ * reach another channel.
1264
+ */
1265
+ function requireSlackChannelMessageScope(automation) {
1266
+ if (automation.trigger.namespace !== "slack") return automation;
1267
+ const channelId = automation.destination.channelId;
1268
+ if (!CHANNEL_ID_PATTERN.test(channelId)) throw new ToolInputError("A Slack channel-message automation works only in a channel, not in a DM.");
1269
+ const { identifier, match } = automation.trigger;
1270
+ if ((identifier === void 0 ? match?.channelId : identifier === "current_channel" ? channelId : identifier) !== channelId) throw new ToolInputError("A Slack channel-message automation can watch only the channel where it posts. Leave out the channel_id filter, or create the automation in the channel to watch.");
1271
+ return {
1272
+ ...automation,
1273
+ credentialMode: "system",
1274
+ trigger: {
1275
+ ...automation.trigger,
1276
+ ...identifier === void 0 ? void 0 : { identifier: channelId }
1277
+ }
1278
+ };
1279
+ }
1280
+ /**
1281
+ * Build the Event for one new channel message or thread reply, or nothing.
1282
+ *
1283
+ * Slackbot posts do not count. Bot posts are marked with `postedByBot`, so
1284
+ * only automations that name the bot can run on them. Thread replies carry
1285
+ * the `thread` location, so only automations that name it can run on them.
1286
+ */
1287
+ function slackChannelMessageEvent(input) {
1288
+ const { author } = input;
1289
+ if (author.kind === "user" && author.userId === "USLACKBOT") return void 0;
1290
+ if (!CHANNEL_ID_PATTERN.test(input.channelId)) return void 0;
1291
+ const postedByBot = author.kind === "bot" || Boolean(input.botId || input.subtype === "bot_message");
1292
+ const userId = author.kind === "bot" ? author.botId : author.userId;
1293
+ const threadTs = input.threadTs && input.threadTs !== input.ts ? input.threadTs : void 0;
1294
+ return {
1295
+ eventKey: `${input.channelId}:${input.ts}`,
1296
+ eventType: MESSAGE_POSTED_EVENT,
1297
+ identifier: input.channelId,
1298
+ occurredAtMs: Math.floor(Number(input.ts) * 1e3),
1299
+ trustedSummary: `${postedByBot ? "The bot " : ""}${author.kind === "bot" ? author.botId : `<@${author.userId}>`} posted a new ${threadTs ? `thread reply under message ${threadTs}` : "message"} in <#${input.channelId}>.`,
1300
+ data: {
1301
+ channelId: input.channelId,
1302
+ location: threadTs ? THREAD_LOCATION : CHANNEL_LOCATION,
1303
+ messageTs: input.ts,
1304
+ ...threadTs ? { threadTs } : void 0,
1305
+ userId,
1306
+ ...postedByBot ? { postedByBot: true } : void 0
1307
+ },
1308
+ ...input.text?.trim() ? { untrustedText: input.text } : void 0
1309
+ };
1310
+ }
1311
+ /**
1312
+ * Decide whether a channel-message Event may run one automation.
1313
+ *
1314
+ * A message runs only automations that post in its own channel, so private
1315
+ * channel text cannot reach another channel. The trigger already names that
1316
+ * channel, and this check keeps the rule when it does not.
1317
+ * A bot post runs only automations whose match names its author in `userId`.
1318
+ * Bots can post often and would use up the run limit of every other
1319
+ * automation in the channel. A thread reply runs only automations whose
1320
+ * match names the `thread` location, so existing automations stay top-level.
1321
+ */
1322
+ function slackChannelMessageRunsAutomation(event, automation) {
1323
+ if (event.namespace !== "slack") return true;
1324
+ if (event.data?.channelId !== automation.destination.channelId) return false;
1325
+ if (event.data?.location === THREAD_LOCATION && ![automation.trigger.match?.location].flat().includes(THREAD_LOCATION)) return false;
1326
+ if (event.data?.postedByBot !== true) return true;
1327
+ return automation.trigger.match?.userId !== void 0;
1328
+ }
1329
+ /** Return the source message thread for a channel-message run. */
1330
+ function slackChannelMessageReplyThreadTs(event) {
1331
+ if (event.namespace !== "slack") return void 0;
1332
+ const messageTs = event.data?.threadTs ?? event.data?.messageTs;
1333
+ return typeof messageTs === "string" ? messageTs : void 0;
1334
+ }
1335
+ // src/chat/events/runtime-catalog.ts
1336
+ /**
1337
+ * Enabled event registrations for search, guidance, and tool schemas.
1338
+ *
1339
+ * Includes core Workspace snapshot events under the `junior` namespace, Slack
1340
+ * channel-message events under the `slack` namespace, plus every enabled plugin
1341
+ * registration. Plugins may not use the `junior` or `slack` namespaces.
1342
+ */
1343
+ function getEventCatalog() {
1344
+ const snapshot = workspaceSnapshotEvents();
1345
+ const catalog = {
1346
+ [CORE_EVENT_NAMESPACE]: eventCatalogEntry({
1347
+ displayName: botConfig.userName,
1348
+ resourceTypes: [...snapshot.resourceTypes, {
1349
+ type: "timer",
1350
+ supportedEvents: ["timer.fired"],
1351
+ suggestedEvents: []
1352
+ }],
1353
+ events: {
1354
+ ...snapshot.events,
1355
+ "timer.fired": { reach: "resource" }
1356
+ },
1357
+ limits: {
1358
+ ...snapshot.limits,
1359
+ timer: {
1360
+ automation: false,
1361
+ watch: false,
1362
+ watchUnavailableMessage: "Use watchTimer to create a timer Watch."
1363
+ }
1364
+ }
1365
+ }),
1366
+ [SLACK_EVENT_NAMESPACE]: eventCatalogEntry({
1367
+ ...slackChannelMessageEvents(),
1368
+ displayName: "Slack"
1369
+ })
1370
+ };
1371
+ for (const plugin of getPlugins()) {
1372
+ const registration = plugin.events;
1373
+ if (!registration || registration.isEnabled?.() === false) continue;
1374
+ if (plugin.manifest.name === "junior" || plugin.manifest.name === "slack") throw new Error(`Plugin "${plugin.manifest.name}" cannot register events; that namespace is reserved for core events`);
1375
+ catalog[plugin.manifest.name] = eventCatalogEntry({
1376
+ ...registration,
1377
+ displayName: plugin.manifest.displayName
1378
+ });
1379
+ }
1380
+ return catalog;
1381
+ }
1382
+ // src/chat/experimental.ts
1383
+ /**
1384
+ * Known unstable product features that must be opted into explicitly.
1385
+ * Add new keys here as features graduate from private experiments; remove them
1386
+ * once they become stable defaults.
1387
+ */
1388
+ const EXPERIMENTAL_FEATURES = [
1389
+ "operator-tools",
1390
+ "passive-routing",
1391
+ "user-customization"
1392
+ ];
1393
+ const EXPERIMENTAL_FEATURE_SET = new Set(EXPERIMENTAL_FEATURES);
1394
+ let configuredExperimental = {};
1395
+ function isExperimentalFeature(value) {
1396
+ return EXPERIMENTAL_FEATURE_SET.has(value);
1397
+ }
1398
+ /** Replace app-level experimental opt-ins and return the previous setting. */
1399
+ function setExperimentalFeatures(config) {
1400
+ const previous = { ...configuredExperimental };
1401
+ if (config === void 0) {
1402
+ configuredExperimental = {};
1403
+ return previous;
1404
+ }
1405
+ const next = {};
1406
+ for (const [rawName, enabled] of Object.entries(config)) {
1407
+ if (enabled === void 0) continue;
1408
+ if (typeof enabled !== "boolean") throw new Error(`experimental.${rawName} must be a boolean when provided`);
1409
+ if (!isExperimentalFeature(rawName)) throw new Error(`experimental.${rawName} is not a known experimental feature. Known features: ${EXPERIMENTAL_FEATURES.join(", ")}`);
1410
+ next[rawName] = enabled;
1411
+ }
1412
+ configuredExperimental = next;
1413
+ return previous;
1414
+ }
1415
+ /** Return a copy of the app-level experimental opt-ins configured by createApp(). */
1416
+ function getExperimentalFeatures() {
1417
+ return { ...configuredExperimental };
1418
+ }
1419
+ /** Return whether one experimental feature is enabled via createApp({ experimental }). */
1420
+ function isExperimentalFeatureEnabled(feature) {
1421
+ return configuredExperimental[feature] === true;
1121
1422
  }
1122
1423
  // src/chat/conversations/sql/subtree.ts
1123
1424
  /** Columns of the `conversation_subtree` table that `conversationSubtree` returns. */
@@ -1758,526 +2059,261 @@ async function sendSlackReply(args) {
1758
2059
  const blocks = buildSlackReplyBlocks(text, void 0) ?? [];
1759
2060
  for (const card of cards) if (!card.entity) blocks.push({
1760
2061
  type: "section",
1761
- text: {
1762
- type: "mrkdwn",
1763
- text: card.text
1764
- }
1765
- });
1766
- if (isFinalChunk || !text.trim()) blocks.push(...buildSlackReplyBlocks("", footer) ?? []);
1767
- const entities = cards.flatMap((card) => card.entity ? [card.entity] : []);
1768
- const accessibleText = [text, ...cards.map((card) => card.text)].filter(Boolean).join("\n\n");
1769
- const fallbackText = isFinalChunk && args.replyAttribution ? `${accessibleText}\n\n${escapeSlackMrkdwnText(formatReplyAttribution(args.replyAttribution))}` : accessibleText;
1770
- const response = await postSlackMessage({
1771
- channelId: args.channelId,
1772
- threadTs,
1773
- text: fallbackText,
1774
- ...blocks.length ? { blocks } : void 0,
1775
- ...entities.length ? { entities } : void 0
1776
- });
1777
- if (response.ts) {
1778
- messageTs.push(response.ts);
1779
- threadTs ??= response.ts;
1780
- }
1781
- }
1782
- return messageTs;
1783
- }
1784
- // src/chat/slack/automated-turn-limit-notice.ts
1785
- /**
1786
- * Pause notice for the consecutive automated-turn limit.
1787
- *
1788
- * Best-effort: a failed post must not fail the Turn or re-enable event wakes.
1789
- * The consecutive-turn limit claims the notice slot before this post. Clear that
1790
- * claim when the post fails or is skipped so a later paused wake can try again.
1791
- */
1792
- async function releaseFailedNoticeClaim(args) {
1793
- try {
1794
- await clearAutomatedTurnLimitNoticeClaim(args);
1795
- } catch (error) {
1796
- logException(error, "automated_turn_limit.notice_claim_clear_failed");
1797
- }
1798
- }
1799
- /** Post the pause notice for one Conversation Location when known. */
1800
- async function postAutomatedTurnLimitNoticeForConversation(args) {
1801
- try {
1802
- const conversation = await getConversationStore().get({ conversationId: args.conversationId });
1803
- const location = conversation?.parentConversationId ? void 0 : conversation?.location;
1804
- if (!location || location.provider !== "slack") {
1805
- logWarn("automated_turn_limit.notice_skipped", {
1806
- conversationId: args.conversationId,
1807
- "app.automated_turn_limit.reason": location ? "unsupported_location" : "missing_location"
1808
- });
1809
- await releaseFailedNoticeClaim({
1810
- conversationId: args.conversationId,
1811
- nowMs: args.nowMs
1812
- });
1813
- return false;
1814
- }
1815
- await sendSlackReply({
1816
- ...resolveSlackReplyTarget({
1817
- destination: location,
1818
- location,
1819
- source: args.source
1820
- }),
1821
- conversationId: args.conversationId,
1822
- text: buildAutomatedTurnLimitResponse({ maxTurns: args.maxTurns })
1823
- });
1824
- return true;
1825
- } catch (error) {
1826
- logException(error, "automated_turn_limit.notice_failed", { conversationId: args.conversationId });
1827
- await releaseFailedNoticeClaim({
1828
- conversationId: args.conversationId,
1829
- nowMs: args.nowMs
1830
- });
1831
- return false;
1832
- }
1833
- }
1834
- /** Post the pause notice after a finished Turn hits the limit. */
1835
- async function maybePostAutomatedTurnLimitNotice(args) {
1836
- if (!args.update?.shouldPostNotice) return;
1837
- await postAutomatedTurnLimitNoticeForConversation({
1838
- conversationId: args.conversationId,
1839
- maxTurns: args.maxTurns,
1840
- nowMs: args.nowMs,
1841
- source: args.source
1842
- });
1843
- }
1844
- // src/chat/task-input.ts
1845
- /**
1846
- * Shared agent input for tasks: one `<task>` input tag. A task can come from
1847
- * a schedule, an event, or a watch. Call sites supply facts; this module owns
1848
- * layout and the reply contract. Unit snapshots in
1849
- * `tests/unit/chat/task-input.test.ts` own the exact text. Event data stays in
1850
- * its own child tags, and the outcome rule is always last.
1851
- */
1852
- /**
1853
- * Shared closing lines. Automations pass outcomes and end with an answer
1854
- * tool. Watches follow the Conversation's reply rules. A Watch reply goes
1855
- * only to the Conversation, so a question asked in the provider must also get
1856
- * its answer there. Watch instructions often say to stay silent, so this rule
1857
- * sits in the contract, not in plugin guidance.
1858
- */
1859
- function replyContractLines(outcomes) {
1860
- if (!outcomes) return [
1861
- "When an Event asks you a question, answer it where it was asked, with that provider's tool. Then reply with the answer and a link to it.",
1862
- "When you reply, follow any reply format in the instructions.",
1863
- `When the outcome needs nobody's attention, such as a routine fix that worked or feedback that you handled, end the Turn with \`${NO_REPLY_TOOL_NAME}\` and put the outcome in its \`note\`. The note stays in the Conversation but notifies nobody. Do not use it when the instructions say to notify, mention, or report to a person, when the reply asks a question, when a person must decide or act, or when something failed.`
1864
- ];
1865
- return [`End with \`${REPLY_TOOL_NAME}\`, \`${NO_REPLY_TOOL_NAME}\`, or \`${REPORT_BLOCKED_TOOL_NAME}\`.`];
1866
- }
1867
- function oneLine(value) {
1868
- return value.replace(/[\r\n]+/g, " ").replace(/\s+/g, " ").trim();
1869
- }
1870
- function clip(value, maxLength) {
1871
- return maxLength === void 0 ? value : value.slice(0, maxLength);
1872
- }
1873
- const CREATOR_REFERENCE = /\bthe Automation creator\b/gi;
1874
- /**
1875
- * Write the creator mention where the instructions say "the Automation
1876
- * creator", so the run does not have to swap it in.
1877
- */
1878
- function mentionCreator(instructions, creator) {
1879
- return instructions.replace(CREATOR_REFERENCE, () => creator);
1880
- }
1881
- function quoted(values) {
1882
- return values.map((value) => `"${value}"`).join(" or ");
1883
- }
1884
- /**
1885
- * Render each linked person once. A doer in `<people>` gets a note in that
1886
- * list. Other doers get a `<done-by>` tag. Without one entry per person, the
1887
- * agent can mention a person and then name them again by handle as if they
1888
- * were someone else. The "you" rule covers doers outside `<people>` too,
1889
- * because instructions can still ask to mention them, such as a requester who
1890
- * reviews their own pull request. A child agent replies to its parent, not to
1891
- * the person, so it writes the mention instead of the handle. That carries
1892
- * who the person is up each level to the agent that replies to them.
1893
- */
1894
- function peopleTags(people, doers) {
1895
- const label = (doer) => `${doer.mention} (${[doer.did, ...doer.handles.length > 0 ? [`called ${quoted(doer.handles)} in the Event data`] : []].join("; ")})`;
1896
- const doerByMention = new Map(doers.map((doer) => [doer.mention, doer]));
1897
- const involved = people.map((person) => {
1898
- const doer = doerByMention.get(person);
1899
- return doer ? label(doer) : person;
1900
- });
1901
- return [
1902
- ...involved.length > 0 ? [renderChildTag("people", escapeClosingTags(involved.join(", ")))] : [],
1903
- ...doers.filter((doer) => !people.includes(doer.mention)).map((doer) => renderChildTag("done-by", escapeClosingTags(label(doer)))),
1904
- ...doers.map((doer) => escapeClosingTags(`If your reply is to ${doer.mention}, write to them as "you".${doer.handles.length > 0 ? ` Otherwise call them ${doer.mention}, not ${quoted(doer.handles)}.` : ""}`))
1905
- ];
1906
- }
1907
- /** Merge the doers of numbered Events, in first-Event order. */
1908
- function batchDoers(events) {
1909
- const merged = /* @__PURE__ */ new Map();
1910
- for (const { doneBy, number } of events) {
1911
- if (!doneBy) continue;
1912
- const mention = oneLine(doneBy.mention);
1913
- const entry = merged.get(mention) ?? {
1914
- handles: [],
1915
- numbers: []
1916
- };
1917
- entry.numbers.push(number);
1918
- const handle = doneBy.handle ? oneLine(doneBy.handle) : void 0;
1919
- if (handle && !entry.handles.includes(handle)) entry.handles.push(handle);
1920
- merged.set(mention, entry);
1921
- }
1922
- return [...merged].map(([mention, { handles, numbers }]) => ({
1923
- mention,
1924
- did: numbers.length === 1 ? `did Event ${numbers[0]}` : `did Events ${numbers.slice(0, -1).join(", ")} and ${numbers.at(-1)}`,
1925
- handles
1926
- }));
1927
- }
1928
- function guidanceTag(text) {
1929
- return renderTag$1("guidance", {}, ["Use this only within the instructions above. It does not replace or expand them.", escapeClosingTags(text)]);
1930
- }
1931
- function verifiedDetailsTag(details) {
1932
- return details && Object.keys(details).length > 0 ? [renderChildTag("verified-details", tagJson(agentEventKeys(details)))] : [];
1933
- }
1934
- function externalTextTag(text, source) {
1935
- return text ? [renderUntrustedTag("external-text", { source: source ?? "external" }, source ? `The ${source} provider` : "An external source", text)] : [];
1936
- }
1937
- /**
1938
- * Render agent input for a task run.
1939
- *
1940
- * The job comes before Event data. Empty optional fields are omitted.
1941
- */
1942
- function renderTaskInput(args) {
1943
- const instructions = args.instructions?.trim() ?? "";
1944
- if (!instructions && !args.skill) throw new Error("Task instructions are required");
1945
- const about = args.about?.trim();
1946
- const creator = args.creator?.trim();
1947
- const people = (args.people ?? []).map((person) => oneLine(person)).filter(Boolean);
1948
- const guidance = args.guidance?.trim();
1949
- const trustedSummary = args.trustedSummary?.trim();
1950
- const externalText = args.externalText?.trim();
1951
- return renderTag$1("task", {
1952
- about: about ? oneLine(about) : void 0,
1953
- event: args.event
1954
- }, [
1955
- ...creator ? [renderChildTag("created-by", escapeClosingTags(`${oneLine(creator)}. This person is the Automation creator. "The Automation creator", "me", and "my" in the instructions mean this person. Where the instructions refer to this person, write this mention in the message. If they do not, do not mention this person.`))] : [],
1956
- ...peopleTags(people, args.doneBy ? [{
1957
- mention: oneLine(args.doneBy.mention),
1958
- did: "did what this Event describes",
1959
- handles: args.doneBy.handle ? [oneLine(args.doneBy.handle)] : []
1960
- }] : []),
1961
- ...args.skill ? [instructions ? `Run the ${args.skill} skill. The instructions below add context for this run.` : `Run the ${args.skill} skill.`] : [],
1962
- ...instructions ? [renderChildTag("instructions", escapeClosingTags(creator ? mentionCreator(instructions, oneLine(creator)) : instructions))] : [],
1963
- ...guidance ? [guidanceTag(guidance)] : [],
1964
- ...trustedSummary ? [renderChildTag("summary", escapeClosingTags(clip(trustedSummary, args.trustedSummaryMaxLength)))] : [],
1965
- ...verifiedDetailsTag(args.verifiedDetails),
1966
- ...externalTextTag(externalText && clip(externalText, args.externalTextMaxLength), args.source),
1967
- ...replyContractLines(args.outcomes)
1968
- ]);
1969
- }
1970
- function eventTag(event, index) {
1971
- const trustedSummary = event.trustedSummary?.trim();
1972
- return renderTag$1("event", {
1973
- index,
1974
- type: event.eventType
1975
- }, [
1976
- ...trustedSummary ? [renderChildTag("summary", escapeClosingTags(trustedSummary))] : [],
1977
- ...verifiedDetailsTag(event.verifiedDetails),
1978
- ...externalTextTag(event.externalText?.trim(), event.source)
1979
- ]);
1980
- }
1981
- /**
1982
- * Render one `<task>` for several Watch Events that arrived together.
1983
- *
1984
- * Each `<watch>` group states its instructions once, then lists its Events.
1985
- * Child tags match `renderTaskInput`. The outcome rule appears once, at the
1986
- * end.
1987
- */
1988
- function renderTaskBatchInput(args) {
1989
- const total = args.groups.reduce((count, group) => count + group.events.length, 0);
1990
- if (total === 0) throw new Error("Task batch requires at least one Event");
1991
- const body = [`You received ${total} ${total === 1 ? "event" : "events"}.`];
1992
- let number = 0;
1993
- for (const group of args.groups) {
1994
- const instructions = group.instructions.trim();
1995
- if (!instructions) throw new Error("Task instructions are required");
1996
- const about = group.about?.trim();
1997
- const people = group.people.map((person) => oneLine(person)).filter(Boolean);
1998
- const numbered = group.events.map((event, index) => ({
1999
- ...event,
2000
- number: number + index + 1
2001
- }));
2002
- number += group.events.length;
2003
- const guidance = /* @__PURE__ */ new Map();
2004
- for (const event of group.events) {
2005
- const text = event.guidance?.trim();
2006
- if (text && !guidance.has(event.eventType)) guidance.set(event.eventType, text);
2062
+ text: {
2063
+ type: "mrkdwn",
2064
+ text: card.text
2065
+ }
2066
+ });
2067
+ if (isFinalChunk || !text.trim()) blocks.push(...buildSlackReplyBlocks("", footer) ?? []);
2068
+ const entities = cards.flatMap((card) => card.entity ? [card.entity] : []);
2069
+ const accessibleText = [text, ...cards.map((card) => card.text)].filter(Boolean).join("\n\n");
2070
+ const fallbackText = isFinalChunk && args.replyAttribution ? `${accessibleText}\n\n${escapeSlackMrkdwnText(formatReplyAttribution(args.replyAttribution))}` : accessibleText;
2071
+ const response = await postSlackMessage({
2072
+ channelId: args.channelId,
2073
+ threadTs,
2074
+ text: fallbackText,
2075
+ ...blocks.length ? { blocks } : void 0,
2076
+ ...entities.length ? { entities } : void 0
2077
+ });
2078
+ if (response.ts) {
2079
+ messageTs.push(response.ts);
2080
+ threadTs ??= response.ts;
2007
2081
  }
2008
- body.push(renderTag$1("watch", { about: about ? oneLine(about) : void 0 }, [
2009
- ...peopleTags(people, batchDoers(numbered)),
2010
- renderChildTag("instructions", escapeClosingTags(instructions)),
2011
- ...guidance.size > 0 ? [guidanceTag([...guidance].map(([eventType, text]) => `- ${eventType}: ${text}`).join("\n"))] : [],
2012
- ...numbered.map((event) => eventTag(event, event.number))
2013
- ]));
2014
2082
  }
2015
- return renderTag$1("task", {}, [...body, ...replyContractLines(void 0)]);
2083
+ return messageTs;
2016
2084
  }
2017
- // src/chat/sandbox/snapshot/events.ts
2018
- const WORKSPACE_SNAPSHOT_NAMESPACE = CORE_EVENT_NAMESPACE;
2019
- const WORKSPACE_SNAPSHOT_RESOURCE_TYPE = "workspace_snapshot";
2020
- const WORKSPACE_SNAPSHOT_READY_EVENT = "workspace_snapshot.ready";
2021
- const WORKSPACE_SNAPSHOT_FAILED_EVENT = "workspace_snapshot.failed";
2085
+ // src/chat/slack/automated-turn-limit-notice.ts
2022
2086
  /**
2023
- * Core catalog entry for Workspace snapshot ready and failed events.
2087
+ * Pause notice for the consecutive automated-turn limit.
2024
2088
  *
2025
- * Uses the same registration shape as plugins so search, guidance, and tool
2026
- * schemas treat these events like any other resource type. Snapshot finish
2027
- * does not run event-automation ingest, so only watches can use these events.
2089
+ * Best-effort: a failed post must not fail the Turn or re-enable event wakes.
2090
+ * The consecutive-turn limit claims the notice slot before this post. Clear that
2091
+ * claim when the post fails or is skipped so a later paused wake can try again.
2028
2092
  */
2029
- function workspaceSnapshotEvents() {
2030
- return {
2031
- resourceTypes: [{
2032
- type: WORKSPACE_SNAPSHOT_RESOURCE_TYPE,
2033
- supportedEvents: [WORKSPACE_SNAPSHOT_READY_EVENT, WORKSPACE_SNAPSHOT_FAILED_EVENT],
2034
- suggestedEvents: []
2035
- }],
2036
- events: {
2037
- [WORKSPACE_SNAPSHOT_READY_EVENT]: {
2038
- reach: "resource",
2039
- guidance: "Call switchWorkspace again with the same Workspace name. Do not create another watch when switchWorkspace already returned a subscription."
2040
- },
2041
- [WORKSPACE_SNAPSHOT_FAILED_EVENT]: {
2042
- reach: "resource",
2043
- guidance: "Report the snapshot failure. Do not keep waiting for this Workspace unless the user asks to retry."
2044
- }
2045
- },
2046
- limits: { [WORKSPACE_SNAPSHOT_RESOURCE_TYPE]: { automation: false } }
2047
- };
2048
- }
2049
- /** Describe the events that report when a snapshot build ends. */
2050
- function workspaceSnapshotWatch(input) {
2051
- return {
2052
- identifier: input.workspaceId,
2053
- label: `Workspace ${input.workspaceName} snapshot`,
2054
- namespace: WORKSPACE_SNAPSHOT_NAMESPACE,
2055
- supported_events: [WORKSPACE_SNAPSHOT_READY_EVENT, WORKSPACE_SNAPSHOT_FAILED_EVENT],
2056
- suggested_events: [],
2057
- type: WORKSPACE_SNAPSHOT_RESOURCE_TYPE
2058
- };
2093
+ async function releaseFailedNoticeClaim(args) {
2094
+ try {
2095
+ await clearAutomatedTurnLimitNoticeClaim(args);
2096
+ } catch (error) {
2097
+ logException(error, "automated_turn_limit.notice_claim_clear_failed");
2098
+ }
2059
2099
  }
2060
- /** Report that a Workspace snapshot build is ready or failed. */
2061
- function workspaceSnapshotFinishedEvent(input) {
2062
- const occurredAtMs = input.occurredAtMs ?? Date.now();
2063
- const eventType = input.status === "ready" ? WORKSPACE_SNAPSHOT_READY_EVENT : WORKSPACE_SNAPSHOT_FAILED_EVENT;
2064
- const trustedSummary = input.status === "ready" ? "Workspace snapshot is ready." : "Workspace snapshot build failed.";
2065
- const event = {
2066
- eventKey: `${WORKSPACE_SNAPSHOT_NAMESPACE}:${input.workspaceId}:${input.resultId}:${input.status}`,
2067
- eventType,
2068
- identifier: input.workspaceId,
2069
- namespace: WORKSPACE_SNAPSHOT_NAMESPACE,
2070
- occurredAtMs,
2071
- terminal: true,
2072
- trustedSummary,
2073
- data: {
2074
- workspaceId: input.workspaceId,
2075
- status: input.status
2100
+ /** Post the pause notice for one Conversation Location when known. */
2101
+ async function postAutomatedTurnLimitNoticeForConversation(args) {
2102
+ try {
2103
+ const conversation = await getConversationStore().get({ conversationId: args.conversationId });
2104
+ const location = conversation?.parentConversationId ? void 0 : conversation?.location;
2105
+ if (!location || location.provider !== "slack") {
2106
+ logWarn("automated_turn_limit.notice_skipped", {
2107
+ conversationId: args.conversationId,
2108
+ "app.automated_turn_limit.reason": location ? "unsupported_location" : "missing_location"
2109
+ });
2110
+ await releaseFailedNoticeClaim({
2111
+ conversationId: args.conversationId,
2112
+ nowMs: args.nowMs
2113
+ });
2114
+ return false;
2076
2115
  }
2077
- };
2078
- if (input.status === "failed" && input.error) event.untrustedText = input.error;
2079
- return event;
2116
+ await sendSlackReply({
2117
+ ...resolveSlackReplyTarget({
2118
+ destination: location,
2119
+ location,
2120
+ source: args.source
2121
+ }),
2122
+ conversationId: args.conversationId,
2123
+ text: buildAutomatedTurnLimitResponse({ maxTurns: args.maxTurns })
2124
+ });
2125
+ return true;
2126
+ } catch (error) {
2127
+ logException(error, "automated_turn_limit.notice_failed", { conversationId: args.conversationId });
2128
+ await releaseFailedNoticeClaim({
2129
+ conversationId: args.conversationId,
2130
+ nowMs: args.nowMs
2131
+ });
2132
+ return false;
2133
+ }
2080
2134
  }
2081
- // src/chat/slack/channel-message-events.ts
2135
+ /** Post the pause notice after a finished Turn hits the limit. */
2136
+ async function maybePostAutomatedTurnLimitNotice(args) {
2137
+ if (!args.update?.shouldPostNotice) return;
2138
+ await postAutomatedTurnLimitNoticeForConversation({
2139
+ conversationId: args.conversationId,
2140
+ maxTurns: args.maxTurns,
2141
+ nowMs: args.nowMs,
2142
+ source: args.source
2143
+ });
2144
+ }
2145
+ // src/chat/task-input.ts
2082
2146
  /**
2083
- * Slack channel-message Events for Event automations.
2084
- *
2085
- * Core publishes these Events from Slack ingress, so the `slack` namespace is
2086
- * core owned, like `junior`. Anyone in the channel writes the Event text, so an
2087
- * automation can watch only its own channel and always uses system credentials.
2147
+ * Shared agent input for tasks: one `<task>` input tag. A task can come from
2148
+ * a schedule, an event, or a watch. Call sites supply facts; this module owns
2149
+ * layout and the reply contract. Unit snapshots in
2150
+ * `tests/unit/chat/task-input.test.ts` own the exact text. Event data stays in
2151
+ * its own child tags, and the outcome rule is always last.
2088
2152
  */
2089
- /** Core-owned event namespace for Slack Events. Not a plugin publisher. */
2090
- const SLACK_EVENT_NAMESPACE = "slack";
2091
- /** The trigger identifier that names the channel of the automation. */
2092
- const SLACK_CURRENT_CHANNEL_IDENTIFIER = "current_channel";
2093
- const CHANNEL_RESOURCE_TYPE = "channel";
2094
- const MESSAGE_POSTED_EVENT = "message.posted";
2095
- const CHANNEL_ID_PATTERN = /^[CG][A-Z0-9]{2,}$/;
2096
- const CHANNEL_LOCATION = "channel";
2097
- const THREAD_LOCATION = "thread";
2098
- const CHANNEL_MESSAGE_MATCH_FIELDS = eventMatchFieldsSchema.parse({
2099
- channelId: {
2100
- kind: "string",
2101
- description: "Slack channel ID of the message. It is always the channel where the automation posts.",
2102
- events: [MESSAGE_POSTED_EVENT]
2103
- },
2104
- userId: {
2105
- kind: "string",
2106
- description: "Slack user ID of the message author, or the bot ID (B…) of a bot post that has no user, such as an app integration. Required to run on bot posts."
2107
- },
2108
- location: {
2109
- kind: "string",
2110
- enum: [CHANNEL_LOCATION, THREAD_LOCATION],
2111
- description: "channel for a top-level message, thread for a thread reply. Leave out for top-level only; thread replies run only when this names thread."
2112
- }
2113
- });
2114
2153
  /**
2115
- * Event registration for new Slack channel messages and thread replies. Only
2116
- * event automations can use it, so watchEvents rejects it.
2154
+ * Shared closing lines. Automations pass outcomes and end with an answer
2155
+ * tool. Watches follow the Conversation's reply rules. A Watch reply goes
2156
+ * only to the Conversation, so a question asked in the provider must also get
2157
+ * its answer there. Watch instructions often say to stay silent, so this rule
2158
+ * sits in the contract, not in plugin guidance.
2117
2159
  */
2118
- function slackChannelMessageEvents() {
2119
- return {
2120
- resourceTypes: [{
2121
- type: CHANNEL_RESOURCE_TYPE,
2122
- identifier: {
2123
- format: `"${SLACK_CURRENT_CHANNEL_IDENTIFIER}" for the channel where the automation is created`,
2124
- pattern: String.raw`^(?:current_channel|[CG][A-Z0-9]{2,})$`
2125
- },
2126
- supportedEvents: [MESSAGE_POSTED_EVENT],
2127
- suggestedEvents: [],
2128
- matchFields: CHANNEL_MESSAGE_MATCH_FIELDS
2129
- }],
2130
- events: { [MESSAGE_POSTED_EVENT]: {
2131
- reach: { anyOf: ["channelId"] },
2132
- guidance: "A person or bot posted a new message in this channel. A bot post runs the automation only when match names the bot in user_id, by its user ID or, for a post with no user, its bot ID. A thread reply runs it only when match.location names thread. A reply goes in the message's Slack thread. If the instructions do not apply to this message, end with no action."
2133
- } },
2134
- limits: { [CHANNEL_RESOURCE_TYPE]: {
2135
- watch: false,
2136
- watchUnavailableMessage: "Slack channel messages can trigger only an event automation in that channel. Use createAutomation with an event trigger."
2137
- } }
2138
- };
2160
+ function replyContractLines(outcomes) {
2161
+ if (!outcomes) return [
2162
+ "When an Event asks you a question, answer it where it was asked, with that provider's tool. Then reply with the answer and a link to it.",
2163
+ "When you reply, follow any reply format in the instructions.",
2164
+ `When the outcome needs nobody's attention, such as a routine fix that worked or feedback that you handled, end the Turn with \`${NO_REPLY_TOOL_NAME}\` and put the outcome in its \`note\`. The note stays in the Conversation but notifies nobody. Do not use it when the instructions say to notify, mention, or report to a person, when the reply asks a question, when a person must decide or act, or when something failed.`
2165
+ ];
2166
+ return [`End with \`${REPLY_TOOL_NAME}\`, \`${NO_REPLY_TOOL_NAME}\`, or \`${REPORT_BLOCKED_TOOL_NAME}\`.`];
2139
2167
  }
2140
- /**
2141
- * Set the `channelId` filter of a Slack channel-message trigger to the
2142
- * channel where the automation posts. A trigger that names another channel,
2143
- * or a saved trigger with an identifier, stays as it is for
2144
- * `requireSlackChannelMessageScope` to check.
2145
- */
2146
- function slackChannelMessageTrigger(trigger, channelId) {
2147
- if (trigger.namespace !== "slack") return trigger;
2148
- if (trigger.identifier != null || trigger.match?.channelId !== void 0) return trigger;
2149
- return {
2150
- ...trigger,
2151
- match: {
2152
- ...trigger.match,
2153
- channelId
2154
- }
2155
- };
2168
+ function oneLine(value) {
2169
+ return value.replace(/[\r\n]+/g, " ").replace(/\s+/g, " ").trim();
2170
+ }
2171
+ function clip(value, maxLength) {
2172
+ return maxLength === void 0 ? value : value.slice(0, maxLength);
2156
2173
  }
2174
+ const CREATOR_REFERENCE = /\bthe Automation creator\b/gi;
2157
2175
  /**
2158
- * Bind a Slack channel-message automation to its own channel.
2159
- *
2160
- * The trigger names the channel with a `channelId` filter. A saved trigger
2161
- * can name it with an identifier instead, where `current_channel` means the
2162
- * destination channel. Reject other channels, so private channel text cannot
2163
- * reach another channel.
2164
- */
2165
- function requireSlackChannelMessageScope(automation) {
2166
- if (automation.trigger.namespace !== "slack") return automation;
2167
- const channelId = automation.destination.channelId;
2168
- if (!CHANNEL_ID_PATTERN.test(channelId)) throw new ToolInputError("A Slack channel-message automation works only in a channel, not in a DM.");
2169
- const { identifier, match } = automation.trigger;
2170
- if ((identifier === void 0 ? match?.channelId : identifier === "current_channel" ? channelId : identifier) !== channelId) throw new ToolInputError("A Slack channel-message automation can watch only the channel where it posts. Leave out the channel_id filter, or create the automation in the channel to watch.");
2171
- return {
2172
- ...automation,
2173
- credentialMode: "system",
2174
- trigger: {
2175
- ...automation.trigger,
2176
- ...identifier === void 0 ? void 0 : { identifier: channelId }
2177
- }
2178
- };
2176
+ * Write the creator mention where the instructions say "the Automation
2177
+ * creator", so the run does not have to swap it in.
2178
+ */
2179
+ function mentionCreator(instructions, creator) {
2180
+ return instructions.replace(CREATOR_REFERENCE, () => creator);
2181
+ }
2182
+ function quoted(values) {
2183
+ return values.map((value) => `"${value}"`).join(" or ");
2179
2184
  }
2180
2185
  /**
2181
- * Build the Event for one new channel message or thread reply, or nothing.
2182
- *
2183
- * Slackbot posts do not count. Bot posts are marked with `postedByBot`, so
2184
- * only automations that name the bot can run on them. Thread replies carry
2185
- * the `thread` location, so only automations that name it can run on them.
2186
+ * Render each linked person once. A doer in `<people>` gets a note in that
2187
+ * list. Other doers get a `<done-by>` tag. Without one entry per person, the
2188
+ * agent can mention a person and then name them again by handle as if they
2189
+ * were someone else. The "you" rule covers doers outside `<people>` too,
2190
+ * because instructions can still ask to mention them, such as a requester who
2191
+ * reviews their own pull request. A child agent replies to its parent, not to
2192
+ * the person, so it writes the mention instead of the handle. That carries
2193
+ * who the person is up each level to the agent that replies to them.
2186
2194
  */
2187
- function slackChannelMessageEvent(input) {
2188
- const { author } = input;
2189
- if (author.kind === "user" && author.userId === "USLACKBOT") return void 0;
2190
- if (!CHANNEL_ID_PATTERN.test(input.channelId)) return void 0;
2191
- const postedByBot = author.kind === "bot" || Boolean(input.botId || input.subtype === "bot_message");
2192
- const userId = author.kind === "bot" ? author.botId : author.userId;
2193
- const threadTs = input.threadTs && input.threadTs !== input.ts ? input.threadTs : void 0;
2194
- return {
2195
- eventKey: `${input.channelId}:${input.ts}`,
2196
- eventType: MESSAGE_POSTED_EVENT,
2197
- identifier: input.channelId,
2198
- occurredAtMs: Math.floor(Number(input.ts) * 1e3),
2199
- trustedSummary: `${postedByBot ? "The bot " : ""}${author.kind === "bot" ? author.botId : `<@${author.userId}>`} posted a new ${threadTs ? `thread reply under message ${threadTs}` : "message"} in <#${input.channelId}>.`,
2200
- data: {
2201
- channelId: input.channelId,
2202
- location: threadTs ? THREAD_LOCATION : CHANNEL_LOCATION,
2203
- messageTs: input.ts,
2204
- ...threadTs ? { threadTs } : void 0,
2205
- userId,
2206
- ...postedByBot ? { postedByBot: true } : void 0
2207
- },
2208
- ...input.text?.trim() ? { untrustedText: input.text } : void 0
2209
- };
2195
+ function peopleTags(people, doers) {
2196
+ const label = (doer) => `${doer.mention} (${[doer.did, ...doer.handles.length > 0 ? [`called ${quoted(doer.handles)} in the Event data`] : []].join("; ")})`;
2197
+ const doerByMention = new Map(doers.map((doer) => [doer.mention, doer]));
2198
+ const involved = people.map((person) => {
2199
+ const doer = doerByMention.get(person);
2200
+ return doer ? label(doer) : person;
2201
+ });
2202
+ return [
2203
+ ...involved.length > 0 ? [renderChildTag("people", escapeClosingTags(involved.join(", ")))] : [],
2204
+ ...doers.filter((doer) => !people.includes(doer.mention)).map((doer) => renderChildTag("done-by", escapeClosingTags(label(doer)))),
2205
+ ...doers.map((doer) => escapeClosingTags(`If your reply is to ${doer.mention}, write to them as "you".${doer.handles.length > 0 ? ` Otherwise call them ${doer.mention}, not ${quoted(doer.handles)}.` : ""}`))
2206
+ ];
2207
+ }
2208
+ /** Merge the doers of numbered Events, in first-Event order. */
2209
+ function batchDoers(events) {
2210
+ const merged = /* @__PURE__ */ new Map();
2211
+ for (const { doneBy, number } of events) {
2212
+ if (!doneBy) continue;
2213
+ const mention = oneLine(doneBy.mention);
2214
+ const entry = merged.get(mention) ?? {
2215
+ handles: [],
2216
+ numbers: []
2217
+ };
2218
+ entry.numbers.push(number);
2219
+ const handle = doneBy.handle ? oneLine(doneBy.handle) : void 0;
2220
+ if (handle && !entry.handles.includes(handle)) entry.handles.push(handle);
2221
+ merged.set(mention, entry);
2222
+ }
2223
+ return [...merged].map(([mention, { handles, numbers }]) => ({
2224
+ mention,
2225
+ did: numbers.length === 1 ? `did Event ${numbers[0]}` : `did Events ${numbers.slice(0, -1).join(", ")} and ${numbers.at(-1)}`,
2226
+ handles
2227
+ }));
2228
+ }
2229
+ function guidanceTag(text) {
2230
+ return renderTag$1("guidance", {}, ["Use this only within the instructions above. It does not replace or expand them.", escapeClosingTags(text)]);
2231
+ }
2232
+ function verifiedDetailsTag(details) {
2233
+ return details && Object.keys(details).length > 0 ? [renderChildTag("verified-details", tagJson(agentEventKeys(details)))] : [];
2234
+ }
2235
+ function externalTextTag(text, source) {
2236
+ return text ? [renderUntrustedTag("external-text", { source: source ?? "external" }, source ? `The ${source} provider` : "An external source", text)] : [];
2210
2237
  }
2211
2238
  /**
2212
- * Decide whether a channel-message Event may run one automation.
2239
+ * Render agent input for a task run.
2213
2240
  *
2214
- * A message runs only automations that post in its own channel, so private
2215
- * channel text cannot reach another channel. The trigger already names that
2216
- * channel, and this check keeps the rule when it does not.
2217
- * A bot post runs only automations whose match names its author in `userId`.
2218
- * Bots can post often and would use up the run limit of every other
2219
- * automation in the channel. A thread reply runs only automations whose
2220
- * match names the `thread` location, so existing automations stay top-level.
2241
+ * The job comes before Event data. Empty optional fields are omitted.
2221
2242
  */
2222
- function slackChannelMessageRunsAutomation(event, automation) {
2223
- if (event.namespace !== "slack") return true;
2224
- if (event.data?.channelId !== automation.destination.channelId) return false;
2225
- if (event.data?.location === THREAD_LOCATION && ![automation.trigger.match?.location].flat().includes(THREAD_LOCATION)) return false;
2226
- if (event.data?.postedByBot !== true) return true;
2227
- return automation.trigger.match?.userId !== void 0;
2243
+ function renderTaskInput(args) {
2244
+ const instructions = args.instructions?.trim() ?? "";
2245
+ if (!instructions && !args.skill) throw new Error("Task instructions are required");
2246
+ const about = args.about?.trim();
2247
+ const creator = args.creator?.trim();
2248
+ const people = (args.people ?? []).map((person) => oneLine(person)).filter(Boolean);
2249
+ const guidance = args.guidance?.trim();
2250
+ const trustedSummary = args.trustedSummary?.trim();
2251
+ const externalText = args.externalText?.trim();
2252
+ return renderTag$1("task", {
2253
+ about: about ? oneLine(about) : void 0,
2254
+ event: args.event
2255
+ }, [
2256
+ ...creator ? [renderChildTag("created-by", escapeClosingTags(`${oneLine(creator)}. This person is the Automation creator. "The Automation creator", "me", and "my" in the instructions mean this person. Where the instructions refer to this person, write this mention in the message. If they do not, do not mention this person.`))] : [],
2257
+ ...peopleTags(people, args.doneBy ? [{
2258
+ mention: oneLine(args.doneBy.mention),
2259
+ did: "did what this Event describes",
2260
+ handles: args.doneBy.handle ? [oneLine(args.doneBy.handle)] : []
2261
+ }] : []),
2262
+ ...args.skill ? [instructions ? `Run the ${args.skill} skill. The instructions below add context for this run.` : `Run the ${args.skill} skill.`] : [],
2263
+ ...instructions ? [renderChildTag("instructions", escapeClosingTags(creator ? mentionCreator(instructions, oneLine(creator)) : instructions))] : [],
2264
+ ...guidance ? [guidanceTag(guidance)] : [],
2265
+ ...trustedSummary ? [renderChildTag("summary", escapeClosingTags(clip(trustedSummary, args.trustedSummaryMaxLength)))] : [],
2266
+ ...verifiedDetailsTag(args.verifiedDetails),
2267
+ ...externalTextTag(externalText && clip(externalText, args.externalTextMaxLength), args.source),
2268
+ ...replyContractLines(args.outcomes)
2269
+ ]);
2228
2270
  }
2229
- /** Return the source message thread for a channel-message run. */
2230
- function slackChannelMessageReplyThreadTs(event) {
2231
- if (event.namespace !== "slack") return void 0;
2232
- const messageTs = event.data?.threadTs ?? event.data?.messageTs;
2233
- return typeof messageTs === "string" ? messageTs : void 0;
2271
+ function eventTag(event, index) {
2272
+ const trustedSummary = event.trustedSummary?.trim();
2273
+ return renderTag$1("event", {
2274
+ index,
2275
+ type: event.eventType
2276
+ }, [
2277
+ ...trustedSummary ? [renderChildTag("summary", escapeClosingTags(trustedSummary))] : [],
2278
+ ...verifiedDetailsTag(event.verifiedDetails),
2279
+ ...externalTextTag(event.externalText?.trim(), event.source)
2280
+ ]);
2234
2281
  }
2235
- // src/chat/events/runtime-catalog.ts
2236
2282
  /**
2237
- * Enabled event registrations for search, guidance, and tool schemas.
2283
+ * Render one `<task>` for several Watch Events that arrived together.
2238
2284
  *
2239
- * Includes core Workspace snapshot events under the `junior` namespace, Slack
2240
- * channel-message events under the `slack` namespace, plus every enabled plugin
2241
- * registration. Plugins may not use the `junior` or `slack` namespaces.
2285
+ * Each `<watch>` group states its instructions once, then lists its Events.
2286
+ * Child tags match `renderTaskInput`. The outcome rule appears once, at the
2287
+ * end.
2242
2288
  */
2243
- function getEventCatalog() {
2244
- const snapshot = workspaceSnapshotEvents();
2245
- const catalog = {
2246
- [CORE_EVENT_NAMESPACE]: eventCatalogEntry({
2247
- displayName: botConfig.userName,
2248
- resourceTypes: [...snapshot.resourceTypes, {
2249
- type: "timer",
2250
- supportedEvents: ["timer.fired"],
2251
- suggestedEvents: []
2252
- }],
2253
- events: {
2254
- ...snapshot.events,
2255
- "timer.fired": { reach: "resource" }
2256
- },
2257
- limits: {
2258
- ...snapshot.limits,
2259
- timer: {
2260
- automation: false,
2261
- watch: false,
2262
- watchUnavailableMessage: "Use watchTimer to create a timer Watch."
2263
- }
2264
- }
2265
- }),
2266
- [SLACK_EVENT_NAMESPACE]: eventCatalogEntry({
2267
- ...slackChannelMessageEvents(),
2268
- displayName: "Slack"
2269
- })
2270
- };
2271
- for (const plugin of getPlugins()) {
2272
- const registration = plugin.events;
2273
- if (!registration || registration.isEnabled?.() === false) continue;
2274
- if (plugin.manifest.name === "junior" || plugin.manifest.name === "slack") throw new Error(`Plugin "${plugin.manifest.name}" cannot register events; that namespace is reserved for core events`);
2275
- catalog[plugin.manifest.name] = eventCatalogEntry({
2276
- ...registration,
2277
- displayName: plugin.manifest.displayName
2278
- });
2289
+ function renderTaskBatchInput(args) {
2290
+ const total = args.groups.reduce((count, group) => count + group.events.length, 0);
2291
+ if (total === 0) throw new Error("Task batch requires at least one Event");
2292
+ const body = [`You received ${total} ${total === 1 ? "event" : "events"}.`];
2293
+ let number = 0;
2294
+ for (const group of args.groups) {
2295
+ const instructions = group.instructions.trim();
2296
+ if (!instructions) throw new Error("Task instructions are required");
2297
+ const about = group.about?.trim();
2298
+ const people = group.people.map((person) => oneLine(person)).filter(Boolean);
2299
+ const numbered = group.events.map((event, index) => ({
2300
+ ...event,
2301
+ number: number + index + 1
2302
+ }));
2303
+ number += group.events.length;
2304
+ const guidance = /* @__PURE__ */ new Map();
2305
+ for (const event of group.events) {
2306
+ const text = event.guidance?.trim();
2307
+ if (text && !guidance.has(event.eventType)) guidance.set(event.eventType, text);
2308
+ }
2309
+ body.push(renderTag$1("watch", { about: about ? oneLine(about) : void 0 }, [
2310
+ ...peopleTags(people, batchDoers(numbered)),
2311
+ renderChildTag("instructions", escapeClosingTags(instructions)),
2312
+ ...guidance.size > 0 ? [guidanceTag([...guidance].map(([eventType, text]) => `- ${eventType}: ${text}`).join("\n"))] : [],
2313
+ ...numbered.map((event) => eventTag(event, event.number))
2314
+ ]));
2279
2315
  }
2280
- return catalog;
2316
+ return renderTag$1("task", {}, [...body, ...replyContractLines(void 0)]);
2281
2317
  }
2282
2318
  // src/chat/events/notification.ts
2283
2319
  const EVENT_WAIT_MS = 3e4;
@@ -2784,47 +2820,6 @@ async function loadTurnConversationNotes(input) {
2784
2820
  }
2785
2821
  return newestFirst.reverse();
2786
2822
  }
2787
- // src/chat/experimental.ts
2788
- /**
2789
- * Known unstable product features that must be opted into explicitly.
2790
- * Add new keys here as features graduate from private experiments; remove them
2791
- * once they become stable defaults.
2792
- */
2793
- const EXPERIMENTAL_FEATURES = [
2794
- "operator-tools",
2795
- "passive-routing",
2796
- "user-customization"
2797
- ];
2798
- const EXPERIMENTAL_FEATURE_SET = new Set(EXPERIMENTAL_FEATURES);
2799
- let configuredExperimental = {};
2800
- function isExperimentalFeature(value) {
2801
- return EXPERIMENTAL_FEATURE_SET.has(value);
2802
- }
2803
- /** Replace app-level experimental opt-ins and return the previous setting. */
2804
- function setExperimentalFeatures(config) {
2805
- const previous = { ...configuredExperimental };
2806
- if (config === void 0) {
2807
- configuredExperimental = {};
2808
- return previous;
2809
- }
2810
- const next = {};
2811
- for (const [rawName, enabled] of Object.entries(config)) {
2812
- if (enabled === void 0) continue;
2813
- if (typeof enabled !== "boolean") throw new Error(`experimental.${rawName} must be a boolean when provided`);
2814
- if (!isExperimentalFeature(rawName)) throw new Error(`experimental.${rawName} is not a known experimental feature. Known features: ${EXPERIMENTAL_FEATURES.join(", ")}`);
2815
- next[rawName] = enabled;
2816
- }
2817
- configuredExperimental = next;
2818
- return previous;
2819
- }
2820
- /** Return a copy of the app-level experimental opt-ins configured by createApp(). */
2821
- function getExperimentalFeatures() {
2822
- return { ...configuredExperimental };
2823
- }
2824
- /** Return whether one experimental feature is enabled via createApp({ experimental }). */
2825
- function isExperimentalFeatureEnabled(feature) {
2826
- return configuredExperimental[feature] === true;
2827
- }
2828
2823
  // src/chat/identities/customization.ts
2829
2824
  /** Read the saved customization for one user. */
2830
2825
  async function readUserCustomization(userId) {
@@ -3428,4 +3423,4 @@ async function saveStoppedConversationEvents(conversationId, messages) {
3428
3423
  }
3429
3424
  }]);
3430
3425
  }
3431
- export { sendSlackReply as $, turnInputFactsFromConversationMessage as A, requireSlackChannelMessageScope as B, getAuthPausedConversationTurnId as C, parseEventMessages as D, listActiveMailboxTurns as E, isEventMailboxMetadata as F, WORKSPACE_SNAPSHOT_FAILED_EVENT as G, slackChannelMessageReplyThreadTs as H, renderEventBatchInputs as I, workspaceSnapshotWatch as J, WORKSPACE_SNAPSHOT_READY_EVENT as K, timerWatchCredentialSubject as L, EVENT_WAIT_MS as M, enqueueEventNotification as N, resolveMailboxTurnWork as O, eventBatchMessageMeta as P, resolveSlackReplyTarget as Q, getEventCatalog as R, addConversationNote as S, listActiveMailboxTurnSources as T, slackChannelMessageRunsAutomation as U, slackChannelMessageEvent as V, slackChannelMessageTrigger as W, maybePostAutomatedTurnLimitNotice as X, renderTaskInput as Y, postAutomatedTurnLimitNoticeForConversation as Z, readUserCustomization as _, session_stop_exports as a, conversationSubtree as at, isExperimentalFeatureEnabled as b, loadReviewItemInput as c, systemPromptHash as ct, buildPromptInput as d, AGENTS_REPLACEMENT_NOTICE as dt, resolveEventMentions as et, buildSteeringPiMessage as f, buildAgentsInstructionsMessage as ft, withoutSavedSteeringMessages as g, showsAgentsInstructions as gt, loadPromptTurnContext as h, renderAgentsInstructions as ht, resumeStoppedConversationTree as i, resetAutomatedTurnLimit as it, legacyWebMailboxMetadataSchema as j, sourceFromTurnInput as k, savedInputInstruction as l, JUNIOR_PERSONALITY as lt, instructionForInputs as m, readRepositoryInstructions as mt, isSkippedAfterConversationStop as n, admitAutomatedTurn as nt, skipInputAfterConversationStop as o, conversationSubtreeColumns as ot, instructionActorFor as p, findVisibleAgentsInstructions as pt, workspaceSnapshotFinishedEvent as q, markConversationsStopped as r, recordFinishedTurnForAutomatedLimit as rt, eventReviewItemInputs as s, buildDeploymentSystemPrompt as st, getConversationStoppedAtMs as t, renderSlackObjectCard as tt, assemblePrompt as u, AGENTS_REMOVAL_NOTICE as ut, saveUserCustomization as v, getEventBatchDelayMs as w, setExperimentalFeatures as x, getExperimentalFeatures as y, SLACK_EVENT_NAMESPACE as z };
3426
+ export { slackChannelMessageEvent as $, enqueueEventNotification as A, resolveEventMentions as B, listActiveMailboxTurns as C, turnInputFactsFromConversationMessage as D, sourceFromTurnInput as E, renderTaskInput as F, conversationSubtree as G, admitAutomatedTurn as H, maybePostAutomatedTurnLimitNotice as I, isExperimentalFeatureEnabled as J, conversationSubtreeColumns as K, postAutomatedTurnLimitNoticeForConversation as L, isEventMailboxMetadata as M, renderEventBatchInputs as N, legacyWebMailboxMetadataSchema as O, timerWatchCredentialSubject as P, requireSlackChannelMessageScope as Q, resolveSlackReplyTarget as R, listActiveMailboxTurnSources as S, resolveMailboxTurnWork as T, recordFinishedTurnForAutomatedLimit as U, renderSlackObjectCard as V, resetAutomatedTurnLimit as W, getEventCatalog as X, setExperimentalFeatures as Y, SLACK_EVENT_NAMESPACE as Z, readUserCustomization as _, session_stop_exports as a, workspaceSnapshotFinishedEvent as at, getAuthPausedConversationTurnId as b, loadReviewItemInput as c, JUNIOR_PERSONALITY as ct, buildPromptInput as d, buildAgentsInstructionsMessage as dt, slackChannelMessageReplyThreadTs as et, buildSteeringPiMessage as f, findVisibleAgentsInstructions as ft, withoutSavedSteeringMessages as g, loadPromptTurnContext as h, showsAgentsInstructions as ht, resumeStoppedConversationTree as i, WORKSPACE_SNAPSHOT_READY_EVENT as it, eventBatchMessageMeta as j, EVENT_WAIT_MS as k, savedInputInstruction as l, AGENTS_REMOVAL_NOTICE as lt, instructionForInputs as m, renderAgentsInstructions as mt, isSkippedAfterConversationStop as n, slackChannelMessageTrigger as nt, skipInputAfterConversationStop as o, workspaceSnapshotWatch as ot, instructionActorFor as p, readRepositoryInstructions as pt, getExperimentalFeatures as q, markConversationsStopped as r, WORKSPACE_SNAPSHOT_FAILED_EVENT as rt, eventReviewItemInputs as s, buildDeploymentSystemPrompt as st, getConversationStoppedAtMs as t, slackChannelMessageRunsAutomation as tt, assemblePrompt as u, AGENTS_REPLACEMENT_NOTICE as ut, saveUserCustomization as v, parseEventMessages as w, getEventBatchDelayMs as x, addConversationNote as y, sendSlackReply as z };