typeclaw 0.48.3 → 0.48.5
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 +6 -1
- package/src/agent/live-subagents.ts +15 -0
- package/src/agent/plugin-tools.ts +7 -0
- package/src/agent/session-origin.ts +104 -16
- package/src/agent/subagent-completion-reminder.ts +1 -1
- package/src/agent/subagent-drain.ts +11 -1
- package/src/agent/subagents.ts +52 -7
- package/src/agent/tool-file-safety.ts +14 -4
- package/src/agent/tools/runtime-notice.ts +29 -0
- package/src/agent/tools/spawn-subagent.ts +88 -7
- package/src/agent/tools/subagent-cancel.ts +1 -0
- package/src/agent/tools/subagent-output.ts +7 -2
- package/src/agent/tools/webfetch/adaptive-html.ts +319 -0
- package/src/agent/tools/webfetch/html-lexical.ts +841 -0
- package/src/agent/tools/webfetch/inline-style-visibility.ts +281 -0
- package/src/agent/tools/webfetch/strategies/readability.ts +306 -5
- package/src/agent/tools/webfetch/tool.ts +45 -2
- package/src/agent/tools/webfetch/types.ts +7 -0
- package/src/agent/turn-runner.ts +7 -3
- package/src/bundled-plugins/github-cli-auth/gh-command.ts +187 -8
- 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/reviewer/reviewer.ts +32 -5
- package/src/bundled-plugins/reviewer/skills/code-review.ts +5 -3
- package/src/bundled-plugins/reviewer/skills/doc-review.ts +1 -1
- package/src/bundled-plugins/reviewer/skills/plan-review.ts +1 -1
- package/src/bundled-plugins/security/index.ts +1 -0
- package/src/bundled-plugins/security/policies/private-surface-read.ts +74 -18
- package/src/channels/router.ts +32 -47
- package/src/cli/hostd.ts +1 -1
- package/src/hostd/kakao-renewal-manager.ts +23 -11
- package/src/plugin/index.ts +1 -0
- package/src/plugin/types.ts +9 -10
- package/src/run/channel-session-factory.ts +3 -1
- package/src/run/index.ts +29 -29
- package/src/run/subagent-coalescing.ts +24 -0
- package/src/secrets/kakao-renewal.ts +123 -20
- package/src/server/index.ts +4 -1
- package/src/skills/typeclaw-channel-github/SKILL.md +6 -6
- package/src/skills/typeclaw-channel-instagram/SKILL.md +1 -1
- package/src/skills/typeclaw-channel-kakaotalk/SKILL.md +1 -1
- package/src/skills/typeclaw-channel-line/SKILL.md +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeclaw",
|
|
3
|
-
"version": "0.48.
|
|
3
|
+
"version": "0.48.5",
|
|
4
4
|
"homepage": "https://github.com/typeclaw/typeclaw#readme",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/typeclaw/typeclaw/issues"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@mariozechner/pi-tui": "^0.73.1",
|
|
51
51
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
52
52
|
"@mozilla/readability": "^0.6.0",
|
|
53
|
-
"agent-messenger": "^2.
|
|
53
|
+
"agent-messenger": "^2.35.0",
|
|
54
54
|
"cheerio": "^1.2.0",
|
|
55
55
|
"citty": "^0.2.2",
|
|
56
56
|
"cron-parser": "^5.5.0",
|
|
@@ -4,6 +4,8 @@ import { parseArgs } from 'node:util'
|
|
|
4
4
|
|
|
5
5
|
import { composeSystemPrompt, deriveSystemPromptMode, renderTurnTimeAnchor, type SystemPromptMode } from '@/agent'
|
|
6
6
|
import type { SessionOrigin, SessionRoleContext } from '@/agent/session-origin'
|
|
7
|
+
import { renderRetrievedMemorySection, type RetrievedMemoryItem } from '@/bundled-plugins/memory/load-memory'
|
|
8
|
+
import { composeTurnPrompt } from '@/channels/router'
|
|
7
9
|
|
|
8
10
|
type OriginKind = 'tui' | 'cron' | 'channel' | 'subagent'
|
|
9
11
|
const ALL_KINDS: readonly OriginKind[] = ['tui', 'cron', 'channel', 'subagent'] as const
|
|
@@ -42,6 +44,39 @@ const PLACEHOLDER_GIT_NUDGE = [
|
|
|
42
44
|
"These are real, current modifications — not advice. Before declaring this session's task done, commit any of these you're responsible for, with `git add <paths>` and `git commit -m \"…\"` per the version-control rules above. If a listed path is from earlier work you didn't touch, leave it alone.",
|
|
43
45
|
].join('\n')
|
|
44
46
|
|
|
47
|
+
const PLACEHOLDER_TURN_TEXT: Record<OriginKind, string> = {
|
|
48
|
+
tui: '<PLACEHOLDER: interactive user request from the TUI>',
|
|
49
|
+
cron: '<PLACEHOLDER: scheduled cron job prompt>',
|
|
50
|
+
channel: '<PLACEHOLDER: current channel message addressed to the agent>',
|
|
51
|
+
subagent: '<PLACEHOLDER: delegated subagent task>',
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const PLACEHOLDER_MEMORY_ITEMS: RetrievedMemoryItem[] = [
|
|
55
|
+
{
|
|
56
|
+
source: 'topic',
|
|
57
|
+
key: 'placeholder-working-preference',
|
|
58
|
+
heading: '<PLACEHOLDER: durable user preference relevant to the current request>',
|
|
59
|
+
excerpt:
|
|
60
|
+
'<PLACEHOLDER: full memory excerpt with the durable preference, supporting context, and fragment citations>',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
source: 'stream',
|
|
64
|
+
key: 'stream:<PLACEHOLDER-fragment-id>',
|
|
65
|
+
heading: '<PLACEHOLDER: recent undreamed observation relevant to this turn>',
|
|
66
|
+
excerpt: '<PLACEHOLDER: recent observation body awaiting dreaming consolidation>',
|
|
67
|
+
who: '<PLACEHOLDER: speaker name>',
|
|
68
|
+
when: '2026-05-21T08:30:00.000Z',
|
|
69
|
+
where: {
|
|
70
|
+
adapter: 'slack-bot',
|
|
71
|
+
workspace: 'T<PLACEHOLDER-WS>',
|
|
72
|
+
workspaceName: '<PLACEHOLDER: workspace display name>',
|
|
73
|
+
chat: 'C<PLACEHOLDER-CH>',
|
|
74
|
+
chatName: '<PLACEHOLDER: channel display name>',
|
|
75
|
+
thread: null,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
]
|
|
79
|
+
|
|
45
80
|
type Fixture = {
|
|
46
81
|
origin: SessionOrigin
|
|
47
82
|
roleContext: SessionRoleContext
|
|
@@ -263,6 +298,106 @@ export function dumpSystemPrompt(kind: OriginKind, options: { gitNudge: boolean
|
|
|
263
298
|
return dumpSystemPromptWithBreakdown(kind, options).prompt
|
|
264
299
|
}
|
|
265
300
|
|
|
301
|
+
export function dumpTurnPromptWithBreakdown(kind: OriginKind): DumpResult {
|
|
302
|
+
const fixture = buildFixture(kind)
|
|
303
|
+
const memory = renderRetrievedMemorySection(PLACEHOLDER_MEMORY_ITEMS, { origin: fixture.origin })
|
|
304
|
+
if (kind !== 'channel') {
|
|
305
|
+
const timeAnchor = `${renderTurnTimeAnchor(PLACEHOLDER_NOW)}\n\n`
|
|
306
|
+
const userText = `${PLACEHOLDER_TURN_TEXT[kind]}\n\n`
|
|
307
|
+
const prompt = `${timeAnchor}${userText}${memory}`
|
|
308
|
+
return buildDumpResult(prompt, [
|
|
309
|
+
['Time anchor', timeAnchor],
|
|
310
|
+
['User text', userText],
|
|
311
|
+
['Memory block', memory],
|
|
312
|
+
])
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const observed = [
|
|
316
|
+
{
|
|
317
|
+
text: '<PLACEHOLDER: earlier human message observed while the agent was not engaged>',
|
|
318
|
+
authorId: 'U<PLACEHOLDER-OBSERVER-1>',
|
|
319
|
+
authorName: '<PLACEHOLDER: first participant name>',
|
|
320
|
+
authorIsBot: false,
|
|
321
|
+
receivedAt: PLACEHOLDER_NOW.getTime() - 90_000,
|
|
322
|
+
ts: PLACEHOLDER_NOW.getTime() - 90_000,
|
|
323
|
+
source: 'observed' as const,
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
text: '<PLACEHOLDER: peer-bot follow-up retained as recent channel context>',
|
|
327
|
+
authorId: 'U<PLACEHOLDER-PEER-BOT>',
|
|
328
|
+
authorName: '<PLACEHOLDER: peer bot name>',
|
|
329
|
+
authorIsBot: true,
|
|
330
|
+
receivedAt: PLACEHOLDER_NOW.getTime() - 45_000,
|
|
331
|
+
ts: PLACEHOLDER_NOW.getTime() - 45_000,
|
|
332
|
+
source: 'observed' as const,
|
|
333
|
+
},
|
|
334
|
+
]
|
|
335
|
+
const batch = [
|
|
336
|
+
{
|
|
337
|
+
text: PLACEHOLDER_TURN_TEXT.channel,
|
|
338
|
+
authorId: 'U<PLACEHOLDER-AUTHOR>',
|
|
339
|
+
authorName: '<PLACEHOLDER: current speaker name>',
|
|
340
|
+
authorIsBot: false,
|
|
341
|
+
externalMessageId: '<PLACEHOLDER-message-id>',
|
|
342
|
+
isBotMention: true,
|
|
343
|
+
replyToBotMessageId: '<PLACEHOLDER-prior-bot-message-id>',
|
|
344
|
+
isDm: false,
|
|
345
|
+
receivedAt: PLACEHOLDER_NOW.getTime(),
|
|
346
|
+
ts: PLACEHOLDER_NOW.getTime(),
|
|
347
|
+
},
|
|
348
|
+
]
|
|
349
|
+
const channelTurn = composeTurnPrompt(observed, batch, {
|
|
350
|
+
adapter: 'slack-bot',
|
|
351
|
+
loopGuardActive: false,
|
|
352
|
+
groupChatNudge: true,
|
|
353
|
+
now: PLACEHOLDER_NOW,
|
|
354
|
+
role: fixture.roleContext.role,
|
|
355
|
+
})
|
|
356
|
+
const prompt = `${channelTurn}\n\n${memory}`
|
|
357
|
+
return buildDumpResultFromMarkers(prompt, [
|
|
358
|
+
['Time anchor', '<current-time>'],
|
|
359
|
+
['Role anchor', '<your-role authority="current-speaker">'],
|
|
360
|
+
// Anchored on the fence, not the notice's prose: the fence is the invariant
|
|
361
|
+
// every runtime notice carries, so rewording a notice can't break the dump.
|
|
362
|
+
['Group-chat nudge', '---\n**[SYSTEM MESSAGE — not from a human]**'],
|
|
363
|
+
['Recent context', '## Recent context (not addressed to you, for awareness only)'],
|
|
364
|
+
['Current message', 'Note: if earlier turns appear above, they are real conversation history you can use.'],
|
|
365
|
+
['Memory block (channel headings only)', '# Memory'],
|
|
366
|
+
])
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export function dumpTurnPrompt(kind: OriginKind): string {
|
|
370
|
+
return dumpTurnPromptWithBreakdown(kind).prompt
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function buildDumpResult(prompt: string, parts: ReadonlyArray<readonly [string, string]>): DumpResult {
|
|
374
|
+
if (parts.map(([, body]) => body).join('') !== prompt) {
|
|
375
|
+
throw new Error('turn-prompt breakdown does not cover the rendered prompt exactly')
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
prompt,
|
|
379
|
+
sections: parts.map(([name, body]) => mkSection(name, body)),
|
|
380
|
+
totalBytes: byteLength(prompt),
|
|
381
|
+
totalChars: prompt.length,
|
|
382
|
+
totalTokens: estimateTokens(prompt),
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function buildDumpResultFromMarkers(prompt: string, markers: ReadonlyArray<readonly [string, string]>): DumpResult {
|
|
387
|
+
const starts = markers.map(([name, marker], index) => {
|
|
388
|
+
const start = prompt.indexOf(marker, index === 0 ? 0 : 1)
|
|
389
|
+
if (start < 0) throw new Error(`turn-prompt section marker not found: ${name}`)
|
|
390
|
+
return { name, start }
|
|
391
|
+
})
|
|
392
|
+
if (starts[0]?.start !== 0 || starts.some((part, index) => index > 0 && part.start <= starts[index - 1]!.start)) {
|
|
393
|
+
throw new Error('turn-prompt section markers are not in rendered order')
|
|
394
|
+
}
|
|
395
|
+
return buildDumpResult(
|
|
396
|
+
prompt,
|
|
397
|
+
starts.map((part, index) => [part.name, prompt.slice(part.start, starts[index + 1]?.start)] as const),
|
|
398
|
+
)
|
|
399
|
+
}
|
|
400
|
+
|
|
266
401
|
// Slice between two unique headers in the rendered prompt. Both anchors are
|
|
267
402
|
// guaranteed unique by `composeSystemPrompt`'s contract (each section's
|
|
268
403
|
// header appears exactly once). Used by the breakdown so we attribute each
|
|
@@ -276,10 +411,10 @@ function extractSection(prompt: string, startHeader: string, endHeader: string |
|
|
|
276
411
|
return end < 0 ? prompt.slice(afterStart) : prompt.slice(afterStart, end)
|
|
277
412
|
}
|
|
278
413
|
|
|
279
|
-
function header(kind: OriginKind, result: DumpResult): string {
|
|
414
|
+
function header(kind: OriginKind, result: DumpResult, label: 'SYSTEM PROMPT' | 'USER TURN'): string {
|
|
280
415
|
const bar = '═'.repeat(78)
|
|
281
416
|
const summary = `~${result.totalTokens} tok / ${result.totalChars} chars / ${result.totalBytes} bytes (tok est. chars/4)`
|
|
282
|
-
return `\n${bar}\n
|
|
417
|
+
return `\n${bar}\n ${label} — origin: ${kind} — ${summary}\n${bar}\n`
|
|
283
418
|
}
|
|
284
419
|
|
|
285
420
|
function renderBreakdownTable(result: DumpResult): string {
|
|
@@ -309,6 +444,7 @@ function main(): void {
|
|
|
309
444
|
options: {
|
|
310
445
|
origin: { type: 'string', short: 'o', default: 'all' },
|
|
311
446
|
'no-git-nudge': { type: 'boolean', default: false },
|
|
447
|
+
turn: { type: 'boolean', default: false },
|
|
312
448
|
help: { type: 'boolean', short: 'h', default: false },
|
|
313
449
|
},
|
|
314
450
|
allowPositionals: false,
|
|
@@ -317,15 +453,17 @@ function main(): void {
|
|
|
317
453
|
if (values.help) {
|
|
318
454
|
process.stdout.write(
|
|
319
455
|
[
|
|
320
|
-
'Usage: bun run debug:prompt [--origin <kind>] [--no-git-nudge]',
|
|
456
|
+
'Usage: bun run debug:prompt [--turn] [--origin <kind>] [--no-git-nudge]',
|
|
321
457
|
'',
|
|
322
|
-
'Dump the rendered system prompt
|
|
458
|
+
'Dump the rendered system prompt, or the per-turn user message with --turn,',
|
|
459
|
+
'for one or all session-origin kinds,',
|
|
323
460
|
'using placeholder values for every dynamic field. Each dump is prefixed',
|
|
324
461
|
'with a per-section breakdown showing approximate tokens (chars/4),',
|
|
325
462
|
'character count, and UTF-8 byte length.',
|
|
326
463
|
'',
|
|
327
464
|
'Options:',
|
|
328
465
|
' -o, --origin <kind> tui | cron | channel | subagent | all (default: all)',
|
|
466
|
+
' --turn dump the non-cacheable user-turn message instead',
|
|
329
467
|
' --no-git-nudge omit the "Uncommitted changes at session start" block',
|
|
330
468
|
' -h, --help show this help',
|
|
331
469
|
'',
|
|
@@ -348,18 +486,15 @@ function main(): void {
|
|
|
348
486
|
})()
|
|
349
487
|
|
|
350
488
|
for (const kind of kinds) {
|
|
351
|
-
const result =
|
|
352
|
-
|
|
489
|
+
const result = values.turn
|
|
490
|
+
? dumpTurnPromptWithBreakdown(kind)
|
|
491
|
+
: dumpSystemPromptWithBreakdown(kind, { gitNudge: !values['no-git-nudge'] })
|
|
492
|
+
process.stdout.write(header(kind, result, values.turn ? 'USER TURN' : 'SYSTEM PROMPT'))
|
|
353
493
|
process.stdout.write(renderBreakdownTable(result))
|
|
354
494
|
process.stdout.write('\n\n')
|
|
355
495
|
process.stdout.write(result.prompt)
|
|
356
496
|
process.stdout.write('\n')
|
|
357
497
|
}
|
|
358
|
-
|
|
359
|
-
const anchor = renderTurnTimeAnchor(PLACEHOLDER_NOW)
|
|
360
|
-
const bar = '═'.repeat(78)
|
|
361
|
-
process.stdout.write(`\n${bar}\n PER-TURN INJECTION (prepended to every user message)\n${bar}\n\n`)
|
|
362
|
-
process.stdout.write(`${anchor}\n`)
|
|
363
498
|
}
|
|
364
499
|
|
|
365
500
|
if (import.meta.main) {
|
package/src/agent/index.ts
CHANGED
|
@@ -61,7 +61,7 @@ import type { SubagentBashPolicy } from './reviewer-bash-policy'
|
|
|
61
61
|
import { loadSelf } from './self'
|
|
62
62
|
import { SESSION_META_CUSTOM_TYPE, sessionMetaPayload } from './session-meta'
|
|
63
63
|
import { renderSessionOrigin, type SessionOrigin, type SessionRoleContext } from './session-origin'
|
|
64
|
-
import type { CreateSessionForSubagent, SubagentRegistry } from './subagents'
|
|
64
|
+
import type { CreateSessionForSubagent, SubagentCoalescer, SubagentRegistry } from './subagents'
|
|
65
65
|
import {
|
|
66
66
|
buildDefaultSystemPrompt,
|
|
67
67
|
buildSlimSystemPrompt,
|
|
@@ -219,6 +219,7 @@ export type CreateSessionOptions = {
|
|
|
219
219
|
// (omitting these for subagent sessions) is what prevents recursive
|
|
220
220
|
// spawning.
|
|
221
221
|
liveSubagentRegistry?: LiveSubagentRegistry
|
|
222
|
+
subagentCoalescer?: SubagentCoalescer
|
|
222
223
|
subagentRegistry?: SubagentRegistry
|
|
223
224
|
createSessionForSubagent?: CreateSessionForSubagent
|
|
224
225
|
allowBackgroundFromSubagent?: boolean
|
|
@@ -401,6 +402,7 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
401
402
|
permissions: options.permissions,
|
|
402
403
|
stream: options.stream,
|
|
403
404
|
allowBackgroundFromSubagent: options.allowBackgroundFromSubagent,
|
|
405
|
+
coalescer: options.subagentCoalescer,
|
|
404
406
|
}),
|
|
405
407
|
]
|
|
406
408
|
: [
|
|
@@ -444,6 +446,7 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
444
446
|
getOrigin,
|
|
445
447
|
permissions: options.permissions,
|
|
446
448
|
stream: options.stream,
|
|
449
|
+
coalescer: options.subagentCoalescer,
|
|
447
450
|
}),
|
|
448
451
|
...buildRoleGrantTools({
|
|
449
452
|
agentDir: options.plugins?.agentDir,
|
|
@@ -845,6 +848,7 @@ export function buildSubagentOrchestrationTools(opts: {
|
|
|
845
848
|
permissions: PermissionService | undefined
|
|
846
849
|
stream: Stream | undefined
|
|
847
850
|
allowBackgroundFromSubagent?: boolean
|
|
851
|
+
coalescer?: SubagentCoalescer
|
|
848
852
|
}): ToolDefinition[] {
|
|
849
853
|
if (
|
|
850
854
|
opts.liveRegistry === undefined ||
|
|
@@ -867,6 +871,7 @@ export function buildSubagentOrchestrationTools(opts: {
|
|
|
867
871
|
...(opts.allowBackgroundFromSubagent !== undefined
|
|
868
872
|
? { allowBackgroundFromSubagent: opts.allowBackgroundFromSubagent }
|
|
869
873
|
: {}),
|
|
874
|
+
...(opts.coalescer !== undefined ? { coalescer: opts.coalescer } : {}),
|
|
870
875
|
}),
|
|
871
876
|
createSubagentOutputTool({
|
|
872
877
|
liveRegistry: opts.liveRegistry,
|
|
@@ -32,6 +32,7 @@ export type LiveSubagent = {
|
|
|
32
32
|
status: SubagentStatus
|
|
33
33
|
completion?: SubagentCompletion
|
|
34
34
|
abort: () => Promise<void>
|
|
35
|
+
releaseCoalesceKey?: () => void
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export const MAX_EVENTS_PER_SUBAGENT = 100
|
|
@@ -96,6 +97,7 @@ export type StatusSnapshot = {
|
|
|
96
97
|
export class LiveSubagentRegistry {
|
|
97
98
|
private readonly entries = new Map<string, LiveSubagent>()
|
|
98
99
|
private readonly events = new Map<string, SubagentProgressEvent[]>()
|
|
100
|
+
private readonly capturedFinalMessages = new Map<string, string>()
|
|
99
101
|
|
|
100
102
|
register(live: LiveSubagent): void {
|
|
101
103
|
if (this.entries.has(live.taskId)) {
|
|
@@ -108,6 +110,7 @@ export class LiveSubagentRegistry {
|
|
|
108
110
|
unregister(taskId: string): void {
|
|
109
111
|
this.entries.delete(taskId)
|
|
110
112
|
this.events.delete(taskId)
|
|
113
|
+
this.capturedFinalMessages.delete(taskId)
|
|
111
114
|
}
|
|
112
115
|
|
|
113
116
|
get(taskId: string): LiveSubagent | undefined {
|
|
@@ -136,6 +139,17 @@ export class LiveSubagentRegistry {
|
|
|
136
139
|
}
|
|
137
140
|
}
|
|
138
141
|
|
|
142
|
+
recordCapturedFinalMessageIfRunning(taskId: string, finalMessage: string): boolean {
|
|
143
|
+
const entry = this.entries.get(taskId)
|
|
144
|
+
if (entry === undefined || entry.status !== 'running') return false
|
|
145
|
+
this.capturedFinalMessages.set(taskId, finalMessage)
|
|
146
|
+
return true
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
getCapturedFinalMessage(taskId: string): string | undefined {
|
|
150
|
+
return this.capturedFinalMessages.get(taskId)
|
|
151
|
+
}
|
|
152
|
+
|
|
139
153
|
recordCompletion(taskId: string, completion: SubagentCompletion): void {
|
|
140
154
|
const entry = this.entries.get(taskId)
|
|
141
155
|
if (entry === undefined) return
|
|
@@ -186,6 +200,7 @@ export class LiveSubagentRegistry {
|
|
|
186
200
|
clear(): void {
|
|
187
201
|
this.entries.clear()
|
|
188
202
|
this.events.clear()
|
|
203
|
+
this.capturedFinalMessages.clear()
|
|
189
204
|
}
|
|
190
205
|
}
|
|
191
206
|
|
|
@@ -354,6 +354,8 @@ export function wrapPluginTool(tool: Tool<any>, opts: WrapToolOptions): ToolDefi
|
|
|
354
354
|
sessionId: opts.sessionId,
|
|
355
355
|
callId: toolCallId,
|
|
356
356
|
args: mutableArgs,
|
|
357
|
+
toolProvenance: 'plugin',
|
|
358
|
+
|
|
357
359
|
...(liveOrigin !== undefined ? { origin: liveOrigin } : {}),
|
|
358
360
|
...(tool.fileOperands !== undefined ? { fileOperands: tool.fileOperands } : {}),
|
|
359
361
|
}
|
|
@@ -388,6 +390,7 @@ export function wrapPluginTool(tool: Tool<any>, opts: WrapToolOptions): ToolDefi
|
|
|
388
390
|
tool: opts.toolName,
|
|
389
391
|
args: before.args,
|
|
390
392
|
agentDir: opts.agentDir,
|
|
393
|
+
toolProvenance: 'plugin',
|
|
391
394
|
genericInputs: true,
|
|
392
395
|
fileOperands: tool.fileOperands,
|
|
393
396
|
logger: opts.logger,
|
|
@@ -453,6 +456,7 @@ export function wrapSystemTool<TParams extends TSchema, TDetails = unknown, TSta
|
|
|
453
456
|
sessionId: opts.sessionId,
|
|
454
457
|
callId: toolCallId,
|
|
455
458
|
args: mutableArgs,
|
|
459
|
+
toolProvenance: 'first-party',
|
|
456
460
|
...(liveOrigin !== undefined ? { origin: liveOrigin } : {}),
|
|
457
461
|
...(preflightFileOperands !== undefined ? { fileOperands: preflightFileOperands } : {}),
|
|
458
462
|
})
|
|
@@ -485,6 +489,7 @@ export function wrapSystemTool<TParams extends TSchema, TDetails = unknown, TSta
|
|
|
485
489
|
tool: tool.name,
|
|
486
490
|
args: mutableArgs,
|
|
487
491
|
agentDir: opts.agentDir,
|
|
492
|
+
toolProvenance: 'first-party',
|
|
488
493
|
genericInputs: tool.name !== 'mcp_call',
|
|
489
494
|
...(opts.permissions !== undefined
|
|
490
495
|
? { hidden: resolveHiddenPaths(opts.permissions, liveOrigin, opts.agentDir) }
|
|
@@ -562,6 +567,7 @@ export function wrapBuiltinToolDefinition<TParams extends TSchema, TDetails = un
|
|
|
562
567
|
sessionId: opts.sessionId,
|
|
563
568
|
callId: toolCallId,
|
|
564
569
|
args: mutableArgs,
|
|
570
|
+
toolProvenance: 'first-party',
|
|
565
571
|
...(liveOrigin !== undefined ? { origin: liveOrigin } : {}),
|
|
566
572
|
})
|
|
567
573
|
if (blockResult !== undefined) {
|
|
@@ -646,6 +652,7 @@ export function wrapBuiltinToolDefinition<TParams extends TSchema, TDetails = un
|
|
|
646
652
|
tool: tool.name,
|
|
647
653
|
args: attemptArgs,
|
|
648
654
|
agentDir: opts.agentDir,
|
|
655
|
+
toolProvenance: 'first-party',
|
|
649
656
|
...(opts.permissions !== undefined
|
|
650
657
|
? {
|
|
651
658
|
hidden:
|
|
@@ -126,6 +126,9 @@ export const PARTICIPANTS_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000
|
|
|
126
126
|
type PlatformInfo = {
|
|
127
127
|
displayName: string
|
|
128
128
|
mentionMode: 'angle-id' | 'at-username' | 'alias'
|
|
129
|
+
// This platform has no rich-text rendering, so markdown markers appear
|
|
130
|
+
// literally to users.
|
|
131
|
+
plainTextOnly: boolean
|
|
129
132
|
// Whether this adapter registers a ReactionCallback, i.e. whether
|
|
130
133
|
// `channel_react` actually does anything here. Gates the proactive-reaction
|
|
131
134
|
// prompt guidance so we never tell a KakaoTalk/Telegram agent to react when
|
|
@@ -145,28 +148,90 @@ type PlatformInfo = {
|
|
|
145
148
|
}
|
|
146
149
|
|
|
147
150
|
const PLATFORM_INFO: Record<AdapterId, PlatformInfo> = {
|
|
148
|
-
slack: {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
slack: {
|
|
152
|
+
displayName: 'Slack',
|
|
153
|
+
mentionMode: 'angle-id',
|
|
154
|
+
plainTextOnly: false,
|
|
155
|
+
supportsReactions: true,
|
|
156
|
+
supportsAttachments: true,
|
|
157
|
+
},
|
|
158
|
+
'slack-bot': {
|
|
159
|
+
displayName: 'Slack',
|
|
160
|
+
mentionMode: 'angle-id',
|
|
161
|
+
plainTextOnly: false,
|
|
162
|
+
supportsReactions: true,
|
|
163
|
+
supportsAttachments: true,
|
|
164
|
+
},
|
|
165
|
+
discord: {
|
|
166
|
+
displayName: 'Discord',
|
|
167
|
+
mentionMode: 'angle-id',
|
|
168
|
+
plainTextOnly: false,
|
|
169
|
+
supportsReactions: true,
|
|
170
|
+
supportsAttachments: true,
|
|
171
|
+
},
|
|
151
172
|
'discord-bot': {
|
|
152
173
|
displayName: 'Discord',
|
|
153
174
|
mentionMode: 'angle-id',
|
|
175
|
+
plainTextOnly: false,
|
|
154
176
|
supportsReactions: true,
|
|
155
177
|
supportsAttachments: true,
|
|
156
178
|
},
|
|
157
|
-
github: {
|
|
158
|
-
|
|
179
|
+
github: {
|
|
180
|
+
displayName: 'GitHub',
|
|
181
|
+
mentionMode: 'at-username',
|
|
182
|
+
plainTextOnly: false,
|
|
183
|
+
supportsReactions: true,
|
|
184
|
+
supportsAttachments: false,
|
|
185
|
+
},
|
|
186
|
+
instagram: {
|
|
187
|
+
displayName: 'Instagram',
|
|
188
|
+
mentionMode: 'alias',
|
|
189
|
+
plainTextOnly: true,
|
|
190
|
+
supportsReactions: false,
|
|
191
|
+
supportsAttachments: false,
|
|
192
|
+
},
|
|
159
193
|
'telegram-bot': {
|
|
160
194
|
displayName: 'Telegram',
|
|
161
195
|
mentionMode: 'at-username',
|
|
196
|
+
plainTextOnly: false,
|
|
197
|
+
supportsReactions: false,
|
|
198
|
+
supportsAttachments: true,
|
|
199
|
+
},
|
|
200
|
+
webex: {
|
|
201
|
+
displayName: 'Webex',
|
|
202
|
+
mentionMode: 'angle-id',
|
|
203
|
+
plainTextOnly: false,
|
|
204
|
+
supportsReactions: false,
|
|
205
|
+
supportsAttachments: true,
|
|
206
|
+
},
|
|
207
|
+
'webex-bot': {
|
|
208
|
+
displayName: 'Webex',
|
|
209
|
+
mentionMode: 'angle-id',
|
|
210
|
+
plainTextOnly: false,
|
|
211
|
+
supportsReactions: false,
|
|
212
|
+
supportsAttachments: false,
|
|
213
|
+
},
|
|
214
|
+
teams: {
|
|
215
|
+
displayName: 'Teams',
|
|
216
|
+
mentionMode: 'alias',
|
|
217
|
+
plainTextOnly: false,
|
|
218
|
+
supportsReactions: false,
|
|
219
|
+
supportsAttachments: false,
|
|
220
|
+
},
|
|
221
|
+
line: {
|
|
222
|
+
displayName: 'LINE',
|
|
223
|
+
mentionMode: 'alias',
|
|
224
|
+
plainTextOnly: true,
|
|
225
|
+
supportsReactions: false,
|
|
226
|
+
supportsAttachments: false,
|
|
227
|
+
},
|
|
228
|
+
kakaotalk: {
|
|
229
|
+
displayName: 'KakaoTalk',
|
|
230
|
+
mentionMode: 'alias',
|
|
231
|
+
plainTextOnly: true,
|
|
162
232
|
supportsReactions: false,
|
|
163
233
|
supportsAttachments: true,
|
|
164
234
|
},
|
|
165
|
-
webex: { displayName: 'Webex', mentionMode: 'angle-id', supportsReactions: false, supportsAttachments: true },
|
|
166
|
-
'webex-bot': { displayName: 'Webex', mentionMode: 'angle-id', supportsReactions: false, supportsAttachments: false },
|
|
167
|
-
teams: { displayName: 'Teams', mentionMode: 'alias', supportsReactions: false, supportsAttachments: false },
|
|
168
|
-
line: { displayName: 'LINE', mentionMode: 'alias', supportsReactions: false, supportsAttachments: false },
|
|
169
|
-
kakaotalk: { displayName: 'KakaoTalk', mentionMode: 'alias', supportsReactions: false, supportsAttachments: true },
|
|
170
235
|
}
|
|
171
236
|
|
|
172
237
|
function getPlatformInfo(adapter: AdapterId): PlatformInfo {
|
|
@@ -375,6 +440,10 @@ function renderChannelOrigin(
|
|
|
375
440
|
'it via `channel_reply`/`gh pr comment`; that is a visible duplicate.',
|
|
376
441
|
'One verdict, one surface. After submitting the review, use',
|
|
377
442
|
'`skip_response({ reason: "verdict posted as review" })`.',
|
|
443
|
+
'',
|
|
444
|
+
'GitHub renders real Markdown; use it freely.',
|
|
445
|
+
'The GitHub adapter cannot send file attachments.',
|
|
446
|
+
'GitHub has no typing indicator.',
|
|
378
447
|
)
|
|
379
448
|
|
|
380
449
|
// Models reliably address review-comment feedback and then end the turn
|
|
@@ -416,6 +485,25 @@ function renderChannelOrigin(
|
|
|
416
485
|
)
|
|
417
486
|
}
|
|
418
487
|
|
|
488
|
+
if (platformInfo.plainTextOnly) {
|
|
489
|
+
lines.push(
|
|
490
|
+
'',
|
|
491
|
+
'This platform renders messages as PLAIN TEXT with no rich-text formatting.',
|
|
492
|
+
'Write plain text from the start.',
|
|
493
|
+
'Do not use markdown bold/italics, `##` headings, `|` tables, fenced code',
|
|
494
|
+
'blocks, inline-code backticks, or `[label](url)` links; they appear literally.',
|
|
495
|
+
'Send bare URLs; the client auto-links them.',
|
|
496
|
+
'No threads and no quoted replies; every message is top-level.',
|
|
497
|
+
'Keep replies short and conversational for mobile reading: lead with a',
|
|
498
|
+
'one-sentence summary, then at most a few short lines.',
|
|
499
|
+
'If asked for something the platform cannot do, say so plainly.',
|
|
500
|
+
platformInfo.supportsAttachments
|
|
501
|
+
? 'Attachments can be passed via `attachments[]` on `channel_send`/`channel_reply`.'
|
|
502
|
+
: 'Outbound attachments and stickers are unsupported; send text or a link instead.',
|
|
503
|
+
...(platformInfo.supportsAttachments ? ['Outbound stickers/emoticons are not supported.'] : []),
|
|
504
|
+
)
|
|
505
|
+
}
|
|
506
|
+
|
|
419
507
|
const conversationLine = renderConversationLine(origin)
|
|
420
508
|
if (conversationLine !== null) lines.push('', conversationLine)
|
|
421
509
|
|
|
@@ -616,18 +704,18 @@ function renderMentionGuidance(
|
|
|
616
704
|
]
|
|
617
705
|
case 'at-username':
|
|
618
706
|
return [
|
|
619
|
-
`To mention someone in your reply, use
|
|
620
|
-
|
|
707
|
+
`To mention someone in your reply, use ${platformInfo.displayName} syntax \`@username\` in plain text.`,
|
|
708
|
+
`${platformInfo.displayName} usernames are a SEPARATE field from \`authorId\`; \`<@id>\` tokens`,
|
|
621
709
|
'in participants are inbound-only typeclaw markers, so do not echo them back as outbound mentions.',
|
|
622
710
|
'If no `@username` is known, use display name; reply context carries it.',
|
|
623
711
|
...renderSelfMention(platformInfo, self),
|
|
624
712
|
]
|
|
625
713
|
case 'alias':
|
|
626
714
|
return [
|
|
627
|
-
|
|
715
|
+
`${platformInfo.displayName} has no in-band mention syntax. To address someone, just type their display name as plain text;`,
|
|
628
716
|
"the participants block shows display names. Users get the bot's attention with configured aliases,",
|
|
629
717
|
'not copied tokens. Any `<@id>` marker is inbound-only typeclaw convention;',
|
|
630
|
-
|
|
718
|
+
`do not echo them back as outbound mentions or ${platformInfo.displayName} renders them literally.`,
|
|
631
719
|
]
|
|
632
720
|
}
|
|
633
721
|
}
|
|
@@ -763,13 +851,13 @@ function renderParticipantsTrailing(platformInfo: PlatformInfo): string[] {
|
|
|
763
851
|
case 'at-username':
|
|
764
852
|
return [
|
|
765
853
|
"If a current sender isn't listed, address by `@username` when known.",
|
|
766
|
-
|
|
854
|
+
`${platformInfo.displayName} usernames are a SEPARATE field from numeric \`authorId\`, and`,
|
|
767
855
|
'not every user has one. The list is recent context, not a directory.',
|
|
768
856
|
]
|
|
769
857
|
case 'alias':
|
|
770
858
|
return [
|
|
771
859
|
"If a current sender isn't listed, address by display name as plain text.",
|
|
772
|
-
|
|
860
|
+
`${platformInfo.displayName} has no in-band mention syntax; \`authorId\` is reference only`,
|
|
773
861
|
'and must not be echoed back. The list is recent context, not a directory.',
|
|
774
862
|
]
|
|
775
863
|
}
|
|
@@ -58,7 +58,7 @@ export function renderSubagentCompletionReminder(args: CompletionReminderArgs):
|
|
|
58
58
|
const err = args.error ?? 'unknown error'
|
|
59
59
|
const recoveryHint =
|
|
60
60
|
args.hasRecoverableOutput === true
|
|
61
|
-
? `It produced output before failing — call subagent_output to recover it instead of redoing the work. `
|
|
61
|
+
? `It produced output before failing — call subagent_output to recover it as partial recovery data, not a completed verdict, instead of redoing the work. `
|
|
62
62
|
: `Use subagent_output to inspect. `
|
|
63
63
|
return (
|
|
64
64
|
`<system-reminder>\n` +
|
|
@@ -93,13 +93,22 @@ function expireOverdueChildren(
|
|
|
93
93
|
if (child.startedAt > deadline) continue
|
|
94
94
|
const durationMs = now() - child.startedAt
|
|
95
95
|
const error = `subagent ${child.subagentName} exceeded the ${maxChildWaitMs}ms drain wait and was abandoned`
|
|
96
|
+
const finalMessage = drain.liveRegistry.getCapturedFinalMessage(child.taskId)
|
|
96
97
|
// Claim the settlement BEFORE aborting. If the child's real completion
|
|
97
98
|
// already won, skip — no double-settle, no broadcast. Awaiting abort here
|
|
98
99
|
// would be the bug the ceiling exists to prevent: a wedged `session.abort()`
|
|
99
100
|
// that never reaches idle would hang the drain, so fire-and-forget instead.
|
|
100
101
|
// Logical settlement can precede physical teardown; startSubagent still
|
|
101
102
|
// disposes the session when its own work settles.
|
|
102
|
-
if (
|
|
103
|
+
if (
|
|
104
|
+
!drain.liveRegistry.recordCompletionIfRunning(child.taskId, {
|
|
105
|
+
ok: false,
|
|
106
|
+
durationMs,
|
|
107
|
+
error,
|
|
108
|
+
...(finalMessage !== undefined ? { finalMessage } : {}),
|
|
109
|
+
})
|
|
110
|
+
)
|
|
111
|
+
continue
|
|
103
112
|
drain.stream.publish({
|
|
104
113
|
target: { kind: 'broadcast' },
|
|
105
114
|
payload: {
|
|
@@ -110,6 +119,7 @@ function expireOverdueChildren(
|
|
|
110
119
|
ok: false,
|
|
111
120
|
durationMs,
|
|
112
121
|
error,
|
|
122
|
+
...(finalMessage !== undefined ? { hasRecoverableOutput: true } : {}),
|
|
113
123
|
},
|
|
114
124
|
})
|
|
115
125
|
void child.abort().catch(() => {})
|