typeclaw 0.48.12 → 0.48.13
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 +6 -3
- package/src/agent/attention-escalation.ts +8 -5
- package/src/agent/auth-reloadable.ts +2 -3
- package/src/agent/auth.ts +59 -79
- package/src/agent/compaction.ts +2 -2
- package/src/agent/index.ts +31 -15
- package/src/agent/llm-replay-sanitizer.ts +1 -1
- package/src/agent/model-overrides.ts +1 -1
- package/src/agent/multimodal/look-at.ts +3 -3
- package/src/agent/multimodal/read-redirect.ts +1 -1
- package/src/agent/plugin-tools.ts +26 -31
- package/src/agent/reload-tool.ts +1 -1
- package/src/agent/subagents.ts +1 -1
- package/src/agent/tool-error-remediation.ts +1 -1
- package/src/agent/tool-result-budget.ts +2 -2
- package/src/agent/tools/channel-disengage.ts +2 -2
- package/src/agent/tools/channel-edit.ts +2 -2
- package/src/agent/tools/channel-fetch-attachment.ts +2 -2
- package/src/agent/tools/channel-history.ts +2 -2
- package/src/agent/tools/channel-react.ts +2 -2
- package/src/agent/tools/channel-read.ts +2 -2
- package/src/agent/tools/channel-reply.ts +2 -2
- package/src/agent/tools/channel-send.ts +2 -2
- package/src/agent/tools/grant-role.ts +2 -2
- package/src/agent/tools/post-github-review.ts +2 -2
- package/src/agent/tools/restart.ts +2 -2
- package/src/agent/tools/skip-response.ts +2 -2
- package/src/agent/tools/spawn-subagent.ts +2 -2
- package/src/agent/tools/stream-snapshot.ts +2 -2
- package/src/agent/tools/subagent-cancel.ts +2 -2
- package/src/agent/tools/subagent-output.ts +2 -2
- package/src/agent/tools/todo/index.ts +2 -2
- package/src/agent/tools/webfetch/tool.ts +2 -2
- package/src/agent/tools/websearch.ts +2 -2
- package/src/channels/github-review-verdict-coordinator.ts +26 -3
- package/src/channels/router.ts +50 -25
- package/src/cli/model.ts +7 -5
- package/src/cli/oauth-callbacks.ts +38 -23
- package/src/config/config.ts +62 -25
- package/src/config/providers.ts +272 -47
- package/src/init/index.ts +4 -4
- package/src/init/oauth-login.ts +57 -17
- package/src/inspect/transcript-view.ts +6 -3
- package/src/run/channel-session-factory.ts +5 -4
- package/src/run/index.ts +11 -11
- package/src/secrets/refresh-provider-oauth.ts +30 -76
- package/src/secrets/schema.ts +3 -4
- package/src/secrets/storage.ts +133 -234
- package/src/server/index.ts +1 -1
- package/src/sessions/index.ts +1 -1
- package/src/skills/typeclaw-config/SKILL.md +4 -4
- package/src/skills/typeclaw-plugins/SKILL.md +5 -5
- package/src/tui/index.ts +5 -3
- package/src/tui/theme.ts +1 -1
- package/typeclaw.schema.json +32 -1
- package/src/agent/adaptive-thinking-compat.ts +0 -79
- package/src/secrets/oauth-xai.ts +0 -348
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Type } from '@
|
|
2
|
-
import { defineTool } from '@
|
|
1
|
+
import { Type } from '@earendil-works/pi-ai'
|
|
2
|
+
import { defineTool } from '@earendil-works/pi-coding-agent'
|
|
3
3
|
|
|
4
4
|
import { recordReview, recordReviewOutput, type ReviewVerdict } from '@/channels/github-review-turn-ledger'
|
|
5
5
|
import { createSharedReviewVerdictGuard, type ReviewVerdictGuard } from '@/channels/github-review-verdict-coordinator'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Type } from '@
|
|
2
|
-
import { defineTool } from '@
|
|
1
|
+
import { Type } from '@earendil-works/pi-ai'
|
|
2
|
+
import { defineTool } from '@earendil-works/pi-coding-agent'
|
|
3
3
|
|
|
4
4
|
import { requestContainerRestart } from '@/agent/restart'
|
|
5
5
|
import type { RestartHandoffOrigin } from '@/agent/restart-handoff'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Type } from '@
|
|
2
|
-
import { defineTool } from '@
|
|
1
|
+
import { Type } from '@earendil-works/pi-ai'
|
|
2
|
+
import { defineTool } from '@earendil-works/pi-coding-agent'
|
|
3
3
|
|
|
4
4
|
import type { ChannelRouter } from '@/channels/router'
|
|
5
5
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto'
|
|
2
2
|
|
|
3
|
-
import { Type } from '@
|
|
4
|
-
import { defineTool } from '@
|
|
3
|
+
import { Type } from '@earendil-works/pi-ai'
|
|
4
|
+
import { defineTool } from '@earendil-works/pi-coding-agent'
|
|
5
5
|
|
|
6
6
|
import { githubReviewerWorkKey } from '@/channels/github-repo'
|
|
7
7
|
import type { PermissionService } from '@/permissions'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Type } from '@
|
|
2
|
-
import { defineTool } from '@
|
|
1
|
+
import { Type } from '@earendil-works/pi-ai'
|
|
2
|
+
import { defineTool } from '@earendil-works/pi-coding-agent'
|
|
3
3
|
|
|
4
4
|
import { formatLocalDateTime } from '@/shared'
|
|
5
5
|
import type { ScanFilter, Stream, StreamMessage, TargetFilter } from '@/stream'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Type } from '@
|
|
2
|
-
import { defineTool } from '@
|
|
1
|
+
import { Type } from '@earendil-works/pi-ai'
|
|
2
|
+
import { defineTool } from '@earendil-works/pi-coding-agent'
|
|
3
3
|
|
|
4
4
|
import type { PermissionService } from '@/permissions'
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Type } from '@
|
|
2
|
-
import { defineTool } from '@
|
|
1
|
+
import { Type } from '@earendil-works/pi-ai'
|
|
2
|
+
import { defineTool } from '@earendil-works/pi-coding-agent'
|
|
3
3
|
|
|
4
4
|
import type { PermissionService } from '@/permissions'
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Type } from '@
|
|
2
|
-
import { defineTool } from '@
|
|
1
|
+
import { Type } from '@earendil-works/pi-ai'
|
|
2
|
+
import { defineTool } from '@earendil-works/pi-coding-agent'
|
|
3
3
|
|
|
4
4
|
import type { SessionOrigin } from '@/agent/session-origin'
|
|
5
5
|
import { resolveTodoScope, type TodoScope } from '@/agent/todo/scope'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Type } from '@
|
|
2
|
-
import { defineTool } from '@
|
|
1
|
+
import { Type } from '@earendil-works/pi-ai'
|
|
2
|
+
import { defineTool } from '@earendil-works/pi-coding-agent'
|
|
3
3
|
|
|
4
4
|
import { extractAdaptiveHtml, validateAdaptiveHtmlComplexity } from './adaptive-html'
|
|
5
5
|
import { fetchWithLimits, normalizeUrl, parseMimeType, WebFetchError } from './fetch'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Type } from '@
|
|
2
|
-
import { defineTool } from '@
|
|
1
|
+
import { Type } from '@earendil-works/pi-ai'
|
|
2
|
+
import { defineTool } from '@earendil-works/pi-coding-agent'
|
|
3
3
|
|
|
4
4
|
import { CurlImpersonateError, isCurlExitTimeout } from './curl-impersonate'
|
|
5
5
|
import { ddgSearch, DdgCaptchaError, type DdgResult } from './ddg'
|
|
@@ -119,6 +119,16 @@ const ROUND_INELIGIBLE_REASON =
|
|
|
119
119
|
'This review follow-up round assigned the formal verdict to another sibling thread session. ' +
|
|
120
120
|
'Do not submit a formal verdict from this session; wait for the designated sibling verdict activity, then close out only this thread.'
|
|
121
121
|
|
|
122
|
+
const ROUND_HEAD_UNVERIFIED_REASON =
|
|
123
|
+
"Could not verify this pull request's current head commit on GitHub, so the review round's verdict was not submitted. " +
|
|
124
|
+
'You are still the designated carrier for this round. Retry the same verdict once shortly. ' +
|
|
125
|
+
'If it fails again, stop retrying: the head read may be failing persistently (missing credentials or a denied or malformed GitHub API response), ' +
|
|
126
|
+
'so report that the PR head could not be verified and ask the operator to check GitHub credentials and API access.'
|
|
127
|
+
|
|
128
|
+
const ROUND_HEAD_MOVED_REASON =
|
|
129
|
+
'The pull request head moved past the commit this review round covers, so a verdict from this round would describe stale code. ' +
|
|
130
|
+
'Do not submit it; the new push starts its own review round.'
|
|
131
|
+
|
|
122
132
|
// The standing verdict a fresh attempt would duplicate. APPROVE duplicates a
|
|
123
133
|
// standing APPROVED; REQUEST_CHANGES duplicates a standing CHANGES_REQUESTED.
|
|
124
134
|
function duplicatesStanding(verdict: ReviewVerdict, effective: EffectiveVerdict): boolean {
|
|
@@ -594,7 +604,7 @@ export function createApproveIdempotencyGuard(deps: {
|
|
|
594
604
|
if (args.verdict !== 'APPROVE' && args.verdict !== 'REQUEST_CHANGES') return null
|
|
595
605
|
expireRecentLanded(now)
|
|
596
606
|
expirePendingPublications(now, logger)
|
|
597
|
-
const blocked = await evaluateRoundEligibility(args, deps.resolveHeadSha ?? processHeadShaResolver, now)
|
|
607
|
+
const blocked = await evaluateRoundEligibility(args, deps.resolveHeadSha ?? processHeadShaResolver, now, logger)
|
|
598
608
|
if (blocked !== null) return blocked
|
|
599
609
|
const key = prKey(args.workspace, args.prNumber)
|
|
600
610
|
|
|
@@ -766,6 +776,7 @@ async function evaluateRoundEligibility(
|
|
|
766
776
|
},
|
|
767
777
|
resolveHeadSha: HeadShaResolver,
|
|
768
778
|
now: () => number = Date.now,
|
|
779
|
+
logger: ReviewVerdictCoordinatorLogger = processLogger,
|
|
769
780
|
): Promise<ApproveBlock | null> {
|
|
770
781
|
expireReviewRounds(now)
|
|
771
782
|
const pendingRoundForPr = Array.from(reviewRounds.values()).find(
|
|
@@ -800,8 +811,20 @@ async function evaluateRoundEligibility(
|
|
|
800
811
|
workspace: activeRound.workspace,
|
|
801
812
|
prNumber: activeRound.prNumber,
|
|
802
813
|
})
|
|
803
|
-
|
|
804
|
-
|
|
814
|
+
// This session IS the carrier here, so the sibling-carrier reason would be a
|
|
815
|
+
// lie that tells the model to stand down and strands the round. Name the
|
|
816
|
+
// actual cause instead: an unverified head (one retry, then diagnostics) or a moved head.
|
|
817
|
+
if (currentRoundHead === null) {
|
|
818
|
+
logger.warn(
|
|
819
|
+
`[github] review round head read failed pr=${activeRound.workspace}#${activeRound.prNumber} round=${activeRound.roundId} carrier=${activeRound.carrierThread ?? 'root'}`,
|
|
820
|
+
)
|
|
821
|
+
return { block: true, kind: 'round-ineligible', reason: ROUND_HEAD_UNVERIFIED_REASON }
|
|
822
|
+
}
|
|
823
|
+
if (currentRoundHead !== activeRound.headSha) {
|
|
824
|
+
logger.warn(
|
|
825
|
+
`[github] review round head moved pr=${activeRound.workspace}#${activeRound.prNumber} round=${activeRound.roundId} round_head=${activeRound.headSha} current_head=${currentRoundHead}`,
|
|
826
|
+
)
|
|
827
|
+
return { block: true, kind: 'round-ineligible', reason: ROUND_HEAD_MOVED_REASON }
|
|
805
828
|
}
|
|
806
829
|
registerGithubReviewRound(activeRound, now())
|
|
807
830
|
return null
|
package/src/channels/router.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { statSync } from 'node:fs'
|
|
2
2
|
import { basename } from 'node:path'
|
|
3
3
|
|
|
4
|
-
import { createAssistantMessageEventStream, type AssistantMessage, type ToolResultMessage } from '@
|
|
5
|
-
import { type SessionEntry, SessionManager } from '@
|
|
4
|
+
import { createAssistantMessageEventStream, type AssistantMessage, type ToolResultMessage } from '@earendil-works/pi-ai'
|
|
5
|
+
import { type SessionEntry, SessionManager } from '@earendil-works/pi-coding-agent'
|
|
6
6
|
|
|
7
7
|
import { createSession, renderTurnRoleAnchor, renderTurnTimeAnchor, type AgentSession } from '@/agent'
|
|
8
8
|
import { applyTurnThinkingLevel, getQuestionSignal, type QuestionSignal } from '@/agent/attention-escalation'
|
|
@@ -302,16 +302,17 @@ export function buildRestartResumeWakeReminder(interruptedSubagents?: readonly s
|
|
|
302
302
|
// start alongside `turnSeq`.
|
|
303
303
|
export const MAX_POLICY_DENIED_CHANNEL_SENDS_PER_TURN = 3
|
|
304
304
|
// Per-request output-token cap for channel sessions, threaded into the agent's
|
|
305
|
-
// stream options to override pi-ai's
|
|
306
|
-
//
|
|
305
|
+
// stream options to override pi-ai's model max-tokens default, which 0.87.1
|
|
306
|
+
// clamps to the remaining context window (`buildBaseOptions` in
|
|
307
|
+
// @earendil-works/pi-ai/dist/api/simple-options.js:10-18). Without it, Fireworks'
|
|
307
308
|
// kimi-k2p6-turbo — which degenerates into single-token repetition on the
|
|
308
|
-
// post-tool follow-up turn —
|
|
309
|
-
//
|
|
310
|
-
//
|
|
311
|
-
//
|
|
312
|
-
//
|
|
313
|
-
//
|
|
314
|
-
//
|
|
309
|
+
// post-tool follow-up turn — can run the model's full output capability
|
|
310
|
+
// (~116s of garbage) before `stopReason: 'length'`. The terminal-reply hook
|
|
311
|
+
// below removes the turn that triggers this; the cap bounds any other path that
|
|
312
|
+
// still reaches a channel LLM call. 4096 fits a thinking block plus a nontrivial
|
|
313
|
+
// reply (healthy channel turns observed at ~317 output tokens including
|
|
314
|
+
// reasoning). Deliberately NOT lowered in `providers.ts`, where `maxTokens` is
|
|
315
|
+
// the model's true capability that compaction math reads.
|
|
315
316
|
export const CHANNEL_MAX_OUTPUT_TOKENS = 4096
|
|
316
317
|
// Raised output-token budget threaded into the ONE re-prompt that follows a
|
|
317
318
|
// `stopReason:'length'` empty turn. The default 4096 backstop bounds kimi's
|
|
@@ -320,8 +321,7 @@ export const CHANNEL_MAX_OUTPUT_TOKENS = 4096
|
|
|
320
321
|
// prose — re-prompting under the identical cap reproduces the truncation. A
|
|
321
322
|
// `length` truncation that the byte-identical loop guard did NOT catch is
|
|
322
323
|
// evidence of genuine reasoning starved for room, not a repetition loop, so the
|
|
323
|
-
//
|
|
324
|
-
// turn that IS looping still can't burn the full pi-ai default. Consumed
|
|
324
|
+
// turn that IS looping still can't burn the model's full output capability. Consumed
|
|
325
325
|
// one-shot via `LiveSession.nextPromptMaxTokens`, then reset at the next real
|
|
326
326
|
// user turn so the raised budget never leaks past the turn that needed it.
|
|
327
327
|
export const CHANNEL_EMPTY_TURN_RETRY_MAX_OUTPUT_TOKENS = 16384
|
|
@@ -1155,7 +1155,7 @@ type LiveSession = {
|
|
|
1155
1155
|
// turn can never trigger a nudge on a later one. `null` when no such reply
|
|
1156
1156
|
// ended this turn.
|
|
1157
1157
|
lastTerminalReplyCompletion: { turnSeq: number; text?: string; tokens: number } | null
|
|
1158
|
-
// Armed after a successful terminal reply. pi-agent-core invokes
|
|
1158
|
+
// Armed after a successful terminal reply. pi-agent-core invokes streamFunction
|
|
1159
1159
|
// again only after emitting every matching toolResult into its event queue;
|
|
1160
1160
|
// the wrapper consumes this marker at that awaited provider boundary and
|
|
1161
1161
|
// returns a local aborted response instead of calling the provider. Event
|
|
@@ -3289,18 +3289,25 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
|
|
|
3289
3289
|
}
|
|
3290
3290
|
}
|
|
3291
3291
|
|
|
3292
|
-
// Override pi-ai's
|
|
3293
|
-
//
|
|
3294
|
-
//
|
|
3295
|
-
//
|
|
3296
|
-
//
|
|
3297
|
-
//
|
|
3298
|
-
//
|
|
3299
|
-
//
|
|
3292
|
+
// Override pi-ai's model max-tokens default for channel sessions by threading an
|
|
3293
|
+
// explicit `maxTokens` into every stream call. pi-ai 0.87.1 clamps the requested
|
|
3294
|
+
// value to remaining context (`buildBaseOptions`, simple-options.js:10-18), rather
|
|
3295
|
+
// than applying the removed 32k cap. See CHANNEL_MAX_OUTPUT_TOKENS for why.
|
|
3296
|
+
// Composes the existing streamFunction (pi's default `Models.streamSimple` unless a
|
|
3297
|
+
// proxy was installed). Compaction and branch-summary calls are excluded: pi 0.87.1
|
|
3298
|
+
// invokes `agent.streamFunction` for compaction (pi-coding-agent
|
|
3299
|
+
// dist/core/agent-session.js:1844) while `isCompacting` remains true
|
|
3300
|
+
// (agent-session.js:927-932). They must retain pi's own stream options and cannot
|
|
3301
|
+
// consume a channel turn's pending terminal stop or one-shot retry budget.
|
|
3302
|
+
// Precedence for channel assistant calls: an explicit per-call `maxTokens` always
|
|
3303
|
+
// wins; otherwise a one-shot `live.nextPromptMaxTokens` (set by the empty-turn
|
|
3304
|
+
// length-retry) is consumed and cleared so the raised budget applies to exactly one
|
|
3305
|
+
// stream call; otherwise the default backstop.
|
|
3300
3306
|
const installChannelOutputCap = (live: LiveSession): void => {
|
|
3301
3307
|
const { agent } = live.session
|
|
3302
|
-
const inner = agent.
|
|
3303
|
-
agent.
|
|
3308
|
+
const inner = agent.streamFunction
|
|
3309
|
+
agent.streamFunction = async (model, context, streamOptions) => {
|
|
3310
|
+
if (live.session.isCompacting) return await inner(model, context, streamOptions)
|
|
3304
3311
|
const pendingTerminalStop = live.pendingTerminalReplyStop
|
|
3305
3312
|
if (pendingTerminalStop?.turnSeq === live.turnSeq && live.userStoppedTurnSeq !== pendingTerminalStop.turnSeq) {
|
|
3306
3313
|
live.pendingTerminalReplyStop = null
|
|
@@ -3546,6 +3553,16 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
|
|
|
3546
3553
|
)
|
|
3547
3554
|
return
|
|
3548
3555
|
}
|
|
3556
|
+
// A queued re-prompt (typically the completion of a reviewer this turn
|
|
3557
|
+
// spawned) is the model's next chance to close the thread with real
|
|
3558
|
+
// content. Posting the canned fallback now strands the verdict that turn is
|
|
3559
|
+
// about to deliver, so re-evaluate at the end of that turn instead.
|
|
3560
|
+
if (live.pendingSystemReminders.length > 0 || live.promptQueue.length > 0) {
|
|
3561
|
+
logger.info(
|
|
3562
|
+
`[channels] ${live.keyId} github_thread_closeout_deferred pr=${closeout.prNumber} root=${closeout.rootCommentId} reason=reprompt_queued`,
|
|
3563
|
+
)
|
|
3564
|
+
return
|
|
3565
|
+
}
|
|
3549
3566
|
if (live.skippedTurn?.turnSeq === live.turnSeq) live.skippedTurn = null
|
|
3550
3567
|
if (closeout.correctionAttempts === 0) {
|
|
3551
3568
|
closeout.correctionAttempts++
|
|
@@ -3731,6 +3748,11 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
|
|
|
3731
3748
|
) {
|
|
3732
3749
|
sibling.githubReviewRound = promoted
|
|
3733
3750
|
persistGithubReviewRound(sibling, promoted)
|
|
3751
|
+
// Tools read the round off originRef, which is otherwise rebuilt only
|
|
3752
|
+
// at turn start. A sibling promoted mid-turn would keep seeing the old
|
|
3753
|
+
// carrier and have its own reviewer spawn / verdict denied.
|
|
3754
|
+
const origin = sibling.originRef.current
|
|
3755
|
+
if (origin?.kind === 'channel') sibling.originRef.current = { ...origin, githubReviewRound: promoted }
|
|
3734
3756
|
}
|
|
3735
3757
|
}
|
|
3736
3758
|
waiter.pendingSystemReminders.push(
|
|
@@ -8631,7 +8653,10 @@ function repairDanglingToolUseBranch(session: AgentSession, timestamp: number):
|
|
|
8631
8653
|
timestamp,
|
|
8632
8654
|
}))
|
|
8633
8655
|
for (const message of repairedMessages) session.sessionManager.appendMessage(message)
|
|
8634
|
-
|
|
8656
|
+
// SessionManager is canonical in pi 0.87: assigning agent.state.messages no longer
|
|
8657
|
+
// changes provider history. Refresh after appending so the next prompt sees the
|
|
8658
|
+
// persisted interruption results (pi-coding-agent 0.87.0 CHANGELOG:39-45).
|
|
8659
|
+
session.refreshContext()
|
|
8635
8660
|
return missing.map((toolCall) => toolCall.name)
|
|
8636
8661
|
}
|
|
8637
8662
|
|
package/src/cli/model.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { join } from 'node:path'
|
|
|
4
4
|
import { autocomplete, cancel, intro, isCancel, log, select } from '@clack/prompts'
|
|
5
5
|
import { defineCommand } from 'citty'
|
|
6
6
|
|
|
7
|
-
import type
|
|
7
|
+
import { type CustomModelMeta, type ThinkingLevel, thinkingLevelSchema } from '@/config'
|
|
8
8
|
import {
|
|
9
9
|
addProfile,
|
|
10
10
|
listModelProfiles,
|
|
@@ -59,7 +59,7 @@ const setSub = defineCommand({
|
|
|
59
59
|
thinking: {
|
|
60
60
|
type: 'string',
|
|
61
61
|
description:
|
|
62
|
-
"reasoning effort for THIS profile (off|minimal|low|medium|high|xhigh|default); the `default` profile's level is the de-facto global default",
|
|
62
|
+
"reasoning effort for THIS profile (off|minimal|low|medium|high|xhigh|max|default); the `default` profile's level is the de-facto global default",
|
|
63
63
|
required: false,
|
|
64
64
|
},
|
|
65
65
|
},
|
|
@@ -117,7 +117,7 @@ const thinkingSub = defineCommand({
|
|
|
117
117
|
level: {
|
|
118
118
|
type: 'positional',
|
|
119
119
|
description:
|
|
120
|
-
'reasoning effort (off|minimal|low|medium|high|xhigh); or "default" to clear and defer to the SDK default',
|
|
120
|
+
'reasoning effort (off|minimal|low|medium|high|xhigh|max); or "default" to clear and defer to the SDK default',
|
|
121
121
|
required: false,
|
|
122
122
|
},
|
|
123
123
|
},
|
|
@@ -318,7 +318,9 @@ async function pickProfileName(): Promise<string> {
|
|
|
318
318
|
return choice
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
-
|
|
321
|
+
// The config schema is the single source of truth, so `--thinking` and the
|
|
322
|
+
// picker accept exactly the levels typeclaw.json accepts (including `max`).
|
|
323
|
+
const THINKING_LEVELS: readonly ThinkingLevel[] = thinkingLevelSchema.options
|
|
322
324
|
const KEEP_THINKING_SENTINEL = '__keep__'
|
|
323
325
|
|
|
324
326
|
export type ParsedThinkingArg = { ok: true; level: ThinkingLevel | undefined } | { ok: false; reason: string }
|
|
@@ -326,7 +328,7 @@ export type ParsedThinkingArg = { ok: true; level: ThinkingLevel | undefined } |
|
|
|
326
328
|
export function parseThinkingArg(raw: string): ParsedThinkingArg {
|
|
327
329
|
const value = raw.trim().toLowerCase()
|
|
328
330
|
if (value === 'default' || value === 'unset' || value === 'none') return { ok: true, level: undefined }
|
|
329
|
-
if ((THINKING_LEVELS as string[]).includes(value)) return { ok: true, level: value as ThinkingLevel }
|
|
331
|
+
if ((THINKING_LEVELS as readonly string[]).includes(value)) return { ok: true, level: value as ThinkingLevel }
|
|
330
332
|
return {
|
|
331
333
|
ok: false,
|
|
332
334
|
reason: `Invalid --thinking "${raw}". Use one of: ${THINKING_LEVELS.join(', ')}, or "default" to clear.`,
|
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
import { isCancel, log, note, text } from '@clack/prompts'
|
|
1
|
+
import { isCancel, log, note, password, select, text } from '@clack/prompts'
|
|
2
2
|
|
|
3
3
|
import type { OAuthCallbacks } from '@/init/oauth-login'
|
|
4
4
|
|
|
5
5
|
// Shared between `typeclaw init` (src/cli/init.ts) and `typeclaw provider
|
|
6
6
|
// add/set` (src/cli/provider.ts). Both call into the same OAuth runner, so
|
|
7
7
|
// they need to render the same UX: a note() box with the URL + cross-device
|
|
8
|
-
// guidance, a
|
|
9
|
-
//
|
|
10
|
-
// different host than the CLI. See
|
|
11
|
-
// on each callback and why
|
|
8
|
+
// guidance, a select() prompt for provider-defined choices, a text() prompt
|
|
9
|
+
// for the post-callback manual fallback, and a concurrent onManualCodeInput
|
|
10
|
+
// prompt for users whose browser is on a different host than the CLI. See
|
|
11
|
+
// src/init/oauth-login.ts for the contract on each callback and why
|
|
12
|
+
// onManualCodeInput is required for cross-device.
|
|
12
13
|
//
|
|
13
|
-
// Returns `{ callbacks, dispose }` rather than bare callbacks because
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
// the user sees "Logged in to {Provider}" immediately followed by the stale
|
|
21
|
-
// "paste the redirect URL here" prompt that's now meaningless. Each call
|
|
22
|
-
// site (init/provider) MUST call `dispose()` in a finally after the OAuth
|
|
23
|
-
// runner returns so the orphaned prompt aborts cleanly; clack honors the
|
|
24
|
-
// signal by resolving the prompt with cancel state, the cancel branch
|
|
25
|
-
// throws inside our callback, and pi-ai's outer `.catch()` swallows it
|
|
26
|
-
// (since it stops awaiting the manual promise on the winning-browser path).
|
|
14
|
+
// Returns `{ callbacks, dispose }` rather than bare callbacks because pi-ai
|
|
15
|
+
// races `onManualCodeInput()` against the local callback server. Pi 0.87 aborts
|
|
16
|
+
// the losing manual prompt through its prompt signal (pi-ai
|
|
17
|
+
// dist/auth/oauth/anthropic.js:216-221,266); dispose remains a fallback for
|
|
18
|
+
// callers that end OAuth before pi reaches that race. Each call site
|
|
19
|
+
// (init/provider) MUST call `dispose()` in a finally after the OAuth runner
|
|
20
|
+
// returns so any still-live clack prompt is cancelled cleanly.
|
|
27
21
|
export type OAuthCallbackHandle = {
|
|
28
22
|
callbacks: OAuthCallbacks
|
|
29
23
|
dispose: () => void
|
|
@@ -32,6 +26,8 @@ export type OAuthCallbackHandle = {
|
|
|
32
26
|
export function buildOAuthCallbacks(providerName: string): OAuthCallbackHandle {
|
|
33
27
|
const controller = new AbortController()
|
|
34
28
|
const { signal } = controller
|
|
29
|
+
const promptSignal = (upstream?: AbortSignal): AbortSignal =>
|
|
30
|
+
upstream === undefined ? signal : AbortSignal.any([signal, upstream])
|
|
35
31
|
return {
|
|
36
32
|
dispose: () => controller.abort(),
|
|
37
33
|
callbacks: {
|
|
@@ -56,21 +52,40 @@ export function buildOAuthCallbacks(providerName: string): OAuthCallbackHandle {
|
|
|
56
52
|
onProgress: (message) => {
|
|
57
53
|
log.info(message)
|
|
58
54
|
},
|
|
59
|
-
onPrompt: async (message, placeholder) => {
|
|
55
|
+
onPrompt: async (message, placeholder, upstreamSignal) => {
|
|
60
56
|
const value = await text({
|
|
61
57
|
message,
|
|
62
|
-
signal,
|
|
58
|
+
signal: promptSignal(upstreamSignal),
|
|
63
59
|
...(placeholder !== undefined ? { placeholder } : {}),
|
|
64
60
|
})
|
|
65
61
|
if (isCancel(value)) return null
|
|
66
62
|
return value
|
|
67
63
|
},
|
|
68
|
-
|
|
64
|
+
// clack's password() has no placeholder option (PasswordOptions).
|
|
65
|
+
onSecret: async (message, _placeholder, upstreamSignal) => {
|
|
66
|
+
const value = await password({ message, signal: promptSignal(upstreamSignal) })
|
|
67
|
+
if (isCancel(value)) return null
|
|
68
|
+
return value
|
|
69
|
+
},
|
|
70
|
+
onSelect: async (message, options, upstreamSignal) => {
|
|
71
|
+
const value = await select({
|
|
72
|
+
message,
|
|
73
|
+
options: options.map((option) => ({
|
|
74
|
+
value: option.id,
|
|
75
|
+
label: option.label,
|
|
76
|
+
hint: option.description,
|
|
77
|
+
})),
|
|
78
|
+
signal: promptSignal(upstreamSignal),
|
|
79
|
+
})
|
|
80
|
+
if (isCancel(value)) return null
|
|
81
|
+
return value
|
|
82
|
+
},
|
|
83
|
+
onManualCodeInput: async (upstreamSignal) => {
|
|
69
84
|
const value = await text({
|
|
70
85
|
message:
|
|
71
86
|
'After signing in, paste the code shown on the page (some providers offer a copy button), or the full redirect address from the top of the browser:',
|
|
72
87
|
placeholder: 'code, or http://localhost:1455/auth/callback?code=...&state=...',
|
|
73
|
-
signal,
|
|
88
|
+
signal: promptSignal(upstreamSignal),
|
|
74
89
|
})
|
|
75
90
|
if (isCancel(value)) throw new Error('Login cancelled by user')
|
|
76
91
|
return value
|
package/src/config/config.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { accessSync, constants as fsConstants, readFileSync, statSync, writeFile
|
|
|
2
2
|
import { homedir } from 'node:os'
|
|
3
3
|
import { isAbsolute, join, posix, resolve } from 'node:path'
|
|
4
4
|
|
|
5
|
-
import type { KnownApi, Model } from '@
|
|
5
|
+
import type { KnownApi, Model } from '@earendil-works/pi-ai'
|
|
6
|
+
import { getBuiltinModel } from '@earendil-works/pi-ai/providers/all'
|
|
6
7
|
import { z } from 'zod'
|
|
7
8
|
|
|
8
9
|
import { channelsSchema, SEEDED_GITHUB_EVENT_ALLOWLISTS } from '@/channels/schema'
|
|
@@ -676,7 +677,7 @@ function asModelRef(value: string): ModelRef {
|
|
|
676
677
|
// Mirrors pi-coding-agent's `ThinkingLevel`. Kept as a local enum (rather than
|
|
677
678
|
// importing the SDK type) so the schema owns the canonical value list and zod
|
|
678
679
|
// can validate `typeclaw.json` without a runtime SDK dependency.
|
|
679
|
-
export const thinkingLevelSchema = z.enum(['off', 'minimal', 'low', 'medium', 'high', 'xhigh'])
|
|
680
|
+
export const thinkingLevelSchema = z.enum(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'])
|
|
680
681
|
export type ThinkingLevel = z.infer<typeof thinkingLevelSchema>
|
|
681
682
|
|
|
682
683
|
// Reject exact duplicates in a chain — retrying the same ref after the same
|
|
@@ -842,44 +843,80 @@ export function resolveModel(ref: KnownModelRef | ModelRef | string): Model<Know
|
|
|
842
843
|
}
|
|
843
844
|
|
|
844
845
|
const meta = getConfig().customModels[ref]
|
|
846
|
+
// `api`, `baseUrl`, and (by default) `compat` come from the provider template
|
|
847
|
+
// because they describe the PROVIDER's wire dialect, not the model. pi-ai
|
|
848
|
+
// infers compat from the baseUrl and only recognises first-party hosts, so a
|
|
849
|
+
// custom ref on a provider that pins compat (OpenGateway, Upstage) would
|
|
850
|
+
// otherwise fall back to OpenAI-native defaults and send `store`, the
|
|
851
|
+
// `developer` role, `strict` tool schemas and `max_completion_tokens` to an
|
|
852
|
+
// endpoint that never accepts them.
|
|
853
|
+
//
|
|
854
|
+
// The exception is a ref that pi-ai's catalog already knows, exactly or as
|
|
855
|
+
// its undated `-YYYYMMDD` base, on the same transport. The catalog describes
|
|
856
|
+
// the MODEL, so its name, capabilities, limits, and pricing are the defaults;
|
|
857
|
+
// `customModels` remains the explicit per-field override. pi 0.87 reads some
|
|
858
|
+
// behavior only from per-model metadata: e.g. Anthropic adaptive thinking is
|
|
859
|
+
// `compat.forceAdaptiveThinking` and is no longer inferred from the id.
|
|
860
|
+
// Anthropic's streamSimple gates adaptive thinking on the resolved model's
|
|
861
|
+
// `reasoning` capability, so a dated Sonnet 5 alias must inherit that too.
|
|
862
|
+
// That entry's compat and thinkingLevelMap are used, minus
|
|
863
|
+
// `allowedFallbackModels` (see the Fable 5 record). Without a catalog match
|
|
864
|
+
// `thinkingLevelMap` is deliberately not carried: it varies per model even
|
|
865
|
+
// within one provider, so copying the template's would be a guess.
|
|
866
|
+
const builtin = findBuiltinModel(providerId, modelId)
|
|
867
|
+
const catalogMetadata = builtin !== undefined && builtin.api === template.api ? builtin : undefined
|
|
868
|
+
let compat = template.compat
|
|
869
|
+
if (catalogMetadata !== undefined) {
|
|
870
|
+
const catalogCompat: Record<string, unknown> | undefined =
|
|
871
|
+
catalogMetadata.compat === undefined ? undefined : { ...catalogMetadata.compat }
|
|
872
|
+
if (catalogCompat !== undefined) delete catalogCompat.allowedFallbackModels
|
|
873
|
+
compat = catalogCompat as Model<KnownApi>['compat']
|
|
874
|
+
}
|
|
845
875
|
return {
|
|
846
876
|
id: modelId,
|
|
847
877
|
provider: providerId,
|
|
848
878
|
baseUrl: provider.baseUrl ?? template.baseUrl,
|
|
849
879
|
api: template.api,
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
// the template's would be a guess.
|
|
859
|
-
...(template.compat !== undefined ? { compat: template.compat } : {}),
|
|
860
|
-
name: meta?.name ?? modelId,
|
|
861
|
-
reasoning: meta?.reasoning ?? false,
|
|
862
|
-
input: resolveCustomModelInput(meta?.input),
|
|
863
|
-
contextWindow: meta?.contextWindow ?? template.contextWindow,
|
|
864
|
-
maxTokens: meta?.maxTokens ?? template.maxTokens,
|
|
865
|
-
cost: resolveCustomModelCost(meta?.cost),
|
|
880
|
+
...(compat !== undefined ? { compat } : {}),
|
|
881
|
+
...(catalogMetadata?.thinkingLevelMap !== undefined ? { thinkingLevelMap: catalogMetadata.thinkingLevelMap } : {}),
|
|
882
|
+
name: meta?.name ?? catalogMetadata?.name ?? modelId,
|
|
883
|
+
reasoning: meta?.reasoning ?? catalogMetadata?.reasoning ?? false,
|
|
884
|
+
input: resolveCustomModelInput(meta?.input, catalogMetadata?.input),
|
|
885
|
+
contextWindow: meta?.contextWindow ?? catalogMetadata?.contextWindow ?? template.contextWindow,
|
|
886
|
+
maxTokens: meta?.maxTokens ?? catalogMetadata?.maxTokens ?? template.maxTokens,
|
|
887
|
+
cost: resolveCustomModelCost(meta?.cost, catalogMetadata?.cost),
|
|
866
888
|
}
|
|
867
889
|
}
|
|
868
890
|
|
|
869
|
-
function
|
|
870
|
-
|
|
891
|
+
function findBuiltinModel(providerId: string, modelId: string): Model<KnownApi> | undefined {
|
|
892
|
+
const direct = getBuiltinModel(providerId as never, modelId as never) as Model<KnownApi> | undefined
|
|
893
|
+
if (direct !== undefined) return direct
|
|
894
|
+
const undatedId = modelId.replace(/-\d{8}$/, '')
|
|
895
|
+
return undatedId === modelId
|
|
896
|
+
? undefined
|
|
897
|
+
: (getBuiltinModel(providerId as never, undatedId as never) as Model<KnownApi> | undefined)
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
function resolveCustomModelInput(
|
|
901
|
+
input: readonly string[] | undefined,
|
|
902
|
+
fallback: Model<KnownApi>['input'] | undefined,
|
|
903
|
+
): Model<KnownApi>['input'] {
|
|
904
|
+
if (input === undefined) return fallback ?? ['text']
|
|
871
905
|
const supported = input.filter(
|
|
872
906
|
(value): value is Model<KnownApi>['input'][number] => value === 'text' || value === 'image',
|
|
873
907
|
)
|
|
874
908
|
return supported.length > 0 ? supported : ['text']
|
|
875
909
|
}
|
|
876
910
|
|
|
877
|
-
function resolveCustomModelCost(
|
|
911
|
+
function resolveCustomModelCost(
|
|
912
|
+
cost: CustomModelMeta['cost'],
|
|
913
|
+
fallback: Model<KnownApi>['cost'] | undefined,
|
|
914
|
+
): Model<KnownApi>['cost'] {
|
|
878
915
|
return {
|
|
879
|
-
input: cost?.input ?? 0,
|
|
880
|
-
output: cost?.output ?? 0,
|
|
881
|
-
cacheRead: cost?.cacheRead ?? 0,
|
|
882
|
-
cacheWrite: cost?.cacheWrite ?? 0,
|
|
916
|
+
input: cost?.input ?? fallback?.input ?? 0,
|
|
917
|
+
output: cost?.output ?? fallback?.output ?? 0,
|
|
918
|
+
cacheRead: cost?.cacheRead ?? fallback?.cacheRead ?? 0,
|
|
919
|
+
cacheWrite: cost?.cacheWrite ?? fallback?.cacheWrite ?? 0,
|
|
883
920
|
}
|
|
884
921
|
}
|
|
885
922
|
|