typeclaw 0.48.2 → 0.48.4
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/package.json +2 -2
- package/scripts/dump-system-prompt.ts +146 -11
- package/src/agent/index.ts +35 -9
- package/src/agent/plugin-tools.ts +21 -0
- package/src/agent/todo/continuation-policy.ts +11 -1
- package/src/agent/todo/continuation-state.ts +3 -1
- package/src/agent/todo/continuation-wiring.ts +2 -0
- package/src/agent/tool-file-safety.ts +19 -3
- package/src/agent/tools/channel-reply.ts +18 -1
- package/src/agent/tools/runtime-notice.ts +29 -0
- package/src/bundled-plugins/github-cli-auth/git-command.ts +497 -652
- package/src/bundled-plugins/memory/load-memory.ts +23 -27
- package/src/bundled-plugins/security/index.ts +1 -0
- package/src/bundled-plugins/security/policies/private-surface-read.ts +152 -40
- package/src/channels/adapters/discord-bot-reactions.ts +1 -0
- package/src/channels/adapters/discord-bot.ts +11 -2
- package/src/channels/adapters/discord-reactions.ts +1 -0
- package/src/channels/adapters/discord.ts +1 -0
- package/src/channels/adapters/slack-bot.ts +11 -2
- package/src/channels/adapters/slack.ts +1 -0
- package/src/channels/completion-claim.ts +307 -0
- package/src/channels/router.ts +307 -102
- package/src/channels/types.ts +4 -1
- package/src/cli/hostd.ts +1 -1
- package/src/config/providers.ts +16 -10
- package/src/hostd/kakao-renewal-manager.ts +23 -11
- package/src/init/models-dev.ts +25 -8
- package/src/mcp/client.ts +65 -7
- package/src/mcp/tools.ts +71 -4
- package/src/permissions/index.ts +1 -0
- package/src/permissions/permissions.ts +23 -0
- package/src/plugin/index.ts +1 -0
- package/src/plugin/manager.ts +19 -1
- package/src/plugin/types.ts +9 -0
- package/src/sandbox/canonical-secrets.ts +24 -4
- package/src/sandbox/hidden-paths.ts +8 -3
- package/src/sandbox/index.ts +2 -0
- package/src/secrets/kakao-renewal.ts +123 -20
- package/src/skills/typeclaw-permissions/SKILL.md +13 -1
- package/src/skills/typeclaw-plugins/SKILL.md +91 -11
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
export type CompletionClaimDecision =
|
|
2
|
+
| { kind: 'allow' }
|
|
3
|
+
| { kind: 'block'; reason: string }
|
|
4
|
+
| { kind: 'warn'; notice: string }
|
|
5
|
+
|
|
6
|
+
export type CompletionClaimInput = {
|
|
7
|
+
text: string | undefined
|
|
8
|
+
qualifyingWorkObserved: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type ToolResultEvidenceInput = {
|
|
12
|
+
toolName: string
|
|
13
|
+
isError: boolean
|
|
14
|
+
details: unknown
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function checkCompletionClaim(input: CompletionClaimInput): CompletionClaimDecision {
|
|
18
|
+
if (input.qualifyingWorkObserved) return { kind: 'allow' }
|
|
19
|
+
const text = normalize(input.text ?? '')
|
|
20
|
+
if (text === '') return { kind: 'allow' }
|
|
21
|
+
|
|
22
|
+
if (matchesKoreanClaim(text) || hasAssertivePhrase(text, ALL_FIRST_PERSON_PHRASES)) {
|
|
23
|
+
return { kind: 'block', reason: UNSUPPORTED_COMPLETION_REASON }
|
|
24
|
+
}
|
|
25
|
+
if (SOFT_PHRASES.some((phrase) => text.includes(phrase))) {
|
|
26
|
+
return { kind: 'warn', notice: SOFT_NOTICE }
|
|
27
|
+
}
|
|
28
|
+
return { kind: 'allow' }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isQualifyingWorkResult(input: ToolResultEvidenceInput): boolean {
|
|
32
|
+
if (input.isError) return false
|
|
33
|
+
const details = isRecord(input.details) ? input.details : undefined
|
|
34
|
+
if (details?.ok === false || details?.error === true) return false
|
|
35
|
+
if (
|
|
36
|
+
NON_WORK_TOOLS.has(input.toolName) ||
|
|
37
|
+
input.toolName.startsWith('channel_') ||
|
|
38
|
+
input.toolName.startsWith('todo_')
|
|
39
|
+
) {
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
if (input.toolName === 'spawn_subagent') return details?.mode === 'sync'
|
|
43
|
+
if (input.toolName === 'subagent_output') return details?.status === 'completed'
|
|
44
|
+
return true
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function normalize(text: string): string {
|
|
48
|
+
return maskQuotedAndCodeSpans(text)
|
|
49
|
+
.toLocaleLowerCase()
|
|
50
|
+
.replace(/[*_~]/gu, ' ')
|
|
51
|
+
.replace(/\r\n?/gu, '\n')
|
|
52
|
+
.replace(/[^\S\n]+/gu, ' ')
|
|
53
|
+
.replace(/ *\n */gu, '\n')
|
|
54
|
+
.replace(/\n+/gu, '\n')
|
|
55
|
+
.trim()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function maskQuotedAndCodeSpans(text: string): string {
|
|
59
|
+
return NON_ASSERTED_SPAN_PATTERNS.reduce(
|
|
60
|
+
(masked, pattern) => masked.replace(pattern, (span) => span.replace(/[^\r\n]/gu, ' ')),
|
|
61
|
+
text,
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function matchesKoreanClaim(text: string): boolean {
|
|
66
|
+
for (const phrase of KO_PHRASES) {
|
|
67
|
+
for (const index of phraseIndexes(text, phrase)) {
|
|
68
|
+
if (claimIsQuestion(text, index) || claimHasPastOrAttributedContext(text, index)) continue
|
|
69
|
+
const prefix = text.slice(Math.max(latestSentenceBoundary(text, index) + 1, index - 24), index)
|
|
70
|
+
if (KOREAN_OTHER_SUBJECT.test(prefix) && !KOREAN_FIRST_PERSON_SUBJECT.test(prefix)) continue
|
|
71
|
+
return true
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return false
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function hasAssertivePhrase(text: string, phrases: readonly string[]): boolean {
|
|
78
|
+
return phrases.some((phrase) => {
|
|
79
|
+
return phraseIndexes(text, phrase).some(
|
|
80
|
+
(index) => !claimIsQuestion(text, index) && !claimHasPastOrAttributedContext(text, index),
|
|
81
|
+
)
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function phraseIndexes(text: string, phrase: string): number[] {
|
|
86
|
+
const indexes: number[] = []
|
|
87
|
+
let offset = 0
|
|
88
|
+
while (offset < text.length) {
|
|
89
|
+
const index = text.indexOf(phrase, offset)
|
|
90
|
+
if (index < 0) break
|
|
91
|
+
indexes.push(index)
|
|
92
|
+
offset = index + phrase.length
|
|
93
|
+
}
|
|
94
|
+
return indexes
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function claimIsQuestion(text: string, claimIndex: number): boolean {
|
|
98
|
+
const nextQuestion = earliestIndex(text, QUESTION_TERMINATORS, claimIndex)
|
|
99
|
+
if (nextQuestion < 0) return false
|
|
100
|
+
const nextStatementEnd = earliestIndex(text, DECLARATIVE_TERMINATORS, claimIndex)
|
|
101
|
+
if (nextStatementEnd < 0) return true
|
|
102
|
+
return nextQuestion < nextStatementEnd
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function earliestIndex(text: string, needles: readonly string[], offset: number): number {
|
|
106
|
+
const indexes = needles.map((needle) => text.indexOf(needle, offset)).filter((index) => index >= 0)
|
|
107
|
+
return indexes.length === 0 ? -1 : Math.min(...indexes)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function claimHasPastOrAttributedContext(text: string, claimIndex: number): boolean {
|
|
111
|
+
const sentenceStart = latestSentenceBoundary(text, claimIndex)
|
|
112
|
+
const prefix = text.slice(sentenceStart + 1, claimIndex)
|
|
113
|
+
return HISTORICAL_MARKERS.some((marker) => prefix.includes(marker)) || ATTRIBUTION_END.test(prefix)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function latestSentenceBoundary(text: string, offset: number): number {
|
|
117
|
+
return Math.max(...SENTENCE_TERMINATORS.map((terminator) => text.lastIndexOf(terminator, offset)))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
121
|
+
return typeof value === 'object' && value !== null
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Every block phrase is first-person and perfective. Bare verbs stay in the
|
|
125
|
+
// warning tier so descriptions of another actor are never hard-denied.
|
|
126
|
+
const EN_PHRASES: readonly string[] = [
|
|
127
|
+
'i saved it',
|
|
128
|
+
"i've saved it",
|
|
129
|
+
'i have saved it',
|
|
130
|
+
'i wrote it',
|
|
131
|
+
"i've written it",
|
|
132
|
+
'i recorded it',
|
|
133
|
+
'i applied it',
|
|
134
|
+
'i updated it',
|
|
135
|
+
"i've updated it",
|
|
136
|
+
'i fixed it',
|
|
137
|
+
"i've fixed it",
|
|
138
|
+
'i deployed it',
|
|
139
|
+
'i committed it',
|
|
140
|
+
'i removed it',
|
|
141
|
+
'i deleted it',
|
|
142
|
+
'i saved the ',
|
|
143
|
+
"i've saved the ",
|
|
144
|
+
'i wrote the ',
|
|
145
|
+
"i've written the ",
|
|
146
|
+
'i recorded the ',
|
|
147
|
+
'i applied the ',
|
|
148
|
+
'i updated the ',
|
|
149
|
+
"i've updated the ",
|
|
150
|
+
'i fixed the ',
|
|
151
|
+
"i've fixed the ",
|
|
152
|
+
'i deployed the ',
|
|
153
|
+
'i committed the ',
|
|
154
|
+
'i removed the ',
|
|
155
|
+
'i deleted the ',
|
|
156
|
+
'i saved your ',
|
|
157
|
+
'i updated your ',
|
|
158
|
+
'i fixed your ',
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
// Korean commonly drops the subject. The perfective endings below are safe for
|
|
162
|
+
// a bare assistant ack; an explicit nearby third-person 은/는/이/가 subject
|
|
163
|
+
// demotes the match, while 내가/제가 keeps the first-person reading.
|
|
164
|
+
const KO_PHRASES: readonly string[] = [
|
|
165
|
+
'저장했어',
|
|
166
|
+
'저장했습니다',
|
|
167
|
+
'기록했어',
|
|
168
|
+
'기록했습니다',
|
|
169
|
+
'반영했어',
|
|
170
|
+
'반영했습니다',
|
|
171
|
+
'고쳤어',
|
|
172
|
+
'고쳤습니다',
|
|
173
|
+
'수정했어',
|
|
174
|
+
'수정했습니다',
|
|
175
|
+
'커밋했어',
|
|
176
|
+
'커밋했습니다',
|
|
177
|
+
'삭제했어',
|
|
178
|
+
'삭제했습니다',
|
|
179
|
+
]
|
|
180
|
+
|
|
181
|
+
const ES_PHRASES: readonly string[] = ['lo guardé', 'lo escribí', 'lo actualicé', 'lo corregí', 'lo eliminé']
|
|
182
|
+
const FR_PHRASES: readonly string[] = [
|
|
183
|
+
"je l'ai enregistré",
|
|
184
|
+
"je l'ai écrit",
|
|
185
|
+
"je l'ai mis à jour",
|
|
186
|
+
"je l'ai corrigé",
|
|
187
|
+
"je l'ai supprimé",
|
|
188
|
+
]
|
|
189
|
+
const IT_PHRASES: readonly string[] = [
|
|
190
|
+
"l'ho salvato",
|
|
191
|
+
"l'ho scritto",
|
|
192
|
+
"l'ho aggiornato",
|
|
193
|
+
"l'ho corretto",
|
|
194
|
+
"l'ho eliminato",
|
|
195
|
+
]
|
|
196
|
+
const PT_PHRASES: readonly string[] = ['eu salvei', 'eu escrevi', 'eu atualizei', 'eu corrigi', 'eu removi']
|
|
197
|
+
const DE_PHRASES: readonly string[] = [
|
|
198
|
+
'ich habe es gespeichert',
|
|
199
|
+
'ich habe es geschrieben',
|
|
200
|
+
'ich habe es aktualisiert',
|
|
201
|
+
'ich habe es korrigiert',
|
|
202
|
+
'ich habe es gelöscht',
|
|
203
|
+
]
|
|
204
|
+
const RU_PHRASES: readonly string[] = ['я сохранил', 'я записал', 'я обновил', 'я исправил', 'я удалил']
|
|
205
|
+
const ZH_PHRASES: readonly string[] = ['我已经保存了', '我已经写好了', '我已经更新了', '我已经修好了', '我已经删除了']
|
|
206
|
+
const JA_PHRASES: readonly string[] = [
|
|
207
|
+
'私は保存しておきました',
|
|
208
|
+
'私は書いておきました',
|
|
209
|
+
'私は更新しておきました',
|
|
210
|
+
'私は修正しておきました',
|
|
211
|
+
'私は削除しておきました',
|
|
212
|
+
]
|
|
213
|
+
const AR_PHRASES: readonly string[] = ['أنا حفظته', 'أنا كتبته', 'أنا حدّثته', 'أنا أصلحته', 'أنا حذفته']
|
|
214
|
+
const HI_PHRASES: readonly string[] = [
|
|
215
|
+
'मैंने इसे सहेज दिया',
|
|
216
|
+
'मैंने इसे लिख दिया',
|
|
217
|
+
'मैंने इसे अपडेट कर दिया',
|
|
218
|
+
'मैंने इसे ठीक कर दिया',
|
|
219
|
+
'मैंने इसे हटा दिया',
|
|
220
|
+
]
|
|
221
|
+
const TR_PHRASES: readonly string[] = ['kaydettim', 'yazdım', 'güncelledim', 'düzelttim', 'sildim']
|
|
222
|
+
const VI_PHRASES: readonly string[] = ['tôi đã lưu', 'tôi đã viết', 'tôi đã cập nhật', 'tôi đã sửa', 'tôi đã xóa']
|
|
223
|
+
const ID_PHRASES: readonly string[] = [
|
|
224
|
+
'saya sudah menyimpan',
|
|
225
|
+
'saya sudah menulis',
|
|
226
|
+
'saya sudah memperbarui',
|
|
227
|
+
'saya sudah memperbaiki',
|
|
228
|
+
'saya sudah menghapus',
|
|
229
|
+
]
|
|
230
|
+
|
|
231
|
+
const ALL_FIRST_PERSON_PHRASES: readonly string[] = [
|
|
232
|
+
...EN_PHRASES,
|
|
233
|
+
...ES_PHRASES,
|
|
234
|
+
...FR_PHRASES,
|
|
235
|
+
...IT_PHRASES,
|
|
236
|
+
...PT_PHRASES,
|
|
237
|
+
...DE_PHRASES,
|
|
238
|
+
...RU_PHRASES,
|
|
239
|
+
...ZH_PHRASES,
|
|
240
|
+
...JA_PHRASES,
|
|
241
|
+
...AR_PHRASES,
|
|
242
|
+
...HI_PHRASES,
|
|
243
|
+
...TR_PHRASES,
|
|
244
|
+
...VI_PHRASES,
|
|
245
|
+
...ID_PHRASES,
|
|
246
|
+
]
|
|
247
|
+
|
|
248
|
+
const KOREAN_OTHER_SUBJECT = /(?:^|[\s,])[^\s,]{1,16}(?:은|는|이|가)(?:\s+\S+){0,3}\s*$/u
|
|
249
|
+
const KOREAN_FIRST_PERSON_SUBJECT = /(?:내가|제가|나는|저는)(?:\s+\S+){0,3}\s*$/u
|
|
250
|
+
const ATTRIBUTION_END =
|
|
251
|
+
/(?:said|wrote|reported|dijo|a dit|ha detto|disse|sagte|сказал[аи]?|说|言いました|قال|कहा|dedi|nói|berkata|말했어|말했습니다|썼어|썼습니다)\s*[:"“']?\s*$/u
|
|
252
|
+
const QUESTION_TERMINATORS: readonly string[] = ['?', '?', '﹖']
|
|
253
|
+
const DECLARATIVE_TERMINATORS: readonly string[] = ['.', '!', '。', '!', '。', '.', '﹒', '﹗', '\n']
|
|
254
|
+
const SENTENCE_TERMINATORS: readonly string[] = [...QUESTION_TERMINATORS, ...DECLARATIVE_TERMINATORS]
|
|
255
|
+
const NON_ASSERTED_SPAN_PATTERNS: readonly RegExp[] = [
|
|
256
|
+
/```[\s\S]*?```/gu,
|
|
257
|
+
/`[^`\r\n]*`/gu,
|
|
258
|
+
/"[^"\r\n]*"/gu,
|
|
259
|
+
/(?<![\p{L}\p{N}])'[^'\r\n]+'(?![\p{L}\p{N}])/gu,
|
|
260
|
+
/“[^”\r\n]*”/gu,
|
|
261
|
+
/‘[^’\r\n]*’/gu,
|
|
262
|
+
/「[^」\r\n]*」/gu,
|
|
263
|
+
/『[^』\r\n]*』/gu,
|
|
264
|
+
]
|
|
265
|
+
const HISTORICAL_MARKERS: readonly string[] = [
|
|
266
|
+
'yesterday',
|
|
267
|
+
'earlier',
|
|
268
|
+
'previously',
|
|
269
|
+
'i thought',
|
|
270
|
+
'i think',
|
|
271
|
+
'last week',
|
|
272
|
+
'last month',
|
|
273
|
+
'for another project',
|
|
274
|
+
'ayer',
|
|
275
|
+
'hier',
|
|
276
|
+
'ieri',
|
|
277
|
+
'ontem',
|
|
278
|
+
'gestern',
|
|
279
|
+
'вчера',
|
|
280
|
+
'昨天',
|
|
281
|
+
'昨日',
|
|
282
|
+
'أمس',
|
|
283
|
+
'कल',
|
|
284
|
+
'dün',
|
|
285
|
+
'hôm qua',
|
|
286
|
+
'kemarin',
|
|
287
|
+
'어제',
|
|
288
|
+
'라고',
|
|
289
|
+
'줄 알았',
|
|
290
|
+
'전에',
|
|
291
|
+
'이전에',
|
|
292
|
+
'지난주',
|
|
293
|
+
'지난달',
|
|
294
|
+
]
|
|
295
|
+
|
|
296
|
+
const SOFT_PHRASES: readonly string[] = ['saved and ready', 'updated and ready', '반영 완료', '수정 완료']
|
|
297
|
+
|
|
298
|
+
const NON_WORK_TOOLS = new Set(['skip_response', 'restart', 'grant_role', 'subagent_cancel'])
|
|
299
|
+
|
|
300
|
+
const UNSUPPORTED_COMPLETION_REASON =
|
|
301
|
+
'This reply claims you already completed durable work, but this logical turn has no successful non-communication work result to support it. ' +
|
|
302
|
+
'Actually perform the work with the appropriate tool, confirm that it succeeds, and then reply with the completion claim. ' +
|
|
303
|
+
'If no durable change was intended, reword the reply without claiming it was saved, applied, updated, fixed, or otherwise completed.'
|
|
304
|
+
|
|
305
|
+
const SOFT_NOTICE =
|
|
306
|
+
'This reply sounds completion-shaped, but no successful non-communication work was observed this turn. ' +
|
|
307
|
+
'Only claim a durable result after the relevant tool succeeds; otherwise describe what remains to be done.'
|