typeclaw 0.39.0 → 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 +1 -0
- package/package.json +2 -2
- package/src/agent/attention-escalation.ts +154 -4
- package/src/agent/git-nudge.ts +7 -7
- package/src/agent/session-origin.ts +21 -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/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/config/config.ts +7 -5
- package/src/container/shared.ts +115 -14
- package/src/container/shell.ts +12 -2
- 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/webex-renewal-manager.ts +216 -0
- package/src/init/dockerfile.ts +13 -4
- package/src/init/gitignore.ts +4 -2
- package/src/secrets/schema.ts +1 -0
- package/src/secrets/webex-renewal.ts +215 -0
- package/src/server/index.ts +25 -3
- package/typeclaw.schema.json +6 -1
package/README.md
CHANGED
|
@@ -127,6 +127,7 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for the recommended local dev loop (`bu
|
|
|
127
127
|
|
|
128
128
|
- **Multi-channel** is powered by [agent-messenger](https://github.com/agent-messenger/agent-messenger) — every non-GitHub adapter (`slack-bot`, `discord-bot`, `telegram-bot`, `webex-bot`, `line`, `kakaotalk`) is built on its SDK. Thanks to the maintainers for the credential extraction, listener protocols, and platform coverage that made multi-channel a feature instead of a year-long project.
|
|
129
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.
|
|
130
131
|
|
|
131
132
|
## License
|
|
132
133
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeclaw",
|
|
3
|
-
"version": "0.39.
|
|
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,10 +554,158 @@ 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
|
}
|
|
@@ -570,8 +718,9 @@ const ESCALATED_LEVEL: ThinkingLevel = 'xhigh'
|
|
|
570
718
|
export function resolveTurnThinkingLevel(
|
|
571
719
|
text: string,
|
|
572
720
|
sessionDefault: ThinkingLevel | undefined,
|
|
721
|
+
prior?: QuestionSignal | null,
|
|
573
722
|
): ThinkingLevel | undefined {
|
|
574
|
-
return detectAttentionEscalation(text) ? ESCALATED_LEVEL : sessionDefault
|
|
723
|
+
return detectAttentionEscalation(text, prior) ? ESCALATED_LEVEL : sessionDefault
|
|
575
724
|
}
|
|
576
725
|
|
|
577
726
|
type ThinkingLevelSettable = {
|
|
@@ -585,7 +734,8 @@ export function applyTurnThinkingLevel(
|
|
|
585
734
|
session: ThinkingLevelSettable,
|
|
586
735
|
text: string,
|
|
587
736
|
sessionDefault: ThinkingLevel | undefined,
|
|
737
|
+
prior?: QuestionSignal | null,
|
|
588
738
|
): void {
|
|
589
|
-
const resolved = resolveTurnThinkingLevel(text, sessionDefault)
|
|
739
|
+
const resolved = resolveTurnThinkingLevel(text, sessionDefault, prior)
|
|
590
740
|
if (resolved !== undefined) session.setThinkingLevel(resolved)
|
|
591
741
|
}
|
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',
|
|
@@ -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
|
|
@@ -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' },
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
|
|
4
|
+
import { type AgentGit, resolveAgentGit } from '@/git/resolve-agent-git'
|
|
5
|
+
|
|
4
6
|
export const COMMIT_TIMEOUT_MS = 30_000
|
|
5
7
|
export const NETWORK_TIMEOUT_MS = 60_000
|
|
6
8
|
|
|
@@ -64,9 +66,10 @@ type PushPlan = ActivePushPlan | { kind: 'skip' }
|
|
|
64
66
|
export async function runBackup(options: BackupRunnerOptions, deps: BackupRunnerDeps): Promise<BackupResult> {
|
|
65
67
|
const { cwd, pushToOrigin } = options
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
const repo = resolveAgentGit(cwd)
|
|
70
|
+
if (!repo) return { ok: true, kind: 'no-repo' }
|
|
68
71
|
|
|
69
|
-
const status = await deps.gitSpawn(['status', '--porcelain=v1', '--untracked-files=all'], {
|
|
72
|
+
const status = await deps.gitSpawn([...repo.gitArgs, 'status', '--porcelain=v1', '--untracked-files=all'], {
|
|
70
73
|
cwd,
|
|
71
74
|
timeoutMs: COMMIT_TIMEOUT_MS,
|
|
72
75
|
})
|
|
@@ -76,23 +79,32 @@ export async function runBackup(options: BackupRunnerOptions, deps: BackupRunner
|
|
|
76
79
|
if (dirty.length === 0 && force.length === 0) return { ok: true, kind: 'clean' }
|
|
77
80
|
|
|
78
81
|
if (dirty.length > 0) {
|
|
79
|
-
const add = await deps.gitSpawn(['add', '--', ...dirty], { cwd, timeoutMs: COMMIT_TIMEOUT_MS })
|
|
82
|
+
const add = await deps.gitSpawn([...repo.gitArgs, 'add', '--', ...dirty], { cwd, timeoutMs: COMMIT_TIMEOUT_MS })
|
|
80
83
|
if (add.exitCode !== 0) return { ok: false, kind: 'commit-failed', reason: `git add failed: ${shortErr(add)}` }
|
|
81
84
|
}
|
|
82
85
|
if (force.length > 0) {
|
|
83
86
|
const present = force.filter((p) => existsSync(join(cwd, p)))
|
|
84
87
|
if (present.length > 0) {
|
|
85
|
-
const addF = await deps.gitSpawn(['add', '-f', '--', ...present], {
|
|
88
|
+
const addF = await deps.gitSpawn([...repo.gitArgs, 'add', '-f', '--', ...present], {
|
|
89
|
+
cwd,
|
|
90
|
+
timeoutMs: COMMIT_TIMEOUT_MS,
|
|
91
|
+
})
|
|
86
92
|
if (addF.exitCode !== 0) {
|
|
87
93
|
return { ok: false, kind: 'commit-failed', reason: `git add -f failed: ${shortErr(addF)}` }
|
|
88
94
|
}
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
|
|
92
|
-
const stagedCheck = await deps.gitSpawn(['diff', '--cached', '--quiet'], {
|
|
98
|
+
const stagedCheck = await deps.gitSpawn([...repo.gitArgs, 'diff', '--cached', '--quiet'], {
|
|
99
|
+
cwd,
|
|
100
|
+
timeoutMs: COMMIT_TIMEOUT_MS,
|
|
101
|
+
})
|
|
93
102
|
if (stagedCheck.exitCode === 0) return { ok: true, kind: 'clean' }
|
|
94
103
|
|
|
95
|
-
const diffstat = await deps.gitSpawn(['diff', '--cached', '--stat'], {
|
|
104
|
+
const diffstat = await deps.gitSpawn([...repo.gitArgs, 'diff', '--cached', '--stat'], {
|
|
105
|
+
cwd,
|
|
106
|
+
timeoutMs: COMMIT_TIMEOUT_MS,
|
|
107
|
+
})
|
|
96
108
|
const message = await deps.pickCommitMessage({
|
|
97
109
|
status: status.stdout.slice(0, 4096),
|
|
98
110
|
diffstat: diffstat.stdout.slice(0, 4096),
|
|
@@ -106,14 +118,17 @@ export async function runBackup(options: BackupRunnerOptions, deps: BackupRunner
|
|
|
106
118
|
// one-cycle-behind churn. Re-status, filter to `sessions/` additions
|
|
107
119
|
// only (don't accidentally stage user work that arrived during the
|
|
108
120
|
// window), and force-add anything new.
|
|
109
|
-
const reStatus = await deps.gitSpawn(['status', '--porcelain=v1', '--untracked-files=all'], {
|
|
121
|
+
const reStatus = await deps.gitSpawn([...repo.gitArgs, 'status', '--porcelain=v1', '--untracked-files=all'], {
|
|
110
122
|
cwd,
|
|
111
123
|
timeoutMs: COMMIT_TIMEOUT_MS,
|
|
112
124
|
})
|
|
113
125
|
if (reStatus.exitCode === 0) {
|
|
114
126
|
const lateForce = filterForceAdd(parsePorcelain(reStatus.stdout)).filter((p) => existsSync(join(cwd, p)))
|
|
115
127
|
if (lateForce.length > 0) {
|
|
116
|
-
const lateAdd = await deps.gitSpawn(['add', '-f', '--', ...lateForce], {
|
|
128
|
+
const lateAdd = await deps.gitSpawn([...repo.gitArgs, 'add', '-f', '--', ...lateForce], {
|
|
129
|
+
cwd,
|
|
130
|
+
timeoutMs: COMMIT_TIMEOUT_MS,
|
|
131
|
+
})
|
|
117
132
|
if (lateAdd.exitCode !== 0) {
|
|
118
133
|
return { ok: false, kind: 'commit-failed', reason: `git add -f (post-message) failed: ${shortErr(lateAdd)}` }
|
|
119
134
|
}
|
|
@@ -121,16 +136,19 @@ export async function runBackup(options: BackupRunnerOptions, deps: BackupRunner
|
|
|
121
136
|
}
|
|
122
137
|
|
|
123
138
|
const safeMessage = sanitizeCommitMessage(message)
|
|
124
|
-
const commit = await deps.gitSpawn(['commit', '-m', safeMessage], {
|
|
139
|
+
const commit = await deps.gitSpawn([...repo.gitArgs, 'commit', '-m', safeMessage], {
|
|
140
|
+
cwd,
|
|
141
|
+
timeoutMs: COMMIT_TIMEOUT_MS,
|
|
142
|
+
})
|
|
125
143
|
if (commit.exitCode !== 0)
|
|
126
144
|
return { ok: false, kind: 'commit-failed', reason: `git commit failed: ${shortErr(commit)}` }
|
|
127
145
|
|
|
128
146
|
if (!pushToOrigin) return { ok: true, kind: 'committed' }
|
|
129
147
|
|
|
130
|
-
const plan = await resolvePushPlan(cwd, deps)
|
|
148
|
+
const plan = await resolvePushPlan(cwd, deps, repo)
|
|
131
149
|
if (plan.kind === 'skip') return { ok: true, kind: 'committed' }
|
|
132
150
|
|
|
133
|
-
return pushWithRecovery(cwd, deps, plan)
|
|
151
|
+
return pushWithRecovery(cwd, deps, repo, plan)
|
|
134
152
|
}
|
|
135
153
|
|
|
136
154
|
// `@{upstream}` resolution failing was previously treated as "no push" — but a
|
|
@@ -140,11 +158,14 @@ export async function runBackup(options: BackupRunnerOptions, deps: BackupRunner
|
|
|
140
158
|
// branch": then we push AND set the upstream in one shot, and every later run
|
|
141
159
|
// takes the plain-upstream path. No remote / detached HEAD stays commit-only
|
|
142
160
|
// (a legitimate offline state), so it returns `skip` rather than diagnosing.
|
|
143
|
-
async function resolvePushPlan(cwd: string, deps: BackupRunnerDeps): Promise<PushPlan> {
|
|
144
|
-
const upstream = await deps.gitSpawn(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
161
|
+
async function resolvePushPlan(cwd: string, deps: BackupRunnerDeps, repo: AgentGit): Promise<PushPlan> {
|
|
162
|
+
const upstream = await deps.gitSpawn(
|
|
163
|
+
[...repo.gitArgs, 'rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}'],
|
|
164
|
+
{
|
|
165
|
+
cwd,
|
|
166
|
+
timeoutMs: COMMIT_TIMEOUT_MS,
|
|
167
|
+
},
|
|
168
|
+
)
|
|
148
169
|
if (upstream.exitCode === 0 && upstream.stdout.trim().length > 0) {
|
|
149
170
|
return { kind: 'upstream', upstreamRef: upstream.stdout.trim() }
|
|
150
171
|
}
|
|
@@ -153,13 +174,19 @@ async function resolvePushPlan(cwd: string, deps: BackupRunnerDeps): Promise<Pus
|
|
|
153
174
|
// would guess a destination the operator never configured. `get-url` (not
|
|
154
175
|
// `get-url --push`) is enough here — we only need to know origin EXISTS and
|
|
155
176
|
// is named `origin`; the push targets `origin` by name regardless of pushurl.
|
|
156
|
-
const origin = await deps.gitSpawn(['remote', 'get-url', 'origin'], {
|
|
177
|
+
const origin = await deps.gitSpawn([...repo.gitArgs, 'remote', 'get-url', 'origin'], {
|
|
178
|
+
cwd,
|
|
179
|
+
timeoutMs: COMMIT_TIMEOUT_MS,
|
|
180
|
+
})
|
|
157
181
|
if (origin.exitCode !== 0 || origin.stdout.trim().length === 0) return { kind: 'skip' }
|
|
158
182
|
|
|
159
183
|
// `symbolic-ref --short HEAD` fails on a detached HEAD (no branch to set an
|
|
160
184
|
// upstream for); `rev-parse --abbrev-ref HEAD` would have returned the literal
|
|
161
185
|
// "HEAD" and we'd have tried to push a branch named HEAD. Skip cleanly.
|
|
162
|
-
const branch = await deps.gitSpawn(['symbolic-ref', '--short', 'HEAD'], {
|
|
186
|
+
const branch = await deps.gitSpawn([...repo.gitArgs, 'symbolic-ref', '--short', 'HEAD'], {
|
|
187
|
+
cwd,
|
|
188
|
+
timeoutMs: COMMIT_TIMEOUT_MS,
|
|
189
|
+
})
|
|
163
190
|
if (branch.exitCode !== 0 || branch.stdout.trim().length === 0) return { kind: 'skip' }
|
|
164
191
|
|
|
165
192
|
return { kind: 'set-upstream', remote: 'origin', branch: branch.stdout.trim() }
|
|
@@ -169,13 +196,18 @@ async function resolvePushPlan(cwd: string, deps: BackupRunnerDeps): Promise<Pus
|
|
|
169
196
|
// non-fast-forward recovery: fetch, rebase onto the intended remote branch,
|
|
170
197
|
// re-push. Keeping one helper stops the set-upstream path from silently becoming
|
|
171
198
|
// a weaker duplicate that skips recovery.
|
|
172
|
-
async function pushWithRecovery(
|
|
173
|
-
|
|
199
|
+
async function pushWithRecovery(
|
|
200
|
+
cwd: string,
|
|
201
|
+
deps: BackupRunnerDeps,
|
|
202
|
+
repo: AgentGit,
|
|
203
|
+
plan: ActivePushPlan,
|
|
204
|
+
): Promise<BackupResult> {
|
|
205
|
+
const pushArgs = [...repo.gitArgs, ...pushArgsFor(plan)]
|
|
174
206
|
const rebaseRef = plan.kind === 'upstream' ? plan.upstreamRef : `${plan.remote}/${plan.branch}`
|
|
175
207
|
// In the set-upstream case there is no tracking ref yet, so a bare `git fetch`
|
|
176
208
|
// has no configured remote to default to — fetch the same remote we rebase
|
|
177
209
|
// onto. The upstream case keeps bare `fetch` (its tracking config resolves it).
|
|
178
|
-
const fetchArgs = plan.kind === 'upstream' ? ['fetch'] : ['fetch', plan.remote]
|
|
210
|
+
const fetchArgs = [...repo.gitArgs, ...(plan.kind === 'upstream' ? ['fetch'] : ['fetch', plan.remote])]
|
|
179
211
|
const pushedKind: BackupResult = { ok: true, kind: plan.kind === 'upstream' ? 'pushed' : 'pushed-set-upstream' }
|
|
180
212
|
// Credentials ride ONLY on the network calls (push/fetch). The rebase is
|
|
181
213
|
// local (it replays onto an already-fetched remote-tracking ref), so it runs
|
|
@@ -202,9 +234,9 @@ async function pushWithRecovery(cwd: string, deps: BackupRunnerDeps, plan: Activ
|
|
|
202
234
|
return { ok: false, kind: 'push-failed', reason: `git fetch failed: ${shortErr(fetch)}` }
|
|
203
235
|
}
|
|
204
236
|
|
|
205
|
-
const rebase = await deps.gitSpawn(['rebase', rebaseRef], { cwd, timeoutMs: NETWORK_TIMEOUT_MS })
|
|
237
|
+
const rebase = await deps.gitSpawn([...repo.gitArgs, 'rebase', rebaseRef], { cwd, timeoutMs: NETWORK_TIMEOUT_MS })
|
|
206
238
|
if (rebase.exitCode !== 0) {
|
|
207
|
-
await deps.gitSpawn(['rebase', '--abort'], { cwd, timeoutMs: COMMIT_TIMEOUT_MS })
|
|
239
|
+
await deps.gitSpawn([...repo.gitArgs, 'rebase', '--abort'], { cwd, timeoutMs: COMMIT_TIMEOUT_MS })
|
|
208
240
|
await maybeDiagnose(deps, {
|
|
209
241
|
cwd,
|
|
210
242
|
stage: 'rebase',
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join } from 'node:path'
|
|
3
|
-
|
|
1
|
+
import { resolveAgentGit } from '@/git/resolve-agent-git'
|
|
4
2
|
import type { ContentPart, ToolResult } from '@/plugin'
|
|
5
3
|
|
|
6
4
|
export const GUARD_UNCOMMITTED_CHANGES = 'uncommittedChanges'
|
|
@@ -13,7 +11,7 @@ const WARNING_TEXT =
|
|
|
13
11
|
'\n\n[guard:uncommittedChanges] The worktree has uncommitted changes. Commit (or stash) them when this task is done — leaving stale changes around between turns risks losing work and confusing future commits.'
|
|
14
12
|
|
|
15
13
|
export type UncommittedChangesDeps = {
|
|
16
|
-
readStatus: (agentDir: string) => Promise<readonly string[] | null>
|
|
14
|
+
readStatus: (agentDir: string, gitArgs: readonly string[]) => Promise<readonly string[] | null>
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
export async function checkUncommittedChangesAdvice(options: {
|
|
@@ -24,10 +22,11 @@ export async function checkUncommittedChangesAdvice(options: {
|
|
|
24
22
|
}): Promise<void> {
|
|
25
23
|
const { tool, agentDir, result } = options
|
|
26
24
|
if (!FILE_TOUCHING_TOOLS.has(tool)) return
|
|
27
|
-
|
|
25
|
+
const repo = resolveAgentGit(agentDir)
|
|
26
|
+
if (!repo) return
|
|
28
27
|
|
|
29
28
|
const deps = options.deps ?? defaultDeps
|
|
30
|
-
const status = await deps.readStatus(agentDir)
|
|
29
|
+
const status = await deps.readStatus(agentDir, repo.gitArgs)
|
|
31
30
|
if (status === null) return
|
|
32
31
|
|
|
33
32
|
const dirty = status.filter((p) => !RUNTIME_OWNED_PREFIXES.some((prefix) => p.startsWith(prefix)))
|
|
@@ -59,12 +58,12 @@ function appendAdviceToContent(content: ContentPart[], advice: string): void {
|
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
const defaultDeps: UncommittedChangesDeps = {
|
|
62
|
-
async readStatus(agentDir) {
|
|
61
|
+
async readStatus(agentDir, gitArgs) {
|
|
63
62
|
const bun = getBun()
|
|
64
63
|
if (!bun) return null
|
|
65
64
|
try {
|
|
66
65
|
const proc = bun.spawn({
|
|
67
|
-
cmd: ['git', 'status', '--porcelain=v1'],
|
|
66
|
+
cmd: ['git', ...gitArgs, 'status', '--porcelain=v1'],
|
|
68
67
|
cwd: agentDir,
|
|
69
68
|
stdout: 'pipe',
|
|
70
69
|
stderr: 'pipe',
|