typeclaw 0.46.2 → 0.47.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 +2 -1
- package/package.json +1 -1
- package/src/agent/git-nudge.ts +4 -12
- package/src/agent/session-origin.ts +8 -6
- package/src/agent/tools/channel-reply.ts +13 -13
- package/src/agent/tools/channel-send.ts +3 -3
- package/src/bundled-plugins/guard/policies/uncommitted-changes.ts +4 -11
- package/src/bundled-plugins/memory/dreaming.ts +28 -67
- package/src/bundled-plugins/memory/load-shards.ts +31 -3
- package/src/bundled-plugins/memory/memory-logger.ts +2 -1
- package/src/bundled-plugins/memory/memory-snapshot.ts +8 -0
- package/src/bundled-plugins/memory/vector/embedder.ts +28 -9
- package/src/bundled-plugins/security/policies/git-exfil.ts +45 -27
- package/src/channels/adapters/telegram-bot-classify.ts +29 -0
- package/src/channels/continuation-willingness.ts +2 -2
- package/src/channels/github-false-receipt.ts +4 -4
- package/src/channels/github-rereview-guard.ts +8 -8
- package/src/channels/router.ts +276 -58
- package/src/channels/types.ts +7 -0
- package/src/cli/command-meta.ts +2 -0
- package/src/cli/compose-stats.ts +103 -0
- package/src/cli/compose.ts +13 -0
- package/src/cli/index.ts +1 -0
- package/src/cli/stats.ts +134 -0
- package/src/compose/index.ts +1 -0
- package/src/compose/stats.ts +51 -0
- package/src/config/config.ts +14 -0
- package/src/config/index.ts +4 -0
- package/src/container/controller.ts +6 -0
- package/src/container/index.ts +1 -0
- package/src/container/log-archive.ts +448 -0
- package/src/container/shared.ts +30 -13
- package/src/container/start.ts +78 -63
- package/src/container/stats.ts +86 -0
- package/src/container/stop.ts +63 -36
- package/src/git/run.ts +60 -0
- package/src/init/restart-deps-preflight.ts +2 -2
- package/src/run/index.ts +5 -0
- package/src/run/resource-report.ts +226 -0
- package/src/sandbox/canonical-secrets.ts +1 -0
- package/src/skills/typeclaw-channel-github/SKILL.md +4 -4
- package/typeclaw.schema.json +14 -0
|
@@ -3,33 +3,43 @@ import { ACKNOWLEDGE_GUARDS, type SecurityBlock, isGuardAcknowledged } from '../
|
|
|
3
3
|
import { getRemoteTaint, recordRemoteTaint } from './remote-taint-state'
|
|
4
4
|
|
|
5
5
|
export const GUARD_GIT_EXFIL = 'gitExfil'
|
|
6
|
+
// The coarse, role-gated first-line publication/file-transfer gate. It matches
|
|
7
|
+
// the command STRING only (see checkGitExfilGuard); it has no working
|
|
8
|
+
// directory, no resolved git repository identity, and no view of a checkout's
|
|
9
|
+
// content provenance. It therefore fires regardless of where the command runs
|
|
10
|
+
// — a `/tmp` clone is NOT a trusted boundary, because an earlier turn may have
|
|
11
|
+
// copied identity files or secrets into it, and the effective repository is
|
|
12
|
+
// unknowable from the string alone (`git -C`, `--git-dir`, `GIT_DIR`, `cd`,
|
|
13
|
+
// subshells, aliases). Do NOT re-introduce cwd/path scoping here: it would be
|
|
14
|
+
// a bypass, not a fix (Oracle-reviewed). Member-tier publishing, if ever
|
|
15
|
+
// required, belongs in a separate out-of-band capability, not a path heuristic.
|
|
16
|
+
//
|
|
6
17
|
// Classified `medium` (silent-attack axis). Originally `high`; reclassified
|
|
7
|
-
// because the
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
// by `gitRemoteTainted` even though trusted no longer needs to ack the
|
|
18
|
-
// push itself. Net effect: trusted users can push to remotes the operator
|
|
19
|
-
// configured without per-call acks, but cannot retarget-and-push.
|
|
18
|
+
// because the one narrow retarget-then-push audience-leak shape (re-point
|
|
19
|
+
// origin to an attacker URL, then push) is gated separately by
|
|
20
|
+
// `gitRemoteTainted` (still high). The recorder-vs-checker split is what makes
|
|
21
|
+
// that reclassification safe: the recorder fires for any actor who can run a
|
|
22
|
+
// `git remote set-url` (per-guard bypass OR the medium-tier permission via the
|
|
23
|
+
// OR check), so trusted's first-step set-url still records taint and the
|
|
24
|
+
// second-step push still gets caught by `gitRemoteTainted` even though trusted
|
|
25
|
+
// no longer needs to ack the push itself. Net effect: trusted users can push
|
|
26
|
+
// to remotes the operator configured without per-call acks, but cannot
|
|
27
|
+
// retarget-and-push.
|
|
20
28
|
export const GUARD_GIT_EXFIL_SEVERITY: SecuritySeverity = 'medium'
|
|
21
29
|
export const GUARD_GIT_REMOTE_TAINTED = 'gitRemoteTainted'
|
|
22
|
-
// Classified `high` (audience-leak axis)
|
|
23
|
-
// for git
|
|
24
|
-
//
|
|
25
|
-
// the
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
30
|
+
// Classified `high` (audience-leak axis). This is NOT the complete audience-
|
|
31
|
+
// leak defense for git — it gates ONE specific two-step shape: a push to a
|
|
32
|
+
// remote whose URL was changed mid-session (the breach pattern that motivated
|
|
33
|
+
// the security plugin per PR #134). Its state is keyed by session + remote
|
|
34
|
+
// name, so it does not cover pushes to an initially-malicious remote, direct
|
|
35
|
+
// URL pushes, or destinations established outside its session recorder — those
|
|
36
|
+
// stay under the coarse `gitExfil` gate above. Stays high regardless of how
|
|
37
|
+
// `gitExfil` is classified — the two are independent per-guard strings AND
|
|
38
|
+
// independent tier classifications. The recorder-vs-checker split (see comment
|
|
39
|
+
// on recordGitRemoteTaintIfAny below) is still load-bearing: the recorder
|
|
40
|
+
// fires for anyone who can run the underlying `set-url` command (ack, per-guard
|
|
41
|
+
// `bypassGitExfil`, OR the medium-tier permission — which now includes trusted
|
|
42
|
+
// by default), so the second-step taint check still fires on the eventual push.
|
|
33
43
|
export const GUARD_GIT_REMOTE_TAINTED_SEVERITY: SecuritySeverity = 'high'
|
|
34
44
|
|
|
35
45
|
// Anchors we reuse: a `git` token must be at start-of-line or follow a shell
|
|
@@ -185,9 +195,17 @@ export function checkGitExfilGuard(options: {
|
|
|
185
195
|
return {
|
|
186
196
|
block: true,
|
|
187
197
|
reason: [
|
|
188
|
-
`Guard \`${GUARD_GIT_EXFIL}\` blocked
|
|
189
|
-
//
|
|
190
|
-
|
|
198
|
+
`Guard \`${GUARD_GIT_EXFIL}\` blocked a risky repository-publication or file-transfer command: ${matched.label}.`,
|
|
199
|
+
// Deliberately directory-INDEPENDENT: the guard sees only the command
|
|
200
|
+
// string and cannot prove which repository git will operate on, nor that
|
|
201
|
+
// an external checkout (e.g. a /tmp clone) does not already contain data
|
|
202
|
+
// copied out of the agent folder. A "clean" path is not a security
|
|
203
|
+
// boundary, so this fires wherever the command runs. Pushing a repo,
|
|
204
|
+
// adding/re-pointing a remote, or piping a remote payload to a shell can
|
|
205
|
+
// publish identity files (MEMORY.md, IDENTITY.md, SOUL.md, AGENTS.md) and
|
|
206
|
+
// embedded secrets - including via prompt-injected requests from chat
|
|
207
|
+
// channels.
|
|
208
|
+
'This applies regardless of working directory.',
|
|
191
209
|
`If this is genuinely intentional and the user (not a channel message) explicitly asked for it, retry with \`${ACKNOWLEDGE_GUARDS}.${GUARD_GIT_EXFIL}: true\` in the bash arguments.`,
|
|
192
210
|
].join(' '),
|
|
193
211
|
}
|
|
@@ -62,6 +62,8 @@ export function classifyInbound(
|
|
|
62
62
|
|
|
63
63
|
const thread = event.message_thread_id !== undefined ? String(event.message_thread_id) : null
|
|
64
64
|
|
|
65
|
+
const isBotMentionOnly = attachments.length === 0 && isOnlyBotMention(entities, fullText, bot.id, botUsername)
|
|
66
|
+
|
|
65
67
|
return {
|
|
66
68
|
kind: 'route',
|
|
67
69
|
payload: {
|
|
@@ -76,6 +78,7 @@ export function classifyInbound(
|
|
|
76
78
|
authorName: formatAuthorName(author),
|
|
77
79
|
authorIsBot: author.is_bot === true,
|
|
78
80
|
isBotMention,
|
|
81
|
+
isBotMentionOnly,
|
|
79
82
|
replyToBotMessageId,
|
|
80
83
|
mentionsOthers,
|
|
81
84
|
replyToOtherMessageId,
|
|
@@ -85,6 +88,32 @@ export function classifyInbound(
|
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
|
|
91
|
+
// A "bare ping" is a message whose entire body (ignoring surrounding
|
|
92
|
+
// whitespace) is a SINGLE mention of the bot. The router cannot detect this
|
|
93
|
+
// from `text` because a `text_mention` renders as the target's display name,
|
|
94
|
+
// not `<@id>` markup, so the adapter must decide it here where the structured
|
|
95
|
+
// entities are still available. Offsets are UTF-16 code units in both Telegram
|
|
96
|
+
// entities and JS strings, so slicing lines up. Multiple mentions, any extra
|
|
97
|
+
// words, or a mention that does not span the whole trimmed text are not bare.
|
|
98
|
+
function isOnlyBotMention(
|
|
99
|
+
entities: readonly TelegramMessageEntity[],
|
|
100
|
+
fullText: string,
|
|
101
|
+
botId: number,
|
|
102
|
+
botUsername: string | undefined,
|
|
103
|
+
): boolean {
|
|
104
|
+
const userMentions = entities.filter(isUserMentionEntity)
|
|
105
|
+
if (userMentions.length !== 1) return false
|
|
106
|
+
const entity = userMentions[0]!
|
|
107
|
+
const start = fullText.length - fullText.trimStart().length
|
|
108
|
+
const end = fullText.trimEnd().length
|
|
109
|
+
return (
|
|
110
|
+
start < end &&
|
|
111
|
+
entity.offset === start &&
|
|
112
|
+
entity.offset + entity.length === end &&
|
|
113
|
+
isUserMentionForBot(entity, fullText, botId, botUsername)
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
88
117
|
function formatAuthorName(user: TelegramBotUser): string {
|
|
89
118
|
if (user.username !== undefined && user.username !== '') return user.username
|
|
90
119
|
const last = user.last_name ?? ''
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// A channel turn ends after a successful `channel_reply` (the terminal-reply
|
|
2
2
|
// abort in router.ts). When the model's reply PROMISES to keep working this
|
|
3
3
|
// turn ("바로 확인해볼게요", "let me check", "I'll continue now") but it forgot
|
|
4
|
-
// to set `channel_reply({
|
|
4
|
+
// to set `channel_reply({ more_work_this_turn: true })`, the turn aborts and the promised
|
|
5
5
|
// follow-up never runs. The router uses this detector to inject ONE bounded
|
|
6
6
|
// reminder nudge so the model gets a second chance. See the empty-turn retry
|
|
7
7
|
// (router.ts) for the sibling mechanism this mirrors.
|
|
@@ -73,7 +73,7 @@ const EN_PHRASES: readonly string[] = [
|
|
|
73
73
|
// Action/config verb family. The retrieval verbs above ("check/look/look up")
|
|
74
74
|
// miss the much larger class of "I'll DO X" promises — update/configure/set up/
|
|
75
75
|
// schedule/fix/apply/create — which is exactly the class that silently truncates
|
|
76
|
-
// when the model forgets `
|
|
76
|
+
// when the model forgets `more_work_this_turn: true` (the cron-update production miss).
|
|
77
77
|
"i'll update",
|
|
78
78
|
"i'll set up",
|
|
79
79
|
"i'll set it up",
|
|
@@ -19,7 +19,7 @@ export type FalseReceiptInput = {
|
|
|
19
19
|
chat: string
|
|
20
20
|
thread: string | null
|
|
21
21
|
text: string | undefined
|
|
22
|
-
|
|
22
|
+
moreWorkThisTurn: boolean
|
|
23
23
|
resolveReviewThread: boolean
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -32,9 +32,9 @@ export function checkFalseReceipt(input: FalseReceiptInput): FalseReceiptDecisio
|
|
|
32
32
|
if (claim === 'ignore') return { kind: 'allow' }
|
|
33
33
|
if (claim === 'warn') return { kind: 'warn', notice: SOFT_NOTICE }
|
|
34
34
|
|
|
35
|
-
// A turn the agent explicitly keeps alive (
|
|
36
|
-
// — the real action may still be coming. Never block; nudge instead.
|
|
37
|
-
if (input.
|
|
35
|
+
// A turn the agent explicitly keeps alive (more_work_this_turn:true) is not yet
|
|
36
|
+
// a receipt — the real action may still be coming. Never block; nudge instead.
|
|
37
|
+
if (input.moreWorkThisTurn) return { kind: 'warn', notice: SOFT_NOTICE }
|
|
38
38
|
|
|
39
39
|
if (claim === 'block-resolve') {
|
|
40
40
|
if (input.thread === null) return { kind: 'allow' }
|
|
@@ -17,10 +17,10 @@ export type RereviewGuardInput = {
|
|
|
17
17
|
thread: string | null
|
|
18
18
|
text: string | undefined
|
|
19
19
|
wantsResolve: boolean
|
|
20
|
-
// A mid-turn status reply (
|
|
21
|
-
// suppresses the warn-tier escalation below — but never the explicit
|
|
22
|
-
// which is a real mutation. Mirrors the false-receipt guard's
|
|
23
|
-
|
|
20
|
+
// A mid-turn status reply (more_work_this_turn:true) is not the turn's receipt,
|
|
21
|
+
// so it suppresses the warn-tier escalation below — but never the explicit
|
|
22
|
+
// resolve, which is a real mutation. Mirrors the false-receipt guard's rule.
|
|
23
|
+
moreWorkThisTurn: boolean
|
|
24
24
|
getReviewState: (req: { adapter: 'github'; workspace: string; chat: string }) => Promise<ReviewStateResult>
|
|
25
25
|
workspace: string
|
|
26
26
|
}
|
|
@@ -62,14 +62,14 @@ export async function evaluateRereviewGuard(input: RereviewGuardInput): Promise<
|
|
|
62
62
|
// live CHANGES_REQUESTED, so casual approval-shaped chatter on an unblocked PR
|
|
63
63
|
// still posts. Only POSITIVE warn phrases escalate — negative ones ("needs
|
|
64
64
|
// changes", "still needs work") re-assert a block rather than strand it, so they
|
|
65
|
-
// stay non-firing. `
|
|
66
|
-
// planning, not the receipt), but never the explicit resolve action.
|
|
67
|
-
// `ignore` text never fires.
|
|
65
|
+
// stay non-firing. `more_work_this_turn:true` exempts the warn escalation
|
|
66
|
+
// (mid-turn planning, not the receipt), but never the explicit resolve action.
|
|
67
|
+
// Plain `ignore` text never fires.
|
|
68
68
|
function isCloseoutAttempt(input: RereviewGuardInput): boolean {
|
|
69
69
|
if (input.wantsResolve && input.thread !== null) return true
|
|
70
70
|
const claim = classifyReviewClaim(input.text ?? '')
|
|
71
71
|
if (claim === 'block-resolve' || claim === 'block-approve') return true
|
|
72
|
-
return !input.
|
|
72
|
+
return !input.moreWorkThisTurn && isPositiveWarnCloseout(input.text ?? '')
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function unverifiableReason(error: string): string {
|