typeclaw 0.42.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/package.json +3 -3
- package/src/agent/adaptive-thinking-compat.ts +79 -0
- package/src/agent/index.ts +79 -101
- 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/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/stream-snapshot.ts +8 -3
- package/src/bundled-plugins/agent-browser/index.ts +18 -8
- 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/capabilities/control-plane.ts +24 -0
- package/src/capabilities/index.ts +2 -0
- package/src/capabilities/runtime.ts +30 -0
- package/src/channels/manager.ts +41 -47
- package/src/channels/router.ts +11 -2
- package/src/cli/channel.ts +49 -12
- package/src/cli/hostd.ts +4 -3
- 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 +2 -2
- 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/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/init/index.ts +1 -1
- package/src/init/instagram-auth.ts +189 -34
- package/src/inspect/logs-item.ts +2 -2
- package/src/mcp/client.ts +1 -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 +4 -13
- package/src/secrets/kakao-store.ts +4 -13
- package/src/secrets/line-store.ts +4 -13
- 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 +1 -1
- 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 +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeclaw",
|
|
3
|
-
"version": "0.42.
|
|
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,8 +46,8 @@
|
|
|
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
53
|
"agent-messenger": "^2.28.0",
|
|
@@ -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,17 +63,12 @@ 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'
|
|
@@ -100,13 +95,6 @@ export { renderTurnRoleAnchor, renderTurnTimeAnchor } from './system-prompt'
|
|
|
100
95
|
|
|
101
96
|
type AgentSessionTools = NonNullable<Parameters<typeof createAgentSession>[0]>['tools']
|
|
102
97
|
|
|
103
|
-
// pi's default active built-in tools when a session declares no `tools:` filter
|
|
104
|
-
// (pi `createAgentSession` falls back to `defaultActiveToolNames`, which is the
|
|
105
|
-
// name set of `codingTools`). Derived from pi's own `createCodingTools()` rather
|
|
106
|
-
// than hardcoded so the list can't silently drift if pi adds/removes/renames a
|
|
107
|
-
// default builtin; `default-pi-builtins match pi's coding tool set` pins it.
|
|
108
|
-
const DEFAULT_PI_BUILTIN_TOOL_NAMES = createCodingTools(process.cwd()).map((t) => t.name)
|
|
109
|
-
|
|
110
98
|
export type PluginSessionWiring = {
|
|
111
99
|
registry: PluginRegistry
|
|
112
100
|
hooks: HookBus
|
|
@@ -311,16 +299,15 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
311
299
|
const abortHolder: { abort?: (reason?: string) => void; reason?: string } = {}
|
|
312
300
|
const getAbort: () => ((reason?: string) => void) | undefined = () => abortHolder.abort
|
|
313
301
|
|
|
314
|
-
// Subagent built-in tool refs
|
|
315
|
-
//
|
|
316
|
-
//
|
|
317
|
-
//
|
|
318
|
-
// subagent pi-side builtins) are mutually exclusive — `options.tools` is only
|
|
319
|
-
// passed by non-subagent callers like multimodal look-at; subagent sessions
|
|
320
|
-
// 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).
|
|
321
306
|
const resolvedSubagentBuiltins = options.pluginSubagent?.toolRefs
|
|
322
|
-
? resolveBuiltinToolRefs(options.pluginSubagent.toolRefs)
|
|
323
|
-
:
|
|
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))
|
|
324
311
|
const pluginCustomTools = options.pluginSubagent
|
|
325
312
|
? wrapSubagentCustomTools(options.pluginSubagent, options.plugins, getOrigin, getAbort)
|
|
326
313
|
: wrapRegistryTools(options.plugins, getOrigin, getAbort)
|
|
@@ -337,15 +324,12 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
337
324
|
: undefined
|
|
338
325
|
const sessionBudgetState = sessionBudget ? createBudgetState() : undefined
|
|
339
326
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
wrapAgentToolWithBudget(t, sessionBudget, sessionBudgetState),
|
|
347
|
-
) as typeof hookWrappedTools)
|
|
348
|
-
: 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)
|
|
349
333
|
|
|
350
334
|
// Hoisted above tool construction so the restart tool can be wired with the
|
|
351
335
|
// session's stable identity (sessionManager.getSessionId()). Subscribers use
|
|
@@ -384,7 +368,7 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
384
368
|
? options.customTools
|
|
385
369
|
: options.pluginSubagent
|
|
386
370
|
? [
|
|
387
|
-
...
|
|
371
|
+
...subagentTypeclawToolDefinitions,
|
|
388
372
|
...buildSubagentOrchestrationTools({
|
|
389
373
|
liveRegistry: options.liveSubagentRegistry,
|
|
390
374
|
registry: options.subagentRegistry,
|
|
@@ -434,23 +418,23 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
434
418
|
}),
|
|
435
419
|
...buildTodoTools(options.plugins?.agentDir, getOrigin),
|
|
436
420
|
]
|
|
437
|
-
//
|
|
438
|
-
//
|
|
439
|
-
//
|
|
440
|
-
//
|
|
441
|
-
//
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
+
})
|
|
454
438
|
const wrappedCustomSystemTools = wrapSystemTools(customSystemTools, options.plugins, getOrigin, getAbort)
|
|
455
439
|
const customToolsPreBudget = [...wrappedCustomSystemTools, ...pluginCustomTools, ...builtinPiToolOverrides]
|
|
456
440
|
const customTools =
|
|
@@ -458,6 +442,19 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
458
442
|
? customToolsPreBudget.map((t) => wrapToolDefinitionWithBudget(t, sessionBudget, sessionBudgetState))
|
|
459
443
|
: customToolsPreBudget
|
|
460
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
|
+
|
|
461
458
|
const model = applyModelRuntimeOverrides(resolveModel(activeRef), activeRef)
|
|
462
459
|
// Read live so a reloaded `models` lands on the next session without a
|
|
463
460
|
// container restart.
|
|
@@ -469,7 +466,8 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
469
466
|
authStorage,
|
|
470
467
|
modelRegistry,
|
|
471
468
|
resourceLoader,
|
|
472
|
-
|
|
469
|
+
noTools: 'builtin',
|
|
470
|
+
tools: intendedActiveToolNames,
|
|
473
471
|
customTools,
|
|
474
472
|
...(thinkingLevel ? { thinkingLevel } : {}),
|
|
475
473
|
})
|
|
@@ -491,35 +489,18 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
491
489
|
}
|
|
492
490
|
}
|
|
493
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
|
+
|
|
494
499
|
abortHolder.abort = (reason?: string) => {
|
|
495
500
|
if (reason !== undefined) abortHolder.reason = reason
|
|
496
501
|
if (session.agent.signal?.aborted !== true) session.agent.abort()
|
|
497
502
|
}
|
|
498
503
|
|
|
499
|
-
// The names the session actually exposes to the model: pi's active base set
|
|
500
|
-
// (the caller's `tools:` filter, or pi's default builtins when unset) union
|
|
501
|
-
// the typeclaw/plugin custom tools. Deliberately EXCLUDES
|
|
502
|
-
// `builtinPiToolOverrides` — those replace builtin implementations by name,
|
|
503
|
-
// they are not additional callable names. This is the single source of truth
|
|
504
|
-
// for both the active-set re-narrowing below and the tool-not-found nudge
|
|
505
|
-
// vocabulary, so the two never drift (a divergence would make the nudge miss
|
|
506
|
-
// real tools or suggest tools the session deliberately did not expose).
|
|
507
|
-
const intendedActiveToolNames = [
|
|
508
|
-
...new Set([
|
|
509
|
-
...(tools !== undefined ? tools.map((t) => t.name) : DEFAULT_PI_BUILTIN_TOOL_NAMES),
|
|
510
|
-
...[...wrappedCustomSystemTools, ...pluginCustomTools].map((t) => t.name),
|
|
511
|
-
]),
|
|
512
|
-
]
|
|
513
|
-
|
|
514
|
-
// Re-narrow the active tool set after `createAgentSession`. pi 0.67.3's
|
|
515
|
-
// `_refreshToolRegistry` runs with `includeAllExtensionTools: true` and
|
|
516
|
-
// pushes every customTool name into the active set, which would widen
|
|
517
|
-
// a subagent's declared `[edit]` to all 7 builtin overrides plus every
|
|
518
|
-
// typeclaw custom tool.
|
|
519
|
-
if (builtinPiToolOverrides.length > 0) {
|
|
520
|
-
session.setActiveToolsByName(intendedActiveToolNames)
|
|
521
|
-
}
|
|
522
|
-
|
|
523
504
|
const unsubRestart = subscribeRestartNotice(options.stream, sessionManager)
|
|
524
505
|
|
|
525
506
|
const unsubToolNudge = attachToolNotFoundNudge(session, intendedActiveToolNames)
|
|
@@ -873,24 +854,6 @@ function wrapRegistryTools(
|
|
|
873
854
|
)
|
|
874
855
|
}
|
|
875
856
|
|
|
876
|
-
function wrapSystemAgentTools(
|
|
877
|
-
tools: AgentSessionTools | undefined,
|
|
878
|
-
plugins: PluginSessionWiring | undefined,
|
|
879
|
-
getOrigin: () => SessionOrigin | undefined,
|
|
880
|
-
getAbort: () => ((reason?: string) => void) | undefined,
|
|
881
|
-
): AgentSessionTools | undefined {
|
|
882
|
-
if (!tools || !hasToolHooks(plugins)) return tools
|
|
883
|
-
return tools.map((tool) =>
|
|
884
|
-
wrapSystemAgentTool(tool, {
|
|
885
|
-
agentDir: plugins.agentDir,
|
|
886
|
-
sessionId: plugins.sessionId,
|
|
887
|
-
hooks: plugins.hooks,
|
|
888
|
-
getOrigin,
|
|
889
|
-
getAbort,
|
|
890
|
-
}),
|
|
891
|
-
)
|
|
892
|
-
}
|
|
893
|
-
|
|
894
857
|
function wrapSystemTools(
|
|
895
858
|
tools: ToolDefinition[],
|
|
896
859
|
plugins: PluginSessionWiring | undefined,
|
|
@@ -952,9 +915,13 @@ export async function createOverrideResourceLoader(
|
|
|
952
915
|
runtimeVersion?: string,
|
|
953
916
|
): Promise<DefaultResourceLoader> {
|
|
954
917
|
const withRuntime =
|
|
955
|
-
runtimeVersion !== undefined
|
|
918
|
+
getConfig().branding && runtimeVersion !== undefined
|
|
919
|
+
? `${systemPrompt}\n\n${renderRuntimeBlock(runtimeVersion)}`
|
|
920
|
+
: systemPrompt
|
|
956
921
|
const finalPrompt = withOrigin(withRuntime, origin, permissions)
|
|
957
922
|
const loader = new DefaultResourceLoader({
|
|
923
|
+
cwd: process.cwd(),
|
|
924
|
+
agentDir: process.cwd(),
|
|
958
925
|
systemPromptOverride: () => finalPrompt,
|
|
959
926
|
appendSystemPromptOverride: () => [],
|
|
960
927
|
})
|
|
@@ -1034,6 +1001,10 @@ export type SystemPromptMode = 'full' | 'slim'
|
|
|
1034
1001
|
|
|
1035
1002
|
export type SystemPromptComposition = {
|
|
1036
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
|
|
1037
1008
|
self: string
|
|
1038
1009
|
// Pre-rendered full-mode orchestration roster (from `renderPublicSubagentRoster`).
|
|
1039
1010
|
// Kept as a ready string so this composer stays pure and registry-free; the
|
|
@@ -1071,12 +1042,13 @@ export type SystemPromptComposition = {
|
|
|
1071
1042
|
// suffix anyway — and removes the staleness failure mode where a session
|
|
1072
1043
|
// opened Friday answered "today is Friday" on Thursday.
|
|
1073
1044
|
export function composeSystemPrompt(parts: SystemPromptComposition): string {
|
|
1045
|
+
const branding = parts.branding ?? true
|
|
1074
1046
|
const base =
|
|
1075
1047
|
parts.mode === 'slim'
|
|
1076
|
-
?
|
|
1077
|
-
: buildDefaultSystemPrompt(parts.subagentRoster ?? DEFAULT_SUBAGENT_ROSTER)
|
|
1048
|
+
? buildSlimSystemPrompt(branding)
|
|
1049
|
+
: buildDefaultSystemPrompt(parts.subagentRoster ?? DEFAULT_SUBAGENT_ROSTER, branding)
|
|
1078
1050
|
let prompt = `${base}\n\n${parts.self}`
|
|
1079
|
-
if (parts.runtimeVersion !== undefined) {
|
|
1051
|
+
if (branding && parts.runtimeVersion !== undefined) {
|
|
1080
1052
|
prompt = `${prompt}\n\n${renderRuntimeBlock(parts.runtimeVersion)}`
|
|
1081
1053
|
}
|
|
1082
1054
|
if (parts.origin !== undefined) {
|
|
@@ -1107,8 +1079,11 @@ export async function createResourceLoader(options: CreateResourceLoaderOptions
|
|
|
1107
1079
|
: options.subagentRegistry !== undefined
|
|
1108
1080
|
? renderPublicSubagentRoster(options.subagentRegistry)
|
|
1109
1081
|
: DEFAULT_SUBAGENT_ROSTER
|
|
1082
|
+
const branding = getConfig().branding
|
|
1110
1083
|
const basePrompt =
|
|
1111
|
-
mode === 'slim'
|
|
1084
|
+
mode === 'slim'
|
|
1085
|
+
? buildSlimSystemPrompt(branding)
|
|
1086
|
+
: buildDefaultSystemPrompt(subagentRoster ?? DEFAULT_SUBAGENT_ROSTER, branding)
|
|
1112
1087
|
|
|
1113
1088
|
// Kick off the independent I/O paths concurrently. Sequential awaits
|
|
1114
1089
|
// here used to be the dominant cold-start cost amplifier: loadSelf is 2
|
|
@@ -1173,6 +1148,7 @@ export async function createResourceLoader(options: CreateResourceLoaderOptions
|
|
|
1173
1148
|
|
|
1174
1149
|
const systemPrompt = composeSystemPrompt({
|
|
1175
1150
|
mode,
|
|
1151
|
+
branding,
|
|
1176
1152
|
self,
|
|
1177
1153
|
subagentRoster,
|
|
1178
1154
|
...(options.runtimeVersion !== undefined ? { runtimeVersion: options.runtimeVersion } : {}),
|
|
@@ -1213,6 +1189,8 @@ export async function createResourceLoader(options: CreateResourceLoaderOptions
|
|
|
1213
1189
|
}
|
|
1214
1190
|
|
|
1215
1191
|
const loader = new DefaultResourceLoader({
|
|
1192
|
+
cwd: agentDir,
|
|
1193
|
+
agentDir,
|
|
1216
1194
|
systemPromptOverride: () => systemPrompt,
|
|
1217
1195
|
appendSystemPromptOverride: () => [],
|
|
1218
1196
|
additionalSkillPaths,
|