@ethosagent/core 0.2.0 → 0.2.2
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/dist/index.js +94 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
package/dist/index.js
CHANGED
|
@@ -1,7 +1,100 @@
|
|
|
1
1
|
// src/agent-loop.ts
|
|
2
2
|
import { homedir } from "os";
|
|
3
3
|
import { join } from "path";
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
// ../storage-fs/src/fs-storage.ts
|
|
6
|
+
import {
|
|
7
|
+
appendFile,
|
|
8
|
+
mkdir,
|
|
9
|
+
readdir,
|
|
10
|
+
readFile,
|
|
11
|
+
rename,
|
|
12
|
+
rm,
|
|
13
|
+
stat,
|
|
14
|
+
writeFile
|
|
15
|
+
} from "fs/promises";
|
|
16
|
+
|
|
17
|
+
// ../storage-fs/src/in-memory-storage.ts
|
|
18
|
+
import { dirname } from "path";
|
|
19
|
+
|
|
20
|
+
// ../storage-fs/src/scoped-storage.ts
|
|
21
|
+
import {
|
|
22
|
+
BoundaryError
|
|
23
|
+
} from "@ethosagent/types";
|
|
24
|
+
var ScopedStorage = class {
|
|
25
|
+
constructor(inner, scope) {
|
|
26
|
+
this.inner = inner;
|
|
27
|
+
this.readPrefixes = scope.read.map(normalizePrefix);
|
|
28
|
+
this.writePrefixes = scope.write.map(normalizePrefix);
|
|
29
|
+
}
|
|
30
|
+
inner;
|
|
31
|
+
readPrefixes;
|
|
32
|
+
writePrefixes;
|
|
33
|
+
check(path, kind) {
|
|
34
|
+
const allowed = kind === "read" ? this.readPrefixes : this.writePrefixes;
|
|
35
|
+
if (!isPathAllowed(path, allowed)) {
|
|
36
|
+
throw new BoundaryError(kind, path, allowed);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async read(path) {
|
|
40
|
+
this.check(path, "read");
|
|
41
|
+
return this.inner.read(path);
|
|
42
|
+
}
|
|
43
|
+
async exists(path) {
|
|
44
|
+
this.check(path, "read");
|
|
45
|
+
return this.inner.exists(path);
|
|
46
|
+
}
|
|
47
|
+
async mtime(path) {
|
|
48
|
+
this.check(path, "read");
|
|
49
|
+
return this.inner.mtime(path);
|
|
50
|
+
}
|
|
51
|
+
async list(dir) {
|
|
52
|
+
this.check(dir, "read");
|
|
53
|
+
return this.inner.list(dir);
|
|
54
|
+
}
|
|
55
|
+
async listEntries(dir) {
|
|
56
|
+
this.check(dir, "read");
|
|
57
|
+
return this.inner.listEntries(dir);
|
|
58
|
+
}
|
|
59
|
+
async write(path, content, opts) {
|
|
60
|
+
this.check(path, "write");
|
|
61
|
+
return this.inner.write(path, content, opts);
|
|
62
|
+
}
|
|
63
|
+
async append(path, content) {
|
|
64
|
+
this.check(path, "write");
|
|
65
|
+
return this.inner.append(path, content);
|
|
66
|
+
}
|
|
67
|
+
async writeAtomic(path, content, opts) {
|
|
68
|
+
this.check(path, "write");
|
|
69
|
+
return this.inner.writeAtomic(path, content, opts);
|
|
70
|
+
}
|
|
71
|
+
async mkdir(dir) {
|
|
72
|
+
this.check(dir, "write");
|
|
73
|
+
return this.inner.mkdir(dir);
|
|
74
|
+
}
|
|
75
|
+
async remove(path, opts) {
|
|
76
|
+
this.check(path, "write");
|
|
77
|
+
return this.inner.remove(path, opts);
|
|
78
|
+
}
|
|
79
|
+
async rename(from, to) {
|
|
80
|
+
this.check(from, "write");
|
|
81
|
+
this.check(to, "write");
|
|
82
|
+
return this.inner.rename(from, to);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function normalizePrefix(prefix) {
|
|
86
|
+
return prefix;
|
|
87
|
+
}
|
|
88
|
+
function isPathAllowed(path, prefixes) {
|
|
89
|
+
for (const prefix of prefixes) {
|
|
90
|
+
if (path === prefix) return true;
|
|
91
|
+
const withoutSlash = prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
92
|
+
if (path === withoutSlash) return true;
|
|
93
|
+
const withSlash = `${withoutSlash}/`;
|
|
94
|
+
if (path.startsWith(withSlash)) return true;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
5
98
|
|
|
6
99
|
// src/defaults/in-memory-session.ts
|
|
7
100
|
var InMemorySessionStore = class {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/agent-loop.ts","../src/defaults/in-memory-session.ts","../src/defaults/noop-memory.ts","../src/defaults/noop-personality.ts","../src/hook-registry.ts","../src/tool-registry.ts","../src/plugin-registry.ts"],"sourcesContent":["import { homedir } from 'node:os';\nimport { join } from 'node:path';\nimport { ScopedStorage } from '@ethosagent/storage-fs';\nimport type {\n CompletionChunk,\n ContextInjector,\n HookRegistry,\n LLMProvider,\n MemoryProvider,\n Message,\n MessageContent,\n PersonalityConfig,\n PersonalityRegistry,\n PromptContext,\n SessionStore,\n Storage,\n StoredMessage,\n ToolFilterOpts,\n ToolRegistry,\n ToolResult,\n} from '@ethosagent/types';\n\nimport { InMemorySessionStore } from './defaults/in-memory-session';\nimport { NoopMemoryProvider } from './defaults/noop-memory';\nimport { DefaultPersonalityRegistry } from './defaults/noop-personality';\nimport { DefaultHookRegistry } from './hook-registry';\nimport { DefaultToolRegistry } from './tool-registry';\n\n// ---------------------------------------------------------------------------\n// Agent events emitted by run()\n// ---------------------------------------------------------------------------\n\nexport type AgentEvent =\n | { type: 'text_delta'; text: string }\n | { type: 'thinking_delta'; thinking: string }\n | { type: 'tool_start'; toolCallId: string; toolName: string; args: unknown }\n // Phase 30.2 — `audience` gates whether channel adapters / chat.ts surface\n // this event to the user. Default is `'internal'`; tools opt in to `'user'`\n // per event. Framework-emitted budget warnings are `'user'` (see step 7).\n | {\n type: 'tool_progress';\n toolName: string;\n message: string;\n percent?: number;\n audience: 'internal' | 'user';\n }\n | {\n type: 'tool_end';\n toolCallId: string;\n toolName: string;\n ok: boolean;\n durationMs: number;\n // Phase 30.2 — same boundary applies to tool_end success rendering.\n // Failures (`ok: false`) ignore the field and always render.\n audience?: 'internal' | 'user';\n /**\n * Tool output body — the success value when `ok`, or the error\n * message when `ok: false`. Optional so consumers that only care\n * about the status (CLI ASCII chips, telemetry) can ignore it.\n * The web chip surfaces this on expand-on-click without a\n * follow-up history fetch.\n */\n result?: string;\n }\n | { type: 'usage'; inputTokens: number; outputTokens: number; estimatedCostUsd: number }\n | { type: 'error'; error: string; code: string }\n | { type: 'done'; text: string; turnCount: number }\n // Emitted once after context injectors run; carries any metadata they wrote to PromptContext.meta.\n | { type: 'context_meta'; data: Record<string, unknown> };\n\n// ---------------------------------------------------------------------------\n// Config\n// ---------------------------------------------------------------------------\n\nexport interface AgentLoopConfig {\n llm: LLMProvider;\n tools?: ToolRegistry;\n personalities?: PersonalityRegistry;\n memory?: MemoryProvider;\n session?: SessionStore;\n hooks?: HookRegistry;\n injectors?: ContextInjector[];\n /**\n * Maps each plugin-registered injector to its plugin id so AgentLoop can\n * gate injectors by personality. Built-in injectors are absent (always fire).\n * Populated by PluginApiImpl.registerInjector(); passed through from wiring.\n */\n injectorPluginIds?: Map<ContextInjector, string>;\n /**\n * Base Storage instance handed to tools via `ToolContext.storage` after\n * being decorated with a ScopedStorage that enforces the active\n * personality's `fs_reach` allowlist. When unset, ToolContext.storage is\n * left undefined and tools fall back to unrestricted node:fs (legacy\n * behavior — existing CLI/TUI tests don't need a storage instance).\n */\n storage?: Storage;\n /**\n * Absolute path to ~/.ethos/ used for `${ETHOS_HOME}` substitution in\n * `fs_reach` paths. Defaults to `${HOME}/.ethos`. Required only when\n * `storage` is set.\n */\n dataDir?: string;\n // Maps personality ID → model ID. Resolution: modelRouting[id] → personality.model → llm.model\n modelRouting?: Record<string, string>;\n options?: {\n maxIterations?: number;\n historyLimit?: number;\n platform?: string;\n workingDir?: string;\n resultBudgetChars?: number;\n /**\n * Hard cap on total tool calls per user turn (across all LLM iterations).\n * Defaults to 20. Trips a `tool_progress` warning and exits cleanly.\n * See plan/IMPROVEMENT.md P1-3.\n */\n maxToolCallsPerTurn?: number;\n /**\n * Hard cap on the number of times the same tool name can be invoked in a\n * single turn. Catches the \"infinite loop on a single tool\" failure mode\n * (e.g. tts loop reported as OpenClaw #67744). Defaults to 5.\n */\n maxIdenticalToolCalls?: number;\n /**\n * Default streaming watchdog in milliseconds. If no chunk arrives from the\n * LLM within this window, the agent aborts the stream and emits an error.\n * Reset on every chunk. Personalities can override via\n * `personality.streamingTimeoutMs`. Defaults to 120000 (2 minutes).\n */\n streamingTimeoutMs?: number;\n };\n}\n\nexport interface RunOptions {\n sessionKey?: string;\n personalityId?: string;\n abortSignal?: AbortSignal;\n /**\n * Identifier surfaced to tools as `ToolContext.agentId`. Delegation tools\n * use this to thread spawn depth (`depth:N`) into child loops so\n * `MAX_SPAWN_DEPTH` can be enforced across recursive sub-agent calls.\n */\n agentId?: string;\n}\n\n// ---------------------------------------------------------------------------\n// AgentLoop\n// ---------------------------------------------------------------------------\n\nexport class AgentLoop {\n private readonly llm: LLMProvider;\n private readonly tools: ToolRegistry;\n private readonly personalities: PersonalityRegistry;\n private readonly memory: MemoryProvider;\n private readonly session: SessionStore;\n /** Public so surfaces (web, ACP) can register late-binding hooks they own\n * without re-running the whole wiring factory. The CLI/TUI register hooks\n * before construction; web registers an approval hook after createAgentLoop\n * returns. */\n readonly hooks: HookRegistry;\n private readonly injectors: ContextInjector[];\n private readonly injectorPluginIds: Map<ContextInjector, string>;\n private readonly maxIterations: number;\n private readonly historyLimit: number;\n private readonly platform: string;\n private readonly workingDir: string;\n private readonly resultBudgetChars: number;\n private readonly maxToolCallsPerTurn: number;\n private readonly maxIdenticalToolCalls: number;\n private readonly streamingTimeoutMs: number;\n private readonly modelRouting: Record<string, string>;\n private readonly storage?: Storage;\n private readonly dataDir?: string;\n\n constructor(config: AgentLoopConfig) {\n this.llm = config.llm;\n this.tools = config.tools ?? new DefaultToolRegistry();\n this.personalities = config.personalities ?? new DefaultPersonalityRegistry();\n this.memory = config.memory ?? new NoopMemoryProvider();\n this.session = config.session ?? new InMemorySessionStore();\n this.hooks = config.hooks ?? new DefaultHookRegistry();\n this.injectors = (config.injectors ?? []).sort((a, b) => b.priority - a.priority);\n this.injectorPluginIds = config.injectorPluginIds ?? new Map();\n this.maxIterations = config.options?.maxIterations ?? 50;\n this.historyLimit = config.options?.historyLimit ?? 200;\n this.platform = config.options?.platform ?? 'cli';\n this.workingDir = config.options?.workingDir ?? process.cwd();\n this.resultBudgetChars = config.options?.resultBudgetChars ?? 80_000;\n this.maxToolCallsPerTurn = config.options?.maxToolCallsPerTurn ?? 20;\n this.maxIdenticalToolCalls = config.options?.maxIdenticalToolCalls ?? 5;\n this.streamingTimeoutMs = config.options?.streamingTimeoutMs ?? 120_000;\n this.modelRouting = config.modelRouting ?? {};\n if (config.storage) this.storage = config.storage;\n if (config.dataDir) this.dataDir = config.dataDir;\n }\n\n async *run(text: string, opts: RunOptions = {}): AsyncGenerator<AgentEvent> {\n const abortSignal = opts.abortSignal ?? new AbortController().signal;\n const sessionKey = opts.sessionKey ?? `${this.platform}:default`;\n\n // Step 1: Resolve or create session\n const ethosSession =\n (await this.session.getSessionByKey(sessionKey)) ??\n (await this.session.createSession({\n key: sessionKey,\n platform: this.platform,\n model: this.llm.model,\n provider: this.llm.name,\n personalityId: opts.personalityId,\n workingDir: this.workingDir,\n usage: {\n inputTokens: 0,\n outputTokens: 0,\n cacheReadTokens: 0,\n cacheCreationTokens: 0,\n estimatedCostUsd: 0,\n apiCallCount: 0,\n compactionCount: 0,\n },\n }));\n\n const sessionId = ethosSession.id;\n const personality =\n (opts.personalityId ? this.personalities.get(opts.personalityId) : null) ??\n this.personalities.getDefault();\n\n // Resolve effective model: explicit per-personality routing > LLM base model.\n // personality.model is intentionally skipped — those IDs are Anthropic-specific\n // and break non-Anthropic providers (OpenRouter, Gemini, Ollama, etc.).\n // Configure overrides via modelRouting in ~/.ethos/config.yaml instead.\n const effectiveModel = this.modelRouting[personality.id] ?? this.llm.model;\n const modelOverride = effectiveModel !== this.llm.model ? effectiveModel : undefined;\n // Allowed tool names for this personality (undefined = no restriction)\n const allowedTools = personality.toolset?.length ? personality.toolset : undefined;\n // Per-personality plugin + MCP gate (default-deny: missing field = no access)\n const allowedPlugins = personality.plugins ?? [];\n const filterOpts: ToolFilterOpts = {\n allowedMcpServers: personality.mcp_servers,\n allowedPlugins,\n };\n\n // Step 2: Fire session_start hooks\n await this.hooks.fireVoid(\n 'session_start',\n {\n sessionId,\n sessionKey,\n platform: this.platform,\n personalityId: personality.id,\n },\n allowedPlugins,\n );\n\n // Step 3: Persist the user message.\n //\n // Subagent task contract: the delegated task always lives in the child's\n // first user message (this `text`). It is NEVER copied into the system\n // prompt, NEVER injected via memory, and NEVER duplicated across both.\n // The regression test in\n // `extensions/tools-delegation/src/__tests__/task-contract.test.ts`\n // captures every `LLMProvider.complete()` request and asserts the marker\n // never appears in `opts.system` and appears exactly once across all\n // user-role messages.\n await this.session.appendMessage({\n sessionId,\n role: 'user',\n content: text,\n });\n\n // Step 4: Load history (trimmed to most-recent limit)\n const allMessages = await this.session.getMessages(sessionId, { limit: this.historyLimit });\n const history = allMessages.filter((m) => m.role !== 'system');\n\n // Step 5: Prefetch memory\n const memCtx = await this.memory.prefetch({\n sessionId,\n sessionKey,\n platform: this.platform,\n workingDir: this.workingDir,\n personalityId: personality.id,\n memoryScope: personality.memoryScope,\n query: text,\n });\n\n // Step 6: Build system prompt from injectors\n const promptCtx: PromptContext = {\n sessionId,\n sessionKey,\n platform: this.platform,\n model: this.llm.model,\n history,\n workingDir: this.workingDir,\n isDm: true,\n turnNumber: allMessages.length,\n personalityId: personality.id,\n };\n\n const systemParts: string[] = [];\n\n // ETHOS.md / personality identity — routes through Storage so ScopedStorage\n // and InMemoryStorage fixtures work correctly. Only runs when storage is\n // wired (production always provides it; tests without a real ethosFile skip).\n if (personality.ethosFile && this.storage) {\n const identity = await this.storage.read(personality.ethosFile);\n if (identity) systemParts.push(identity.trim());\n }\n\n // Context injectors sorted by priority (already sorted in constructor)\n for (const injector of this.injectors) {\n // Plugin-registered injectors only fire when the plugin is permitted.\n const injPluginId = this.injectorPluginIds.get(injector);\n if (injPluginId !== undefined && !allowedPlugins.includes(injPluginId)) continue;\n if (injector.shouldInject && !injector.shouldInject(promptCtx)) continue;\n const result = await injector.inject(promptCtx);\n if (result) {\n if (result.position === 'prepend') {\n systemParts.unshift(result.content);\n } else {\n systemParts.push(result.content);\n }\n }\n }\n\n // Emit injector metadata (e.g. skill_files_used) so eval harness can capture it.\n if (promptCtx.meta && Object.keys(promptCtx.meta).length > 0) {\n yield { type: 'context_meta', data: promptCtx.meta };\n }\n\n // Memory injected last, as context about the user\n if (memCtx) {\n systemParts.push(`## Memory\\n\\n${memCtx.content}`);\n }\n\n // Step 7: Before-prompt-build modifying hooks (plugins can prepend/append/override)\n const buildResult = await this.hooks.fireModifying(\n 'before_prompt_build',\n {\n sessionId,\n personalityId: personality.id,\n history,\n },\n allowedPlugins,\n );\n\n if (buildResult.overrideSystem) {\n systemParts.length = 0;\n systemParts.push(buildResult.overrideSystem);\n } else {\n if (buildResult.prependSystem) systemParts.unshift(buildResult.prependSystem);\n if (buildResult.appendSystem) systemParts.push(buildResult.appendSystem);\n }\n\n const systemPrompt = systemParts.join('\\n\\n').trim() || undefined;\n\n // Step 8: Agentic loop — LLM call → tool use → LLM call → ...\n const llmMessages = this.toLLMMessages(history);\n let fullText = '';\n let turnCount = 0;\n\n // Tool-call budget tracking — prevents runaway loops (see IMPROVEMENT.md P1-3).\n // Counted across all iterations within a single user turn.\n let totalToolCalls = 0;\n const toolNameCounts = new Map<string, number>();\n\n for (let iteration = 0; iteration < this.maxIterations; iteration++) {\n if (abortSignal.aborted) {\n yield { type: 'error', error: 'Aborted', code: 'aborted' };\n return;\n }\n\n // Budget guard: bail before the next LLM call if we've already exceeded\n // either the total tool-call budget or the per-tool repeat budget. The\n // previous iteration's tool_result is in llmMessages, so the LLM history\n // stays valid; we just refuse to call again.\n if (totalToolCalls >= this.maxToolCallsPerTurn) {\n yield {\n type: 'tool_progress',\n toolName: '_budget',\n message: `Stopped: hit ${this.maxToolCallsPerTurn}-tool-call budget for this turn`,\n audience: 'user',\n };\n break;\n }\n const overusedTool = [...toolNameCounts.entries()].find(\n ([, count]) => count >= this.maxIdenticalToolCalls,\n );\n if (overusedTool) {\n yield {\n type: 'tool_progress',\n toolName: overusedTool[0],\n message: `Stopped: ${overusedTool[0]} called ${overusedTool[1]} times in one turn (likely loop)`,\n audience: 'user',\n };\n break;\n }\n\n // Fire before_llm_call\n await this.hooks.fireVoid(\n 'before_llm_call',\n {\n sessionId,\n model: this.llm.model,\n turnNumber: turnCount,\n },\n allowedPlugins,\n );\n\n // Stream LLM response\n const pendingToolCalls: Array<{\n toolCallId: string;\n toolName: string;\n partialJson: string;\n args?: unknown;\n }> = [];\n let chunkText = '';\n\n // Streaming watchdog: cancel the stream if no chunk arrives within the\n // per-personality window. Reset every chunk so slow-but-progressing\n // reasoning is unaffected. See IMPROVEMENT.md P1-2 / OpenClaw #68596.\n const watchdogMs = personality.streamingTimeoutMs ?? this.streamingTimeoutMs;\n const watchdogController = new AbortController();\n const combinedSignal = AbortSignal.any([abortSignal, watchdogController.signal]);\n let watchdogTimer: ReturnType<typeof setTimeout> | undefined;\n const armWatchdog = () => {\n if (watchdogTimer) clearTimeout(watchdogTimer);\n watchdogTimer = setTimeout(() => watchdogController.abort(), watchdogMs);\n };\n const disarmWatchdog = () => {\n if (watchdogTimer) clearTimeout(watchdogTimer);\n watchdogTimer = undefined;\n };\n\n try {\n armWatchdog();\n const stream = this.llm.complete(llmMessages, this.tools.toDefinitions(allowedTools, filterOpts), {\n system: systemPrompt,\n cacheSystemPrompt: true,\n abortSignal: combinedSignal,\n ...(modelOverride ? { modelOverride } : {}),\n });\n\n for await (const chunk of stream) {\n if (abortSignal.aborted) break;\n if (watchdogController.signal.aborted) break;\n armWatchdog();\n yield* this.handleChunk(chunk, pendingToolCalls, (t) => {\n chunkText += t;\n fullText += t;\n });\n }\n disarmWatchdog();\n\n if (watchdogController.signal.aborted && !abortSignal.aborted) {\n yield {\n type: 'error',\n error: `LLM stream stalled — no chunk for ${watchdogMs}ms`,\n code: 'streaming_timeout',\n };\n return;\n }\n } catch (err) {\n disarmWatchdog();\n if (watchdogController.signal.aborted && !abortSignal.aborted) {\n yield {\n type: 'error',\n error: `LLM stream stalled — no chunk for ${watchdogMs}ms`,\n code: 'streaming_timeout',\n };\n return;\n }\n const msg = err instanceof Error ? err.message : String(err);\n yield { type: 'error', error: msg, code: 'llm_error' };\n return;\n }\n\n turnCount++;\n\n // Determine which tool calls completed parsing\n const completedToolCalls = pendingToolCalls.filter((tc) => tc.args !== undefined);\n\n // Update budget counters — these gate the NEXT iteration's LLM call.\n totalToolCalls += completedToolCalls.length;\n for (const tc of completedToolCalls) {\n toolNameCounts.set(tc.toolName, (toolNameCounts.get(tc.toolName) ?? 0) + 1);\n }\n\n // Persist assistant message — include tool_use references so history is LLM-replayable\n await this.session.appendMessage({\n sessionId,\n role: 'assistant',\n content: chunkText,\n ...(completedToolCalls.length > 0 && {\n toolCalls: completedToolCalls.map((tc) => ({\n id: tc.toolCallId,\n name: tc.toolName,\n input: tc.args,\n })),\n }),\n });\n\n // Fire after_llm_call\n await this.hooks.fireVoid(\n 'after_llm_call',\n {\n sessionId,\n text: chunkText,\n usage: { inputTokens: 0, outputTokens: 0 },\n },\n allowedPlugins,\n );\n\n // Push assistant message with proper content blocks for next iteration\n if (completedToolCalls.length > 0) {\n const assistantContent: MessageContent[] = [];\n if (chunkText) assistantContent.push({ type: 'text', text: chunkText });\n for (const tc of completedToolCalls) {\n assistantContent.push({\n type: 'tool_use',\n id: tc.toolCallId,\n name: tc.toolName,\n input: tc.args,\n });\n }\n llmMessages.push({ role: 'assistant', content: assistantContent });\n } else {\n llmMessages.push({ role: 'assistant', content: chunkText });\n break;\n }\n\n // Step 9: Pre-flight hooks → execute non-rejected tools → collect all results\n\n // Phase 30.2 — tools call ctx.emit() during execution; AsyncGenerator can't\n // yield from a sync callback, so we buffer per-batch then drain after\n // executeParallel resolves. Order is preserved (insertion = call order).\n const progressBuffer: Array<{\n toolName: string;\n message: string;\n percent?: number;\n audience: 'internal' | 'user';\n }> = [];\n\n const scopedStorage = this.buildScopedStorage(personality);\n\n const toolCtxBase = {\n sessionId,\n sessionKey,\n platform: this.platform,\n workingDir: this.workingDir,\n agentId: opts.agentId,\n personalityId: personality.id,\n memoryScope: personality.memoryScope,\n currentTurn: turnCount,\n messageCount: allMessages.length + turnCount,\n abortSignal,\n emit: (event: {\n type: 'progress';\n toolName: string;\n message: string;\n percent?: number;\n audience?: 'internal' | 'user';\n }) => {\n progressBuffer.push({\n toolName: event.toolName,\n message: event.message,\n ...(event.percent !== undefined && { percent: event.percent }),\n audience: event.audience ?? 'internal',\n });\n },\n resultBudgetChars: this.resultBudgetChars,\n ...(scopedStorage ? { storage: scopedStorage } : {}),\n };\n\n // Run before_tool_call hooks; build exec list with effective args\n // Rejected tools get tool_end ok:false + an error tool_result sent back to LLM\n type Prepped = { toolCallId: string; name: string; args: unknown; rejected?: string };\n const prepped: Prepped[] = [];\n\n for (const tc of completedToolCalls) {\n const beforeResult = await this.hooks.fireModifying(\n 'before_tool_call',\n {\n sessionId,\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n args: tc.args,\n },\n allowedPlugins,\n );\n\n if (beforeResult.error) {\n yield {\n type: 'tool_end',\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n ok: false,\n durationMs: 0,\n result: beforeResult.error,\n };\n prepped.push({\n toolCallId: tc.toolCallId,\n name: tc.toolName,\n args: tc.args,\n rejected: beforeResult.error,\n });\n continue;\n }\n\n const effectiveArgs = beforeResult.args ?? tc.args;\n yield {\n type: 'tool_start',\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n args: effectiveArgs,\n };\n prepped.push({ toolCallId: tc.toolCallId, name: tc.toolName, args: effectiveArgs });\n }\n\n // Execute only non-rejected tools; results keyed by toolCallId\n const execInputs = prepped\n .filter((p) => p.rejected === undefined)\n .map((p) => ({ toolCallId: p.toolCallId, name: p.name, args: p.args }));\n\n const startedAt = Date.now();\n const execResults =\n execInputs.length > 0\n ? await this.tools.executeParallel(execInputs, toolCtxBase, allowedTools, filterOpts)\n : [];\n const execResultMap = new Map(execResults.map((r) => [r.toolCallId, r]));\n\n // Drain any progress events tools emitted during execution. Order is\n // call-order (across the parallel batch) — close enough for users; the\n // exact interleaving doesn't matter when ctx.emit is best-effort.\n for (const ev of progressBuffer) {\n yield { type: 'tool_progress', ...ev };\n }\n progressBuffer.length = 0;\n\n // Persist results + emit tool_end + build tool_result content blocks (original order)\n const toolResultContent: MessageContent[] = [];\n\n for (const p of prepped) {\n const durationMs = Date.now() - startedAt;\n let result: ToolResult;\n\n if (p.rejected !== undefined) {\n result = { ok: false, error: p.rejected, code: 'execution_failed' };\n // tool_end already emitted above; no after_tool_call hook for blocked tools\n } else {\n const execResult = execResultMap.get(p.toolCallId);\n result = execResult?.result ?? {\n ok: false,\n error: 'Tool result missing',\n code: 'execution_failed',\n };\n yield {\n type: 'tool_end',\n toolCallId: p.toolCallId,\n toolName: p.name,\n ok: result.ok,\n durationMs,\n result: result.ok ? result.value : result.error,\n };\n await this.hooks.fireVoid(\n 'after_tool_call',\n {\n sessionId,\n toolName: p.name,\n result,\n durationMs,\n },\n allowedPlugins,\n );\n }\n\n // Persist every result (rejected or not) so history matches what LLM sees\n await this.session.appendMessage({\n sessionId,\n role: 'tool_result',\n content: result.ok ? result.value : result.error,\n toolCallId: p.toolCallId,\n toolName: p.name,\n });\n\n toolResultContent.push({\n type: 'tool_result',\n tool_use_id: p.toolCallId,\n content: result.ok ? result.value : result.error,\n is_error: !result.ok,\n });\n }\n\n // Feed all tool results back to LLM as a single user message with content blocks\n llmMessages.push({ role: 'user', content: toolResultContent });\n }\n\n // Step 10: Memory writes flow through the `memory_save` tool during the\n // turn (see extensions/tools-memory). The agent-loop itself produces no\n // updates, so there's nothing to sync here.\n\n // Step 11: Update usage\n await this.session.updateUsage(sessionId, { apiCallCount: turnCount });\n\n // Step 12: Fire agent_done\n await this.hooks.fireVoid('agent_done', { sessionId, text: fullText, turnCount }, allowedPlugins);\n\n yield { type: 'done', text: fullText, turnCount };\n }\n\n private *handleChunk(\n chunk: CompletionChunk,\n pendingToolCalls: Array<{\n toolCallId: string;\n toolName: string;\n partialJson: string;\n args?: unknown;\n }>,\n onText: (t: string) => void,\n ): Generator<AgentEvent> {\n switch (chunk.type) {\n case 'text_delta':\n onText(chunk.text);\n yield { type: 'text_delta', text: chunk.text };\n break;\n\n case 'thinking_delta':\n yield { type: 'thinking_delta', thinking: chunk.thinking };\n break;\n\n case 'tool_use_start':\n pendingToolCalls.push({\n toolCallId: chunk.toolCallId,\n toolName: chunk.toolName,\n partialJson: '',\n });\n break;\n\n case 'tool_use_delta': {\n const tc = pendingToolCalls.find((t) => t.toolCallId === chunk.toolCallId);\n if (tc) tc.partialJson += chunk.partialJson;\n break;\n }\n\n case 'tool_use_end': {\n const tc = pendingToolCalls.find((t) => t.toolCallId === chunk.toolCallId);\n if (tc) {\n try {\n tc.args = JSON.parse(chunk.inputJson || tc.partialJson);\n } catch {\n tc.args = {};\n }\n }\n break;\n }\n\n case 'usage':\n yield {\n type: 'usage',\n inputTokens: chunk.usage.inputTokens,\n outputTokens: chunk.usage.outputTokens,\n estimatedCostUsd: chunk.usage.estimatedCostUsd,\n };\n break;\n\n case 'done':\n // finishReason available here for future context-compaction (Phase 3)\n break;\n }\n }\n\n // Reconstruct LLM-ready messages from stored history.\n // Assistant messages with tool calls produce proper tool_use content blocks.\n // Consecutive tool_result rows are grouped into a single user message.\n private toLLMMessages(stored: StoredMessage[]): Message[] {\n const messages: Message[] = [];\n\n for (const msg of stored) {\n if (msg.role === 'system') continue;\n\n if (msg.role === 'user') {\n messages.push({ role: 'user', content: msg.content });\n } else if (msg.role === 'assistant') {\n if (msg.toolCalls && msg.toolCalls.length > 0) {\n const content: MessageContent[] = [];\n if (msg.content) content.push({ type: 'text', text: msg.content });\n for (const tc of msg.toolCalls) {\n content.push({ type: 'tool_use', id: tc.id, name: tc.name, input: tc.input });\n }\n messages.push({ role: 'assistant', content });\n } else {\n messages.push({ role: 'assistant', content: msg.content });\n }\n } else if (msg.role === 'tool_result') {\n const resultBlock: MessageContent = {\n type: 'tool_result',\n tool_use_id: msg.toolCallId ?? '',\n content: msg.content,\n is_error: false,\n };\n const last = messages[messages.length - 1];\n // Append to existing tool_result user message, or start a new one\n if (last?.role === 'user' && Array.isArray(last.content)) {\n (last.content as MessageContent[]).push(resultBlock);\n } else {\n messages.push({ role: 'user', content: [resultBlock] });\n }\n }\n }\n\n return messages;\n }\n\n // ---------------------------------------------------------------------------\n // Per-turn ScopedStorage construction (Phase 4 — fs_reach enforcement).\n //\n // When the AgentLoop was wired with `storage` + `dataDir`, build a\n // ScopedStorage decorated with the active personality's `fs_reach`\n // allowlist for this turn. Substitutions (${ETHOS_HOME} / ${self} /\n // ${CWD}) are resolved here so the underlying storage-fs class stays\n // pristine. When `fs_reach` is unset, fall back to a sensible default:\n // read: [<ethosHome>/personalities/<self>/, <ethosHome>/skills/, <cwd>]\n // write: [<ethosHome>/personalities/<self>/, <cwd>]\n // ---------------------------------------------------------------------------\n\n private buildScopedStorage(personality: PersonalityConfig): Storage | undefined {\n if (!this.storage) return undefined;\n\n const ethosHome = this.dataDir ?? join(homedir(), '.ethos');\n const cwd = this.workingDir;\n const self = personality.id;\n const ownDir = `${join(ethosHome, 'personalities', self)}/`;\n\n const fsReach = personality.fs_reach;\n const readPrefixes =\n fsReach?.read && fsReach.read.length > 0\n ? fsReach.read.map((p) => substitute(p, { ethosHome, self, cwd }))\n : [ownDir, `${join(ethosHome, 'skills')}/`, cwd];\n const writePrefixes =\n fsReach?.write && fsReach.write.length > 0\n ? fsReach.write.map((p) => substitute(p, { ethosHome, self, cwd }))\n : [ownDir, cwd];\n\n return new ScopedStorage(this.storage, { read: readPrefixes, write: writePrefixes });\n }\n}\n\nfunction substitute(\n template: string,\n vars: { ethosHome: string; self: string; cwd: string },\n): string {\n return template\n .replace(/\\$\\{ETHOS_HOME\\}/g, vars.ethosHome)\n .replace(/\\$\\{self\\}/g, vars.self)\n .replace(/\\$\\{CWD\\}/g, vars.cwd);\n}\n","import type {\n SearchResult,\n Session,\n SessionFilter,\n SessionStore,\n SessionUsage,\n StoredMessage,\n} from '@ethosagent/types';\n\nexport class InMemorySessionStore implements SessionStore {\n private sessions = new Map<string, Session>();\n private messages = new Map<string, StoredMessage[]>();\n private idCounter = 0;\n\n async createSession(data: Omit<Session, 'id' | 'createdAt' | 'updatedAt'>): Promise<Session> {\n const session: Session = {\n ...data,\n id: `session_${++this.idCounter}`,\n createdAt: new Date(),\n updatedAt: new Date(),\n };\n this.sessions.set(session.id, session);\n this.messages.set(session.id, []);\n return session;\n }\n\n async getSession(id: string): Promise<Session | null> {\n return this.sessions.get(id) ?? null;\n }\n\n async getSessionByKey(key: string): Promise<Session | null> {\n for (const s of this.sessions.values()) {\n if (s.key === key) return s;\n }\n return null;\n }\n\n async updateSession(id: string, patch: Partial<Session>): Promise<void> {\n const session = this.sessions.get(id);\n if (!session) throw new Error(`Session not found: ${id}`);\n this.sessions.set(id, { ...session, ...patch, updatedAt: new Date() });\n }\n\n async deleteSession(id: string): Promise<void> {\n this.sessions.delete(id);\n this.messages.delete(id);\n }\n\n async listSessions(filter?: SessionFilter): Promise<Session[]> {\n let results = [...this.sessions.values()];\n if (filter?.platform) results = results.filter((s) => s.platform === filter.platform);\n if (filter?.personalityId)\n results = results.filter((s) => s.personalityId === filter.personalityId);\n if (filter?.workingDir) results = results.filter((s) => s.workingDir === filter.workingDir);\n if (filter?.since) {\n const since = filter.since;\n results = results.filter((s) => s.createdAt >= since);\n }\n results.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());\n const offset = filter?.offset ?? 0;\n const limit = filter?.limit ?? results.length;\n return results.slice(offset, offset + limit);\n }\n\n async appendMessage(data: Omit<StoredMessage, 'id' | 'timestamp'>): Promise<StoredMessage> {\n const message: StoredMessage = {\n ...data,\n id: `msg_${++this.idCounter}`,\n timestamp: new Date(),\n };\n const list = this.messages.get(data.sessionId) ?? [];\n list.push(message);\n this.messages.set(data.sessionId, list);\n return message;\n }\n\n async getMessages(\n sessionId: string,\n options?: { limit?: number; offset?: number },\n ): Promise<StoredMessage[]> {\n const all = this.messages.get(sessionId) ?? [];\n const offset = options?.offset ?? 0;\n // Return most-recent messages: trim from the tail, then skip `offset` from the end\n const end = all.length - offset;\n const start = options?.limit ? Math.max(0, end - options.limit) : 0;\n return all.slice(start, end);\n }\n\n async updateUsage(sessionId: string, delta: Partial<SessionUsage>): Promise<void> {\n const session = this.sessions.get(sessionId);\n if (!session) return;\n const usage = { ...session.usage };\n for (const [k, v] of Object.entries(delta) as [keyof SessionUsage, number][]) {\n (usage[k] as number) += v;\n }\n this.sessions.set(sessionId, { ...session, usage, updatedAt: new Date() });\n }\n\n async search(\n query: string,\n options?: { limit?: number; sessionId?: string },\n ): Promise<SearchResult[]> {\n const results: SearchResult[] = [];\n const lower = query.toLowerCase();\n for (const [sessionId, msgs] of this.messages.entries()) {\n if (options?.sessionId && sessionId !== options.sessionId) continue;\n for (const msg of msgs) {\n const idx = msg.content.toLowerCase().indexOf(lower);\n if (idx >= 0) {\n results.push({\n sessionId,\n messageId: msg.id,\n snippet: msg.content.slice(Math.max(0, idx - 50), idx + 150),\n score: 1,\n timestamp: msg.timestamp,\n });\n }\n }\n }\n results.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime());\n return results.slice(0, options?.limit ?? 20);\n }\n\n async pruneOldSessions(olderThan: Date): Promise<number> {\n let count = 0;\n for (const [id, session] of this.sessions.entries()) {\n if (session.updatedAt < olderThan) {\n this.sessions.delete(id);\n this.messages.delete(id);\n count++;\n }\n }\n return count;\n }\n\n async vacuum(): Promise<void> {\n // No-op for in-memory store\n }\n}\n","import type { MemoryLoadContext, MemoryProvider, MemoryUpdate } from '@ethosagent/types';\n\nexport class NoopMemoryProvider implements MemoryProvider {\n async prefetch(_ctx: MemoryLoadContext) {\n return null;\n }\n\n async sync(_ctx: MemoryLoadContext, _updates: MemoryUpdate[]): Promise<void> {\n // No-op\n }\n}\n","import type { PersonalityConfig, PersonalityRegistry } from '@ethosagent/types';\n\nconst DEFAULT_PERSONALITY: PersonalityConfig = {\n id: 'default',\n name: 'Default',\n description: 'Default Ethos personality',\n};\n\nexport class DefaultPersonalityRegistry implements PersonalityRegistry {\n private readonly personalities = new Map<string, PersonalityConfig>([\n ['default', DEFAULT_PERSONALITY],\n ]);\n private defaultId = 'default';\n\n define(config: PersonalityConfig): void {\n this.personalities.set(config.id, config);\n }\n\n get(id: string): PersonalityConfig | undefined {\n return this.personalities.get(id);\n }\n\n list(): PersonalityConfig[] {\n return [...this.personalities.values()];\n }\n\n getDefault(): PersonalityConfig {\n return this.personalities.get(this.defaultId) ?? DEFAULT_PERSONALITY;\n }\n\n setDefault(id: string): void {\n if (!this.personalities.has(id)) {\n throw new Error(`Unknown personality: ${id}`);\n }\n this.defaultId = id;\n }\n\n async loadFromDirectory(_dir: string): Promise<void> {\n // Implemented in extensions/personalities\n }\n\n remove(id: string): void {\n this.personalities.delete(id);\n }\n}\n","import type { ClaimingHooks, HookRegistry, ModifyingHooks, VoidHooks } from '@ethosagent/types';\n\ntype AnyHandler = (...args: unknown[]) => Promise<unknown>;\n\ninterface RegisteredHandler {\n handler: AnyHandler;\n pluginId?: string;\n failurePolicy: 'fail-open' | 'fail-closed';\n}\n\n/** Returns true when a handler should fire given the allowedPlugins filter. */\nfunction isAllowed(h: RegisteredHandler, allowedPlugins: string[] | undefined): boolean {\n if (allowedPlugins === undefined) return true; // no filter — fire all\n if (!h.pluginId) return true; // built-in handler — always fires\n return allowedPlugins.includes(h.pluginId);\n}\n\nexport class DefaultHookRegistry implements HookRegistry {\n private readonly voidHandlers = new Map<string, RegisteredHandler[]>();\n private readonly modifyingHandlers = new Map<string, RegisteredHandler[]>();\n private readonly claimingHandlers = new Map<string, RegisteredHandler[]>();\n\n registerVoid<K extends keyof VoidHooks>(\n name: K,\n handler: (payload: VoidHooks[K]) => Promise<void>,\n opts?: { pluginId?: string; failurePolicy?: 'fail-open' | 'fail-closed' },\n ): () => void {\n const entry: RegisteredHandler = {\n handler: handler as AnyHandler,\n pluginId: opts?.pluginId,\n failurePolicy: opts?.failurePolicy ?? 'fail-open',\n };\n const list = this.voidHandlers.get(name) ?? [];\n list.push(entry);\n this.voidHandlers.set(name, list);\n return () => this.remove(this.voidHandlers, name, entry);\n }\n\n registerModifying<K extends keyof ModifyingHooks>(\n name: K,\n handler: (payload: ModifyingHooks[K][0]) => Promise<Partial<ModifyingHooks[K][1]> | null>,\n opts?: { pluginId?: string },\n ): () => void {\n const entry: RegisteredHandler = {\n handler: handler as AnyHandler,\n pluginId: opts?.pluginId,\n failurePolicy: 'fail-open',\n };\n const list = this.modifyingHandlers.get(name) ?? [];\n list.push(entry);\n this.modifyingHandlers.set(name, list);\n return () => this.remove(this.modifyingHandlers, name, entry);\n }\n\n registerClaiming<K extends keyof ClaimingHooks>(\n name: K,\n handler: (payload: ClaimingHooks[K][0]) => Promise<ClaimingHooks[K][1]>,\n opts?: { pluginId?: string },\n ): () => void {\n const entry: RegisteredHandler = {\n handler: handler as AnyHandler,\n pluginId: opts?.pluginId,\n failurePolicy: 'fail-open',\n };\n const list = this.claimingHandlers.get(name) ?? [];\n list.push(entry);\n this.claimingHandlers.set(name, list);\n return () => this.remove(this.claimingHandlers, name, entry);\n }\n\n // Void hooks: all handlers run in parallel via Promise.allSettled.\n // Failures are logged but never propagate (fail-open by default).\n // allowedPlugins gates plugin-registered handlers; built-in handlers always fire.\n async fireVoid<K extends keyof VoidHooks>(\n name: K,\n payload: VoidHooks[K],\n allowedPlugins?: string[],\n ): Promise<void> {\n const handlers = (this.voidHandlers.get(name) ?? []).filter((h) =>\n isAllowed(h, allowedPlugins),\n );\n await Promise.allSettled(handlers.map((h) => h.handler(payload)));\n }\n\n // Modifying hooks: handlers run sequentially; results are merged (first non-null value per key wins).\n async fireModifying<K extends keyof ModifyingHooks>(\n name: K,\n payload: ModifyingHooks[K][0],\n allowedPlugins?: string[],\n ): Promise<ModifyingHooks[K][1]> {\n const handlers = (this.modifyingHandlers.get(name) ?? []).filter((h) =>\n isAllowed(h, allowedPlugins),\n );\n const merged: Record<string, unknown> = {};\n for (const h of handlers) {\n try {\n const result = await h.handler(payload);\n if (result && typeof result === 'object') {\n for (const [k, v] of Object.entries(result)) {\n if (!(k in merged) && v !== null && v !== undefined) {\n merged[k] = v;\n }\n }\n }\n } catch {\n // fail-open: continue with other handlers\n }\n }\n return merged as ModifyingHooks[K][1];\n }\n\n // Claiming hooks: handlers run sequentially, stop after first { handled: true }.\n async fireClaiming<K extends keyof ClaimingHooks>(\n name: K,\n payload: ClaimingHooks[K][0],\n allowedPlugins?: string[],\n ): Promise<ClaimingHooks[K][1]> {\n const handlers = (this.claimingHandlers.get(name) ?? []).filter((h) =>\n isAllowed(h, allowedPlugins),\n );\n for (const h of handlers) {\n try {\n const result = (await h.handler(payload)) as ClaimingHooks[K][1];\n if (result && (result as { handled: boolean }).handled) {\n return result;\n }\n } catch {\n // fail-open: try next handler\n }\n }\n return { handled: false } as ClaimingHooks[K][1];\n }\n\n unregisterPlugin(pluginId: string): void {\n for (const map of [this.voidHandlers, this.modifyingHandlers, this.claimingHandlers]) {\n for (const [name, handlers] of map.entries()) {\n map.set(\n name,\n handlers.filter((h) => h.pluginId !== pluginId),\n );\n }\n }\n }\n\n private remove(\n map: Map<string, RegisteredHandler[]>,\n name: string,\n entry: RegisteredHandler,\n ): void {\n const list = map.get(name) ?? [];\n map.set(\n name,\n list.filter((h) => h !== entry),\n );\n }\n}\n","import type { Tool, ToolContext, ToolFilterOpts, ToolRegistry, ToolResult } from '@ethosagent/types';\n\ninterface ToolEntry {\n tool: Tool;\n pluginId?: string;\n}\n\n/** Extract MCP server name from `mcp__<server>__<tool>` naming convention. */\nfunction mcpServerName(toolName: string): string | undefined {\n if (!toolName.startsWith('mcp__')) return undefined;\n return toolName.split('__')[1];\n}\n\n/** Returns true when a tool passes the MCP server + plugin filters. */\nfunction passesFilter(entry: ToolEntry, filterOpts: ToolFilterOpts | undefined): boolean {\n if (!filterOpts) return true;\n\n const { allowedMcpServers, allowedPlugins } = filterOpts;\n\n // MCP server gate: MCP tools only appear when their server is in the allowlist.\n if (allowedMcpServers !== undefined) {\n const server = mcpServerName(entry.tool.name);\n if (server !== undefined && !allowedMcpServers.includes(server)) return false;\n }\n\n // Plugin gate: plugin tools only appear when their plugin is in the allowlist.\n if (allowedPlugins !== undefined && entry.pluginId !== undefined) {\n if (!allowedPlugins.includes(entry.pluginId)) return false;\n }\n\n return true;\n}\n\nexport class DefaultToolRegistry implements ToolRegistry {\n private readonly tools = new Map<string, ToolEntry>();\n\n register(tool: Tool, opts?: { pluginId?: string }): void {\n this.tools.set(tool.name, { tool, pluginId: opts?.pluginId });\n }\n\n registerAll(tools: Tool[]): void {\n for (const tool of tools) {\n this.register(tool);\n }\n }\n\n unregister(name: string): void {\n this.tools.delete(name);\n }\n\n get(name: string): Tool | undefined {\n return this.tools.get(name)?.tool;\n }\n\n getAvailable(): Tool[] {\n return [...this.tools.values()]\n .filter((e) => !e.tool.isAvailable || e.tool.isAvailable())\n .map((e) => e.tool);\n }\n\n getForToolset(toolset: string): Tool[] {\n return this.getAvailable().filter((t) => t.toolset === toolset);\n }\n\n toDefinitions(allowedTools?: string[], filterOpts?: ToolFilterOpts) {\n const entries = [...this.tools.values()].filter(\n (e) => !e.tool.isAvailable || e.tool.isAvailable(),\n );\n\n const filtered = entries.filter((e) => {\n if (allowedTools && allowedTools.length > 0 && !allowedTools.includes(e.tool.name))\n return false;\n return passesFilter(e, filterOpts);\n });\n\n return filtered.map((e) => ({\n name: e.tool.name,\n description: e.tool.description,\n parameters: e.tool.schema,\n }));\n }\n\n // Runs all tool calls in parallel. Results are returned in input order.\n // Budget is split evenly across parallel calls; each result is post-trimmed to budget.\n // allowedTools + filterOpts enforce tool access at execution time (belt-and-suspenders).\n async executeParallel(\n calls: Array<{ toolCallId: string; name: string; args: unknown }>,\n ctx: ToolContext,\n allowedTools?: string[],\n filterOpts?: ToolFilterOpts,\n ): Promise<Array<{ toolCallId: string; name: string; result: ToolResult }>> {\n const perCallBudget = Math.floor(ctx.resultBudgetChars / Math.max(calls.length, 1));\n\n const results = await Promise.allSettled(\n calls.map(async (call) => {\n // Name-based allowlist check\n if (allowedTools && allowedTools.length > 0 && !allowedTools.includes(call.name)) {\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: false,\n error: `Tool ${call.name} is not permitted for this personality`,\n code: 'not_available',\n } as ToolResult,\n };\n }\n\n const entry = this.tools.get(call.name);\n if (!entry) {\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: false,\n error: `Unknown tool: ${call.name}`,\n code: 'not_available',\n } as ToolResult,\n };\n }\n\n // MCP server + plugin filter check\n if (!passesFilter(entry, filterOpts)) {\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: false,\n error: `Tool ${call.name} is not permitted for this personality`,\n code: 'not_available',\n } as ToolResult,\n };\n }\n\n if (entry.tool.isAvailable && !entry.tool.isAvailable()) {\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: false,\n error: `Tool ${call.name} is not currently available`,\n code: 'not_available',\n } as ToolResult,\n };\n }\n\n const budget = Math.min(perCallBudget, entry.tool.maxResultChars ?? perCallBudget);\n const toolCtx: ToolContext = { ...ctx, resultBudgetChars: budget };\n\n try {\n const result = await entry.tool.execute(call.args, toolCtx);\n // Post-trim result to budget\n if (result.ok && result.value.length > budget) {\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: true,\n value: `${result.value.slice(0, budget)}\\n[truncated — ${result.value.length} chars total]`,\n } as ToolResult,\n };\n }\n return { toolCallId: call.toolCallId, name: call.name, result };\n } catch (err) {\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: false,\n error: err instanceof Error ? err.message : String(err),\n code: 'execution_failed',\n } as ToolResult,\n };\n }\n }),\n );\n\n // Unwrap settled results — always return, never throw\n return results.map((r, i) => {\n if (r.status === 'fulfilled') return r.value;\n const call = calls[i] ?? { toolCallId: 'unknown', name: 'unknown', args: {} };\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: false,\n error: String(r.reason),\n code: 'execution_failed',\n } as ToolResult,\n };\n });\n }\n}\n","// Generic plugin registry — adapted from praxis PluginRegistry pattern.\n// Each subsystem (tools, channels, memory backends) gets its own instance.\n\nexport type PluginFactory<T, C = unknown> = (config: C) => T | null;\n\nexport class PluginRegistry<T, C = unknown> {\n private readonly factories = new Map<string, PluginFactory<T, C>>();\n\n register(type: string, factory: PluginFactory<T, C>): void {\n this.factories.set(type, factory);\n }\n\n create(type: string, config: C): T {\n const factory = this.factories.get(type);\n if (!factory) {\n throw new Error(\n `Unknown plugin type: \"${type}\". Registered: ${[...this.factories.keys()].join(', ')}`,\n );\n }\n const instance = factory(config);\n if (!instance) {\n throw new Error(`Plugin factory for \"${type}\" returned null`);\n }\n return instance;\n }\n\n has(type: string): boolean {\n return this.factories.has(type);\n }\n\n types(): string[] {\n return [...this.factories.keys()];\n }\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,qBAAqB;;;ACOvB,IAAM,uBAAN,MAAmD;AAAA,EAChD,WAAW,oBAAI,IAAqB;AAAA,EACpC,WAAW,oBAAI,IAA6B;AAAA,EAC5C,YAAY;AAAA,EAEpB,MAAM,cAAc,MAAyE;AAC3F,UAAM,UAAmB;AAAA,MACvB,GAAG;AAAA,MACH,IAAI,WAAW,EAAE,KAAK,SAAS;AAAA,MAC/B,WAAW,oBAAI,KAAK;AAAA,MACpB,WAAW,oBAAI,KAAK;AAAA,IACtB;AACA,SAAK,SAAS,IAAI,QAAQ,IAAI,OAAO;AACrC,SAAK,SAAS,IAAI,QAAQ,IAAI,CAAC,CAAC;AAChC,W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AAN,MAAqC;AAAA,EACzB,YAAY,oBAAI,IAAiC;AAAA,EAElE,SAAS,MAAc,SAAoC;AACzD,SAAK,UAAU,IAAI,MAAM,OAAO;AAAA,EAClC;AAAA,EAEA,OAAO,MAAc,QAAc;AACjC,UAAM,UAAU,KAAK,UAAU,IAAI,IAAI;AACvC,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI;AAAA,QACR,yBAAyB,IAAI,kBAAkB,CAAC,GAAG,KAAK,UAAU,KAAK,CAAC,EAAE,KAAK,IAAI,CAAC;AAAA,MACtF;AAAA,IACF;AACA,UAAM,WAAW,QAAQ,MAAM;AAC/B,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MAAM,uBAAuB,IAAI,iBAAiB;AAAA,IAC9D;AACA,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,MAAuB;AACzB,WAAO,KAAK,UAAU,IAAI,IAAI;AAAA,EAChC;AAAA,EAEA,QAAkB;AAChB,WAAO,CAAC,GAAG,KAAK,UAAU,KAAK,CAAC;AAAA,EAClC;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/agent-loop.ts","../../storage-fs/src/fs-storage.ts","../../storage-fs/src/in-memory-storage.ts","../../storage-fs/src/scoped-storage.ts","../src/defaults/in-memory-session.ts","../src/defaults/noop-memory.ts","../src/defaults/noop-personality.ts","../src/hook-registry.ts","../src/tool-registry.ts","../src/plugin-registry.ts"],"sourcesContent":["import { homedir } from 'node:os';\nimport { join } from 'node:path';\nimport { ScopedStorage } from '@ethosagent/storage-fs';\nimport type {\n CompletionChunk,\n ContextInjector,\n HookRegistry,\n LLMProvider,\n MemoryProvider,\n Message,\n MessageContent,\n PersonalityConfig,\n PersonalityRegistry,\n PromptContext,\n SessionStore,\n Storage,\n StoredMessage,\n ToolFilterOpts,\n ToolRegistry,\n ToolResult,\n} from '@ethosagent/types';\n\nimport { InMemorySessionStore } from './defaults/in-memory-session';\nimport { NoopMemoryProvider } from './defaults/noop-memory';\nimport { DefaultPersonalityRegistry } from './defaults/noop-personality';\nimport { DefaultHookRegistry } from './hook-registry';\nimport { DefaultToolRegistry } from './tool-registry';\n\n// ---------------------------------------------------------------------------\n// Agent events emitted by run()\n// ---------------------------------------------------------------------------\n\nexport type AgentEvent =\n | { type: 'text_delta'; text: string }\n | { type: 'thinking_delta'; thinking: string }\n | { type: 'tool_start'; toolCallId: string; toolName: string; args: unknown }\n // Phase 30.2 — `audience` gates whether channel adapters / chat.ts surface\n // this event to the user. Default is `'internal'`; tools opt in to `'user'`\n // per event. Framework-emitted budget warnings are `'user'` (see step 7).\n | {\n type: 'tool_progress';\n toolName: string;\n message: string;\n percent?: number;\n audience: 'internal' | 'user';\n }\n | {\n type: 'tool_end';\n toolCallId: string;\n toolName: string;\n ok: boolean;\n durationMs: number;\n // Phase 30.2 — same boundary applies to tool_end success rendering.\n // Failures (`ok: false`) ignore the field and always render.\n audience?: 'internal' | 'user';\n /**\n * Tool output body — the success value when `ok`, or the error\n * message when `ok: false`. Optional so consumers that only care\n * about the status (CLI ASCII chips, telemetry) can ignore it.\n * The web chip surfaces this on expand-on-click without a\n * follow-up history fetch.\n */\n result?: string;\n }\n | { type: 'usage'; inputTokens: number; outputTokens: number; estimatedCostUsd: number }\n | { type: 'error'; error: string; code: string }\n | { type: 'done'; text: string; turnCount: number }\n // Emitted once after context injectors run; carries any metadata they wrote to PromptContext.meta.\n | { type: 'context_meta'; data: Record<string, unknown> };\n\n// ---------------------------------------------------------------------------\n// Config\n// ---------------------------------------------------------------------------\n\nexport interface AgentLoopConfig {\n llm: LLMProvider;\n tools?: ToolRegistry;\n personalities?: PersonalityRegistry;\n memory?: MemoryProvider;\n session?: SessionStore;\n hooks?: HookRegistry;\n injectors?: ContextInjector[];\n /**\n * Maps each plugin-registered injector to its plugin id so AgentLoop can\n * gate injectors by personality. Built-in injectors are absent (always fire).\n * Populated by PluginApiImpl.registerInjector(); passed through from wiring.\n */\n injectorPluginIds?: Map<ContextInjector, string>;\n /**\n * Base Storage instance handed to tools via `ToolContext.storage` after\n * being decorated with a ScopedStorage that enforces the active\n * personality's `fs_reach` allowlist. When unset, ToolContext.storage is\n * left undefined and tools fall back to unrestricted node:fs (legacy\n * behavior — existing CLI/TUI tests don't need a storage instance).\n */\n storage?: Storage;\n /**\n * Absolute path to ~/.ethos/ used for `${ETHOS_HOME}` substitution in\n * `fs_reach` paths. Defaults to `${HOME}/.ethos`. Required only when\n * `storage` is set.\n */\n dataDir?: string;\n // Maps personality ID → model ID. Resolution: modelRouting[id] → personality.model → llm.model\n modelRouting?: Record<string, string>;\n options?: {\n maxIterations?: number;\n historyLimit?: number;\n platform?: string;\n workingDir?: string;\n resultBudgetChars?: number;\n /**\n * Hard cap on total tool calls per user turn (across all LLM iterations).\n * Defaults to 20. Trips a `tool_progress` warning and exits cleanly.\n * See plan/IMPROVEMENT.md P1-3.\n */\n maxToolCallsPerTurn?: number;\n /**\n * Hard cap on the number of times the same tool name can be invoked in a\n * single turn. Catches the \"infinite loop on a single tool\" failure mode\n * (e.g. tts loop reported as OpenClaw #67744). Defaults to 5.\n */\n maxIdenticalToolCalls?: number;\n /**\n * Default streaming watchdog in milliseconds. If no chunk arrives from the\n * LLM within this window, the agent aborts the stream and emits an error.\n * Reset on every chunk. Personalities can override via\n * `personality.streamingTimeoutMs`. Defaults to 120000 (2 minutes).\n */\n streamingTimeoutMs?: number;\n };\n}\n\nexport interface RunOptions {\n sessionKey?: string;\n personalityId?: string;\n abortSignal?: AbortSignal;\n /**\n * Identifier surfaced to tools as `ToolContext.agentId`. Delegation tools\n * use this to thread spawn depth (`depth:N`) into child loops so\n * `MAX_SPAWN_DEPTH` can be enforced across recursive sub-agent calls.\n */\n agentId?: string;\n}\n\n// ---------------------------------------------------------------------------\n// AgentLoop\n// ---------------------------------------------------------------------------\n\nexport class AgentLoop {\n private readonly llm: LLMProvider;\n private readonly tools: ToolRegistry;\n private readonly personalities: PersonalityRegistry;\n private readonly memory: MemoryProvider;\n private readonly session: SessionStore;\n /** Public so surfaces (web, ACP) can register late-binding hooks they own\n * without re-running the whole wiring factory. The CLI/TUI register hooks\n * before construction; web registers an approval hook after createAgentLoop\n * returns. */\n readonly hooks: HookRegistry;\n private readonly injectors: ContextInjector[];\n private readonly injectorPluginIds: Map<ContextInjector, string>;\n private readonly maxIterations: number;\n private readonly historyLimit: number;\n private readonly platform: string;\n private readonly workingDir: string;\n private readonly resultBudgetChars: number;\n private readonly maxToolCallsPerTurn: number;\n private readonly maxIdenticalToolCalls: number;\n private readonly streamingTimeoutMs: number;\n private readonly modelRouting: Record<string, string>;\n private readonly storage?: Storage;\n private readonly dataDir?: string;\n\n constructor(config: AgentLoopConfig) {\n this.llm = config.llm;\n this.tools = config.tools ?? new DefaultToolRegistry();\n this.personalities = config.personalities ?? new DefaultPersonalityRegistry();\n this.memory = config.memory ?? new NoopMemoryProvider();\n this.session = config.session ?? new InMemorySessionStore();\n this.hooks = config.hooks ?? new DefaultHookRegistry();\n this.injectors = (config.injectors ?? []).sort((a, b) => b.priority - a.priority);\n this.injectorPluginIds = config.injectorPluginIds ?? new Map();\n this.maxIterations = config.options?.maxIterations ?? 50;\n this.historyLimit = config.options?.historyLimit ?? 200;\n this.platform = config.options?.platform ?? 'cli';\n this.workingDir = config.options?.workingDir ?? process.cwd();\n this.resultBudgetChars = config.options?.resultBudgetChars ?? 80_000;\n this.maxToolCallsPerTurn = config.options?.maxToolCallsPerTurn ?? 20;\n this.maxIdenticalToolCalls = config.options?.maxIdenticalToolCalls ?? 5;\n this.streamingTimeoutMs = config.options?.streamingTimeoutMs ?? 120_000;\n this.modelRouting = config.modelRouting ?? {};\n if (config.storage) this.storage = config.storage;\n if (config.dataDir) this.dataDir = config.dataDir;\n }\n\n async *run(text: string, opts: RunOptions = {}): AsyncGenerator<AgentEvent> {\n const abortSignal = opts.abortSignal ?? new AbortController().signal;\n const sessionKey = opts.sessionKey ?? `${this.platform}:default`;\n\n // Step 1: Resolve or create session\n const ethosSession =\n (await this.session.getSessionByKey(sessionKey)) ??\n (await this.session.createSession({\n key: sessionKey,\n platform: this.platform,\n model: this.llm.model,\n provider: this.llm.name,\n personalityId: opts.personalityId,\n workingDir: this.workingDir,\n usage: {\n inputTokens: 0,\n outputTokens: 0,\n cacheReadTokens: 0,\n cacheCreationTokens: 0,\n estimatedCostUsd: 0,\n apiCallCount: 0,\n compactionCount: 0,\n },\n }));\n\n const sessionId = ethosSession.id;\n const personality =\n (opts.personalityId ? this.personalities.get(opts.personalityId) : null) ??\n this.personalities.getDefault();\n\n // Resolve effective model: explicit per-personality routing > LLM base model.\n // personality.model is intentionally skipped — those IDs are Anthropic-specific\n // and break non-Anthropic providers (OpenRouter, Gemini, Ollama, etc.).\n // Configure overrides via modelRouting in ~/.ethos/config.yaml instead.\n const effectiveModel = this.modelRouting[personality.id] ?? this.llm.model;\n const modelOverride = effectiveModel !== this.llm.model ? effectiveModel : undefined;\n // Allowed tool names for this personality (undefined = no restriction)\n const allowedTools = personality.toolset?.length ? personality.toolset : undefined;\n // Per-personality plugin + MCP gate (default-deny: missing field = no access)\n const allowedPlugins = personality.plugins ?? [];\n const filterOpts: ToolFilterOpts = {\n allowedMcpServers: personality.mcp_servers,\n allowedPlugins,\n };\n\n // Step 2: Fire session_start hooks\n await this.hooks.fireVoid(\n 'session_start',\n {\n sessionId,\n sessionKey,\n platform: this.platform,\n personalityId: personality.id,\n },\n allowedPlugins,\n );\n\n // Step 3: Persist the user message.\n //\n // Subagent task contract: the delegated task always lives in the child's\n // first user message (this `text`). It is NEVER copied into the system\n // prompt, NEVER injected via memory, and NEVER duplicated across both.\n // The regression test in\n // `extensions/tools-delegation/src/__tests__/task-contract.test.ts`\n // captures every `LLMProvider.complete()` request and asserts the marker\n // never appears in `opts.system` and appears exactly once across all\n // user-role messages.\n await this.session.appendMessage({\n sessionId,\n role: 'user',\n content: text,\n });\n\n // Step 4: Load history (trimmed to most-recent limit)\n const allMessages = await this.session.getMessages(sessionId, { limit: this.historyLimit });\n const history = allMessages.filter((m) => m.role !== 'system');\n\n // Step 5: Prefetch memory\n const memCtx = await this.memory.prefetch({\n sessionId,\n sessionKey,\n platform: this.platform,\n workingDir: this.workingDir,\n personalityId: personality.id,\n memoryScope: personality.memoryScope,\n query: text,\n });\n\n // Step 6: Build system prompt from injectors\n const promptCtx: PromptContext = {\n sessionId,\n sessionKey,\n platform: this.platform,\n model: this.llm.model,\n history,\n workingDir: this.workingDir,\n isDm: true,\n turnNumber: allMessages.length,\n personalityId: personality.id,\n };\n\n const systemParts: string[] = [];\n\n // ETHOS.md / personality identity — routes through Storage so ScopedStorage\n // and InMemoryStorage fixtures work correctly. Only runs when storage is\n // wired (production always provides it; tests without a real ethosFile skip).\n if (personality.ethosFile && this.storage) {\n const identity = await this.storage.read(personality.ethosFile);\n if (identity) systemParts.push(identity.trim());\n }\n\n // Context injectors sorted by priority (already sorted in constructor)\n for (const injector of this.injectors) {\n // Plugin-registered injectors only fire when the plugin is permitted.\n const injPluginId = this.injectorPluginIds.get(injector);\n if (injPluginId !== undefined && !allowedPlugins.includes(injPluginId)) continue;\n if (injector.shouldInject && !injector.shouldInject(promptCtx)) continue;\n const result = await injector.inject(promptCtx);\n if (result) {\n if (result.position === 'prepend') {\n systemParts.unshift(result.content);\n } else {\n systemParts.push(result.content);\n }\n }\n }\n\n // Emit injector metadata (e.g. skill_files_used) so eval harness can capture it.\n if (promptCtx.meta && Object.keys(promptCtx.meta).length > 0) {\n yield { type: 'context_meta', data: promptCtx.meta };\n }\n\n // Memory injected last, as context about the user\n if (memCtx) {\n systemParts.push(`## Memory\\n\\n${memCtx.content}`);\n }\n\n // Step 7: Before-prompt-build modifying hooks (plugins can prepend/append/override)\n const buildResult = await this.hooks.fireModifying(\n 'before_prompt_build',\n {\n sessionId,\n personalityId: personality.id,\n history,\n },\n allowedPlugins,\n );\n\n if (buildResult.overrideSystem) {\n systemParts.length = 0;\n systemParts.push(buildResult.overrideSystem);\n } else {\n if (buildResult.prependSystem) systemParts.unshift(buildResult.prependSystem);\n if (buildResult.appendSystem) systemParts.push(buildResult.appendSystem);\n }\n\n const systemPrompt = systemParts.join('\\n\\n').trim() || undefined;\n\n // Step 8: Agentic loop — LLM call → tool use → LLM call → ...\n const llmMessages = this.toLLMMessages(history);\n let fullText = '';\n let turnCount = 0;\n\n // Tool-call budget tracking — prevents runaway loops (see IMPROVEMENT.md P1-3).\n // Counted across all iterations within a single user turn.\n let totalToolCalls = 0;\n const toolNameCounts = new Map<string, number>();\n\n for (let iteration = 0; iteration < this.maxIterations; iteration++) {\n if (abortSignal.aborted) {\n yield { type: 'error', error: 'Aborted', code: 'aborted' };\n return;\n }\n\n // Budget guard: bail before the next LLM call if we've already exceeded\n // either the total tool-call budget or the per-tool repeat budget. The\n // previous iteration's tool_result is in llmMessages, so the LLM history\n // stays valid; we just refuse to call again.\n if (totalToolCalls >= this.maxToolCallsPerTurn) {\n yield {\n type: 'tool_progress',\n toolName: '_budget',\n message: `Stopped: hit ${this.maxToolCallsPerTurn}-tool-call budget for this turn`,\n audience: 'user',\n };\n break;\n }\n const overusedTool = [...toolNameCounts.entries()].find(\n ([, count]) => count >= this.maxIdenticalToolCalls,\n );\n if (overusedTool) {\n yield {\n type: 'tool_progress',\n toolName: overusedTool[0],\n message: `Stopped: ${overusedTool[0]} called ${overusedTool[1]} times in one turn (likely loop)`,\n audience: 'user',\n };\n break;\n }\n\n // Fire before_llm_call\n await this.hooks.fireVoid(\n 'before_llm_call',\n {\n sessionId,\n model: this.llm.model,\n turnNumber: turnCount,\n },\n allowedPlugins,\n );\n\n // Stream LLM response\n const pendingToolCalls: Array<{\n toolCallId: string;\n toolName: string;\n partialJson: string;\n args?: unknown;\n }> = [];\n let chunkText = '';\n\n // Streaming watchdog: cancel the stream if no chunk arrives within the\n // per-personality window. Reset every chunk so slow-but-progressing\n // reasoning is unaffected. See IMPROVEMENT.md P1-2 / OpenClaw #68596.\n const watchdogMs = personality.streamingTimeoutMs ?? this.streamingTimeoutMs;\n const watchdogController = new AbortController();\n const combinedSignal = AbortSignal.any([abortSignal, watchdogController.signal]);\n let watchdogTimer: ReturnType<typeof setTimeout> | undefined;\n const armWatchdog = () => {\n if (watchdogTimer) clearTimeout(watchdogTimer);\n watchdogTimer = setTimeout(() => watchdogController.abort(), watchdogMs);\n };\n const disarmWatchdog = () => {\n if (watchdogTimer) clearTimeout(watchdogTimer);\n watchdogTimer = undefined;\n };\n\n try {\n armWatchdog();\n const stream = this.llm.complete(llmMessages, this.tools.toDefinitions(allowedTools, filterOpts), {\n system: systemPrompt,\n cacheSystemPrompt: true,\n abortSignal: combinedSignal,\n ...(modelOverride ? { modelOverride } : {}),\n });\n\n for await (const chunk of stream) {\n if (abortSignal.aborted) break;\n if (watchdogController.signal.aborted) break;\n armWatchdog();\n yield* this.handleChunk(chunk, pendingToolCalls, (t) => {\n chunkText += t;\n fullText += t;\n });\n }\n disarmWatchdog();\n\n if (watchdogController.signal.aborted && !abortSignal.aborted) {\n yield {\n type: 'error',\n error: `LLM stream stalled — no chunk for ${watchdogMs}ms`,\n code: 'streaming_timeout',\n };\n return;\n }\n } catch (err) {\n disarmWatchdog();\n if (watchdogController.signal.aborted && !abortSignal.aborted) {\n yield {\n type: 'error',\n error: `LLM stream stalled — no chunk for ${watchdogMs}ms`,\n code: 'streaming_timeout',\n };\n return;\n }\n const msg = err instanceof Error ? err.message : String(err);\n yield { type: 'error', error: msg, code: 'llm_error' };\n return;\n }\n\n turnCount++;\n\n // Determine which tool calls completed parsing\n const completedToolCalls = pendingToolCalls.filter((tc) => tc.args !== undefined);\n\n // Update budget counters — these gate the NEXT iteration's LLM call.\n totalToolCalls += completedToolCalls.length;\n for (const tc of completedToolCalls) {\n toolNameCounts.set(tc.toolName, (toolNameCounts.get(tc.toolName) ?? 0) + 1);\n }\n\n // Persist assistant message — include tool_use references so history is LLM-replayable\n await this.session.appendMessage({\n sessionId,\n role: 'assistant',\n content: chunkText,\n ...(completedToolCalls.length > 0 && {\n toolCalls: completedToolCalls.map((tc) => ({\n id: tc.toolCallId,\n name: tc.toolName,\n input: tc.args,\n })),\n }),\n });\n\n // Fire after_llm_call\n await this.hooks.fireVoid(\n 'after_llm_call',\n {\n sessionId,\n text: chunkText,\n usage: { inputTokens: 0, outputTokens: 0 },\n },\n allowedPlugins,\n );\n\n // Push assistant message with proper content blocks for next iteration\n if (completedToolCalls.length > 0) {\n const assistantContent: MessageContent[] = [];\n if (chunkText) assistantContent.push({ type: 'text', text: chunkText });\n for (const tc of completedToolCalls) {\n assistantContent.push({\n type: 'tool_use',\n id: tc.toolCallId,\n name: tc.toolName,\n input: tc.args,\n });\n }\n llmMessages.push({ role: 'assistant', content: assistantContent });\n } else {\n llmMessages.push({ role: 'assistant', content: chunkText });\n break;\n }\n\n // Step 9: Pre-flight hooks → execute non-rejected tools → collect all results\n\n // Phase 30.2 — tools call ctx.emit() during execution; AsyncGenerator can't\n // yield from a sync callback, so we buffer per-batch then drain after\n // executeParallel resolves. Order is preserved (insertion = call order).\n const progressBuffer: Array<{\n toolName: string;\n message: string;\n percent?: number;\n audience: 'internal' | 'user';\n }> = [];\n\n const scopedStorage = this.buildScopedStorage(personality);\n\n const toolCtxBase = {\n sessionId,\n sessionKey,\n platform: this.platform,\n workingDir: this.workingDir,\n agentId: opts.agentId,\n personalityId: personality.id,\n memoryScope: personality.memoryScope,\n currentTurn: turnCount,\n messageCount: allMessages.length + turnCount,\n abortSignal,\n emit: (event: {\n type: 'progress';\n toolName: string;\n message: string;\n percent?: number;\n audience?: 'internal' | 'user';\n }) => {\n progressBuffer.push({\n toolName: event.toolName,\n message: event.message,\n ...(event.percent !== undefined && { percent: event.percent }),\n audience: event.audience ?? 'internal',\n });\n },\n resultBudgetChars: this.resultBudgetChars,\n ...(scopedStorage ? { storage: scopedStorage } : {}),\n };\n\n // Run before_tool_call hooks; build exec list with effective args\n // Rejected tools get tool_end ok:false + an error tool_result sent back to LLM\n type Prepped = { toolCallId: string; name: string; args: unknown; rejected?: string };\n const prepped: Prepped[] = [];\n\n for (const tc of completedToolCalls) {\n const beforeResult = await this.hooks.fireModifying(\n 'before_tool_call',\n {\n sessionId,\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n args: tc.args,\n },\n allowedPlugins,\n );\n\n if (beforeResult.error) {\n yield {\n type: 'tool_end',\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n ok: false,\n durationMs: 0,\n result: beforeResult.error,\n };\n prepped.push({\n toolCallId: tc.toolCallId,\n name: tc.toolName,\n args: tc.args,\n rejected: beforeResult.error,\n });\n continue;\n }\n\n const effectiveArgs = beforeResult.args ?? tc.args;\n yield {\n type: 'tool_start',\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n args: effectiveArgs,\n };\n prepped.push({ toolCallId: tc.toolCallId, name: tc.toolName, args: effectiveArgs });\n }\n\n // Execute only non-rejected tools; results keyed by toolCallId\n const execInputs = prepped\n .filter((p) => p.rejected === undefined)\n .map((p) => ({ toolCallId: p.toolCallId, name: p.name, args: p.args }));\n\n const startedAt = Date.now();\n const execResults =\n execInputs.length > 0\n ? await this.tools.executeParallel(execInputs, toolCtxBase, allowedTools, filterOpts)\n : [];\n const execResultMap = new Map(execResults.map((r) => [r.toolCallId, r]));\n\n // Drain any progress events tools emitted during execution. Order is\n // call-order (across the parallel batch) — close enough for users; the\n // exact interleaving doesn't matter when ctx.emit is best-effort.\n for (const ev of progressBuffer) {\n yield { type: 'tool_progress', ...ev };\n }\n progressBuffer.length = 0;\n\n // Persist results + emit tool_end + build tool_result content blocks (original order)\n const toolResultContent: MessageContent[] = [];\n\n for (const p of prepped) {\n const durationMs = Date.now() - startedAt;\n let result: ToolResult;\n\n if (p.rejected !== undefined) {\n result = { ok: false, error: p.rejected, code: 'execution_failed' };\n // tool_end already emitted above; no after_tool_call hook for blocked tools\n } else {\n const execResult = execResultMap.get(p.toolCallId);\n result = execResult?.result ?? {\n ok: false,\n error: 'Tool result missing',\n code: 'execution_failed',\n };\n yield {\n type: 'tool_end',\n toolCallId: p.toolCallId,\n toolName: p.name,\n ok: result.ok,\n durationMs,\n result: result.ok ? result.value : result.error,\n };\n await this.hooks.fireVoid(\n 'after_tool_call',\n {\n sessionId,\n toolName: p.name,\n result,\n durationMs,\n },\n allowedPlugins,\n );\n }\n\n // Persist every result (rejected or not) so history matches what LLM sees\n await this.session.appendMessage({\n sessionId,\n role: 'tool_result',\n content: result.ok ? result.value : result.error,\n toolCallId: p.toolCallId,\n toolName: p.name,\n });\n\n toolResultContent.push({\n type: 'tool_result',\n tool_use_id: p.toolCallId,\n content: result.ok ? result.value : result.error,\n is_error: !result.ok,\n });\n }\n\n // Feed all tool results back to LLM as a single user message with content blocks\n llmMessages.push({ role: 'user', content: toolResultContent });\n }\n\n // Step 10: Memory writes flow through the `memory_save` tool during the\n // turn (see extensions/tools-memory). The agent-loop itself produces no\n // updates, so there's nothing to sync here.\n\n // Step 11: Update usage\n await this.session.updateUsage(sessionId, { apiCallCount: turnCount });\n\n // Step 12: Fire agent_done\n await this.hooks.fireVoid('agent_done', { sessionId, text: fullText, turnCount }, allowedPlugins);\n\n yield { type: 'done', text: fullText, turnCount };\n }\n\n private *handleChunk(\n chunk: CompletionChunk,\n pendingToolCalls: Array<{\n toolCallId: string;\n toolName: string;\n partialJson: string;\n args?: unknown;\n }>,\n onText: (t: string) => void,\n ): Generator<AgentEvent> {\n switch (chunk.type) {\n case 'text_delta':\n onText(chunk.text);\n yield { type: 'text_delta', text: chunk.text };\n break;\n\n case 'thinking_delta':\n yield { type: 'thinking_delta', thinking: chunk.thinking };\n break;\n\n case 'tool_use_start':\n pendingToolCalls.push({\n toolCallId: chunk.toolCallId,\n toolName: chunk.toolName,\n partialJson: '',\n });\n break;\n\n case 'tool_use_delta': {\n const tc = pendingToolCalls.find((t) => t.toolCallId === chunk.toolCallId);\n if (tc) tc.partialJson += chunk.partialJson;\n break;\n }\n\n case 'tool_use_end': {\n const tc = pendingToolCalls.find((t) => t.toolCallId === chunk.toolCallId);\n if (tc) {\n try {\n tc.args = JSON.parse(chunk.inputJson || tc.partialJson);\n } catch {\n tc.args = {};\n }\n }\n break;\n }\n\n case 'usage':\n yield {\n type: 'usage',\n inputTokens: chunk.usage.inputTokens,\n outputTokens: chunk.usage.outputTokens,\n estimatedCostUsd: chunk.usage.estimatedCostUsd,\n };\n break;\n\n case 'done':\n // finishReason available here for future context-compaction (Phase 3)\n break;\n }\n }\n\n // Reconstruct LLM-ready messages from stored history.\n // Assistant messages with tool calls produce proper tool_use content blocks.\n // Consecutive tool_result rows are grouped into a single user message.\n private toLLMMessages(stored: StoredMessage[]): Message[] {\n const messages: Message[] = [];\n\n for (const msg of stored) {\n if (msg.role === 'system') continue;\n\n if (msg.role === 'user') {\n messages.push({ role: 'user', content: msg.content });\n } else if (msg.role === 'assistant') {\n if (msg.toolCalls && msg.toolCalls.length > 0) {\n const content: MessageContent[] = [];\n if (msg.content) content.push({ type: 'text', text: msg.content });\n for (const tc of msg.toolCalls) {\n content.push({ type: 'tool_use', id: tc.id, name: tc.name, input: tc.input });\n }\n messages.push({ role: 'assistant', content });\n } else {\n messages.push({ role: 'assistant', content: msg.content });\n }\n } else if (msg.role === 'tool_result') {\n const resultBlock: MessageContent = {\n type: 'tool_result',\n tool_use_id: msg.toolCallId ?? '',\n content: msg.content,\n is_error: false,\n };\n const last = messages[messages.length - 1];\n // Append to existing tool_result user message, or start a new one\n if (last?.role === 'user' && Array.isArray(last.content)) {\n (last.content as MessageContent[]).push(resultBlock);\n } else {\n messages.push({ role: 'user', content: [resultBlock] });\n }\n }\n }\n\n return messages;\n }\n\n // ---------------------------------------------------------------------------\n // Per-turn ScopedStorage construction (Phase 4 — fs_reach enforcement).\n //\n // When the AgentLoop was wired with `storage` + `dataDir`, build a\n // ScopedStorage decorated with the active personality's `fs_reach`\n // allowlist for this turn. Substitutions (${ETHOS_HOME} / ${self} /\n // ${CWD}) are resolved here so the underlying storage-fs class stays\n // pristine. When `fs_reach` is unset, fall back to a sensible default:\n // read: [<ethosHome>/personalities/<self>/, <ethosHome>/skills/, <cwd>]\n // write: [<ethosHome>/personalities/<self>/, <cwd>]\n // ---------------------------------------------------------------------------\n\n private buildScopedStorage(personality: PersonalityConfig): Storage | undefined {\n if (!this.storage) return undefined;\n\n const ethosHome = this.dataDir ?? join(homedir(), '.ethos');\n const cwd = this.workingDir;\n const self = personality.id;\n const ownDir = `${join(ethosHome, 'personalities', self)}/`;\n\n const fsReach = personality.fs_reach;\n const readPrefixes =\n fsReach?.read && fsReach.read.length > 0\n ? fsReach.read.map((p) => substitute(p, { ethosHome, self, cwd }))\n : [ownDir, `${join(ethosHome, 'skills')}/`, cwd];\n const writePrefixes =\n fsReach?.write && fsReach.write.length > 0\n ? fsReach.write.map((p) => substitute(p, { ethosHome, self, cwd }))\n : [ownDir, cwd];\n\n return new ScopedStorage(this.storage, { read: readPrefixes, write: writePrefixes });\n }\n}\n\nfunction substitute(\n template: string,\n vars: { ethosHome: string; self: string; cwd: string },\n): string {\n return template\n .replace(/\\$\\{ETHOS_HOME\\}/g, vars.ethosHome)\n .replace(/\\$\\{self\\}/g, vars.self)\n .replace(/\\$\\{CWD\\}/g, vars.cwd);\n}\n","import {\n appendFile,\n mkdir,\n readdir,\n readFile,\n rename,\n rm,\n stat,\n writeFile,\n} from 'node:fs/promises';\nimport type {\n Storage,\n StorageDirEntry,\n StorageRemoveOptions,\n StorageWriteOptions,\n} from '@ethosagent/types';\n\nexport class FsStorage implements Storage {\n async read(path: string): Promise<string | null> {\n try {\n return await readFile(path, 'utf-8');\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return null;\n throw err;\n }\n }\n\n async exists(path: string): Promise<boolean> {\n try {\n await stat(path);\n return true;\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return false;\n throw err;\n }\n }\n\n async mtime(path: string): Promise<number | null> {\n try {\n const s = await stat(path);\n return s.mtimeMs;\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return null;\n throw err;\n }\n }\n\n async list(dir: string): Promise<string[]> {\n try {\n return await readdir(dir);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return [];\n throw err;\n }\n }\n\n async listEntries(dir: string): Promise<StorageDirEntry[]> {\n try {\n const entries = await readdir(dir, { withFileTypes: true });\n return entries.map((e) => ({ name: e.name, isDir: e.isDirectory() }));\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return [];\n throw err;\n }\n }\n\n async write(path: string, content: string, opts?: StorageWriteOptions): Promise<void> {\n if (opts?.mode !== undefined) {\n await writeFile(path, content, { encoding: 'utf-8', mode: opts.mode });\n return;\n }\n await writeFile(path, content, 'utf-8');\n }\n\n async append(path: string, content: string): Promise<void> {\n await appendFile(path, content, 'utf-8');\n }\n\n async writeAtomic(path: string, content: string, opts?: StorageWriteOptions): Promise<void> {\n const tmp = `${path}.tmp.${process.pid}.${Date.now()}`;\n if (opts?.mode !== undefined) {\n await writeFile(tmp, content, { encoding: 'utf-8', mode: opts.mode });\n } else {\n await writeFile(tmp, content, 'utf-8');\n }\n try {\n await rename(tmp, path);\n } catch (err) {\n // Best-effort cleanup of temp file on rename failure.\n try {\n await rm(tmp, { force: true });\n } catch {\n // ignore\n }\n throw err;\n }\n }\n\n async mkdir(dir: string): Promise<void> {\n await mkdir(dir, { recursive: true });\n }\n\n async remove(path: string, opts?: StorageRemoveOptions): Promise<void> {\n await rm(path, { recursive: opts?.recursive === true });\n }\n\n async rename(from: string, to: string): Promise<void> {\n await rename(from, to);\n }\n}\n","import { dirname } from 'node:path';\nimport type {\n Storage,\n StorageDirEntry,\n StorageRemoveOptions,\n StorageWriteOptions,\n} from '@ethosagent/types';\n\ninterface FileNode {\n type: 'file';\n content: string;\n mode?: number;\n mtimeMs: number;\n}\n\ninterface DirNode {\n type: 'dir';\n mtimeMs: number;\n}\n\ntype Node = FileNode | DirNode;\n\n/**\n * In-memory Storage implementation for tests. Mirrors fs semantics closely:\n *\n * - read/exists/mtime return null for missing paths.\n * - write requires the parent directory to exist (throws ENOENT otherwise) —\n * matches fs.writeFile and forces tests to mkdir first, just like prod.\n * - mkdir is always recursive; no-op on existing dirs; throws on file conflict.\n * - remove without recursive throws on missing paths and on non-empty dirs.\n * - writeAtomic round-trips through a temp key, identical to fs flow.\n *\n * mtime ticks forward on every write so cache-by-mtime patterns work in tests\n * without sleeping.\n */\nexport class InMemoryStorage implements Storage {\n // Absolute path → node\n private readonly nodes = new Map<string, Node>();\n private clock = 0;\n\n // Treat the filesystem root as always existing so consumers don't need to\n // mkdir('/') before writing to a file at the root.\n private isRootLike(path: string): boolean {\n return path === '/' || /^[A-Za-z]:[\\\\/]?$/.test(path);\n }\n\n private nextMtime(): number {\n this.clock += 1;\n return this.clock;\n }\n\n private getNode(path: string): Node | undefined {\n return this.nodes.get(path);\n }\n\n private requireParentDir(path: string): void {\n const parent = dirname(path);\n if (parent === path) return;\n if (this.isRootLike(parent)) return;\n const node = this.nodes.get(parent);\n if (!node) {\n const err = new Error(`ENOENT: no such file or directory, open '${path}'`);\n (err as NodeJS.ErrnoException).code = 'ENOENT';\n throw err;\n }\n if (node.type !== 'dir') {\n const err = new Error(`ENOTDIR: not a directory, open '${path}'`);\n (err as NodeJS.ErrnoException).code = 'ENOTDIR';\n throw err;\n }\n }\n\n async read(path: string): Promise<string | null> {\n const node = this.getNode(path);\n if (!node) return null;\n if (node.type === 'dir') {\n const err = new Error(`EISDIR: illegal operation on a directory, read '${path}'`);\n (err as NodeJS.ErrnoException).code = 'EISDIR';\n throw err;\n }\n return node.content;\n }\n\n async exists(path: string): Promise<boolean> {\n return this.nodes.has(path);\n }\n\n async mtime(path: string): Promise<number | null> {\n const node = this.getNode(path);\n return node ? node.mtimeMs : null;\n }\n\n async list(dir: string): Promise<string[]> {\n const node = this.getNode(dir);\n if (!node) return [];\n if (node.type !== 'dir') {\n const err = new Error(`ENOTDIR: not a directory, scandir '${dir}'`);\n (err as NodeJS.ErrnoException).code = 'ENOTDIR';\n throw err;\n }\n const prefix = dir.endsWith('/') ? dir : `${dir}/`;\n const names: string[] = [];\n for (const key of this.nodes.keys()) {\n if (key === dir) continue;\n if (!key.startsWith(prefix)) continue;\n const rest = key.slice(prefix.length);\n if (rest.includes('/')) continue;\n names.push(rest);\n }\n return names.sort();\n }\n\n async listEntries(dir: string): Promise<StorageDirEntry[]> {\n const names = await this.list(dir);\n const prefix = dir.endsWith('/') ? dir : `${dir}/`;\n return names.map((name) => {\n const node = this.nodes.get(prefix + name);\n return { name, isDir: node?.type === 'dir' };\n });\n }\n\n async write(path: string, content: string, opts?: StorageWriteOptions): Promise<void> {\n const existing = this.nodes.get(path);\n if (existing && existing.type === 'dir') {\n const err = new Error(`EISDIR: illegal operation on a directory, write '${path}'`);\n (err as NodeJS.ErrnoException).code = 'EISDIR';\n throw err;\n }\n this.requireParentDir(path);\n const node: FileNode = {\n type: 'file',\n content,\n mtimeMs: this.nextMtime(),\n };\n if (opts?.mode !== undefined) node.mode = opts.mode;\n this.nodes.set(path, node);\n }\n\n async writeAtomic(path: string, content: string, opts?: StorageWriteOptions): Promise<void> {\n // Same observable end-state as write — atomicity is a property of the\n // backing store; the in-memory map is single-step by definition.\n await this.write(path, content, opts);\n }\n\n async append(path: string, content: string): Promise<void> {\n const existing = this.nodes.get(path);\n if (existing && existing.type === 'dir') {\n const err = new Error(`EISDIR: illegal operation on a directory, append '${path}'`);\n (err as NodeJS.ErrnoException).code = 'EISDIR';\n throw err;\n }\n if (!existing) {\n // appendFile creates the file if missing — match that semantics.\n this.requireParentDir(path);\n this.nodes.set(path, {\n type: 'file',\n content,\n mtimeMs: this.nextMtime(),\n });\n return;\n }\n this.nodes.set(path, {\n ...existing,\n content: existing.content + content,\n mtimeMs: this.nextMtime(),\n });\n }\n\n async mkdir(dir: string): Promise<void> {\n if (this.isRootLike(dir)) return;\n const existing = this.nodes.get(dir);\n if (existing) {\n if (existing.type === 'dir') return;\n const err = new Error(`EEXIST: file already exists, mkdir '${dir}'`);\n (err as NodeJS.ErrnoException).code = 'EEXIST';\n throw err;\n }\n // Recursively create parents.\n const parent = dirname(dir);\n if (parent !== dir && !this.isRootLike(parent) && !this.nodes.has(parent)) {\n await this.mkdir(parent);\n }\n this.nodes.set(dir, { type: 'dir', mtimeMs: this.nextMtime() });\n }\n\n async remove(path: string, opts?: StorageRemoveOptions): Promise<void> {\n const node = this.nodes.get(path);\n if (!node) {\n const err = new Error(`ENOENT: no such file or directory, remove '${path}'`);\n (err as NodeJS.ErrnoException).code = 'ENOENT';\n throw err;\n }\n if (node.type === 'file') {\n this.nodes.delete(path);\n return;\n }\n // Directory.\n const prefix = path.endsWith('/') ? path : `${path}/`;\n const children: string[] = [];\n for (const key of this.nodes.keys()) {\n if (key !== path && key.startsWith(prefix)) children.push(key);\n }\n if (children.length > 0 && opts?.recursive !== true) {\n const err = new Error(`ENOTEMPTY: directory not empty, remove '${path}'`);\n (err as NodeJS.ErrnoException).code = 'ENOTEMPTY';\n throw err;\n }\n for (const key of children) this.nodes.delete(key);\n this.nodes.delete(path);\n }\n\n async rename(from: string, to: string): Promise<void> {\n const node = this.nodes.get(from);\n if (!node) {\n const err = new Error(`ENOENT: no such file or directory, rename '${from}' -> '${to}'`);\n (err as NodeJS.ErrnoException).code = 'ENOENT';\n throw err;\n }\n this.requireParentDir(to);\n\n if (node.type === 'file') {\n const target = this.nodes.get(to);\n if (target?.type === 'dir') {\n const err = new Error(`EISDIR: cannot rename file onto directory, '${from}' -> '${to}'`);\n (err as NodeJS.ErrnoException).code = 'EISDIR';\n throw err;\n }\n this.nodes.delete(from);\n this.nodes.set(to, { ...node, mtimeMs: this.nextMtime() });\n return;\n }\n\n // Directory rename — move the directory itself plus every descendant.\n const targetExisting = this.nodes.get(to);\n if (targetExisting) {\n const err = new Error(`EEXIST: target exists, rename '${from}' -> '${to}'`);\n (err as NodeJS.ErrnoException).code = 'EEXIST';\n throw err;\n }\n const fromPrefix = from.endsWith('/') ? from : `${from}/`;\n const moves: Array<[string, string]> = [[from, to]];\n for (const key of this.nodes.keys()) {\n if (key !== from && key.startsWith(fromPrefix)) {\n moves.push([key, to + key.slice(from.length)]);\n }\n }\n for (const [src, dst] of moves) {\n const n = this.nodes.get(src);\n if (!n) continue;\n this.nodes.delete(src);\n this.nodes.set(dst, { ...n, mtimeMs: this.nextMtime() });\n }\n }\n\n // --- Test helpers -----------------------------------------------------\n\n /** Drop all state. Useful for `beforeEach` resets without re-instantiating. */\n reset(): void {\n this.nodes.clear();\n this.clock = 0;\n }\n\n /** Return the recorded mode for a file (undefined if no mode was set). */\n getMode(path: string): number | undefined {\n const node = this.nodes.get(path);\n if (!node || node.type !== 'file') return undefined;\n return node.mode;\n }\n}\n","import {\n BoundaryError,\n type Storage,\n type StorageDirEntry,\n type StorageRemoveOptions,\n type StorageWriteOptions,\n} from '@ethosagent/types';\n\nexport interface ScopedStorageScope {\n /** Absolute path prefixes that may be read. */\n read: readonly string[];\n /** Absolute path prefixes that may be written / mutated. */\n write: readonly string[];\n}\n\n/**\n * Decorator over Storage that enforces a per-scope read/write allowlist.\n * Used by tools-file to bound a personality's filesystem reach to its own\n * directory + cwd (Phase 4 of the storage abstraction plan).\n *\n * A path is permitted if any allowed prefix is a prefix of the absolute path.\n * Prefixes are matched literally — there is no glob expansion. Pass paths\n * that end in `/` for directory scopes; ScopedStorage normalizes them so\n * `/a/b` does not also match `/a/bc/`.\n */\nexport class ScopedStorage implements Storage {\n private readonly readPrefixes: string[];\n private readonly writePrefixes: string[];\n\n constructor(\n private readonly inner: Storage,\n scope: ScopedStorageScope,\n ) {\n this.readPrefixes = scope.read.map(normalizePrefix);\n this.writePrefixes = scope.write.map(normalizePrefix);\n }\n\n private check(path: string, kind: 'read' | 'write'): void {\n const allowed = kind === 'read' ? this.readPrefixes : this.writePrefixes;\n if (!isPathAllowed(path, allowed)) {\n throw new BoundaryError(kind, path, allowed);\n }\n }\n\n async read(path: string): Promise<string | null> {\n this.check(path, 'read');\n return this.inner.read(path);\n }\n\n async exists(path: string): Promise<boolean> {\n this.check(path, 'read');\n return this.inner.exists(path);\n }\n\n async mtime(path: string): Promise<number | null> {\n this.check(path, 'read');\n return this.inner.mtime(path);\n }\n\n async list(dir: string): Promise<string[]> {\n this.check(dir, 'read');\n return this.inner.list(dir);\n }\n\n async listEntries(dir: string): Promise<StorageDirEntry[]> {\n this.check(dir, 'read');\n return this.inner.listEntries(dir);\n }\n\n async write(path: string, content: string, opts?: StorageWriteOptions): Promise<void> {\n this.check(path, 'write');\n return this.inner.write(path, content, opts);\n }\n\n async append(path: string, content: string): Promise<void> {\n this.check(path, 'write');\n return this.inner.append(path, content);\n }\n\n async writeAtomic(path: string, content: string, opts?: StorageWriteOptions): Promise<void> {\n this.check(path, 'write');\n return this.inner.writeAtomic(path, content, opts);\n }\n\n async mkdir(dir: string): Promise<void> {\n this.check(dir, 'write');\n return this.inner.mkdir(dir);\n }\n\n async remove(path: string, opts?: StorageRemoveOptions): Promise<void> {\n this.check(path, 'write');\n return this.inner.remove(path, opts);\n }\n\n async rename(from: string, to: string): Promise<void> {\n this.check(from, 'write');\n this.check(to, 'write');\n return this.inner.rename(from, to);\n }\n}\n\nfunction normalizePrefix(prefix: string): string {\n // A prefix matches any path where prefix is followed by '/' or end-of-string,\n // OR where the path equals the prefix exactly. We keep the prefix as-given\n // (with or without trailing slash) and handle the boundary in isPathAllowed.\n return prefix;\n}\n\nfunction isPathAllowed(path: string, prefixes: readonly string[]): boolean {\n for (const prefix of prefixes) {\n if (path === prefix) return true;\n const withoutSlash = prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;\n // Allow the directory itself (without trailing slash) — needed so\n // `mkdir(<personality-dir>)` and `list(<personality-dir>)` succeed\n // when the configured prefix has a trailing slash.\n if (path === withoutSlash) return true;\n const withSlash = `${withoutSlash}/`;\n if (path.startsWith(withSlash)) return true;\n }\n return false;\n}\n","import type {\n SearchResult,\n Session,\n SessionFilter,\n SessionStore,\n SessionUsage,\n StoredMessage,\n} from '@ethosagent/types';\n\nexport class InMemorySessionStore implements SessionStore {\n private sessions = new Map<string, Session>();\n private messages = new Map<string, StoredMessage[]>();\n private idCounter = 0;\n\n async createSession(data: Omit<Session, 'id' | 'createdAt' | 'updatedAt'>): Promise<Session> {\n const session: Session = {\n ...data,\n id: `session_${++this.idCounter}`,\n createdAt: new Date(),\n updatedAt: new Date(),\n };\n this.sessions.set(session.id, session);\n this.messages.set(session.id, []);\n return session;\n }\n\n async getSession(id: string): Promise<Session | null> {\n return this.sessions.get(id) ?? null;\n }\n\n async getSessionByKey(key: string): Promise<Session | null> {\n for (const s of this.sessions.values()) {\n if (s.key === key) return s;\n }\n return null;\n }\n\n async updateSession(id: string, patch: Partial<Session>): Promise<void> {\n const session = this.sessions.get(id);\n if (!session) throw new Error(`Session not found: ${id}`);\n this.sessions.set(id, { ...session, ...patch, updatedAt: new Date() });\n }\n\n async deleteSession(id: string): Promise<void> {\n this.sessions.delete(id);\n this.messages.delete(id);\n }\n\n async listSessions(filter?: SessionFilter): Promise<Session[]> {\n let results = [...this.sessions.values()];\n if (filter?.platform) results = results.filter((s) => s.platform === filter.platform);\n if (filter?.personalityId)\n results = results.filter((s) => s.personalityId === filter.personalityId);\n if (filter?.workingDir) results = results.filter((s) => s.workingDir === filter.workingDir);\n if (filter?.since) {\n const since = filter.since;\n results = results.filter((s) => s.createdAt >= since);\n }\n results.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());\n const offset = filter?.offset ?? 0;\n const limit = filter?.limit ?? results.length;\n return results.slice(offset, offset + limit);\n }\n\n async appendMessage(data: Omit<StoredMessage, 'id' | 'timestamp'>): Promise<StoredMessage> {\n const message: StoredMessage = {\n ...data,\n id: `msg_${++this.idCounter}`,\n timestamp: new Date(),\n };\n const list = this.messages.get(data.sessionId) ?? [];\n list.push(message);\n this.messages.set(data.sessionId, list);\n return message;\n }\n\n async getMessages(\n sessionId: string,\n options?: { limit?: number; offset?: number },\n ): Promise<StoredMessage[]> {\n const all = this.messages.get(sessionId) ?? [];\n const offset = options?.offset ?? 0;\n // Return most-recent messages: trim from the tail, then skip `offset` from the end\n const end = all.length - offset;\n const start = options?.limit ? Math.max(0, end - options.limit) : 0;\n return all.slice(start, end);\n }\n\n async updateUsage(sessionId: string, delta: Partial<SessionUsage>): Promise<void> {\n const session = this.sessions.get(sessionId);\n if (!session) return;\n const usage = { ...session.usage };\n for (const [k, v] of Object.entries(delta) as [keyof SessionUsage, number][]) {\n (usage[k] as number) += v;\n }\n this.sessions.set(sessionId, { ...session, usage, updatedAt: new Date() });\n }\n\n async search(\n query: string,\n options?: { limit?: number; sessionId?: string },\n ): Promise<SearchResult[]> {\n const results: SearchResult[] = [];\n const lower = query.toLowerCase();\n for (const [sessionId, msgs] of this.messages.entries()) {\n if (options?.sessionId && sessionId !== options.sessionId) continue;\n for (const msg of msgs) {\n const idx = msg.content.toLowerCase().indexOf(lower);\n if (idx >= 0) {\n results.push({\n sessionId,\n messageId: msg.id,\n snippet: msg.content.slice(Math.max(0, idx - 50), idx + 150),\n score: 1,\n timestamp: msg.timestamp,\n });\n }\n }\n }\n results.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime());\n return results.slice(0, options?.limit ?? 20);\n }\n\n async pruneOldSessions(olderThan: Date): Promise<number> {\n let count = 0;\n for (const [id, session] of this.sessions.entries()) {\n if (session.updatedAt < olderThan) {\n this.sessions.delete(id);\n this.messages.delete(id);\n count++;\n }\n }\n return count;\n }\n\n async vacuum(): Promise<void> {\n // No-op for in-memory store\n }\n}\n","import type { MemoryLoadContext, MemoryProvider, MemoryUpdate } from '@ethosagent/types';\n\nexport class NoopMemoryProvider implements MemoryProvider {\n async prefetch(_ctx: MemoryLoadContext) {\n return null;\n }\n\n async sync(_ctx: MemoryLoadContext, _updates: MemoryUpdate[]): Promise<void> {\n // No-op\n }\n}\n","import type { PersonalityConfig, PersonalityRegistry } from '@ethosagent/types';\n\nconst DEFAULT_PERSONALITY: PersonalityConfig = {\n id: 'default',\n name: 'Default',\n description: 'Default Ethos personality',\n};\n\nexport class DefaultPersonalityRegistry implements PersonalityRegistry {\n private readonly personalities = new Map<string, PersonalityConfig>([\n ['default', DEFAULT_PERSONALITY],\n ]);\n private defaultId = 'default';\n\n define(config: PersonalityConfig): void {\n this.personalities.set(config.id, config);\n }\n\n get(id: string): PersonalityConfig | undefined {\n return this.personalities.get(id);\n }\n\n list(): PersonalityConfig[] {\n return [...this.personalities.values()];\n }\n\n getDefault(): PersonalityConfig {\n return this.personalities.get(this.defaultId) ?? DEFAULT_PERSONALITY;\n }\n\n setDefault(id: string): void {\n if (!this.personalities.has(id)) {\n throw new Error(`Unknown personality: ${id}`);\n }\n this.defaultId = id;\n }\n\n async loadFromDirectory(_dir: string): Promise<void> {\n // Implemented in extensions/personalities\n }\n\n remove(id: string): void {\n this.personalities.delete(id);\n }\n}\n","import type { ClaimingHooks, HookRegistry, ModifyingHooks, VoidHooks } from '@ethosagent/types';\n\ntype AnyHandler = (...args: unknown[]) => Promise<unknown>;\n\ninterface RegisteredHandler {\n handler: AnyHandler;\n pluginId?: string;\n failurePolicy: 'fail-open' | 'fail-closed';\n}\n\n/** Returns true when a handler should fire given the allowedPlugins filter. */\nfunction isAllowed(h: RegisteredHandler, allowedPlugins: string[] | undefined): boolean {\n if (allowedPlugins === undefined) return true; // no filter — fire all\n if (!h.pluginId) return true; // built-in handler — always fires\n return allowedPlugins.includes(h.pluginId);\n}\n\nexport class DefaultHookRegistry implements HookRegistry {\n private readonly voidHandlers = new Map<string, RegisteredHandler[]>();\n private readonly modifyingHandlers = new Map<string, RegisteredHandler[]>();\n private readonly claimingHandlers = new Map<string, RegisteredHandler[]>();\n\n registerVoid<K extends keyof VoidHooks>(\n name: K,\n handler: (payload: VoidHooks[K]) => Promise<void>,\n opts?: { pluginId?: string; failurePolicy?: 'fail-open' | 'fail-closed' },\n ): () => void {\n const entry: RegisteredHandler = {\n handler: handler as AnyHandler,\n pluginId: opts?.pluginId,\n failurePolicy: opts?.failurePolicy ?? 'fail-open',\n };\n const list = this.voidHandlers.get(name) ?? [];\n list.push(entry);\n this.voidHandlers.set(name, list);\n return () => this.remove(this.voidHandlers, name, entry);\n }\n\n registerModifying<K extends keyof ModifyingHooks>(\n name: K,\n handler: (payload: ModifyingHooks[K][0]) => Promise<Partial<ModifyingHooks[K][1]> | null>,\n opts?: { pluginId?: string },\n ): () => void {\n const entry: RegisteredHandler = {\n handler: handler as AnyHandler,\n pluginId: opts?.pluginId,\n failurePolicy: 'fail-open',\n };\n const list = this.modifyingHandlers.get(name) ?? [];\n list.push(entry);\n this.modifyingHandlers.set(name, list);\n return () => this.remove(this.modifyingHandlers, name, entry);\n }\n\n registerClaiming<K extends keyof ClaimingHooks>(\n name: K,\n handler: (payload: ClaimingHooks[K][0]) => Promise<ClaimingHooks[K][1]>,\n opts?: { pluginId?: string },\n ): () => void {\n const entry: RegisteredHandler = {\n handler: handler as AnyHandler,\n pluginId: opts?.pluginId,\n failurePolicy: 'fail-open',\n };\n const list = this.claimingHandlers.get(name) ?? [];\n list.push(entry);\n this.claimingHandlers.set(name, list);\n return () => this.remove(this.claimingHandlers, name, entry);\n }\n\n // Void hooks: all handlers run in parallel via Promise.allSettled.\n // Failures are logged but never propagate (fail-open by default).\n // allowedPlugins gates plugin-registered handlers; built-in handlers always fire.\n async fireVoid<K extends keyof VoidHooks>(\n name: K,\n payload: VoidHooks[K],\n allowedPlugins?: string[],\n ): Promise<void> {\n const handlers = (this.voidHandlers.get(name) ?? []).filter((h) =>\n isAllowed(h, allowedPlugins),\n );\n await Promise.allSettled(handlers.map((h) => h.handler(payload)));\n }\n\n // Modifying hooks: handlers run sequentially; results are merged (first non-null value per key wins).\n async fireModifying<K extends keyof ModifyingHooks>(\n name: K,\n payload: ModifyingHooks[K][0],\n allowedPlugins?: string[],\n ): Promise<ModifyingHooks[K][1]> {\n const handlers = (this.modifyingHandlers.get(name) ?? []).filter((h) =>\n isAllowed(h, allowedPlugins),\n );\n const merged: Record<string, unknown> = {};\n for (const h of handlers) {\n try {\n const result = await h.handler(payload);\n if (result && typeof result === 'object') {\n for (const [k, v] of Object.entries(result)) {\n if (!(k in merged) && v !== null && v !== undefined) {\n merged[k] = v;\n }\n }\n }\n } catch {\n // fail-open: continue with other handlers\n }\n }\n return merged as ModifyingHooks[K][1];\n }\n\n // Claiming hooks: handlers run sequentially, stop after first { handled: true }.\n async fireClaiming<K extends keyof ClaimingHooks>(\n name: K,\n payload: ClaimingHooks[K][0],\n allowedPlugins?: string[],\n ): Promise<ClaimingHooks[K][1]> {\n const handlers = (this.claimingHandlers.get(name) ?? []).filter((h) =>\n isAllowed(h, allowedPlugins),\n );\n for (const h of handlers) {\n try {\n const result = (await h.handler(payload)) as ClaimingHooks[K][1];\n if (result && (result as { handled: boolean }).handled) {\n return result;\n }\n } catch {\n // fail-open: try next handler\n }\n }\n return { handled: false } as ClaimingHooks[K][1];\n }\n\n unregisterPlugin(pluginId: string): void {\n for (const map of [this.voidHandlers, this.modifyingHandlers, this.claimingHandlers]) {\n for (const [name, handlers] of map.entries()) {\n map.set(\n name,\n handlers.filter((h) => h.pluginId !== pluginId),\n );\n }\n }\n }\n\n private remove(\n map: Map<string, RegisteredHandler[]>,\n name: string,\n entry: RegisteredHandler,\n ): void {\n const list = map.get(name) ?? [];\n map.set(\n name,\n list.filter((h) => h !== entry),\n );\n }\n}\n","import type { Tool, ToolContext, ToolFilterOpts, ToolRegistry, ToolResult } from '@ethosagent/types';\n\ninterface ToolEntry {\n tool: Tool;\n pluginId?: string;\n}\n\n/** Extract MCP server name from `mcp__<server>__<tool>` naming convention. */\nfunction mcpServerName(toolName: string): string | undefined {\n if (!toolName.startsWith('mcp__')) return undefined;\n return toolName.split('__')[1];\n}\n\n/** Returns true when a tool passes the MCP server + plugin filters. */\nfunction passesFilter(entry: ToolEntry, filterOpts: ToolFilterOpts | undefined): boolean {\n if (!filterOpts) return true;\n\n const { allowedMcpServers, allowedPlugins } = filterOpts;\n\n // MCP server gate: MCP tools only appear when their server is in the allowlist.\n if (allowedMcpServers !== undefined) {\n const server = mcpServerName(entry.tool.name);\n if (server !== undefined && !allowedMcpServers.includes(server)) return false;\n }\n\n // Plugin gate: plugin tools only appear when their plugin is in the allowlist.\n if (allowedPlugins !== undefined && entry.pluginId !== undefined) {\n if (!allowedPlugins.includes(entry.pluginId)) return false;\n }\n\n return true;\n}\n\nexport class DefaultToolRegistry implements ToolRegistry {\n private readonly tools = new Map<string, ToolEntry>();\n\n register(tool: Tool, opts?: { pluginId?: string }): void {\n this.tools.set(tool.name, { tool, pluginId: opts?.pluginId });\n }\n\n registerAll(tools: Tool[]): void {\n for (const tool of tools) {\n this.register(tool);\n }\n }\n\n unregister(name: string): void {\n this.tools.delete(name);\n }\n\n get(name: string): Tool | undefined {\n return this.tools.get(name)?.tool;\n }\n\n getAvailable(): Tool[] {\n return [...this.tools.values()]\n .filter((e) => !e.tool.isAvailable || e.tool.isAvailable())\n .map((e) => e.tool);\n }\n\n getForToolset(toolset: string): Tool[] {\n return this.getAvailable().filter((t) => t.toolset === toolset);\n }\n\n toDefinitions(allowedTools?: string[], filterOpts?: ToolFilterOpts) {\n const entries = [...this.tools.values()].filter(\n (e) => !e.tool.isAvailable || e.tool.isAvailable(),\n );\n\n const filtered = entries.filter((e) => {\n if (allowedTools && allowedTools.length > 0 && !allowedTools.includes(e.tool.name))\n return false;\n return passesFilter(e, filterOpts);\n });\n\n return filtered.map((e) => ({\n name: e.tool.name,\n description: e.tool.description,\n parameters: e.tool.schema,\n }));\n }\n\n // Runs all tool calls in parallel. Results are returned in input order.\n // Budget is split evenly across parallel calls; each result is post-trimmed to budget.\n // allowedTools + filterOpts enforce tool access at execution time (belt-and-suspenders).\n async executeParallel(\n calls: Array<{ toolCallId: string; name: string; args: unknown }>,\n ctx: ToolContext,\n allowedTools?: string[],\n filterOpts?: ToolFilterOpts,\n ): Promise<Array<{ toolCallId: string; name: string; result: ToolResult }>> {\n const perCallBudget = Math.floor(ctx.resultBudgetChars / Math.max(calls.length, 1));\n\n const results = await Promise.allSettled(\n calls.map(async (call) => {\n // Name-based allowlist check\n if (allowedTools && allowedTools.length > 0 && !allowedTools.includes(call.name)) {\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: false,\n error: `Tool ${call.name} is not permitted for this personality`,\n code: 'not_available',\n } as ToolResult,\n };\n }\n\n const entry = this.tools.get(call.name);\n if (!entry) {\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: false,\n error: `Unknown tool: ${call.name}`,\n code: 'not_available',\n } as ToolResult,\n };\n }\n\n // MCP server + plugin filter check\n if (!passesFilter(entry, filterOpts)) {\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: false,\n error: `Tool ${call.name} is not permitted for this personality`,\n code: 'not_available',\n } as ToolResult,\n };\n }\n\n if (entry.tool.isAvailable && !entry.tool.isAvailable()) {\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: false,\n error: `Tool ${call.name} is not currently available`,\n code: 'not_available',\n } as ToolResult,\n };\n }\n\n const budget = Math.min(perCallBudget, entry.tool.maxResultChars ?? perCallBudget);\n const toolCtx: ToolContext = { ...ctx, resultBudgetChars: budget };\n\n try {\n const result = await entry.tool.execute(call.args, toolCtx);\n // Post-trim result to budget\n if (result.ok && result.value.length > budget) {\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: true,\n value: `${result.value.slice(0, budget)}\\n[truncated — ${result.value.length} chars total]`,\n } as ToolResult,\n };\n }\n return { toolCallId: call.toolCallId, name: call.name, result };\n } catch (err) {\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: false,\n error: err instanceof Error ? err.message : String(err),\n code: 'execution_failed',\n } as ToolResult,\n };\n }\n }),\n );\n\n // Unwrap settled results — always return, never throw\n return results.map((r, i) => {\n if (r.status === 'fulfilled') return r.value;\n const call = calls[i] ?? { toolCallId: 'unknown', name: 'unknown', args: {} };\n return {\n toolCallId: call.toolCallId,\n name: call.name,\n result: {\n ok: false,\n error: String(r.reason),\n code: 'execution_failed',\n } as ToolResult,\n };\n });\n }\n}\n","// Generic plugin registry — adapted from praxis PluginRegistry pattern.\n// Each subsystem (tools, channels, memory backends) gets its own instance.\n\nexport type PluginFactory<T, C = unknown> = (config: C) => T | null;\n\nexport class PluginRegistry<T, C = unknown> {\n private readonly factories = new Map<string, PluginFactory<T, C>>();\n\n register(type: string, factory: PluginFactory<T, C>): void {\n this.factories.set(type, factory);\n }\n\n create(type: string, config: C): T {\n const factory = this.factories.get(type);\n if (!factory) {\n throw new Error(\n `Unknown plugin type: \"${type}\". Registered: ${[...this.factories.keys()].join(', ')}`,\n );\n }\n const instance = factory(config);\n if (!instance) {\n throw new Error(`Plugin factory for \"${type}\" returned null`);\n }\n return instance;\n }\n\n has(type: string): boolean {\n return this.factories.has(type);\n }\n\n types(): string[] {\n return [...this.factories.keys()];\n }\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,YAAY;;;ACDrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACTP,SAAS,eAAe;;;ACAxB;AAAA,EACE;AAAA,OAKK;AAmBA,IAAM,gBAAN,MAAuC;AAAA,EAI5C,YACmB,OACjB,OACA;AAFiB;AAGjB,SAAK,eAAe,MAAM,KAAK,IAAI,eAAe;AAClD,SAAK,gBAAgB,MAAM,MAAM,IAAI,eAAe;AAAA,EACtD;AAAA,EALmB;AAAA,EAJF;AAAA,EACA;AAAA,EAUT,MAAM,MAAc,MAA8B;AACxD,UAAM,UAAU,SAAS,SAAS,KAAK,eAAe,KAAK;AAC3D,QAAI,CAAC,cAAc,MAAM,OAAO,GAAG;AACjC,YAAM,IAAI,cAAc,MAAM,MAAM,OAAO;AAAA,IAC7C;AAAA,EACF;AAAA,EAEA,MAAM,KAAK,MAAsC;AAC/C,SAAK,MAAM,MAAM,MAAM;AACvB,WAAO,KAAK,MAAM,KAAK,IAAI;AAAA,EAC7B;AAAA,EAEA,MAAM,OAAO,M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O,KAAK,UAAU,IAAI,IAAI;AAAA,EAChC;AAAA,EAEA,QAAkB;AAChB,WAAO,CAAC,GAAG,KAAK,UAAU,KAAK,CAAC;AAAA,EAClC;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ethosagent/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Core agent loop, tool registry, and hook registry for the Ethos agent framework",
|
|
@@ -19,10 +19,12 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@ethosagent/
|
|
23
|
-
|
|
22
|
+
"@ethosagent/types": "0.2.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@ethosagent/storage-fs": "0.0.0"
|
|
24
26
|
},
|
|
25
27
|
"scripts": {
|
|
26
|
-
"build": "tsup
|
|
28
|
+
"build": "tsup"
|
|
27
29
|
}
|
|
28
30
|
}
|