typeclaw 0.41.0 → 0.42.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 +3 -2
- package/auth.schema.json +57 -0
- package/package.json +4 -4
- package/secrets.schema.json +57 -0
- package/src/agent/adaptive-thinking-compat.ts +79 -0
- package/src/agent/index.ts +89 -107
- package/src/agent/plugin-tools.ts +77 -130
- package/src/agent/provider-error.ts +37 -0
- package/src/agent/reload-tool.ts +1 -1
- package/src/agent/session-origin.ts +1 -0
- package/src/agent/subagents.ts +2 -2
- package/src/agent/system-prompt.ts +19 -5
- package/src/agent/tool-result-budget.ts +1 -1
- package/src/agent/tools/channel-history-render.ts +21 -0
- package/src/agent/tools/channel-history.ts +2 -17
- package/src/agent/tools/channel-read.ts +206 -0
- package/src/agent/tools/stream-snapshot.ts +8 -3
- package/src/bundled-plugins/agent-browser/index.ts +18 -8
- package/src/bundled-plugins/agent-browser/skills/agent-browser/SKILL.md +26 -2
- package/src/bundled-plugins/github-cli-auth/index.ts +25 -6
- package/src/bundled-plugins/memory/README.md +4 -1
- package/src/bundled-plugins/memory/belief-sentence.ts +50 -0
- package/src/bundled-plugins/memory/dreaming.ts +13 -6
- package/src/bundled-plugins/memory/load-memory.ts +22 -2
- package/src/bundled-plugins/memory/memory-logger.ts +1 -1
- package/src/bundled-plugins/memory/vector/hybrid.ts +73 -6
- package/src/bundled-plugins/memory/vector/passages.ts +2 -24
- package/src/bundled-plugins/memory/vector/truncation.ts +28 -0
- package/src/bundled-plugins/tool-result-cap/README.md +10 -1
- package/src/bundled-plugins/tool-result-cap/cap-result.ts +8 -0
- package/src/capabilities/control-plane.ts +24 -0
- package/src/capabilities/index.ts +2 -0
- package/src/capabilities/runtime.ts +30 -0
- package/src/channels/adapters/discord-bot.ts +112 -0
- package/src/channels/adapters/instagram-channel-resolver.ts +113 -0
- package/src/channels/adapters/instagram-classify.ts +69 -0
- package/src/channels/adapters/instagram-format.ts +8 -0
- package/src/channels/adapters/instagram.ts +346 -0
- package/src/channels/adapters/slack-bot.ts +147 -0
- package/src/channels/manager.ts +96 -44
- package/src/channels/router.ts +75 -2
- package/src/channels/schema.ts +5 -0
- package/src/channels/types.ts +46 -0
- package/src/cli/channel.ts +121 -9
- package/src/cli/hostd.ts +4 -3
- package/src/cli/init.ts +1 -0
- package/src/cli/logs.ts +2 -2
- package/src/cli/restart.ts +5 -3
- package/src/cli/shell.ts +2 -2
- package/src/cli/start.ts +2 -2
- package/src/cli/status.ts +37 -14
- package/src/cli/stop.ts +2 -2
- package/src/compose/restart.ts +4 -3
- package/src/compose/start.ts +2 -2
- package/src/compose/stop.ts +2 -2
- package/src/config/channels-mutation.ts +2 -1
- package/src/config/config.ts +10 -1
- package/src/config/providers.ts +61 -9
- package/src/container/controller.ts +104 -0
- package/src/container/index.ts +9 -0
- package/src/doctor/channel-checks.ts +28 -0
- package/src/hostd/daemon.ts +11 -7
- package/src/hostd/protocol.ts +2 -0
- package/src/init/index.ts +51 -2
- package/src/init/instagram-auth.ts +289 -0
- package/src/init/run-owner-claim.ts +1 -0
- package/src/inspect/logs-item.ts +2 -2
- package/src/mcp/client.ts +1 -1
- package/src/permissions/match-rule.ts +1 -1
- package/src/permissions/resolve.ts +1 -0
- package/src/role-claim/match-rule.ts +2 -1
- package/src/run/index.ts +21 -9
- package/src/run/{codex-fetch-observer.ts → llm-fetch-observer.ts} +182 -82
- package/src/sandbox/availability.ts +2 -2
- package/src/sandbox/build.ts +1 -1
- package/src/sandbox/policy.ts +2 -2
- package/src/secrets/discord-store.ts +4 -13
- package/src/secrets/instagram-store.ts +103 -0
- package/src/secrets/kakao-store.ts +4 -13
- package/src/secrets/line-store.ts +4 -13
- package/src/secrets/schema.ts +18 -0
- package/src/secrets/secrets-provider.ts +86 -0
- package/src/secrets/slack-store.ts +4 -13
- package/src/secrets/webex-store.ts +4 -13
- package/src/server/index.ts +2 -2
- package/src/skills/typeclaw-channel-instagram/SKILL.md +30 -0
- package/src/skills/typeclaw-config/SKILL.md +5 -3
- package/src/skills/typeclaw-plugins/SKILL.md +1 -1
- package/src/stream/broker.ts +4 -3
- package/src/stream/types.ts +1 -0
- package/typeclaw.schema.json +175 -1
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
|
|
27
27
|
## Channels — one agent, many inboxes
|
|
28
28
|
|
|
29
|
-
- 📨 **Supported channels** — Slack, Discord, Telegram, Webex, LINE, KakaoTalk, GitHub, and a websocket TUI, driven by the same agent
|
|
29
|
+
- 📨 **Supported channels** — Slack, Discord, Telegram, Webex, Instagram, LINE, KakaoTalk, GitHub, and a websocket TUI, driven by the same agent
|
|
30
|
+
- 🔎 **Cross-channel reading** — beyond the conversation it's in, it can read another channel's history, pull a single message by id, or list a workspace's channels on demand, so "check what's going on in #general" or "what do you make of this message?" just works
|
|
30
31
|
- ✅ **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
|
|
31
32
|
|
|
32
33
|
## Web & research — reads the web like a person
|
|
@@ -125,7 +126,7 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for the recommended local dev loop (`bu
|
|
|
125
126
|
|
|
126
127
|
## Acknowledgments
|
|
127
128
|
|
|
128
|
-
- **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.
|
|
129
|
+
- **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`, `instagram`, `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.
|
|
129
130
|
- **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.
|
|
130
131
|
- **Question-mark attention escalation** ("Jeff Bezos detection") was suggested by [@kdhfred](https://github.com/kdhfred). Thanks for the idea that turned a wall of `?` into a real signal.
|
|
131
132
|
|
package/auth.schema.json
CHANGED
|
@@ -393,6 +393,63 @@
|
|
|
393
393
|
"accounts"
|
|
394
394
|
]
|
|
395
395
|
},
|
|
396
|
+
"instagram": {
|
|
397
|
+
"type": "object",
|
|
398
|
+
"properties": {
|
|
399
|
+
"currentAccount": {
|
|
400
|
+
"anyOf": [
|
|
401
|
+
{
|
|
402
|
+
"type": "string"
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
"type": "null"
|
|
406
|
+
}
|
|
407
|
+
]
|
|
408
|
+
},
|
|
409
|
+
"accounts": {
|
|
410
|
+
"type": "object",
|
|
411
|
+
"propertyNames": {
|
|
412
|
+
"type": "string"
|
|
413
|
+
},
|
|
414
|
+
"additionalProperties": {
|
|
415
|
+
"type": "object",
|
|
416
|
+
"properties": {
|
|
417
|
+
"account_id": {
|
|
418
|
+
"type": "string"
|
|
419
|
+
},
|
|
420
|
+
"username": {
|
|
421
|
+
"type": "string"
|
|
422
|
+
},
|
|
423
|
+
"full_name": {
|
|
424
|
+
"type": "string"
|
|
425
|
+
},
|
|
426
|
+
"profile_pic_url": {
|
|
427
|
+
"type": "string"
|
|
428
|
+
},
|
|
429
|
+
"pk": {
|
|
430
|
+
"type": "string"
|
|
431
|
+
},
|
|
432
|
+
"created_at": {
|
|
433
|
+
"type": "string"
|
|
434
|
+
},
|
|
435
|
+
"updated_at": {
|
|
436
|
+
"type": "string"
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
"required": [
|
|
440
|
+
"account_id",
|
|
441
|
+
"username",
|
|
442
|
+
"created_at",
|
|
443
|
+
"updated_at"
|
|
444
|
+
]
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
"required": [
|
|
449
|
+
"currentAccount",
|
|
450
|
+
"accounts"
|
|
451
|
+
]
|
|
452
|
+
},
|
|
396
453
|
"kakaotalk": {
|
|
397
454
|
"type": "object",
|
|
398
455
|
"properties": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeclaw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.1",
|
|
4
4
|
"homepage": "https://github.com/typeclaw/typeclaw#readme",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/typeclaw/typeclaw/issues"
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"@clack/core": "^1.2.0",
|
|
47
47
|
"@clack/prompts": "^1.2.0",
|
|
48
48
|
"@huggingface/transformers": "4.2.0",
|
|
49
|
-
"@mariozechner/pi-coding-agent": "^0.
|
|
50
|
-
"@mariozechner/pi-tui": "^0.
|
|
49
|
+
"@mariozechner/pi-coding-agent": "^0.73.1",
|
|
50
|
+
"@mariozechner/pi-tui": "^0.73.1",
|
|
51
51
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
52
52
|
"@mozilla/readability": "^0.6.0",
|
|
53
|
-
"agent-messenger": "^2.
|
|
53
|
+
"agent-messenger": "^2.28.0",
|
|
54
54
|
"cheerio": "^1.2.0",
|
|
55
55
|
"citty": "^0.2.2",
|
|
56
56
|
"cron-parser": "^5.5.0",
|
package/secrets.schema.json
CHANGED
|
@@ -393,6 +393,63 @@
|
|
|
393
393
|
"accounts"
|
|
394
394
|
]
|
|
395
395
|
},
|
|
396
|
+
"instagram": {
|
|
397
|
+
"type": "object",
|
|
398
|
+
"properties": {
|
|
399
|
+
"currentAccount": {
|
|
400
|
+
"anyOf": [
|
|
401
|
+
{
|
|
402
|
+
"type": "string"
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
"type": "null"
|
|
406
|
+
}
|
|
407
|
+
]
|
|
408
|
+
},
|
|
409
|
+
"accounts": {
|
|
410
|
+
"type": "object",
|
|
411
|
+
"propertyNames": {
|
|
412
|
+
"type": "string"
|
|
413
|
+
},
|
|
414
|
+
"additionalProperties": {
|
|
415
|
+
"type": "object",
|
|
416
|
+
"properties": {
|
|
417
|
+
"account_id": {
|
|
418
|
+
"type": "string"
|
|
419
|
+
},
|
|
420
|
+
"username": {
|
|
421
|
+
"type": "string"
|
|
422
|
+
},
|
|
423
|
+
"full_name": {
|
|
424
|
+
"type": "string"
|
|
425
|
+
},
|
|
426
|
+
"profile_pic_url": {
|
|
427
|
+
"type": "string"
|
|
428
|
+
},
|
|
429
|
+
"pk": {
|
|
430
|
+
"type": "string"
|
|
431
|
+
},
|
|
432
|
+
"created_at": {
|
|
433
|
+
"type": "string"
|
|
434
|
+
},
|
|
435
|
+
"updated_at": {
|
|
436
|
+
"type": "string"
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
"required": [
|
|
440
|
+
"account_id",
|
|
441
|
+
"username",
|
|
442
|
+
"created_at",
|
|
443
|
+
"updated_at"
|
|
444
|
+
]
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
"required": [
|
|
449
|
+
"currentAccount",
|
|
450
|
+
"accounts"
|
|
451
|
+
]
|
|
452
|
+
},
|
|
396
453
|
"kakaotalk": {
|
|
397
454
|
"type": "object",
|
|
398
455
|
"properties": {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Compatibility shim for adaptive-thinking-only Anthropic models on the
|
|
2
|
+
// pinned pi stack (@mariozechner/* 0.73.x).
|
|
3
|
+
//
|
|
4
|
+
// The problem: Sonnet 5 and Fable 5 accept ONLY adaptive thinking. Manual
|
|
5
|
+
// extended thinking (`thinking: {type: "enabled"}` with `budget_tokens`)
|
|
6
|
+
// returns a 400. But pi-ai's `supportsAdaptiveThinking()` matches only
|
|
7
|
+
// 4.6-generation ids (`opus-4-6`, `sonnet-4-6`), so for any OTHER Anthropic
|
|
8
|
+
// model registered with `reasoning: true` it falls back to the budget-based
|
|
9
|
+
// path — and thinking is on by default (pi-coding-agent's
|
|
10
|
+
// DEFAULT_THINKING_LEVEL is "medium", and `defaultThinkingLevelForRef`
|
|
11
|
+
// deliberately defers to it). Net effect without this shim: a session on
|
|
12
|
+
// Sonnet 5 / Fable 5 400s on its first request. Still true on 0.73.1: pi-ai
|
|
13
|
+
// 0.73.1 does not force adaptive thinking for these ids, so bumping the
|
|
14
|
+
// @mariozechner/* stack to 0.73 (PR #1123) did not obviate this shim.
|
|
15
|
+
//
|
|
16
|
+
// The fix: pi-ai calls `options.onPayload(params, model)` right before the
|
|
17
|
+
// HTTP request and adopts a non-undefined return value as the request params
|
|
18
|
+
// (see `streamAnthropic` in pi-ai's providers/anthropic.ts). We hook that seam
|
|
19
|
+
// via `Agent.onPayload` — a public field, same seam `src/agent/index.ts`
|
|
20
|
+
// already uses for `convertToLlm` (the replay sanitizer) — and rewrite
|
|
21
|
+
// `thinking: {type: "enabled", ...}` to `thinking: {type: "adaptive"}` for
|
|
22
|
+
// exactly the adaptive-only model ids. Everything else passes through
|
|
23
|
+
// byte-identical.
|
|
24
|
+
//
|
|
25
|
+
// Not covered (deliberately): pi-ai also sends the
|
|
26
|
+
// `interleaved-thinking-2025-05-14` beta header for non-4.6 models. That
|
|
27
|
+
// header is set at SDK-client construction, before `onPayload` runs, so this
|
|
28
|
+
// shim can't remove it — it is redundant-but-harmless on adaptive models (the
|
|
29
|
+
// API ignores it), unlike the budget `thinking` payload which hard-fails.
|
|
30
|
+
//
|
|
31
|
+
// TODO(pi-migration): DELETE THIS FILE when typeclaw migrates off the
|
|
32
|
+
// @mariozechner/pi-* 0.73.x line to @earendil-works/pi-* >= 0.80 (the same
|
|
33
|
+
// maintainers' scope rename; @mariozechner ends at 0.73.1, @earendil-works
|
|
34
|
+
// starts at 0.74.0). As of @earendil-works/pi-ai 0.80.3 the sonnet-5 / fable-5
|
|
35
|
+
// model records carry `compat: { forceAdaptiveThinking: true }`, and the
|
|
36
|
+
// Anthropic transport reads that flag to emit `thinking: {type: "adaptive"}`
|
|
37
|
+
// itself (AnthropicMessagesCompat.forceAdaptiveThinking) — so on that stack the
|
|
38
|
+
// rewrite here becomes redundant and both this file and its `onPayload` wiring
|
|
39
|
+
// in `src/agent/index.ts` should be removed.
|
|
40
|
+
|
|
41
|
+
import type { Api, Model } from '@mariozechner/pi-ai'
|
|
42
|
+
|
|
43
|
+
type OnPayload = (payload: unknown, model: Model<Api>) => unknown | undefined | Promise<unknown | undefined>
|
|
44
|
+
|
|
45
|
+
type OnPayloadHost = { onPayload?: OnPayload }
|
|
46
|
+
|
|
47
|
+
// Mirrors pi-ai's own id matching style (`String.includes`, date-suffix
|
|
48
|
+
// tolerant). Scoped to the Anthropic Messages API so a same-named id on a
|
|
49
|
+
// different transport (e.g. a Bedrock alias) is never touched.
|
|
50
|
+
export function isAdaptiveOnlyAnthropicModel(model: Pick<Model<Api>, 'api' | 'id'>): boolean {
|
|
51
|
+
if (model.api !== 'anthropic-messages') return false
|
|
52
|
+
return model.id.includes('sonnet-5') || model.id.includes('fable-5')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Pure rewrite: budget-based `thinking` -> `{type: "adaptive"}` for
|
|
56
|
+
// adaptive-only models. Returns the ORIGINAL payload object (not a clone)
|
|
57
|
+
// whenever no rewrite applies, so "untouched" is reference-checkable in tests.
|
|
58
|
+
export function rewriteThinkingForAdaptiveOnlyModels(payload: unknown, model: Pick<Model<Api>, 'api' | 'id'>): unknown {
|
|
59
|
+
if (!isAdaptiveOnlyAnthropicModel(model)) return payload
|
|
60
|
+
if (payload === null || typeof payload !== 'object') return payload
|
|
61
|
+
if (!('thinking' in payload)) return payload
|
|
62
|
+
const thinking = payload.thinking
|
|
63
|
+
if (thinking === null || typeof thinking !== 'object') return payload
|
|
64
|
+
if (!('type' in thinking) || thinking.type !== 'enabled') return payload
|
|
65
|
+
return { ...payload, thinking: { type: 'adaptive' } }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Layers the rewrite over an agent's existing `onPayload` (pi-coding-agent
|
|
69
|
+
// installs one that dispatches extension `before_provider_request` handlers).
|
|
70
|
+
// Honors pi's contract that an `undefined` return means "keep the original
|
|
71
|
+
// payload": the inner hook's undefined falls back to the incoming payload
|
|
72
|
+
// before the rewrite runs, so the rewrite always sees the effective params.
|
|
73
|
+
export function applyAdaptiveThinkingCompat(agent: OnPayloadHost): void {
|
|
74
|
+
const inner = agent.onPayload
|
|
75
|
+
agent.onPayload = async (payload, model) => {
|
|
76
|
+
const effective = inner === undefined ? payload : ((await inner(payload, model)) ?? payload)
|
|
77
|
+
return rewriteThinkingForAdaptiveOnlyModels(effective, model)
|
|
78
|
+
}
|
|
79
|
+
}
|
package/src/agent/index.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { fileURLToPath } from 'node:url'
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
createAgentSession,
|
|
7
|
-
createCodingTools,
|
|
8
7
|
DefaultResourceLoader,
|
|
9
8
|
defineTool as definePiTool,
|
|
10
9
|
SessionManager,
|
|
@@ -34,10 +33,11 @@ import type {
|
|
|
34
33
|
RegisteredTool as PluginRegisteredTool,
|
|
35
34
|
Tool as PluginTool,
|
|
36
35
|
} from '@/plugin'
|
|
37
|
-
import { materializeSkills } from '@/plugin'
|
|
36
|
+
import { createHookBus, materializeSkills } from '@/plugin'
|
|
38
37
|
import type { ReloadRegistry } from '@/reload'
|
|
39
38
|
import type { Stream } from '@/stream'
|
|
40
39
|
|
|
40
|
+
import { applyAdaptiveThinkingCompat } from './adaptive-thinking-compat'
|
|
41
41
|
import { getAuthFor } from './auth'
|
|
42
42
|
import { createCompactionSettingsManager } from './compaction'
|
|
43
43
|
import { renderGitNudge } from './git-nudge'
|
|
@@ -47,9 +47,9 @@ import { applyModelRuntimeOverrides } from './model-overrides'
|
|
|
47
47
|
import { createChannelLookAtTool, lookAtTool } from './multimodal'
|
|
48
48
|
import {
|
|
49
49
|
buildBuiltinPiToolOverrides,
|
|
50
|
+
isPiCodingBuiltinName,
|
|
50
51
|
resolveBuiltinToolRefs,
|
|
51
52
|
wrapPluginTool,
|
|
52
|
-
wrapSystemAgentTool,
|
|
53
53
|
wrapSystemTool,
|
|
54
54
|
zodToToolParameters,
|
|
55
55
|
} from './plugin-tools'
|
|
@@ -63,21 +63,17 @@ import { renderSessionOrigin, type SessionOrigin, type SessionRoleContext } from
|
|
|
63
63
|
import type { CreateSessionForSubagent, SubagentRegistry } from './subagents'
|
|
64
64
|
import {
|
|
65
65
|
buildDefaultSystemPrompt,
|
|
66
|
+
buildSlimSystemPrompt,
|
|
66
67
|
DEFAULT_SUBAGENT_ROSTER,
|
|
67
68
|
renderRuntimeBlock,
|
|
68
|
-
SLIM_SYSTEM_PROMPT,
|
|
69
69
|
} from './system-prompt'
|
|
70
70
|
import { attachToolNotFoundNudge } from './tool-not-found-nudge'
|
|
71
|
-
import {
|
|
72
|
-
createBudgetState,
|
|
73
|
-
type ToolResultBudget,
|
|
74
|
-
wrapAgentToolWithBudget,
|
|
75
|
-
wrapToolDefinitionWithBudget,
|
|
76
|
-
} from './tool-result-budget'
|
|
71
|
+
import { createBudgetState, type ToolResultBudget, wrapToolDefinitionWithBudget } from './tool-result-budget'
|
|
77
72
|
import { createChannelDisengageTool } from './tools/channel-disengage'
|
|
78
73
|
import { createChannelFetchAttachmentTool } from './tools/channel-fetch-attachment'
|
|
79
74
|
import { createChannelHistoryTool } from './tools/channel-history'
|
|
80
75
|
import { createChannelReactTool } from './tools/channel-react'
|
|
76
|
+
import { createChannelReadTool } from './tools/channel-read'
|
|
81
77
|
import { createChannelReplyTool } from './tools/channel-reply'
|
|
82
78
|
import { createChannelSendTool } from './tools/channel-send'
|
|
83
79
|
import { createGrantRoleTool } from './tools/grant-role'
|
|
@@ -99,13 +95,6 @@ export { renderTurnRoleAnchor, renderTurnTimeAnchor } from './system-prompt'
|
|
|
99
95
|
|
|
100
96
|
type AgentSessionTools = NonNullable<Parameters<typeof createAgentSession>[0]>['tools']
|
|
101
97
|
|
|
102
|
-
// pi's default active built-in tools when a session declares no `tools:` filter
|
|
103
|
-
// (pi `createAgentSession` falls back to `defaultActiveToolNames`, which is the
|
|
104
|
-
// name set of `codingTools`). Derived from pi's own `createCodingTools()` rather
|
|
105
|
-
// than hardcoded so the list can't silently drift if pi adds/removes/renames a
|
|
106
|
-
// default builtin; `default-pi-builtins match pi's coding tool set` pins it.
|
|
107
|
-
const DEFAULT_PI_BUILTIN_TOOL_NAMES = createCodingTools(process.cwd()).map((t) => t.name)
|
|
108
|
-
|
|
109
98
|
export type PluginSessionWiring = {
|
|
110
99
|
registry: PluginRegistry
|
|
111
100
|
hooks: HookBus
|
|
@@ -310,16 +299,15 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
310
299
|
const abortHolder: { abort?: (reason?: string) => void; reason?: string } = {}
|
|
311
300
|
const getAbort: () => ((reason?: string) => void) | undefined = () => abortHolder.abort
|
|
312
301
|
|
|
313
|
-
// Subagent built-in tool refs
|
|
314
|
-
//
|
|
315
|
-
//
|
|
316
|
-
//
|
|
317
|
-
// subagent pi-side builtins) are mutually exclusive — `options.tools` is only
|
|
318
|
-
// passed by non-subagent callers like multimodal look-at; subagent sessions
|
|
319
|
-
// never set both.
|
|
302
|
+
// Subagent built-in tool refs resolve to `ToolDefinition`s (see
|
|
303
|
+
// plugin-tools.ts). Their NAMES narrow the session via `tools:`; their wrapped
|
|
304
|
+
// implementations arrive through `customTools` (either `builtinPiToolOverrides`
|
|
305
|
+
// for pi coding builtins, or `customSystemTools` for typeclaw web tools).
|
|
320
306
|
const resolvedSubagentBuiltins = options.pluginSubagent?.toolRefs
|
|
321
|
-
? resolveBuiltinToolRefs(options.pluginSubagent.toolRefs)
|
|
322
|
-
:
|
|
307
|
+
? resolveBuiltinToolRefs(options.pluginSubagent.toolRefs, options.plugins?.agentDir ?? process.cwd())
|
|
308
|
+
: []
|
|
309
|
+
const subagentBuiltinNames = resolvedSubagentBuiltins.map((t) => t.name)
|
|
310
|
+
const subagentTypeclawToolDefinitions = resolvedSubagentBuiltins.filter((t) => !isPiCodingBuiltinName(t.name))
|
|
323
311
|
const pluginCustomTools = options.pluginSubagent
|
|
324
312
|
? wrapSubagentCustomTools(options.pluginSubagent, options.plugins, getOrigin, getAbort)
|
|
325
313
|
: wrapRegistryTools(options.plugins, getOrigin, getAbort)
|
|
@@ -336,15 +324,12 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
336
324
|
: undefined
|
|
337
325
|
const sessionBudgetState = sessionBudget ? createBudgetState() : undefined
|
|
338
326
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
wrapAgentToolWithBudget(t, sessionBudget, sessionBudgetState),
|
|
346
|
-
) as typeof hookWrappedTools)
|
|
347
|
-
: hookWrappedTools
|
|
327
|
+
// The session's tool-name allowlist (pi 0.73 `tools:` is names, not tools).
|
|
328
|
+
// A subagent narrows to its declared refs; a non-subagent caller passes its
|
|
329
|
+
// own explicit list (e.g. look-at's `[]`); everyone else leaves it undefined
|
|
330
|
+
// so pi's default builtins apply. Implementations arrive via `customTools`;
|
|
331
|
+
// budget-wrapping happens there, not here.
|
|
332
|
+
const tools: AgentSessionTools = options.tools ?? (options.pluginSubagent ? subagentBuiltinNames : undefined)
|
|
348
333
|
|
|
349
334
|
// Hoisted above tool construction so the restart tool can be wired with the
|
|
350
335
|
// session's stable identity (sessionManager.getSessionId()). Subscribers use
|
|
@@ -383,7 +368,7 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
383
368
|
? options.customTools
|
|
384
369
|
: options.pluginSubagent
|
|
385
370
|
? [
|
|
386
|
-
...
|
|
371
|
+
...subagentTypeclawToolDefinitions,
|
|
387
372
|
...buildSubagentOrchestrationTools({
|
|
388
373
|
liveRegistry: options.liveSubagentRegistry,
|
|
389
374
|
registry: options.subagentRegistry,
|
|
@@ -433,23 +418,23 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
433
418
|
}),
|
|
434
419
|
...buildTodoTools(options.plugins?.agentDir, getOrigin),
|
|
435
420
|
]
|
|
436
|
-
//
|
|
437
|
-
//
|
|
438
|
-
//
|
|
439
|
-
//
|
|
440
|
-
//
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
421
|
+
// TypeClaw owns every pi builtin (read/bash/edit/write/grep/find/ls): each is
|
|
422
|
+
// wrapped with the hook + guard + sandbox + bash-policy pipeline and shipped
|
|
423
|
+
// via `customTools`, and the call site sets `noTools: "builtin"` so pi's own
|
|
424
|
+
// unwrapped copies are never the active implementation. Built unconditionally
|
|
425
|
+
// — the sandbox and bash policy are security behavior independent of whether
|
|
426
|
+
// any plugin registered a tool hook, so gating on hooks would leave an
|
|
427
|
+
// unsandboxed bash path. `wrapBuiltinToolDefinition` no-ops the optional
|
|
428
|
+
// stages (plugin hooks, permissions, bashPolicy) when they are absent.
|
|
429
|
+
const builtinPiToolOverrides = buildBuiltinPiToolOverrides({
|
|
430
|
+
agentDir: options.plugins?.agentDir ?? process.cwd(),
|
|
431
|
+
sessionId: options.plugins?.sessionId ?? sessionManager.getSessionId(),
|
|
432
|
+
hooks: options.plugins?.hooks ?? createHookBus(),
|
|
433
|
+
getOrigin,
|
|
434
|
+
getAbort,
|
|
435
|
+
...(options.permissions ? { permissions: options.permissions } : {}),
|
|
436
|
+
...(options.bashPolicy !== undefined ? { bashPolicy: options.bashPolicy } : {}),
|
|
437
|
+
})
|
|
453
438
|
const wrappedCustomSystemTools = wrapSystemTools(customSystemTools, options.plugins, getOrigin, getAbort)
|
|
454
439
|
const customToolsPreBudget = [...wrappedCustomSystemTools, ...pluginCustomTools, ...builtinPiToolOverrides]
|
|
455
440
|
const customTools =
|
|
@@ -457,6 +442,19 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
457
442
|
? customToolsPreBudget.map((t) => wrapToolDefinitionWithBudget(t, sessionBudget, sessionBudgetState))
|
|
458
443
|
: customToolsPreBudget
|
|
459
444
|
|
|
445
|
+
// The exact set of tool names the session exposes to the model, and the single
|
|
446
|
+
// source of truth passed to `createAgentSession({ tools })`. Because we set
|
|
447
|
+
// `noTools: "builtin"`, pi's default active set is empty — this list IS the
|
|
448
|
+
// active set. `builtinPiToolOverrides` names supply read/bash/edit/write/grep/
|
|
449
|
+
// find/ls; `wrappedCustomSystemTools` + `pluginCustomTools` add the typeclaw/
|
|
450
|
+
// plugin surface. A subagent's `tools` (subagentBuiltinNames) narrows the
|
|
451
|
+
// builtin slice to exactly its declared refs. Also feeds the tool-not-found
|
|
452
|
+
// nudge vocabulary so the two never drift.
|
|
453
|
+
const builtinActiveNames = tools ?? builtinPiToolOverrides.map((t) => t.name)
|
|
454
|
+
const intendedActiveToolNames = [
|
|
455
|
+
...new Set([...builtinActiveNames, ...[...wrappedCustomSystemTools, ...pluginCustomTools].map((t) => t.name)]),
|
|
456
|
+
]
|
|
457
|
+
|
|
460
458
|
const model = applyModelRuntimeOverrides(resolveModel(activeRef), activeRef)
|
|
461
459
|
// Read live so a reloaded `models` lands on the next session without a
|
|
462
460
|
// container restart.
|
|
@@ -468,7 +466,8 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
468
466
|
authStorage,
|
|
469
467
|
modelRegistry,
|
|
470
468
|
resourceLoader,
|
|
471
|
-
|
|
469
|
+
noTools: 'builtin',
|
|
470
|
+
tools: intendedActiveToolNames,
|
|
472
471
|
customTools,
|
|
473
472
|
...(thinkingLevel ? { thinkingLevel } : {}),
|
|
474
473
|
})
|
|
@@ -490,35 +489,18 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
490
489
|
}
|
|
491
490
|
}
|
|
492
491
|
|
|
492
|
+
// Same seam, one hook later: layer the adaptive-thinking rewrite over pi's
|
|
493
|
+
// onPayload so Sonnet 5 / Fable 5 never receive the budget-based `thinking`
|
|
494
|
+
// payload the pinned pi-ai 0.73.x emits for them (a hard 400 — see
|
|
495
|
+
// adaptive-thinking-compat.ts). Covers every provider call path through the
|
|
496
|
+
// agent, including model switches mid-session.
|
|
497
|
+
applyAdaptiveThinkingCompat(session.agent)
|
|
498
|
+
|
|
493
499
|
abortHolder.abort = (reason?: string) => {
|
|
494
500
|
if (reason !== undefined) abortHolder.reason = reason
|
|
495
501
|
if (session.agent.signal?.aborted !== true) session.agent.abort()
|
|
496
502
|
}
|
|
497
503
|
|
|
498
|
-
// The names the session actually exposes to the model: pi's active base set
|
|
499
|
-
// (the caller's `tools:` filter, or pi's default builtins when unset) union
|
|
500
|
-
// the typeclaw/plugin custom tools. Deliberately EXCLUDES
|
|
501
|
-
// `builtinPiToolOverrides` — those replace builtin implementations by name,
|
|
502
|
-
// they are not additional callable names. This is the single source of truth
|
|
503
|
-
// for both the active-set re-narrowing below and the tool-not-found nudge
|
|
504
|
-
// vocabulary, so the two never drift (a divergence would make the nudge miss
|
|
505
|
-
// real tools or suggest tools the session deliberately did not expose).
|
|
506
|
-
const intendedActiveToolNames = [
|
|
507
|
-
...new Set([
|
|
508
|
-
...(tools !== undefined ? tools.map((t) => t.name) : DEFAULT_PI_BUILTIN_TOOL_NAMES),
|
|
509
|
-
...[...wrappedCustomSystemTools, ...pluginCustomTools].map((t) => t.name),
|
|
510
|
-
]),
|
|
511
|
-
]
|
|
512
|
-
|
|
513
|
-
// Re-narrow the active tool set after `createAgentSession`. pi 0.67.3's
|
|
514
|
-
// `_refreshToolRegistry` runs with `includeAllExtensionTools: true` and
|
|
515
|
-
// pushes every customTool name into the active set, which would widen
|
|
516
|
-
// a subagent's declared `[edit]` to all 7 builtin overrides plus every
|
|
517
|
-
// typeclaw custom tool.
|
|
518
|
-
if (builtinPiToolOverrides.length > 0) {
|
|
519
|
-
session.setActiveToolsByName(intendedActiveToolNames)
|
|
520
|
-
}
|
|
521
|
-
|
|
522
504
|
const unsubRestart = subscribeRestartNotice(options.stream, sessionManager)
|
|
523
505
|
|
|
524
506
|
const unsubToolNudge = attachToolNotFoundNudge(session, intendedActiveToolNames)
|
|
@@ -665,12 +647,13 @@ export function formatRestartNoticeOriginating(restartedAt: string): string {
|
|
|
665
647
|
].join('\n')
|
|
666
648
|
}
|
|
667
649
|
|
|
668
|
-
// Builds the channel tool subset: channel_send
|
|
669
|
-
//
|
|
670
|
-
//
|
|
671
|
-
//
|
|
672
|
-
// (when sessionId is known)
|
|
673
|
-
// addressing or per-session turn
|
|
650
|
+
// Builds the channel tool subset: channel_send and channel_read (both always
|
|
651
|
+
// when a router is available — they take explicit addressing, not origin-bound),
|
|
652
|
+
// plus the origin-bound channel tools when the session origin is a channel —
|
|
653
|
+
// channel_reply, channel_history, channel_react, channel_fetch_attachment,
|
|
654
|
+
// look_at_channel_attachment, channel_disengage, and (when sessionId is known)
|
|
655
|
+
// skip_response. Those rely on origin-bound addressing or per-session turn
|
|
656
|
+
// state. Extracted from
|
|
674
657
|
// createSessionWithDispose so composition can be unit-tested without
|
|
675
658
|
// going through createAgentSession / auth.
|
|
676
659
|
//
|
|
@@ -702,6 +685,7 @@ export function buildChannelTools(
|
|
|
702
685
|
}),
|
|
703
686
|
)
|
|
704
687
|
tools.push(createChannelHistoryTool({ router: channelRouter, origin: channelOrigin }))
|
|
688
|
+
tools.push(createChannelReadTool({ router: channelRouter }))
|
|
705
689
|
tools.push(
|
|
706
690
|
createChannelSendTool({
|
|
707
691
|
router: channelRouter,
|
|
@@ -736,6 +720,7 @@ export function buildChannelTools(
|
|
|
736
720
|
}
|
|
737
721
|
} else {
|
|
738
722
|
tools.push(createChannelSendTool({ router: channelRouter }))
|
|
723
|
+
tools.push(createChannelReadTool({ router: channelRouter }))
|
|
739
724
|
}
|
|
740
725
|
return tools
|
|
741
726
|
}
|
|
@@ -869,24 +854,6 @@ function wrapRegistryTools(
|
|
|
869
854
|
)
|
|
870
855
|
}
|
|
871
856
|
|
|
872
|
-
function wrapSystemAgentTools(
|
|
873
|
-
tools: AgentSessionTools | undefined,
|
|
874
|
-
plugins: PluginSessionWiring | undefined,
|
|
875
|
-
getOrigin: () => SessionOrigin | undefined,
|
|
876
|
-
getAbort: () => ((reason?: string) => void) | undefined,
|
|
877
|
-
): AgentSessionTools | undefined {
|
|
878
|
-
if (!tools || !hasToolHooks(plugins)) return tools
|
|
879
|
-
return tools.map((tool) =>
|
|
880
|
-
wrapSystemAgentTool(tool, {
|
|
881
|
-
agentDir: plugins.agentDir,
|
|
882
|
-
sessionId: plugins.sessionId,
|
|
883
|
-
hooks: plugins.hooks,
|
|
884
|
-
getOrigin,
|
|
885
|
-
getAbort,
|
|
886
|
-
}),
|
|
887
|
-
)
|
|
888
|
-
}
|
|
889
|
-
|
|
890
857
|
function wrapSystemTools(
|
|
891
858
|
tools: ToolDefinition[],
|
|
892
859
|
plugins: PluginSessionWiring | undefined,
|
|
@@ -948,9 +915,13 @@ export async function createOverrideResourceLoader(
|
|
|
948
915
|
runtimeVersion?: string,
|
|
949
916
|
): Promise<DefaultResourceLoader> {
|
|
950
917
|
const withRuntime =
|
|
951
|
-
runtimeVersion !== undefined
|
|
918
|
+
getConfig().branding && runtimeVersion !== undefined
|
|
919
|
+
? `${systemPrompt}\n\n${renderRuntimeBlock(runtimeVersion)}`
|
|
920
|
+
: systemPrompt
|
|
952
921
|
const finalPrompt = withOrigin(withRuntime, origin, permissions)
|
|
953
922
|
const loader = new DefaultResourceLoader({
|
|
923
|
+
cwd: process.cwd(),
|
|
924
|
+
agentDir: process.cwd(),
|
|
954
925
|
systemPromptOverride: () => finalPrompt,
|
|
955
926
|
appendSystemPromptOverride: () => [],
|
|
956
927
|
})
|
|
@@ -1030,6 +1001,10 @@ export type SystemPromptMode = 'full' | 'slim'
|
|
|
1030
1001
|
|
|
1031
1002
|
export type SystemPromptComposition = {
|
|
1032
1003
|
mode?: SystemPromptMode
|
|
1004
|
+
// Whether the prompt discloses that the agent runs on TypeClaw. When false,
|
|
1005
|
+
// the base prompt's opening is phrased generically and the `## Runtime`
|
|
1006
|
+
// version block is dropped. Defaults to true. Mirrors `config.branding`.
|
|
1007
|
+
branding?: boolean
|
|
1033
1008
|
self: string
|
|
1034
1009
|
// Pre-rendered full-mode orchestration roster (from `renderPublicSubagentRoster`).
|
|
1035
1010
|
// Kept as a ready string so this composer stays pure and registry-free; the
|
|
@@ -1067,12 +1042,13 @@ export type SystemPromptComposition = {
|
|
|
1067
1042
|
// suffix anyway — and removes the staleness failure mode where a session
|
|
1068
1043
|
// opened Friday answered "today is Friday" on Thursday.
|
|
1069
1044
|
export function composeSystemPrompt(parts: SystemPromptComposition): string {
|
|
1045
|
+
const branding = parts.branding ?? true
|
|
1070
1046
|
const base =
|
|
1071
1047
|
parts.mode === 'slim'
|
|
1072
|
-
?
|
|
1073
|
-
: buildDefaultSystemPrompt(parts.subagentRoster ?? DEFAULT_SUBAGENT_ROSTER)
|
|
1048
|
+
? buildSlimSystemPrompt(branding)
|
|
1049
|
+
: buildDefaultSystemPrompt(parts.subagentRoster ?? DEFAULT_SUBAGENT_ROSTER, branding)
|
|
1074
1050
|
let prompt = `${base}\n\n${parts.self}`
|
|
1075
|
-
if (parts.runtimeVersion !== undefined) {
|
|
1051
|
+
if (branding && parts.runtimeVersion !== undefined) {
|
|
1076
1052
|
prompt = `${prompt}\n\n${renderRuntimeBlock(parts.runtimeVersion)}`
|
|
1077
1053
|
}
|
|
1078
1054
|
if (parts.origin !== undefined) {
|
|
@@ -1103,8 +1079,11 @@ export async function createResourceLoader(options: CreateResourceLoaderOptions
|
|
|
1103
1079
|
: options.subagentRegistry !== undefined
|
|
1104
1080
|
? renderPublicSubagentRoster(options.subagentRegistry)
|
|
1105
1081
|
: DEFAULT_SUBAGENT_ROSTER
|
|
1082
|
+
const branding = getConfig().branding
|
|
1106
1083
|
const basePrompt =
|
|
1107
|
-
mode === 'slim'
|
|
1084
|
+
mode === 'slim'
|
|
1085
|
+
? buildSlimSystemPrompt(branding)
|
|
1086
|
+
: buildDefaultSystemPrompt(subagentRoster ?? DEFAULT_SUBAGENT_ROSTER, branding)
|
|
1108
1087
|
|
|
1109
1088
|
// Kick off the independent I/O paths concurrently. Sequential awaits
|
|
1110
1089
|
// here used to be the dominant cold-start cost amplifier: loadSelf is 2
|
|
@@ -1169,6 +1148,7 @@ export async function createResourceLoader(options: CreateResourceLoaderOptions
|
|
|
1169
1148
|
|
|
1170
1149
|
const systemPrompt = composeSystemPrompt({
|
|
1171
1150
|
mode,
|
|
1151
|
+
branding,
|
|
1172
1152
|
self,
|
|
1173
1153
|
subagentRoster,
|
|
1174
1154
|
...(options.runtimeVersion !== undefined ? { runtimeVersion: options.runtimeVersion } : {}),
|
|
@@ -1209,6 +1189,8 @@ export async function createResourceLoader(options: CreateResourceLoaderOptions
|
|
|
1209
1189
|
}
|
|
1210
1190
|
|
|
1211
1191
|
const loader = new DefaultResourceLoader({
|
|
1192
|
+
cwd: agentDir,
|
|
1193
|
+
agentDir,
|
|
1212
1194
|
systemPromptOverride: () => systemPrompt,
|
|
1213
1195
|
appendSystemPromptOverride: () => [],
|
|
1214
1196
|
additionalSkillPaths,
|