typeclaw 0.37.7 → 0.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/auth.schema.json +109 -0
- package/package.json +2 -2
- package/secrets.schema.json +109 -0
- package/src/agent/session-origin.ts +16 -2
- package/src/bundled-plugins/memory/README.md +12 -1
- package/src/bundled-plugins/memory/index.ts +39 -2
- package/src/channels/adapters/kakaotalk.ts +1 -1
- package/src/channels/adapters/webex-bot-channel-resolver.ts +29 -0
- package/src/channels/adapters/webex-bot-classify.ts +98 -0
- package/src/channels/adapters/webex-bot-reference.ts +49 -0
- package/src/channels/adapters/webex-bot.ts +462 -0
- package/src/channels/adapters/webex-channel-resolver.ts +29 -0
- package/src/channels/adapters/webex-classify.ts +104 -0
- package/src/channels/adapters/webex-format.ts +53 -0
- package/src/channels/adapters/webex-id-ref.ts +32 -0
- package/src/channels/adapters/webex-reference.ts +49 -0
- package/src/channels/adapters/webex.ts +493 -0
- package/src/channels/manager.ts +75 -4
- package/src/channels/persistence.ts +67 -5
- package/src/channels/router.ts +9 -0
- package/src/channels/schema.ts +17 -1
- package/src/cli/channel.ts +155 -8
- package/src/cli/init.ts +129 -6
- package/src/config/channels-mutation.ts +11 -2
- package/src/doctor/channel-checks.ts +56 -1
- package/src/hostd/daemon.ts +7 -5
- package/src/hostd/protocol.ts +2 -2
- package/src/init/checkpoint.ts +1 -1
- package/src/init/index.ts +97 -17
- package/src/init/run-owner-claim.ts +2 -0
- package/src/init/webex-auth.ts +68 -0
- package/src/inspect/label.ts +13 -2
- package/src/inspect/render.ts +5 -3
- package/src/permissions/match-rule.ts +7 -3
- package/src/permissions/resolve.ts +44 -5
- package/src/role-claim/match-rule.ts +7 -2
- package/src/secrets/codex-auth-json.ts +52 -17
- package/src/secrets/defaults.ts +1 -0
- package/src/secrets/encryption.ts +5 -1
- package/src/secrets/export-codex-auth-file.ts +26 -3
- package/src/secrets/schema.ts +35 -0
- package/src/secrets/webex-store.ts +113 -0
- package/typeclaw.schema.json +321 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
## Channels — one agent, many inboxes
|
|
24
24
|
|
|
25
|
-
- 📨 **Supported channels** — Slack, Discord, Telegram, LINE, KakaoTalk, GitHub, and a websocket TUI, driven by the same agent
|
|
25
|
+
- 📨 **Supported channels** — Slack, Discord, Telegram, Webex, LINE, KakaoTalk, GitHub, and a websocket TUI, driven by the same agent
|
|
26
26
|
- ✅ **Pull-request review** — treats a GitHub PR as a conversation, reviewing as a participant, with guards against claiming a verdict it didn't actually post and against leaving a PR stranded
|
|
27
27
|
|
|
28
28
|
## Web & research — reads the web like a person
|
|
@@ -121,7 +121,7 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for the recommended local dev loop (`bu
|
|
|
121
121
|
|
|
122
122
|
## Acknowledgments
|
|
123
123
|
|
|
124
|
-
- **Multi-channel** is powered by [agent-messenger](https://github.com/agent-messenger/agent-messenger) — every non-GitHub adapter (`slack-bot`, `discord-bot`, `telegram-bot`, `line`, `kakaotalk`) is built on its SDK. Thanks to the maintainers for the credential extraction, listener protocols, and platform coverage that made multi-channel a feature instead of a year-long project.
|
|
124
|
+
- **Multi-channel** is powered by [agent-messenger](https://github.com/agent-messenger/agent-messenger) — every non-GitHub adapter (`slack-bot`, `discord-bot`, `telegram-bot`, `webex-bot`, `line`, `kakaotalk`) is built on its SDK. Thanks to the maintainers for the credential extraction, listener protocols, and platform coverage that made multi-channel a feature instead of a year-long project.
|
|
125
125
|
- **Subagent architecture** is inspired by [oh-my-openagent](https://github.com/code-yeongyu/oh-my-openagent) by [@code-yeongyu](https://github.com/code-yeongyu). Thanks for the shape that made this clean.
|
|
126
126
|
|
|
127
127
|
## License
|
package/auth.schema.json
CHANGED
|
@@ -498,6 +498,115 @@
|
|
|
498
498
|
"currentAccount",
|
|
499
499
|
"accounts"
|
|
500
500
|
]
|
|
501
|
+
},
|
|
502
|
+
"webex": {
|
|
503
|
+
"type": "object",
|
|
504
|
+
"properties": {
|
|
505
|
+
"currentAccount": {
|
|
506
|
+
"anyOf": [
|
|
507
|
+
{
|
|
508
|
+
"type": "string"
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
"type": "null"
|
|
512
|
+
}
|
|
513
|
+
]
|
|
514
|
+
},
|
|
515
|
+
"accounts": {
|
|
516
|
+
"type": "object",
|
|
517
|
+
"propertyNames": {
|
|
518
|
+
"type": "string"
|
|
519
|
+
},
|
|
520
|
+
"additionalProperties": {
|
|
521
|
+
"type": "object",
|
|
522
|
+
"properties": {
|
|
523
|
+
"account_id": {
|
|
524
|
+
"type": "string"
|
|
525
|
+
},
|
|
526
|
+
"access_token": {
|
|
527
|
+
"type": "string"
|
|
528
|
+
},
|
|
529
|
+
"refresh_token": {
|
|
530
|
+
"type": "string"
|
|
531
|
+
},
|
|
532
|
+
"expires_at": {
|
|
533
|
+
"type": "number"
|
|
534
|
+
},
|
|
535
|
+
"device_url": {
|
|
536
|
+
"type": "string"
|
|
537
|
+
},
|
|
538
|
+
"user_id": {
|
|
539
|
+
"type": "string"
|
|
540
|
+
},
|
|
541
|
+
"client_id": {
|
|
542
|
+
"type": "string"
|
|
543
|
+
},
|
|
544
|
+
"client_secret": {
|
|
545
|
+
"type": "string"
|
|
546
|
+
},
|
|
547
|
+
"created_at": {
|
|
548
|
+
"type": "string"
|
|
549
|
+
},
|
|
550
|
+
"updated_at": {
|
|
551
|
+
"type": "string"
|
|
552
|
+
},
|
|
553
|
+
"email": {
|
|
554
|
+
"type": "string"
|
|
555
|
+
},
|
|
556
|
+
"encryptedPassword": {
|
|
557
|
+
"type": "object",
|
|
558
|
+
"properties": {
|
|
559
|
+
"v": {
|
|
560
|
+
"type": "number",
|
|
561
|
+
"const": 1
|
|
562
|
+
},
|
|
563
|
+
"alg": {
|
|
564
|
+
"type": "string",
|
|
565
|
+
"const": "AES-256-GCM"
|
|
566
|
+
},
|
|
567
|
+
"kid": {
|
|
568
|
+
"type": "string"
|
|
569
|
+
},
|
|
570
|
+
"iv": {
|
|
571
|
+
"type": "string"
|
|
572
|
+
},
|
|
573
|
+
"ciphertext": {
|
|
574
|
+
"type": "string"
|
|
575
|
+
},
|
|
576
|
+
"authTag": {
|
|
577
|
+
"type": "string"
|
|
578
|
+
},
|
|
579
|
+
"createdAt": {
|
|
580
|
+
"type": "string"
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
"required": [
|
|
584
|
+
"v",
|
|
585
|
+
"alg",
|
|
586
|
+
"kid",
|
|
587
|
+
"iv",
|
|
588
|
+
"ciphertext",
|
|
589
|
+
"authTag",
|
|
590
|
+
"createdAt"
|
|
591
|
+
],
|
|
592
|
+
"additionalProperties": false
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
"required": [
|
|
596
|
+
"account_id",
|
|
597
|
+
"access_token",
|
|
598
|
+
"refresh_token",
|
|
599
|
+
"expires_at",
|
|
600
|
+
"created_at",
|
|
601
|
+
"updated_at"
|
|
602
|
+
]
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
"required": [
|
|
607
|
+
"currentAccount",
|
|
608
|
+
"accounts"
|
|
609
|
+
]
|
|
501
610
|
}
|
|
502
611
|
},
|
|
503
612
|
"additionalProperties": {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeclaw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.1",
|
|
4
4
|
"homepage": "https://github.com/typeclaw/typeclaw#readme",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/typeclaw/typeclaw/issues"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@mariozechner/pi-tui": "^0.67.3",
|
|
51
51
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
52
52
|
"@mozilla/readability": "^0.6.0",
|
|
53
|
-
"agent-messenger": "2.
|
|
53
|
+
"agent-messenger": "2.23.4",
|
|
54
54
|
"cheerio": "^1.2.0",
|
|
55
55
|
"citty": "^0.2.2",
|
|
56
56
|
"cron-parser": "^5.5.0",
|
package/secrets.schema.json
CHANGED
|
@@ -498,6 +498,115 @@
|
|
|
498
498
|
"currentAccount",
|
|
499
499
|
"accounts"
|
|
500
500
|
]
|
|
501
|
+
},
|
|
502
|
+
"webex": {
|
|
503
|
+
"type": "object",
|
|
504
|
+
"properties": {
|
|
505
|
+
"currentAccount": {
|
|
506
|
+
"anyOf": [
|
|
507
|
+
{
|
|
508
|
+
"type": "string"
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
"type": "null"
|
|
512
|
+
}
|
|
513
|
+
]
|
|
514
|
+
},
|
|
515
|
+
"accounts": {
|
|
516
|
+
"type": "object",
|
|
517
|
+
"propertyNames": {
|
|
518
|
+
"type": "string"
|
|
519
|
+
},
|
|
520
|
+
"additionalProperties": {
|
|
521
|
+
"type": "object",
|
|
522
|
+
"properties": {
|
|
523
|
+
"account_id": {
|
|
524
|
+
"type": "string"
|
|
525
|
+
},
|
|
526
|
+
"access_token": {
|
|
527
|
+
"type": "string"
|
|
528
|
+
},
|
|
529
|
+
"refresh_token": {
|
|
530
|
+
"type": "string"
|
|
531
|
+
},
|
|
532
|
+
"expires_at": {
|
|
533
|
+
"type": "number"
|
|
534
|
+
},
|
|
535
|
+
"device_url": {
|
|
536
|
+
"type": "string"
|
|
537
|
+
},
|
|
538
|
+
"user_id": {
|
|
539
|
+
"type": "string"
|
|
540
|
+
},
|
|
541
|
+
"client_id": {
|
|
542
|
+
"type": "string"
|
|
543
|
+
},
|
|
544
|
+
"client_secret": {
|
|
545
|
+
"type": "string"
|
|
546
|
+
},
|
|
547
|
+
"created_at": {
|
|
548
|
+
"type": "string"
|
|
549
|
+
},
|
|
550
|
+
"updated_at": {
|
|
551
|
+
"type": "string"
|
|
552
|
+
},
|
|
553
|
+
"email": {
|
|
554
|
+
"type": "string"
|
|
555
|
+
},
|
|
556
|
+
"encryptedPassword": {
|
|
557
|
+
"type": "object",
|
|
558
|
+
"properties": {
|
|
559
|
+
"v": {
|
|
560
|
+
"type": "number",
|
|
561
|
+
"const": 1
|
|
562
|
+
},
|
|
563
|
+
"alg": {
|
|
564
|
+
"type": "string",
|
|
565
|
+
"const": "AES-256-GCM"
|
|
566
|
+
},
|
|
567
|
+
"kid": {
|
|
568
|
+
"type": "string"
|
|
569
|
+
},
|
|
570
|
+
"iv": {
|
|
571
|
+
"type": "string"
|
|
572
|
+
},
|
|
573
|
+
"ciphertext": {
|
|
574
|
+
"type": "string"
|
|
575
|
+
},
|
|
576
|
+
"authTag": {
|
|
577
|
+
"type": "string"
|
|
578
|
+
},
|
|
579
|
+
"createdAt": {
|
|
580
|
+
"type": "string"
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
"required": [
|
|
584
|
+
"v",
|
|
585
|
+
"alg",
|
|
586
|
+
"kid",
|
|
587
|
+
"iv",
|
|
588
|
+
"ciphertext",
|
|
589
|
+
"authTag",
|
|
590
|
+
"createdAt"
|
|
591
|
+
],
|
|
592
|
+
"additionalProperties": false
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
"required": [
|
|
596
|
+
"account_id",
|
|
597
|
+
"access_token",
|
|
598
|
+
"refresh_token",
|
|
599
|
+
"expires_at",
|
|
600
|
+
"created_at",
|
|
601
|
+
"updated_at"
|
|
602
|
+
]
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
"required": [
|
|
607
|
+
"currentAccount",
|
|
608
|
+
"accounts"
|
|
609
|
+
]
|
|
501
610
|
}
|
|
502
611
|
},
|
|
503
612
|
"additionalProperties": {}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toRef } from '@/channels/adapters/webex-id-ref'
|
|
1
2
|
import { MEMBERSHIP_FRESHNESS_MS, type MembershipCount } from '@/channels/membership'
|
|
2
3
|
import type { AdapterId } from '@/channels/schema'
|
|
3
4
|
import type { ChannelSelfIdentity, ReactionRef } from '@/channels/types'
|
|
@@ -156,6 +157,8 @@ const PLATFORM_INFO: Record<AdapterId, PlatformInfo> = {
|
|
|
156
157
|
supportsReactions: false,
|
|
157
158
|
supportsAttachments: true,
|
|
158
159
|
},
|
|
160
|
+
webex: { displayName: 'Webex', mentionMode: 'angle-id', supportsReactions: false, supportsAttachments: true },
|
|
161
|
+
'webex-bot': { displayName: 'Webex', mentionMode: 'angle-id', supportsReactions: false, supportsAttachments: false },
|
|
159
162
|
line: { displayName: 'LINE', mentionMode: 'alias', supportsReactions: false, supportsAttachments: false },
|
|
160
163
|
kakaotalk: { displayName: 'KakaoTalk', mentionMode: 'alias', supportsReactions: false, supportsAttachments: true },
|
|
161
164
|
}
|
|
@@ -629,6 +632,12 @@ function renderSelfMention(platformInfo: PlatformInfo, self: ChannelSelfIdentity
|
|
|
629
632
|
}
|
|
630
633
|
}
|
|
631
634
|
|
|
635
|
+
const WEBEX_ADAPTERS = new Set<AdapterId>(['webex', 'webex-bot'])
|
|
636
|
+
|
|
637
|
+
function readableChannelId(adapter: AdapterId, id: string): string {
|
|
638
|
+
return WEBEX_ADAPTERS.has(adapter) ? toRef(id) : id
|
|
639
|
+
}
|
|
640
|
+
|
|
632
641
|
function renderConversationLine(origin: {
|
|
633
642
|
adapter: AdapterId
|
|
634
643
|
workspace: string
|
|
@@ -641,8 +650,13 @@ function renderConversationLine(origin: {
|
|
|
641
650
|
if (!hasChat && !hasWorkspace) return null
|
|
642
651
|
|
|
643
652
|
const chatPrefix = origin.adapter === 'slack-bot' ? '#' : ''
|
|
644
|
-
|
|
645
|
-
|
|
653
|
+
// The parenthetical/backtick id is a human-and-model disambiguator, NOT the
|
|
654
|
+
// send target — tools source the canonical room id from the JSON origin block,
|
|
655
|
+
// which stays raw. So decode webex base64 blobs to their readable ref here.
|
|
656
|
+
const chatId = readableChannelId(origin.adapter, origin.chat)
|
|
657
|
+
const workspaceId = readableChannelId(origin.adapter, origin.workspace)
|
|
658
|
+
const chatLabel = hasChat ? `**${chatPrefix}${origin.chatName!}** (${chatId})` : `\`${chatId}\``
|
|
659
|
+
const workspaceLabel = hasWorkspace ? `**${origin.workspaceName!}** (${workspaceId})` : `\`${workspaceId}\``
|
|
646
660
|
|
|
647
661
|
return `Conversation: ${chatLabel} in ${workspaceLabel}.`
|
|
648
662
|
}
|
|
@@ -42,7 +42,7 @@ All fields are **restart-required** — the plugin reads them once at boot. The
|
|
|
42
42
|
| Cron | `__plugin_memory_dreaming` | `kind: 'prompt'`, `subagent: 'dreaming'`, scheduled per `memory.dreaming.schedule`. |
|
|
43
43
|
| Hook | `session.idle` | Per-session debouncer with size-based ceiling. Spawns `memory-logger` on idle or buffer-trip. |
|
|
44
44
|
| Hook | `session.end` | Spawns `memory-logger` immediately; also unlinks the retrieval-cache file for this session. |
|
|
45
|
-
| Hook | `session.turn.start` | **Vector on:** renders the per-turn user-prompt memory block into `event.retrievalContext.results` (direct-mode shards under budget, de-duplicated across turns per session; top-K `hybridSearch` over budget; channel origins always index/headings-only); runs for every origin that supplies a `retrievalContext`, including subagents. **Vector off:** when `buildInjectionPlan` returns `mode: 'index'` and origin is not a subagent, spawns `memory-retrieval` (detached) with the turn's `userPrompt` so the cache reflects the user's current question. Fire-and-forget; failures route through the plugin logger.
|
|
45
|
+
| Hook | `session.turn.start` | **Vector on:** renders the per-turn user-prompt memory block into `event.retrievalContext.results` (direct-mode shards under budget, de-duplicated across turns per session; top-K `hybridSearch` over budget; channel origins always index/headings-only); runs for every origin that supplies a `retrievalContext`, including user-delegated subagents (researcher, reviewer) — but NOT TypeClaw-owned infrastructure turns (`system` origins and `system`-spawned subagents memory-logger/backup, plus the dreaming cron job matched by its `__plugin_memory_dreaming` job id), whose `userPrompt` is a fixed instruction block, not a user message (see [Internal-infrastructure turns skip retrieval](#internal-infrastructure-turns-skip-retrieval)). **Vector off:** when `buildInjectionPlan` returns `mode: 'index'` and origin is not a subagent, spawns `memory-retrieval` (detached) with the turn's `userPrompt` so the cache reflects the user's current question. Fire-and-forget; failures route through the plugin logger. |
|
|
46
46
|
|
|
47
47
|
## Memory injection (two-tier, topic shards only)
|
|
48
48
|
|
|
@@ -61,6 +61,17 @@ Default budget is 16 KB. Direct mode when shard bytes sum ≤ budget: all shard
|
|
|
61
61
|
|
|
62
62
|
The invariant `suppressSystemMemory === memory.vector.enabled` is load-bearing: a session must never carry memory in both the system prompt and the user turn.
|
|
63
63
|
|
|
64
|
+
### Internal-infrastructure turns skip retrieval
|
|
65
|
+
|
|
66
|
+
The `session.turn.start` per-turn injection runs for user-delegated subagents (researcher, reviewer) but is skipped entirely for **TypeClaw-owned infrastructure turns**. Their `userPrompt` is a fixed instruction block (`buildInitialPrompt`), not a user message — feeding it into `hybridSearch` keyword-mines the subagent's own framing prose ("Read the transcript past the watermark…"), retrieves nothing useful, and embeds a ~560-token query that trips the 512-token bound warning on every spawn. None of these subagents consume injected long-term memory the way a conversational turn does, so retrieval there is pure waste.
|
|
67
|
+
|
|
68
|
+
The discriminator (`isInternalInfraTurn` in `index.ts`) matches two provenance shapes, because the infra subagents are spawned two different ways:
|
|
69
|
+
|
|
70
|
+
- **`system` provenance** — `memory-logger` and `backup` are spawned directly with a `system` parent origin, so either a `system` origin itself or a subagent whose `spawnedByOrigin.kind === 'system'` is skipped.
|
|
71
|
+
- **The dreaming cron job** — `dreaming` is spawned by the memory plugin's own cron job (`__plugin_memory_dreaming`), so its parent origin is `cron`, NOT `system` (the cron consumer stamps a `cron` parentOrigin so the subagent resolves to the right role). It is matched by that specific job id — `spawnedByOrigin.kind === 'cron' && jobId === __plugin_memory_dreaming` — derived via `buildPluginCronGlobalId` so it can't drift from the registration. A **user-scheduled** cron subagent has a different job id and is real delegated work, so it keeps memory.
|
|
72
|
+
|
|
73
|
+
This is the same "don't mine framing prose" class of bug PR #340 fixed for `memory-retrieval`, applied to the subagent turn-start path.
|
|
74
|
+
|
|
64
75
|
### Vector retrieval is parent-child, not a flat pool
|
|
65
76
|
|
|
66
77
|
When `memory.vector.enabled` is true, `hybridSearch` does **not** rank topic vectors and stream-fragment vectors together in one flat cosine pool. It uses a parent-child collapse so the result set is always topic-level current truth:
|
|
@@ -6,7 +6,7 @@ import { CronExpressionParser } from 'cron-parser'
|
|
|
6
6
|
import { z } from 'zod'
|
|
7
7
|
|
|
8
8
|
import type { SessionOrigin } from '@/agent/session-origin'
|
|
9
|
-
import { definePlugin, type SpawnSubagentOptions } from '@/plugin'
|
|
9
|
+
import { buildPluginCronGlobalId, definePlugin, type SpawnSubagentOptions } from '@/plugin'
|
|
10
10
|
import { formatLocalDate } from '@/shared'
|
|
11
11
|
|
|
12
12
|
import { createDreamingSubagent, type DreamingPayload } from './dreaming'
|
|
@@ -58,6 +58,13 @@ const DEFAULT_MIN_IDLE_DELTA_LINES = 3
|
|
|
58
58
|
// sporadic agents entirely. Operators can override via `memory.dreaming.schedule`.
|
|
59
59
|
const DEFAULT_DREAMING_SCHEDULE = '*/30 * * * *'
|
|
60
60
|
|
|
61
|
+
// Local key of the dreaming cron job (registered under `cronJobs.dreaming`) and
|
|
62
|
+
// the global id the scheduler stamps on its `parentOrigin.jobId`. Derived
|
|
63
|
+
// through the same builder the registry uses so the registration site and the
|
|
64
|
+
// infra-turn discriminator below cannot drift to different ids.
|
|
65
|
+
const DREAMING_CRON_KEY = 'dreaming'
|
|
66
|
+
const DREAMING_CRON_JOB_ID = buildPluginCronGlobalId('memory', DREAMING_CRON_KEY)
|
|
67
|
+
|
|
61
68
|
// memory-retrieval's ceiling, enforced by the orchestration layer (see
|
|
62
69
|
// `awaitWithSubagentTimeout` in @/agent/subagents). 30s is sized for the
|
|
63
70
|
// declared workload — up to 3 `memory_search` calls + 1 `write` against a
|
|
@@ -167,6 +174,35 @@ const defaultDeps: MemoryPluginDeps = {
|
|
|
167
174
|
openAppendVectorStore: (agentDir) => VectorStore.open(join(agentDir, 'memory', '.vectors', 'index.db')),
|
|
168
175
|
}
|
|
169
176
|
|
|
177
|
+
// TypeClaw-owned infrastructure subagents (memory-logger, dreaming, backup) run
|
|
178
|
+
// the agent over their OWN fixed instruction prompt, not a user message. Their
|
|
179
|
+
// `userPrompt` is the static framing block buildInitialPrompt produces — feeding
|
|
180
|
+
// it into hybridSearch keyword-mines the subagent's own prose ("Read the
|
|
181
|
+
// transcript past the watermark…"), retrieves nothing useful, and embeds a
|
|
182
|
+
// ~560-token query that trips the 512-token bound warning on every spawn. None
|
|
183
|
+
// of these subagents consume injected long-term memory the way a conversational
|
|
184
|
+
// turn does, so per-turn retrieval is pure waste here. This is the same class of
|
|
185
|
+
// "don't mine framing prose" bug PR #340 fixed for memory-retrieval, applied to
|
|
186
|
+
// the subagent turn-start path.
|
|
187
|
+
//
|
|
188
|
+
// Two provenance shapes carry infra work, because the two infra subagents are
|
|
189
|
+
// spawned differently:
|
|
190
|
+
// - memory-logger / backup: spawned directly with a `system` parent origin.
|
|
191
|
+
// - dreaming: spawned by the memory plugin's own CRON job, so its parent
|
|
192
|
+
// origin is `cron` (jobId `__plugin_memory_dreaming`), NOT `system` — the
|
|
193
|
+
// cron consumer stamps a `cron` parentOrigin so the subagent resolves to the
|
|
194
|
+
// right role (src/cron/consumer.ts). It must be matched by its specific job
|
|
195
|
+
// id, not by "any cron subagent": a user-SCHEDULED cron subagent is real
|
|
196
|
+
// delegated work and keeps memory.
|
|
197
|
+
function isInternalInfraTurn(origin: SessionOrigin | undefined): boolean {
|
|
198
|
+
if (origin === undefined) return false
|
|
199
|
+
if (origin.kind === 'system') return true
|
|
200
|
+
if (origin.kind !== 'subagent') return false
|
|
201
|
+
const spawnedBy = origin.spawnedByOrigin
|
|
202
|
+
if (spawnedBy?.kind === 'system') return true
|
|
203
|
+
return spawnedBy?.kind === 'cron' && spawnedBy.jobId === DREAMING_CRON_JOB_ID
|
|
204
|
+
}
|
|
205
|
+
|
|
170
206
|
// Builds the per-turn user-prompt memory block for a vector agent. Non-channel
|
|
171
207
|
// turns always use top-K hybrid search, regardless of total shard size. Repeated
|
|
172
208
|
// retrieved excerpts de-duplicate across turns, and an empty retrieval falls back
|
|
@@ -184,6 +220,7 @@ async function renderVectorTurnMemory(
|
|
|
184
220
|
deps: MemoryPluginDeps,
|
|
185
221
|
logger?: { info: (msg: string) => void },
|
|
186
222
|
): Promise<string> {
|
|
223
|
+
if (isInternalInfraTurn(event.origin)) return ''
|
|
187
224
|
const plan = await loadMemoryInjectionPlan(event.agentDir, { injectionBudgetBytes })
|
|
188
225
|
const isChannel = event.origin?.kind === 'channel'
|
|
189
226
|
if (plan.mode === 'direct' && isChannel) {
|
|
@@ -431,7 +468,7 @@ export function createMemoryPlugin(deps: MemoryPluginDeps = defaultDeps) {
|
|
|
431
468
|
memory_search: createMemorySearchTool(),
|
|
432
469
|
},
|
|
433
470
|
cronJobs: {
|
|
434
|
-
|
|
471
|
+
[DREAMING_CRON_KEY]: {
|
|
435
472
|
schedule: dreamingSchedule,
|
|
436
473
|
kind: 'prompt' as const,
|
|
437
474
|
prompt: '(internal: dreaming consolidation; user prompt is built by the dreaming subagent handler)',
|
|
@@ -436,7 +436,7 @@ export function createKakaotalkAdapter(options: KakaotalkAdapterOptions): Kakaot
|
|
|
436
436
|
event.chat_id,
|
|
437
437
|
)
|
|
438
438
|
logger.info(
|
|
439
|
-
`[kakaotalk] inbound log_id=${event.log_id} author=${event.author_id} ${inboundTag} type=${event.message_type} text_len=${event.message.length}`,
|
|
439
|
+
`[kakaotalk] inbound log_id=${event.log_id} author=${event.author_name ?? event.author_id} ${inboundTag} type=${event.message_type} text_len=${event.message.length}`,
|
|
440
440
|
)
|
|
441
441
|
|
|
442
442
|
// Ack the message BEFORE classify/route so the sender's unread "1"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { WebexBotClient } from 'agent-messenger/webexbot'
|
|
2
|
+
|
|
3
|
+
import type { ChannelNameResolver, ResolvedChannelNames } from '@/channels/types'
|
|
4
|
+
|
|
5
|
+
const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000
|
|
6
|
+
|
|
7
|
+
export function createWebexChannelNameResolver(deps: {
|
|
8
|
+
client: Pick<WebexBotClient, 'getSpace'>
|
|
9
|
+
ttlMs?: number
|
|
10
|
+
now?: () => number
|
|
11
|
+
}): ChannelNameResolver {
|
|
12
|
+
const ttlMs = deps.ttlMs ?? DEFAULT_TTL_MS
|
|
13
|
+
const now = deps.now ?? Date.now
|
|
14
|
+
const cache = new Map<string, { value: string; expiresAt: number }>()
|
|
15
|
+
|
|
16
|
+
return async (key): Promise<ResolvedChannelNames> => {
|
|
17
|
+
if (key.adapter !== 'webex-bot') return {}
|
|
18
|
+
const cached = cache.get(key.chat)
|
|
19
|
+
if (cached && cached.expiresAt > now()) return { chatName: cached.value }
|
|
20
|
+
try {
|
|
21
|
+
const space = await deps.client.getSpace(key.chat)
|
|
22
|
+
if (space.title === '') return {}
|
|
23
|
+
cache.set(key.chat, { value: space.title, expiresAt: now() + ttlMs })
|
|
24
|
+
return { chatName: space.title }
|
|
25
|
+
} catch {
|
|
26
|
+
return {}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { WebexBotListenerEventMap } from 'agent-messenger/webexbot'
|
|
2
|
+
|
|
3
|
+
import { matchesAnyAlias } from '@/channels/engagement'
|
|
4
|
+
import type { ChannelAdapterConfig } from '@/channels/schema'
|
|
5
|
+
import type { InboundAttachment, InboundMessage } from '@/channels/types'
|
|
6
|
+
|
|
7
|
+
export type WebexInboundMessage = WebexBotListenerEventMap['message_created'][0]
|
|
8
|
+
|
|
9
|
+
export type InboundDropReason = 'self_author' | 'empty_content' | 'pre_connect'
|
|
10
|
+
|
|
11
|
+
export type InboundClassification =
|
|
12
|
+
| { kind: 'drop'; reason: InboundDropReason }
|
|
13
|
+
| { kind: 'route'; payload: InboundMessage }
|
|
14
|
+
|
|
15
|
+
export function classifyInbound(
|
|
16
|
+
event: WebexInboundMessage,
|
|
17
|
+
_config: ChannelAdapterConfig,
|
|
18
|
+
botPersonRef: string | null,
|
|
19
|
+
selfAliases: readonly string[] = [],
|
|
20
|
+
): InboundClassification {
|
|
21
|
+
if (botPersonRef !== null && event.personRef === botPersonRef) {
|
|
22
|
+
return { kind: 'drop', reason: 'self_author' }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { text, attachments } = splitInbound(event)
|
|
26
|
+
if (text === '') return { kind: 'drop', reason: 'empty_content' }
|
|
27
|
+
|
|
28
|
+
if (botPersonRef === null) {
|
|
29
|
+
return { kind: 'drop', reason: 'pre_connect' }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const isDm = event.roomType === 'direct'
|
|
33
|
+
const structuredBotMention = event.mentionedPeopleRefs.includes(botPersonRef) || event.mentionedGroups.includes('all')
|
|
34
|
+
const aliasMatched = !structuredBotMention && matchesAnyAlias(text, selfAliases)
|
|
35
|
+
const isBotMention = structuredBotMention || aliasMatched
|
|
36
|
+
const mentionsOthers = event.mentionedPeopleRefs.length > 0 && !event.mentionedPeopleRefs.includes(botPersonRef)
|
|
37
|
+
const ts = Date.parse(event.created)
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
kind: 'route',
|
|
41
|
+
payload: {
|
|
42
|
+
adapter: 'webex-bot',
|
|
43
|
+
// Webex message events do not include an org/team id; the room ref is the
|
|
44
|
+
// stable permission bucket for group spaces while DMs use the shared key.
|
|
45
|
+
workspace: isDm ? '@dm' : event.roomRef,
|
|
46
|
+
chat: event.roomRef,
|
|
47
|
+
thread: null,
|
|
48
|
+
text,
|
|
49
|
+
...(attachments.length > 0 ? { attachments } : {}),
|
|
50
|
+
externalMessageId: event.ref,
|
|
51
|
+
authorId: event.personRef,
|
|
52
|
+
authorName: event.personEmail,
|
|
53
|
+
authorIsBot: false,
|
|
54
|
+
isBotMention,
|
|
55
|
+
// Webex Mercury only exposes parentRef inline, not the parent author. When
|
|
56
|
+
// the reply has a structured bot mention we can identify it as bot-directed;
|
|
57
|
+
// otherwise leave the parent unattributed instead of guessing. Alias matches
|
|
58
|
+
// are mention-equivalent for engagement, but they do not prove the parent
|
|
59
|
+
// is bot-authored; enrichment fetches the parent and attributes it.
|
|
60
|
+
replyToBotMessageId: event.parentRef !== undefined && structuredBotMention ? event.parentRef : null,
|
|
61
|
+
mentionsOthers,
|
|
62
|
+
replyToOtherMessageId: null,
|
|
63
|
+
isDm,
|
|
64
|
+
ts: Number.isFinite(ts) ? ts : 0,
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type SplitInbound = { text: string; attachments: InboundAttachment[] }
|
|
70
|
+
|
|
71
|
+
function splitInbound(event: WebexInboundMessage): SplitInbound {
|
|
72
|
+
const attachments = event.files.map((ref, index) => ({
|
|
73
|
+
id: index + 1,
|
|
74
|
+
kind: 'file' as const,
|
|
75
|
+
ref,
|
|
76
|
+
filename: filenameFromUrl(ref) ?? `webex-file-${index + 1}`,
|
|
77
|
+
}))
|
|
78
|
+
if (attachments.length === 0) return { text: event.text, attachments: [] }
|
|
79
|
+
const summary = attachments.map(renderPlaceholder).join('\n')
|
|
80
|
+
const text = event.text === '' ? summary : `${event.text}\n${summary}`
|
|
81
|
+
return { text, attachments }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function filenameFromUrl(ref: string): string | null {
|
|
85
|
+
try {
|
|
86
|
+
const url = new URL(ref)
|
|
87
|
+
const name = url.pathname.split('/').filter(Boolean).pop()
|
|
88
|
+
return name === undefined || name === '' ? null : name
|
|
89
|
+
} catch {
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function renderPlaceholder(attachment: InboundAttachment): string {
|
|
95
|
+
const parts: string[] = [`Webex attachment #${attachment.id}: ${attachment.kind}`]
|
|
96
|
+
if (attachment.filename !== undefined) parts.push(`name=${attachment.filename}`)
|
|
97
|
+
return `[${parts.join(' ')}]`
|
|
98
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { WebexBotClient } from 'agent-messenger/webexbot'
|
|
2
|
+
|
|
3
|
+
import type { InboundMessage, QuoteAnchorSource } from '@/channels/types'
|
|
4
|
+
|
|
5
|
+
import { resolveWebexBodyText } from './webex-format'
|
|
6
|
+
|
|
7
|
+
// Webex Mercury delivers only the parent message id inline, not its author,
|
|
8
|
+
// so the classifier cannot tell whether a reply targets the bot. We fetch the
|
|
9
|
+
// parent here (already needed for the quote anchor) and use its author to set
|
|
10
|
+
// the reply-target fields the engagement layer reads: a non-mention reply to a
|
|
11
|
+
// bot-authored parent must engage via the `reply` trigger, and a reply to a
|
|
12
|
+
// different author must suppress the solo-human fallback. Both are no-ops if
|
|
13
|
+
// the classifier already attributed the reply (it sets replyToBotMessageId
|
|
14
|
+
// when the reply also @-mentions the bot).
|
|
15
|
+
export async function enrichWebexMessageReference(args: {
|
|
16
|
+
client: Pick<WebexBotClient, 'getMessage'>
|
|
17
|
+
inbound: InboundMessage
|
|
18
|
+
parentRef?: string
|
|
19
|
+
botPersonId: string | null
|
|
20
|
+
}): Promise<InboundMessage> {
|
|
21
|
+
if (args.parentRef === undefined || args.parentRef === '') return args.inbound
|
|
22
|
+
try {
|
|
23
|
+
const parent = await args.client.getMessage(args.parentRef)
|
|
24
|
+
const attributed = attributeReply(args.inbound, parent.ref, parent.personRef, args.botPersonId)
|
|
25
|
+
const source: QuoteAnchorSource = {
|
|
26
|
+
adapter: 'webex-bot',
|
|
27
|
+
authorId: parent.personRef,
|
|
28
|
+
authorName: parent.personEmail,
|
|
29
|
+
text: resolveWebexBodyText(parent),
|
|
30
|
+
}
|
|
31
|
+
if (source.text.trim() === '') return attributed
|
|
32
|
+
return { ...attributed, referenceContext: { kind: 'reply', sources: [source] } }
|
|
33
|
+
} catch {
|
|
34
|
+
return args.inbound
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function attributeReply(
|
|
39
|
+
inbound: InboundMessage,
|
|
40
|
+
parentId: string,
|
|
41
|
+
parentPersonId: string,
|
|
42
|
+
botPersonId: string | null,
|
|
43
|
+
): InboundMessage {
|
|
44
|
+
if (inbound.replyToBotMessageId !== null || inbound.replyToOtherMessageId !== null) return inbound
|
|
45
|
+
if (botPersonId !== null && parentPersonId === botPersonId) {
|
|
46
|
+
return { ...inbound, replyToBotMessageId: parentId }
|
|
47
|
+
}
|
|
48
|
+
return { ...inbound, replyToOtherMessageId: parentId }
|
|
49
|
+
}
|