typeclaw 0.1.4 → 0.1.6

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 (134) hide show
  1. package/README.md +15 -13
  2. package/auth.schema.json +41 -0
  3. package/cron.schema.json +8 -0
  4. package/package.json +1 -1
  5. package/secrets.schema.json +41 -0
  6. package/src/agent/auth.ts +45 -22
  7. package/src/agent/index.ts +189 -19
  8. package/src/agent/multimodal/index.ts +12 -0
  9. package/src/agent/multimodal/look-at.ts +185 -0
  10. package/src/agent/multimodal/looker.ts +145 -0
  11. package/src/agent/plugin-tools.ts +30 -1
  12. package/src/agent/session-origin.ts +194 -46
  13. package/src/agent/subagents.ts +57 -1
  14. package/src/agent/system-prompt.ts +1 -1
  15. package/src/agent/tool-result-budget.ts +121 -0
  16. package/src/bundled-plugins/backup/index.ts +23 -8
  17. package/src/bundled-plugins/backup/runner.ts +22 -0
  18. package/src/bundled-plugins/memory/README.md +13 -10
  19. package/src/bundled-plugins/memory/append-tool.ts +87 -61
  20. package/src/bundled-plugins/memory/dreaming.ts +137 -7
  21. package/src/bundled-plugins/memory/find-entry-tool.ts +62 -0
  22. package/src/bundled-plugins/memory/fragment-parser.ts +19 -44
  23. package/src/bundled-plugins/memory/index.ts +91 -8
  24. package/src/bundled-plugins/memory/load-memory.ts +74 -34
  25. package/src/bundled-plugins/memory/memory-logger.ts +72 -29
  26. package/src/bundled-plugins/memory/migration.ts +276 -0
  27. package/src/bundled-plugins/memory/stream-events.ts +55 -0
  28. package/src/bundled-plugins/memory/stream-io.ts +63 -0
  29. package/src/bundled-plugins/memory/watermark.ts +48 -8
  30. package/src/bundled-plugins/security/index.ts +103 -10
  31. package/src/bundled-plugins/security/permissions.ts +12 -0
  32. package/src/bundled-plugins/security/policies/git-exfil.ts +51 -18
  33. package/src/bundled-plugins/tool-result-cap/README.md +9 -4
  34. package/src/bundled-plugins/tool-result-cap/cap-jsonl.ts +115 -0
  35. package/src/bundled-plugins/tool-result-cap/cap-result.ts +25 -13
  36. package/src/bundled-plugins/tool-result-cap/index.ts +16 -2
  37. package/src/channels/adapters/discord-bot-classify.ts +2 -6
  38. package/src/channels/adapters/discord-bot.ts +4 -45
  39. package/src/channels/adapters/kakaotalk-classify.ts +3 -7
  40. package/src/channels/adapters/kakaotalk.ts +28 -47
  41. package/src/channels/adapters/slack-bot-classify.ts +2 -6
  42. package/src/channels/adapters/slack-bot.ts +4 -50
  43. package/src/channels/adapters/telegram-bot-classify.ts +8 -10
  44. package/src/channels/adapters/telegram-bot.ts +3 -16
  45. package/src/channels/index.ts +3 -2
  46. package/src/channels/manager.ts +15 -1
  47. package/src/channels/persistence.ts +44 -10
  48. package/src/channels/router.ts +228 -19
  49. package/src/channels/schema.ts +6 -156
  50. package/src/cli/channel.ts +200 -4
  51. package/src/cli/compose-usage.ts +182 -0
  52. package/src/cli/compose.ts +33 -0
  53. package/src/cli/hostd.ts +49 -1
  54. package/src/cli/index.ts +4 -0
  55. package/src/cli/init.ts +809 -300
  56. package/src/cli/model.ts +244 -0
  57. package/src/cli/provider.ts +404 -0
  58. package/src/cli/reload.ts +11 -3
  59. package/src/cli/role.ts +156 -0
  60. package/src/cli/run.ts +3 -1
  61. package/src/cli/tui.ts +13 -3
  62. package/src/cli/usage-args.ts +47 -0
  63. package/src/cli/usage.ts +97 -0
  64. package/src/compose/index.ts +1 -0
  65. package/src/compose/usage.ts +65 -0
  66. package/src/config/config.ts +491 -19
  67. package/src/config/index.ts +15 -1
  68. package/src/config/models-mutation.ts +200 -0
  69. package/src/config/providers-mutation.ts +250 -0
  70. package/src/config/providers.ts +141 -2
  71. package/src/config/reloadable.ts +15 -4
  72. package/src/container/index.ts +6 -1
  73. package/src/container/port.ts +10 -0
  74. package/src/container/require-running.ts +33 -0
  75. package/src/container/start.ts +81 -63
  76. package/src/cron/consumer.ts +22 -2
  77. package/src/cron/index.ts +45 -4
  78. package/src/cron/schema.ts +104 -0
  79. package/src/doctor/checks.ts +51 -34
  80. package/src/doctor/plugin-bridge.ts +28 -4
  81. package/src/git/system-commit.ts +103 -0
  82. package/src/hostd/daemon.ts +16 -0
  83. package/src/hostd/kakao-renewal-manager.ts +223 -0
  84. package/src/hostd/paths.ts +7 -0
  85. package/src/init/dockerfile.ts +36 -10
  86. package/src/init/gitignore.ts +1 -1
  87. package/src/init/index.ts +213 -85
  88. package/src/init/kakaotalk-auth.ts +18 -1
  89. package/src/init/models-dev.ts +26 -1
  90. package/src/init/run-owner-claim.ts +77 -0
  91. package/src/permissions/builtins.ts +70 -0
  92. package/src/permissions/grant.ts +99 -0
  93. package/src/permissions/index.ts +29 -0
  94. package/src/permissions/match-rule.ts +305 -0
  95. package/src/permissions/permissions.ts +196 -0
  96. package/src/permissions/resolve.ts +80 -0
  97. package/src/permissions/schema.ts +79 -0
  98. package/src/plugin/context.ts +8 -4
  99. package/src/plugin/define.ts +2 -0
  100. package/src/plugin/index.ts +2 -0
  101. package/src/plugin/manager.ts +41 -0
  102. package/src/plugin/registry.ts +9 -0
  103. package/src/plugin/types.ts +35 -1
  104. package/src/reload/client.ts +25 -1
  105. package/src/role-claim/client.ts +182 -0
  106. package/src/role-claim/code.ts +53 -0
  107. package/src/role-claim/controller.ts +194 -0
  108. package/src/role-claim/index.ts +19 -0
  109. package/src/role-claim/match-rule.ts +43 -0
  110. package/src/role-claim/pending.ts +100 -0
  111. package/src/run/channel-session-factory.ts +76 -5
  112. package/src/run/index.ts +68 -7
  113. package/src/secrets/encryption.ts +116 -0
  114. package/src/secrets/kakao-renewal.ts +248 -0
  115. package/src/secrets/kakao-store.ts +66 -7
  116. package/src/secrets/keys.ts +173 -0
  117. package/src/secrets/schema.ts +23 -0
  118. package/src/secrets/storage.ts +83 -0
  119. package/src/server/index.ts +198 -71
  120. package/src/shared/index.ts +4 -0
  121. package/src/shared/protocol.ts +27 -0
  122. package/src/skills/typeclaw-channel-kakaotalk/SKILL.md +3 -3
  123. package/src/skills/typeclaw-config/SKILL.md +104 -112
  124. package/src/skills/typeclaw-memory/SKILL.md +9 -9
  125. package/src/skills/typeclaw-permissions/SKILL.md +166 -0
  126. package/src/stream/types.ts +7 -1
  127. package/src/tui/client.ts +66 -5
  128. package/src/tui/index.ts +61 -9
  129. package/src/usage/aggregate.ts +117 -0
  130. package/src/usage/format.ts +30 -0
  131. package/src/usage/index.ts +68 -0
  132. package/src/usage/report.ts +354 -0
  133. package/src/usage/scan.ts +186 -0
  134. package/typeclaw.schema.json +134 -98
package/src/cli/hostd.ts CHANGED
@@ -3,6 +3,7 @@ import { defineCommand } from 'citty'
3
3
  import { loadConfigSync, validateConfig, type Config, type ValidateConfigResult } from '@/config'
4
4
  import { start, stop, type StartOptions, type StartResult, type StopResult } from '@/container'
5
5
  import { startDaemon, type DaemonLogEvent, type RestartPreflight } from '@/hostd/daemon'
6
+ import { createKakaoRenewalManager } from '@/hostd/kakao-renewal-manager'
6
7
  import { createPortbrokerManager } from '@/hostd/portbroker-manager'
7
8
  import type { SupervisorLogEvent, SupervisorRestart } from '@/hostd/supervisor'
8
9
  import { computeSourceVersion, resolveSrcRoot, UNVERSIONED_SENTINEL } from '@/hostd/version'
@@ -22,19 +23,35 @@ export const hostdCommand = defineCommand({
22
23
  onLog: (msg) => writeLogLine(msg),
23
24
  })
24
25
 
26
+ const hostdRestart = buildHostdRestart(cliEntry, defaultRestartDeps, version)
27
+ const kakaoRenewal = createKakaoRenewalManager({
28
+ onLog: (event) => writeLogLine(formatLog(event)),
29
+ onRenewalOk: async ({ containerName, cwd }) => {
30
+ // Restart the container so the in-memory KakaoTalk LOCO client picks
31
+ // up the renewed tokens from secrets.json. Without this, the cron
32
+ // would write fresh tokens but the running adapter would keep using
33
+ // the old token in its closure and still 401 at the ~7-day wall.
34
+ const result = await hostdRestart({ containerName, cwd })
35
+ if (!result.ok) throw new Error(result.reason)
36
+ },
37
+ shouldRenew: ({ cwd }) => kakaoChannelConfigured(cwd),
38
+ })
39
+
25
40
  const daemon = await startDaemon({
26
41
  onLog: (e) => writeLogLine(formatLog(e)),
27
42
  version,
28
43
  onShutdown: () => process.exit(0),
29
44
  portbroker,
45
+ kakaoRenewal,
30
46
  restartPreflight: buildHostdRestartPreflight(cliEntry, version),
31
- restart: buildHostdRestart(cliEntry, defaultRestartDeps, version),
47
+ restart: hostdRestart,
32
48
  })
33
49
 
34
50
  const shutdown = (): void => {
35
51
  void daemon
36
52
  .stop()
37
53
  .then(() => portbroker.drain())
54
+ .then(() => kakaoRenewal.drain())
38
55
  .then(() => process.exit(0))
39
56
  }
40
57
  process.on('SIGTERM', shutdown)
@@ -135,6 +152,37 @@ function formatLog(event: DaemonLogEvent | SupervisorLogEvent): string {
135
152
  return formatPortForwardEvent(event.event)
136
153
  case 'tailscale-serve-event':
137
154
  return formatTailscaleServeEvent(event.event)
155
+ case 'kakao-renewal-tick-start':
156
+ return `[hostd] kakao renewal tick started for ${event.containerName}`
157
+ case 'kakao-renewal-tick-skipped':
158
+ return `[hostd] kakao renewal skipped for ${event.containerName}: ${event.reason}${event.ageMs !== undefined ? ` (age=${Math.round(event.ageMs / 1000 / 60 / 60)}h)` : ''}`
159
+ case 'kakao-renewal-tick-ok':
160
+ return `[hostd] kakao renewal OK for ${event.containerName} account=${event.accountId} (was last updated ${event.previousUpdatedAt})`
161
+ case 'kakao-renewal-tick-reauth-required':
162
+ return `[hostd] kakao renewal REAUTH REQUIRED for ${event.containerName} account=${event.accountId} reason=${event.reason} — ${event.message}`
163
+ case 'kakao-renewal-tick-transient-failure':
164
+ return `[hostd] kakao renewal transient failure for ${event.containerName} account=${event.accountId}: ${event.reason}`
165
+ case 'kakao-renewal-tick-error':
166
+ return `[hostd] kakao renewal ERROR for ${event.containerName}: ${event.error}`
167
+ case 'kakao-renewal-restart-scheduled':
168
+ return `[hostd] kakao renewal scheduled container restart for ${event.containerName} account=${event.accountId}`
169
+ case 'kakao-renewal-restart-failed':
170
+ return `[hostd] kakao renewal container restart FAILED for ${event.containerName} account=${event.accountId}: ${event.reason}`
171
+ }
172
+ }
173
+
174
+ // Reads the agent's typeclaw.json to decide whether the kakao renewal cron
175
+ // should run for this container. Without this, every typeclaw agent on the
176
+ // host gets a daily `no_account` skip event from the renewal manager — log
177
+ // spam for non-kakao agents. Returns false on read/parse errors so the
178
+ // renewal cron stays silent for agents we can't classify; the kakao adapter
179
+ // itself would surface the real config issue on its next start.
180
+ function kakaoChannelConfigured(cwd: string): boolean {
181
+ try {
182
+ const cfg = loadConfigSync(cwd)
183
+ return cfg.channels?.kakaotalk !== undefined
184
+ } catch {
185
+ return false
138
186
  }
139
187
  }
140
188
 
package/src/cli/index.ts CHANGED
@@ -23,7 +23,11 @@ const main = defineCommand({
23
23
  shell: () => import('./shell').then((m) => m.shellCommand),
24
24
  compose: () => import('./compose').then((m) => m.composeCommand),
25
25
  channel: () => import('./channel').then((m) => m.channelCommand),
26
+ role: () => import('./role').then((m) => m.roleCommand),
27
+ provider: () => import('./provider').then((m) => m.providerCommand),
28
+ model: () => import('./model').then((m) => m.modelCommand),
26
29
  doctor: () => import('./doctor').then((m) => m.doctorCommand),
30
+ usage: () => import('./usage').then((m) => m.usageCommand),
27
31
  _hostd: () => import('./hostd').then((m) => m.hostdCommand),
28
32
  },
29
33
  })