typeclaw 0.37.3 → 0.37.5
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 +69 -46
- package/package.json +1 -1
- package/src/agent/compaction.ts +24 -15
- package/src/agent/doctor.ts +6 -1
- package/src/agent/session-origin.ts +101 -173
- package/src/agent/subagents.ts +146 -14
- package/src/agent/system-prompt.ts +46 -48
- package/src/agent/todo/scope.ts +4 -2
- package/src/agent/tools/channel-reply.ts +7 -9
- package/src/bundled-plugins/memory/index.ts +33 -33
- package/src/bundled-plugins/memory/load-memory.ts +92 -35
- package/src/bundled-plugins/memory/slug.ts +19 -0
- package/src/bundled-plugins/memory/turn-dedup.ts +32 -29
- package/src/bundled-plugins/security/policies/private-surface-read.ts +4 -1
- package/src/bundled-plugins/tool-result-cap/README.md +7 -7
- package/src/bundled-plugins/tool-result-cap/index.ts +1 -1
- package/src/channels/adapters/discord-bot.ts +11 -4
- package/src/channels/adapters/github/inbound.ts +68 -43
- package/src/channels/adapters/github/index.ts +57 -9
- package/src/channels/adapters/github/recover-failed-deliveries.ts +270 -0
- package/src/channels/adapters/kakaotalk.ts +5 -1
- package/src/channels/adapters/mention-hints.ts +75 -0
- package/src/channels/adapters/slack-bot.ts +8 -2
- package/src/channels/continuation-willingness.ts +216 -68
- package/src/channels/router.ts +149 -15
- package/src/cli/dreams.ts +2 -2
- package/src/cli/init.ts +41 -7
- package/src/cli/inspect.ts +2 -2
- package/src/cli/logs.ts +2 -2
- package/src/cli/qr.ts +4 -3
- package/src/cli/require-agent-dir.ts +31 -0
- package/src/cli/shell.ts +2 -2
- package/src/cli/stop.ts +2 -2
- package/src/cli/tui.ts +20 -6
- package/src/cli/ui.ts +8 -4
- package/src/container/shared.ts +18 -0
- package/src/container/start.ts +1 -1
- package/src/doctor/checks.ts +145 -2
- package/src/hostd/client.ts +48 -52
- package/src/hostd/daemon.ts +82 -39
- package/src/hostd/paths.ts +22 -2
- package/src/hostd/spawn.ts +7 -0
- package/src/hostd/tailscale.ts +12 -1
- package/src/init/index.ts +35 -8
- package/src/init/kakaotalk-auth.ts +2 -2
- package/src/init/packagejson.ts +2 -2
- package/src/init/run-bun-install.ts +71 -37
- package/src/inspect/transcript-view.ts +15 -2
- package/src/plugin/loader.ts +7 -4
- package/src/portbroker/hostd-client.ts +32 -6
- package/src/sandbox/session-tmp.ts +6 -1
- package/src/secrets/export-claude-credentials-file.ts +2 -2
- package/src/shared/index.ts +4 -0
- package/src/shared/platform.ts +11 -0
- package/src/shared/wsl.ts +139 -0
- package/src/tui/index.ts +26 -8
- package/src/tui/terminal-guard.ts +139 -0
- package/typeclaw.schema.json +2 -2
package/src/tui/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
formatUserPromptHistory,
|
|
24
24
|
withTimestamp,
|
|
25
25
|
} from './format'
|
|
26
|
+
import { armTerminalGuard } from './terminal-guard'
|
|
26
27
|
import { colors, editorTheme, markdownTheme } from './theme'
|
|
27
28
|
|
|
28
29
|
export type ClientFactory = (url: string) => Promise<Client>
|
|
@@ -103,6 +104,10 @@ export function createTui({
|
|
|
103
104
|
const status = new Text(colors.dim(`connecting to ${displayUrl}...`), 0, 0)
|
|
104
105
|
tui.addChild(status)
|
|
105
106
|
tui.start()
|
|
107
|
+
// Armed once the terminal is in raw mode + Kitty kbd protocol: restores the
|
|
108
|
+
// terminal on an abnormal exit (SSH SIGHUP, kill, crash) that never reaches
|
|
109
|
+
// tui.stop(), so the shell isn't left echoing Kitty key-release events.
|
|
110
|
+
const guard = armTerminalGuard()
|
|
106
111
|
tui.requestRender()
|
|
107
112
|
|
|
108
113
|
// Pre-handshake failures resolve 'connectFailed' (not throw): the standalone
|
|
@@ -113,6 +118,7 @@ export function createTui({
|
|
|
113
118
|
status.setText(colors.red(`connection error: ${err instanceof Error ? err.message : String(err)}`))
|
|
114
119
|
tui.requestRender()
|
|
115
120
|
tui.stop()
|
|
121
|
+
guard.disarm()
|
|
116
122
|
exit(1)
|
|
117
123
|
return null
|
|
118
124
|
})
|
|
@@ -124,6 +130,7 @@ export function createTui({
|
|
|
124
130
|
tui.requestRender()
|
|
125
131
|
client.close()
|
|
126
132
|
tui.stop()
|
|
133
|
+
guard.disarm()
|
|
127
134
|
exit(1)
|
|
128
135
|
return null
|
|
129
136
|
})
|
|
@@ -418,21 +425,32 @@ export function createTui({
|
|
|
418
425
|
// Settle BEFORE closing the client: client.close() fires onClose, which
|
|
419
426
|
// settles 'lostConnection'. settle() is idempotent, so the first call wins —
|
|
420
427
|
// settling the deliberate outcome first keeps the later onClose a no-op.
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
428
|
+
// drainInput() runs before stop() so late Kitty key-release bytes (the keys
|
|
429
|
+
// that triggered the exit) are swallowed instead of leaking to the shell
|
|
430
|
+
// over a slow SSH link. The promise is memoized so repeated callers (a
|
|
431
|
+
// fire-and-forget detach/exit plus the end-of-run await) share ONE teardown
|
|
432
|
+
// and the end-of-run await truly blocks until draining finishes — otherwise
|
|
433
|
+
// the next clack picker could start reading stdin mid-drain.
|
|
434
|
+
let teardownPromise: Promise<void> | null = null
|
|
435
|
+
const teardown = (): Promise<void> => {
|
|
436
|
+
teardownPromise ??= (async () => {
|
|
437
|
+
stopAllLoaders()
|
|
438
|
+
await terminal.drainInput().catch(() => {})
|
|
439
|
+
tui.stop()
|
|
440
|
+
client.close()
|
|
441
|
+
guard.disarm()
|
|
442
|
+
})()
|
|
443
|
+
return teardownPromise
|
|
425
444
|
}
|
|
426
445
|
|
|
427
446
|
const exitWith = (code: number): void => {
|
|
428
447
|
settle({ reason: 'exit', exitCode: code })
|
|
429
|
-
teardown()
|
|
430
|
-
exit(code)
|
|
448
|
+
void teardown().finally(() => exit(code))
|
|
431
449
|
}
|
|
432
450
|
|
|
433
451
|
const detach = (): void => {
|
|
434
452
|
settle({ reason: 'detach' })
|
|
435
|
-
teardown()
|
|
453
|
+
void teardown()
|
|
436
454
|
}
|
|
437
455
|
|
|
438
456
|
// Ctrl+C exits the client. In raw mode the kernel does NOT generate SIGINT,
|
|
@@ -490,7 +508,7 @@ export function createTui({
|
|
|
490
508
|
}
|
|
491
509
|
|
|
492
510
|
const result = await outcome
|
|
493
|
-
|
|
511
|
+
await teardown()
|
|
494
512
|
return result
|
|
495
513
|
}
|
|
496
514
|
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { writeSync } from 'node:fs'
|
|
2
|
+
|
|
3
|
+
// Mirrors pi-tui ProcessTerminal.stop()'s resets so an abnormal exit (SSH
|
|
4
|
+
// SIGHUP, a frozen TUI the user kills, a crash, or a Bun process.exit() that
|
|
5
|
+
// drops pi-tui's buffered stop() writes) can't leave the parent shell with the
|
|
6
|
+
// Kitty keyboard protocol still on. While on, the terminal emits CSI-u
|
|
7
|
+
// key-RELEASE events (`;1:3u`) for every keystroke, corrupting the shell. Order
|
|
8
|
+
// matches stop(): pop Kitty kbd protocol, disable xterm modifyOtherKeys, disable
|
|
9
|
+
// bracketed paste, end synchronized output, show cursor.
|
|
10
|
+
export const RESTORE_SEQUENCE = '\x1b[<u\x1b[>4;0m\x1b[?2004l\x1b[?2026l\x1b[?25h'
|
|
11
|
+
|
|
12
|
+
const STDOUT_FD = 1
|
|
13
|
+
|
|
14
|
+
const SCOPED_SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP'] as const
|
|
15
|
+
export type ScopedSignal = (typeof SCOPED_SIGNALS)[number]
|
|
16
|
+
|
|
17
|
+
const SIGNAL_EXIT_CODE: Record<ScopedSignal, number> = {
|
|
18
|
+
SIGINT: 130,
|
|
19
|
+
SIGTERM: 143,
|
|
20
|
+
SIGHUP: 129,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type TerminalGuardDeps = {
|
|
24
|
+
isTty: boolean
|
|
25
|
+
writeStdout: (seq: string) => void
|
|
26
|
+
setRawMode: (mode: boolean) => void
|
|
27
|
+
on: (event: string, handler: (...args: unknown[]) => void) => void
|
|
28
|
+
off: (event: string, handler: (...args: unknown[]) => void) => void
|
|
29
|
+
killSelf: (signal: ScopedSignal) => void
|
|
30
|
+
exit: (code: number) => void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type TerminalGuard = {
|
|
34
|
+
arm: () => void
|
|
35
|
+
disarm: () => void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function createTerminalGuard(deps: TerminalGuardDeps): TerminalGuard {
|
|
39
|
+
let armed = 0
|
|
40
|
+
let exitInstalled = false
|
|
41
|
+
let signalHandlers: Map<ScopedSignal, (...args: unknown[]) => void> | null = null
|
|
42
|
+
|
|
43
|
+
const restore = (): void => {
|
|
44
|
+
if (!deps.isTty) return
|
|
45
|
+
deps.writeStdout(RESTORE_SEQUENCE)
|
|
46
|
+
deps.setRawMode(false)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const onExit = (): void => {
|
|
50
|
+
restore()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const installSignalHandlers = (): void => {
|
|
54
|
+
if (signalHandlers !== null) return
|
|
55
|
+
const handlers = new Map<ScopedSignal, (...args: unknown[]) => void>()
|
|
56
|
+
for (const sig of SCOPED_SIGNALS) {
|
|
57
|
+
const handler = (): void => {
|
|
58
|
+
// Restore the terminal, then let the signal terminate with default
|
|
59
|
+
// semantics. Remove our handlers first so the re-raised signal isn't
|
|
60
|
+
// swallowed by this same handler; fall back to an explicit exit if the
|
|
61
|
+
// re-raise somehow doesn't terminate.
|
|
62
|
+
removeSignalHandlers()
|
|
63
|
+
restore()
|
|
64
|
+
deps.killSelf(sig)
|
|
65
|
+
deps.exit(SIGNAL_EXIT_CODE[sig])
|
|
66
|
+
}
|
|
67
|
+
deps.on(sig, handler)
|
|
68
|
+
handlers.set(sig, handler)
|
|
69
|
+
}
|
|
70
|
+
signalHandlers = handlers
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const removeSignalHandlers = (): void => {
|
|
74
|
+
if (signalHandlers === null) return
|
|
75
|
+
for (const [sig, handler] of signalHandlers) deps.off(sig, handler)
|
|
76
|
+
signalHandlers = null
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
arm: () => {
|
|
81
|
+
// A non-TTY process (piped/redirected, or the test runner) has no terminal
|
|
82
|
+
// state to protect, so the guard stays fully inert — it never touches the
|
|
83
|
+
// real process signal/exit handlers.
|
|
84
|
+
if (!deps.isTty) return
|
|
85
|
+
armed += 1
|
|
86
|
+
if (!exitInstalled) {
|
|
87
|
+
deps.on('exit', onExit)
|
|
88
|
+
exitInstalled = true
|
|
89
|
+
}
|
|
90
|
+
installSignalHandlers()
|
|
91
|
+
},
|
|
92
|
+
disarm: () => {
|
|
93
|
+
if (!deps.isTty) return
|
|
94
|
+
if (armed > 0) armed -= 1
|
|
95
|
+
if (armed === 0) removeSignalHandlers()
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let defaultGuard: TerminalGuard | null = null
|
|
101
|
+
|
|
102
|
+
function getDefaultGuard(): TerminalGuard {
|
|
103
|
+
defaultGuard ??= createTerminalGuard({
|
|
104
|
+
isTty: Boolean(process.stdout.isTTY),
|
|
105
|
+
writeStdout: (seq) => {
|
|
106
|
+
try {
|
|
107
|
+
writeSync(STDOUT_FD, seq)
|
|
108
|
+
} catch {
|
|
109
|
+
/* fd closed mid-teardown */
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
setRawMode: (mode) => {
|
|
113
|
+
try {
|
|
114
|
+
process.stdin.setRawMode?.(mode)
|
|
115
|
+
} catch {
|
|
116
|
+
/* terminal already torn down */
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
on: (event, handler) => {
|
|
120
|
+
process.on(event as NodeJS.Signals, handler)
|
|
121
|
+
},
|
|
122
|
+
off: (event, handler) => {
|
|
123
|
+
process.off(event as NodeJS.Signals, handler)
|
|
124
|
+
},
|
|
125
|
+
killSelf: (signal) => {
|
|
126
|
+
process.kill(process.pid, signal)
|
|
127
|
+
},
|
|
128
|
+
exit: (code) => {
|
|
129
|
+
process.exit(code)
|
|
130
|
+
},
|
|
131
|
+
})
|
|
132
|
+
return defaultGuard
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function armTerminalGuard(): TerminalGuard {
|
|
136
|
+
const guard = getDefaultGuard()
|
|
137
|
+
guard.arm()
|
|
138
|
+
return guard
|
|
139
|
+
}
|
package/typeclaw.schema.json
CHANGED
|
@@ -1669,7 +1669,7 @@
|
|
|
1669
1669
|
"default": {
|
|
1670
1670
|
"enabled": true,
|
|
1671
1671
|
"imageMaxBytes": 262144,
|
|
1672
|
-
"textMaxBytes":
|
|
1672
|
+
"textMaxBytes": 32768,
|
|
1673
1673
|
"exemptTools": []
|
|
1674
1674
|
},
|
|
1675
1675
|
"type": "object",
|
|
@@ -1685,7 +1685,7 @@
|
|
|
1685
1685
|
"maximum": 9007199254740991
|
|
1686
1686
|
},
|
|
1687
1687
|
"textMaxBytes": {
|
|
1688
|
-
"default":
|
|
1688
|
+
"default": 32768,
|
|
1689
1689
|
"type": "integer",
|
|
1690
1690
|
"minimum": 1024,
|
|
1691
1691
|
"maximum": 9007199254740991
|