typeclaw 0.39.6 → 0.40.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 (72) hide show
  1. package/package.json +1 -1
  2. package/scripts/dump-system-prompt.ts +4 -50
  3. package/src/agent/auth-reloadable.ts +24 -0
  4. package/src/agent/auth.ts +12 -0
  5. package/src/agent/index.ts +18 -58
  6. package/src/agent/todo/continuation-policy.ts +8 -0
  7. package/src/agent/todo/continuation-state.ts +41 -7
  8. package/src/agent/todo/continuation-wiring.ts +26 -0
  9. package/src/bundled-plugins/guard/policies/non-workspace-write.ts +0 -2
  10. package/src/bundled-plugins/guard/policy.ts +0 -5
  11. package/src/bundled-plugins/memory/README.md +26 -37
  12. package/src/bundled-plugins/memory/index.ts +32 -144
  13. package/src/bundled-plugins/memory/load-memory.ts +7 -121
  14. package/src/bundled-plugins/memory/memory-logger.ts +12 -6
  15. package/src/bundled-plugins/memory/search-command.ts +124 -0
  16. package/src/bundled-plugins/memory/vector/doctor.ts +1 -1
  17. package/src/bundled-plugins/memory/vector/embedder.ts +4 -5
  18. package/src/bundled-plugins/memory/vector/hybrid.ts +47 -5
  19. package/src/bundled-plugins/memory/vector/relevance-gate.ts +11 -7
  20. package/src/bundled-plugins/memory/vector/script.ts +87 -0
  21. package/src/channels/adapters/describe-error.ts +40 -0
  22. package/src/channels/adapters/discord.ts +9 -12
  23. package/src/channels/adapters/kakaotalk.ts +14 -17
  24. package/src/channels/adapters/line.ts +11 -14
  25. package/src/channels/adapters/slack-bot.ts +15 -18
  26. package/src/channels/adapters/slack.ts +45 -21
  27. package/src/channels/adapters/telegram-bot.ts +15 -18
  28. package/src/channels/adapters/webex-bot.ts +13 -14
  29. package/src/channels/adapters/webex.ts +14 -15
  30. package/src/channels/router.ts +60 -1
  31. package/src/cli/command-meta.ts +7 -16
  32. package/src/cli/compose.ts +21 -1
  33. package/src/cli/cron.ts +1 -1
  34. package/src/cli/docker-preflight.ts +42 -0
  35. package/src/cli/doctor.ts +1 -1
  36. package/src/cli/dreams.ts +1 -1
  37. package/src/cli/hostd.ts +12 -3
  38. package/src/cli/index.ts +1 -1
  39. package/src/cli/init.ts +24 -22
  40. package/src/cli/inspect.ts +1 -1
  41. package/src/cli/logs.ts +7 -0
  42. package/src/cli/memory.ts +85 -0
  43. package/src/cli/model.ts +1 -1
  44. package/src/cli/provider.ts +8 -1
  45. package/src/cli/reload.ts +6 -0
  46. package/src/cli/restart.ts +7 -0
  47. package/src/cli/shell.ts +7 -0
  48. package/src/cli/start.ts +7 -0
  49. package/src/cli/status.ts +9 -0
  50. package/src/cli/stop.ts +7 -0
  51. package/src/cli/tui.ts +6 -0
  52. package/src/config/config.ts +31 -8
  53. package/src/container/docker-app.ts +253 -0
  54. package/src/container/index.ts +11 -0
  55. package/src/container/start.ts +85 -41
  56. package/src/hostd/current-host-daemon.ts +21 -0
  57. package/src/hostd/daemon.ts +27 -3
  58. package/src/hostd/supervisor.ts +18 -3
  59. package/src/plugin/hooks.ts +3 -4
  60. package/src/plugin/types.ts +1 -1
  61. package/src/role-claim/client.ts +6 -1
  62. package/src/run/channel-session-factory.ts +3 -5
  63. package/src/run/index.ts +50 -17
  64. package/src/server/command-runner.ts +2 -11
  65. package/src/server/index.ts +8 -0
  66. package/src/skills/typeclaw-memory/SKILL.md +2 -2
  67. package/src/skills/typeclaw-plugins/SKILL.md +1 -1
  68. package/typeclaw.schema.json +1 -23
  69. package/src/bundled-plugins/guard/policies/memory-retrieval-cache-write.ts +0 -43
  70. package/src/bundled-plugins/memory/memory-retrieval.ts +0 -111
  71. package/src/bundled-plugins/memory/vector/cache-write.ts +0 -19
  72. package/src/bundled-plugins/memory/vector/config.ts +0 -28
package/src/cli/hostd.ts CHANGED
@@ -2,6 +2,7 @@ import { defineCommand } from 'citty'
2
2
 
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
+ import { createCurrentHostDaemonHolder } from '@/hostd/current-host-daemon'
5
6
  import { startDaemon, type DaemonLogEvent, type RestartPreflight } from '@/hostd/daemon'
6
7
  import { createKakaoRenewalManager } from '@/hostd/kakao-renewal-manager'
7
8
  import { createPortbrokerManager } from '@/hostd/portbroker-manager'
@@ -26,6 +27,10 @@ export const hostdCommand = defineCommand({
26
27
  })
27
28
 
28
29
  const hostdRestart = buildHostdRestart(cliEntry, defaultRestartDeps, version)
30
+ // Renewal restarts call hostdRestart directly (not via the restart RPC), so
31
+ // they must thread currentHostDaemon themselves to get the in-process
32
+ // registration path. The daemon populates this holder once booted.
33
+ const currentHostDaemonHolder = createCurrentHostDaemonHolder()
29
34
  const kakaoRenewal = createKakaoRenewalManager({
30
35
  onLog: (event) => writeLogLine(formatLog(event)),
31
36
  onRenewalOk: async ({ containerName, cwd }) => {
@@ -33,7 +38,8 @@ export const hostdCommand = defineCommand({
33
38
  // up the renewed tokens from secrets.json. Without this, the cron
34
39
  // would write fresh tokens but the running adapter would keep using
35
40
  // the old token in its closure and still 401 at the ~7-day wall.
36
- const result = await hostdRestart({ containerName, cwd })
41
+ const currentHostDaemon = await currentHostDaemonHolder.ready()
42
+ const result = await hostdRestart({ containerName, cwd, currentHostDaemon })
37
43
  if (!result.ok) throw new Error(result.reason)
38
44
  },
39
45
  shouldRenew: ({ cwd }) => kakaoChannelConfigured(cwd),
@@ -45,7 +51,8 @@ export const hostdCommand = defineCommand({
45
51
  // secrets.json. Without this, the cron writes a fresh token but the
46
52
  // running adapter keeps the old token in its getToken closure and still
47
53
  // 401s on every outbound REST call + KMS key fetch.
48
- const result = await hostdRestart({ containerName, cwd })
54
+ const currentHostDaemon = await currentHostDaemonHolder.ready()
55
+ const result = await hostdRestart({ containerName, cwd, currentHostDaemon })
49
56
  if (!result.ok) throw new Error(result.reason)
50
57
  },
51
58
  shouldRenew: ({ cwd }) => webexChannelConfigured(cwd),
@@ -58,6 +65,7 @@ export const hostdCommand = defineCommand({
58
65
  portbroker,
59
66
  kakaoRenewal,
60
67
  webexRenewal,
68
+ currentHostDaemonHolder,
61
69
  restartPreflight: buildHostdRestartPreflight(cliEntry, version, defaultPreflightDeps),
62
70
  restart: hostdRestart,
63
71
  })
@@ -96,7 +104,7 @@ export function buildHostdRestart(
96
104
  deps: HostdRestartDeps = defaultRestartDeps,
97
105
  daemonVersion?: string,
98
106
  ): SupervisorRestart {
99
- return async ({ containerName, cwd, build = false }) => {
107
+ return async ({ containerName, cwd, build = false, currentHostDaemon }) => {
100
108
  const drift = await detectSourceDrift(cliEntry, daemonVersion)
101
109
  if (drift) return { ok: false, reason: drift }
102
110
 
@@ -114,6 +122,7 @@ export function buildHostdRestart(
114
122
  forceBuild: build,
115
123
  cliEntry,
116
124
  reuseCurrentHostDaemon: true,
125
+ ...(currentHostDaemon ? { currentHostDaemon } : {}),
117
126
  })
118
127
  if (!startResult.ok) return { ok: false, reason: `start failed: ${startResult.reason}` }
119
128
  return { ok: true }
package/src/cli/index.ts CHANGED
@@ -25,7 +25,7 @@ const main = defineCommand({
25
25
  reload: () => import('./reload').then((m) => m.reload),
26
26
  logs: () => import('./logs').then((m) => m.logsCommand),
27
27
  inspect: () => import('./inspect').then((m) => m.inspectCommand),
28
- dreams: () => import('./dreams').then((m) => m.dreamsCommand),
28
+ memory: () => import('./memory').then((m) => m.memoryCommand),
29
29
  shell: () => import('./shell').then((m) => m.shellCommand),
30
30
  compose: () => import('./compose').then((m) => m.composeCommand),
31
31
  channel: () => import('./channel').then((m) => m.channelCommand),
package/src/cli/init.ts CHANGED
@@ -30,7 +30,13 @@ import {
30
30
  type KnownProviderId,
31
31
  type KnownProviderVendorId,
32
32
  } from '@/config/providers'
33
- import { checkDockerAvailable, type DockerAvailability } from '@/container'
33
+ import {
34
+ checkDockerAvailable,
35
+ detectInstalledDockerApps,
36
+ pickRuntimeToNudge,
37
+ renderDockerUnavailableGuidance,
38
+ type DockerAvailability,
39
+ } from '@/container'
34
40
  import {
35
41
  appendOrReplaceEnvKey,
36
42
  findAgentDir,
@@ -1928,31 +1934,27 @@ function reportProgress(
1928
1934
  }
1929
1935
  }
1930
1936
 
1937
+ function renderPreflightFailure(result: Extract<DockerAvailability, { ok: false }>): {
1938
+ summary: string
1939
+ lines: string[]
1940
+ } {
1941
+ const detail = result.reason === 'daemon-down' ? result.detail : undefined
1942
+ const installed = detectInstalledDockerApps()
1943
+ const nudge = pickRuntimeToNudge(process.env, detail, installed)
1944
+ return renderDockerUnavailableGuidance(result, {
1945
+ platform: process.platform,
1946
+ nudge,
1947
+ installed,
1948
+ retryHint: 'Then re-run `typeclaw init`.',
1949
+ })
1950
+ }
1951
+
1931
1952
  function preflightFailureSummary(result: Extract<DockerAvailability, { ok: false }>): string {
1932
- if (result.reason === 'binary-missing') return 'Docker is not installed.'
1933
- return 'Docker is installed but the daemon is not reachable.'
1953
+ return renderPreflightFailure(result).summary
1934
1954
  }
1935
1955
 
1936
1956
  function preflightFailureGuidance(result: Extract<DockerAvailability, { ok: false }>): string[] {
1937
- if (result.reason === 'binary-missing') {
1938
- return [
1939
- 'TypeClaw runs every agent inside its own Docker container, so Docker is required.',
1940
- '',
1941
- 'Install one of:',
1942
- ' • Docker Desktop — https://docs.docker.com/get-docker/',
1943
- ' • OrbStack (macOS, lighter) — https://orbstack.dev',
1944
- '',
1945
- 'Then re-run `typeclaw init`.',
1946
- ]
1947
- }
1948
- return [
1949
- 'The docker CLI is on $PATH, but the daemon refused the connection:',
1950
- '',
1951
- ` ${result.detail}`,
1952
- '',
1953
- 'Start Docker Desktop / OrbStack (or `sudo systemctl start docker` on Linux),',
1954
- 'then re-run `typeclaw init`.',
1955
- ]
1957
+ return renderPreflightFailure(result).lines
1956
1958
  }
1957
1959
 
1958
1960
  function reportKakaotalkAuth(result: KakaotalkAuthResult): string {
@@ -27,7 +27,7 @@ const ESC_DEBOUNCE_MS = 50
27
27
  export const inspectCommand = defineCommand({
28
28
  meta: {
29
29
  name: 'inspect',
30
- description: 'session viewer: pick a session, the live TUI, or container logs to observe (host stage)',
30
+ description: 'session viewer: a session, the live TUI, or container logs',
31
31
  },
32
32
  args: {
33
33
  session: {
package/src/cli/logs.ts CHANGED
@@ -2,6 +2,7 @@ import { defineCommand } from 'citty'
2
2
 
3
3
  import { logs, parseTailValue } from '@/container'
4
4
 
5
+ import { preflightDocker, printDockerGuidance } from './docker-preflight'
5
6
  import { runInspectViewer } from './inspect'
6
7
  import { requireAgentDir } from './require-agent-dir'
7
8
  import { c, errorLine } from './ui'
@@ -51,6 +52,12 @@ export const logsCommand = defineCommand({
51
52
  process.exit(exitCode)
52
53
  }
53
54
 
55
+ const preflight = await preflightDocker()
56
+ if (!preflight.ok) {
57
+ printDockerGuidance(preflight)
58
+ process.exit(1)
59
+ }
60
+
54
61
  if (args.follow) {
55
62
  console.log(c.cyan('Streaming container logs...'))
56
63
  } else {
@@ -0,0 +1,85 @@
1
+ import { defineCommand } from 'citty'
2
+
3
+ import { proxyContainerCommand } from './container-command-client'
4
+ import { dreamsCommand } from './dreams'
5
+ import { requireAgentDir } from './require-agent-dir'
6
+ import { errorLine } from './ui'
7
+
8
+ const MEMORY_SEARCH_COMMAND = 'memory-search'
9
+
10
+ const searchSub = defineCommand({
11
+ meta: {
12
+ name: 'search',
13
+ description: 'vector-search the agent long-term memory inside the running container (host stage)',
14
+ },
15
+ args: {
16
+ query: {
17
+ type: 'positional',
18
+ description: 'the search query',
19
+ required: true,
20
+ },
21
+ topK: {
22
+ type: 'string',
23
+ description: 'return at most N ranked results (default 10)',
24
+ },
25
+ json: {
26
+ type: 'boolean',
27
+ description: 'emit raw JSON results instead of formatted text',
28
+ default: false,
29
+ },
30
+ },
31
+ async run({ args }) {
32
+ const cwd = requireAgentDir()
33
+ const topK = parseTopK(args.topK)
34
+ if (topK === 'invalid') {
35
+ process.stderr.write(`${errorLine('--topK must be a positive integer')}\n`)
36
+ process.exit(2)
37
+ }
38
+
39
+ const result = await proxyContainerCommand({
40
+ agentDir: cwd,
41
+ commandName: MEMORY_SEARCH_COMMAND,
42
+ args: {
43
+ query: args.query,
44
+ json: args.json === true,
45
+ ...(topK !== undefined ? { topK } : {}),
46
+ },
47
+ stdout: nodeWritable(process.stdout),
48
+ stderr: nodeWritable(process.stderr),
49
+ })
50
+
51
+ if (!result.ok) {
52
+ process.stderr.write(`${errorLine(result.message)}\n`)
53
+ process.exit(result.exitCode)
54
+ }
55
+ process.exit(result.exitCode)
56
+ },
57
+ })
58
+
59
+ export const memoryCommand = defineCommand({
60
+ meta: {
61
+ name: 'memory',
62
+ description: "browse and search the agent's long-term memory",
63
+ },
64
+ subCommands: {
65
+ dreams: dreamsCommand,
66
+ search: searchSub,
67
+ },
68
+ })
69
+
70
+ function parseTopK(raw: unknown): number | undefined | 'invalid' {
71
+ if (typeof raw !== 'string') return undefined
72
+ // Whole-string match, not Number.parseInt — parseInt silently truncates
73
+ // "1.5" to 1 and "10abc" to 10, proxying invalid input as a valid-looking
74
+ // topK. The container's max-50 zod check stays as the upper-bound guard.
75
+ if (!/^[1-9]\d*$/.test(raw)) return 'invalid'
76
+ return Number(raw)
77
+ }
78
+
79
+ function nodeWritable(stream: NodeJS.WriteStream): WritableStream<Uint8Array> {
80
+ return new WritableStream<Uint8Array>({
81
+ write(chunk) {
82
+ stream.write(chunk)
83
+ },
84
+ })
85
+ }
package/src/cli/model.ts CHANGED
@@ -277,7 +277,7 @@ const listSub = defineCommand({
277
277
  export const modelCommand = defineCommand({
278
278
  meta: {
279
279
  name: 'model',
280
- description: 'manage model profiles in typeclaw.json (models.default, models.fast, …)',
280
+ description: 'manage model profiles in typeclaw.json (models.default, ...)',
281
281
  },
282
282
  subCommands: {
283
283
  set: setSub,
@@ -438,5 +438,12 @@ function describeSource(source: CredentialSource): string {
438
438
 
439
439
  function nextStepHints(opts: { credentialChanged: boolean }): { label: string; command: string }[] {
440
440
  if (!opts.credentialChanged) return []
441
- return [{ label: 'If the agent is running:', command: 'typeclaw reload' }]
441
+ // secrets.json is bind-mounted live, so `typeclaw reload` clears the provider
442
+ // auth cache and the next call re-reads this file. Editing a key's value in
443
+ // .env instead still needs a restart — container env is fixed at `docker run`
444
+ // — so surface both paths to the user, not just reload.
445
+ return [
446
+ { label: 'Apply the secrets.json change:', command: 'typeclaw reload' },
447
+ { label: 'If you changed a key in .env:', command: 'typeclaw restart' },
448
+ ]
442
449
  }
package/src/cli/reload.ts CHANGED
@@ -4,6 +4,7 @@ import { requireContainerRunning, resolveHostPort, resolveTuiToken } from '@/con
4
4
  import { findAgentDir } from '@/init'
5
5
  import { requestReloadWithFallback, type ReloadResult } from '@/reload'
6
6
 
7
+ import { preflightDocker, printDockerGuidance } from './docker-preflight'
7
8
  import { c, errorLine, spinner } from './ui'
8
9
 
9
10
  export const reload = defineCommand({
@@ -84,6 +85,11 @@ export function printReloadRecoveryHint(recoveredHostError: string | undefined):
84
85
 
85
86
  async function defaultTarget(): Promise<{ url: string; cwd: string; token: string | null }> {
86
87
  const cwd = findAgentDir(process.cwd()) ?? process.cwd()
88
+ const preflight = await preflightDocker()
89
+ if (!preflight.ok) {
90
+ printDockerGuidance(preflight)
91
+ process.exit(1)
92
+ }
87
93
  const precheck = await requireContainerRunning({ cwd })
88
94
  if (!precheck.ok) {
89
95
  console.error(errorLine(precheck.reason))
@@ -5,6 +5,7 @@ import { config, validateConfig } from '@/config'
5
5
  import { start, stop } from '@/container'
6
6
  import { findAgentDir, isInitialized } from '@/init'
7
7
 
8
+ import { preflightDocker, printDockerGuidance } from './docker-preflight'
8
9
  import { guardIncompleteInit } from './incomplete-init'
9
10
  import { c, errorLine, renderStartSuccess, reportConfigWarnings, spinner } from './ui'
10
11
 
@@ -63,6 +64,12 @@ export const restartCommand = defineCommand({
63
64
  }
64
65
  reportConfigWarnings(validated.warnings)
65
66
 
67
+ const preflight = await preflightDocker()
68
+ if (!preflight.ok) {
69
+ printDockerGuidance(preflight)
70
+ process.exit(1)
71
+ }
72
+
66
73
  const stopSpin = spinner()
67
74
  stopSpin.start('Stopping container...')
68
75
  const stopped = await stop({ cwd })
package/src/cli/shell.ts CHANGED
@@ -2,6 +2,7 @@ import { defineCommand } from 'citty'
2
2
 
3
3
  import { shell } from '@/container'
4
4
 
5
+ import { preflightDocker, printDockerGuidance } from './docker-preflight'
5
6
  import { requireAgentDir } from './require-agent-dir'
6
7
  import { c, errorLine } from './ui'
7
8
 
@@ -20,6 +21,12 @@ export const shellCommand = defineCommand({
20
21
  async run({ args }) {
21
22
  const cwd = requireAgentDir()
22
23
 
24
+ const preflight = await preflightDocker()
25
+ if (!preflight.ok) {
26
+ printDockerGuidance(preflight)
27
+ process.exit(1)
28
+ }
29
+
23
30
  console.log(c.cyan(`Attaching ${args.shell} inside the container...`))
24
31
 
25
32
  const result = await shell({ cwd, shell: args.shell })
package/src/cli/start.ts CHANGED
@@ -5,6 +5,7 @@ import { config, validateConfig } from '@/config'
5
5
  import { start } from '@/container'
6
6
  import { findAgentDir, isInitialized } from '@/init'
7
7
 
8
+ import { preflightDocker, printDockerGuidance } from './docker-preflight'
8
9
  import { guardIncompleteInit } from './incomplete-init'
9
10
  import { errorLine, renderStartSuccess, reportConfigWarnings, spinner } from './ui'
10
11
 
@@ -63,6 +64,12 @@ export const startCommand = defineCommand({
63
64
  }
64
65
  reportConfigWarnings(validated.warnings)
65
66
 
67
+ const preflight = await preflightDocker()
68
+ if (!preflight.ok) {
69
+ printDockerGuidance(preflight)
70
+ process.exit(1)
71
+ }
72
+
66
73
  const s = spinner()
67
74
  s.start('Starting container...')
68
75
  const result = await start({
package/src/cli/status.ts CHANGED
@@ -7,6 +7,8 @@ import { isDaemonReachable, send } from '@/hostd'
7
7
  import type { StatusResult } from '@/hostd'
8
8
  import { findAgentDir } from '@/init'
9
9
 
10
+ import { preflightDocker, printDockerGuidance } from './docker-preflight'
11
+
10
12
  export type HostdStatus =
11
13
  | { kind: 'unreachable' }
12
14
  | { kind: 'not-registered'; reason: string }
@@ -25,6 +27,13 @@ export const statusCommand = defineCommand({
25
27
  },
26
28
  async run() {
27
29
  const cwd = findAgentDir(process.cwd()) ?? process.cwd()
30
+
31
+ const preflight = await preflightDocker()
32
+ if (!preflight.ok) {
33
+ printDockerGuidance(preflight)
34
+ process.exit(1)
35
+ }
36
+
28
37
  const container = await containerStatus({ cwd })
29
38
  const hostd = await fetchHostdStatus(container.containerName)
30
39
 
package/src/cli/stop.ts CHANGED
@@ -2,6 +2,7 @@ import { defineCommand } from 'citty'
2
2
 
3
3
  import { stop } from '@/container'
4
4
 
5
+ import { preflightDocker, printDockerGuidance } from './docker-preflight'
5
6
  import { requireAgentDir } from './require-agent-dir'
6
7
  import { c, spinner } from './ui'
7
8
 
@@ -13,6 +14,12 @@ export const stopCommand = defineCommand({
13
14
  async run() {
14
15
  const cwd = requireAgentDir()
15
16
 
17
+ const preflight = await preflightDocker()
18
+ if (!preflight.ok) {
19
+ printDockerGuidance(preflight)
20
+ process.exit(1)
21
+ }
22
+
16
23
  const s = spinner()
17
24
  s.start('Stopping container...')
18
25
  const result = await stop({ cwd })
package/src/cli/tui.ts CHANGED
@@ -5,6 +5,7 @@ import { CLI_VERSION } from '@/init/cli-version'
5
5
  import { runTuiViewer } from '@/inspect'
6
6
  import { formatVersionMismatchWarning } from '@/tui'
7
7
 
8
+ import { preflightDocker, printDockerGuidance } from './docker-preflight'
8
9
  import { runInspectViewer } from './inspect'
9
10
  import { requireAgentDir } from './require-agent-dir'
10
11
  import { errorLine } from './ui'
@@ -75,6 +76,11 @@ export const tui = defineCommand({
75
76
  })
76
77
 
77
78
  async function defaultUrl(cwd: string): Promise<string> {
79
+ const preflight = await preflightDocker()
80
+ if (!preflight.ok) {
81
+ printDockerGuidance(preflight)
82
+ process.exit(1)
83
+ }
78
84
  const precheck = await requireContainerRunning({ cwd })
79
85
  if (!precheck.ok) throw new Error(precheck.reason)
80
86
  const port = await resolveHostPort({ cwd })
@@ -1197,7 +1197,7 @@ export function loadConfigBundleSync(cwd: string): { config: Config; pluginConfi
1197
1197
  // `changed` is the boolean equivalent of `applied.length > 0` and is preserved
1198
1198
  // for back-compat with the many call sites that only care whether ANY rewrite
1199
1199
  // happened.
1200
- export type MigrationStep = { kind: 'drop-github-seeded-event-allowlist' }
1200
+ export type MigrationStep = { kind: 'drop-github-seeded-event-allowlist' } | { kind: 'drop-memory-vector-config' }
1201
1201
 
1202
1202
  export type MigrationResult = { json: unknown; changed: boolean; applied: MigrationStep[] }
1203
1203
 
@@ -1207,18 +1207,20 @@ export function migrateLegacyConfigShape(json: unknown): MigrationResult {
1207
1207
  }
1208
1208
 
1209
1209
  const obj = json as Record<string, unknown>
1210
- const hasSeededGithubEventAllowlist = isSeededGithubEventAllowlist(obj)
1211
- if (!hasSeededGithubEventAllowlist) {
1212
- return { json, changed: false, applied: [] }
1213
- }
1214
-
1215
1210
  const applied: MigrationStep[] = []
1216
1211
  const next: Record<string, unknown> = { ...obj }
1217
- if (hasSeededGithubEventAllowlist) {
1212
+
1213
+ if (isSeededGithubEventAllowlist(obj)) {
1218
1214
  dropSeededGithubEventAllowlist(next)
1219
1215
  applied.push({ kind: 'drop-github-seeded-event-allowlist' })
1220
1216
  }
1221
- return { json: next, changed: true, applied }
1217
+
1218
+ if (hasLegacyMemoryVectorConfig(obj)) {
1219
+ dropMemoryVectorConfig(next)
1220
+ applied.push({ kind: 'drop-memory-vector-config' })
1221
+ }
1222
+
1223
+ return { json: applied.length > 0 ? next : json, changed: applied.length > 0, applied }
1222
1224
  }
1223
1225
 
1224
1226
  // True when channels.github.eventAllowlist deep-equals an allowlist that
@@ -1243,6 +1245,23 @@ function dropSeededGithubEventAllowlist(next: Record<string, unknown>): void {
1243
1245
  next.channels = { ...channels, github: rest }
1244
1246
  }
1245
1247
 
1248
+ function hasLegacyMemoryVectorConfig(obj: Record<string, unknown>): boolean {
1249
+ const memory = obj.memory
1250
+ return isPlainObject(memory) && Object.prototype.hasOwnProperty.call(memory, 'vector')
1251
+ }
1252
+
1253
+ function dropMemoryVectorConfig(next: Record<string, unknown>): void {
1254
+ const memory = next.memory
1255
+ if (!isPlainObject(memory)) return
1256
+ const clone = { ...memory }
1257
+ delete clone.vector
1258
+ if (Object.keys(clone).length === 0) {
1259
+ delete next.memory
1260
+ return
1261
+ }
1262
+ next.memory = clone
1263
+ }
1264
+
1246
1265
  function arraysEqual(a: readonly unknown[], b: readonly unknown[]): boolean {
1247
1266
  if (a.length !== b.length) return false
1248
1267
  for (let i = 0; i < a.length; i++) {
@@ -1267,6 +1286,8 @@ function shortStepLabel(step: MigrationStep): string {
1267
1286
  switch (step.kind) {
1268
1287
  case 'drop-github-seeded-event-allowlist':
1269
1288
  return 'drop seeded channels.github.eventAllowlist'
1289
+ case 'drop-memory-vector-config':
1290
+ return 'drop memory.vector config'
1270
1291
  }
1271
1292
  }
1272
1293
 
@@ -1274,6 +1295,8 @@ function describeStep(step: MigrationStep): string {
1274
1295
  switch (step.kind) {
1275
1296
  case 'drop-github-seeded-event-allowlist':
1276
1297
  return 'drop seeded channels.github.eventAllowlist so it re-tracks the shipped default'
1298
+ case 'drop-memory-vector-config':
1299
+ return 'drop memory.vector config; vector memory is always on'
1277
1300
  }
1278
1301
  }
1279
1302