typeclaw 0.37.6 → 0.38.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.
- package/README.md +2 -2
- package/package.json +2 -2
- package/src/agent/attention-escalation.ts +590 -0
- package/src/agent/session-origin.ts +11 -7
- package/src/agent/subagents.ts +2 -0
- package/src/agent/system-prompt.ts +2 -2
- package/src/channels/adapters/webex-bot-channel-resolver.ts +29 -0
- package/src/channels/adapters/webex-bot-classify.ts +92 -0
- package/src/channels/adapters/webex-bot-reference.ts +47 -0
- package/src/channels/adapters/webex-bot.ts +395 -0
- package/src/channels/manager.ts +15 -0
- package/src/channels/router.ts +10 -1
- package/src/channels/schema.ts +15 -1
- package/src/cli/channel.ts +38 -2
- package/src/cli/init.ts +67 -6
- package/src/cli/restart.ts +1 -0
- package/src/cli/start.ts +1 -0
- package/src/config/channels-mutation.ts +9 -1
- package/src/config/config.ts +12 -10
- package/src/container/start.ts +17 -4
- package/src/cron/consumer.ts +7 -0
- package/src/doctor/channel-checks.ts +13 -1
- package/src/doctor/checks.ts +13 -1
- package/src/init/dockerfile.ts +51 -3
- package/src/init/index.ts +39 -16
- package/src/init/run-owner-claim.ts +1 -0
- package/src/permissions/match-rule.ts +7 -3
- package/src/permissions/resolve.ts +6 -4
- package/src/role-claim/match-rule.ts +2 -1
- package/src/secrets/defaults.ts +1 -0
- package/src/server/command-runner.ts +2 -0
- package/src/server/index.ts +9 -0
- package/typeclaw.schema.json +161 -1
package/src/channels/schema.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
export const ADAPTER_IDS = [
|
|
3
|
+
export const ADAPTER_IDS = [
|
|
4
|
+
'discord-bot',
|
|
5
|
+
'github',
|
|
6
|
+
'line',
|
|
7
|
+
'kakaotalk',
|
|
8
|
+
'slack-bot',
|
|
9
|
+
'telegram-bot',
|
|
10
|
+
'webex-bot',
|
|
11
|
+
] as const
|
|
4
12
|
|
|
5
13
|
export type AdapterId = (typeof ADAPTER_IDS)[number]
|
|
6
14
|
|
|
@@ -262,6 +270,12 @@ export const channelsSchema = z
|
|
|
262
270
|
kakaotalk: adapterSchema.optional(),
|
|
263
271
|
'slack-bot': adapterSchema.optional(),
|
|
264
272
|
'telegram-bot': adapterSchema.optional(),
|
|
273
|
+
// Webex bots receive messages in real time over a Mercury WebSocket
|
|
274
|
+
// (agent-messenger's WebexBotListener), the same persistent-socket model
|
|
275
|
+
// as slack-bot (Socket Mode) and discord-bot (Gateway) — no public
|
|
276
|
+
// webhook URL required. Single bot-token auth; config shape is the
|
|
277
|
+
// standard adapterSchema (engagement + history + enabled).
|
|
278
|
+
'webex-bot': adapterSchema.optional(),
|
|
265
279
|
})
|
|
266
280
|
.default({})
|
|
267
281
|
|
package/src/cli/channel.ts
CHANGED
|
@@ -42,6 +42,7 @@ const CHANNEL_LABELS: Record<ChannelKind, string> = {
|
|
|
42
42
|
'slack-bot': 'Slack',
|
|
43
43
|
'discord-bot': 'Discord',
|
|
44
44
|
'telegram-bot': 'Telegram',
|
|
45
|
+
'webex-bot': 'Webex',
|
|
45
46
|
line: 'LINE',
|
|
46
47
|
kakaotalk: 'KakaoTalk',
|
|
47
48
|
github: 'GitHub',
|
|
@@ -104,7 +105,7 @@ const addSub = defineCommand({
|
|
|
104
105
|
// is included here but routed through its own prompt path because it has
|
|
105
106
|
// three independent secrets (PAT or App private key + webhook secret) and a
|
|
106
107
|
// structural auth-type flip is forbidden during rotation.
|
|
107
|
-
const SETTABLE_ADAPTERS = ['slack-bot', 'discord-bot', 'telegram-bot', 'github'] as const
|
|
108
|
+
const SETTABLE_ADAPTERS = ['slack-bot', 'discord-bot', 'telegram-bot', 'webex-bot', 'github'] as const
|
|
108
109
|
type SettableAdapter = (typeof SETTABLE_ADAPTERS)[number]
|
|
109
110
|
|
|
110
111
|
const setSub = defineCommand({
|
|
@@ -651,6 +652,9 @@ async function runSet(cwd: string, adapter: SettableAdapter): Promise<void> {
|
|
|
651
652
|
case 'telegram-bot':
|
|
652
653
|
await runSetTelegram(cwd)
|
|
653
654
|
break
|
|
655
|
+
case 'webex-bot':
|
|
656
|
+
await runSetWebex(cwd)
|
|
657
|
+
break
|
|
654
658
|
case 'slack-bot':
|
|
655
659
|
await runSetSlack(cwd)
|
|
656
660
|
break
|
|
@@ -680,6 +684,16 @@ async function runSetTelegram(cwd: string): Promise<void> {
|
|
|
680
684
|
await maybePromptCredentialRefresh(cwd, CHANNEL_LABELS['telegram-bot'], 'credentials updated')
|
|
681
685
|
}
|
|
682
686
|
|
|
687
|
+
async function runSetWebex(cwd: string): Promise<void> {
|
|
688
|
+
const token = await promptWebexToken()
|
|
689
|
+
const result = await setChannelSecrets(cwd, 'webex-bot', { token })
|
|
690
|
+
if (!result.ok) {
|
|
691
|
+
console.error(errorLine(result.reason))
|
|
692
|
+
process.exit(1)
|
|
693
|
+
}
|
|
694
|
+
await maybePromptCredentialRefresh(cwd, CHANNEL_LABELS['webex-bot'], 'credentials updated')
|
|
695
|
+
}
|
|
696
|
+
|
|
683
697
|
type SlackSetChoice = 'bot' | 'app' | 'both'
|
|
684
698
|
|
|
685
699
|
async function runSetSlack(cwd: string): Promise<void> {
|
|
@@ -778,6 +792,7 @@ type CollectedCredentials =
|
|
|
778
792
|
| { channel: 'discord-bot'; discordBotToken: string }
|
|
779
793
|
| { channel: 'slack-bot'; slackBotToken: string; slackAppToken: string }
|
|
780
794
|
| { channel: 'telegram-bot'; telegramBotToken: string }
|
|
795
|
+
| { channel: 'webex-bot'; webexBotToken: string }
|
|
781
796
|
| { channel: 'line'; runLineAuth: (options: { cwd: string }) => Promise<LineAuthResult> }
|
|
782
797
|
| { channel: 'kakaotalk'; runKakaotalkAuth: (options: { cwd: string }) => Promise<KakaotalkAuthResult> }
|
|
783
798
|
| {
|
|
@@ -804,6 +819,8 @@ async function collectCredentials(
|
|
|
804
819
|
}
|
|
805
820
|
case 'telegram-bot':
|
|
806
821
|
return { channel, telegramBotToken: await promptTelegramToken() }
|
|
822
|
+
case 'webex-bot':
|
|
823
|
+
return { channel, webexBotToken: await promptWebexToken() }
|
|
807
824
|
case 'line': {
|
|
808
825
|
const login = await promptLineLogin(lineSpinnerHolder ? holderSpinnerControl(lineSpinnerHolder) : undefined)
|
|
809
826
|
return {
|
|
@@ -1116,7 +1133,7 @@ async function promptDiscordToken(): Promise<string> {
|
|
|
1116
1133
|
[
|
|
1117
1134
|
'https://discord.com/developers/applications',
|
|
1118
1135
|
'New Application → Bot tab → Reset Token.',
|
|
1119
|
-
'
|
|
1136
|
+
'Under Privileged Gateway Intents, enable MESSAGE CONTENT and GUILD MEMBERS.',
|
|
1120
1137
|
].join('\n'),
|
|
1121
1138
|
'Get a Discord bot token',
|
|
1122
1139
|
)
|
|
@@ -1212,6 +1229,25 @@ async function promptTelegramToken(): Promise<string> {
|
|
|
1212
1229
|
return token
|
|
1213
1230
|
}
|
|
1214
1231
|
|
|
1232
|
+
async function promptWebexToken(): Promise<string> {
|
|
1233
|
+
note(
|
|
1234
|
+
[
|
|
1235
|
+
'Create a bot at https://developer.webex.com/my-apps/new/bot.',
|
|
1236
|
+
'Copy the Bot Access Token from the bot settings page.',
|
|
1237
|
+
].join('\n'),
|
|
1238
|
+
'Get a Webex bot token',
|
|
1239
|
+
)
|
|
1240
|
+
const token = await password({
|
|
1241
|
+
message: 'Webex bot access token',
|
|
1242
|
+
validate: (value) => (value && value.length > 0 ? undefined : 'Token is required'),
|
|
1243
|
+
})
|
|
1244
|
+
if (isCancel(token)) {
|
|
1245
|
+
cancel('Aborted.')
|
|
1246
|
+
process.exit(0)
|
|
1247
|
+
}
|
|
1248
|
+
return token
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1215
1251
|
async function promptKakaotalkCredentials(
|
|
1216
1252
|
opts: { defaultEmail?: string } = {},
|
|
1217
1253
|
): Promise<{ email: string; password: string }> {
|
package/src/cli/init.ts
CHANGED
|
@@ -532,6 +532,15 @@ export async function collectWizardInputs(
|
|
|
532
532
|
let pendingBackOrigin: StepId | null = null
|
|
533
533
|
let oauthCredentialsSaved = false
|
|
534
534
|
|
|
535
|
+
// One-shot replay of checkpoint answers: while active, choice steps whose
|
|
536
|
+
// answer was seeded auto-advance (running their normal tail) instead of
|
|
537
|
+
// re-prompting. The first interactive prompt or any Back ends the replay
|
|
538
|
+
// (cleared in `onResult`), so back-navigation behaves like a fresh wizard.
|
|
539
|
+
// Secret-entry steps are never in `resumeCovered`, so a checkpointed
|
|
540
|
+
// `authMethod` still drops to its key/login prompt when nothing is on disk.
|
|
541
|
+
const resumeReplay = { active: false }
|
|
542
|
+
const resumeCovered = new Set<StepId>()
|
|
543
|
+
|
|
535
544
|
// Resume saved wizard answers from a prior unfinished init. `--reset` skips
|
|
536
545
|
// this entirely (the user asked to re-answer everything). Route through the
|
|
537
546
|
// shared detectInitProgress() predicate so init/start/restart classify a
|
|
@@ -554,6 +563,9 @@ export async function collectWizardInputs(
|
|
|
554
563
|
const decision = await prompts.confirmResumeCheckpoint(sanitized)
|
|
555
564
|
if (decision === 'resume') {
|
|
556
565
|
seedWizardState(state, sanitized)
|
|
566
|
+
step = resumeStep(state)
|
|
567
|
+
resumeReplay.active = true
|
|
568
|
+
for (const covered of resumeCoveredSteps(state)) resumeCovered.add(covered)
|
|
557
569
|
} else {
|
|
558
570
|
await checkpointStore.clear(cwd)
|
|
559
571
|
}
|
|
@@ -570,6 +582,11 @@ export async function collectWizardInputs(
|
|
|
570
582
|
}
|
|
571
583
|
|
|
572
584
|
const onResult = <T>(currentStep: StepId, result: StepResult<T>): StepResult<T> => {
|
|
585
|
+
// Any Back, or any non-auto (interactive) answer, ends the resume replay:
|
|
586
|
+
// from here on the user is driving, so downstream seeded steps prompt
|
|
587
|
+
// normally. Synthesized auto-skips keep replay alive and, as before, leave
|
|
588
|
+
// `pendingBackOrigin` untouched so they never affect double-back abort.
|
|
589
|
+
if (result.kind === 'back' || !result.auto) resumeReplay.active = false
|
|
573
590
|
if (result.kind === 'back') {
|
|
574
591
|
if (pendingBackOrigin === currentStep) abort()
|
|
575
592
|
pendingBackOrigin = currentStep
|
|
@@ -579,6 +596,16 @@ export async function collectWizardInputs(
|
|
|
579
596
|
return result
|
|
580
597
|
}
|
|
581
598
|
|
|
599
|
+
// Synthesize a step's seeded answer as an auto-advance result during resume
|
|
600
|
+
// replay, so the step runs its normal tail (state assignment, on-disk
|
|
601
|
+
// credential reconstruction, routing) without re-prompting. Returns
|
|
602
|
+
// undefined when replay is off, this step isn't checkpoint-covered, or the
|
|
603
|
+
// value is unset — callers fall back to the real prompt.
|
|
604
|
+
const resumeSkip = <T>(currentStep: StepId, value: T | undefined): StepResult<T> | undefined => {
|
|
605
|
+
if (!resumeReplay.active || !resumeCovered.has(currentStep) || value === undefined) return undefined
|
|
606
|
+
return { kind: 'value', value, auto: true }
|
|
607
|
+
}
|
|
608
|
+
|
|
582
609
|
const readExistingApiKey = async (providerId: KnownProviderId): Promise<string | null> => {
|
|
583
610
|
if (reset) return null
|
|
584
611
|
return await prompts.readExistingApiKey(cwd, providerId)
|
|
@@ -724,7 +751,11 @@ export async function collectWizardInputs(
|
|
|
724
751
|
}
|
|
725
752
|
|
|
726
753
|
case 'pick-model': {
|
|
727
|
-
const result = onResult(
|
|
754
|
+
const result = onResult(
|
|
755
|
+
step,
|
|
756
|
+
resumeSkip(step, state.model) ??
|
|
757
|
+
(await prompts.pickModel(catalog.options, state.providerId!, state.model?.ref)),
|
|
758
|
+
)
|
|
728
759
|
if (result.kind === 'back') {
|
|
729
760
|
step = stepBeforeModel(state)
|
|
730
761
|
break
|
|
@@ -757,7 +788,11 @@ export async function collectWizardInputs(
|
|
|
757
788
|
|
|
758
789
|
case 'pick-vision-vendor': {
|
|
759
790
|
const visionOptions = catalog.options.filter((o) => o.supportsVision)
|
|
760
|
-
const result = onResult(
|
|
791
|
+
const result: StepResult<KnownProviderVendorId | 'skip'> = onResult(
|
|
792
|
+
step,
|
|
793
|
+
resumeSkip<KnownProviderVendorId | 'skip'>(step, state.visionVendorId) ??
|
|
794
|
+
(await prompts.pickVisionVendor(visionOptions, state.visionVendorId)),
|
|
795
|
+
)
|
|
761
796
|
if (result.kind === 'back') {
|
|
762
797
|
step = stepBeforeVision(state)
|
|
763
798
|
break
|
|
@@ -788,7 +823,8 @@ export async function collectWizardInputs(
|
|
|
788
823
|
const visionOptions = catalog.options.filter((o) => o.supportsVision)
|
|
789
824
|
const result = onResult(
|
|
790
825
|
step,
|
|
791
|
-
|
|
826
|
+
resumeSkip(step, state.visionProviderId) ??
|
|
827
|
+
(await prompts.pickVisionProviderVariant(state.visionVendorId!, visionOptions, state.visionProviderId)),
|
|
792
828
|
)
|
|
793
829
|
if (result.kind === 'back') {
|
|
794
830
|
step = 'pick-vision-vendor'
|
|
@@ -809,7 +845,8 @@ export async function collectWizardInputs(
|
|
|
809
845
|
const visionOptions = catalog.options.filter((o) => o.supportsVision)
|
|
810
846
|
const result = onResult(
|
|
811
847
|
step,
|
|
812
|
-
|
|
848
|
+
resumeSkip(step, state.visionModel) ??
|
|
849
|
+
(await prompts.pickVisionModel(visionOptions, state.visionProviderId!, state.visionModel?.ref)),
|
|
813
850
|
)
|
|
814
851
|
if (result.kind === 'back') {
|
|
815
852
|
step = 'pick-vision-provider-variant'
|
|
@@ -901,7 +938,10 @@ export async function collectWizardInputs(
|
|
|
901
938
|
}
|
|
902
939
|
|
|
903
940
|
case 'pick-channel': {
|
|
904
|
-
const result: StepResult<ChannelChoice> = onResult(
|
|
941
|
+
const result: StepResult<ChannelChoice> = onResult(
|
|
942
|
+
step,
|
|
943
|
+
resumeSkip(step, state.channelChoice) ?? (await prompts.pickChannel(state.channelChoice)),
|
|
944
|
+
)
|
|
905
945
|
if (result.kind === 'back') {
|
|
906
946
|
step = stepBeforePickChannel(state)
|
|
907
947
|
break
|
|
@@ -1030,6 +1070,27 @@ function resolveModelOption(catalog: WizardState['catalog'], ref: string | undef
|
|
|
1030
1070
|
return catalog.options.find((option) => option.ref === ref)
|
|
1031
1071
|
}
|
|
1032
1072
|
|
|
1073
|
+
function resumeStep(state: WizardState): StepId {
|
|
1074
|
+
if (state.providerId !== undefined) return 'reuse-existing-key'
|
|
1075
|
+
if (state.vendorId !== undefined) return 'pick-provider-variant'
|
|
1076
|
+
return 'pick-vendor'
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// Choice steps whose seeded answer lets resume replay auto-advance them. Only
|
|
1080
|
+
// non-secret picks the checkpoint actually carries — never `enter-api-key` /
|
|
1081
|
+
// `enter-vision-api-key` (key values aren't checkpointed) and never the
|
|
1082
|
+
// reuse-* / channel-flow steps (those reconstruct from disk or collect secrets,
|
|
1083
|
+
// so they must run their own logic, not replay a stored answer).
|
|
1084
|
+
function resumeCoveredSteps(state: WizardState): StepId[] {
|
|
1085
|
+
const covered: StepId[] = []
|
|
1086
|
+
if (state.model !== undefined) covered.push('pick-model')
|
|
1087
|
+
if (state.visionVendorId !== undefined) covered.push('pick-vision-vendor')
|
|
1088
|
+
if (state.visionProviderId !== undefined) covered.push('pick-vision-provider-variant')
|
|
1089
|
+
if (state.visionModel !== undefined) covered.push('pick-vision-model')
|
|
1090
|
+
if (state.channelChoice !== undefined) covered.push('pick-channel')
|
|
1091
|
+
return covered
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1033
1094
|
function projectCheckpoint(cwd: string, state: WizardState): WizardAnswerCheckpointV1 {
|
|
1034
1095
|
return checkpointFromSelections({
|
|
1035
1096
|
cwd,
|
|
@@ -1429,7 +1490,7 @@ async function runDiscordFlow(): Promise<StepResult<CollectedInputs['channelSecr
|
|
|
1429
1490
|
[
|
|
1430
1491
|
'https://discord.com/developers/applications',
|
|
1431
1492
|
'New Application → Bot tab → Reset Token.',
|
|
1432
|
-
'
|
|
1493
|
+
'Under Privileged Gateway Intents, enable MESSAGE CONTENT and GUILD MEMBERS.',
|
|
1433
1494
|
].join('\n'),
|
|
1434
1495
|
'Get a Discord bot token',
|
|
1435
1496
|
)
|
package/src/cli/restart.ts
CHANGED
package/src/cli/start.ts
CHANGED
|
@@ -7,7 +7,15 @@ import { SecretsBackend } from '@/secrets'
|
|
|
7
7
|
const CONFIG_FILE = 'typeclaw.json'
|
|
8
8
|
const SECRETS_FILE = 'secrets.json'
|
|
9
9
|
|
|
10
|
-
export const CHANNEL_KINDS = [
|
|
10
|
+
export const CHANNEL_KINDS = [
|
|
11
|
+
'slack-bot',
|
|
12
|
+
'discord-bot',
|
|
13
|
+
'telegram-bot',
|
|
14
|
+
'webex-bot',
|
|
15
|
+
'line',
|
|
16
|
+
'kakaotalk',
|
|
17
|
+
'github',
|
|
18
|
+
] as const
|
|
11
19
|
|
|
12
20
|
export type ChannelKind = (typeof CHANNEL_KINDS)[number]
|
|
13
21
|
|
package/src/config/config.ts
CHANGED
|
@@ -1200,14 +1200,18 @@ export function validateConfig(cwd: string, options: ValidateConfigOptions = {})
|
|
|
1200
1200
|
const parsed = parseConfigJson(raw, { migrate: true, persistTarget: cwd })
|
|
1201
1201
|
if (!parsed.ok) return parsed
|
|
1202
1202
|
|
|
1203
|
-
|
|
1203
|
+
// Append lines are advisory here — never fatal. The Dockerfile renderer
|
|
1204
|
+
// (renderCustomDockerfileLines) is the enforcement boundary: it STRIPS unsafe
|
|
1205
|
+
// lines so the container still comes up, and a bad line written by the
|
|
1206
|
+
// in-container agent can never brick `typeclaw start`. We surface the same
|
|
1207
|
+
// strip/warn decisions as warnings so the operator sees them pre-build.
|
|
1204
1208
|
const warnings: string[] = []
|
|
1205
1209
|
const appendLines = parsed.config.docker.file.append
|
|
1206
1210
|
for (let i = 0; i < appendLines.length; i++) {
|
|
1207
1211
|
const check = validateDockerfileAppendLine(appendLines[i]!)
|
|
1208
1212
|
if (!check.ok) {
|
|
1209
|
-
|
|
1210
|
-
|
|
1213
|
+
warnings.push(`docker.file.append[${i}] will be stripped on start — ${check.reason}`)
|
|
1214
|
+
continue
|
|
1211
1215
|
}
|
|
1212
1216
|
if (check.warning) warnings.push(`docker.file.append[${i}] ${check.warning}`)
|
|
1213
1217
|
}
|
|
@@ -1317,12 +1321,6 @@ export function validateMount(mount: Mount, cwd: string): ValidateConfigResult {
|
|
|
1317
1321
|
return { ok: true }
|
|
1318
1322
|
}
|
|
1319
1323
|
|
|
1320
|
-
// Host env (not config) on purpose: an in-container agent can edit its own
|
|
1321
|
-
// typeclaw.json but cannot set the env of the host `typeclaw start` that runs
|
|
1322
|
-
// this gate, so it can never waive its own footgun. Only relaxes SEMANTIC
|
|
1323
|
-
// blocks; structural blocks always fire (they break Dockerfile generation).
|
|
1324
|
-
const ALLOW_UNSAFE_DOCKER_APPEND_ENV = 'TYPECLAW_ALLOW_UNSAFE_DOCKER_APPEND'
|
|
1325
|
-
|
|
1326
1324
|
// FROM/ENTRYPOINT/CMD/MAINTAINER are intentionally excluded — see the
|
|
1327
1325
|
// structural blocks in validateDockerfileAppendLine for why.
|
|
1328
1326
|
const ALLOWED_APPEND_INSTRUCTIONS = new Set([
|
|
@@ -1450,9 +1448,13 @@ export function validateDockerfileAppendLine(line: string): AppendLineCheck {
|
|
|
1450
1448
|
}
|
|
1451
1449
|
}
|
|
1452
1450
|
if (!ALLOWED_APPEND_INSTRUCTIONS.has(instruction)) {
|
|
1451
|
+
// Reason is intentionally input-free: this string is forwarded verbatim into
|
|
1452
|
+
// operator-facing warnings (classifyDockerfileAppend -> dockerfileWarnings),
|
|
1453
|
+
// and the offending token is user-controlled — echoing it could leak a
|
|
1454
|
+
// secret/token-like first word from a malformed line into start/doctor output.
|
|
1453
1455
|
return {
|
|
1454
1456
|
ok: false,
|
|
1455
|
-
reason:
|
|
1457
|
+
reason: 'does not begin with a recognized Dockerfile instruction',
|
|
1456
1458
|
kind: 'structural',
|
|
1457
1459
|
}
|
|
1458
1460
|
}
|
package/src/container/start.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
readInstalledTypeclawVersionFromAgent,
|
|
21
21
|
} from '@/init/auto-upgrade'
|
|
22
22
|
import { resolveBaseImageVersion } from '@/init/cli-version'
|
|
23
|
-
import { buildDockerfile, DOCKERFILE } from '@/init/dockerfile'
|
|
23
|
+
import { buildDockerfile, classifyDockerfileAppend, DOCKERFILE } from '@/init/dockerfile'
|
|
24
24
|
import { ensureDepsInstalled, type EnsureDepsResult } from '@/init/ensure-deps'
|
|
25
25
|
import { buildGitignore, GITIGNORE_FILE } from '@/init/gitignore'
|
|
26
26
|
import { refreshPackageJson } from '@/init/packagejson'
|
|
@@ -148,6 +148,10 @@ export type StartResult =
|
|
|
148
148
|
// registry. Non-fatal by design: a typo'd or unpublished plugin warns
|
|
149
149
|
// instead of blocking the launch.
|
|
150
150
|
skippedPlugins: string[]
|
|
151
|
+
// Non-fatal warnings from docker.file.append: unsafe lines stripped from
|
|
152
|
+
// the generated Dockerfile, plus warn-but-allow lines (curl|bash, remote
|
|
153
|
+
// ADD). Surfaced by the CLI so a stripped line is never a silent no-op.
|
|
154
|
+
dockerfileWarnings: string[]
|
|
151
155
|
}
|
|
152
156
|
| { ok: false; reason: string }
|
|
153
157
|
|
|
@@ -485,6 +489,7 @@ export async function start({
|
|
|
485
489
|
alreadyRunning: false,
|
|
486
490
|
autoUpgrade: upgrade,
|
|
487
491
|
skippedPlugins: pluginReconcile.skipped,
|
|
492
|
+
dockerfileWarnings: dockerfileRefresh.warnings,
|
|
488
493
|
}
|
|
489
494
|
} catch (error) {
|
|
490
495
|
return { ok: false, reason: error instanceof Error ? error.message : String(error) }
|
|
@@ -701,18 +706,24 @@ async function resolvePublishHost(exec: DockerExec): Promise<string> {
|
|
|
701
706
|
// the cheapest correct signal: the build context for `docker build` is the
|
|
702
707
|
// Dockerfile itself, so equal contents definitionally produce an equivalent
|
|
703
708
|
// image.
|
|
704
|
-
export async function refreshDockerfile(
|
|
709
|
+
export async function refreshDockerfile(
|
|
710
|
+
cwd: string,
|
|
711
|
+
opts: { buildKit?: boolean } = {},
|
|
712
|
+
): Promise<{ changed: boolean; warnings: string[] }> {
|
|
705
713
|
const cfg = await loadTypeclawConfig(cwd)
|
|
706
714
|
const next = buildDockerfile(cfg.docker.file, {
|
|
707
715
|
baseImageVersion: resolveBaseImageVersion(cwd),
|
|
708
716
|
cjkFontsAuto: hostLocaleIsCjk(),
|
|
709
717
|
buildKit: opts.buildKit,
|
|
710
718
|
})
|
|
719
|
+
// Reuse the renderer's classifier so reported warnings match exactly what was
|
|
720
|
+
// stripped/kept in the Dockerfile above (single source of truth).
|
|
721
|
+
const { warnings } = classifyDockerfileAppend(cfg.docker.file.append)
|
|
711
722
|
const path = join(cwd, DOCKERFILE)
|
|
712
723
|
const prev = await readFile(path, 'utf8').catch(() => null)
|
|
713
|
-
if (prev === next) return { changed: false }
|
|
724
|
+
if (prev === next) return { changed: false, warnings }
|
|
714
725
|
await writeFile(path, next)
|
|
715
|
-
return { changed: true }
|
|
726
|
+
return { changed: true, warnings }
|
|
716
727
|
}
|
|
717
728
|
|
|
718
729
|
// Builds the agent image with a seamless buildx->legacy fallback. The preferred
|
|
@@ -836,6 +847,7 @@ async function reportAlreadyRunning(exec: DockerExec, cwd: string, containerName
|
|
|
836
847
|
}
|
|
837
848
|
const tuiToken = await resolveTuiToken({ cwd, exec })
|
|
838
849
|
const plan = await planStart({ cwd, hostPort, imageExists: true, forceBuild: false, tuiToken })
|
|
850
|
+
const { warnings: dockerfileWarnings } = classifyDockerfileAppend((await loadTypeclawConfig(cwd)).docker.file.append)
|
|
839
851
|
return {
|
|
840
852
|
ok: true,
|
|
841
853
|
plan,
|
|
@@ -847,6 +859,7 @@ async function reportAlreadyRunning(exec: DockerExec, cwd: string, containerName
|
|
|
847
859
|
alreadyRunning: true,
|
|
848
860
|
autoUpgrade: { kind: 'skipped-already-running' },
|
|
849
861
|
skippedPlugins: [],
|
|
862
|
+
dockerfileWarnings,
|
|
850
863
|
}
|
|
851
864
|
}
|
|
852
865
|
|
package/src/cron/consumer.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AgentSession } from '@/agent'
|
|
2
|
+
import { applyTurnThinkingLevel } from '@/agent/attention-escalation'
|
|
2
3
|
import { promptWithFallback, resolveFallbackChain } from '@/agent/model-fallback'
|
|
3
4
|
import type { SessionOrigin } from '@/agent/session-origin'
|
|
4
5
|
import { getConfig } from '@/config'
|
|
@@ -235,6 +236,12 @@ async function runPromptOnce(
|
|
|
235
236
|
if (created.hooks && turnEvent !== undefined) {
|
|
236
237
|
await created.hooks.runSessionTurnStart({ ...turnEvent, userPrompt: job.prompt, retrievalContext })
|
|
237
238
|
}
|
|
239
|
+
// Cron sessions are created fresh per fallback attempt, so the live getter
|
|
240
|
+
// is still the creation-time default here — safe to read without a separate
|
|
241
|
+
// captured field. The test-fake path omits `.session`; skip it then.
|
|
242
|
+
if (created.session !== undefined) {
|
|
243
|
+
applyTurnThinkingLevel(created.session, job.prompt, created.session.thinkingLevel)
|
|
244
|
+
}
|
|
238
245
|
// Bridge the CronSession wrapper into the AgentSession surface the
|
|
239
246
|
// fallback helper expects:
|
|
240
247
|
// prompt → CronSession.prompt (wrapper that calls AgentSession.prompt
|
|
@@ -28,6 +28,7 @@ export function buildChannelChecks(): DoctorCheck[] {
|
|
|
28
28
|
slackBotCredentials(),
|
|
29
29
|
discordBotCredentials(),
|
|
30
30
|
telegramBotCredentials(),
|
|
31
|
+
webexBotCredentials(),
|
|
31
32
|
lineCredentials(),
|
|
32
33
|
kakaotalkCredentials(),
|
|
33
34
|
githubCredentials(),
|
|
@@ -65,6 +66,16 @@ function telegramBotCredentials(): DoctorCheck {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
function webexBotCredentials(): DoctorCheck {
|
|
70
|
+
return {
|
|
71
|
+
name: 'channel.webex-bot.credentials',
|
|
72
|
+
category: 'channels',
|
|
73
|
+
description: 'webex-bot adapter has WEBEX_BOT_TOKEN',
|
|
74
|
+
applies: (ctx) => ctx.hasAgentFolder,
|
|
75
|
+
run: (ctx) => runTokenAdapterCheck(ctx, 'webex-bot', ['WEBEX_BOT_TOKEN']),
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
68
79
|
function lineCredentials(): DoctorCheck {
|
|
69
80
|
return {
|
|
70
81
|
name: 'channel.line.credentials',
|
|
@@ -216,7 +227,7 @@ function githubWebhookDelivery(): DoctorCheck {
|
|
|
216
227
|
|
|
217
228
|
async function runTokenAdapterCheck(
|
|
218
229
|
ctx: CheckContext,
|
|
219
|
-
adapter: Extract<AdapterId, 'slack-bot' | 'discord-bot' | 'telegram-bot'>,
|
|
230
|
+
adapter: Extract<AdapterId, 'slack-bot' | 'discord-bot' | 'telegram-bot' | 'webex-bot'>,
|
|
220
231
|
envNames: readonly string[],
|
|
221
232
|
): Promise<CheckResult> {
|
|
222
233
|
const channels = readDeclaredChannels(ctx)
|
|
@@ -297,6 +308,7 @@ function fieldNameForEnv(adapter: AdapterId, envName: string): string | undefine
|
|
|
297
308
|
'slack-bot': ['botToken', 'appToken'],
|
|
298
309
|
'discord-bot': ['token'],
|
|
299
310
|
'telegram-bot': ['token'],
|
|
311
|
+
'webex-bot': ['token'],
|
|
300
312
|
}
|
|
301
313
|
const fields = candidates[adapter]
|
|
302
314
|
if (!fields) return undefined
|
package/src/doctor/checks.ts
CHANGED
|
@@ -210,7 +210,19 @@ function configValid(): DoctorCheck {
|
|
|
210
210
|
applies: (ctx) => ctx.hasAgentFolder,
|
|
211
211
|
async run(ctx) {
|
|
212
212
|
const result = validateConfig(ctx.cwd)
|
|
213
|
-
if (result.ok)
|
|
213
|
+
if (result.ok) {
|
|
214
|
+
if (result.warnings && result.warnings.length > 0) {
|
|
215
|
+
return {
|
|
216
|
+
status: 'warning',
|
|
217
|
+
message: `typeclaw.json valid; ${result.warnings.length} docker.file.append warning(s):\n${result.warnings.join('\n')}`,
|
|
218
|
+
fix: {
|
|
219
|
+
description:
|
|
220
|
+
'Review the docker.file.append entries above; unsafe lines are stripped from the Dockerfile on start.',
|
|
221
|
+
},
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return { status: 'ok', message: 'typeclaw.json valid; mounts accessible' }
|
|
225
|
+
}
|
|
214
226
|
return {
|
|
215
227
|
status: 'error',
|
|
216
228
|
message: result.reason,
|
package/src/init/dockerfile.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateDockerfileAppendLine } from '@/config/config'
|
|
1
2
|
import type { DockerfileConfig, DockerfileFeatureToggle } from '@/config/config'
|
|
2
3
|
import {
|
|
3
4
|
CLAUDE_CREDENTIALS_FILE_NAME,
|
|
@@ -1700,10 +1701,57 @@ RUN ${aptCacheMount(buildKit)}apt-get update \\
|
|
|
1700
1701
|
`
|
|
1701
1702
|
}
|
|
1702
1703
|
|
|
1704
|
+
// Render-time enforcement is the security boundary: this is the sole bottleneck
|
|
1705
|
+
// where docker.file.append entries reach the generated Dockerfile, so unsafe
|
|
1706
|
+
// lines are STRIPPED here (never spliced into the build) rather than blocking
|
|
1707
|
+
// `typeclaw start`. docker.file.append is untrusted input even when the
|
|
1708
|
+
// in-container agent writes it — a bad line (e.g. the decode-and-exec footgun
|
|
1709
|
+
// that bricked a real build) becomes ineffective, not fatal. Validation
|
|
1710
|
+
// elsewhere only warns; this is what guarantees the line never runs.
|
|
1703
1711
|
function renderCustomDockerfileLines(lines: string[]): string {
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1712
|
+
const { kept, strippedCount } = classifyDockerfileAppend(lines)
|
|
1713
|
+
if (kept.length === 0 && strippedCount === 0) return ''
|
|
1714
|
+
// Durable, payload-free record so a stripped line isn't a silent no-op: the
|
|
1715
|
+
// operator sees the Dockerfile itself note the count (full reasons surface as
|
|
1716
|
+
// startup warnings). Never echo the stripped content — it may carry secrets.
|
|
1717
|
+
const strippedNote =
|
|
1718
|
+
strippedCount > 0
|
|
1719
|
+
? `# typeclaw stripped ${strippedCount} unsafe docker.file.append line(s); see startup warnings and typeclaw.json.
|
|
1720
|
+
`
|
|
1721
|
+
: ''
|
|
1722
|
+
if (kept.length === 0) return strippedNote ? `${strippedNote}\n` : ''
|
|
1723
|
+
return `${strippedNote}# Custom lines from typeclaw.json#docker.file.append.
|
|
1724
|
+
${kept.join('\n')}
|
|
1707
1725
|
|
|
1708
1726
|
`
|
|
1709
1727
|
}
|
|
1728
|
+
|
|
1729
|
+
export type DockerfileAppendClassification = {
|
|
1730
|
+
kept: string[]
|
|
1731
|
+
warnings: string[]
|
|
1732
|
+
strippedCount: number
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
// Single source of truth for "what happens to each docker.file.append line",
|
|
1736
|
+
// reusing the config-layer classifier (validateDockerfileAppendLine). Both the
|
|
1737
|
+
// renderer (enforcement: drops unsafe lines) and refreshDockerfile (reporting:
|
|
1738
|
+
// surfaces warnings to the user) call this so the two never drift. Warn-but-
|
|
1739
|
+
// allow lines (curl|bash, remote ADD) are KEPT but produce a warning; structural
|
|
1740
|
+
// and semantic blocks are stripped with a warning.
|
|
1741
|
+
export function classifyDockerfileAppend(lines: string[]): DockerfileAppendClassification {
|
|
1742
|
+
const kept: string[] = []
|
|
1743
|
+
const warnings: string[] = []
|
|
1744
|
+
let strippedCount = 0
|
|
1745
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1746
|
+
const line = lines[i]!
|
|
1747
|
+
const check = validateDockerfileAppendLine(line)
|
|
1748
|
+
if (!check.ok) {
|
|
1749
|
+
strippedCount++
|
|
1750
|
+
warnings.push(`docker.file.append[${i}] stripped — ${check.reason}`)
|
|
1751
|
+
continue
|
|
1752
|
+
}
|
|
1753
|
+
if (check.warning) warnings.push(`docker.file.append[${i}] ${check.warning}`)
|
|
1754
|
+
kept.push(line)
|
|
1755
|
+
}
|
|
1756
|
+
return { kept, warnings, strippedCount }
|
|
1757
|
+
}
|