typeclaw 0.48.2 → 0.48.3
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 +1 -1
- package/src/agent/index.ts +35 -9
- package/src/agent/plugin-tools.ts +14 -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 +7 -1
- package/src/agent/tools/channel-reply.ts +18 -1
- package/src/bundled-plugins/security/policies/private-surface-read.ts +88 -32
- 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 +275 -55
- package/src/channels/types.ts +4 -1
- package/src/config/providers.ts +16 -10
- 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/manager.ts +19 -1
- 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/skills/typeclaw-permissions/SKILL.md +13 -1
- package/src/skills/typeclaw-plugins/SKILL.md +91 -11
package/package.json
CHANGED
package/src/agent/index.ts
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import { defaultThinkingLevelForRef, isOpenAiFamilyRef, providerForModelRef, type ModelRef } from '@/config/providers'
|
|
24
24
|
import { renderMcpCatalog } from '@/mcp/catalog'
|
|
25
25
|
import type { McpManager } from '@/mcp/manager'
|
|
26
|
-
import { createMcpDispatcherTools, MCP_DISPATCHER_TOOL_NAMES } from '@/mcp/tools'
|
|
26
|
+
import { createMcpDispatcherTools, MCP_DISPATCHER_TOOL_NAMES, resolveMcpCallPreflightFileOperands } from '@/mcp/tools'
|
|
27
27
|
import { noopPermissionService, type PermissionService, type RolesConfig } from '@/permissions'
|
|
28
28
|
import type {
|
|
29
29
|
BuiltinToolRef,
|
|
@@ -35,6 +35,7 @@ import type {
|
|
|
35
35
|
} from '@/plugin'
|
|
36
36
|
import { createHookBus, materializeSkills } from '@/plugin'
|
|
37
37
|
import type { ReloadRegistry } from '@/reload'
|
|
38
|
+
import { resolveHiddenPaths } from '@/sandbox'
|
|
38
39
|
import type { Stream } from '@/stream'
|
|
39
40
|
|
|
40
41
|
import { applyAdaptiveThinkingCompat } from './adaptive-thinking-compat'
|
|
@@ -406,7 +407,13 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
406
407
|
webSearchTool,
|
|
407
408
|
webFetchTool,
|
|
408
409
|
createLookAtTool(options.permissions),
|
|
409
|
-
...(options.mcpManager
|
|
410
|
+
...(options.mcpManager
|
|
411
|
+
? buildMcpDispatcherToolDefinitions(options.mcpManager, {
|
|
412
|
+
permissions: options.permissions,
|
|
413
|
+
getOrigin,
|
|
414
|
+
agentDir: options.plugins?.agentDir ?? process.cwd(),
|
|
415
|
+
})
|
|
416
|
+
: []),
|
|
410
417
|
...(options.reloadRegistry ? [createReloadTool({ registry: options.reloadRegistry })] : []),
|
|
411
418
|
...(options.stream ? [createStreamSnapshotTool({ stream: options.stream })] : []),
|
|
412
419
|
...buildChannelTools(
|
|
@@ -471,6 +478,7 @@ export async function createSessionWithDispose(options: CreateSessionOptions = {
|
|
|
471
478
|
getOrigin,
|
|
472
479
|
getAbort,
|
|
473
480
|
getLoopGuardTurn,
|
|
481
|
+
...(options.mcpManager === undefined ? {} : { mcpManager: options.mcpManager }),
|
|
474
482
|
})
|
|
475
483
|
const customToolsPreBudget = [...wrappedCustomSystemTools, ...pluginCustomTools, ...builtinPiToolOverrides]
|
|
476
484
|
const customTools =
|
|
@@ -783,16 +791,26 @@ export function buildChannelTools(
|
|
|
783
791
|
return tools
|
|
784
792
|
}
|
|
785
793
|
|
|
786
|
-
export function buildMcpDispatcherToolDefinitions(
|
|
787
|
-
|
|
794
|
+
export function buildMcpDispatcherToolDefinitions(
|
|
795
|
+
manager: McpManager,
|
|
796
|
+
opts: {
|
|
797
|
+
permissions: PermissionService | undefined
|
|
798
|
+
getOrigin: () => SessionOrigin | undefined
|
|
799
|
+
agentDir: string
|
|
800
|
+
},
|
|
801
|
+
): ToolDefinition[] {
|
|
802
|
+
const permissions = opts.permissions ?? noopPermissionService
|
|
803
|
+
const tools = createMcpDispatcherTools(manager, {
|
|
804
|
+
resolveHidden: () => resolveHiddenPaths(permissions, opts.getOrigin(), opts.agentDir),
|
|
805
|
+
})
|
|
788
806
|
return [
|
|
789
|
-
defineMcpDispatcherTool(MCP_DISPATCHER_TOOL_NAMES[0], tools[0]),
|
|
790
|
-
defineMcpDispatcherTool(MCP_DISPATCHER_TOOL_NAMES[1], tools[1]),
|
|
791
|
-
defineMcpDispatcherTool(MCP_DISPATCHER_TOOL_NAMES[2], tools[2]),
|
|
807
|
+
defineMcpDispatcherTool(MCP_DISPATCHER_TOOL_NAMES[0], tools[0], opts.agentDir),
|
|
808
|
+
defineMcpDispatcherTool(MCP_DISPATCHER_TOOL_NAMES[1], tools[1], opts.agentDir),
|
|
809
|
+
defineMcpDispatcherTool(MCP_DISPATCHER_TOOL_NAMES[2], tools[2], opts.agentDir),
|
|
792
810
|
]
|
|
793
811
|
}
|
|
794
812
|
|
|
795
|
-
function defineMcpDispatcherTool<P>(name: string, tool: PluginTool<P
|
|
813
|
+
function defineMcpDispatcherTool<P>(name: string, tool: PluginTool<P>, agentDir: string): ToolDefinition {
|
|
796
814
|
return definePiTool({
|
|
797
815
|
name,
|
|
798
816
|
label: name,
|
|
@@ -809,7 +827,7 @@ function defineMcpDispatcherTool<P>(name: string, tool: PluginTool<P>): ToolDefi
|
|
|
809
827
|
const result = await tool.execute(validated.data, {
|
|
810
828
|
signal,
|
|
811
829
|
sessionId: 'mcp-dispatcher',
|
|
812
|
-
agentDir
|
|
830
|
+
agentDir,
|
|
813
831
|
logger: { info() {}, warn() {}, error() {} },
|
|
814
832
|
})
|
|
815
833
|
return { content: result.content, details: result.details ?? null }
|
|
@@ -925,8 +943,15 @@ export function wrapSystemTools(
|
|
|
925
943
|
getOrigin: () => SessionOrigin | undefined
|
|
926
944
|
getAbort: () => ((reason?: string) => void) | undefined
|
|
927
945
|
getLoopGuardTurn?: () => number | undefined
|
|
946
|
+
mcpManager?: McpManager
|
|
928
947
|
},
|
|
929
948
|
): ToolDefinition[] {
|
|
949
|
+
const mcpManager = options.mcpManager
|
|
950
|
+
const resolvePreflightFileOperands =
|
|
951
|
+
mcpManager === undefined
|
|
952
|
+
? undefined
|
|
953
|
+
: (tool: string, args: Record<string, unknown>) =>
|
|
954
|
+
tool === MCP_DISPATCHER_TOOL_NAMES[2] ? resolveMcpCallPreflightFileOperands(mcpManager, args) : undefined
|
|
930
955
|
return tools.map((tool) =>
|
|
931
956
|
wrapSystemTool(tool, {
|
|
932
957
|
agentDir: options.agentDir,
|
|
@@ -935,6 +960,7 @@ export function wrapSystemTools(
|
|
|
935
960
|
getOrigin: options.getOrigin,
|
|
936
961
|
getAbort: options.getAbort,
|
|
937
962
|
getLoopGuardTurn: options.getLoopGuardTurn,
|
|
963
|
+
...(resolvePreflightFileOperands === undefined ? {} : { resolvePreflightFileOperands }),
|
|
938
964
|
}),
|
|
939
965
|
)
|
|
940
966
|
}
|
|
@@ -44,6 +44,7 @@ import type {
|
|
|
44
44
|
Tool,
|
|
45
45
|
ToolBeforeEvent,
|
|
46
46
|
ToolContext,
|
|
47
|
+
ToolFileOperands,
|
|
47
48
|
ToolResult,
|
|
48
49
|
} from '@/plugin'
|
|
49
50
|
import {
|
|
@@ -300,6 +301,14 @@ export type WrapSystemToolOptions = {
|
|
|
300
301
|
bashSandboxBoundary?: BashSandboxBoundary
|
|
301
302
|
realProcDependencyCheck?: typeof commandNeedsRealProc
|
|
302
303
|
remediations?: RemediationRegistry
|
|
304
|
+
// A dispatcher system tool (mcp_call) forwards a nested payload to a target
|
|
305
|
+
// chosen at call time, so its operand declarations are not knowable from the
|
|
306
|
+
// static tool definition the way a plugin tool's are. This seam resolves them
|
|
307
|
+
// per call, BEFORE the hooks run. The result feeds the security hooks ONLY —
|
|
308
|
+
// it is never handed to `enforceAndPinToolFiles`, so it can never make this
|
|
309
|
+
// boundary pin a file. It must not perform I/O against an unconnected target;
|
|
310
|
+
// returning undefined keeps the existing fail-closed scan.
|
|
311
|
+
resolvePreflightFileOperands?: (tool: string, args: Record<string, unknown>) => ToolFileOperands | undefined
|
|
303
312
|
incidentLedger?: IncidentLedger
|
|
304
313
|
}
|
|
305
314
|
|
|
@@ -438,12 +447,14 @@ export function wrapSystemTool<TParams extends TSchema, TDetails = unknown, TSta
|
|
|
438
447
|
const mutableArgs = params as Record<string, unknown>
|
|
439
448
|
normalizeDefaultTreeRoot(tool.name, mutableArgs)
|
|
440
449
|
const liveOrigin = opts.getOrigin?.()
|
|
450
|
+
const preflightFileOperands = opts.resolvePreflightFileOperands?.(tool.name, mutableArgs)
|
|
441
451
|
const blockResult = await opts.hooks.runToolBefore({
|
|
442
452
|
tool: tool.name,
|
|
443
453
|
sessionId: opts.sessionId,
|
|
444
454
|
callId: toolCallId,
|
|
445
455
|
args: mutableArgs,
|
|
446
456
|
...(liveOrigin !== undefined ? { origin: liveOrigin } : {}),
|
|
457
|
+
...(preflightFileOperands !== undefined ? { fileOperands: preflightFileOperands } : {}),
|
|
447
458
|
})
|
|
448
459
|
if (blockResult !== undefined) {
|
|
449
460
|
throw new Error(`blocked: ${blockResult.reason}`)
|
|
@@ -467,6 +478,9 @@ export function wrapSystemTool<TParams extends TSchema, TDetails = unknown, TSta
|
|
|
467
478
|
}
|
|
468
479
|
stripGuardAcknowledgements(mutableArgs)
|
|
469
480
|
|
|
481
|
+
// `preflightFileOperands` is deliberately NOT forwarded: this boundary's
|
|
482
|
+
// canonical credential denial must stay unconditional, so a target-declared
|
|
483
|
+
// nonFile operand can never exempt `secrets.json`/`.env`/`~/.ssh` from it.
|
|
470
484
|
const pinnedFiles = await enforceAndPinToolFiles({
|
|
471
485
|
tool: tool.name,
|
|
472
486
|
args: mutableArgs,
|
|
@@ -46,6 +46,9 @@ export type ContinuationEpisode = {
|
|
|
46
46
|
export type TurnOutcome = {
|
|
47
47
|
turnId: string
|
|
48
48
|
stopReason: 'stop' | 'length' | 'aborted' | 'error' | 'unknown'
|
|
49
|
+
// Trusted runtime provenance for the one intentional abort that is safe to
|
|
50
|
+
// continue. Optional so older state files remain valid.
|
|
51
|
+
termination?: 'terminal-after-channel-reply'
|
|
49
52
|
endedAt: number
|
|
50
53
|
// Total tokens the just-completed turn consumed (from the assistant
|
|
51
54
|
// message's usage). Accumulated into the episode's cumulativeTokens so the
|
|
@@ -136,6 +139,7 @@ function parseOutcome(value: unknown): TurnOutcome | null {
|
|
|
136
139
|
turnId: o.turnId,
|
|
137
140
|
stopReason: o.stopReason as TurnOutcome['stopReason'],
|
|
138
141
|
endedAt: o.endedAt,
|
|
142
|
+
...(o.termination === 'terminal-after-channel-reply' ? { termination: o.termination } : {}),
|
|
139
143
|
...(isFiniteNumber(o.tokens) ? { tokens: o.tokens } : {}),
|
|
140
144
|
}
|
|
141
145
|
}
|
|
@@ -209,7 +213,13 @@ export function decideContinuation(args: {
|
|
|
209
213
|
if (state.autoResumeBlockedUntilRealUserTurn) return { kind: 'skip', reason: 'user-abort-blocked' }
|
|
210
214
|
|
|
211
215
|
const outcome = state.lastTurnOutcome
|
|
212
|
-
|
|
216
|
+
const isSafeTerminalReplyAbort =
|
|
217
|
+
outcome?.stopReason === 'aborted' && outcome.termination === 'terminal-after-channel-reply'
|
|
218
|
+
if (
|
|
219
|
+
outcome === null ||
|
|
220
|
+
outcome.stopReason === 'unknown' ||
|
|
221
|
+
(outcome.stopReason === 'aborted' && !isSafeTerminalReplyAbort)
|
|
222
|
+
) {
|
|
213
223
|
return { kind: 'skip', reason: 'turn-not-safe' }
|
|
214
224
|
}
|
|
215
225
|
|
|
@@ -81,7 +81,9 @@ export function onTurnStart(state: ContinuationState, isRealUserTurn: boolean):
|
|
|
81
81
|
// consumed here regardless — so a later genuine user abort still arms D1.
|
|
82
82
|
export function onTurnOutcome(state: ContinuationState, outcome: TurnOutcome): ContinuationState {
|
|
83
83
|
const next: ContinuationState = { ...state, lastTurnOutcome: outcome, restartAbortPending: false }
|
|
84
|
-
|
|
84
|
+
const isSafeTerminalReplyAbort =
|
|
85
|
+
outcome.stopReason === 'aborted' && outcome.termination === 'terminal-after-channel-reply'
|
|
86
|
+
if (outcome.stopReason === 'aborted' && !state.restartAbortPending && !isSafeTerminalReplyAbort) {
|
|
85
87
|
next.autoResumeBlockedUntilRealUserTurn = true
|
|
86
88
|
}
|
|
87
89
|
return next
|
|
@@ -52,6 +52,7 @@ export async function recordTurnOutcome(args: {
|
|
|
52
52
|
origin: SessionOrigin
|
|
53
53
|
turnId: string
|
|
54
54
|
stopReason: TurnOutcome['stopReason']
|
|
55
|
+
termination?: TurnOutcome['termination']
|
|
55
56
|
tokens?: number
|
|
56
57
|
now?: number
|
|
57
58
|
}): Promise<void> {
|
|
@@ -62,6 +63,7 @@ export async function recordTurnOutcome(args: {
|
|
|
62
63
|
turnId: args.turnId,
|
|
63
64
|
stopReason: args.stopReason,
|
|
64
65
|
endedAt: args.now ?? Date.now(),
|
|
66
|
+
...(args.termination !== undefined ? { termination: args.termination } : {}),
|
|
65
67
|
...(args.tokens !== undefined ? { tokens: args.tokens } : {}),
|
|
66
68
|
}
|
|
67
69
|
await writeContinuationState(args.agentDir, scope, onTurnOutcome(state, outcome))
|
|
@@ -245,12 +245,18 @@ async function removePinnedSnapshot(root: string): Promise<void> {
|
|
|
245
245
|
await rm(root, { recursive: true, force: true })
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
// Canonical credential denial is the one check no operand declaration can waive:
|
|
249
|
+
// `fileOperands` is destructured away rather than spread through, so a tool (or a
|
|
250
|
+
// remote MCP server) declaring `nonFile` on an operand cannot make `secrets.json`,
|
|
251
|
+
// `.env`, or `~/.ssh` pass here. Role-derived private directories stay declarable
|
|
252
|
+
// and are enforced separately by the private-surface-read guard.
|
|
248
253
|
export function enforceCanonicalSecretDenial(options: {
|
|
249
254
|
tool: string
|
|
250
255
|
args: Record<string, unknown>
|
|
251
256
|
agentDir: string
|
|
252
257
|
}): void {
|
|
253
|
-
const
|
|
258
|
+
const { tool, args, agentDir } = options
|
|
259
|
+
const blocked = checkPrivateSurfaceReadGuard({ tool, args, agentDir, hidden: { dirs: [], files: [] } })
|
|
254
260
|
if (blocked !== undefined) throw new Error(`blocked: ${blocked.reason}`)
|
|
255
261
|
}
|
|
256
262
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Type } from '@mariozechner/pi-ai'
|
|
2
2
|
import { defineTool } from '@mariozechner/pi-coding-agent'
|
|
3
3
|
|
|
4
|
+
import { checkCompletionClaim } from '@/channels/completion-claim'
|
|
4
5
|
import { checkFalseReceipt } from '@/channels/github-false-receipt'
|
|
5
6
|
import { evaluateRereviewGuard } from '@/channels/github-rereview-guard'
|
|
6
7
|
import {
|
|
@@ -197,6 +198,19 @@ export function createChannelReplyTool({
|
|
|
197
198
|
}
|
|
198
199
|
const falseReceiptNotice = falseReceipt.kind === 'warn' ? falseReceipt.notice : null
|
|
199
200
|
|
|
201
|
+
const completionClaim = checkCompletionClaim({
|
|
202
|
+
text,
|
|
203
|
+
qualifyingWorkObserved: router.hasQualifyingWorkThisLogicalTurn?.(origin) === true,
|
|
204
|
+
})
|
|
205
|
+
if (completionClaim.kind === 'block') {
|
|
206
|
+
logger.warn(formatChannelToolFailure('channel_reply', completionClaim.reason))
|
|
207
|
+
return {
|
|
208
|
+
content: [{ type: 'text' as const, text: `channel_reply denied: ${completionClaim.reason}` }],
|
|
209
|
+
details: { ok: false, error: completionClaim.reason },
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const completionClaimNotice = completionClaim.kind === 'warn' ? completionClaim.notice : null
|
|
213
|
+
|
|
200
214
|
// Re-review stranding guard: block a thread close-out / verdict ack while
|
|
201
215
|
// the bot still holds its own CHANGES_REQUESTED on this PR, so it can't
|
|
202
216
|
// silently leave the PR blocked (PR #644). Runs before the resolve so a
|
|
@@ -307,7 +321,10 @@ export function createChannelReplyTool({
|
|
|
307
321
|
// TOOL_RESULT_PREFIX to match the denial branch below. The prefix is
|
|
308
322
|
// intentionally weaker and is safe ONLY because denials carry no echoed
|
|
309
323
|
// prose; the success result does, and the weak prefix let Kimi loop.
|
|
310
|
-
const
|
|
324
|
+
const warnings = [falseReceiptNotice, completionClaimNotice].filter(
|
|
325
|
+
(notice): notice is string => notice !== null,
|
|
326
|
+
)
|
|
327
|
+
const warnNote = warnings.length > 0 ? fenceRuntimeNotice(warnings.join('\n\n')) : ''
|
|
311
328
|
const missNote = resolveMissNotice ?? ''
|
|
312
329
|
return {
|
|
313
330
|
content: [{ type: 'text' as const, text: `${fenceToolResult(receipt)}${hint}${warnNote}${missNote}` }],
|
|
@@ -19,11 +19,11 @@ import { TOOLS_WITHOUT_LOCAL_FILE_OPERANDS } from '@/agent/tools-without-local-f
|
|
|
19
19
|
import { RECOVER_MISSING_OR_UNSEARCHABLE, realIntendedPathSync } from '@/path-safety/real-intended-path'
|
|
20
20
|
import type { ToolFileOperands } from '@/plugin'
|
|
21
21
|
import {
|
|
22
|
-
CANONICAL_AGENT_SECRET_DIRS,
|
|
23
22
|
CANONICAL_AGENT_SECRET_FILES,
|
|
24
23
|
CANONICAL_HOME_SECRET_DIRS,
|
|
25
24
|
CANONICAL_HOME_SECRET_FILES,
|
|
26
25
|
CONTAINER_RUNTIME_HOME,
|
|
26
|
+
RUNTIME_OWNED_SECRET_DIRS,
|
|
27
27
|
type HiddenPaths,
|
|
28
28
|
} from '@/sandbox'
|
|
29
29
|
|
|
@@ -83,22 +83,27 @@ export function checkPrivateSurfaceReadGuard(
|
|
|
83
83
|
const { tool, args, agentDir, hidden, fileOperands } = options
|
|
84
84
|
if (UNSCANNED_TOOLS.has(tool)) return undefined
|
|
85
85
|
try {
|
|
86
|
-
const {
|
|
87
|
-
|
|
88
|
-
const
|
|
86
|
+
const { canonicalDirs, canonicalFiles, roleDirs, roleFiles } = deniedSurface(agentDir, hidden)
|
|
87
|
+
const canonicalEmpty = canonicalDirs.length === 0 && canonicalFiles.length === 0
|
|
88
|
+
const roleEmpty = roleDirs.length === 0 && roleFiles.length === 0
|
|
89
|
+
if (canonicalEmpty && roleEmpty) return undefined
|
|
89
90
|
const realpath = hooks.realpathNative ?? realpathSync.native
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
if (!canonicalEmpty) {
|
|
93
|
+
const identityScanner = createHardlinkIdentityScanner(agentDir, canonicalDirs, canonicalFiles, hooks)
|
|
94
|
+
for (const candidate of collectPathCandidates(args, tool, undefined, undefined, true)) {
|
|
95
|
+
const hit = matchHidden(candidate, agentDir, canonicalDirs, canonicalFiles, identityScanner, realpath)
|
|
96
|
+
if (hit !== undefined) return privateSurfacePathBlock(tool, candidate, hit)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!roleEmpty) {
|
|
101
|
+
const identityScanner = createHardlinkIdentityScanner(agentDir, roleDirs, roleFiles, hooks)
|
|
102
|
+
const nonFile = fileOperands?.nonFile === undefined ? undefined : new Set(fileOperands.nonFile)
|
|
103
|
+
const localOperands = collectLocalOperandPaths(fileOperands)
|
|
104
|
+
for (const candidate of collectPathCandidates(args, tool, nonFile, localOperands, false)) {
|
|
105
|
+
const hit = matchHidden(candidate, agentDir, roleDirs, roleFiles, identityScanner, realpath)
|
|
106
|
+
if (hit !== undefined) return privateSurfacePathBlock(tool, candidate, hit)
|
|
102
107
|
}
|
|
103
108
|
}
|
|
104
109
|
return undefined
|
|
@@ -134,7 +139,9 @@ export function createPrivateSurfaceReadIdentityVerifier(
|
|
|
134
139
|
options: PrivateSurfaceIdentityOptions,
|
|
135
140
|
hooks: PrivateSurfaceIdentityScanHooks = {},
|
|
136
141
|
): PrivateSurfaceIdentityVerifier {
|
|
137
|
-
const {
|
|
142
|
+
const { canonicalDirs, canonicalFiles, roleDirs, roleFiles } = deniedSurface(options.agentDir, options.hidden)
|
|
143
|
+
const deniedDirs = [...new Set([...canonicalDirs, ...roleDirs])]
|
|
144
|
+
const deniedFiles = [...new Set([...canonicalFiles, ...roleFiles])]
|
|
138
145
|
const scanner = createHardlinkIdentityScanner(options.agentDir, deniedDirs, deniedFiles, hooks)
|
|
139
146
|
return {
|
|
140
147
|
check(identity) {
|
|
@@ -174,12 +181,14 @@ function createHardlinkIdentityScanner(
|
|
|
174
181
|
})
|
|
175
182
|
}
|
|
176
183
|
|
|
177
|
-
function deniedSurface(
|
|
184
|
+
function deniedSurface(
|
|
185
|
+
agentDir: string,
|
|
186
|
+
hidden: HiddenPaths,
|
|
187
|
+
): { canonicalDirs: string[]; canonicalFiles: string[]; roleDirs: string[]; roleFiles: string[] } {
|
|
178
188
|
return {
|
|
179
|
-
|
|
189
|
+
canonicalDirs: [
|
|
180
190
|
...new Set([
|
|
181
|
-
...
|
|
182
|
-
...CANONICAL_AGENT_SECRET_DIRS.map((dir) => path.join(agentDir, dir)),
|
|
191
|
+
...RUNTIME_OWNED_SECRET_DIRS.map((dir) => path.join(agentDir, dir)),
|
|
183
192
|
// homedir() follows the live container HOME; the fixed runtime path
|
|
184
193
|
// keeps the same denial deterministic in host-stage tests and any
|
|
185
194
|
// partially-initialized caller whose environment has not switched yet.
|
|
@@ -189,14 +198,25 @@ function deniedSurface(agentDir: string, hidden: HiddenPaths): { deniedDirs: str
|
|
|
189
198
|
],
|
|
190
199
|
// Keep runtime-owned credential stores independent of role-derived
|
|
191
200
|
// visibility so a partially-wired caller cannot expose raw credentials.
|
|
192
|
-
|
|
201
|
+
canonicalFiles: [
|
|
193
202
|
...new Set([
|
|
194
|
-
...hidden.files,
|
|
195
203
|
...CANONICAL_AGENT_SECRET_FILES.map((file) => path.join(agentDir, file)),
|
|
196
204
|
...CANONICAL_HOME_SECRET_FILES.map((file) => path.join(homedir(), file)),
|
|
197
205
|
...CANONICAL_HOME_SECRET_FILES.map((file) => path.join(CONTAINER_RUNTIME_HOME, file)),
|
|
198
206
|
]),
|
|
199
207
|
],
|
|
208
|
+
roleDirs: [...new Set(hidden.dirs)],
|
|
209
|
+
roleFiles: [...new Set(hidden.files)],
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function privateSurfacePathBlock(tool: string, candidate: string, hit: string): SecurityBlock {
|
|
214
|
+
return {
|
|
215
|
+
block: true,
|
|
216
|
+
reason: [
|
|
217
|
+
`Guard \`${GUARD_PRIVATE_SURFACE_READ}\` blocked ${tool}: argument \`${candidate}\` resolves to ${hit}, which is not available to LLM tools.`,
|
|
218
|
+
'The bash sandbox masks the same path. Privileged roles cannot bypass canonical agent credential files; use host-side redacted diagnostics such as `typeclaw doctor`, `typeclaw provider list`, or `typeclaw channel list` instead.',
|
|
219
|
+
].join(' '),
|
|
200
220
|
}
|
|
201
221
|
}
|
|
202
222
|
|
|
@@ -295,11 +315,37 @@ function trimmedFileUri(value: string): string | undefined {
|
|
|
295
315
|
// enforcement points agree — an id like `{ tenant: "memory" }` on a tool that
|
|
296
316
|
// declared `nonFile: ['tenant']` is not blocked here. Scoped by EXACT operand
|
|
297
317
|
// path (not key name), so an undeclared key still fails closed; `input`/
|
|
298
|
-
// `output`/`destructive` are
|
|
299
|
-
// that resolves under a hidden dir must still block).
|
|
300
|
-
|
|
318
|
+
// `output`/`create`/`destructive` are never exemptions — they FORCE a scan (a
|
|
319
|
+
// declared real-file path that resolves under a hidden dir must still block).
|
|
320
|
+
// `localOperands` holds the declared `input`/`output`/`create`/`destructive`
|
|
321
|
+
// operand PATHS. A string at one of those paths is ALWAYS scanned, overriding
|
|
322
|
+
// both the prose-key exemptions above and any `nonFile` claim on the same path.
|
|
323
|
+
// Without that override the two exemption layers compose into a bypass: a tool
|
|
324
|
+
// declaring a real local operand under a universally-free-text key (`query`,
|
|
325
|
+
// `content`, `text`, `name`, ...) would have its value skipped here as prose,
|
|
326
|
+
// then dereferenced downstream — so `{ input: ['query'], query: 'memory/x' }`
|
|
327
|
+
// would reach a hidden directory the role cannot see. Declaring a path as a
|
|
328
|
+
// local file is exactly the claim that it is NOT prose.
|
|
329
|
+
function collectLocalOperandPaths(operands: ToolFileOperands | undefined): ReadonlySet<string> | undefined {
|
|
330
|
+
if (operands === undefined) return undefined
|
|
331
|
+
const paths = new Set([
|
|
332
|
+
...(operands.input ?? []),
|
|
333
|
+
...(operands.output ?? []),
|
|
334
|
+
...(operands.create ?? []),
|
|
335
|
+
...(operands.destructive ?? []),
|
|
336
|
+
])
|
|
337
|
+
return paths.size === 0 ? undefined : paths
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function collectPathCandidates(
|
|
341
|
+
value: unknown,
|
|
342
|
+
tool: string,
|
|
343
|
+
nonFile?: ReadonlySet<string>,
|
|
344
|
+
localOperands?: ReadonlySet<string>,
|
|
345
|
+
disableExemptions = false,
|
|
346
|
+
): string[] {
|
|
301
347
|
const out: string[] = []
|
|
302
|
-
walk(value, out, tool, false, nonFile, '')
|
|
348
|
+
walk(value, out, tool, false, nonFile, localOperands, '', disableExemptions)
|
|
303
349
|
return out
|
|
304
350
|
}
|
|
305
351
|
|
|
@@ -309,27 +355,37 @@ function walk(
|
|
|
309
355
|
tool: string,
|
|
310
356
|
underExempt: boolean,
|
|
311
357
|
nonFile: ReadonlySet<string> | undefined,
|
|
358
|
+
localOperands: ReadonlySet<string> | undefined,
|
|
312
359
|
operandPath: string,
|
|
360
|
+
disableExemptions: boolean,
|
|
313
361
|
key?: string,
|
|
314
362
|
): void {
|
|
315
363
|
if (typeof value === 'string') {
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
|
|
364
|
+
if (!disableExemptions) {
|
|
365
|
+
const declaredLocal = localOperands?.has(operandPath) === true
|
|
366
|
+
if (!declaredLocal) {
|
|
367
|
+
if (nonFile?.has(operandPath) === true) return
|
|
368
|
+
const isFileUrl = trimmedFileUri(value) !== undefined
|
|
369
|
+
if (underExempt && !isPathKey(key) && !isFileUrl) return
|
|
370
|
+
}
|
|
371
|
+
}
|
|
319
372
|
const normalized = normalizeCandidate(value)
|
|
320
373
|
if (normalized !== undefined) out.push(normalized)
|
|
321
374
|
return
|
|
322
375
|
}
|
|
323
376
|
if (Array.isArray(value)) {
|
|
324
|
-
for (const item of value)
|
|
377
|
+
for (const item of value) {
|
|
378
|
+
walk(item, out, tool, underExempt, nonFile, localOperands, operandPath, disableExemptions, key)
|
|
379
|
+
}
|
|
325
380
|
return
|
|
326
381
|
}
|
|
327
382
|
if (value !== null && typeof value === 'object') {
|
|
328
383
|
const toolFreeText = FREE_TEXT_KEYS_BY_TOOL[tool]
|
|
329
384
|
for (const [childKey, item] of Object.entries(value)) {
|
|
330
|
-
|
|
385
|
+
if (disableExemptions && childKey === 'filename' && toolFreeText?.has(childKey) === true) continue
|
|
386
|
+
const keyIsExempt = !disableExemptions && (NON_PATH_KEYS.has(childKey) || (toolFreeText?.has(childKey) ?? false))
|
|
331
387
|
const childPath = operandPath === '' ? childKey : `${operandPath}.${childKey}`
|
|
332
|
-
walk(item, out, tool, underExempt || keyIsExempt, nonFile, childPath, childKey)
|
|
388
|
+
walk(item, out, tool, underExempt || keyIsExempt, nonFile, localOperands, childPath, disableExemptions, childKey)
|
|
333
389
|
}
|
|
334
390
|
}
|
|
335
391
|
}
|
|
@@ -60,7 +60,11 @@ import {
|
|
|
60
60
|
} from './discord-bot-classify'
|
|
61
61
|
import { createDiscordEditMessageCallback } from './discord-bot-edit'
|
|
62
62
|
import { convertDiscordTables } from './discord-bot-format'
|
|
63
|
-
import {
|
|
63
|
+
import {
|
|
64
|
+
createDiscordReactionCallback,
|
|
65
|
+
createDiscordRemoveReactionCallback,
|
|
66
|
+
encodeDiscordReactionRef,
|
|
67
|
+
} from './discord-bot-reactions'
|
|
64
68
|
import { enrichDiscordMessageReferences } from './discord-bot-reference'
|
|
65
69
|
import {
|
|
66
70
|
ackInteraction,
|
|
@@ -840,7 +844,12 @@ export function createOutboundCallback(deps: {
|
|
|
840
844
|
Object.keys(sendOptions).length > 0 ? sendOptions : undefined,
|
|
841
845
|
)
|
|
842
846
|
logger.info(`[discord-bot] sent id=${sent.id} ${tag}`)
|
|
843
|
-
return {
|
|
847
|
+
return {
|
|
848
|
+
ok: true,
|
|
849
|
+
messageId: sent.id,
|
|
850
|
+
messageIds: [sent.id],
|
|
851
|
+
reactionRef: encodeDiscordReactionRef({ channel: msg.chat, message: sent.id }),
|
|
852
|
+
}
|
|
844
853
|
} catch (err) {
|
|
845
854
|
const message = describeError(err)
|
|
846
855
|
logger.error(`[discord-bot] sendMessage failed: ${message}`)
|
|
@@ -108,6 +108,7 @@ export function createDiscordOutboundCallback(deps: {
|
|
|
108
108
|
await deps.client.sendMessage(msg.chat, chunk, replyOption(index === 0 ? replyTo : undefined))
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
+
// The user-account SDK send APIs return no posted-message id, so no reaction target ref is available.
|
|
111
112
|
return { ok: true }
|
|
112
113
|
} catch (err) {
|
|
113
114
|
const message = describeError(err)
|
|
@@ -56,7 +56,11 @@ import {
|
|
|
56
56
|
} from './slack-bot-classify'
|
|
57
57
|
import { createSlackDedupe } from './slack-bot-dedupe'
|
|
58
58
|
import { createSlackEditMessageCallback } from './slack-bot-edit'
|
|
59
|
-
import {
|
|
59
|
+
import {
|
|
60
|
+
createSlackReactionCallback,
|
|
61
|
+
createSlackRemoveReactionCallback,
|
|
62
|
+
encodeSlackReactionRef,
|
|
63
|
+
} from './slack-bot-reactions'
|
|
60
64
|
import { enrichSlackReferenceContext } from './slack-bot-reference'
|
|
61
65
|
import {
|
|
62
66
|
buildSlashAckPayload,
|
|
@@ -1006,7 +1010,12 @@ export function createOutboundCallback(deps: {
|
|
|
1006
1010
|
if (threadTs === null && chunks.length > 1) threadTs = sent.ts
|
|
1007
1011
|
}
|
|
1008
1012
|
if (typingTracker) await typingTracker.clearAfterSend(msg.chat, msg.typingThread ?? msg.thread)
|
|
1009
|
-
return {
|
|
1013
|
+
return {
|
|
1014
|
+
ok: true,
|
|
1015
|
+
messageId: sentTs[0],
|
|
1016
|
+
messageIds: sentTs,
|
|
1017
|
+
reactionRef: encodeSlackReactionRef({ channel: msg.chat, ts: sentTs[0]! }),
|
|
1018
|
+
}
|
|
1010
1019
|
} catch (err) {
|
|
1011
1020
|
const message = describeError(err)
|
|
1012
1021
|
logger.error(`[slack-bot] postMessage failed: ${message}`)
|
|
@@ -106,6 +106,7 @@ export function createSlackOutboundCallback(deps: {
|
|
|
106
106
|
const filename = attachment.filename ?? basename(path)
|
|
107
107
|
await deps.client.uploadFile([msg.chat], buffer, filename)
|
|
108
108
|
}
|
|
109
|
+
// The user-account SDK send APIs return no posted-message id, so no reaction target ref is available.
|
|
109
110
|
return { ok: true }
|
|
110
111
|
} catch (err) {
|
|
111
112
|
const message = describeError(err)
|