typeclaw 0.50.0 → 0.52.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 (258) hide show
  1. package/dist/types/agent/bash-sandbox-env.d.ts +17 -0
  2. package/dist/types/agent/bash-sandbox-proc.d.ts +8 -0
  3. package/dist/types/agent/bash-sandbox.d.ts +98 -0
  4. package/dist/types/agent/compaction.d.ts +4 -4
  5. package/dist/types/agent/idle-compaction.d.ts +1 -0
  6. package/dist/types/agent/index.d.ts +10 -17
  7. package/dist/types/agent/multimodal/look-at.d.ts +1 -1
  8. package/dist/types/agent/output-allowance.d.ts +4 -0
  9. package/dist/types/agent/plugin-tools.d.ts +8 -75
  10. package/dist/types/agent/prompt-cache-key.d.ts +1 -0
  11. package/dist/types/agent/session-tail.d.ts +12 -0
  12. package/dist/types/agent/subagents.d.ts +5 -0
  13. package/dist/types/agent/system-prompt-composition.d.ts +18 -0
  14. package/dist/types/agent/system-prompt.d.ts +2 -0
  15. package/dist/types/agent/tools/channel-disengage.d.ts +1 -1
  16. package/dist/types/agent/tools/channel-edit.d.ts +1 -1
  17. package/dist/types/agent/tools/channel-fetch-attachment.d.ts +1 -1
  18. package/dist/types/agent/tools/channel-handoff.d.ts +1 -1
  19. package/dist/types/agent/tools/channel-history.d.ts +1 -1
  20. package/dist/types/agent/tools/channel-react.d.ts +1 -1
  21. package/dist/types/agent/tools/channel-read.d.ts +10 -2
  22. package/dist/types/agent/tools/channel-reply.d.ts +1 -1
  23. package/dist/types/agent/tools/channel-send.d.ts +1 -1
  24. package/dist/types/agent/tools/channel-session-search.d.ts +1 -1
  25. package/dist/types/agent/tools/ddg.d.ts +9 -0
  26. package/dist/types/agent/tools/grant-role.d.ts +1 -1
  27. package/dist/types/agent/tools/post-github-review.d.ts +1 -1
  28. package/dist/types/agent/tools/restart.d.ts +1 -1
  29. package/dist/types/agent/tools/skip-response.d.ts +1 -1
  30. package/dist/types/agent/tools/spawn-subagent.d.ts +2 -1
  31. package/dist/types/agent/tools/stream-snapshot.d.ts +2 -2
  32. package/dist/types/agent/tools/subagent-cancel.d.ts +1 -1
  33. package/dist/types/agent/tools/subagent-output.d.ts +1 -1
  34. package/dist/types/agent/tools/todo/index.d.ts +1 -1
  35. package/dist/types/agent/tools/webfetch/adaptive-html.d.ts +3 -3
  36. package/dist/types/agent/tools/webfetch/strategies/readability-process.d.ts +48 -0
  37. package/dist/types/agent/tools/webfetch/tool.d.ts +2 -2
  38. package/dist/types/agent/tools/websearch.d.ts +1 -1
  39. package/dist/types/channels/adapters/github/auth-app.d.ts +25 -0
  40. package/dist/types/channels/adapters/github/auth-pat.d.ts +17 -0
  41. package/dist/types/channels/adapters/github/auth.d.ts +24 -0
  42. package/dist/types/channels/github-review-check.d.ts +1 -1
  43. package/dist/types/channels/github-token-bridge.d.ts +4 -0
  44. package/dist/types/channels/lost-background-context.d.ts +2 -0
  45. package/dist/types/channels/persistence.d.ts +1 -0
  46. package/dist/types/channels/router.d.ts +16 -50
  47. package/dist/types/channels/types.d.ts +1 -0
  48. package/dist/types/coding-agent/tool.d.ts +1 -1
  49. package/dist/types/config/config.d.ts +22 -0
  50. package/dist/types/config/providers.d.ts +50 -1
  51. package/dist/types/container/start.d.ts +1 -0
  52. package/dist/types/eval/cell.d.ts +26 -0
  53. package/dist/types/eval/config.d.ts +19 -0
  54. package/dist/types/eval/dispatch.d.ts +7 -0
  55. package/dist/types/eval/kernel.d.ts +28 -0
  56. package/dist/types/eval/process.d.ts +23 -0
  57. package/dist/types/eval/protocol.d.ts +34 -0
  58. package/dist/types/eval/sandbox.d.ts +12 -0
  59. package/dist/types/eval/tool.d.ts +17 -0
  60. package/dist/types/eval/wire.d.ts +33 -0
  61. package/dist/types/git/resolve-identity.d.ts +2 -0
  62. package/dist/types/init/dockerfile.d.ts +1 -0
  63. package/dist/types/init/gitignore.d.ts +1 -1
  64. package/dist/types/permissions/builtins.d.ts +1 -0
  65. package/dist/types/plugin/types.d.ts +3 -0
  66. package/dist/types/sandbox/canonical-secrets.d.ts +2 -2
  67. package/dist/types/sandbox/coding-agent.d.ts +1 -1
  68. package/dist/types/sandbox/dependency-bins.d.ts +1 -0
  69. package/dist/types/sandbox/dev-source.d.ts +2 -2
  70. package/dist/types/sandbox/env-exposure.d.ts +2 -0
  71. package/dist/types/sandbox/hidden-paths.d.ts +1 -0
  72. package/dist/types/sandbox/index.d.ts +1 -1
  73. package/dist/types/sandbox/policy.d.ts +3 -0
  74. package/dist/types/typevault/cli-path.d.ts +2 -0
  75. package/dist/types/typevault/envelope-store.d.ts +11 -0
  76. package/dist/types/typevault/lifecycle.d.ts +13 -0
  77. package/dist/types/typevault/vault.d.ts +27 -0
  78. package/package.json +8 -7
  79. package/scripts/test.ts +252 -0
  80. package/src/agent/bash-sandbox-env.ts +136 -0
  81. package/src/agent/bash-sandbox-proc.ts +70 -0
  82. package/src/agent/bash-sandbox.ts +239 -0
  83. package/src/agent/compaction.ts +22 -10
  84. package/src/agent/idle-compaction.ts +7 -3
  85. package/src/agent/index.ts +185 -187
  86. package/src/agent/multimodal/look-at.ts +1 -1
  87. package/src/agent/output-allowance.ts +7 -0
  88. package/src/agent/plugin-tools.ts +64 -380
  89. package/src/agent/prompt-cache-key.ts +26 -3
  90. package/src/agent/session-origin.ts +41 -19
  91. package/src/agent/session-tail.ts +28 -0
  92. package/src/agent/subagent-completion-reminder.ts +2 -2
  93. package/src/agent/subagents.ts +21 -2
  94. package/src/agent/system-prompt-composition.ts +159 -0
  95. package/src/agent/system-prompt.ts +43 -5
  96. package/src/agent/todo/scope.ts +1 -1
  97. package/src/agent/tool-error-remediation.ts +18 -3
  98. package/src/agent/tools/channel-disengage.ts +1 -1
  99. package/src/agent/tools/channel-edit.ts +1 -1
  100. package/src/agent/tools/channel-fetch-attachment.ts +1 -1
  101. package/src/agent/tools/channel-handoff.ts +3 -2
  102. package/src/agent/tools/channel-history.ts +2 -1
  103. package/src/agent/tools/channel-react.ts +1 -1
  104. package/src/agent/tools/channel-read.ts +36 -3
  105. package/src/agent/tools/channel-reply.ts +1 -1
  106. package/src/agent/tools/channel-send.ts +4 -3
  107. package/src/agent/tools/channel-session-search.ts +13 -4
  108. package/src/agent/tools/ddg.ts +71 -11
  109. package/src/agent/tools/grant-role.ts +1 -1
  110. package/src/agent/tools/post-github-review.ts +1 -1
  111. package/src/agent/tools/restart.ts +1 -1
  112. package/src/agent/tools/skip-response.ts +1 -1
  113. package/src/agent/tools/spawn-subagent.ts +15 -1
  114. package/src/agent/tools/stream-snapshot.ts +1 -1
  115. package/src/agent/tools/subagent-cancel.ts +1 -1
  116. package/src/agent/tools/subagent-output.ts +1 -1
  117. package/src/agent/tools/todo/index.ts +1 -1
  118. package/src/agent/tools/webfetch/adaptive-html.ts +6 -4
  119. package/src/agent/tools/webfetch/strategies/readability-child.ts +25 -0
  120. package/src/agent/tools/webfetch/strategies/readability-process.ts +185 -0
  121. package/src/agent/tools/webfetch/tool.ts +6 -5
  122. package/src/agent/tools/websearch.ts +1 -1
  123. package/src/agent/tools-without-local-file-operands.ts +4 -0
  124. package/src/browser/dockerfile.ts +1 -1
  125. package/src/browser/fill-secret.ts +364 -0
  126. package/src/browser/registry.ts +6 -6
  127. package/src/bundled-plugins/agent-messenger-cli-auth/command.ts +211 -0
  128. package/src/bundled-plugins/agent-messenger-cli-auth/index.ts +186 -0
  129. package/src/bundled-plugins/backup/index.ts +17 -2
  130. package/src/bundled-plugins/backup/runner.ts +37 -2
  131. package/src/bundled-plugins/browser-agent/browser-agent.ts +51 -14
  132. package/src/bundled-plugins/browser-agent/index.ts +12 -5
  133. package/src/bundled-plugins/explorer/explorer.ts +1 -1
  134. package/src/bundled-plugins/github-cli-auth/gh-review-detect.ts +40 -16
  135. package/src/bundled-plugins/github-cli-auth/graphql-auth-nudge.ts +12 -7
  136. package/src/bundled-plugins/github-cli-auth/index.ts +10 -1
  137. package/src/bundled-plugins/managed-browser/index.ts +130 -2
  138. package/src/bundled-plugins/managed-browser/skills/browserskill/browserskill/SKILL.md +13 -5
  139. package/src/bundled-plugins/managed-browser/skills/omowright/omowright/SKILL.md +56 -5
  140. package/src/bundled-plugins/memory/README.md +23 -2
  141. package/src/bundled-plugins/memory/append-fragment.ts +133 -0
  142. package/src/bundled-plugins/memory/append-tool.ts +80 -149
  143. package/src/bundled-plugins/memory/dreaming.ts +6 -1
  144. package/src/bundled-plugins/memory/index.ts +33 -6
  145. package/src/bundled-plugins/memory/load-memory.ts +2 -4
  146. package/src/bundled-plugins/memory/memory-logger.ts +200 -6
  147. package/src/bundled-plugins/memory/references/store-reference-tool.ts +56 -32
  148. package/src/bundled-plugins/memory/remember-tool.ts +81 -0
  149. package/src/bundled-plugins/memory/search-tool-hybrid.ts +91 -0
  150. package/src/bundled-plugins/memory/search-tool.ts +58 -12
  151. package/src/bundled-plugins/memory/stream-events.ts +2 -0
  152. package/src/bundled-plugins/memory/transcript-cursor.ts +30 -0
  153. package/src/bundled-plugins/memory/transcript-preload.ts +208 -0
  154. package/src/bundled-plugins/memory/transcript-view.ts +36 -0
  155. package/src/bundled-plugins/memory/vector/hybrid.ts +25 -14
  156. package/src/bundled-plugins/memory/watermark.ts +19 -10
  157. package/src/bundled-plugins/reviewer/reviewer.ts +20 -0
  158. package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +3 -6
  159. package/src/bundled-plugins/security/policies/outbound-text.ts +20 -0
  160. package/src/bundled-plugins/security/policies/private-surface-read.ts +166 -201
  161. package/src/bundled-plugins/security/policies/system-prompt-leak.ts +2 -7
  162. package/src/bundled-plugins/typevault/grants.ts +119 -0
  163. package/src/bundled-plugins/typevault/index.ts +152 -0
  164. package/src/bundled-plugins/typevault/request.ts +87 -0
  165. package/src/bundled-plugins/typevault/runtime.ts +45 -0
  166. package/src/bundled-plugins/typevault/skills/typevault/SKILL.md +65 -0
  167. package/src/channels/adapter-halt.ts +17 -0
  168. package/src/channels/adapters/discord-bot-reference.ts +5 -4
  169. package/src/channels/adapters/discord-bot.ts +1 -0
  170. package/src/channels/adapters/discord-classify.ts +8 -3
  171. package/src/channels/adapters/discord.ts +29 -0
  172. package/src/channels/adapters/github/history.ts +23 -2
  173. package/src/channels/adapters/github/inbound.ts +60 -1
  174. package/src/channels/adapters/github/index.ts +27 -5
  175. package/src/channels/adapters/github/reconcile-open-prs.ts +7 -1
  176. package/src/channels/adapters/kakaotalk-author-resolver.ts +7 -5
  177. package/src/channels/adapters/kakaotalk-channel-resolver.ts +45 -15
  178. package/src/channels/adapters/kakaotalk-classify.ts +7 -9
  179. package/src/channels/adapters/kakaotalk-list.ts +62 -0
  180. package/src/channels/adapters/kakaotalk-member-cache.ts +67 -0
  181. package/src/channels/adapters/kakaotalk-membership.ts +27 -10
  182. package/src/channels/adapters/kakaotalk-mention.ts +61 -0
  183. package/src/channels/adapters/kakaotalk.ts +159 -125
  184. package/src/channels/adapters/teams-classify.ts +18 -8
  185. package/src/channels/github-review-check.ts +5 -1
  186. package/src/channels/github-review-verdict-coordinator.ts +68 -2
  187. package/src/channels/github-token-bridge.ts +13 -0
  188. package/src/channels/lost-background-context.ts +46 -0
  189. package/src/channels/manager.ts +52 -3
  190. package/src/channels/persistence.ts +5 -0
  191. package/src/channels/router.ts +208 -128
  192. package/src/channels/schema.ts +1 -1
  193. package/src/channels/subagent-completion-bridge.ts +3 -2
  194. package/src/channels/types.ts +3 -0
  195. package/src/cli/hostd.ts +3 -0
  196. package/src/coding-agent/tool.ts +1 -1
  197. package/src/config/config.ts +35 -1
  198. package/src/config/providers.ts +75 -4
  199. package/src/container/start.ts +52 -3
  200. package/src/doctor/channel-checks.ts +33 -0
  201. package/src/doctor/checks.ts +37 -18
  202. package/src/doctor/index.ts +48 -12
  203. package/src/doctor/operational-incidents.ts +16 -1
  204. package/src/doctor/plugin-bridge.ts +14 -1
  205. package/src/doctor/stage.ts +14 -0
  206. package/src/doctor/types.ts +6 -0
  207. package/src/eval/cell.ts +93 -0
  208. package/src/eval/config.ts +32 -0
  209. package/src/eval/dispatch.ts +67 -0
  210. package/src/eval/entry.ts +261 -0
  211. package/src/eval/kernel.ts +154 -0
  212. package/src/eval/process.ts +113 -0
  213. package/src/eval/protocol.ts +26 -0
  214. package/src/eval/redeclare.ts +174 -0
  215. package/src/eval/sandbox.ts +117 -0
  216. package/src/eval/tool.ts +99 -0
  217. package/src/eval/wire.ts +93 -0
  218. package/src/git/resolve-identity.ts +67 -2
  219. package/src/git/system-commit.ts +7 -0
  220. package/src/init/dockerfile.ts +5 -1
  221. package/src/init/gitignore.ts +3 -3
  222. package/src/init/index.ts +1 -0
  223. package/src/init/models-dev.ts +2 -0
  224. package/src/init/validate-api-key.ts +5 -0
  225. package/src/migrations/secrets-v1-to-v2.ts +2 -0
  226. package/src/operations/classify-tool-outcome.ts +1 -1
  227. package/src/permissions/builtins.ts +8 -0
  228. package/src/plugin/core-tool-names.ts +6 -1
  229. package/src/plugin/types.ts +6 -0
  230. package/src/run/bundled-plugins.ts +12 -0
  231. package/src/run/channel-session-factory.ts +3 -0
  232. package/src/run/index.ts +13 -2
  233. package/src/sandbox/build.ts +1 -0
  234. package/src/sandbox/canonical-secrets.ts +6 -0
  235. package/src/sandbox/dependency-bins.ts +13 -1
  236. package/src/sandbox/dev-source.ts +21 -12
  237. package/src/sandbox/env-exposure.ts +20 -0
  238. package/src/sandbox/hidden-paths.ts +1 -1
  239. package/src/sandbox/index.ts +1 -0
  240. package/src/sandbox/policy.ts +5 -0
  241. package/src/secrets/hydrate.ts +4 -1
  242. package/src/secrets/storage.ts +10 -1
  243. package/src/server/command-runner.ts +4 -0
  244. package/src/server/index.ts +54 -12
  245. package/src/skills/typeclaw-config/SKILL.md +36 -2
  246. package/src/skills/typeclaw-memory/SKILL.md +3 -1
  247. package/src/skills/typeclaw-permissions/SKILL.md +8 -8
  248. package/src/skills/typeclaw-troubleshooting/SKILL.md +18 -1
  249. package/src/tunnels/active.ts +14 -0
  250. package/src/typevault/bash-cli.ts +18 -0
  251. package/src/typevault/cli-path.ts +11 -0
  252. package/src/typevault/envelope-helper.ts +17 -0
  253. package/src/typevault/envelope-store.ts +98 -0
  254. package/src/typevault/lifecycle.ts +132 -0
  255. package/src/typevault/prompt-tunnel.ts +33 -0
  256. package/src/typevault/redaction.ts +37 -0
  257. package/src/typevault/vault.ts +283 -0
  258. package/typeclaw.schema.json +92 -10
@@ -0,0 +1,33 @@
1
+ import type { TunnelConfig } from '@/tunnels'
2
+
3
+ const PROMPT_TUNNEL_NAME = 'typevault'
4
+
5
+ type PromptTunnelConfig = { typevault: { enabled: boolean; promptPort: number }; tunnels: readonly TunnelConfig[] }
6
+
7
+ // The one-time secret page must be reachable from the user's phone. An
8
+ // operator's own manual tunnel wins: one to the prompt port, or one named
9
+ // `typevault` with no port (a cloudflare-named tunnel, whose upstream is set in
10
+ // Cloudflare). Otherwise an enabled vault gets a free Cloudflare quick tunnel,
11
+ // so `vault_request` works with no setup. The page carries only ciphertext
12
+ // (the browser encrypts to the tier).
13
+ export function typevaultPromptTunnel(config: PromptTunnelConfig): TunnelConfig | undefined {
14
+ const configured = config.tunnels.find(
15
+ (entry) =>
16
+ entry.for.kind === 'manual' &&
17
+ (entry.upstreamPort === config.typevault.promptPort ||
18
+ (entry.name === PROMPT_TUNNEL_NAME && entry.upstreamPort === undefined)),
19
+ )
20
+ if (configured !== undefined) return configured
21
+ if (!config.typevault.enabled) return undefined
22
+ // The tunnel manager keys tunnels by name, so a reused name would replace
23
+ // an operator's tunnel instead of adding this one.
24
+ const taken = new Set(config.tunnels.map((entry) => entry.name))
25
+ let name = PROMPT_TUNNEL_NAME
26
+ for (let suffix = 2; taken.has(name); suffix++) name = `${PROMPT_TUNNEL_NAME}-${suffix}`
27
+ return { name, provider: 'cloudflare-quick', for: { kind: 'manual' }, upstreamPort: config.typevault.promptPort }
28
+ }
29
+
30
+ export function runtimeTunnels(config: PromptTunnelConfig): TunnelConfig[] {
31
+ const prompt = typevaultPromptTunnel(config)
32
+ return prompt === undefined || config.tunnels.includes(prompt) ? [...config.tunnels] : [...config.tunnels, prompt]
33
+ }
@@ -0,0 +1,37 @@
1
+ import { entriesStamp } from './envelope-store'
2
+ import { openVault, RUNTIME_TIER } from './vault'
3
+
4
+ const READ_REASON = 'redact tool output'
5
+
6
+ const cache = new Map<string, { stamp: string; values: readonly string[] }>()
7
+ // Every value ever seen, per agent, for the life of the process (which outlives
8
+ // every session in it): a secret that was overwritten or deleted can still sit
9
+ // in a log or artifact, so it stays redacted.
10
+ const observed = new Map<string, Set<string>>()
11
+
12
+ // Every secret value stored in the vault outside the runtime tier, read with
13
+ // the agent's own key. Redacting by what the vault holds, rather than by what
14
+ // a grant reports it handed out, covers derived grants, a bash command still
15
+ // running when another tool finishes, and grants that expired or were revoked
16
+ // before their history could be read. Public `text` fields are left alone.
17
+ // Cached until the vault's entries change.
18
+ export async function vaultSecretValues(agentDir: string): Promise<readonly string[]> {
19
+ const stamp = entriesStamp(agentDir)
20
+ const cached = cache.get(agentDir)
21
+ if (cached !== undefined && cached.stamp === stamp) return cached.values
22
+ const vault = await openVault(agentDir)
23
+ const values = observed.get(agentDir) ?? new Set<string>()
24
+ observed.set(agentDir, values)
25
+ for (const summary of await vault.list()) {
26
+ if (summary.tier === RUNTIME_TIER) continue
27
+ const entry = await vault.get(summary.name, READ_REASON)
28
+ for (const field of Object.values(entry.fields)) {
29
+ if (field.type === 'text') continue
30
+ if (field.type === 'oauth') for (const part of Object.values(field.value)) values.add(part)
31
+ else values.add(field.value)
32
+ }
33
+ }
34
+ const snapshot = [...values]
35
+ if (entriesStamp(agentDir) === stamp) cache.set(agentDir, { stamp, values: snapshot })
36
+ return snapshot
37
+ }
@@ -0,0 +1,283 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { existsSync, readdirSync, readFileSync, rmSync } from 'node:fs'
3
+ import { join, resolve } from 'node:path'
4
+
5
+ import { type Access, createClient, parseEntryName, TypeVaultError } from 'typevault'
6
+ import { type AdminClient, createAdmin } from 'typevault/admin'
7
+
8
+ import { typevaultCliPath } from './cli-path'
9
+
10
+ // The agent's vault and its private state both live inside the agent folder,
11
+ // so copying the folder moves the whole vault. `.typevault/` holds only
12
+ // ciphertext and signed manifests (force-committed by the backup plugin);
13
+ // `.typeclaw/typevault/` holds the agent's own machine key and typevault's
14
+ // per-checkout state (trust pin, audit log, locks), gitignored and masked
15
+ // from every role.
16
+ export const TYPEVAULT_VAULT_RELATIVE_DIR = '.typevault'
17
+ export const TYPEVAULT_STATE_RELATIVE_DIR = '.typeclaw/typevault'
18
+
19
+ // The vault's single owner: a machine identity, so nothing ever waits for a
20
+ // human to unlock it.
21
+ const MEMBER_NAME = 'typeclaw'
22
+
23
+ // Holds the whole secrets.json envelope. No grant issued to a model session
24
+ // ever reaches this tier.
25
+ export const RUNTIME_TIER = 'runtime'
26
+
27
+ const SECRETS_ENTRY = parseEntryName('typevault://typeclaw/secrets')
28
+ const READ_REASON = 'typeclaw runtime credentials'
29
+
30
+ export function typevaultDir(agentDir: string): string {
31
+ return join(agentDir, TYPEVAULT_VAULT_RELATIVE_DIR)
32
+ }
33
+
34
+ export function vaultExists(agentDir: string): boolean {
35
+ return existsSync(join(typevaultDir(agentDir), 'owner.json'))
36
+ }
37
+
38
+ // typevault lets one machine at a time use a vault's private state, and names
39
+ // the machine that holds it in a `daemon.holder` claim that survives the
40
+ // daemon. Its default name comes from the machine ID or hostname, but for TypeClaw the host-stage CLI
41
+ // and every container recreated for this agent are one owner: a new container
42
+ // can get a new name, so a claim left by the previous one (or held by the live
43
+ // container while the host CLI writes secrets) would refuse every vault open
44
+ // with `in_use`. One stable identity per agent lets typevault replace a claim
45
+ // its own flock proves stale; a claim from any other identity is still refused.
46
+ export const TYPEVAULT_HOST_ID = 'typeclaw-agent'
47
+
48
+ // typevault 0.4 requires `name` in `daemon.holder` and refuses every vault open
49
+ // on a claim without one. The runtime never stops its detached daemon, so each
50
+ // container stop under 0.3 leaves such a claim behind. typevault keys a checkout
51
+ // by the vault's absolute path, so the container's claim sits under the hash of
52
+ // /agent/.typevault, not the host path: scan every checkout in this agent's
53
+ // config root. Call this only while the container is down: a claim under this
54
+ // agent's identity then has no live owner. Any other claim stays, for typevault
55
+ // to refuse with its own error.
56
+ export function clearLegacyDaemonClaims(agentDir: string): void {
57
+ const checkouts = join(runtimeConfigRoot(agentDir), 'typevault', 'checkouts')
58
+ if (!existsSync(checkouts)) return
59
+ for (const checkout of readdirSync(checkouts)) {
60
+ const path = join(checkouts, checkout, 'run', 'daemon.holder')
61
+ if (!existsSync(path)) continue
62
+ let claim: { host?: unknown; name?: unknown } | null
63
+ try {
64
+ claim = JSON.parse(readFileSync(path, 'utf8'))
65
+ } catch {
66
+ continue
67
+ }
68
+ if (claim?.host === TYPEVAULT_HOST_ID && claim.name === undefined) rmSync(path, { force: true })
69
+ }
70
+ }
71
+
72
+ // The environment every typevault call runs under. The agent's vault is opened
73
+ // as typevault's "global" vault at an explicit TYPEVAULT_DIR, so nothing
74
+ // depends on the process cwd, and every ambient TYPEVAULT_* variable is
75
+ // dropped so an operator's own grant or key can never leak in.
76
+ export function typevaultEnv(agentDir: string, base: NodeJS.ProcessEnv = process.env): Record<string, string> {
77
+ const env: Record<string, string> = {}
78
+ for (const [key, value] of Object.entries(base)) {
79
+ if (value !== undefined && !key.startsWith('TYPEVAULT_')) env[key] = value
80
+ }
81
+ env.XDG_CONFIG_HOME = runtimeConfigRoot(agentDir)
82
+ env.TYPEVAULT_DIR = typevaultDir(agentDir)
83
+ env.TYPEVAULT_GLOBAL = '1'
84
+ env.TYPEVAULT_HOST_ID = TYPEVAULT_HOST_ID
85
+ return env
86
+ }
87
+
88
+ // Owner operations have no SDK export yet, so they go through typevault's CLI.
89
+ // `init` mints a new owner key and rewrites the manifests, so it only ever runs
90
+ // on an empty directory: anything left behind is ciphertext that only the old
91
+ // keys can open.
92
+ export async function provisionVault(agentDir: string): Promise<void> {
93
+ if (!vaultExists(agentDir)) {
94
+ const dir = typevaultDir(agentDir)
95
+ if (existsSync(dir) && readdirSync(dir).length > 0) {
96
+ throw new Error(`${dir} is not empty but has no owner.json; refusing to create a new vault over it`)
97
+ }
98
+ await runTypevaultCli(agentDir, ['init', '--machine', '--name', MEMBER_NAME])
99
+ }
100
+ await ensureTier(agentDir, RUNTIME_TIER)
101
+ }
102
+
103
+ // `undefined` only means "not stored yet". Once secrets.json points at the
104
+ // vault, use requireSecretsEntry: typevault skips entries it cannot verify, so
105
+ // a missing entry can be corruption and must never read as an empty store.
106
+ export async function readSecretsEntry(agentDir: string): Promise<string | undefined> {
107
+ const vault = await openVault(agentDir)
108
+ let fields: Awaited<ReturnType<Access['get']>>['fields']
109
+ try {
110
+ fields = (await vault.get(SECRETS_ENTRY, READ_REASON)).fields
111
+ } catch (error) {
112
+ if (error instanceof TypeVaultError && error.code === 'not_found') return undefined
113
+ throw error
114
+ }
115
+ const value = fields['$default']
116
+ if (value?.type !== 'secret') throw new Error('the TypeVault secrets entry has no secret field')
117
+ return value.value
118
+ }
119
+
120
+ export async function requireSecretsEntry(agentDir: string): Promise<string> {
121
+ const text = await readSecretsEntry(agentDir)
122
+ if (text === undefined) {
123
+ throw new Error(
124
+ 'the TypeVault vault has no readable secrets entry (typevault://typeclaw/secrets); restore .typevault/ from the agent repo history',
125
+ )
126
+ }
127
+ return text
128
+ }
129
+
130
+ export async function writeSecretsEntry(agentDir: string, text: string): Promise<void> {
131
+ const vault = await openVault(agentDir)
132
+ await vault.set({
133
+ name: SECRETS_ENTRY,
134
+ tier: RUNTIME_TIER,
135
+ fields: { $default: { type: 'secret', value: text } },
136
+ })
137
+ }
138
+
139
+ // The built-in role tower as tier includes: a grant for a role's tier reaches
140
+ // every tier below it, so a secret stored at `member` is usable by member,
141
+ // trusted and owner sessions, and never by guest.
142
+ export const ROLE_TIER_TOWER = ['owner', 'trusted', 'member', 'guest'] as const
143
+
144
+ const TIER_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
145
+
146
+ // A role reaches the tier of the same name, except the runtime tier: it holds
147
+ // the whole secrets.json envelope, so a custom role named `runtime` must never
148
+ // map onto it.
149
+ export function isRoleTier(name: string): boolean {
150
+ return TIER_NAME.test(name) && name !== RUNTIME_TIER
151
+ }
152
+
153
+ // Creates a tier per role and wires the built-in tower. Returns the roles that
154
+ // get no tier (and so no grant), for the operator log.
155
+ export async function ensureRoleTiers(agentDir: string, roles: readonly string[]): Promise<string[]> {
156
+ const tiers = await listTiers(agentDir)
157
+ const skipped: string[] = []
158
+ for (const role of new Set([...ROLE_TIER_TOWER, ...roles])) {
159
+ if (!isRoleTier(role)) {
160
+ skipped.push(role)
161
+ continue
162
+ }
163
+ if (tiers.has(role)) continue
164
+ await ensureTier(agentDir, role)
165
+ tiers.set(role, new Set())
166
+ }
167
+ for (let i = 0; i < ROLE_TIER_TOWER.length - 1; i++) {
168
+ const upper = ROLE_TIER_TOWER[i]!
169
+ const lower = ROLE_TIER_TOWER[i + 1]!
170
+ if (!tiers.get(upper)?.has(lower)) await runTypevaultCli(agentDir, ['tier', 'include', upper, lower])
171
+ }
172
+ return skipped
173
+ }
174
+
175
+ // `promptPort` reaches the daemon only when this call is what starts it; the
176
+ // runtime's first grant does, so the daemon serves `request` pages there.
177
+ export function vaultAdmin(agentDir: string, options: { promptPort?: number } = {}): AdminClient {
178
+ const env = typevaultEnv(agentDir)
179
+ if (options.promptPort !== undefined) env.TYPEVAULT_PROMPT_PORT = String(options.promptPort)
180
+ return createAdmin({ env, global: true, dir: typevaultDir(agentDir) })
181
+ }
182
+
183
+ export function grantAccess(agentDir: string, grant: string): Promise<Access> {
184
+ return createClient({ grant, global: true, dir: typevaultDir(agentDir), env: typevaultEnv(agentDir) })
185
+ }
186
+
187
+ // typevault keys a vault's private state by the hash of its directory path, so
188
+ // a client with a different config root still finds the socket for the same
189
+ // TYPEVAULT_DIR under `<configRoot>/typevault/checkouts/<hash>/run/`.
190
+ export function agentSocketPath(agentDir: string, configRoot: string): string {
191
+ const checkout = createHash('sha256')
192
+ .update(resolve(typevaultDir(agentDir)), 'utf8')
193
+ .digest('hex')
194
+ .slice(0, 16)
195
+ return join(configRoot, 'typevault', 'checkouts', checkout, 'run', 'agent.sock')
196
+ }
197
+
198
+ export function runtimeConfigRoot(agentDir: string): string {
199
+ return join(agentDir, TYPEVAULT_STATE_RELATIVE_DIR, 'config')
200
+ }
201
+
202
+ // The agent's member identity for other projects' vaults, apart from the key
203
+ // that owns its own vault: model bash gets this one, so it must never open
204
+ // the agent's vault. An owner adds it with the line `typevault join` prints.
205
+ export function projectIdentityPath(agentDir: string): string {
206
+ return join(projectConfigRoot(agentDir), 'typevault', 'identity.json')
207
+ }
208
+
209
+ export async function ensureProjectIdentity(agentDir: string, name: string): Promise<void> {
210
+ if (existsSync(projectIdentityPath(agentDir))) return
211
+ // `join` is typevault's only way to mint a machine identity. It needs some
212
+ // vault to name; the agent's own is opened public-only and left unchanged.
213
+ await runTypevaultCli(agentDir, ['join', '--machine', '--name', name], {
214
+ XDG_CONFIG_HOME: projectConfigRoot(agentDir),
215
+ })
216
+ }
217
+
218
+ // A typevault member name ([a-z0-9-]) for this agent, from its container name.
219
+ export function projectMemberName(containerName: string | undefined): string {
220
+ const name = (containerName ?? '')
221
+ .toLowerCase()
222
+ .replace(/[^a-z0-9]+/g, '-')
223
+ .replace(/^-+|-+$/g, '')
224
+ return name === '' ? MEMBER_NAME : name
225
+ }
226
+
227
+ function projectConfigRoot(agentDir: string): string {
228
+ return join(agentDir, TYPEVAULT_STATE_RELATIVE_DIR, 'project-member')
229
+ }
230
+
231
+ async function listTiers(agentDir: string): Promise<Map<string, Set<string>>> {
232
+ const tiers = new Map<string, Set<string>>()
233
+ const lines = (await runTypevaultCli(agentDir, ['tier', 'ls'])).split('\n').slice(1)
234
+ for (const line of lines) {
235
+ const [name, , ...rest] = line.trim().split(/\s+/)
236
+ if (name === undefined || name === '') continue
237
+ tiers.set(
238
+ name,
239
+ new Set(
240
+ rest
241
+ .join(' ')
242
+ .split(/[,\s]+/)
243
+ .filter(Boolean),
244
+ ),
245
+ )
246
+ }
247
+ return tiers
248
+ }
249
+
250
+ export function openVault(agentDir: string): Promise<Access> {
251
+ return createClient({ direct: true, global: true, dir: typevaultDir(agentDir), env: typevaultEnv(agentDir) })
252
+ }
253
+
254
+ async function ensureTier(agentDir: string, tier: string): Promise<void> {
255
+ try {
256
+ await runTypevaultCli(agentDir, ['tier', 'add', tier])
257
+ } catch (error) {
258
+ if (!(error instanceof Error && error.message.includes(`tier "${tier}" already exists`))) throw error
259
+ }
260
+ }
261
+
262
+ async function runTypevaultCli(
263
+ agentDir: string,
264
+ args: string[],
265
+ envOverride: Record<string, string> = {},
266
+ ): Promise<string> {
267
+ const child = Bun.spawn([process.execPath, typevaultCliPath(), ...args], {
268
+ cwd: agentDir,
269
+ env: { ...typevaultEnv(agentDir), ...envOverride },
270
+ stdin: 'ignore',
271
+ stdout: 'pipe',
272
+ stderr: 'pipe',
273
+ })
274
+ const [stdout, stderr, exitCode] = await Promise.all([
275
+ new Response(child.stdout).text(),
276
+ new Response(child.stderr).text(),
277
+ child.exited,
278
+ ])
279
+ if (exitCode !== 0) {
280
+ throw new Error(`typevault ${args.join(' ')} failed: ${stderr.trim() || `exit code ${exitCode}`}`)
281
+ }
282
+ return stdout
283
+ }
@@ -73,7 +73,8 @@
73
73
  "moonshot/kimi-k2.5",
74
74
  "moonshot-coding/kimi-for-coding",
75
75
  "opengateway/openai/gpt-5.4-nano",
76
- "inception/mercury-3"
76
+ "inception/mercury-3",
77
+ "exaone/k-exaone_v2.5"
77
78
  ]
78
79
  },
79
80
  {
@@ -138,7 +139,8 @@
138
139
  "moonshot/kimi-k2.5",
139
140
  "moonshot-coding/kimi-for-coding",
140
141
  "opengateway/openai/gpt-5.4-nano",
141
- "inception/mercury-3"
142
+ "inception/mercury-3",
143
+ "exaone/k-exaone_v2.5"
142
144
  ]
143
145
  },
144
146
  {
@@ -204,7 +206,8 @@
204
206
  "moonshot/kimi-k2.5",
205
207
  "moonshot-coding/kimi-for-coding",
206
208
  "opengateway/openai/gpt-5.4-nano",
207
- "inception/mercury-3"
209
+ "inception/mercury-3",
210
+ "exaone/k-exaone_v2.5"
208
211
  ]
209
212
  },
210
213
  {
@@ -268,7 +271,8 @@
268
271
  "moonshot/kimi-k2.5",
269
272
  "moonshot-coding/kimi-for-coding",
270
273
  "opengateway/openai/gpt-5.4-nano",
271
- "inception/mercury-3"
274
+ "inception/mercury-3",
275
+ "exaone/k-exaone_v2.5"
272
276
  ]
273
277
  },
274
278
  {
@@ -333,7 +337,8 @@
333
337
  "moonshot/kimi-k2.5",
334
338
  "moonshot-coding/kimi-for-coding",
335
339
  "opengateway/openai/gpt-5.4-nano",
336
- "inception/mercury-3"
340
+ "inception/mercury-3",
341
+ "exaone/k-exaone_v2.5"
337
342
  ]
338
343
  },
339
344
  {
@@ -492,7 +497,8 @@
492
497
  "moonshot/kimi-k2.5",
493
498
  "moonshot-coding/kimi-for-coding",
494
499
  "opengateway/openai/gpt-5.4-nano",
495
- "inception/mercury-3"
500
+ "inception/mercury-3",
501
+ "exaone/k-exaone_v2.5"
496
502
  ]
497
503
  },
498
504
  {
@@ -557,7 +563,8 @@
557
563
  "moonshot/kimi-k2.5",
558
564
  "moonshot-coding/kimi-for-coding",
559
565
  "opengateway/openai/gpt-5.4-nano",
560
- "inception/mercury-3"
566
+ "inception/mercury-3",
567
+ "exaone/k-exaone_v2.5"
561
568
  ]
562
569
  },
563
570
  {
@@ -623,7 +630,8 @@
623
630
  "moonshot/kimi-k2.5",
624
631
  "moonshot-coding/kimi-for-coding",
625
632
  "opengateway/openai/gpt-5.4-nano",
626
- "inception/mercury-3"
633
+ "inception/mercury-3",
634
+ "exaone/k-exaone_v2.5"
627
635
  ]
628
636
  },
629
637
  {
@@ -687,7 +695,8 @@
687
695
  "moonshot/kimi-k2.5",
688
696
  "moonshot-coding/kimi-for-coding",
689
697
  "opengateway/openai/gpt-5.4-nano",
690
- "inception/mercury-3"
698
+ "inception/mercury-3",
699
+ "exaone/k-exaone_v2.5"
691
700
  ]
692
701
  },
693
702
  {
@@ -752,7 +761,8 @@
752
761
  "moonshot/kimi-k2.5",
753
762
  "moonshot-coding/kimi-for-coding",
754
763
  "opengateway/openai/gpt-5.4-nano",
755
- "inception/mercury-3"
764
+ "inception/mercury-3",
765
+ "exaone/k-exaone_v2.5"
756
766
  ]
757
767
  },
758
768
  {
@@ -3035,6 +3045,46 @@
3035
3045
  }
3036
3046
  }
3037
3047
  },
3048
+ "eval": {
3049
+ "default": {
3050
+ "enabled": false,
3051
+ "origins": [
3052
+ "tui",
3053
+ "channel",
3054
+ "cron",
3055
+ "subagent",
3056
+ "system"
3057
+ ]
3058
+ },
3059
+ "type": "object",
3060
+ "properties": {
3061
+ "enabled": {
3062
+ "default": false,
3063
+ "type": "boolean"
3064
+ },
3065
+ "origins": {
3066
+ "default": [
3067
+ "tui",
3068
+ "channel",
3069
+ "cron",
3070
+ "subagent",
3071
+ "system"
3072
+ ],
3073
+ "type": "array",
3074
+ "items": {
3075
+ "type": "string",
3076
+ "enum": [
3077
+ "tui",
3078
+ "channel",
3079
+ "cron",
3080
+ "subagent",
3081
+ "system"
3082
+ ]
3083
+ }
3084
+ }
3085
+ },
3086
+ "additionalProperties": false
3087
+ },
3038
3088
  "docker": {
3039
3089
  "default": {
3040
3090
  "file": {
@@ -3224,6 +3274,26 @@
3224
3274
  }
3225
3275
  }
3226
3276
  },
3277
+ "typevault": {
3278
+ "default": {
3279
+ "enabled": false,
3280
+ "promptPort": 8976
3281
+ },
3282
+ "type": "object",
3283
+ "properties": {
3284
+ "enabled": {
3285
+ "default": false,
3286
+ "type": "boolean"
3287
+ },
3288
+ "promptPort": {
3289
+ "default": 8976,
3290
+ "type": "integer",
3291
+ "minimum": 1,
3292
+ "maximum": 65535
3293
+ }
3294
+ },
3295
+ "additionalProperties": false
3296
+ },
3227
3297
  "logs": {
3228
3298
  "default": {
3229
3299
  "retentionDays": 14
@@ -3346,6 +3416,18 @@
3346
3416
  "default": true,
3347
3417
  "type": "boolean"
3348
3418
  },
3419
+ "compaction": {
3420
+ "default": {},
3421
+ "type": "object",
3422
+ "properties": {
3423
+ "maxTriggerTokens": {
3424
+ "type": "integer",
3425
+ "minimum": 60000,
3426
+ "maximum": 9007199254740991
3427
+ }
3428
+ },
3429
+ "additionalProperties": false
3430
+ },
3349
3431
  "tool-result-cap": {
3350
3432
  "default": {
3351
3433
  "enabled": true,