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.
Files changed (42) hide show
  1. package/README.md +2 -1
  2. package/package.json +1 -1
  3. package/src/agent/git-nudge.ts +4 -12
  4. package/src/agent/session-origin.ts +8 -6
  5. package/src/agent/tools/channel-reply.ts +13 -13
  6. package/src/agent/tools/channel-send.ts +3 -3
  7. package/src/bundled-plugins/guard/policies/uncommitted-changes.ts +4 -11
  8. package/src/bundled-plugins/memory/dreaming.ts +28 -67
  9. package/src/bundled-plugins/memory/load-shards.ts +31 -3
  10. package/src/bundled-plugins/memory/memory-logger.ts +2 -1
  11. package/src/bundled-plugins/memory/memory-snapshot.ts +8 -0
  12. package/src/bundled-plugins/memory/vector/embedder.ts +28 -9
  13. package/src/bundled-plugins/security/policies/git-exfil.ts +45 -27
  14. package/src/channels/adapters/telegram-bot-classify.ts +29 -0
  15. package/src/channels/continuation-willingness.ts +2 -2
  16. package/src/channels/github-false-receipt.ts +4 -4
  17. package/src/channels/github-rereview-guard.ts +8 -8
  18. package/src/channels/router.ts +276 -58
  19. package/src/channels/types.ts +7 -0
  20. package/src/cli/command-meta.ts +2 -0
  21. package/src/cli/compose-stats.ts +103 -0
  22. package/src/cli/compose.ts +13 -0
  23. package/src/cli/index.ts +1 -0
  24. package/src/cli/stats.ts +134 -0
  25. package/src/compose/index.ts +1 -0
  26. package/src/compose/stats.ts +51 -0
  27. package/src/config/config.ts +14 -0
  28. package/src/config/index.ts +4 -0
  29. package/src/container/controller.ts +6 -0
  30. package/src/container/index.ts +1 -0
  31. package/src/container/log-archive.ts +448 -0
  32. package/src/container/shared.ts +30 -13
  33. package/src/container/start.ts +78 -63
  34. package/src/container/stats.ts +86 -0
  35. package/src/container/stop.ts +63 -36
  36. package/src/git/run.ts +60 -0
  37. package/src/init/restart-deps-preflight.ts +2 -2
  38. package/src/run/index.ts +5 -0
  39. package/src/run/resource-report.ts +226 -0
  40. package/src/sandbox/canonical-secrets.ts +1 -0
  41. package/src/skills/typeclaw-channel-github/SKILL.md +4 -4
  42. 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 actual audience-leak surface for `git push` lives in
8
- // `gitRemoteTainted`, not here. A `git push` to a CLEAN, operator-configured
9
- // remote is not audience-leak — the audience (the remote git host) was
10
- // chosen by the operator and is inside their perimeter. The breach pattern
11
- // PR #134 was written for (re-point origin to attacker URL, then push) is
12
- // gated by `gitRemoteTainted` (still high). The recorder-vs-checker split
13
- // is what makes this reclassification safe: the recorder fires for any
14
- // actor who can run a `git remote set-url` (per-guard bypass OR the
15
- // medium-tier permission via the OR check), so trusted's first-step
16
- // set-url still records taint and the second-step push still gets caught
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): the actual audience-leak gate
23
- // for git. A push after a mid-session `git remote set-url` to an
24
- // attacker-controlled URL is exactly the breach pattern that motivated
25
- // the entire security plugin per PR #134. Stays high regardless of how
26
- // `gitExfil` is classified — the two are independent per-guard strings
27
- // AND independent tier classifications. The recorder-vs-checker split
28
- // (see comment on recordGitRemoteTaintIfAny below) is still load-bearing:
29
- // the recorder fires for anyone who can run the underlying `set-url`
30
- // command (ack, per-guard `bypassGitExfil`, OR the medium-tier permission
31
- // — which now includes trusted by default), so the second-step taint
32
- // check still fires on the eventual push.
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 bash command that looks like agent-folder exfiltration: ${matched.label}.`,
189
- // kept: pre-migration agents may still have a root MEMORY.md.
190
- 'Pushing a repo, adding a remote, or piping a remote payload to a shell can leak identity files (MEMORY.md, IDENTITY.md, SOUL.md, AGENTS.md) and embedded secrets to attacker-controlled infrastructure - including via prompt-injected requests from chat channels.',
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({ continue: true })`, the turn aborts and the promised
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 `continue: true` (the cron-update production miss).
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
- isContinue: boolean
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 (continue:true) is not yet a receipt
36
- // — the real action may still be coming. Never block; nudge instead.
37
- if (input.isContinue) return { kind: 'warn', notice: SOFT_NOTICE }
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 (continue:true) is not the turn's receipt, so it
21
- // suppresses the warn-tier escalation below — but never the explicit resolve,
22
- // which is a real mutation. Mirrors the false-receipt guard's continue rule.
23
- isContinue: boolean
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. `continue:true` exempts the warn escalation (mid-turn
66
- // planning, not the receipt), but never the explicit resolve action. Plain
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.isContinue && isPositiveWarnCloseout(input.text ?? '')
72
+ return !input.moreWorkThisTurn && isPositiveWarnCloseout(input.text ?? '')
73
73
  }
74
74
 
75
75
  function unverifiableReason(error: string): string {