typeclaw 0.48.1 → 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/system-prompt.ts +8 -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/guard/policies/managed-config.ts +7 -20
- package/src/bundled-plugins/guard/policies/non-workspace-write.ts +7 -20
- package/src/bundled-plugins/guard/policies/skill-authoring.ts +8 -20
- package/src/bundled-plugins/memory/README.md +2 -0
- package/src/bundled-plugins/memory/dreaming.ts +2 -0
- package/src/bundled-plugins/security/policies/private-surface-read.ts +98 -55
- 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 +100 -20
- package/src/container/start.ts +42 -0
- package/src/init/models-dev.ts +25 -8
- package/src/mcp/client.ts +65 -7
- package/src/mcp/tools.ts +71 -4
- package/src/path-safety/real-intended-path.ts +111 -0
- 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/typeclaw.schema.json +5 -0
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,
|
|
@@ -67,6 +67,12 @@ When the user asks you to build, run, fix, or verify something, the deliverable
|
|
|
67
67
|
|
|
68
68
|
If a tool, install, or network call fails and blocks the real path, say so directly and try an alternative (different approach, different package, ask the user). Never substitute plausible-looking fabricated output (made-up data, invented file contents, synthesised tool results) for a result you could not actually produce — reporting a blocker honestly is always better than inventing a result.
|
|
69
69
|
|
|
70
|
+
A change is not done because it compiled. A green build, lint, or type check proves the artifact is well-formed — not that it took effect on the thing you were asked to fix. Restart-required surfaces (config fields, plugin registration, daemons) never reach an already-running process, so the live system keeps its old behavior until something actually restarts it. Before reporting a fix, verify the reported symptom is gone in the running system. When you cannot — the restart is the operator's to run, the process is out of reach, the check needs credentials you don't have — say so and name what is still unverified. "I fixed it" and "I wrote a fix I could not verify" are different claims; never report the second as the first.
|
|
71
|
+
|
|
72
|
+
Never say you performed an action you did not perform, and never promise one you cannot perform from where you run. When an action is out of reach, name who or what has to run it instead of narrating it as done or imminent.
|
|
73
|
+
|
|
74
|
+
Separate what a tool returned from why you think it happened. Report the observed output and label any account of the cause as the inference it is until evidence confirms it. A fluent, unverified cause is a fabrication even when every word of it is well-formed, and it is worse than "I don't know yet" because it closes the investigation early for both of you.
|
|
75
|
+
|
|
70
76
|
## Parallel tool calls
|
|
71
77
|
|
|
72
78
|
When you need several pieces of information that don't depend on each other, request them in a single response instead of one tool call per turn. Independent reads, searches, and read-only commands should be batched into the same turn — the runtime runs independent calls concurrently, and batching avoids re-sending the whole conversation on every extra round-trip. Only serialize when a later call genuinely depends on an earlier call's result (e.g. read a file before patching it).
|
|
@@ -313,6 +319,8 @@ Never echo secrets from \`secrets.json\` or \`.env\`, or any credential you see
|
|
|
313
319
|
|
|
314
320
|
Never suppress errors to make things "work", and never fabricate results. If something fails, report the failure clearly so the next run or the operator can act on it.
|
|
315
321
|
|
|
322
|
+
A green build or lint proves the artifact is well-formed, not that the change took effect — restart-required surfaces (config, plugins) never reach an already-running process. Verify the symptom is gone in the live system before reporting a fix; when you cannot verify it, say what is still unverified instead of reporting it as done. Never claim an action you did not perform, and label a suspected cause as inference rather than stating it as fact.
|
|
323
|
+
|
|
316
324
|
Do not narrate routine, low-risk tool calls — just call the tool. Do not over-explain what you did unless asked.
|
|
317
325
|
|
|
318
326
|
${PACKAGE_JSON_INSTALL_RULE}
|
|
@@ -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}` }],
|
|
@@ -3,6 +3,7 @@ import path from 'node:path'
|
|
|
3
3
|
|
|
4
4
|
import { parseConfigJson } from '@/config'
|
|
5
5
|
import { validateCronEdit } from '@/cron'
|
|
6
|
+
import { RECOVER_MISSING, realIntendedPath } from '@/path-safety/real-intended-path'
|
|
6
7
|
|
|
7
8
|
import type { GuardBlock } from '../policy'
|
|
8
9
|
|
|
@@ -161,25 +162,11 @@ function blockReason(tool: string, targetPath: string, reason: string): GuardBlo
|
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
164
|
|
|
165
|
+
// RECOVER_MISSING only: this policy decides whether a write is ALLOWED, so an
|
|
166
|
+
// ancestor that cannot be resolved must never widen the permitted surface.
|
|
164
167
|
async function resolveRealIntendedPath(absolutePath: string): Promise<string> {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
try {
|
|
170
|
-
const realCurrent = await realpath(current)
|
|
171
|
-
return path.join(realCurrent, ...pending.reverse())
|
|
172
|
-
} catch (err) {
|
|
173
|
-
if (!isNotFoundError(err)) throw err
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const parent = path.dirname(current)
|
|
177
|
-
if (parent === current) throw new Error(`could not resolve existing parent for ${absolutePath}`)
|
|
178
|
-
pending.push(path.basename(current))
|
|
179
|
-
current = parent
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function isNotFoundError(err: unknown): boolean {
|
|
184
|
-
return err instanceof Error && 'code' in err && err.code === 'ENOENT'
|
|
168
|
+
return await realIntendedPath(absolutePath, realpath, {
|
|
169
|
+
recoverable: RECOVER_MISSING,
|
|
170
|
+
onExhausted: 'throw',
|
|
171
|
+
})
|
|
185
172
|
}
|
|
@@ -2,6 +2,7 @@ import { realpath } from 'node:fs/promises'
|
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
|
|
4
4
|
import type { SessionOrigin } from '@/agent/session-origin'
|
|
5
|
+
import { RECOVER_MISSING, realIntendedPath } from '@/path-safety/real-intended-path'
|
|
5
6
|
|
|
6
7
|
import { ACKNOWLEDGE_GUARDS, type GuardBlock, isGuardAcknowledged } from '../policy'
|
|
7
8
|
import { isMemoryTopicsWriteAllowed } from './memory-topics-write'
|
|
@@ -132,25 +133,11 @@ function isInside(parent: string, child: string): boolean {
|
|
|
132
133
|
return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative))
|
|
133
134
|
}
|
|
134
135
|
|
|
136
|
+
// RECOVER_MISSING only: this policy decides whether a write is ALLOWED, so an
|
|
137
|
+
// ancestor that cannot be resolved must never widen the permitted surface.
|
|
135
138
|
async function resolveRealIntendedPath(absolutePath: string): Promise<string> {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
try {
|
|
141
|
-
const realCurrent = await realpath(current)
|
|
142
|
-
return path.join(realCurrent, ...pending.reverse())
|
|
143
|
-
} catch (err) {
|
|
144
|
-
if (!isNotFoundError(err)) throw err
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const parent = path.dirname(current)
|
|
148
|
-
if (parent === current) throw new Error(`could not resolve existing parent for ${absolutePath}`)
|
|
149
|
-
pending.push(path.basename(current))
|
|
150
|
-
current = parent
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function isNotFoundError(err: unknown): boolean {
|
|
155
|
-
return err instanceof Error && 'code' in err && err.code === 'ENOENT'
|
|
139
|
+
return await realIntendedPath(absolutePath, realpath, {
|
|
140
|
+
recoverable: RECOVER_MISSING,
|
|
141
|
+
onExhausted: 'throw',
|
|
142
|
+
})
|
|
156
143
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { readFile, realpath } from 'node:fs/promises'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
|
|
4
|
+
import { RECOVER_MISSING, realIntendedPath } from '@/path-safety/real-intended-path'
|
|
5
|
+
|
|
4
6
|
import type { GuardBlock } from '../policy'
|
|
5
7
|
|
|
6
8
|
export const GUARD_SKILL_AUTHORING = 'skillAuthoring'
|
|
@@ -161,25 +163,11 @@ function isInside(parent: string, child: string): boolean {
|
|
|
161
163
|
return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative))
|
|
162
164
|
}
|
|
163
165
|
|
|
166
|
+
// RECOVER_MISSING only: this policy decides whether a write is ALLOWED, so an
|
|
167
|
+
// ancestor that cannot be resolved must never widen the permitted surface.
|
|
164
168
|
async function resolveRealIntendedPath(absolutePath: string): Promise<string> {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
try {
|
|
170
|
-
const realCurrent = await realpath(current)
|
|
171
|
-
return path.join(realCurrent, ...pending.reverse())
|
|
172
|
-
} catch (err) {
|
|
173
|
-
if (!isNotFoundError(err)) throw err
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const parent = path.dirname(current)
|
|
177
|
-
if (parent === current) throw new Error(`could not resolve existing parent for ${absolutePath}`)
|
|
178
|
-
pending.push(path.basename(current))
|
|
179
|
-
current = parent
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function isNotFoundError(err: unknown): boolean {
|
|
184
|
-
return err instanceof Error && 'code' in err && err.code === 'ENOENT'
|
|
169
|
+
return await realIntendedPath(absolutePath, realpath, {
|
|
170
|
+
recoverable: RECOVER_MISSING,
|
|
171
|
+
onExhausted: 'throw',
|
|
172
|
+
})
|
|
185
173
|
}
|
|
@@ -111,6 +111,8 @@ The subagent uses these signals to:
|
|
|
111
111
|
|
|
112
112
|
There is no `## Historical observations` bucket. Demoted topics live as their own shards; injection-time filtering (the index/direct split) handles the prompt-budget pressure.
|
|
113
113
|
|
|
114
|
+
**The agent's own response style never becomes a belief (rule 10).** Streams capture the agent's own turns, so fragments sometimes describe how it replied rather than what is true — how it apologized, how it took a correction, how terse its status updates were. Consolidating those teaches the next session to reproduce a shape instead of doing the work; a shard describing a convincing apology is the worst case, because it makes accountability a template the agent can perform without having verified anything. The user-side fact is kept ("the user wants status updates under 20 words"), the agent-side self-description dropped. Voice and register belong in `SOUL.md`, which the subagent never writes.
|
|
115
|
+
|
|
114
116
|
## Muscle memory (three forms)
|
|
115
117
|
|
|
116
118
|
While reading streams, the dreaming subagent watches for **repeated multi-step procedures** the user has guided the main agent through, and codifies them. There are three forms, picked smallest-that-fits (top to bottom, stop at the first match):
|
|
@@ -997,6 +997,8 @@ references:
|
|
|
997
997
|
|
|
998
998
|
The reference files under \`memory/references/\` are verbatim artifacts. You MUST NOT read, rewrite, or distill their content. You may only cite them by slug. On eviction (Phase 4), citations are pruned — but that is a separate pass, not your concern here.
|
|
999
999
|
|
|
1000
|
+
**10. Never turn the main agent's own response style into a belief.** Streams often contain fragments describing how the main agent phrased, structured, or paced its own reply — how it apologized, how it took a correction, how long its status updates ran. A durable fact about the USER is memory; a description of how the agent's own reply *sounded* is not. Consolidating one teaches the next session to reproduce a shape instead of doing the work, and a shard describing a convincing apology is the worst case: it turns accountability into a template the agent can perform without having verified anything, which is exactly the behavior that produces false "I fixed it" claims. Keep the user-side fact ("the user wants status updates under 20 words", "the user corrected the summary language to Korean") and drop the agent-side self-description ("the agent replied with an apology, a root cause, and a fix in under 70 words"). When a fragment carries both, keep only the user-side half. Voice and register live in \`SOUL.md\`, which the user owns and you never write.
|
|
1001
|
+
|
|
1000
1002
|
# What a topic shard looks like
|
|
1001
1003
|
|
|
1002
1004
|
\`\`\`
|