typeclaw 0.39.2 → 0.39.3
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/auth.schema.json +110 -0
- package/package.json +2 -2
- package/secrets.schema.json +110 -0
- package/src/agent/index.ts +44 -19
- package/src/agent/plugin-tools.ts +12 -12
- package/src/agent/session-origin.ts +2 -0
- package/src/agent/todo/store.ts +21 -1
- package/src/agent/tools/channel-reply.ts +18 -5
- package/src/agent/tools/channel-send.ts +13 -2
- package/src/bundled-plugins/doc-render/render.ts +2 -2
- package/src/bundled-plugins/github-cli-auth/approve-idempotency.ts +40 -18
- package/src/channels/adapters/discord-author-resolver.ts +52 -0
- package/src/channels/adapters/discord-bot.ts +1 -1
- package/src/channels/adapters/discord-channel-resolver.ts +44 -0
- package/src/channels/adapters/discord-classify.ts +121 -0
- package/src/channels/adapters/discord-reactions.ts +138 -0
- package/src/channels/adapters/discord.ts +416 -0
- package/src/channels/adapters/github/outbound.ts +23 -4
- package/src/channels/adapters/kakaotalk.ts +8 -1
- package/src/channels/adapters/line.ts +1 -1
- package/src/channels/adapters/slack-author-resolver.ts +54 -0
- package/src/channels/adapters/slack-bot.ts +3 -1
- package/src/channels/adapters/slack-channel-resolver.ts +49 -0
- package/src/channels/adapters/slack-classify.ts +83 -0
- package/src/channels/adapters/slack-reactions.ts +126 -0
- package/src/channels/adapters/slack.ts +416 -0
- package/src/channels/adapters/telegram-bot.ts +2 -1
- package/src/channels/adapters/webex-bot.ts +5 -2
- package/src/channels/adapters/webex.ts +55 -2
- package/src/channels/github-review-turn-ledger.ts +32 -0
- package/src/channels/github-verdict-activity.ts +60 -0
- package/src/channels/index.ts +6 -0
- package/src/channels/manager.ts +130 -6
- package/src/channels/pr-verdict-activity-bridge.ts +43 -0
- package/src/channels/router.ts +161 -9
- package/src/channels/schema.ts +4 -0
- package/src/channels/types.ts +17 -1
- package/src/cli/builtins.ts +1 -0
- package/src/cli/channel.ts +170 -18
- package/src/cli/index.ts +11 -0
- package/src/cli/init.ts +2 -0
- package/src/cli/update-check.ts +14 -0
- package/src/cli/update-notify.ts +91 -0
- package/src/cli/update-suppression.ts +19 -0
- package/src/config/channels-mutation.ts +3 -1
- package/src/config/config.ts +51 -0
- package/src/config/index.ts +1 -0
- package/src/container/start.ts +30 -6
- package/src/doctor/channel-checks.ts +57 -3
- package/src/hostd/daemon.ts +22 -5
- package/src/hostd/index.ts +11 -1
- package/src/hostd/paths.ts +4 -0
- package/src/hostd/protocol.ts +15 -2
- package/src/init/cli-version.ts +1 -1
- package/src/init/discord-auth.ts +50 -0
- package/src/init/index.ts +94 -4
- package/src/init/reconcile-plugin-deps.ts +30 -5
- package/src/init/run-owner-claim.ts +2 -0
- package/src/init/slack-auth.ts +51 -0
- package/src/mcp/manager.ts +94 -7
- package/src/mcp/tools.ts +7 -4
- package/src/permissions/resolve.ts +2 -0
- package/src/role-claim/match-rule.ts +2 -0
- package/src/run/index.ts +74 -29
- package/src/secrets/discord-store.ts +96 -0
- package/src/secrets/schema.ts +34 -0
- package/src/secrets/slack-store.ts +96 -0
- package/src/server/command-runner.ts +21 -0
- package/src/skills/typeclaw-cron/SKILL.md +13 -2
- package/src/tui/format.ts +0 -19
- package/src/tui/index.ts +2 -8
- package/src/update/check.ts +192 -0
- package/typeclaw.schema.json +332 -0
package/auth.schema.json
CHANGED
|
@@ -116,6 +116,57 @@
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
},
|
|
119
|
+
"discord": {
|
|
120
|
+
"type": "object",
|
|
121
|
+
"properties": {
|
|
122
|
+
"currentAccount": {
|
|
123
|
+
"anyOf": [
|
|
124
|
+
{
|
|
125
|
+
"type": "string"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"type": "null"
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"accounts": {
|
|
133
|
+
"type": "object",
|
|
134
|
+
"propertyNames": {
|
|
135
|
+
"type": "string"
|
|
136
|
+
},
|
|
137
|
+
"additionalProperties": {
|
|
138
|
+
"type": "object",
|
|
139
|
+
"properties": {
|
|
140
|
+
"account_id": {
|
|
141
|
+
"type": "string"
|
|
142
|
+
},
|
|
143
|
+
"token": {
|
|
144
|
+
"type": "string"
|
|
145
|
+
},
|
|
146
|
+
"username": {
|
|
147
|
+
"type": "string"
|
|
148
|
+
},
|
|
149
|
+
"created_at": {
|
|
150
|
+
"type": "string"
|
|
151
|
+
},
|
|
152
|
+
"updated_at": {
|
|
153
|
+
"type": "string"
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
"required": [
|
|
157
|
+
"account_id",
|
|
158
|
+
"token",
|
|
159
|
+
"created_at",
|
|
160
|
+
"updated_at"
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"required": [
|
|
166
|
+
"currentAccount",
|
|
167
|
+
"accounts"
|
|
168
|
+
]
|
|
169
|
+
},
|
|
119
170
|
"discord-bot": {
|
|
120
171
|
"type": "object",
|
|
121
172
|
"properties": {
|
|
@@ -607,6 +658,65 @@
|
|
|
607
658
|
"currentAccount",
|
|
608
659
|
"accounts"
|
|
609
660
|
]
|
|
661
|
+
},
|
|
662
|
+
"slack": {
|
|
663
|
+
"type": "object",
|
|
664
|
+
"properties": {
|
|
665
|
+
"currentAccount": {
|
|
666
|
+
"anyOf": [
|
|
667
|
+
{
|
|
668
|
+
"type": "string"
|
|
669
|
+
},
|
|
670
|
+
{
|
|
671
|
+
"type": "null"
|
|
672
|
+
}
|
|
673
|
+
]
|
|
674
|
+
},
|
|
675
|
+
"accounts": {
|
|
676
|
+
"type": "object",
|
|
677
|
+
"propertyNames": {
|
|
678
|
+
"type": "string"
|
|
679
|
+
},
|
|
680
|
+
"additionalProperties": {
|
|
681
|
+
"type": "object",
|
|
682
|
+
"properties": {
|
|
683
|
+
"account_id": {
|
|
684
|
+
"type": "string"
|
|
685
|
+
},
|
|
686
|
+
"token": {
|
|
687
|
+
"type": "string"
|
|
688
|
+
},
|
|
689
|
+
"cookie": {
|
|
690
|
+
"type": "string"
|
|
691
|
+
},
|
|
692
|
+
"workspace_id": {
|
|
693
|
+
"type": "string"
|
|
694
|
+
},
|
|
695
|
+
"workspace_name": {
|
|
696
|
+
"type": "string"
|
|
697
|
+
},
|
|
698
|
+
"created_at": {
|
|
699
|
+
"type": "string"
|
|
700
|
+
},
|
|
701
|
+
"updated_at": {
|
|
702
|
+
"type": "string"
|
|
703
|
+
}
|
|
704
|
+
},
|
|
705
|
+
"required": [
|
|
706
|
+
"account_id",
|
|
707
|
+
"token",
|
|
708
|
+
"cookie",
|
|
709
|
+
"workspace_id",
|
|
710
|
+
"created_at",
|
|
711
|
+
"updated_at"
|
|
712
|
+
]
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
},
|
|
716
|
+
"required": [
|
|
717
|
+
"currentAccount",
|
|
718
|
+
"accounts"
|
|
719
|
+
]
|
|
610
720
|
}
|
|
611
721
|
},
|
|
612
722
|
"additionalProperties": {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeclaw",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.3",
|
|
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.27.1",
|
|
54
54
|
"cheerio": "^1.2.0",
|
|
55
55
|
"citty": "^0.2.2",
|
|
56
56
|
"cron-parser": "^5.5.0",
|
package/secrets.schema.json
CHANGED
|
@@ -116,6 +116,57 @@
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
},
|
|
119
|
+
"discord": {
|
|
120
|
+
"type": "object",
|
|
121
|
+
"properties": {
|
|
122
|
+
"currentAccount": {
|
|
123
|
+
"anyOf": [
|
|
124
|
+
{
|
|
125
|
+
"type": "string"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"type": "null"
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"accounts": {
|
|
133
|
+
"type": "object",
|
|
134
|
+
"propertyNames": {
|
|
135
|
+
"type": "string"
|
|
136
|
+
},
|
|
137
|
+
"additionalProperties": {
|
|
138
|
+
"type": "object",
|
|
139
|
+
"properties": {
|
|
140
|
+
"account_id": {
|
|
141
|
+
"type": "string"
|
|
142
|
+
},
|
|
143
|
+
"token": {
|
|
144
|
+
"type": "string"
|
|
145
|
+
},
|
|
146
|
+
"username": {
|
|
147
|
+
"type": "string"
|
|
148
|
+
},
|
|
149
|
+
"created_at": {
|
|
150
|
+
"type": "string"
|
|
151
|
+
},
|
|
152
|
+
"updated_at": {
|
|
153
|
+
"type": "string"
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
"required": [
|
|
157
|
+
"account_id",
|
|
158
|
+
"token",
|
|
159
|
+
"created_at",
|
|
160
|
+
"updated_at"
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"required": [
|
|
166
|
+
"currentAccount",
|
|
167
|
+
"accounts"
|
|
168
|
+
]
|
|
169
|
+
},
|
|
119
170
|
"discord-bot": {
|
|
120
171
|
"type": "object",
|
|
121
172
|
"properties": {
|
|
@@ -607,6 +658,65 @@
|
|
|
607
658
|
"currentAccount",
|
|
608
659
|
"accounts"
|
|
609
660
|
]
|
|
661
|
+
},
|
|
662
|
+
"slack": {
|
|
663
|
+
"type": "object",
|
|
664
|
+
"properties": {
|
|
665
|
+
"currentAccount": {
|
|
666
|
+
"anyOf": [
|
|
667
|
+
{
|
|
668
|
+
"type": "string"
|
|
669
|
+
},
|
|
670
|
+
{
|
|
671
|
+
"type": "null"
|
|
672
|
+
}
|
|
673
|
+
]
|
|
674
|
+
},
|
|
675
|
+
"accounts": {
|
|
676
|
+
"type": "object",
|
|
677
|
+
"propertyNames": {
|
|
678
|
+
"type": "string"
|
|
679
|
+
},
|
|
680
|
+
"additionalProperties": {
|
|
681
|
+
"type": "object",
|
|
682
|
+
"properties": {
|
|
683
|
+
"account_id": {
|
|
684
|
+
"type": "string"
|
|
685
|
+
},
|
|
686
|
+
"token": {
|
|
687
|
+
"type": "string"
|
|
688
|
+
},
|
|
689
|
+
"cookie": {
|
|
690
|
+
"type": "string"
|
|
691
|
+
},
|
|
692
|
+
"workspace_id": {
|
|
693
|
+
"type": "string"
|
|
694
|
+
},
|
|
695
|
+
"workspace_name": {
|
|
696
|
+
"type": "string"
|
|
697
|
+
},
|
|
698
|
+
"created_at": {
|
|
699
|
+
"type": "string"
|
|
700
|
+
},
|
|
701
|
+
"updated_at": {
|
|
702
|
+
"type": "string"
|
|
703
|
+
}
|
|
704
|
+
},
|
|
705
|
+
"required": [
|
|
706
|
+
"account_id",
|
|
707
|
+
"token",
|
|
708
|
+
"cookie",
|
|
709
|
+
"workspace_id",
|
|
710
|
+
"created_at",
|
|
711
|
+
"updated_at"
|
|
712
|
+
]
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
},
|
|
716
|
+
"required": [
|
|
717
|
+
"currentAccount",
|
|
718
|
+
"accounts"
|
|
719
|
+
]
|
|
610
720
|
}
|
|
611
721
|
},
|
|
612
722
|
"additionalProperties": {}
|
package/src/agent/index.ts
CHANGED
|
@@ -238,22 +238,32 @@ export type CreateSessionOptions = {
|
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
export type CreateSessionResult = {
|
|
241
|
-
session: AgentSession
|
|
241
|
+
session: AgentSession & { getAbortReason?: () => string | undefined }
|
|
242
242
|
dispose: () => Promise<void>
|
|
243
|
+
getAbortReason?: () => string | undefined
|
|
243
244
|
}
|
|
244
245
|
|
|
245
246
|
// A session's reasoning effort layers like the model does: the resolved
|
|
246
|
-
// profile's own `thinkingLevel` → the `
|
|
247
|
-
// (the de-facto global default
|
|
248
|
-
//
|
|
249
|
-
//
|
|
250
|
-
//
|
|
247
|
+
// profile's own `thinkingLevel` → the built-in `deep` default → the `default`
|
|
248
|
+
// profile's `thinkingLevel` (the de-facto global default) → the per-provider/SDK
|
|
249
|
+
// default for the active ref. When the requested profile was unknown, `resolved`
|
|
250
|
+
// is already the `default` profile, so those terms coincide and the expression
|
|
251
|
+
// still does the right thing.
|
|
252
|
+
//
|
|
253
|
+
// The `deep` `high` default sits ABOVE `models.default.thinkingLevel` on purpose:
|
|
254
|
+
// lowering the global default must not stop the "think hard" profile from
|
|
255
|
+
// thinking hard. `high` (not `xhigh`) because `xhigh` ~doubles latency and token
|
|
256
|
+
// spend for no agentic-quality gain. An explicit `models.deep.thinkingLevel`
|
|
257
|
+
// still wins — it is the first term.
|
|
258
|
+
const DEEP_PROFILE_DEFAULT_THINKING_LEVEL: ThinkingLevel = 'high'
|
|
259
|
+
|
|
251
260
|
export function resolveSessionThinkingLevel(
|
|
252
261
|
models: Models,
|
|
253
|
-
resolved: Pick<ResolvedProfile, 'thinkingLevel'>,
|
|
262
|
+
resolved: Pick<ResolvedProfile, 'thinkingLevel' | 'profile'>,
|
|
254
263
|
activeRef: ModelRef,
|
|
255
264
|
): ThinkingLevel | undefined {
|
|
256
|
-
|
|
265
|
+
const deepDefault = resolved.profile === 'deep' ? DEEP_PROFILE_DEFAULT_THINKING_LEVEL : undefined
|
|
266
|
+
return resolved.thinkingLevel ?? deepDefault ?? models.default.thinkingLevel ?? defaultThinkingLevelForRef(activeRef)
|
|
257
267
|
}
|
|
258
268
|
|
|
259
269
|
export async function createSession(options: CreateSessionOptions = {}): Promise<AgentSession> {
|
|
@@ -309,8 +319,8 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
309
319
|
// Tools are wrapped BEFORE the session exists, so the loop guard reaches the
|
|
310
320
|
// abort through this lazily-resolved getter. See `fireLoopAbort` in
|
|
311
321
|
// plugin-tools.ts for why aborting (not throwing) is what stops the loop.
|
|
312
|
-
const abortHolder: { abort?: () => void } = {}
|
|
313
|
-
const getAbort: () => (() => void) | undefined = () => abortHolder.abort
|
|
322
|
+
const abortHolder: { abort?: (reason?: string) => void; reason?: string } = {}
|
|
323
|
+
const getAbort: () => ((reason?: string) => void) | undefined = () => abortHolder.abort
|
|
314
324
|
|
|
315
325
|
// Subagent built-in tool refs are dual-routed (see BUILTIN_TOOL_DEFINITION
|
|
316
326
|
// dual-map in plugin-tools.ts): pi-side coding tools go to `tools:` so they
|
|
@@ -474,6 +484,8 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
474
484
|
customTools,
|
|
475
485
|
...(thinkingLevel ? { thinkingLevel } : {}),
|
|
476
486
|
})
|
|
487
|
+
const getAbortReason = () => abortHolder.reason
|
|
488
|
+
const sessionWithAbortReason = Object.assign(session, { getAbortReason })
|
|
477
489
|
|
|
478
490
|
// Layer the replay sanitizer over pi's convertToLlm so a transcript with an
|
|
479
491
|
// orphaned toolResult (e.g. a torn-down restart turn) can't wedge the session
|
|
@@ -490,7 +502,8 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
490
502
|
}
|
|
491
503
|
}
|
|
492
504
|
|
|
493
|
-
abortHolder.abort = () => {
|
|
505
|
+
abortHolder.abort = (reason?: string) => {
|
|
506
|
+
if (reason !== undefined) abortHolder.reason = reason
|
|
494
507
|
if (session.agent.signal?.aborted !== true) session.agent.abort()
|
|
495
508
|
}
|
|
496
509
|
|
|
@@ -527,7 +540,7 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
527
540
|
unsubToolNudge()
|
|
528
541
|
if (materializedSkills) await materializedSkills.dispose()
|
|
529
542
|
}
|
|
530
|
-
return { session, dispose }
|
|
543
|
+
return { session: sessionWithAbortReason, dispose, getAbortReason }
|
|
531
544
|
}
|
|
532
545
|
|
|
533
546
|
// Decides whether the restart tool should write the cross-restart handoff
|
|
@@ -851,7 +864,7 @@ export function buildTodoTools(
|
|
|
851
864
|
function wrapRegistryTools(
|
|
852
865
|
plugins: PluginSessionWiring | undefined,
|
|
853
866
|
getOrigin: () => SessionOrigin | undefined,
|
|
854
|
-
getAbort: () => (() => void) | undefined,
|
|
867
|
+
getAbort: () => ((reason?: string) => void) | undefined,
|
|
855
868
|
): ToolDefinition[] {
|
|
856
869
|
if (!plugins) return []
|
|
857
870
|
return plugins.registry.tools.map((t: PluginRegisteredTool) =>
|
|
@@ -872,7 +885,7 @@ function wrapSystemAgentTools(
|
|
|
872
885
|
tools: AgentSessionTools | undefined,
|
|
873
886
|
plugins: PluginSessionWiring | undefined,
|
|
874
887
|
getOrigin: () => SessionOrigin | undefined,
|
|
875
|
-
getAbort: () => (() => void) | undefined,
|
|
888
|
+
getAbort: () => ((reason?: string) => void) | undefined,
|
|
876
889
|
): AgentSessionTools | undefined {
|
|
877
890
|
if (!tools || !hasToolHooks(plugins)) return tools
|
|
878
891
|
return tools.map((tool) =>
|
|
@@ -890,7 +903,7 @@ function wrapSystemTools(
|
|
|
890
903
|
tools: ToolDefinition[],
|
|
891
904
|
plugins: PluginSessionWiring | undefined,
|
|
892
905
|
getOrigin: () => SessionOrigin | undefined,
|
|
893
|
-
getAbort: () => (() => void) | undefined,
|
|
906
|
+
getAbort: () => ((reason?: string) => void) | undefined,
|
|
894
907
|
): ToolDefinition[] {
|
|
895
908
|
if (!hasToolHooks(plugins)) return tools
|
|
896
909
|
return tools.map((tool) =>
|
|
@@ -913,7 +926,7 @@ function wrapSubagentCustomTools(
|
|
|
913
926
|
selection: PluginSubagentSelection,
|
|
914
927
|
plugins: PluginSessionWiring | undefined,
|
|
915
928
|
getOrigin: () => SessionOrigin | undefined,
|
|
916
|
-
getAbort: () => (() => void) | undefined,
|
|
929
|
+
getAbort: () => ((reason?: string) => void) | undefined,
|
|
917
930
|
): ToolDefinition[] {
|
|
918
931
|
if (!selection.customTools || !plugins) return []
|
|
919
932
|
const logger = makePluginLogger(selection.pluginName)
|
|
@@ -1155,6 +1168,14 @@ export async function createResourceLoader(options: CreateResourceLoaderOptions
|
|
|
1155
1168
|
...(options.plugins?.sessionId !== undefined ? { currentSessionId: options.plugins.sessionId } : {}),
|
|
1156
1169
|
}),
|
|
1157
1170
|
)
|
|
1171
|
+
// MCP connection is warmed up in the background at boot; gate the catalog
|
|
1172
|
+
// render on that warm-up settling (bounded) so a session created in the
|
|
1173
|
+
// warm-up window still lists connected servers. Kicked off here to overlap
|
|
1174
|
+
// with the self/git/memory I/O above instead of serializing before compose.
|
|
1175
|
+
const mcpReadySettled =
|
|
1176
|
+
mode === 'full' && options.mcpManager !== undefined
|
|
1177
|
+
? options.mcpManager.whenInitialConnectSettled()
|
|
1178
|
+
: Promise.resolve()
|
|
1158
1179
|
|
|
1159
1180
|
let self = await selfPromise
|
|
1160
1181
|
|
|
@@ -1183,6 +1204,12 @@ export async function createResourceLoader(options: CreateResourceLoaderOptions
|
|
|
1183
1204
|
const gitNudge = unwrapSettled(gitNudgeResult)
|
|
1184
1205
|
const memorySection = unwrapSettled(memoryResult)
|
|
1185
1206
|
|
|
1207
|
+
let mcpCatalog: string | undefined
|
|
1208
|
+
if (mode === 'full' && options.mcpManager !== undefined) {
|
|
1209
|
+
await mcpReadySettled
|
|
1210
|
+
mcpCatalog = renderMcpCatalog(options.mcpManager.listServers())
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1186
1213
|
const systemPrompt = composeSystemPrompt({
|
|
1187
1214
|
mode,
|
|
1188
1215
|
self,
|
|
@@ -1190,9 +1217,7 @@ export async function createResourceLoader(options: CreateResourceLoaderOptions
|
|
|
1190
1217
|
...(options.runtimeVersion !== undefined ? { runtimeVersion: options.runtimeVersion } : {}),
|
|
1191
1218
|
...(options.origin !== undefined ? { origin: options.origin } : {}),
|
|
1192
1219
|
...(roleContext !== undefined ? { roleContext } : {}),
|
|
1193
|
-
...(
|
|
1194
|
-
? { mcpCatalog: renderMcpCatalog(options.mcpManager.listServers()) }
|
|
1195
|
-
: {}),
|
|
1220
|
+
...(mcpCatalog !== undefined ? { mcpCatalog } : {}),
|
|
1196
1221
|
gitNudge,
|
|
1197
1222
|
...(options.proactiveNextStepNudge === true ? { proactiveNextStepNudge: PROACTIVE_NEXT_STEP_NUDGE } : {}),
|
|
1198
1223
|
memorySection,
|
|
@@ -190,7 +190,7 @@ export type WrapToolOptions = {
|
|
|
190
190
|
// Resolves the current turn's abort handle. Resolved lazily (not at wrap
|
|
191
191
|
// time) because tools are wrapped BEFORE `createAgentSession` returns the
|
|
192
192
|
// session whose `agent.abort` this points at. See `fireLoopAbort`.
|
|
193
|
-
getAbort?: () => (() => void) | undefined
|
|
193
|
+
getAbort?: () => ((reason?: string) => void) | undefined
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
export type WrapSystemToolOptions = {
|
|
@@ -198,7 +198,7 @@ export type WrapSystemToolOptions = {
|
|
|
198
198
|
sessionId: string
|
|
199
199
|
hooks: HookBus
|
|
200
200
|
getOrigin?: () => SessionOrigin | undefined
|
|
201
|
-
getAbort?: () => (() => void) | undefined
|
|
201
|
+
getAbort?: () => ((reason?: string) => void) | undefined
|
|
202
202
|
// When present, the bash builtin is rewritten through the per-tool bwrap
|
|
203
203
|
// sandbox with role-derived path masks. Absent (or no masks for the role)
|
|
204
204
|
// runs bash unchanged — preserving today's behavior for trusted+ and for
|
|
@@ -262,7 +262,7 @@ export function wrapPluginTool(tool: Tool<any>, opts: WrapToolOptions): ToolDefi
|
|
|
262
262
|
|
|
263
263
|
const loopGate = gateLoopGuard(opts.sessionId, opts.toolName, before.args)
|
|
264
264
|
if (loopGate.blockNow) {
|
|
265
|
-
fireLoopAbort(opts.getAbort)
|
|
265
|
+
fireLoopAbort(opts.getAbort, 'loop_guard:block')
|
|
266
266
|
return errorResult(loopGate.message)
|
|
267
267
|
}
|
|
268
268
|
|
|
@@ -283,7 +283,7 @@ export function wrapPluginTool(tool: Tool<any>, opts: WrapToolOptions): ToolDefi
|
|
|
283
283
|
|
|
284
284
|
const resolved = loopGate.resolve(result)
|
|
285
285
|
if ('deferredBlock' in resolved) {
|
|
286
|
-
fireLoopAbort(opts.getAbort)
|
|
286
|
+
fireLoopAbort(opts.getAbort, 'loop_guard:deferred_block')
|
|
287
287
|
return errorResult(resolved.deferredBlock)
|
|
288
288
|
}
|
|
289
289
|
result = resolved.result
|
|
@@ -325,7 +325,7 @@ export function wrapSystemTool<TParams extends TSchema, TDetails = unknown, TSta
|
|
|
325
325
|
}
|
|
326
326
|
const loopGate = gateLoopGuard(opts.sessionId, tool.name, mutableArgs)
|
|
327
327
|
if (loopGate.blockNow) {
|
|
328
|
-
fireLoopAbort(opts.getAbort)
|
|
328
|
+
fireLoopAbort(opts.getAbort, 'loop_guard:block')
|
|
329
329
|
throw new Error(loopGate.message)
|
|
330
330
|
}
|
|
331
331
|
const guardResult = await runFinalWriteGuards({
|
|
@@ -345,7 +345,7 @@ export function wrapSystemTool<TParams extends TSchema, TDetails = unknown, TSta
|
|
|
345
345
|
const result = await tool.execute(toolCallId, mutableArgs as Static<TParams>, signal, onUpdate, ctx)
|
|
346
346
|
const resolved = loopGate.resolve({ content: result.content as ContentPart[], details: result.details })
|
|
347
347
|
if ('deferredBlock' in resolved) {
|
|
348
|
-
fireLoopAbort(opts.getAbort)
|
|
348
|
+
fireLoopAbort(opts.getAbort, 'loop_guard:deferred_block')
|
|
349
349
|
throw new Error(resolved.deferredBlock)
|
|
350
350
|
}
|
|
351
351
|
const hookResult = resolved.result
|
|
@@ -385,7 +385,7 @@ export function wrapSystemAgentTool<TParams extends TSchema, TDetails = unknown>
|
|
|
385
385
|
}
|
|
386
386
|
const loopGate = gateLoopGuard(opts.sessionId, tool.name, mutableArgs)
|
|
387
387
|
if (loopGate.blockNow) {
|
|
388
|
-
fireLoopAbort(opts.getAbort)
|
|
388
|
+
fireLoopAbort(opts.getAbort, 'loop_guard:block')
|
|
389
389
|
throw new Error(loopGate.message)
|
|
390
390
|
}
|
|
391
391
|
const guardResult = await runFinalWriteGuards({
|
|
@@ -405,7 +405,7 @@ export function wrapSystemAgentTool<TParams extends TSchema, TDetails = unknown>
|
|
|
405
405
|
const result = await tool.execute(toolCallId, mutableArgs as Static<TParams>, signal, onUpdate)
|
|
406
406
|
const resolved = loopGate.resolve({ content: result.content as ContentPart[], details: result.details })
|
|
407
407
|
if ('deferredBlock' in resolved) {
|
|
408
|
-
fireLoopAbort(opts.getAbort)
|
|
408
|
+
fireLoopAbort(opts.getAbort, 'loop_guard:deferred_block')
|
|
409
409
|
throw new Error(resolved.deferredBlock)
|
|
410
410
|
}
|
|
411
411
|
const hookResult = resolved.result
|
|
@@ -460,7 +460,7 @@ export function wrapAgentToolAsCustomToolDefinition<TParams extends TSchema, TDe
|
|
|
460
460
|
delete mutableArgs[TYPECLAW_INTERNAL_BASH_ENV]
|
|
461
461
|
const loopGate = gateLoopGuard(opts.sessionId, tool.name, mutableArgs)
|
|
462
462
|
if (loopGate.blockNow) {
|
|
463
|
-
fireLoopAbort(opts.getAbort)
|
|
463
|
+
fireLoopAbort(opts.getAbort, 'loop_guard:block')
|
|
464
464
|
throw new Error(loopGate.message)
|
|
465
465
|
}
|
|
466
466
|
const guardResult = await runFinalWriteGuards({
|
|
@@ -511,7 +511,7 @@ export function wrapAgentToolAsCustomToolDefinition<TParams extends TSchema, TDe
|
|
|
511
511
|
const result = tmpRedirect !== undefined ? restoreTmpPathInResult(rawResult, tmpRedirect) : rawResult
|
|
512
512
|
const resolved = loopGate.resolve({ content: result.content as ContentPart[], details: result.details })
|
|
513
513
|
if ('deferredBlock' in resolved) {
|
|
514
|
-
fireLoopAbort(opts.getAbort)
|
|
514
|
+
fireLoopAbort(opts.getAbort, 'loop_guard:deferred_block')
|
|
515
515
|
throw new Error(resolved.deferredBlock)
|
|
516
516
|
}
|
|
517
517
|
const hookResult = resolved.result
|
|
@@ -929,8 +929,8 @@ export function __resetSharedLoopGuardForTests(): void {
|
|
|
929
929
|
// 'aborted'). We use the signal-only `agent.abort`, never `session.abort`,
|
|
930
930
|
// which would deadlock awaiting the very run this tool call belongs to. See
|
|
931
931
|
// the matching pattern in src/channels/router.ts (policy-denied send cap).
|
|
932
|
-
function fireLoopAbort(getAbort: (() => (() => void) | undefined) | undefined): void {
|
|
933
|
-
getAbort?.()?.()
|
|
932
|
+
function fireLoopAbort(getAbort: (() => ((reason?: string) => void) | undefined) | undefined, reason: string): void {
|
|
933
|
+
getAbort?.()?.(reason)
|
|
934
934
|
}
|
|
935
935
|
|
|
936
936
|
function errorResult(message: string) {
|
|
@@ -143,7 +143,9 @@ type PlatformInfo = {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
const PLATFORM_INFO: Record<AdapterId, PlatformInfo> = {
|
|
146
|
+
slack: { displayName: 'Slack', mentionMode: 'angle-id', supportsReactions: true, supportsAttachments: true },
|
|
146
147
|
'slack-bot': { displayName: 'Slack', mentionMode: 'angle-id', supportsReactions: true, supportsAttachments: true },
|
|
148
|
+
discord: { displayName: 'Discord', mentionMode: 'angle-id', supportsReactions: true, supportsAttachments: true },
|
|
147
149
|
'discord-bot': {
|
|
148
150
|
displayName: 'Discord',
|
|
149
151
|
mentionMode: 'angle-id',
|
package/src/agent/todo/store.ts
CHANGED
|
@@ -86,7 +86,27 @@ export async function writeTodos(agentDir: string, scope: TodoScope, todos: Todo
|
|
|
86
86
|
await mkdir(dirname(path), { recursive: true })
|
|
87
87
|
const tmp = `${path}.${process.pid}.${randomUUID()}.tmp`
|
|
88
88
|
await writeFile(tmp, `${JSON.stringify(payload, null, 2)}\n`, 'utf8')
|
|
89
|
-
await
|
|
89
|
+
await renameWithRetry(tmp, path)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Windows workaround: rename() onto an existing destination is not atomic and
|
|
93
|
+
// fails transiently (EPERM/EACCES/EBUSY/EEXIST) when another writer or a virus
|
|
94
|
+
// scanner / file indexer momentarily holds the target open — concurrent
|
|
95
|
+
// writeTodos calls onto the same scope file reliably trip this. The retry keeps
|
|
96
|
+
// last-writer-wins instead of rejecting a writer. POSIX rename never hits this.
|
|
97
|
+
const RENAME_RETRY_CODES = new Set(['EPERM', 'EACCES', 'EBUSY', 'EEXIST'])
|
|
98
|
+
|
|
99
|
+
async function renameWithRetry(from: string, to: string, attempts = 10): Promise<void> {
|
|
100
|
+
for (let attempt = 1; ; attempt++) {
|
|
101
|
+
try {
|
|
102
|
+
await rename(from, to)
|
|
103
|
+
return
|
|
104
|
+
} catch (err) {
|
|
105
|
+
const code = typeof err === 'object' && err !== null ? (err as { code?: unknown }).code : undefined
|
|
106
|
+
if (attempt >= attempts || typeof code !== 'string' || !RENAME_RETRY_CODES.has(code)) throw err
|
|
107
|
+
await new Promise((resolve) => setTimeout(resolve, attempt * 10))
|
|
108
|
+
}
|
|
109
|
+
}
|
|
90
110
|
}
|
|
91
111
|
|
|
92
112
|
export function incompleteTodos(todos: readonly Todo[]): Todo[] {
|
|
@@ -53,7 +53,11 @@ export function createChannelReplyTool({
|
|
|
53
53
|
'Reply in the current conversation. This is your default way to respond to a channel session — ' +
|
|
54
54
|
'addressing fields (adapter, workspace, chat, thread) are filled in from the session origin, so ' +
|
|
55
55
|
'you only supply the text. To post somewhere else (different chat, break out of the current ' +
|
|
56
|
-
'thread, etc.), use `channel_send` instead.'
|
|
56
|
+
'thread, etc.), use `channel_send` instead. ' +
|
|
57
|
+
'On success the result carries `messageId` (the posted message id) and `messageIds` (every id when ' +
|
|
58
|
+
'the text was split into multiple posts) when the platform reports them; pass `messageId` as a ' +
|
|
59
|
+
'`channel_send` `thread` to post follow-ups into the same thread. Some adapters do not report an id, ' +
|
|
60
|
+
'in which case both are absent.',
|
|
57
61
|
parameters: Type.Object({
|
|
58
62
|
text: Type.Optional(
|
|
59
63
|
Type.String({
|
|
@@ -216,10 +220,19 @@ export function createChannelReplyTool({
|
|
|
216
220
|
// `continue` is read by the router's terminal hook (installChannelReplyTerminalHook),
|
|
217
221
|
// not by this tool — it suppresses the post-reply abort so a multi-step turn
|
|
218
222
|
// keeps going. Success-only: a denied reply never ran, so there is no turn to keep.
|
|
219
|
-
const details: {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
+
const details: {
|
|
224
|
+
ok: boolean
|
|
225
|
+
error?: string
|
|
226
|
+
continue?: boolean
|
|
227
|
+
messageId?: string
|
|
228
|
+
messageIds?: readonly string[]
|
|
229
|
+
} = result.ok
|
|
230
|
+
? {
|
|
231
|
+
ok: true,
|
|
232
|
+
...(keepTurnAlive ? { continue: true } : {}),
|
|
233
|
+
...(result.messageId !== undefined ? { messageId: result.messageId } : {}),
|
|
234
|
+
...(result.messageIds !== undefined ? { messageIds: result.messageIds } : {}),
|
|
235
|
+
}
|
|
223
236
|
: { ok: false, error: result.error }
|
|
224
237
|
// Echo the delivered text back to the model. The adapter classifier
|
|
225
238
|
// drops self-authored messages on the inbound path (`self_author`),
|
|
@@ -52,7 +52,12 @@ export function createChannelSendTool({
|
|
|
52
52
|
'For Discord guild channels, workspace is the guild id; for Slack team channels, workspace is ' +
|
|
53
53
|
'the team id (e.g. "T0ACME"). For DMs on either platform, workspace is the literal "@dm". ' +
|
|
54
54
|
'On failure (no adapter registered, or the adapter-level send failed), the call returns ' +
|
|
55
|
-
'{ ok: false, error }.
|
|
55
|
+
'{ ok: false, error }. On success it returns { ok: true } and, when the platform reports it, ' +
|
|
56
|
+
'`messageId` (the posted message id, e.g. a Slack thread ts or Discord/Telegram message id) plus ' +
|
|
57
|
+
'`messageIds` (every id in send order when the post was split into multiple messages; `messageId` is ' +
|
|
58
|
+
'the reply anchor — usually the first message). Pass `messageId` back as `thread` on a later send to ' +
|
|
59
|
+
'post follow-ups into the same thread. Some adapters do not report an id, in which case both are absent. ' +
|
|
60
|
+
'There is no auto-reply: the only way for an agent to post is via this tool.',
|
|
56
61
|
parameters: Type.Object({
|
|
57
62
|
adapter: Type.Union(
|
|
58
63
|
ADAPTER_IDS.map((a) => Type.Literal(a)),
|
|
@@ -236,7 +241,13 @@ export function createChannelSendTool({
|
|
|
236
241
|
),
|
|
237
242
|
)
|
|
238
243
|
}
|
|
239
|
-
const details: { ok: boolean; error?: string
|
|
244
|
+
const details: { ok: boolean; error?: string; messageId?: string; messageIds?: readonly string[] } = result.ok
|
|
245
|
+
? {
|
|
246
|
+
ok: true,
|
|
247
|
+
...(result.messageId !== undefined ? { messageId: result.messageId } : {}),
|
|
248
|
+
...(result.messageIds !== undefined ? { messageIds: result.messageIds } : {}),
|
|
249
|
+
}
|
|
250
|
+
: { ok: false, error: result.error }
|
|
240
251
|
// Success wraps the echoed sent text in the strong SYSTEM MESSAGE fence;
|
|
241
252
|
// denials keep the lighter prefix. See channel-reply.ts for the full
|
|
242
253
|
// rationale (PR #481 self-reply loop).
|
|
@@ -79,7 +79,7 @@ export async function loadCompilerModule(cwd: string = process.cwd()): Promise<N
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export async function renderPdf(mainFile: string, outFile: string): Promise<number> {
|
|
82
|
-
const { existsSync
|
|
82
|
+
const { existsSync } = await import('node:fs')
|
|
83
83
|
|
|
84
84
|
const fontPaths = FONT_PATHS.filter((p) => existsSync(p))
|
|
85
85
|
const mod = await loadCompilerModule()
|
|
@@ -88,7 +88,7 @@ export async function renderPdf(mainFile: string, outFile: string): Promise<numb
|
|
|
88
88
|
...(fontPaths.length > 0 ? { fontArgs: [{ fontPaths }] } : {}),
|
|
89
89
|
})
|
|
90
90
|
const pdf = compiler.pdf({ mainFilePath: mainFile })
|
|
91
|
-
|
|
91
|
+
await Bun.write(outFile, pdf)
|
|
92
92
|
return pdf.length
|
|
93
93
|
}
|
|
94
94
|
|