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
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { KakaoAccountCredentials, KakaoConfig } from 'agent-messenger/kakaotalk'
|
|
2
2
|
import type { PendingLoginState } from 'agent-messenger/kakaotalk'
|
|
3
3
|
|
|
4
|
-
import { sendHttp } from '@/hostd/client'
|
|
5
|
-
|
|
6
4
|
import { type KakaoChannelBlock, type KakaoEncryptedPassword, kakaoChannelBlockSchema } from './schema'
|
|
5
|
+
import type { RuntimeSecretsProvider } from './secrets-provider'
|
|
7
6
|
import { SecretsBackend } from './storage'
|
|
8
7
|
|
|
9
8
|
// Account shape accepted by setAccount(). Extends the upstream
|
|
@@ -18,7 +17,7 @@ export type SetKakaoAccountInput = KakaoAccountCredentials & {
|
|
|
18
17
|
|
|
19
18
|
export type SecretsKakaoCredentialStoreOptions =
|
|
20
19
|
| { mode: 'host'; secretsPath: string }
|
|
21
|
-
| { mode: 'container'; secretsPath: string;
|
|
20
|
+
| { mode: 'container'; secretsPath: string; hostProvider: RuntimeSecretsProvider }
|
|
22
21
|
|
|
23
22
|
const EMPTY_BLOCK: KakaoChannelBlock = { currentAccount: null, accounts: {} }
|
|
24
23
|
|
|
@@ -102,7 +101,7 @@ export class SecretsKakaoCredentialStore {
|
|
|
102
101
|
|
|
103
102
|
private readBlock(): KakaoChannelBlock {
|
|
104
103
|
const channels =
|
|
105
|
-
this.options.mode === 'container' ? this.
|
|
104
|
+
this.options.mode === 'container' ? this.options.hostProvider.readChannels() : this.backend.readChannelsSync()
|
|
106
105
|
const raw = channels?.kakaotalk
|
|
107
106
|
return parseBlock(raw)
|
|
108
107
|
}
|
|
@@ -111,15 +110,7 @@ export class SecretsKakaoCredentialStore {
|
|
|
111
110
|
return this.enqueueWrite(async () => {
|
|
112
111
|
if (this.options.mode === 'container') {
|
|
113
112
|
const next = update(this.readBlock())
|
|
114
|
-
|
|
115
|
-
{
|
|
116
|
-
kind: 'secrets-patch',
|
|
117
|
-
containerName: this.options.containerName,
|
|
118
|
-
patch: { channels: { kakaotalk: next } },
|
|
119
|
-
},
|
|
120
|
-
{ url: this.options.hostdUrl, token: this.options.restartToken },
|
|
121
|
-
)
|
|
122
|
-
if (!response.ok) throw new Error(`secrets-patch failed: ${response.reason}`)
|
|
113
|
+
await this.options.hostProvider.writeBackChannelBlock({ kakaotalk: next })
|
|
123
114
|
return
|
|
124
115
|
}
|
|
125
116
|
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { LineAccountCredentials, LineConfig } from 'agent-messenger/line'
|
|
2
2
|
|
|
3
|
-
import { sendHttp } from '@/hostd/client'
|
|
4
|
-
|
|
5
3
|
import { type LineChannelBlock, lineChannelBlockSchema } from './schema'
|
|
4
|
+
import type { RuntimeSecretsProvider } from './secrets-provider'
|
|
6
5
|
import { SecretsBackend } from './storage'
|
|
7
6
|
|
|
8
7
|
export type SecretsLineCredentialStoreOptions =
|
|
9
8
|
| { mode: 'host'; secretsPath: string }
|
|
10
|
-
| { mode: 'container'; secretsPath: string;
|
|
9
|
+
| { mode: 'container'; secretsPath: string; hostProvider: RuntimeSecretsProvider }
|
|
11
10
|
|
|
12
11
|
const EMPTY_BLOCK: LineChannelBlock = { currentAccount: null, accounts: {} }
|
|
13
12
|
|
|
@@ -64,7 +63,7 @@ export class SecretsLineCredentialStore {
|
|
|
64
63
|
|
|
65
64
|
private readBlock(): LineChannelBlock {
|
|
66
65
|
const channels =
|
|
67
|
-
this.options.mode === 'container' ? this.
|
|
66
|
+
this.options.mode === 'container' ? this.options.hostProvider.readChannels() : this.backend.readChannelsSync()
|
|
68
67
|
return parseBlock(channels?.line)
|
|
69
68
|
}
|
|
70
69
|
|
|
@@ -72,15 +71,7 @@ export class SecretsLineCredentialStore {
|
|
|
72
71
|
return this.enqueueWrite(async () => {
|
|
73
72
|
if (this.options.mode === 'container') {
|
|
74
73
|
const next = update(this.readBlock())
|
|
75
|
-
|
|
76
|
-
{
|
|
77
|
-
kind: 'secrets-patch',
|
|
78
|
-
containerName: this.options.containerName,
|
|
79
|
-
patch: { channels: { line: next } },
|
|
80
|
-
},
|
|
81
|
-
{ url: this.options.hostdUrl, token: this.options.restartToken },
|
|
82
|
-
)
|
|
83
|
-
if (!response.ok) throw new Error(`secrets-patch failed: ${response.reason}`)
|
|
74
|
+
await this.options.hostProvider.writeBackChannelBlock({ line: next })
|
|
84
75
|
return
|
|
85
76
|
}
|
|
86
77
|
|
package/src/secrets/schema.ts
CHANGED
|
@@ -90,6 +90,21 @@ export const lineChannelBlockSchema = z.object({
|
|
|
90
90
|
accounts: z.record(z.string(), lineAccountRecordSchema),
|
|
91
91
|
})
|
|
92
92
|
|
|
93
|
+
export const instagramAccountRecordSchema = z.object({
|
|
94
|
+
account_id: z.string(),
|
|
95
|
+
username: z.string(),
|
|
96
|
+
full_name: z.string().optional(),
|
|
97
|
+
profile_pic_url: z.string().optional(),
|
|
98
|
+
pk: z.string().optional(),
|
|
99
|
+
created_at: z.string(),
|
|
100
|
+
updated_at: z.string(),
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
export const instagramChannelBlockSchema = z.object({
|
|
104
|
+
currentAccount: z.string().nullable(),
|
|
105
|
+
accounts: z.record(z.string(), instagramAccountRecordSchema),
|
|
106
|
+
})
|
|
107
|
+
|
|
93
108
|
// Encrypted password envelope produced by src/secrets/encryption.ts. Optional
|
|
94
109
|
// in the schema because legacy v2 accounts (pre-renewal feature) don't have
|
|
95
110
|
// one; the renewal cron treats a missing envelope as "reauth required" and
|
|
@@ -193,6 +208,7 @@ export const channelsSchema = z
|
|
|
193
208
|
github: githubChannelSchema.optional(),
|
|
194
209
|
'telegram-bot': telegramBotChannelSchema.optional(),
|
|
195
210
|
line: lineChannelBlockSchema.optional(),
|
|
211
|
+
instagram: instagramChannelBlockSchema.optional(),
|
|
196
212
|
kakaotalk: kakaoChannelBlockSchema.optional(),
|
|
197
213
|
webex: webexChannelBlockSchema.optional(),
|
|
198
214
|
slack: slackChannelBlockSchema.optional(),
|
|
@@ -220,6 +236,8 @@ export type DiscordAccountRecord = z.infer<typeof discordAccountRecordSchema>
|
|
|
220
236
|
export type DiscordChannelBlock = z.infer<typeof discordChannelBlockSchema>
|
|
221
237
|
export type LineAccountRecord = z.infer<typeof lineAccountRecordSchema>
|
|
222
238
|
export type LineChannelBlock = z.infer<typeof lineChannelBlockSchema>
|
|
239
|
+
export type InstagramAccountRecord = z.infer<typeof instagramAccountRecordSchema>
|
|
240
|
+
export type InstagramChannelBlock = z.infer<typeof instagramChannelBlockSchema>
|
|
223
241
|
export type KakaoAccountRecord = z.infer<typeof kakaoAccountRecordSchema>
|
|
224
242
|
export type PendingLoginRecord = z.infer<typeof kakaoPendingLoginRecordSchema>
|
|
225
243
|
export type KakaoChannelBlock = z.infer<typeof kakaoChannelBlockSchema>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { sendHttp } from '@/hostd/client'
|
|
2
|
+
import type { Request } from '@/hostd/protocol'
|
|
3
|
+
|
|
4
|
+
import type { Channels } from './schema'
|
|
5
|
+
import { SecretsBackend } from './storage'
|
|
6
|
+
|
|
7
|
+
// The channel-block payload a container-mode store hands off to be persisted.
|
|
8
|
+
// Identical to the `secrets-patch` RPC's `patch.channels` union so the hostd
|
|
9
|
+
// implementation forwards it verbatim — the on-the-wire contract is unchanged
|
|
10
|
+
// by this abstraction.
|
|
11
|
+
export type ChannelBlockPatch = Extract<Request, { kind: 'secrets-patch' }>['patch']['channels']
|
|
12
|
+
|
|
13
|
+
// The container-stage secrets seam. Named for what the runtime NEEDS, not the
|
|
14
|
+
// transport that serves it. Two halves:
|
|
15
|
+
// read — the whole channels slice (callers extract their own adapter block).
|
|
16
|
+
// Returns null when secrets.json is absent, so callers degrade rather
|
|
17
|
+
// than crash. File-based today (a mounted secrets.json); a managed
|
|
18
|
+
// impl (volume / secret store) slots in behind the same method.
|
|
19
|
+
// write — persist one adapter's block. The container cannot write the
|
|
20
|
+
// host-owned file directly under hostd, so this may cross a transport
|
|
21
|
+
// (secrets-patch RPC); under a volume it's a direct file write.
|
|
22
|
+
export interface RuntimeSecretsProvider {
|
|
23
|
+
readChannels(): Channels | null
|
|
24
|
+
writeBackChannelBlock(channels: ChannelBlockPatch): Promise<void>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type HostdSecretsProviderOptions = {
|
|
28
|
+
hostdUrl: string
|
|
29
|
+
restartToken: string
|
|
30
|
+
containerName: string
|
|
31
|
+
// The mounted secrets.json the container READS from. Writes go through hostd
|
|
32
|
+
// (secrets-patch RPC) to avoid concurrent-writer corruption; reads are the
|
|
33
|
+
// live bind-mounted file, so this path is needed here.
|
|
34
|
+
secretsPath: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// The container-under-hostd provider: reads the mounted secrets.json directly,
|
|
38
|
+
// writes back via a `secrets-patch` RPC over HTTP to hostd (host.docker.internal),
|
|
39
|
+
// Bearer-authed by the per-container restart token.
|
|
40
|
+
export function createHostdSecretsProvider(options: HostdSecretsProviderOptions): RuntimeSecretsProvider {
|
|
41
|
+
const backend = new SecretsBackend(options.secretsPath)
|
|
42
|
+
return {
|
|
43
|
+
readChannels(): Channels | null {
|
|
44
|
+
return backend.tryReadChannelsSync()
|
|
45
|
+
},
|
|
46
|
+
async writeBackChannelBlock(channels: ChannelBlockPatch): Promise<void> {
|
|
47
|
+
const response = await sendHttp(
|
|
48
|
+
{ kind: 'secrets-patch', containerName: options.containerName, patch: { channels } },
|
|
49
|
+
{ url: options.hostdUrl, token: options.restartToken },
|
|
50
|
+
)
|
|
51
|
+
if (!response.ok) throw new Error(`secrets-patch failed: ${response.reason}`)
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The file-backed provider: both halves hit the secrets.json on disk directly.
|
|
57
|
+
// Used where the runtime owns the file (a mounted volume in a future managed
|
|
58
|
+
// profile, or host-stage). No transport — writes merge the block into the file
|
|
59
|
+
// under the same lock the reads use.
|
|
60
|
+
export function createFileSecretsProvider(secretsPath: string): RuntimeSecretsProvider {
|
|
61
|
+
const backend = new SecretsBackend(secretsPath)
|
|
62
|
+
return {
|
|
63
|
+
readChannels(): Channels | null {
|
|
64
|
+
return backend.tryReadChannelsSync()
|
|
65
|
+
},
|
|
66
|
+
async writeBackChannelBlock(patch: ChannelBlockPatch): Promise<void> {
|
|
67
|
+
await backend.updateChannelsAsync(async (channels) => ({ result: undefined, next: { ...channels, ...patch } }))
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Resolves the container-stage secrets provider from the environment. Returns
|
|
73
|
+
// null when the hostd triple is absent (daemon unreachable at launch, or a
|
|
74
|
+
// managed profile with no write-back wired yet) — callers degrade gracefully
|
|
75
|
+
// rather than crash. Today only the hostd-backed provider exists; a managed
|
|
76
|
+
// impl (volume / secret store) is selected here when it lands.
|
|
77
|
+
export function resolveRuntimeSecretsProvider(
|
|
78
|
+
env: NodeJS.ProcessEnv,
|
|
79
|
+
secretsPath: string,
|
|
80
|
+
): RuntimeSecretsProvider | null {
|
|
81
|
+
const hostdUrl = env.TYPECLAW_HOSTD_URL
|
|
82
|
+
const restartToken = env.TYPECLAW_HOSTD_TOKEN
|
|
83
|
+
const containerName = env.TYPECLAW_CONTAINER_NAME
|
|
84
|
+
if (!hostdUrl || !restartToken || !containerName) return null
|
|
85
|
+
return createHostdSecretsProvider({ hostdUrl, restartToken, containerName, secretsPath })
|
|
86
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { sendHttp } from '@/hostd/client'
|
|
2
|
-
|
|
3
1
|
import { type SlackAccountRecord, type SlackChannelBlock, slackChannelBlockSchema } from './schema'
|
|
2
|
+
import type { RuntimeSecretsProvider } from './secrets-provider'
|
|
4
3
|
import { SecretsBackend } from './storage'
|
|
5
4
|
|
|
6
5
|
export type SetSlackAccountInput = SlackAccountRecord
|
|
7
6
|
|
|
8
7
|
export type SecretsSlackCredentialStoreOptions =
|
|
9
8
|
| { mode: 'host'; secretsPath: string }
|
|
10
|
-
| { mode: 'container'; secretsPath: string;
|
|
9
|
+
| { mode: 'container'; secretsPath: string; hostProvider: RuntimeSecretsProvider }
|
|
11
10
|
|
|
12
11
|
const EMPTY_BLOCK: SlackChannelBlock = { currentAccount: null, accounts: {} }
|
|
13
12
|
|
|
@@ -56,7 +55,7 @@ export class SecretsSlackCredentialStore {
|
|
|
56
55
|
|
|
57
56
|
private readBlock(): SlackChannelBlock {
|
|
58
57
|
const channels =
|
|
59
|
-
this.options.mode === 'container' ? this.
|
|
58
|
+
this.options.mode === 'container' ? this.options.hostProvider.readChannels() : this.backend.readChannelsSync()
|
|
60
59
|
return parseBlock(channels?.slack)
|
|
61
60
|
}
|
|
62
61
|
|
|
@@ -64,15 +63,7 @@ export class SecretsSlackCredentialStore {
|
|
|
64
63
|
return this.enqueueWrite(async () => {
|
|
65
64
|
if (this.options.mode === 'container') {
|
|
66
65
|
const next = update(this.readBlock())
|
|
67
|
-
|
|
68
|
-
{
|
|
69
|
-
kind: 'secrets-patch',
|
|
70
|
-
containerName: this.options.containerName,
|
|
71
|
-
patch: { channels: { slack: next } },
|
|
72
|
-
},
|
|
73
|
-
{ url: this.options.hostdUrl, token: this.options.restartToken },
|
|
74
|
-
)
|
|
75
|
-
if (!response.ok) throw new Error(`secrets-patch failed: ${response.reason}`)
|
|
66
|
+
await this.options.hostProvider.writeBackChannelBlock({ slack: next })
|
|
76
67
|
return
|
|
77
68
|
}
|
|
78
69
|
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { sendHttp } from '@/hostd/client'
|
|
2
|
-
|
|
3
1
|
import { type WebexAccountRecord, type WebexChannelBlock, webexChannelBlockSchema } from './schema'
|
|
2
|
+
import type { RuntimeSecretsProvider } from './secrets-provider'
|
|
4
3
|
import { SecretsBackend } from './storage'
|
|
5
4
|
|
|
6
5
|
export type SetWebexAccountInput = WebexAccountRecord
|
|
7
6
|
|
|
8
7
|
export type SecretsWebexCredentialStoreOptions =
|
|
9
8
|
| { mode: 'host'; secretsPath: string }
|
|
10
|
-
| { mode: 'container'; secretsPath: string;
|
|
9
|
+
| { mode: 'container'; secretsPath: string; hostProvider: RuntimeSecretsProvider }
|
|
11
10
|
|
|
12
11
|
const EMPTY_BLOCK: WebexChannelBlock = { currentAccount: null, accounts: {} }
|
|
13
12
|
|
|
@@ -61,7 +60,7 @@ export class SecretsWebexCredentialStore {
|
|
|
61
60
|
|
|
62
61
|
private readBlock(): WebexChannelBlock {
|
|
63
62
|
const channels =
|
|
64
|
-
this.options.mode === 'container' ? this.
|
|
63
|
+
this.options.mode === 'container' ? this.options.hostProvider.readChannels() : this.backend.readChannelsSync()
|
|
65
64
|
return parseBlock(channels?.webex)
|
|
66
65
|
}
|
|
67
66
|
|
|
@@ -69,15 +68,7 @@ export class SecretsWebexCredentialStore {
|
|
|
69
68
|
return this.enqueueWrite(async () => {
|
|
70
69
|
if (this.options.mode === 'container') {
|
|
71
70
|
const next = update(this.readBlock())
|
|
72
|
-
|
|
73
|
-
{
|
|
74
|
-
kind: 'secrets-patch',
|
|
75
|
-
containerName: this.options.containerName,
|
|
76
|
-
patch: { channels: { webex: next } },
|
|
77
|
-
},
|
|
78
|
-
{ url: this.options.hostdUrl, token: this.options.restartToken },
|
|
79
|
-
)
|
|
80
|
-
if (!response.ok) throw new Error(`secrets-patch failed: ${response.reason}`)
|
|
71
|
+
await this.options.hostProvider.writeBackChannelBlock({ webex: next })
|
|
81
72
|
return
|
|
82
73
|
}
|
|
83
74
|
|
package/src/server/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type { LiveSubagentRegistry } from '@/agent/live-subagents'
|
|
|
15
15
|
import { resolveFallbackChain } from '@/agent/model-fallback'
|
|
16
16
|
import { applyModelRuntimeOverrides } from '@/agent/model-overrides'
|
|
17
17
|
import { forgetSharedLoopGuardTool } from '@/agent/plugin-tools'
|
|
18
|
-
import { detectProviderError,
|
|
18
|
+
import { detectProviderError, isFailoverWorthy } from '@/agent/provider-error'
|
|
19
19
|
import { requestContainerRestart } from '@/agent/restart'
|
|
20
20
|
import { consumeRestartHandoff, type RestartHandoff } from '@/agent/restart-handoff'
|
|
21
21
|
import { sessionMetaPayload } from '@/agent/session-meta'
|
|
@@ -1130,7 +1130,7 @@ async function drain(
|
|
|
1130
1130
|
currentModelRef: state.activeModelRef,
|
|
1131
1131
|
session: state.session,
|
|
1132
1132
|
text: turnText,
|
|
1133
|
-
shouldFailover: (err) =>
|
|
1133
|
+
shouldFailover: (err) => isFailoverWorthy(err.message),
|
|
1134
1134
|
setModelForRef: async (ref) => {
|
|
1135
1135
|
await state.session.setModel(applyModelRuntimeOverrides(resolveModel(ref), ref))
|
|
1136
1136
|
state.activeModelRef = ref
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: typeclaw-channel-instagram
|
|
3
|
+
description: Use this skill BEFORE every `channel_reply` or `channel_send` call whose adapter is `instagram`. Instagram DMs render messages as plain text — no markdown, no surfaced @-mention syntax, no threads, and no outbound attachments or stickers. Read this skill before composing anything on Instagram.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# typeclaw-channel-instagram
|
|
7
|
+
|
|
8
|
+
You are speaking through the `instagram` channel adapter as a personal Instagram account.
|
|
9
|
+
|
|
10
|
+
Write plain text. The adapter strips common markdown as a safety net, but Instagram DMs do not provide rich text in this adapter.
|
|
11
|
+
|
|
12
|
+
Do not rely on:
|
|
13
|
+
|
|
14
|
+
- Markdown formatting, tables, or code fences.
|
|
15
|
+
- `@mention` syntax surfaced to the adapter. Address people by name in text.
|
|
16
|
+
- Threads or replies-with-quote. Every send is a top-level message.
|
|
17
|
+
- Outbound attachments, media, or stickers. The adapter sends text only via `sendMessage`.
|
|
18
|
+
|
|
19
|
+
Inbound media may be observed as metadata, but bytes are not fetchable through this adapter. Do not invent attachment ids.
|
|
20
|
+
|
|
21
|
+
Workspaces:
|
|
22
|
+
|
|
23
|
+
- `@instagram-dm` — a 1:1 direct message.
|
|
24
|
+
- `@instagram-group` — a group thread.
|
|
25
|
+
|
|
26
|
+
Engagement: every DM message engages. Groups are alias-only because the SDK summary does not surface native @-mention metadata.
|
|
27
|
+
|
|
28
|
+
Realtime vs polling transport is automatic and invisible to you: TypeClaw uses the hybrid listener when available and falls back to polling on older SDKs.
|
|
29
|
+
|
|
30
|
+
2FA and checkpoint-protected Instagram accounts are supported: the operator completes the verification code interactively at `typeclaw channel add instagram` (or `reauth`) time. Nothing about this is visible to you at runtime.
|
|
@@ -21,6 +21,7 @@ The runtime reads `typeclaw.json` at container startup. Some fields are picked u
|
|
|
21
21
|
- `plugins` — array of plugin module specifiers loaded at server boot: npm package names for published plugins, or relative paths for local plugins you are authoring. **Restart-required.**
|
|
22
22
|
- `alias` — additional names the agent answers to when a channel message contains its name in plain text (no `<@id>` mention). The agent folder's directory name (`basename(agentDir)`) is always implicit; `alias` adds further forms (Latin transliteration, nicknames, Korean particles, etc.). Used by the channel engagement layer alongside the structural mention/reply/dm triggers. **Live-reloadable.**
|
|
23
23
|
- `channels` — per-adapter engagement triggers and history-prefetch knobs for external messengers (Discord, Slack, Telegram, LINE, KakaoTalk), plus the GitHub channel (a webhook-driven adapter that watches repos and reviews PRs — see **GitHub channel** below). Access control lives in `roles`, not here. **Live-reloadable** — edits take effect on the next `reload` without a container restart.
|
|
24
|
+
- `branding` — whether your system prompt discloses that you run on TypeClaw. Default `true`: the prompt says you run "inside TypeClaw" and stamps a `## Runtime` TypeClaw-version block. Set `false` and both are stripped — the prompt opens generically and the runtime-version block is omitted (also on the subagent prompt path). Read fresh per session, so it applies on the next `reload`. The `typeclaw.json` filename and the `typeclaw-render-pdf` / `typeclaw-troubleshooting` skill names stay regardless — they are tokens you need to operate, not disclosure. **Live-reloadable.**
|
|
24
25
|
- `docker.file` — controls what ships in the autogenerated container image. Two layers: (1) **toggles** for opinionated package installs — `tmux`, `gh`, `python`, `xvfb` default on (`true`); `cjkFonts` defaults to `"auto"` (resolved from host locale at start); `ffmpeg`, `cloudflared`, `claudeCode`, `codexCli` default off (`false`) — set a toggle to `false` to omit, or to a version string like `"2.40.0"` to apt-pin (`python`, `cjkFonts`, `cloudflared`, `xvfb`, `claudeCode`, and `codexCli` are boolean-only). Most toggles install apt packages with BuildKit cache mounts; `cloudflared`, `claudeCode`, and `codexCli` are exceptions — `cloudflared` downloads the pinned GitHub release, `claudeCode` runs Anthropic's official `curl | bash` installer, `codexCli` `bun install`s the `@openai/codex` npm package. (2) **`append`** — extra Dockerfile lines spliced in right before `ENTRYPOINT` for anything the toggles don't cover. The whole Dockerfile is rewritten on every `start` from the typeclaw template. Lives under the `docker` namespace alongside future Docker-related blocks (e.g. `docker.compose`). **Restart-required** (next `typeclaw start` rebuilds the image).
|
|
25
26
|
- `git.ignore.append` — extra `.gitignore` patterns `typeclaw start` splices into the TypeClaw-owned `.gitignore` before the protected TypeClaw rules. The whole `.gitignore` is rewritten and auto-committed on every `start` when it changes; `append` is the supported escape hatch for local ignore patterns without editing the managed file by hand. Lives under the `git` namespace. **Restart-required** (next `typeclaw start` refreshes and commits `.gitignore`).
|
|
26
27
|
- `portForward` — allow/deny policy for the auto port-forwarder (the host-stage `_hostd` daemon's portbroker). When the agent runs a server inside the container that LISTENs on a TCP port, the broker proxies it to the same port number on `127.0.0.1` of the host so the user can hit it directly. `portForward` decides which ports are allowed through. **Restart-required** — the broker captures the policy at register time on `typeclaw start`.
|
|
@@ -29,7 +30,7 @@ The runtime reads `typeclaw.json` at container startup. Some fields are picked u
|
|
|
29
30
|
|
|
30
31
|
There is no file watcher, but there is a `reload` mechanism. When `typeclaw.json` changes:
|
|
31
32
|
|
|
32
|
-
- **Live-reloadable fields** (`models` — including per-profile `thinkingLevel`, `alias`, `channels`) take effect on the next `reload` — no container restart.
|
|
33
|
+
- **Live-reloadable fields** (`models` — including per-profile `thinkingLevel`, `alias`, `channels`, `branding`) take effect on the next `reload` — no container restart.
|
|
33
34
|
- **Restart-required fields** (`port`, `mounts`, `plugins`, `portForward`, `docker.file`, `git.ignore`) are reported as "reload landed but change won't apply until restart". The diff returns success; the runtime still has the old value in memory. Tell the user explicitly which one they're hitting. `docker.file` additionally requires an image rebuild — that happens automatically on the next `typeclaw start`, no extra flag needed. `git.ignore` refreshes the managed `.gitignore` and auto-commits it on the next `typeclaw start` if content changed.
|
|
34
35
|
- **`$schema`** changes are ignored.
|
|
35
36
|
|
|
@@ -54,6 +55,7 @@ You yourself cannot run `typeclaw restart` — that is a host-stage command and
|
|
|
54
55
|
| `portForward` | no | object | Allow/deny policy for the host-stage portbroker that auto-forwards container LISTEN ports to `127.0.0.1` on the host. Defaults to `{ "allow": "*" }` (forward everything). Omitted from scaffolded `typeclaw.json`. **Restart-required.** See **portForward** section below. |
|
|
55
56
|
| `docker` | no | object | Namespace for Docker-related blocks. Today the only child is `docker.file` — toggles (`tmux`, `gh`, `python`, `ffmpeg`, `cjkFonts`, `cloudflared`, `xvfb`, `claudeCode`, `codexCli`) gate opinionated package installs; `append` adds custom Dockerfile lines just before `ENTRYPOINT`. `docker.file` defaults to `{ ffmpeg: false, gh: true, python: true, tmux: true, cjkFonts: 'auto', cloudflared: false, xvfb: true, claudeCode: false, codexCli: false, append: [] }`. Omitted from scaffolded `typeclaw.json`. **Restart-required** (next `typeclaw start` rebuilds the image). See **Dockerfile** section below. |
|
|
56
57
|
| `git` | no | object | Namespace for git-related blocks. Today the only child is `git.ignore` — extra patterns spliced into the autogenerated `.gitignore` before TypeClaw's protected rules. `git.ignore` defaults to `{ "append": [] }`. Omitted from scaffolded `typeclaw.json`. **Restart-required** (next `typeclaw start` refreshes `.gitignore`). See **Gitignore** section below. |
|
|
58
|
+
| `branding` | no | boolean | Whether the system prompt discloses that you run on TypeClaw. Defaults to `true`. Set `false` to strip every TypeClaw clue from the prompt: the base prompt opens generically (no "inside TypeClaw") and the `## Runtime` version block is omitted, on both the main and subagent prompt paths. Read fresh per session. Functional identifiers (`typeclaw.json`, the `typeclaw-render-pdf` / `typeclaw-troubleshooting` skill names) are unaffected. **Live-reloadable.** |
|
|
57
59
|
|
|
58
60
|
> **Top-level keys not in this table are not "ignored unknowns" anymore** — they are reserved for **plugin config blocks**. The schema's `catchall(z.unknown())` preserves them, and the plugin loader hands each block to its owning plugin's `configSchema` for validation. The bundled memory plugin owns `memory` at the top level — see the `typeclaw-memory` skill for that block's semantics. Do not write a top-level key unless you know which plugin owns it.
|
|
59
61
|
|
|
@@ -438,7 +440,7 @@ Every secret-bearing field in `secrets.json` is a **`Secret`**: either a plain s
|
|
|
438
440
|
{
|
|
439
441
|
"version": 2,
|
|
440
442
|
"providers": {
|
|
441
|
-
"
|
|
443
|
+
"openai": { "type": "api_key", "key": "sk-xxx" },
|
|
442
444
|
"openai-codex": { "type": "oauth", "access_token": "...", "refresh_token": "...", "expires_at": 99 }
|
|
443
445
|
},
|
|
444
446
|
"channels": {
|
|
@@ -453,7 +455,7 @@ Every secret-bearing field in `secrets.json` is a **`Secret`**: either a plain s
|
|
|
453
455
|
**Resolution at boot, in order:**
|
|
454
456
|
|
|
455
457
|
1. `process.env[secret.env]` — explicit binding wins (the `env` field on the object form).
|
|
456
|
-
2. `process.env[<canonical env name>]` — canonical-env fallback (`SLACK_BOT_TOKEN`, `
|
|
458
|
+
2. `process.env[<canonical env name>]` — canonical-env fallback (`SLACK_BOT_TOKEN`, `OPENAI_API_KEY`, etc.).
|
|
457
459
|
3. `secret.value` — the on-disk value.
|
|
458
460
|
4. Otherwise the field is treated as missing.
|
|
459
461
|
|
|
@@ -738,7 +738,7 @@ Plugin `ToolContext` is `{ signal, sessionId, agentDir, logger }`. There is no `
|
|
|
738
738
|
- `session.turn.start` / `session.turn.end`: bracket every `session.prompt(text)` call across all four prompt-driver sites — `src/server/index.ts` (TUI drain + fallback), `src/channels/router.ts` (`fireSessionTurnStart`), `src/cron/consumer.ts` (per-attempt), `src/agent/subagents.ts` (subagent runner). `userPrompt` carries the literal text being passed to `session.prompt(text)`.
|
|
739
739
|
- `session.idle`: `src/server/index.ts` `drain()` — fires immediately after every `session.prompt()` resolves (success or error)
|
|
740
740
|
- `session.start`/`session.end`: `src/server/index.ts` ws open/close
|
|
741
|
-
- `tool.before`/`tool.after`: `src/agent/plugin-tools.ts` `wrapPluginTool`, `wrapSystemTool`,
|
|
741
|
+
- `tool.before`/`tool.after`: `src/agent/plugin-tools.ts` `wrapPluginTool`, `wrapSystemTool`, and `wrapBuiltinToolDefinition`. The last one is the load-bearing path for pi's builtin coding tools (`read`/`bash`/`edit`/`write`/`grep`/`find`/`ls`): as of pi-coding-agent 0.73, every builtin is a `ToolDefinition` (via pi's `create*ToolDefinition` factories) that TypeClaw wraps and ships through `customTools`, while `createAgentSession({ noTools: 'builtin', tools })` disables pi's unwrapped copies and narrows the active set to an explicit name allowlist. See the top-of-file contract block in `plugin-tools.ts` for the full reasoning.
|
|
742
742
|
- **Schema additions**: `src/config/config.ts` (`plugins` array, `.catchall(z.unknown())` for per-plugin blocks, `extractPluginConfigs`)
|
|
743
743
|
|
|
744
744
|
### Audit log on boot
|
package/src/stream/broker.ts
CHANGED
|
@@ -22,12 +22,13 @@ const DEFAULT_HISTORY_SIZE = 1000
|
|
|
22
22
|
export function createStream(opts: CreateStreamOptions = {}): Stream {
|
|
23
23
|
const subscriptions = new Set<Subscription>()
|
|
24
24
|
const historySize = Math.max(0, opts.historySize ?? DEFAULT_HISTORY_SIZE)
|
|
25
|
+
const now = opts.now ?? Date.now
|
|
25
26
|
const history: StreamMessage[] = []
|
|
26
27
|
let counter = 0
|
|
27
28
|
|
|
28
29
|
function generateId(): StreamMessageId {
|
|
29
30
|
counter++
|
|
30
|
-
return `s_${
|
|
31
|
+
return `s_${now().toString(36)}_${counter.toString(36)}_${Math.random().toString(36).slice(2, 8)}`
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
function record(msg: StreamMessage): void {
|
|
@@ -51,7 +52,7 @@ export function createStream(opts: CreateStreamOptions = {}): Stream {
|
|
|
51
52
|
function publishMessage(input: StreamMessageInput): StreamMessage {
|
|
52
53
|
const msg: StreamMessage = {
|
|
53
54
|
id: generateId(),
|
|
54
|
-
ts:
|
|
55
|
+
ts: now(),
|
|
55
56
|
target: input.target,
|
|
56
57
|
payload: input.payload,
|
|
57
58
|
...(input.replyTo !== undefined ? { replyTo: input.replyTo } : {}),
|
|
@@ -73,7 +74,7 @@ export function createStream(opts: CreateStreamOptions = {}): Stream {
|
|
|
73
74
|
const requestId = generateId()
|
|
74
75
|
const requestMessage: StreamMessage = {
|
|
75
76
|
id: requestId,
|
|
76
|
-
ts:
|
|
77
|
+
ts: now(),
|
|
77
78
|
target: input.target,
|
|
78
79
|
payload: input.payload,
|
|
79
80
|
...(input.replyTo !== undefined ? { replyTo: input.replyTo } : {}),
|