typeclaw 0.38.1 → 0.39.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 +5 -0
- package/package.json +2 -2
- package/src/agent/attention-escalation.ts +158 -7
- package/src/agent/auth.ts +2 -2
- package/src/agent/git-nudge.ts +7 -7
- package/src/agent/index.ts +25 -2
- package/src/agent/restart/index.ts +17 -8
- package/src/agent/session-origin.ts +21 -0
- package/src/agent/subagents.ts +29 -1
- package/src/agent/system-prompt.ts +18 -5
- package/src/agent/tools/restart.ts +0 -3
- package/src/agent/tools/spawn-subagent.ts +7 -0
- package/src/bundled-plugins/backup/index.ts +5 -2
- package/src/bundled-plugins/backup/runner.ts +55 -23
- package/src/bundled-plugins/guard/policies/uncommitted-changes.ts +7 -8
- package/src/bundled-plugins/memory/dreaming.ts +37 -24
- package/src/bundled-plugins/memory/index.ts +24 -6
- package/src/bundled-plugins/memory/memory-logger.ts +14 -10
- package/src/bundled-plugins/operator/operator.ts +1 -0
- package/src/channels/adapters/kakaotalk-membership.ts +67 -0
- package/src/channels/adapters/kakaotalk.ts +8 -0
- package/src/channels/adapters/line-token.ts +55 -0
- package/src/channels/adapters/line.ts +74 -0
- package/src/channels/adapters/webex-bot-classify.ts +14 -1
- package/src/channels/adapters/webex-bot.ts +24 -1
- package/src/channels/adapters/webex-classify.ts +16 -1
- package/src/channels/adapters/webex.ts +27 -1
- package/src/channels/router.ts +55 -2
- package/src/cli/hostd.ts +40 -0
- package/src/cli/model.ts +143 -3
- package/src/config/config.ts +101 -36
- package/src/config/index.ts +3 -0
- package/src/config/models-mutation.ts +105 -15
- package/src/config/providers-mutation.ts +4 -4
- package/src/config/providers.ts +6 -14
- package/src/container/shared.ts +136 -14
- package/src/container/shell.ts +12 -2
- package/src/container/start.ts +25 -7
- package/src/doctor/commit.ts +10 -10
- package/src/dreams/git.ts +20 -7
- package/src/dreams/index.ts +22 -7
- package/src/git/reconcile-ignored.ts +56 -27
- package/src/git/resolve-agent-git.ts +12 -0
- package/src/git/system-commit.ts +16 -10
- package/src/hostd/daemon.ts +16 -0
- package/src/hostd/index.ts +1 -11
- package/src/hostd/paths.ts +0 -16
- package/src/hostd/webex-renewal-manager.ts +216 -0
- package/src/init/dockerfile.ts +13 -4
- package/src/init/gitignore.ts +4 -2
- package/src/run/index.ts +4 -1
- package/src/secrets/schema.ts +1 -0
- package/src/secrets/webex-renewal.ts +215 -0
- package/src/server/index.ts +25 -3
- package/src/skills/typeclaw-config/SKILL.md +18 -16
- package/typeclaw.schema.json +172 -1
package/README.md
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
<h3 align="center">TypeClaw: The agent for perfectionists</h3>
|
|
6
6
|
<p align="center">Crafted in every detail – it behaves in your team's chat and<br />gets sharper the longer it runs. Sandboxed and self-managing.</p>
|
|
7
7
|
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://discord.gg/V4NQnbXpr"><img src="https://img.shields.io/badge/Discord-Chat%20with%20Typeey-5865F2?logo=discord&logoColor=white" alt="Chat with Typeey on Discord" /></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
8
12
|
<br />
|
|
9
13
|
<br />
|
|
10
14
|
|
|
@@ -123,6 +127,7 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for the recommended local dev loop (`bu
|
|
|
123
127
|
|
|
124
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.
|
|
125
129
|
- **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
|
+
- **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.
|
|
126
131
|
|
|
127
132
|
## License
|
|
128
133
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeclaw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.1",
|
|
4
4
|
"homepage": "https://github.com/typeclaw/typeclaw#readme",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/typeclaw/typeclaw/issues"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@mariozechner/pi-tui": "^0.67.3",
|
|
51
51
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
52
52
|
"@mozilla/readability": "^0.6.0",
|
|
53
|
-
"agent-messenger": "2.
|
|
53
|
+
"agent-messenger": "^2.24.1",
|
|
54
54
|
"cheerio": "^1.2.0",
|
|
55
55
|
"citty": "^0.2.2",
|
|
56
56
|
"cron-parser": "^5.5.0",
|
|
@@ -554,23 +554,173 @@ const MORPHEME_PATTERNS: readonly RegExp[] = []
|
|
|
554
554
|
|
|
555
555
|
const MIN_LENGTH = 2
|
|
556
556
|
|
|
557
|
-
|
|
558
|
-
|
|
557
|
+
// "Jeff Bezos detection": a message that is dense with question marks is a
|
|
558
|
+
// human pressing for a real answer (Bezos was famous for replying to internal
|
|
559
|
+
// mail with a single "?"). We treat three question-shaped patterns as the same
|
|
560
|
+
// budget hint the phrase tables emit — care, not a command. Idea from
|
|
561
|
+
// GitHub @kdhfred.
|
|
562
|
+
//
|
|
563
|
+
// Question punctuation is multilingual: ASCII `?`, fullwidth `?` (U+FF1F),
|
|
564
|
+
// Arabic `؟` (U+061F), and Armenian `՞` (U+055E). The Greek question mark is the
|
|
565
|
+
// ASCII `;`, and `·` (U+00B7) is the Greek ano teleia — both are ambiguous with
|
|
566
|
+
// ordinary punctuation in Latin text, so they only count as question marks when
|
|
567
|
+
// the same message actually contains Greek letters.
|
|
568
|
+
const QUESTION_PUNCT_RE = /[??\u061F\u055E]/u
|
|
569
|
+
// The Greek question mark is the ASCII semicolon `;` (and its canonical
|
|
570
|
+
// equivalent U+037E). The ano teleia `·` (U+00B7) is the Greek SEMICOLON, not a
|
|
571
|
+
// question mark, so it splits sentences but must never count as a question.
|
|
572
|
+
const GREEK_QUESTION_PUNCT_RE = /[;\u037E]/u
|
|
573
|
+
const GREEK_LETTER_RE = /\p{Script=Greek}/u
|
|
574
|
+
// Armenian writes its question mark `՞` (U+055E) INSIDE the questioned word
|
|
575
|
+
// (e.g. `Ի՞նչ եք անում։`), not as a terminal mark — so it must not split a
|
|
576
|
+
// sentence. We detect it on the chunk body instead, and let the Armenian full
|
|
577
|
+
// stop `։` (U+0589, distinct from ASCII `:`) terminate the sentence.
|
|
578
|
+
const ARMENIAN_INLINE_QUESTION_RE = /\u055E/u
|
|
579
|
+
// `\b` is ASCII-only and meaningless for CJK/Arabic/Hindi, so we count Unicode
|
|
580
|
+
// letters and numbers directly instead of tokenizing on word boundaries.
|
|
581
|
+
const ALNUM_RE = /[\p{L}\p{N}]/gu
|
|
582
|
+
// Terminal punctuation that ends a sentence-like chunk, across scripts.
|
|
583
|
+
const TERMINATOR_SPLIT_RE = /([.!??\u061F;·。!?\u0589]+)/u
|
|
584
|
+
|
|
585
|
+
function hasGreek(text: string): boolean {
|
|
586
|
+
return GREEK_LETTER_RE.test(text)
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function isQuestionRun(run: string, greek: boolean): boolean {
|
|
590
|
+
if (QUESTION_PUNCT_RE.test(run)) return true
|
|
591
|
+
return greek && GREEK_QUESTION_PUNCT_RE.test(run)
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function isQuestionSentence(body: string, terminator: string, greek: boolean): boolean {
|
|
595
|
+
return isQuestionRun(terminator, greek) || ARMENIAN_INLINE_QUESTION_RE.test(body)
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function isQuestionOrSpace(char: string, greek: boolean): boolean {
|
|
599
|
+
if (/\s/u.test(char)) return true
|
|
600
|
+
if (QUESTION_PUNCT_RE.test(char)) return true
|
|
601
|
+
return greek && GREEK_QUESTION_PUNCT_RE.test(char)
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function countAlnum(text: string): number {
|
|
605
|
+
const matches = text.match(ALNUM_RE)
|
|
606
|
+
return matches === null ? 0 : matches.length
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// Mode 1: the whole message is nothing but question marks (and whitespace) —
|
|
610
|
+
// `?`, `???`, `??`, `؟؟؟`. A trailing `?` on a real sentence, or `?!`, must NOT
|
|
611
|
+
// match here; those are handled (if at all) by the other modes.
|
|
612
|
+
function isQuestionOnlyMessage(normalized: string): boolean {
|
|
613
|
+
if (normalized.length === 0) return false
|
|
614
|
+
const greek = hasGreek(normalized)
|
|
615
|
+
let sawQuestion = false
|
|
616
|
+
for (const char of normalized) {
|
|
617
|
+
if (QUESTION_PUNCT_RE.test(char) || (greek && GREEK_QUESTION_PUNCT_RE.test(char))) {
|
|
618
|
+
sawQuestion = true
|
|
619
|
+
continue
|
|
620
|
+
}
|
|
621
|
+
if (!isQuestionOrSpace(char, greek)) return false
|
|
622
|
+
}
|
|
623
|
+
return sawQuestion
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
type Sentence = { text: string; isQuestion: boolean }
|
|
627
|
+
|
|
628
|
+
function splitSentences(normalized: string): Sentence[] {
|
|
629
|
+
const greek = hasGreek(normalized)
|
|
630
|
+
const parts = normalized.split(TERMINATOR_SPLIT_RE)
|
|
631
|
+
const sentences: Sentence[] = []
|
|
632
|
+
for (let i = 0; i < parts.length; i += 2) {
|
|
633
|
+
const body = parts[i] ?? ''
|
|
634
|
+
const terminator = parts[i + 1] ?? ''
|
|
635
|
+
const trimmed = body.trim()
|
|
636
|
+
if (trimmed.length === 0 && terminator.length === 0) continue
|
|
637
|
+
if (trimmed.length === 0) continue
|
|
638
|
+
sentences.push({ text: trimmed, isQuestion: isQuestionSentence(trimmed, terminator, greek) })
|
|
639
|
+
}
|
|
640
|
+
return sentences
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// Mode 2: a single turn packed with separate questions — "are you …? do you …?
|
|
644
|
+
// what …? how …?". Require 3+ genuine question sentences, each with enough
|
|
645
|
+
// content (>= 3 letters/numbers) so a bare "? ? ?" stays a mode-1 case only.
|
|
646
|
+
const MODE2_MIN_QUESTIONS = 3
|
|
647
|
+
const SENTENCE_MIN_ALNUM = 3
|
|
648
|
+
|
|
649
|
+
function countContentfulQuestions(sentences: readonly Sentence[]): number {
|
|
650
|
+
let count = 0
|
|
651
|
+
for (const sentence of sentences) {
|
|
652
|
+
if (sentence.isQuestion && countAlnum(sentence.text) >= SENTENCE_MIN_ALNUM) count++
|
|
653
|
+
}
|
|
654
|
+
return count
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
export type QuestionSignal = {
|
|
658
|
+
endedWithQuestion: boolean
|
|
659
|
+
questionSentenceCount: number
|
|
660
|
+
// True when the turn is mostly questions (>= 60% of its sentences), so a
|
|
661
|
+
// single trailing "?" on an otherwise statement-heavy message is not "dominant".
|
|
662
|
+
dominant: boolean
|
|
663
|
+
alnumCount: number
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
export function getQuestionSignal(text: string): QuestionSignal {
|
|
667
|
+
const normalized = normalize(text)
|
|
668
|
+
if (normalized.length === 0) {
|
|
669
|
+
return { endedWithQuestion: false, questionSentenceCount: 0, dominant: false, alnumCount: 0 }
|
|
670
|
+
}
|
|
671
|
+
const sentences = splitSentences(normalized)
|
|
672
|
+
const questionSentenceCount = sentences.reduce((acc, s) => acc + (s.isQuestion ? 1 : 0), 0)
|
|
673
|
+
const sentenceCount = Math.max(sentences.length, 1)
|
|
674
|
+
return {
|
|
675
|
+
endedWithQuestion: sentences.at(-1)?.isQuestion ?? false,
|
|
676
|
+
questionSentenceCount,
|
|
677
|
+
dominant: questionSentenceCount >= 1 && questionSentenceCount >= Math.ceil(sentenceCount * 0.6),
|
|
678
|
+
alnumCount: countAlnum(normalized),
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// Mode 3: the user is interrogating across turns — a question-dominant turn
|
|
683
|
+
// following another question-dominant turn (prev "why …?", current "how …?").
|
|
684
|
+
// A single trailing "?" on consecutive turns is far too common in normal chat,
|
|
685
|
+
// so both turns must be dominant, both must end on a question mark, and both
|
|
686
|
+
// must carry real content (>= 12 letters/numbers) to clear the noise floor.
|
|
687
|
+
const MODE3_MIN_ALNUM = 12
|
|
688
|
+
|
|
689
|
+
function isSequentialQuestionEscalation(current: QuestionSignal, prior: QuestionSignal | null | undefined): boolean {
|
|
690
|
+
return Boolean(
|
|
691
|
+
prior?.dominant &&
|
|
692
|
+
current.dominant &&
|
|
693
|
+
prior.endedWithQuestion &&
|
|
694
|
+
current.endedWithQuestion &&
|
|
695
|
+
prior.alnumCount >= MODE3_MIN_ALNUM &&
|
|
696
|
+
current.alnumCount >= MODE3_MIN_ALNUM,
|
|
697
|
+
)
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
export function detectAttentionEscalation(text: string, prior?: QuestionSignal | null): boolean {
|
|
559
701
|
const normalized = normalize(text)
|
|
702
|
+
// Mode 1 deliberately bypasses MIN_LENGTH: a lone "?" is shorter than the
|
|
703
|
+
// phrase-table floor but is itself the signal.
|
|
704
|
+
if (isQuestionOnlyMessage(normalized)) return true
|
|
560
705
|
if (normalized.length < MIN_LENGTH) return false
|
|
706
|
+
const sentences = splitSentences(normalized)
|
|
707
|
+
if (countContentfulQuestions(sentences) >= MODE2_MIN_QUESTIONS) return true
|
|
708
|
+
if (isSequentialQuestionEscalation(getQuestionSignal(text), prior)) return true
|
|
561
709
|
if (ALL_PHRASES.some((phrase) => normalized.includes(phrase))) return true
|
|
562
710
|
return MORPHEME_PATTERNS.some((pattern) => pattern.test(normalized))
|
|
563
711
|
}
|
|
564
712
|
|
|
565
|
-
//
|
|
566
|
-
//
|
|
567
|
-
|
|
713
|
+
// `xhigh` is the strongest level. It's OpenAI-family-only, but `setThinkingLevel`
|
|
714
|
+
// clamps it per-model (down to `high` on non-OpenAI), so it's safe to pass
|
|
715
|
+
// unconditionally and gives OpenAI models maximum effort on escalation turns.
|
|
716
|
+
const ESCALATED_LEVEL: ThinkingLevel = 'xhigh'
|
|
568
717
|
|
|
569
718
|
export function resolveTurnThinkingLevel(
|
|
570
719
|
text: string,
|
|
571
720
|
sessionDefault: ThinkingLevel | undefined,
|
|
721
|
+
prior?: QuestionSignal | null,
|
|
572
722
|
): ThinkingLevel | undefined {
|
|
573
|
-
return detectAttentionEscalation(text) ? ESCALATED_LEVEL : sessionDefault
|
|
723
|
+
return detectAttentionEscalation(text, prior) ? ESCALATED_LEVEL : sessionDefault
|
|
574
724
|
}
|
|
575
725
|
|
|
576
726
|
type ThinkingLevelSettable = {
|
|
@@ -584,7 +734,8 @@ export function applyTurnThinkingLevel(
|
|
|
584
734
|
session: ThinkingLevelSettable,
|
|
585
735
|
text: string,
|
|
586
736
|
sessionDefault: ThinkingLevel | undefined,
|
|
737
|
+
prior?: QuestionSignal | null,
|
|
587
738
|
): void {
|
|
588
|
-
const resolved = resolveTurnThinkingLevel(text, sessionDefault)
|
|
739
|
+
const resolved = resolveTurnThinkingLevel(text, sessionDefault, prior)
|
|
589
740
|
if (resolved !== undefined) session.setThinkingLevel(resolved)
|
|
590
741
|
}
|
package/src/agent/auth.ts
CHANGED
|
@@ -86,7 +86,7 @@ export function getAuthFor(providerId: KnownProviderId): Auth {
|
|
|
86
86
|
// Uses the head of the fallback chain; auth for the rest of the chain is
|
|
87
87
|
// resolved lazily when fallback actually fires.
|
|
88
88
|
export function getAuth(): Auth {
|
|
89
|
-
const defaultRef = getConfig().models.default[0]!
|
|
89
|
+
const defaultRef = getConfig().models.default.refs[0]!
|
|
90
90
|
return getAuthFor(providerForModelRef(defaultRef))
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -100,7 +100,7 @@ function hasAnyCredentialInEnv(apiKeyEnv: string | null): boolean {
|
|
|
100
100
|
|
|
101
101
|
function missingCredentialMessage(providerId: KnownProviderId): string {
|
|
102
102
|
const provider = KNOWN_PROVIDERS[providerId]
|
|
103
|
-
const defaultRef = getConfig().models.default[0]!
|
|
103
|
+
const defaultRef = getConfig().models.default.refs[0]!
|
|
104
104
|
const defaultProviderId = providerForModelRef(defaultRef)
|
|
105
105
|
// For the `default` profile, name the model in the error message (matches
|
|
106
106
|
// pre-multi-model behavior). For any other profile, the user is mixing
|
package/src/agent/git-nudge.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join } from 'node:path'
|
|
1
|
+
import { resolveAgentGit } from '@/git/resolve-agent-git'
|
|
3
2
|
|
|
4
3
|
const MAX_LISTED_PATHS = 10
|
|
5
4
|
|
|
@@ -9,15 +8,16 @@ const MAX_LISTED_PATHS = 10
|
|
|
9
8
|
const RUNTIME_OWNED_PREFIXES = ['sessions/', 'memory/']
|
|
10
9
|
|
|
11
10
|
export type GitNudgeDeps = {
|
|
12
|
-
readStatus: (agentDir: string) => Promise<readonly string[] | null>
|
|
11
|
+
readStatus: (agentDir: string, gitArgs: readonly string[]) => Promise<readonly string[] | null>
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
// Returns "" (not a placeholder string) when there is nothing to nudge about.
|
|
16
15
|
// The empty case must add zero bytes to the system prompt so cache prefixes
|
|
17
16
|
// stay identical to a clean-worktree agent folder.
|
|
18
17
|
export async function renderGitNudge(agentDir: string, deps: GitNudgeDeps = defaultDeps): Promise<string> {
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const repo = resolveAgentGit(agentDir)
|
|
19
|
+
if (!repo) return ''
|
|
20
|
+
const status = await deps.readStatus(agentDir, repo.gitArgs)
|
|
21
21
|
if (status === null) return ''
|
|
22
22
|
const dirty = filterAgentOwned(status)
|
|
23
23
|
if (dirty.length === 0) return ''
|
|
@@ -66,12 +66,12 @@ function filterAgentOwned(paths: readonly string[]): string[] {
|
|
|
66
66
|
|
|
67
67
|
// Mirrors the spawn pattern in `src/container/start.ts` `commitSystemFile`.
|
|
68
68
|
const defaultDeps: GitNudgeDeps = {
|
|
69
|
-
async readStatus(agentDir) {
|
|
69
|
+
async readStatus(agentDir, gitArgs) {
|
|
70
70
|
const bun = getBun()
|
|
71
71
|
if (!bun) return null
|
|
72
72
|
try {
|
|
73
73
|
const proc = bun.spawn({
|
|
74
|
-
cmd: ['git', 'status', '--porcelain=v1'],
|
|
74
|
+
cmd: ['git', ...gitArgs, 'status', '--porcelain=v1'],
|
|
75
75
|
cwd: agentDir,
|
|
76
76
|
stdout: 'pipe',
|
|
77
77
|
stderr: 'pipe',
|
package/src/agent/index.ts
CHANGED
|
@@ -14,7 +14,14 @@ import type { AgentSession, ToolDefinition } from '@mariozechner/pi-coding-agent
|
|
|
14
14
|
import { loadMemory } from '@/bundled-plugins/memory/load-memory'
|
|
15
15
|
import type { ChannelRouter } from '@/channels/router'
|
|
16
16
|
import type { ReactionRef } from '@/channels/types'
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
getConfig,
|
|
19
|
+
resolveModel,
|
|
20
|
+
resolveProfile,
|
|
21
|
+
type Models,
|
|
22
|
+
type ResolvedProfile,
|
|
23
|
+
type ThinkingLevel,
|
|
24
|
+
} from '@/config'
|
|
18
25
|
import { defaultThinkingLevelForRef, isOpenAiFamilyRef, providerForModelRef, type ModelRef } from '@/config/providers'
|
|
19
26
|
import { renderMcpCatalog } from '@/mcp/catalog'
|
|
20
27
|
import type { McpManager } from '@/mcp/manager'
|
|
@@ -235,6 +242,20 @@ export type CreateSessionResult = {
|
|
|
235
242
|
dispose: () => Promise<void>
|
|
236
243
|
}
|
|
237
244
|
|
|
245
|
+
// A session's reasoning effort layers like the model does: the resolved
|
|
246
|
+
// profile's own `thinkingLevel` → the `default` profile's `thinkingLevel`
|
|
247
|
+
// (the de-facto global default, mirroring how `models.default` is the default
|
|
248
|
+
// model) → the per-provider/SDK default for the active ref. When the requested
|
|
249
|
+
// profile was unknown, `resolved` is already the `default` profile, so the
|
|
250
|
+
// first two terms coincide and the expression still does the right thing.
|
|
251
|
+
export function resolveSessionThinkingLevel(
|
|
252
|
+
models: Models,
|
|
253
|
+
resolved: Pick<ResolvedProfile, 'thinkingLevel'>,
|
|
254
|
+
activeRef: ModelRef,
|
|
255
|
+
): ThinkingLevel | undefined {
|
|
256
|
+
return resolved.thinkingLevel ?? models.default.thinkingLevel ?? defaultThinkingLevelForRef(activeRef)
|
|
257
|
+
}
|
|
258
|
+
|
|
238
259
|
export async function createSession(options: CreateSessionOptions = {}): Promise<AgentSession> {
|
|
239
260
|
const { session } = await createSessionWithDispose(options)
|
|
240
261
|
return session
|
|
@@ -439,7 +460,9 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
439
460
|
: customToolsPreBudget
|
|
440
461
|
|
|
441
462
|
const model = applyModelRuntimeOverrides(resolveModel(activeRef), activeRef)
|
|
442
|
-
|
|
463
|
+
// Read live so a reloaded `models` lands on the next session without a
|
|
464
|
+
// container restart.
|
|
465
|
+
const thinkingLevel = resolveSessionThinkingLevel(getConfig().models, resolved, activeRef)
|
|
443
466
|
const { session } = await createAgentSession({
|
|
444
467
|
model,
|
|
445
468
|
sessionManager,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { basename } from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { type RestartHandoffOrigin, writeRestartHandoff } from '@/agent/restart-handoff'
|
|
4
|
-
import {
|
|
5
|
-
import { containerSocketPath } from '@/hostd/paths'
|
|
4
|
+
import { sendHttp } from '@/hostd/client'
|
|
6
5
|
import type { Stream } from '@/stream'
|
|
7
6
|
|
|
8
7
|
const ACK_TIMEOUT_MS = 5_000
|
|
@@ -16,7 +15,6 @@ export type ContainerRestartingBroadcast = {
|
|
|
16
15
|
export type RequestContainerRestartOptions = {
|
|
17
16
|
containerName: string
|
|
18
17
|
build?: boolean
|
|
19
|
-
socketPath?: string
|
|
20
18
|
hostdUrl?: string
|
|
21
19
|
hostdToken?: string
|
|
22
20
|
ackTimeoutMs?: number
|
|
@@ -49,7 +47,6 @@ export type RequestContainerRestartResult =
|
|
|
49
47
|
export async function requestContainerRestart({
|
|
50
48
|
containerName,
|
|
51
49
|
build,
|
|
52
|
-
socketPath,
|
|
53
50
|
hostdUrl,
|
|
54
51
|
hostdToken,
|
|
55
52
|
ackTimeoutMs,
|
|
@@ -65,10 +62,22 @@ export async function requestContainerRestart({
|
|
|
65
62
|
const httpUrl = hostdUrl ?? process.env.TYPECLAW_HOSTD_URL
|
|
66
63
|
const httpToken = hostdToken ?? process.env.TYPECLAW_HOSTD_TOKEN
|
|
67
64
|
const ackBudget = ackTimeoutMs ?? ACK_TIMEOUT_MS
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
|
|
66
|
+
// HTTP/TCP is the only container->hostd transport (TYPECLAW_HOSTD_URL/TOKEN,
|
|
67
|
+
// injected by start.ts via host.docker.internal). There is no Unix-socket
|
|
68
|
+
// fallback: the host run dir is never bind-mounted, so the old
|
|
69
|
+
// `/run/typeclaw-host/hostd.sock` dial always silently failed — and on native
|
|
70
|
+
// Windows the host transport is a named pipe, not a socket. Fail loud here
|
|
71
|
+
// when the control env is absent (hostd unregistered/disabled).
|
|
72
|
+
if (!httpUrl || !httpToken) {
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
containerName,
|
|
76
|
+
reason:
|
|
77
|
+
'host daemon control endpoint unavailable (TYPECLAW_HOSTD_URL/TYPECLAW_HOSTD_TOKEN not set); cannot request restart',
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const reply = await sendHttp(request, { timeoutMs: ackBudget, url: httpUrl, token: httpToken })
|
|
72
81
|
|
|
73
82
|
if (!reply.ok) return { ok: false, containerName, reason: reply.reason }
|
|
74
83
|
|
|
@@ -370,6 +370,27 @@ function renderChannelOrigin(
|
|
|
370
370
|
'One verdict, one surface. After submitting the review, use',
|
|
371
371
|
'`skip_response({ reason: "verdict posted as review" })`.',
|
|
372
372
|
)
|
|
373
|
+
|
|
374
|
+
// Models reliably address review-comment feedback and then end the turn
|
|
375
|
+
// WITHOUT resolving the thread — leaving a wall of "open" threads on the PR.
|
|
376
|
+
// The `resolve_review_thread` flag lives only in the tool description, which
|
|
377
|
+
// the model reads at call time and routinely skips. The resolve cannot run
|
|
378
|
+
// in a later turn (a successful reply ends the turn), so a bare ack strands
|
|
379
|
+
// the thread permanently. Gate on `thread`: a top-level PR/issue comment has
|
|
380
|
+
// no thread to resolve, and the flag is a no-op there.
|
|
381
|
+
if (origin.thread !== null) {
|
|
382
|
+
lines.push(
|
|
383
|
+
'',
|
|
384
|
+
'**This is an inline review thread. When your reply acknowledges the',
|
|
385
|
+
'concern is fixed/addressed, set `resolve_review_thread: true` on that',
|
|
386
|
+
'`channel_reply` — in the SAME call.** A bare acknowledgement leaves the',
|
|
387
|
+
'thread open forever: the resolve only runs as part of this reply, never',
|
|
388
|
+
'in a later turn. It is safe to set by default — the runtime resolves',
|
|
389
|
+
"only threads you authored and refuses on a human reviewer's thread.",
|
|
390
|
+
'Leave it unset only when you mean to keep the thread open (partial fix,',
|
|
391
|
+
'disagreement, mid-discussion).',
|
|
392
|
+
)
|
|
393
|
+
}
|
|
373
394
|
}
|
|
374
395
|
|
|
375
396
|
// Discord renders no GFM tables — a raw `| a | b |` block shows as literal
|
package/src/agent/subagents.ts
CHANGED
|
@@ -130,6 +130,24 @@ function describePayload(payload: unknown): string {
|
|
|
130
130
|
return typeof payload
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
// Per-spawn override wins over the subagent's declared profile; absent override
|
|
134
|
+
// keeps the declared profile. Both may be undefined (no profile → createSession
|
|
135
|
+
// resolves `default`).
|
|
136
|
+
export function resolveSubagentProfile(
|
|
137
|
+
subagent: SubagentShared<any>,
|
|
138
|
+
options: CreateSessionForSubagentOptions | undefined,
|
|
139
|
+
): string | undefined {
|
|
140
|
+
return options?.profileOverride ?? subagent.profile
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function profileFromPayload(payload: unknown): string | undefined {
|
|
144
|
+
if (payload !== null && typeof payload === 'object') {
|
|
145
|
+
const value = (payload as { profile?: unknown }).profile
|
|
146
|
+
if (typeof value === 'string' && value !== '') return value
|
|
147
|
+
}
|
|
148
|
+
return undefined
|
|
149
|
+
}
|
|
150
|
+
|
|
133
151
|
export type CreateSessionForSubagentResult = {
|
|
134
152
|
session: AgentSession
|
|
135
153
|
dispose?: () => Promise<void>
|
|
@@ -160,6 +178,12 @@ export type CreateSessionForSubagentOptions = {
|
|
|
160
178
|
// wiring hooks without permissions would inject the GitHub token yet leave the
|
|
161
179
|
// sandbox OFF — strictly weaker than the plugin-subagent branch this matches.
|
|
162
180
|
permissions?: PermissionService
|
|
181
|
+
// Per-spawn model-profile override, resolved by `invokeSubagent` from the
|
|
182
|
+
// validated payload's `profile` field. Wins over the subagent's declared
|
|
183
|
+
// `profile`, letting a single spawn run a worker on a different model tier
|
|
184
|
+
// (e.g. operator on `deep`) without a second subagent. Unknown profile names
|
|
185
|
+
// fall back to `default` via resolveProfile, the same as a declared profile.
|
|
186
|
+
profileOverride?: string
|
|
163
187
|
}
|
|
164
188
|
export type CreateSessionForSubagent = (
|
|
165
189
|
subagent: Subagent<any>,
|
|
@@ -180,7 +204,9 @@ export const defaultCreateSessionForSubagent: CreateSessionForSubagent = (subage
|
|
|
180
204
|
customTools: subagent.customTools ?? [],
|
|
181
205
|
...(options?.plugins !== undefined ? { plugins: options.plugins } : {}),
|
|
182
206
|
...(options?.permissions !== undefined ? { permissions: options.permissions } : {}),
|
|
183
|
-
...(subagent
|
|
207
|
+
...(resolveSubagentProfile(subagent, options) !== undefined
|
|
208
|
+
? { profile: resolveSubagentProfile(subagent, options) }
|
|
209
|
+
: {}),
|
|
184
210
|
...(subagent.toolResultBudget !== undefined ? { toolResultBudget: subagent.toolResultBudget } : {}),
|
|
185
211
|
...(subagent.bashPolicy !== undefined ? { bashPolicy: subagent.bashPolicy } : {}),
|
|
186
212
|
})
|
|
@@ -255,11 +281,13 @@ export async function invokeSubagent(name: string, options: InvokeSubagentOption
|
|
|
255
281
|
|
|
256
282
|
const validatedPayload = validateSubagentPayload(name, subagent, options.payload)
|
|
257
283
|
const createSessionForSubagent = options.createSessionForSubagent ?? defaultCreateSessionForSubagent
|
|
284
|
+
const profileOverride = profileFromPayload(validatedPayload)
|
|
258
285
|
const sessionOptions: CreateSessionForSubagentOptions = {
|
|
259
286
|
name,
|
|
260
287
|
...(options.parentSessionId !== undefined ? { parentSessionId: options.parentSessionId } : {}),
|
|
261
288
|
...(options.spawnedByRole !== undefined ? { spawnedByRole: options.spawnedByRole } : {}),
|
|
262
289
|
...(options.spawnedByOrigin !== undefined ? { spawnedByOrigin: options.spawnedByOrigin } : {}),
|
|
290
|
+
...(profileOverride !== undefined ? { profileOverride } : {}),
|
|
263
291
|
}
|
|
264
292
|
|
|
265
293
|
const runSession: RunSession = async (override) => {
|
|
@@ -48,9 +48,23 @@ If it describes how you sound, use SOUL.md; how you work, AGENTS.md. **Edit disc
|
|
|
48
48
|
- **\`typeclaw.json\`** — runtime config. Read when needed.
|
|
49
49
|
- **\`secrets.json\`** — canonical gitignored secrets store. \`.env\` is legacy/env override. Never echo, log, or commit either file's values; hand-edit only when explicitly rotating credentials.
|
|
50
50
|
|
|
51
|
-
##
|
|
51
|
+
## Understanding the request
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
When the next action is clear, start work in the same turn — don't answer with only a plan, and for multi-step work give one short progress update, not narration.
|
|
54
|
+
|
|
55
|
+
Read for the practical task behind the wording, not the literal speech act: a status question ("is the build red?") usually wants the answer **and** the obvious next step it implies, and a capability or permission phrasing ("can you add a retry?", "a dark mode would be nice") is almost always a request to **do** the thing, not a yes/no about whether you're able to — this holds in any language, so treat the polite form as the imperative it is. Reading intent well means **fewer** clarifying questions, not more: act on the safe, conventional reading and stay within the apparent request rather than inventing a larger project; ask only when the plausible interpretations would materially change scope, permissions, cost, or risk.
|
|
56
|
+
|
|
57
|
+
Recognizing the task also means recognizing **who** should do it. When the real work is heavy, side-effectful, long-running, or multi-step — installs, builds, \`docker\`, long test runs, refactors, a bug that resisted a quick fix — prefer to delegate it to a subagent (usually \`operator\`) instead of grinding through it inline; this keeps the conversation responsive and lets you raise the model tier for genuinely hard work. Keep quick, single-shot answers inline. See \`## Subagent orchestration\` for the mechanics.
|
|
58
|
+
|
|
59
|
+
## Finishing the job
|
|
60
|
+
|
|
61
|
+
When the user asks you to build, run, fix, or verify something, the deliverable is a working artifact backed by real tool output — not a description of one. Do not stop after writing a stub, a plan, or a single command; keep working until you have actually exercised the code or produced the requested result, then report what real execution returned.
|
|
62
|
+
|
|
63
|
+
If a tool, install, or network call fails and blocks the real path, say so directly and try an alternative (different approach, different package, ask the user). Never substitute plausible-looking fabricated output (made-up data, invented file contents, synthesised tool results) for a result you could not actually produce — reporting a blocker honestly is always better than inventing a result.
|
|
64
|
+
|
|
65
|
+
## Parallel tool calls
|
|
66
|
+
|
|
67
|
+
When you need several pieces of information that don't depend on each other, request them in a single response instead of one tool call per turn. Independent reads, searches, and read-only commands should be batched into the same turn — the runtime runs independent calls concurrently, and batching avoids re-sending the whole conversation on every extra round-trip. Only serialize when a later call genuinely depends on an earlier call's result (e.g. read a file before patching it).
|
|
54
68
|
|
|
55
69
|
## Tracking your work
|
|
56
70
|
|
|
@@ -96,7 +110,6 @@ Commits to your agent folder (your own state):
|
|
|
96
110
|
- Match the user's register. If SOUL.md specifies a voice, use it; otherwise be concise and direct.
|
|
97
111
|
- Read files/memory before guessing. Follow AGENTS.md under your IDENTITY.md role; suggest AGENTS.md additions for repeatable gaps.
|
|
98
112
|
- Answer questions, do work, and avoid over-explaining unless asked.
|
|
99
|
-
- Ask one clarifying question only when ambiguity would materially change the work; otherwise choose a reasonable default.
|
|
100
113
|
- Never suppress errors to make things "work", and never fabricate results. Report failures clearly.
|
|
101
114
|
|
|
102
115
|
## Subagent orchestration
|
|
@@ -107,9 +120,9 @@ Pick one of three modes:
|
|
|
107
120
|
|
|
108
121
|
**Mode A — Research fan-out.** Broad search: spawn 2-5 \`explorer\`/\`scout\` workers in parallel with \`run_in_background: true\`, end your response, then collect each completion once via \`subagent_output\`. Use \`scout\` for narrow lookups; \`researcher\` for decomposed, multi-source, cross-validated synthesis. When the user *explicitly* says "research"/"investigate" (or equivalent), you MUST spawn \`researcher\` — answering from training memory or a single inline \`web_search\` does not satisfy the request, even if you think you know the answer. (Fanning out \`scout\`/\`explorer\` underneath is fine, but it does not replace \`researcher\`.)
|
|
109
122
|
|
|
110
|
-
**Mode B — Delegate-and-converse.** For >~30s side-effectful/noisy work (installs, builds, \`docker\`, scrapes, long tests, multi-host loops, fetch-and-synthesize chains), spawn one background subagent and stay responsive: \`operator\` for side effects, \`scout\` quick lookup, \`researcher\` deep investigation, \`planner\` risk-aware sequencing. Keep single fast calls inline. When the completion \`<system-reminder>\` lands, Surface the result via \`channel_reply\`/\`channel_send\` in channel sessions because reminders are not user messages.
|
|
123
|
+
**Mode B — Delegate-and-converse.** For >~30s side-effectful/noisy work (installs, builds, \`docker\`, scrapes, long tests, multi-host loops, fetch-and-synthesize chains), spawn one background subagent and stay responsive: \`operator\` for side effects, \`scout\` quick lookup, \`researcher\` deep investigation, \`planner\` risk-aware sequencing. Keep single fast calls inline. For hard execution work that needs stronger reasoning than the default tier — gnarly bugs, non-obvious refactors, failures that resisted a quick fix — pass \`profile: "deep"\` to run that one spawn on a stronger model; leave it off for routine work. When the completion \`<system-reminder>\` lands, Surface the result via \`channel_reply\`/\`channel_send\` in channel sessions because reminders are not user messages.
|
|
111
124
|
|
|
112
|
-
**Mode C — Troubleshooting.** After ~3 non-converging attempts at the same failure, stop and hand the loop to \`operator\` with \`run_in_background: true
|
|
125
|
+
**Mode C — Troubleshooting.** After ~3 non-converging attempts at the same failure, stop and hand the loop to \`operator\` with \`run_in_background: true\` (and \`profile: "deep"\` when the failure is genuinely hard), symptom, attempts, and success condition. Read \`typeclaw-troubleshooting\` before spawning.
|
|
113
126
|
|
|
114
127
|
**Status queries.** If the user asks "status?" on a running subagent, call \`subagent_output({ task_id })\` and report its \`status_summary\` — don't guess.
|
|
115
128
|
|
|
@@ -10,7 +10,6 @@ const EXIT_DELAY_MS = 500
|
|
|
10
10
|
export type CreateRestartToolOptions = {
|
|
11
11
|
containerName: string
|
|
12
12
|
exit?: (code: number) => void
|
|
13
|
-
socketPath?: string
|
|
14
13
|
hostdUrl?: string
|
|
15
14
|
hostdToken?: string
|
|
16
15
|
// Optional so unit tests and ad-hoc tool construction keep working without
|
|
@@ -72,7 +71,6 @@ export type { ContainerRestartingBroadcast } from '@/agent/restart'
|
|
|
72
71
|
export function createRestartTool({
|
|
73
72
|
containerName,
|
|
74
73
|
exit,
|
|
75
|
-
socketPath,
|
|
76
74
|
hostdUrl,
|
|
77
75
|
hostdToken,
|
|
78
76
|
stream,
|
|
@@ -121,7 +119,6 @@ export function createRestartTool({
|
|
|
121
119
|
containerName,
|
|
122
120
|
build,
|
|
123
121
|
originatingSessionId,
|
|
124
|
-
...(socketPath !== undefined ? { socketPath } : {}),
|
|
125
122
|
...(hostdUrl !== undefined ? { hostdUrl } : {}),
|
|
126
123
|
...(hostdToken !== undefined ? { hostdToken } : {}),
|
|
127
124
|
...(ackTimeoutMs !== undefined ? { ackTimeoutMs } : {}),
|
|
@@ -88,6 +88,12 @@ export function createSpawnSubagentTool(options: CreateSpawnSubagentToolOptions)
|
|
|
88
88
|
'NOTE: background mode from subagents is only available when that subagent is explicitly enabled to drain child results; otherwise use sync spawns batched in one turn instead.',
|
|
89
89
|
}),
|
|
90
90
|
),
|
|
91
|
+
profile: Type.Optional(
|
|
92
|
+
Type.String({
|
|
93
|
+
description:
|
|
94
|
+
'Model profile to run this spawn on, overriding the subagent\'s default tier for this one task. Use "deep" for hard work that needs stronger reasoning (gnarly bugs, non-obvious refactors, failures that resisted a quick fix); omit (or "default") for routine work. Resolves against the configured model profiles; an unknown name falls back to default. Most useful on `operator` — leave it off unless the task clearly warrants a heavier model.',
|
|
95
|
+
}),
|
|
96
|
+
),
|
|
91
97
|
}),
|
|
92
98
|
|
|
93
99
|
async execute(_toolCallId, params): Promise<ToolReturn> {
|
|
@@ -122,6 +128,7 @@ export function createSpawnSubagentTool(options: CreateSpawnSubagentToolOptions)
|
|
|
122
128
|
const background = params.run_in_background === true
|
|
123
129
|
const payload: Record<string, unknown> = { requestId: taskId, prompt: params.prompt }
|
|
124
130
|
if (params.description !== undefined) payload.description = params.description
|
|
131
|
+
if (params.profile !== undefined) payload.profile = params.profile
|
|
125
132
|
|
|
126
133
|
const startedAt = now()
|
|
127
134
|
const spawnedByRole = permissions?.resolveRole(origin)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
|
|
3
3
|
import { withGitLock } from '@/git/mutex'
|
|
4
|
+
import { resolveAgentGit } from '@/git/resolve-agent-git'
|
|
4
5
|
import { definePlugin, type PluginContext, type SpawnSubagentOptions, type Subagent } from '@/plugin'
|
|
5
6
|
|
|
6
7
|
import { type BackupPushAuthDeps, makeDefaultAskPassEnsurer, resolveBackupPushAuthEnv } from './git-auth'
|
|
@@ -257,12 +258,14 @@ async function resolveBackupAuthEnv(
|
|
|
257
258
|
}
|
|
258
259
|
}
|
|
259
260
|
|
|
260
|
-
async function resolveOriginPushUrl(cwd: string): Promise<string | null> {
|
|
261
|
+
export async function resolveOriginPushUrl(cwd: string): Promise<string | null> {
|
|
261
262
|
const bun = (globalThis as { Bun?: { spawn: typeof Bun.spawn } }).Bun
|
|
262
263
|
if (!bun) return null
|
|
264
|
+
const repo = resolveAgentGit(cwd)
|
|
265
|
+
if (!repo) return null
|
|
263
266
|
try {
|
|
264
267
|
const proc = bun.spawn({
|
|
265
|
-
cmd: ['git', '-C', cwd, 'remote', 'get-url', '--push', 'origin'],
|
|
268
|
+
cmd: ['git', '-C', cwd, ...repo.gitArgs, 'remote', 'get-url', '--push', 'origin'],
|
|
266
269
|
stdout: 'pipe',
|
|
267
270
|
stderr: 'ignore',
|
|
268
271
|
env: { ...process.env, GIT_TERMINAL_PROMPT: '0', GIT_OPTIONAL_LOCKS: '0' },
|