typeclaw 0.45.0 → 0.46.0

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 (147) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -2
  3. package/src/agent/git-nudge.ts +2 -1
  4. package/src/agent/index.ts +67 -25
  5. package/src/agent/live-subagents.ts +18 -0
  6. package/src/agent/loop-guard.ts +208 -10
  7. package/src/agent/multimodal/index.ts +1 -1
  8. package/src/agent/multimodal/look-at.ts +78 -44
  9. package/src/agent/multimodal/looker.ts +151 -39
  10. package/src/agent/network/response-body.ts +26 -0
  11. package/src/agent/network/safe-http.ts +198 -0
  12. package/src/agent/plugin-tools.ts +438 -162
  13. package/src/agent/provider-error.ts +62 -4
  14. package/src/agent/restart/index.ts +61 -40
  15. package/src/agent/restart-handoff/index.ts +73 -4
  16. package/src/agent/retry-same-ref.ts +66 -0
  17. package/src/agent/reviewer-bash-policy.ts +42 -1
  18. package/src/agent/session-origin.ts +2 -0
  19. package/src/agent/subagent-drain.ts +117 -7
  20. package/src/agent/subagents.ts +77 -18
  21. package/src/agent/throttle-circuit.ts +25 -5
  22. package/src/agent/tool-error-remediation.ts +72 -0
  23. package/src/agent/tool-file-safety.ts +1050 -0
  24. package/src/agent/tools/channel-fetch-attachment.ts +10 -3
  25. package/src/agent/tools/channel-reply.ts +15 -1
  26. package/src/agent/tools/channel-send.ts +17 -1
  27. package/src/agent/tools/ddg.ts +16 -2
  28. package/src/agent/tools/post-github-review.ts +199 -0
  29. package/src/agent/tools/spawn-subagent.ts +21 -18
  30. package/src/agent/tools/webfetch/fetch.ts +143 -183
  31. package/src/agent/tools/webfetch/tool.ts +2 -3
  32. package/src/agent/tools/websearch.ts +23 -2
  33. package/src/agent/tools-without-local-file-operands.ts +27 -0
  34. package/src/agent/turn-runner.ts +109 -15
  35. package/src/bundled-plugins/backup/index.ts +2 -1
  36. package/src/bundled-plugins/backup/runner.ts +2 -1
  37. package/src/bundled-plugins/doc-render/render.ts +93 -12
  38. package/src/bundled-plugins/doc-render/skills/typeclaw-render-pdf/SKILL.md +13 -13
  39. package/src/bundled-plugins/github-cli-auth/effective-approval.ts +16 -6
  40. package/src/bundled-plugins/github-cli-auth/gh-command.ts +555 -15
  41. package/src/bundled-plugins/github-cli-auth/index.ts +131 -135
  42. package/src/bundled-plugins/github-cli-auth/review-checkout.ts +138 -0
  43. package/src/bundled-plugins/guard/policies/uncommitted-changes.ts +2 -1
  44. package/src/bundled-plugins/memory/README.md +23 -11
  45. package/src/bundled-plugins/memory/append-tool.ts +15 -8
  46. package/src/bundled-plugins/memory/citations.ts +22 -9
  47. package/src/bundled-plugins/memory/dreaming.ts +13 -8
  48. package/src/bundled-plugins/memory/find-entry-tool.ts +4 -0
  49. package/src/bundled-plugins/memory/index.ts +0 -4
  50. package/src/bundled-plugins/memory/load-memory.ts +8 -3
  51. package/src/bundled-plugins/memory/provenance-index.ts +717 -0
  52. package/src/bundled-plugins/memory/provenance-sanitize.ts +40 -0
  53. package/src/bundled-plugins/memory/references/store-reference-tool.ts +4 -0
  54. package/src/bundled-plugins/memory/search-tool.ts +163 -60
  55. package/src/bundled-plugins/memory/stream-events.ts +2 -0
  56. package/src/bundled-plugins/memory/vector/hybrid.ts +126 -13
  57. package/src/bundled-plugins/researcher/write-report.ts +6 -3
  58. package/src/bundled-plugins/reviewer/index.ts +2 -2
  59. package/src/bundled-plugins/reviewer/reviewer.ts +10 -3
  60. package/src/bundled-plugins/reviewer/skills/code-review.ts +24 -9
  61. package/src/bundled-plugins/scout/scout.ts +8 -0
  62. package/src/bundled-plugins/security/index.ts +4 -4
  63. package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +1 -0
  64. package/src/bundled-plugins/security/policies/private-surface-read.ts +220 -29
  65. package/src/bundled-plugins/security/policies/secret-exfil-read.ts +1 -0
  66. package/src/bundled-plugins/security/policies/ssrf.ts +29 -9
  67. package/src/channels/adapters/discord-bot-channel-resolver.ts +26 -14
  68. package/src/channels/adapters/discord-bot-thread-room.ts +44 -12
  69. package/src/channels/adapters/discord-bot.ts +91 -10
  70. package/src/channels/adapters/discord-channel-resolver.ts +91 -23
  71. package/src/channels/adapters/discord-id.ts +4 -0
  72. package/src/channels/adapters/discord-resolver-cache.ts +41 -0
  73. package/src/channels/adapters/discord.ts +57 -7
  74. package/src/channels/adapters/github/auth-app.ts +41 -12
  75. package/src/channels/adapters/github/index.ts +23 -11
  76. package/src/channels/adapters/github/review-submitter.ts +302 -0
  77. package/src/channels/adapters/kakaotalk-channel-resolver.ts +12 -1
  78. package/src/channels/adapters/kakaotalk-fetch-attachment.ts +8 -4
  79. package/src/channels/adapters/kakaotalk-typing.ts +127 -0
  80. package/src/channels/adapters/kakaotalk.ts +19 -0
  81. package/src/channels/adapters/slack-attachment-download.ts +71 -0
  82. package/src/channels/adapters/slack-bot.ts +19 -8
  83. package/src/channels/adapters/slack-classify.ts +21 -2
  84. package/src/channels/adapters/slack.ts +59 -7
  85. package/src/channels/adapters/telegram-bot.ts +18 -5
  86. package/src/channels/adapters/webex-bot.ts +8 -3
  87. package/src/channels/adapters/webex.ts +8 -3
  88. package/src/channels/fetch-attachment.ts +43 -0
  89. package/src/{bundled-plugins/github-cli-auth/approve-idempotency.ts → channels/github-review-verdict-coordinator.ts} +25 -1
  90. package/src/channels/github-token-bridge.ts +10 -3
  91. package/src/channels/manager.ts +9 -0
  92. package/src/channels/router.ts +568 -12
  93. package/src/channels/types.ts +28 -1
  94. package/src/cli/channel.ts +1 -1
  95. package/src/cli/init.ts +1 -1
  96. package/src/cli/model.ts +57 -7
  97. package/src/compose/stop.ts +17 -5
  98. package/src/config/config.ts +6 -6
  99. package/src/config/models-mutation.ts +13 -1
  100. package/src/config/providers.ts +176 -0
  101. package/src/container/start.ts +49 -10
  102. package/src/doctor/checks.ts +3 -1
  103. package/src/doctor/commit.ts +2 -1
  104. package/src/doctor/file-ownership.ts +52 -0
  105. package/src/dreams/git.ts +2 -1
  106. package/src/git/hookless.ts +5 -0
  107. package/src/git/reconcile-ignored.ts +18 -5
  108. package/src/git/secret-history.ts +371 -0
  109. package/src/git/system-commit.ts +12 -6
  110. package/src/init/dockerfile.ts +86 -5
  111. package/src/init/index.ts +17 -5
  112. package/src/init/models-dev.ts +4 -0
  113. package/src/init/validate-api-key.ts +2 -0
  114. package/src/mcp/tools.ts +16 -3
  115. package/src/permissions/builtins.ts +3 -1
  116. package/src/plugin/context.ts +2 -0
  117. package/src/plugin/index.ts +1 -0
  118. package/src/plugin/manager.ts +4 -0
  119. package/src/plugin/types.ts +21 -0
  120. package/src/run/index.ts +40 -0
  121. package/src/run/llm-fetch-observer.ts +188 -13
  122. package/src/sandbox/build.ts +37 -15
  123. package/src/sandbox/canonical-secrets.ts +18 -0
  124. package/src/sandbox/env-exposure.ts +80 -0
  125. package/src/sandbox/errors.ts +13 -6
  126. package/src/sandbox/hidden-paths.ts +102 -44
  127. package/src/sandbox/index.ts +22 -4
  128. package/src/sandbox/package-install.ts +3 -27
  129. package/src/sandbox/policy.ts +11 -25
  130. package/src/sandbox/privileged-runtime.ts +255 -0
  131. package/src/sandbox/session-tmp.ts +8 -2
  132. package/src/sandbox/writable-zones.ts +204 -140
  133. package/src/secrets/index.ts +8 -0
  134. package/src/secrets/refresh-provider-oauth.ts +128 -0
  135. package/src/server/command-runner.ts +48 -4
  136. package/src/server/index.ts +4 -0
  137. package/src/skills/typeclaw-channel-github/SKILL.md +49 -56
  138. package/src/skills/typeclaw-claude-code/SKILL.md +24 -60
  139. package/src/skills/typeclaw-claude-code/references/auth-flow.md +17 -158
  140. package/src/skills/typeclaw-codex-cli/SKILL.md +19 -49
  141. package/src/skills/typeclaw-codex-cli/references/auth-flow.md +17 -154
  142. package/src/skills/typeclaw-config/SKILL.md +5 -5
  143. package/src/skills/typeclaw-config/references/recommended-mounts.md +24 -24
  144. package/src/skills/typeclaw-github-contributing/SKILL.md +23 -26
  145. package/src/skills/typeclaw-memory/SKILL.md +9 -3
  146. package/src/skills/typeclaw-permissions/SKILL.md +19 -15
  147. package/typeclaw.schema.json +20 -0
@@ -9,6 +9,7 @@ import { formatLocalDate } from '@/shared'
9
9
 
10
10
  import { fragmentContentHash } from './fragment-parser'
11
11
  import { streamFilePath } from './paths'
12
+ import { sanitizeProvenanceName } from './provenance-sanitize'
12
13
  import { detectSecrets } from './secret-detector'
13
14
  import { newEventId, timestampFromId } from './stream-events'
14
15
  import type { FragmentEvent, FragmentProvenance, WatermarkEvent } from './stream-events'
@@ -52,18 +53,16 @@ export function provenanceFromOrigin(origin: SessionOrigin | undefined): Fragmen
52
53
  // so a credential-shaped name is dropped rather than thrown — keep the raw id,
53
54
  // never let the leaky display string reach git. Raw ids are platform-issued
54
55
  // identifiers, not free text, so they are not scanned.
55
- const workspaceName = redactIfSecret(origin.workspaceName)
56
- const chatName = redactIfSecret(origin.chatName)
56
+ const workspaceName = sanitizeProvenanceName(origin.workspaceName)
57
+ const chatName = sanitizeProvenanceName(origin.chatName)
58
+ const parentChatName = sanitizeProvenanceName(origin.parentChatName)
57
59
  if (workspaceName !== undefined) where.workspaceName = workspaceName
58
60
  if (chatName !== undefined) where.chatName = chatName
61
+ if (origin.parentChat !== undefined) where.parentChat = origin.parentChat
62
+ if (parentChatName !== undefined) where.parentChatName = parentChatName
59
63
  return where
60
64
  }
61
65
 
62
- function redactIfSecret(name: string | undefined): string | undefined {
63
- if (name === undefined) return undefined
64
- return detectSecrets(name).length === 0 ? name : undefined
65
- }
66
-
67
66
  export function createAppendTool(options: CreateAppendToolOptions = {}) {
68
67
  const { onFragmentsAppended, originProvider, referenceSlugResolver } = options
69
68
  return defineTool({
@@ -78,6 +77,13 @@ export function createAppendTool(options: CreateAppendToolOptions = {}) {
78
77
  references: z.array(z.string()).optional(),
79
78
  who: z.string().min(1).optional(),
80
79
  }),
80
+ // None of these is a local path — topic/body are prose, the rest are session/
81
+ // entry/reference ids. The runtime chooses the stream filename; the tool never
82
+ // opens a caller path. Declared so a body carrying "/" or a slug/id that
83
+ // collides with an agent-root dir name is not misread as a file operand.
84
+ fileOperands: {
85
+ nonFile: ['topic', 'body', 'source', 'entry', 'latestEntryId', 'references', 'who'],
86
+ },
81
87
  async execute({ topic, body, source, entry, latestEntryId, references, who }, ctx) {
82
88
  const streamPath = dailyStreamPath(ctx.agentDir)
83
89
  const where = provenanceFromOrigin(originProvider?.())
@@ -116,7 +122,8 @@ export function createAppendTool(options: CreateAppendToolOptions = {}) {
116
122
  if (validReferences.length > 0) {
117
123
  fragment.references = validReferences
118
124
  }
119
- if (who !== undefined) fragment.who = who
125
+ const safeWho = sanitizeProvenanceName(who)
126
+ if (safeWho !== undefined) fragment.who = safeWho
120
127
  if (where !== undefined) fragment.where = where
121
128
  const watermark: WatermarkEvent = {
122
129
  type: 'watermark',
@@ -87,9 +87,11 @@ const SECTION_HEADING = /^[\s-]*(fragments|superseded)\s*:\s*$/i
87
87
 
88
88
  export type SectionedCitations = { active: Set<string>; superseded: Set<string> }
89
89
 
90
- export function splitCitationsBySection(body: string): SectionedCitations {
91
- const active = new Set<string>()
92
- const superseded = new Set<string>()
90
+ export type SectionedCitationRefs = { active: Citation[]; superseded: Citation[] }
91
+
92
+ export function splitCitationRefsBySection(body: string): SectionedCitationRefs {
93
+ const active = new Map<string, Citation>()
94
+ const superseded = new Map<string, Citation>()
93
95
  let current: 'active' | 'superseded' = 'active'
94
96
 
95
97
  for (const line of body.split('\n')) {
@@ -98,13 +100,24 @@ export function splitCitationsBySection(body: string): SectionedCitations {
98
100
  current = heading[1]!.toLowerCase() === 'superseded' ? 'superseded' : 'active'
99
101
  continue
100
102
  }
101
- const citation = CITATION_LINE.exec(line)
102
- if (citation === null) continue
103
- ;(current === 'superseded' ? superseded : active).add(citation[3]!)
103
+ const match = CITATION_LINE.exec(line)
104
+ if (match === null) continue
105
+ const citation = { date: match[2]!, fragmentId: match[3]! }
106
+ const canonical = formatCitation(citation.date, citation.fragmentId)
107
+ ;(current === 'superseded' ? superseded : active).set(canonical, citation)
104
108
  }
105
109
 
106
- // Re-affirmed fact (appears in both sections across edits): active wins.
107
- for (const id of active) superseded.delete(id)
110
+ const activeIds = new Set([...active.values()].map((citation) => citation.fragmentId))
111
+ for (const [canonical, citation] of superseded) {
112
+ if (activeIds.has(citation.fragmentId)) superseded.delete(canonical)
113
+ }
114
+ return { active: [...active.values()], superseded: [...superseded.values()] }
115
+ }
108
116
 
109
- return { active, superseded }
117
+ export function splitCitationsBySection(body: string): SectionedCitations {
118
+ const refs = splitCitationRefsBySection(body)
119
+ return {
120
+ active: new Set(refs.active.map((citation) => citation.fragmentId)),
121
+ superseded: new Set(refs.superseded.map((citation) => citation.fragmentId)),
122
+ }
110
123
  }
@@ -5,6 +5,7 @@ import { basename, join } from 'node:path'
5
5
 
6
6
  import { z } from 'zod'
7
7
 
8
+ import { hooklessGitArgs } from '@/git/hookless'
8
9
  import { withGitLock } from '@/git/mutex'
9
10
  import { type AgentGit, resolveAgentGit } from '@/git/resolve-agent-git'
10
11
  import { defineTool, lsTool, readTool, type Subagent, writeTool } from '@/plugin'
@@ -773,7 +774,7 @@ async function commitMemorySnapshotUnlocked(cwd: string): Promise<void> {
773
774
  }
774
775
 
775
776
  const add = bun.spawn({
776
- cmd: ['git', ...repo.gitArgs, 'add', '-f', '--', ...presentPaths],
777
+ cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'add', '-f', '--', ...presentPaths])],
777
778
  cwd,
778
779
  stdout: 'pipe',
779
780
  stderr: 'pipe',
@@ -788,7 +789,10 @@ async function commitMemorySnapshotUnlocked(cwd: string): Promise<void> {
788
789
  // fails outright when `bar/` matches no tracked file, even if `foo` is
789
790
  // staged.
790
791
  const stagedNames = bun.spawn({
791
- cmd: ['git', ...repo.gitArgs, 'diff', '--cached', '--name-only', '-z', '--', ...SNAPSHOT_PATHS],
792
+ cmd: [
793
+ 'git',
794
+ ...hooklessGitArgs([...repo.gitArgs, 'diff', '--cached', '--name-only', '-z', '--', ...SNAPSHOT_PATHS]),
795
+ ],
792
796
  cwd,
793
797
  stdout: 'pipe',
794
798
  stderr: 'pipe',
@@ -807,7 +811,7 @@ async function commitMemorySnapshotUnlocked(cwd: string): Promise<void> {
807
811
  const message = await buildCommitMessage(bun, cwd, staged, undefined, repo.gitArgs)
808
812
 
809
813
  const commit = bun.spawn({
810
- cmd: ['git', ...repo.gitArgs, 'commit', '-m', message, '--only', '--', ...staged],
814
+ cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'commit', '-m', message, '--only', '--', ...staged])],
811
815
  cwd,
812
816
  stdout: 'pipe',
813
817
  stderr: 'pipe',
@@ -864,7 +868,7 @@ async function buildDreamSummary(
864
868
  // numstat: `<added>\t<deleted>\t<path>` per line. Use NUL-terminated so paths
865
869
  // with whitespace round-trip; -z switches the record separator to NUL.
866
870
  const numstat = bun.spawn({
867
- cmd: ['git', ...gitArgs, 'diff', '--cached', '--numstat', '-z', '--', ...staged],
871
+ cmd: ['git', ...hooklessGitArgs([...gitArgs, 'diff', '--cached', '--numstat', '-z', '--', ...staged])],
868
872
  cwd,
869
873
  stdout: 'pipe',
870
874
  stderr: 'pipe',
@@ -921,7 +925,7 @@ async function listNewlyAddedSkills(
921
925
  gitArgs: readonly string[] = [],
922
926
  ): Promise<string[]> {
923
927
  const proc = bun.spawn({
924
- cmd: ['git', ...gitArgs, 'diff', '--cached', '--name-status', '-z', '--', ...staged],
928
+ cmd: ['git', ...hooklessGitArgs([...gitArgs, 'diff', '--cached', '--name-status', '-z', '--', ...staged])],
925
929
  cwd,
926
930
  stdout: 'pipe',
927
931
  stderr: 'pipe',
@@ -949,7 +953,7 @@ async function listTrackedSnapshotFiles(
949
953
  repo: AgentGit,
950
954
  ): Promise<string[]> {
951
955
  const ls = bun.spawn({
952
- cmd: ['git', ...repo.gitArgs, 'ls-files', '-z', '--', ...SNAPSHOT_PATHS],
956
+ cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'ls-files', '-z', '--', ...SNAPSHOT_PATHS])],
953
957
  cwd,
954
958
  stdout: 'pipe',
955
959
  stderr: 'pipe',
@@ -963,7 +967,7 @@ async function clearSkipWorktree(bun: { spawn: typeof Bun.spawn }, cwd: string,
963
967
  const files = await listTrackedSnapshotFiles(bun, cwd, repo)
964
968
  if (files.length === 0) return
965
969
  const proc = bun.spawn({
966
- cmd: ['git', ...repo.gitArgs, 'update-index', '--no-skip-worktree', '--', ...files],
970
+ cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'update-index', '--no-skip-worktree', '--', ...files])],
967
971
  cwd,
968
972
  stdout: 'pipe',
969
973
  stderr: 'pipe',
@@ -975,7 +979,7 @@ async function applySkipWorktree(bun: { spawn: typeof Bun.spawn }, cwd: string,
975
979
  const files = await listTrackedSnapshotFiles(bun, cwd, repo)
976
980
  if (files.length === 0) return
977
981
  const proc = bun.spawn({
978
- cmd: ['git', ...repo.gitArgs, 'update-index', '--skip-worktree', '--', ...files],
982
+ cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'update-index', '--skip-worktree', '--', ...files])],
979
983
  cwd,
980
984
  stdout: 'pipe',
981
985
  stderr: 'pipe',
@@ -1324,6 +1328,7 @@ function escapeTableCell(value: string): string {
1324
1328
  const dreamingDeleteTopicShardTool = defineTool({
1325
1329
  description: deleteTopicShardTool.description,
1326
1330
  parameters: deleteTopicShardTool.inputSchema,
1331
+ fileOperands: { destructive: ['path'] },
1327
1332
  async execute(args, ctx) {
1328
1333
  const result = await deleteTopicShardTool.run(args, { agentDir: ctx.agentDir })
1329
1334
  return { content: [{ type: 'text', text: JSON.stringify(result) }] }
@@ -19,6 +19,10 @@ export const findEntryTool = defineTool({
19
19
  .min(1)
20
20
  .describe('The entry id to locate (matches the JSONL row whose own `id` field equals this value).'),
21
21
  }),
22
+ // `path` is a real local file this tool reads; declaring it pins an immutable
23
+ // snapshot before readFile (and restores the original path in the result)
24
+ // instead of the scanner rejecting the bare `sessions/...jsonl` path.
25
+ fileOperands: { input: ['path'] },
22
26
  async execute({ path, entryId }) {
23
27
  if (entryId.length === 0) {
24
28
  throw new Error('find_entry requires a non-empty entryId; an empty needle would match every line.')
@@ -717,7 +717,3 @@ async function raceSpawn(work: Promise<void>, ms: number): Promise<void> {
717
717
  if (timer !== null) clearTimeout(timer)
718
718
  }
719
719
  }
720
-
721
- function isEnoent(err: unknown): boolean {
722
- return typeof err === 'object' && err !== null && 'code' in err && err.code === 'ENOENT'
723
- }
@@ -7,6 +7,7 @@ import { firstBeliefSentence, isTitleLikeHeading } from './belief-sentence'
7
7
  import { buildInjectionPlan, type InjectionPlan } from './injection-plan'
8
8
  import { loadAllShards, type TopicShard } from './load-shards'
9
9
  import { topicsDir } from './paths'
10
+ import { sanitizeProvenanceName } from './provenance-sanitize'
10
11
  import { slugIsHeadingEcho } from './slug'
11
12
  import type { FragmentProvenance } from './stream-events'
12
13
  import type { DedupedRetrievedItem } from './turn-dedup'
@@ -68,9 +69,13 @@ export type RetrievedMemoryItem = {
68
69
  // parts that exist are shown; an undreamed fragment with none renders nothing.
69
70
  export function renderProvenanceLine(item: Pick<RetrievedMemoryItem, 'who' | 'when' | 'where'>): string | null {
70
71
  const parts: string[] = []
71
- if (item.who !== undefined) parts.push(item.who)
72
- const room = item.where?.chatName ?? item.where?.chat
73
- if (room !== undefined) parts.push(`in ${item.where?.chatName !== undefined ? `#${room}` : room}`)
72
+ const who = sanitizeProvenanceName(item.who)
73
+ if (who !== undefined) parts.push(`speaker=<untrusted-name>${who}</untrusted-name>`)
74
+ const roomName = sanitizeProvenanceName(item.where?.chatName)
75
+ const room = roomName ?? item.where?.chat
76
+ if (room !== undefined) {
77
+ parts.push(roomName === undefined ? `in ${room}` : `in #<untrusted-name>${roomName}</untrusted-name>`)
78
+ }
74
79
  if (item.when !== undefined) parts.push(`on ${item.when.slice(0, 10)}`)
75
80
  return parts.length === 0 ? null : `_${parts.join(' ')}_`
76
81
  }