typeclaw 0.41.0 → 0.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/auth.schema.json +57 -0
- package/package.json +4 -4
- package/secrets.schema.json +57 -0
- package/src/agent/adaptive-thinking-compat.ts +79 -0
- package/src/agent/index.ts +89 -107
- package/src/agent/plugin-tools.ts +77 -130
- package/src/agent/provider-error.ts +37 -0
- package/src/agent/reload-tool.ts +1 -1
- package/src/agent/session-origin.ts +1 -0
- package/src/agent/subagents.ts +2 -2
- package/src/agent/system-prompt.ts +19 -5
- package/src/agent/tool-result-budget.ts +1 -1
- package/src/agent/tools/channel-history-render.ts +21 -0
- package/src/agent/tools/channel-history.ts +2 -17
- package/src/agent/tools/channel-read.ts +206 -0
- package/src/agent/tools/stream-snapshot.ts +8 -3
- package/src/bundled-plugins/agent-browser/index.ts +18 -8
- package/src/bundled-plugins/agent-browser/skills/agent-browser/SKILL.md +26 -2
- package/src/bundled-plugins/github-cli-auth/index.ts +25 -6
- package/src/bundled-plugins/memory/README.md +4 -1
- package/src/bundled-plugins/memory/belief-sentence.ts +50 -0
- package/src/bundled-plugins/memory/dreaming.ts +13 -6
- package/src/bundled-plugins/memory/load-memory.ts +22 -2
- package/src/bundled-plugins/memory/memory-logger.ts +1 -1
- package/src/bundled-plugins/memory/vector/hybrid.ts +73 -6
- package/src/bundled-plugins/memory/vector/passages.ts +2 -24
- package/src/bundled-plugins/memory/vector/truncation.ts +28 -0
- package/src/bundled-plugins/tool-result-cap/README.md +10 -1
- package/src/bundled-plugins/tool-result-cap/cap-result.ts +8 -0
- package/src/capabilities/control-plane.ts +24 -0
- package/src/capabilities/index.ts +2 -0
- package/src/capabilities/runtime.ts +30 -0
- package/src/channels/adapters/discord-bot.ts +112 -0
- package/src/channels/adapters/instagram-channel-resolver.ts +113 -0
- package/src/channels/adapters/instagram-classify.ts +69 -0
- package/src/channels/adapters/instagram-format.ts +8 -0
- package/src/channels/adapters/instagram.ts +346 -0
- package/src/channels/adapters/slack-bot.ts +147 -0
- package/src/channels/manager.ts +96 -44
- package/src/channels/router.ts +75 -2
- package/src/channels/schema.ts +5 -0
- package/src/channels/types.ts +46 -0
- package/src/cli/channel.ts +121 -9
- package/src/cli/hostd.ts +4 -3
- package/src/cli/init.ts +1 -0
- package/src/cli/logs.ts +2 -2
- package/src/cli/restart.ts +5 -3
- package/src/cli/shell.ts +2 -2
- package/src/cli/start.ts +2 -2
- package/src/cli/status.ts +37 -14
- package/src/cli/stop.ts +2 -2
- package/src/compose/restart.ts +4 -3
- package/src/compose/start.ts +2 -2
- package/src/compose/stop.ts +2 -2
- package/src/config/channels-mutation.ts +2 -1
- package/src/config/config.ts +10 -1
- package/src/config/providers.ts +61 -9
- package/src/container/controller.ts +104 -0
- package/src/container/index.ts +9 -0
- package/src/doctor/channel-checks.ts +28 -0
- package/src/hostd/daemon.ts +11 -7
- package/src/hostd/protocol.ts +2 -0
- package/src/init/index.ts +51 -2
- package/src/init/instagram-auth.ts +289 -0
- package/src/init/run-owner-claim.ts +1 -0
- package/src/inspect/logs-item.ts +2 -2
- package/src/mcp/client.ts +1 -1
- package/src/permissions/match-rule.ts +1 -1
- package/src/permissions/resolve.ts +1 -0
- package/src/role-claim/match-rule.ts +2 -1
- package/src/run/index.ts +21 -9
- package/src/run/{codex-fetch-observer.ts → llm-fetch-observer.ts} +182 -82
- package/src/sandbox/availability.ts +2 -2
- package/src/sandbox/build.ts +1 -1
- package/src/sandbox/policy.ts +2 -2
- package/src/secrets/discord-store.ts +4 -13
- package/src/secrets/instagram-store.ts +103 -0
- package/src/secrets/kakao-store.ts +4 -13
- package/src/secrets/line-store.ts +4 -13
- package/src/secrets/schema.ts +18 -0
- package/src/secrets/secrets-provider.ts +86 -0
- package/src/secrets/slack-store.ts +4 -13
- package/src/secrets/webex-store.ts +4 -13
- package/src/server/index.ts +2 -2
- package/src/skills/typeclaw-channel-instagram/SKILL.md +30 -0
- package/src/skills/typeclaw-config/SKILL.md +5 -3
- package/src/skills/typeclaw-plugins/SKILL.md +1 -1
- package/src/stream/broker.ts +4 -3
- package/src/stream/types.ts +1 -0
- package/typeclaw.schema.json +175 -1
package/src/cli/channel.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
type ChannelListEntry,
|
|
13
13
|
type GithubConfigCleanup,
|
|
14
14
|
} from '@/config/channels-mutation'
|
|
15
|
-
import {
|
|
15
|
+
import { resolveController } from '@/container'
|
|
16
16
|
import {
|
|
17
17
|
CHANNEL_KINDS,
|
|
18
18
|
appendOrReplaceEnvKey,
|
|
@@ -30,12 +30,14 @@ import {
|
|
|
30
30
|
type DiscordAuthResult,
|
|
31
31
|
type GithubCredentialPatch,
|
|
32
32
|
type GithubTunnelProvider,
|
|
33
|
+
type InstagramAuthResult,
|
|
33
34
|
type KakaotalkAuthResult,
|
|
34
35
|
type LineAuthResult,
|
|
35
36
|
type SlackAuthResult,
|
|
36
37
|
type WebexAuthResult,
|
|
37
38
|
} from '@/init'
|
|
38
39
|
import { runDiscordBootstrap } from '@/init/discord-auth'
|
|
40
|
+
import { runInstagramBootstrap, type InstagramLoginCallbacks } from '@/init/instagram-auth'
|
|
39
41
|
import { runKakaotalkBootstrap } from '@/init/kakaotalk-auth'
|
|
40
42
|
import { runLineBootstrap } from '@/init/line-auth'
|
|
41
43
|
import { runSlackBootstrap } from '@/init/slack-auth'
|
|
@@ -55,6 +57,7 @@ const CHANNEL_LABELS: Record<ChannelKind, string> = {
|
|
|
55
57
|
'telegram-bot': 'Telegram',
|
|
56
58
|
webex: 'Webex (User)',
|
|
57
59
|
'webex-bot': 'Webex',
|
|
60
|
+
instagram: 'Instagram',
|
|
58
61
|
line: 'LINE',
|
|
59
62
|
kakaotalk: 'KakaoTalk',
|
|
60
63
|
github: 'GitHub',
|
|
@@ -160,6 +163,15 @@ const setSub = defineCommand({
|
|
|
160
163
|
process.exit(1)
|
|
161
164
|
}
|
|
162
165
|
|
|
166
|
+
if (args.adapter === 'instagram') {
|
|
167
|
+
console.error(
|
|
168
|
+
errorLine(
|
|
169
|
+
'Instagram uses a username/password auth flow. Use `typeclaw channel reauth instagram` to rotate its credentials.',
|
|
170
|
+
),
|
|
171
|
+
)
|
|
172
|
+
process.exit(1)
|
|
173
|
+
}
|
|
174
|
+
|
|
163
175
|
const adapter =
|
|
164
176
|
args.adapter === undefined
|
|
165
177
|
? await pickSettableAdapter(configured)
|
|
@@ -171,7 +183,7 @@ const setSub = defineCommand({
|
|
|
171
183
|
},
|
|
172
184
|
})
|
|
173
185
|
|
|
174
|
-
const REAUTHABLE_ADAPTERS = ['line', 'kakaotalk', 'webex'] as const
|
|
186
|
+
const REAUTHABLE_ADAPTERS = ['line', 'instagram', 'kakaotalk', 'webex'] as const
|
|
175
187
|
type ReauthableAdapter = (typeof REAUTHABLE_ADAPTERS)[number]
|
|
176
188
|
|
|
177
189
|
const reauthSub = defineCommand({
|
|
@@ -441,6 +453,9 @@ async function runReauth(cwd: string, adapter: ReauthableAdapter): Promise<void>
|
|
|
441
453
|
case 'line':
|
|
442
454
|
await runLineReauth(cwd)
|
|
443
455
|
return
|
|
456
|
+
case 'instagram':
|
|
457
|
+
await runInstagramReauth(cwd)
|
|
458
|
+
return
|
|
444
459
|
case 'kakaotalk':
|
|
445
460
|
await runKakaotalkReauth(cwd)
|
|
446
461
|
return
|
|
@@ -450,6 +465,25 @@ async function runReauth(cwd: string, adapter: ReauthableAdapter): Promise<void>
|
|
|
450
465
|
}
|
|
451
466
|
}
|
|
452
467
|
|
|
468
|
+
async function runInstagramReauth(cwd: string): Promise<void> {
|
|
469
|
+
const creds = await promptInstagramCredentials()
|
|
470
|
+
const s = spinner()
|
|
471
|
+
s.start('Logging in to Instagram...')
|
|
472
|
+
const result = await runInstagramBootstrap({
|
|
473
|
+
username: creds.username,
|
|
474
|
+
password: creds.password,
|
|
475
|
+
agentDir: cwd,
|
|
476
|
+
callbacks: instagramLoginCallbacks({ pause: () => s.stop(), resume: (message) => s.start(message) }),
|
|
477
|
+
})
|
|
478
|
+
if (!result.ok) {
|
|
479
|
+
s.stop(`Instagram login failed: ${result.reason}`)
|
|
480
|
+
process.exit(1)
|
|
481
|
+
}
|
|
482
|
+
s.stop('Instagram credentials refreshed in secrets.json.')
|
|
483
|
+
|
|
484
|
+
await maybePromptReauthRefresh(cwd, 'instagram')
|
|
485
|
+
}
|
|
486
|
+
|
|
453
487
|
async function runLineReauth(cwd: string): Promise<void> {
|
|
454
488
|
const holder: LineAuthSpinnerHolder = { current: null }
|
|
455
489
|
const login = await promptLineLogin(holderSpinnerControl(holder))
|
|
@@ -546,7 +580,8 @@ async function maybePromptCredentialRefresh(
|
|
|
546
580
|
label: string,
|
|
547
581
|
verbPast: 're-authenticated' | 'credentials updated',
|
|
548
582
|
): Promise<void> {
|
|
549
|
-
const
|
|
583
|
+
const controller = resolveController()
|
|
584
|
+
const current = await controller.status({ cwd }).catch(() => null)
|
|
550
585
|
if (current === null || current.kind !== 'running') {
|
|
551
586
|
done({
|
|
552
587
|
title: c.green(`${label} ${verbPast}.`),
|
|
@@ -574,12 +609,12 @@ async function maybePromptCredentialRefresh(
|
|
|
574
609
|
return
|
|
575
610
|
}
|
|
576
611
|
|
|
577
|
-
const stopped = await stop({ cwd })
|
|
612
|
+
const stopped = await controller.stop({ cwd })
|
|
578
613
|
if (!stopped.ok) {
|
|
579
614
|
console.error(errorLine(`Restart failed during stop: ${stopped.reason}`))
|
|
580
615
|
process.exit(1)
|
|
581
616
|
}
|
|
582
|
-
const started = await start({ cwd, preferredHostPort: config.port, cliEntry: process.argv[1] })
|
|
617
|
+
const started = await controller.start({ cwd, preferredHostPort: config.port, cliEntry: process.argv[1] })
|
|
583
618
|
if (!started.ok) {
|
|
584
619
|
console.error(errorLine(`Restart failed during start: ${started.reason}`))
|
|
585
620
|
process.exit(1)
|
|
@@ -940,6 +975,7 @@ type CollectedCredentials =
|
|
|
940
975
|
| { channel: 'telegram-bot'; telegramBotToken: string }
|
|
941
976
|
| { channel: 'webex'; runWebexAuth: (options: { cwd: string }) => Promise<WebexAuthResult> }
|
|
942
977
|
| { channel: 'webex-bot'; webexBotToken: string }
|
|
978
|
+
| { channel: 'instagram'; runInstagramAuth: (options: { cwd: string }) => Promise<InstagramAuthResult> }
|
|
943
979
|
| { channel: 'line'; runLineAuth: (options: { cwd: string }) => Promise<LineAuthResult> }
|
|
944
980
|
| { channel: 'kakaotalk'; runKakaotalkAuth: (options: { cwd: string }) => Promise<KakaotalkAuthResult> }
|
|
945
981
|
| {
|
|
@@ -986,6 +1022,15 @@ async function collectCredentials(
|
|
|
986
1022
|
}
|
|
987
1023
|
case 'webex-bot':
|
|
988
1024
|
return { channel, webexBotToken: await promptWebexToken() }
|
|
1025
|
+
case 'instagram': {
|
|
1026
|
+
const creds = await promptInstagramCredentials()
|
|
1027
|
+
const callbacks = instagramLoginCallbacks(lineSpinnerHolder ? holderSpinnerControl(lineSpinnerHolder) : undefined)
|
|
1028
|
+
return {
|
|
1029
|
+
channel,
|
|
1030
|
+
runInstagramAuth: ({ cwd: agentDir }) =>
|
|
1031
|
+
runInstagramBootstrap({ username: creds.username, password: creds.password, agentDir, callbacks }),
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
989
1034
|
case 'line': {
|
|
990
1035
|
const login = await promptLineLogin(lineSpinnerHolder ? holderSpinnerControl(lineSpinnerHolder) : undefined)
|
|
991
1036
|
return {
|
|
@@ -1515,6 +1560,60 @@ async function promptWebexCredentials(
|
|
|
1515
1560
|
return { email, password: pwd }
|
|
1516
1561
|
}
|
|
1517
1562
|
|
|
1563
|
+
async function promptInstagramCredentials(): Promise<{ username: string; password: string }> {
|
|
1564
|
+
note(
|
|
1565
|
+
[
|
|
1566
|
+
'Instagram authentication uses a personal account.',
|
|
1567
|
+
'Messages will be sent and received under this account.',
|
|
1568
|
+
'If the account has 2FA or triggers a checkpoint, you will be prompted for the verification code here.',
|
|
1569
|
+
].join('\n'),
|
|
1570
|
+
'About to log in to Instagram',
|
|
1571
|
+
)
|
|
1572
|
+
const username = await text({
|
|
1573
|
+
message: 'Instagram username',
|
|
1574
|
+
validate: (value) => (value && value.length > 0 ? undefined : 'Username is required'),
|
|
1575
|
+
})
|
|
1576
|
+
if (isCancel(username)) {
|
|
1577
|
+
cancel('Aborted.')
|
|
1578
|
+
process.exit(0)
|
|
1579
|
+
}
|
|
1580
|
+
const pwd = await password({
|
|
1581
|
+
message: 'Instagram password',
|
|
1582
|
+
validate: (value) => (value && value.length > 0 ? undefined : 'Password is required'),
|
|
1583
|
+
})
|
|
1584
|
+
if (isCancel(pwd)) {
|
|
1585
|
+
cancel('Aborted.')
|
|
1586
|
+
process.exit(0)
|
|
1587
|
+
}
|
|
1588
|
+
return { username, password: pwd }
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
// The login spinner ('Logging in to Instagram...') keeps animating while
|
|
1592
|
+
// Instagram's 2FA/checkpoint step waits on a human, and would repaint over the
|
|
1593
|
+
// code prompt. Pause it around the prompt so the input line stays legible, then
|
|
1594
|
+
// resume with a "waiting" message — same control the LINE PIN flow uses.
|
|
1595
|
+
function instagramLoginCallbacks(spinnerControl?: LineAuthSpinnerControl): InstagramLoginCallbacks {
|
|
1596
|
+
const promptCode = async (message: string): Promise<string | null> => {
|
|
1597
|
+
spinnerControl?.pause()
|
|
1598
|
+
const code = await text({
|
|
1599
|
+
message,
|
|
1600
|
+
validate: (value) => (value && value.trim().length > 0 ? undefined : 'A verification code is required'),
|
|
1601
|
+
})
|
|
1602
|
+
if (isCancel(code)) return null
|
|
1603
|
+
spinnerControl?.resume('Verifying the Instagram code...')
|
|
1604
|
+
return code
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
return {
|
|
1608
|
+
onTwoFactorCode: () => promptCode('Enter the Instagram 2FA code from your authenticator app or SMS'),
|
|
1609
|
+
onChallengeCode: async ({ contactPoint }) => {
|
|
1610
|
+
const where = contactPoint === '' ? 'your email or phone' : contactPoint
|
|
1611
|
+
const code = await promptCode(`Enter the Instagram verification code sent to ${where}`)
|
|
1612
|
+
return code === null ? null : { code }
|
|
1613
|
+
},
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1518
1617
|
type LinePromptResult =
|
|
1519
1618
|
| { method: 'qr'; callbacks: { onQRUrl: (url: string) => Promise<void>; onPincode: (pin: string) => void } }
|
|
1520
1619
|
| {
|
|
@@ -1669,7 +1768,9 @@ function reportProgress(
|
|
|
1669
1768
|
const s = spinner()
|
|
1670
1769
|
s.start(START_MESSAGES[event.step])
|
|
1671
1770
|
spinners[event.step] = s
|
|
1672
|
-
if (event.step === 'line-auth' && lineSpinnerHolder)
|
|
1771
|
+
if ((event.step === 'line-auth' || event.step === 'instagram-auth') && lineSpinnerHolder) {
|
|
1772
|
+
lineSpinnerHolder.current = s
|
|
1773
|
+
}
|
|
1673
1774
|
return
|
|
1674
1775
|
}
|
|
1675
1776
|
|
|
@@ -1681,6 +1782,10 @@ function reportProgress(
|
|
|
1681
1782
|
if (lineSpinnerHolder) lineSpinnerHolder.current = null
|
|
1682
1783
|
s.stop(reportLineAuth(event.result))
|
|
1683
1784
|
break
|
|
1785
|
+
case 'instagram-auth':
|
|
1786
|
+
if (lineSpinnerHolder) lineSpinnerHolder.current = null
|
|
1787
|
+
s.stop(reportInstagramAuth(event.result))
|
|
1788
|
+
break
|
|
1684
1789
|
case 'kakaotalk-auth':
|
|
1685
1790
|
s.stop(reportKakaotalkAuth(event.result))
|
|
1686
1791
|
break
|
|
@@ -1708,6 +1813,7 @@ function reportProgress(
|
|
|
1708
1813
|
|
|
1709
1814
|
const START_MESSAGES: Record<AddChannelStepEvent['step'], string> = {
|
|
1710
1815
|
'line-auth': 'Logging in to LINE...',
|
|
1816
|
+
'instagram-auth': 'Logging in to Instagram...',
|
|
1711
1817
|
'kakaotalk-auth': 'Logging in to KakaoTalk...',
|
|
1712
1818
|
'webex-auth': 'Logging in to Webex...',
|
|
1713
1819
|
'discord-auth': 'Logging in to Discord...',
|
|
@@ -1742,13 +1848,19 @@ function reportLineAuth(result: LineAuthResult): string {
|
|
|
1742
1848
|
return `LINE login failed: ${result.reason}`
|
|
1743
1849
|
}
|
|
1744
1850
|
|
|
1851
|
+
function reportInstagramAuth(result: InstagramAuthResult): string {
|
|
1852
|
+
if (result.ok) return 'Instagram credentials saved to secrets.json.'
|
|
1853
|
+
return `Instagram login failed: ${result.reason}`
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1745
1856
|
async function maybePromptRestart(
|
|
1746
1857
|
cwd: string,
|
|
1747
1858
|
channel: ChannelKind,
|
|
1748
1859
|
verb: 'added' | 'removed' = 'added',
|
|
1749
1860
|
): Promise<void> {
|
|
1750
1861
|
const label = CHANNEL_LABELS[channel]
|
|
1751
|
-
const
|
|
1862
|
+
const controller = resolveController()
|
|
1863
|
+
const current = await controller.status({ cwd }).catch(() => null)
|
|
1752
1864
|
if (current === null || current.kind !== 'running') {
|
|
1753
1865
|
done({
|
|
1754
1866
|
title: c.green(`${label} channel ${verb}.`),
|
|
@@ -1775,12 +1887,12 @@ async function maybePromptRestart(
|
|
|
1775
1887
|
return
|
|
1776
1888
|
}
|
|
1777
1889
|
|
|
1778
|
-
const stopped = await stop({ cwd })
|
|
1890
|
+
const stopped = await controller.stop({ cwd })
|
|
1779
1891
|
if (!stopped.ok) {
|
|
1780
1892
|
console.error(errorLine(`Restart failed during stop: ${stopped.reason}`))
|
|
1781
1893
|
process.exit(1)
|
|
1782
1894
|
}
|
|
1783
|
-
const started = await start({ cwd, preferredHostPort: config.port, cliEntry: process.argv[1] })
|
|
1895
|
+
const started = await controller.start({ cwd, preferredHostPort: config.port, cliEntry: process.argv[1] })
|
|
1784
1896
|
if (!started.ok) {
|
|
1785
1897
|
console.error(errorLine(`Restart failed during start: ${started.reason}`))
|
|
1786
1898
|
process.exit(1)
|
package/src/cli/hostd.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineCommand } from 'citty'
|
|
2
2
|
|
|
3
3
|
import { loadConfigSync, validateConfig, type Config, type ValidateConfigResult } from '@/config'
|
|
4
|
-
import {
|
|
4
|
+
import { resolveController, type StartOptions, type StartResult, type StopResult } from '@/container'
|
|
5
5
|
import { createCurrentHostDaemonHolder } from '@/hostd/current-host-daemon'
|
|
6
6
|
import { startDaemon, type DaemonLogEvent, type RestartPreflight } from '@/hostd/daemon'
|
|
7
7
|
import { createKakaoRenewalManager } from '@/hostd/kakao-renewal-manager'
|
|
@@ -92,11 +92,12 @@ export type HostdRestartDeps = {
|
|
|
92
92
|
start: (opts: StartOptions) => Promise<StartResult>
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
const controller = resolveController()
|
|
95
96
|
const defaultRestartDeps: HostdRestartDeps = {
|
|
96
97
|
validateConfig,
|
|
97
|
-
stop,
|
|
98
|
+
stop: (opts) => controller.stop(opts),
|
|
98
99
|
loadConfigSync,
|
|
99
|
-
start,
|
|
100
|
+
start: (opts) => controller.start(opts),
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
export function buildHostdRestart(
|
package/src/cli/init.ts
CHANGED
|
@@ -2047,6 +2047,7 @@ const START_MESSAGES: Record<Exclude<InitStep, 'hatching'>, string> = {
|
|
|
2047
2047
|
scaffold: 'Laying the egg...',
|
|
2048
2048
|
'slack-auth': 'Logging in to Slack...',
|
|
2049
2049
|
'discord-auth': 'Logging in to Discord...',
|
|
2050
|
+
'instagram-auth': 'Logging in to Instagram...',
|
|
2050
2051
|
'kakaotalk-auth': 'Logging in to KakaoTalk...',
|
|
2051
2052
|
'webex-auth': 'Logging in to Webex...',
|
|
2052
2053
|
'github-webhooks': 'Installing GitHub repository webhooks...',
|
package/src/cli/logs.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCommand } from 'citty'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { parseTailValue, resolveController } from '@/container'
|
|
4
4
|
|
|
5
5
|
import { preflightDocker, printDockerGuidance } from './docker-preflight'
|
|
6
6
|
import { runInspectViewer } from './inspect'
|
|
@@ -64,7 +64,7 @@ export const logsCommand = defineCommand({
|
|
|
64
64
|
console.log(c.dim('Showing container logs.'))
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const result = await logs({ cwd, follow: args.follow, tail })
|
|
67
|
+
const result = await resolveController().logs({ cwd, follow: args.follow, tail })
|
|
68
68
|
if (!result.ok) {
|
|
69
69
|
console.error(errorLine(result.reason))
|
|
70
70
|
process.exit(1)
|
package/src/cli/restart.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { confirm, isCancel } from '@clack/prompts'
|
|
|
2
2
|
import { defineCommand } from 'citty'
|
|
3
3
|
|
|
4
4
|
import { config, validateConfig } from '@/config'
|
|
5
|
-
import {
|
|
5
|
+
import { resolveController } from '@/container'
|
|
6
6
|
import { findAgentDir, isInitialized } from '@/init'
|
|
7
7
|
|
|
8
8
|
import { preflightDocker, printDockerGuidance } from './docker-preflight'
|
|
@@ -70,9 +70,11 @@ export const restartCommand = defineCommand({
|
|
|
70
70
|
process.exit(1)
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
const controller = resolveController()
|
|
74
|
+
|
|
73
75
|
const stopSpin = spinner()
|
|
74
76
|
stopSpin.start('Stopping container...')
|
|
75
|
-
const stopped = await stop({ cwd })
|
|
77
|
+
const stopped = await controller.stop({ cwd })
|
|
76
78
|
if (!stopped.ok) {
|
|
77
79
|
stopSpin.error(stopped.reason)
|
|
78
80
|
process.exit(1)
|
|
@@ -81,7 +83,7 @@ export const restartCommand = defineCommand({
|
|
|
81
83
|
|
|
82
84
|
const startSpin = spinner()
|
|
83
85
|
startSpin.start('Starting container...')
|
|
84
|
-
const started = await start({
|
|
86
|
+
const started = await controller.start({
|
|
85
87
|
cwd,
|
|
86
88
|
preferredHostPort: Number(args.port),
|
|
87
89
|
forceBuild: args.build,
|
package/src/cli/shell.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCommand } from 'citty'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { resolveController } from '@/container'
|
|
4
4
|
|
|
5
5
|
import { preflightDocker, printDockerGuidance } from './docker-preflight'
|
|
6
6
|
import { requireAgentDir } from './require-agent-dir'
|
|
@@ -29,7 +29,7 @@ export const shellCommand = defineCommand({
|
|
|
29
29
|
|
|
30
30
|
console.log(c.cyan(`Attaching ${args.shell} inside the container...`))
|
|
31
31
|
|
|
32
|
-
const result = await shell({ cwd, shell: args.shell })
|
|
32
|
+
const result = await resolveController().shell({ cwd, shell: args.shell })
|
|
33
33
|
if (!result.ok) {
|
|
34
34
|
console.error(errorLine(result.reason))
|
|
35
35
|
process.exit(1)
|
package/src/cli/start.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { confirm, isCancel } from '@clack/prompts'
|
|
|
2
2
|
import { defineCommand } from 'citty'
|
|
3
3
|
|
|
4
4
|
import { config, validateConfig } from '@/config'
|
|
5
|
-
import {
|
|
5
|
+
import { resolveController } from '@/container'
|
|
6
6
|
import { findAgentDir, isInitialized } from '@/init'
|
|
7
7
|
|
|
8
8
|
import { preflightDocker, printDockerGuidance } from './docker-preflight'
|
|
@@ -72,7 +72,7 @@ export const startCommand = defineCommand({
|
|
|
72
72
|
|
|
73
73
|
const s = spinner()
|
|
74
74
|
s.start('Starting container...')
|
|
75
|
-
const result = await start({
|
|
75
|
+
const result = await resolveController().start({
|
|
76
76
|
cwd,
|
|
77
77
|
preferredHostPort: Number(args.port),
|
|
78
78
|
forceBuild: args.build,
|
package/src/cli/status.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { styleText } from 'node:util'
|
|
|
2
2
|
|
|
3
3
|
import { defineCommand } from 'citty'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { type ContainerStatus, type DockerExec, resolveController } from '@/container'
|
|
6
6
|
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'
|
|
10
|
+
import { type DockerPreflightResult, preflightDocker, printDockerGuidance } from './docker-preflight'
|
|
11
11
|
|
|
12
12
|
export type HostdStatus =
|
|
13
13
|
| { kind: 'unreachable' }
|
|
@@ -26,21 +26,44 @@ export const statusCommand = defineCommand({
|
|
|
26
26
|
description: 'show the agent container and host daemon status (host stage)',
|
|
27
27
|
},
|
|
28
28
|
async run() {
|
|
29
|
-
|
|
29
|
+
await runStatus()
|
|
30
|
+
},
|
|
31
|
+
})
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
// Injectable seam so the render/flow can be exercised without spawning the real
|
|
34
|
+
// Docker CLI. The broken-config path otherwise pays a ~70s Docker Desktop
|
|
35
|
+
// cold-start on the first `docker info` of a Windows CI run; injecting the
|
|
36
|
+
// preflight + exec keeps the test on the pure flow it actually cares about.
|
|
37
|
+
export type RunStatusDeps = {
|
|
38
|
+
cwd?: string
|
|
39
|
+
preflight?: () => Promise<DockerPreflightResult>
|
|
40
|
+
exec?: DockerExec
|
|
41
|
+
fetchHostd?: (containerName: string) => Promise<HostdStatus>
|
|
42
|
+
write?: (text: string) => void
|
|
43
|
+
onDockerUnavailable?: (failure: Extract<DockerPreflightResult, { ok: false }>) => void
|
|
44
|
+
}
|
|
36
45
|
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
export async function runStatus(deps: RunStatusDeps = {}): Promise<void> {
|
|
47
|
+
const cwd = deps.cwd ?? findAgentDir(process.cwd()) ?? process.cwd()
|
|
39
48
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
const preflight = await (deps.preflight ?? preflightDocker)()
|
|
50
|
+
if (!preflight.ok) {
|
|
51
|
+
;(deps.onDockerUnavailable ?? defaultOnDockerUnavailable)(preflight)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const container = await resolveController().status({ cwd, exec: deps.exec })
|
|
56
|
+
const hostd = await (deps.fetchHostd ?? fetchHostdStatus)(container.containerName)
|
|
57
|
+
|
|
58
|
+
const useColor = Boolean(process.stdout.isTTY) && process.env.NO_COLOR === undefined
|
|
59
|
+
const write = deps.write ?? ((text: string) => process.stdout.write(text))
|
|
60
|
+
write(`${formatStatus({ cwd, container, hostd }, { useColor })}\n`)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function defaultOnDockerUnavailable(failure: Extract<DockerPreflightResult, { ok: false }>): never {
|
|
64
|
+
printDockerGuidance(failure)
|
|
65
|
+
process.exit(1)
|
|
66
|
+
}
|
|
44
67
|
|
|
45
68
|
async function fetchHostdStatus(containerName: string): Promise<HostdStatus> {
|
|
46
69
|
if (!(await isDaemonReachable())) return { kind: 'unreachable' }
|
package/src/cli/stop.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCommand } from 'citty'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { resolveController } from '@/container'
|
|
4
4
|
|
|
5
5
|
import { preflightDocker, printDockerGuidance } from './docker-preflight'
|
|
6
6
|
import { requireAgentDir } from './require-agent-dir'
|
|
@@ -22,7 +22,7 @@ export const stopCommand = defineCommand({
|
|
|
22
22
|
|
|
23
23
|
const s = spinner()
|
|
24
24
|
s.start('Stopping container...')
|
|
25
|
-
const result = await stop({ cwd })
|
|
25
|
+
const result = await resolveController().stop({ cwd })
|
|
26
26
|
|
|
27
27
|
if (!result.ok) {
|
|
28
28
|
s.error(result.reason)
|
package/src/compose/restart.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { validateConfig } from '@/config'
|
|
2
|
-
import {
|
|
2
|
+
import { resolveController } from '@/container'
|
|
3
3
|
|
|
4
4
|
import { discoverAgents, type AgentEntry } from './discover'
|
|
5
5
|
import type { AgentResult, StartSuccess } from './start'
|
|
@@ -57,10 +57,11 @@ async function runOne(
|
|
|
57
57
|
const validated = validateConfig(cwd)
|
|
58
58
|
if (!validated.ok) return { name, ok: false, reason: validated.reason }
|
|
59
59
|
try {
|
|
60
|
-
const
|
|
60
|
+
const controller = resolveController()
|
|
61
|
+
const stopped = await controller.stop({ cwd })
|
|
61
62
|
if (!stopped.ok) return { name, ok: false, reason: stopped.reason }
|
|
62
63
|
onStopped()
|
|
63
|
-
const started = await start({ cwd, preferredHostPort, forceBuild, cliEntry })
|
|
64
|
+
const started = await controller.start({ cwd, preferredHostPort, forceBuild, cliEntry })
|
|
64
65
|
if (!started.ok) return { name, ok: false, reason: started.reason }
|
|
65
66
|
return { name, ok: true, data: { stop: stopped, start: started }, warnings: validated.warnings }
|
|
66
67
|
} catch (error) {
|
package/src/compose/start.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { validateConfig } from '@/config'
|
|
2
|
-
import {
|
|
2
|
+
import { resolveController, type StartResult } from '@/container'
|
|
3
3
|
|
|
4
4
|
import { discoverAgents, type AgentEntry } from './discover'
|
|
5
5
|
|
|
@@ -55,7 +55,7 @@ async function runOne(
|
|
|
55
55
|
const validated = validateConfig(cwd)
|
|
56
56
|
if (!validated.ok) return { name, ok: false, reason: validated.reason }
|
|
57
57
|
try {
|
|
58
|
-
const data = await start({ cwd, preferredHostPort, forceBuild, cliEntry })
|
|
58
|
+
const data = await resolveController().start({ cwd, preferredHostPort, forceBuild, cliEntry })
|
|
59
59
|
if (!data.ok) return { name, ok: false, reason: data.reason }
|
|
60
60
|
return { name, ok: true, data, warnings: validated.warnings }
|
|
61
61
|
} catch (error) {
|
package/src/compose/stop.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveController, type StopResult } from '@/container'
|
|
2
2
|
|
|
3
3
|
import { discoverAgents, type AgentEntry } from './discover'
|
|
4
4
|
import type { AgentResult } from './start'
|
|
@@ -34,7 +34,7 @@ export async function composeStop({ rootCwd, onProgress }: ComposeStopOptions):
|
|
|
34
34
|
|
|
35
35
|
async function runOne(name: string, cwd: string): Promise<AgentResult<StopSuccess>> {
|
|
36
36
|
try {
|
|
37
|
-
const data = await stop({ cwd })
|
|
37
|
+
const data = await resolveController().stop({ cwd })
|
|
38
38
|
if (!data.ok) return { name, ok: false, reason: data.reason }
|
|
39
39
|
return { name, ok: true, data }
|
|
40
40
|
} catch (error) {
|
|
@@ -15,6 +15,7 @@ export const CHANNEL_KINDS = [
|
|
|
15
15
|
'telegram-bot',
|
|
16
16
|
'webex',
|
|
17
17
|
'webex-bot',
|
|
18
|
+
'instagram',
|
|
18
19
|
'line',
|
|
19
20
|
'kakaotalk',
|
|
20
21
|
'github',
|
|
@@ -189,7 +190,7 @@ function buildDetail(kind: ChannelKind, channelConfig: unknown, secretsBlock: un
|
|
|
189
190
|
const repos = isObjectRecord(channelConfig) && Array.isArray(channelConfig.repos) ? channelConfig.repos.length : 0
|
|
190
191
|
return { detail: `${repos} repo${repos === 1 ? '' : 's'}` }
|
|
191
192
|
}
|
|
192
|
-
if (kind === 'line' || kind === 'kakaotalk' || kind === 'webex' || kind === 'discord') {
|
|
193
|
+
if (kind === 'line' || kind === 'instagram' || kind === 'kakaotalk' || kind === 'webex' || kind === 'discord') {
|
|
193
194
|
if (!isObjectRecord(secretsBlock)) return {}
|
|
194
195
|
const accounts = isObjectRecord(secretsBlock.accounts) ? Object.keys(secretsBlock.accounts).length : 0
|
|
195
196
|
const current = typeof secretsBlock.currentAccount === 'string' ? secretsBlock.currentAccount : undefined
|
package/src/config/config.ts
CHANGED
|
@@ -373,7 +373,7 @@ export type NetworkConfig = z.infer<typeof networkSchema>
|
|
|
373
373
|
// the default 'proc-bind' strategy `--ro-bind`s the container's already-real
|
|
374
374
|
// procfs into the sandbox with NO CAP_SYS_ADMIN, giving the runner's child a
|
|
375
375
|
// working /proc/self/{fd,maps} so it stops aborting with Bun's "NotDir". The
|
|
376
|
-
// agent runtime's /proc/N/environ (
|
|
376
|
+
// agent runtime's /proc/N/environ (OPENAI_API_KEY) stays unreadable because
|
|
377
377
|
// bwrap's --unshare-user puts the sandbox in a child user namespace the kernel
|
|
378
378
|
// won't let read a parent-userns process's environ — verified at runtime by a
|
|
379
379
|
// probe before the strategy is selected (src/sandbox/availability.ts). Avoiding
|
|
@@ -786,6 +786,14 @@ export const configSchema = z
|
|
|
786
786
|
git: gitSchema,
|
|
787
787
|
roles: rolesConfigSchema.optional(),
|
|
788
788
|
tunnels: tunnelsArraySchema,
|
|
789
|
+
// When `true` (default), the system prompt tells the agent it runs on
|
|
790
|
+
// TypeClaw and stamps the runtime version. Set `false` to strip every
|
|
791
|
+
// TypeClaw-identifying clue from the system prompt: the base prompt's
|
|
792
|
+
// opening lines are phrased generically ("a general-purpose AI agent"
|
|
793
|
+
// instead of "…running inside TypeClaw") and the `## Runtime` version
|
|
794
|
+
// block is omitted entirely. Read fresh per session via `getConfig()`, so
|
|
795
|
+
// it applies on reload without a restart.
|
|
796
|
+
branding: z.boolean().default(true),
|
|
789
797
|
})
|
|
790
798
|
.catchall(z.unknown())
|
|
791
799
|
|
|
@@ -1012,6 +1020,7 @@ export const FIELD_EFFECTS: Record<string, FieldEffect> = {
|
|
|
1012
1020
|
// the corresponding projections of the whole `roles` block.
|
|
1013
1021
|
'roles.match': 'applied',
|
|
1014
1022
|
'roles.permissions': 'restart-required',
|
|
1023
|
+
branding: 'applied',
|
|
1015
1024
|
}
|
|
1016
1025
|
|
|
1017
1026
|
// Stable JSON for value comparison. Fields are small JSON-shaped objects, so
|