diff --git a/src/application/index.ts b/src/application/index.ts deleted file mode 100644 index 3ec6e86..0000000 --- a/src/application/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Zesdex Application Layer — port traits, use cases, turn service. - * Depends only on @zesdex/domain. Higher-level ports implemented by - * infrastructure adapters. - */ -export * from "./ports/index.ts"; -export * from "./agent/index.ts"; -export * from "./cms/index.ts"; \ No newline at end of file diff --git a/src/domain/cms/conversation.ts b/src/domain/cms/conversation.ts deleted file mode 100644 index e79a3c9..0000000 --- a/src/domain/cms/conversation.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Re-export of conversation types from core (matches Rust `cms/conversation.rs`). - */ -export type { Conversation } from "../core/conversation.ts"; -export type { ChatMessage, Role } from "../core/message.ts"; -export { newConversation, pushMessage, rebuildSystem, toApiMessages } from "../core/conversation.ts"; -export { Roles } from "../core/message.ts"; \ No newline at end of file diff --git a/src/domain/index.ts b/src/domain/index.ts deleted file mode 100644 index 6142f70..0000000 --- a/src/domain/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Zesdex Domain Layer — pure types, value objects, and port interfaces. - * Zero framework dependencies, zero I/O. Mirrors the Rust `zesdex-domain` crate. - */ -export * from "./core/index.ts"; -export * from "./cms/index.ts"; -export * from "./agent/index.ts"; -export * from "./subagent/mod.ts"; -export * from "./workflow/mod.ts"; \ No newline at end of file diff --git a/src/application/agent/index.ts b/src/features/agent/application/index.ts similarity index 89% rename from src/application/agent/index.ts rename to src/features/agent/application/index.ts index cb55c31..403d65d 100644 --- a/src/application/agent/index.ts +++ b/src/features/agent/application/index.ts @@ -14,7 +14,7 @@ export interface ToolExecutor { /** Service for running agent turns asynchronously. */ export interface AgentTurnService { - runTurn(params: import("@zesdex/domain").AgentTurnParams): Promise; + runTurn(params: import("@zesdex/agent").AgentTurnParams): Promise; } export * from "./turn_service.ts"; \ No newline at end of file diff --git a/src/application/ports/index.ts b/src/features/agent/application/ports.ts similarity index 52% rename from src/application/ports/index.ts rename to src/features/agent/application/ports.ts index 759d472..a23a1ab 100644 --- a/src/application/ports/index.ts +++ b/src/features/agent/application/ports.ts @@ -1,6 +1,7 @@ /** - * Port traits (interfaces) to external services. Mirrors `apps/application/src/ports/`. - * Concrete implementations live in the infrastructure layer. + * Port traits (interfaces) that the Agent application layer exposes to + * its infrastructure. Concrete implementations live in + * `features/agent/infrastructure/`. */ import type { ChatMessage, StreamEvent, ToolDef } from "@zesdex/domain"; @@ -31,23 +32,3 @@ export interface ProviderService { signal?: AbortSignal, ): Promise<{ message: ChatMessage; usage: [number, number] | null }>; } - -/** Abstraction for password hashing and verification. */ -export interface PasswordService { - hash(password: string): Promise; - verify(password: string, hash: string): Promise; -} - -/** Abstraction for JWT-based token generation and verification. */ -export interface TokenService { - /** Generate an `[access, refresh]` token pair for the given subject. */ - generateTokens(sub: string): [string, string]; - verifyAccessToken(token: string): string; - verifyRefreshToken(token: string): string; -} - -/** High-level authentication service combining password + token issuance. */ -export interface AuthService { - authenticate(password: string, hash: string): Promise; - issueTokens(sub: string): [string, string]; -} \ No newline at end of file diff --git a/src/application/agent/turn_service.test.ts b/src/features/agent/application/turn_service.test.ts similarity index 100% rename from src/application/agent/turn_service.test.ts rename to src/features/agent/application/turn_service.test.ts diff --git a/src/application/agent/turn_service.ts b/src/features/agent/application/turn_service.ts similarity index 99% rename from src/application/agent/turn_service.ts rename to src/features/agent/application/turn_service.ts index 348220f..2d625e1 100644 --- a/src/application/agent/turn_service.ts +++ b/src/features/agent/application/turn_service.ts @@ -3,23 +3,25 @@ * `apps/application/src/agent/turn_service.rs`. */ import { - type AgentTurnParams, type ChatMessage, type StreamEvent, type ToolCall, type ToolDef, - type TurnEventSink, type JsonValue, systemMessage, userMessage, assistantMessage, toolResultMessage, + sanitizeToolArguments, +} from "@zesdex/domain"; +import { + type AgentTurnParams, + type TurnEventSink, mainAgentPromptWithProjectContext, compactionPrompt, errorRecoveryNote, - sanitizeToolArguments, -} from "@zesdex/domain"; -import type { ProviderService } from "../ports/index.ts"; +} from "@zesdex/agent"; +import type { ProviderService } from "./ports.ts"; import type { ToolExecutor } from "./index.ts"; /* -------------------------------------------------------------------------- */ diff --git a/src/domain/agent/defaults.ts b/src/features/agent/domain/defaults.ts similarity index 100% rename from src/domain/agent/defaults.ts rename to src/features/agent/domain/defaults.ts diff --git a/src/domain/agent/index.ts b/src/features/agent/domain/index.ts similarity index 100% rename from src/domain/agent/index.ts rename to src/features/agent/domain/index.ts diff --git a/src/domain/agent/mod.ts b/src/features/agent/domain/mod.ts similarity index 99% rename from src/domain/agent/mod.ts rename to src/features/agent/domain/mod.ts index 817e6b4..7398ab3 100644 --- a/src/domain/agent/mod.ts +++ b/src/features/agent/domain/mod.ts @@ -2,7 +2,7 @@ * Domain types for agent lifecycle: turn events, session runtime, progress. * Mirrors `apps/domain/src/agent/mod.rs`. */ -import type { ChatMessage, JsonValue, ToolCallResult, UsageStats } from "../core/index.ts"; +import type { ChatMessage, JsonValue, ToolCallResult, UsageStats } from "@zesdex/domain"; import type { AgentProgress } from "./progress.ts"; /** Which kind of caller (main agent vs subagent vs reviewer) is invoking a tool. */ diff --git a/src/domain/agent/progress.ts b/src/features/agent/domain/progress.ts similarity index 100% rename from src/domain/agent/progress.ts rename to src/features/agent/domain/progress.ts diff --git a/src/domain/agent/prompt.ts b/src/features/agent/domain/prompt.ts similarity index 100% rename from src/domain/agent/prompt.ts rename to src/features/agent/domain/prompt.ts diff --git a/src/features/agent/index.ts b/src/features/agent/index.ts new file mode 100644 index 0000000..813307c --- /dev/null +++ b/src/features/agent/index.ts @@ -0,0 +1,5 @@ +/** Agent feature — LLM turn loop, tool-execution runtime, subagent-spawning tools. + * Vertical slice: domain (turn events/runtime) → application (turn service + ports) + * → infrastructure (LLM client + tool registry/executor). */ +export * from "./domain/index.ts"; +export * from "./application/index.ts"; diff --git a/src/features/agent/infrastructure/index.ts b/src/features/agent/infrastructure/index.ts new file mode 100644 index 0000000..684a45e --- /dev/null +++ b/src/features/agent/infrastructure/index.ts @@ -0,0 +1,6 @@ +/** Agent infrastructure — concrete LLM client + tool-execution runtime. + * Consumed by the composition root. */ +export { LlmClient, resolveApiKey } from "./llm/provider.ts"; +export { InfrastructureToolExecutor } from "./tools/executor.ts"; +export { allTools, toolDefs } from "./tools/registry.ts"; +export { type ToolCtx } from "./tools/context.ts"; diff --git a/src/infrastructure/llm/index.ts b/src/features/agent/infrastructure/llm/index.ts similarity index 100% rename from src/infrastructure/llm/index.ts rename to src/features/agent/infrastructure/llm/index.ts diff --git a/src/infrastructure/llm/provider.ts b/src/features/agent/infrastructure/llm/provider.ts similarity index 97% rename from src/infrastructure/llm/provider.ts rename to src/features/agent/infrastructure/llm/provider.ts index ef90790..577ff95 100644 --- a/src/infrastructure/llm/provider.ts +++ b/src/features/agent/infrastructure/llm/provider.ts @@ -8,14 +8,12 @@ import { type StreamEvent, type ToolCall, type ToolDef, - type Settings, - type AppConfig, SseParser, Roles, - DEFAULT_API_BASE, - DEFAULT_MODEL, } from "@zesdex/domain"; -import type { ProviderService } from "@zesdex/application"; +import type { Settings, AppConfig } from "@zesdex/cms"; +import { DEFAULT_API_BASE, DEFAULT_MODEL } from "@zesdex/agent"; +import type { ProviderService } from "../../application/ports.ts"; const DEFAULT_BASE_URL = DEFAULT_API_BASE; const REQUEST_TIMEOUT_MS = 600_000; diff --git a/src/infrastructure/tools/bash_tools.ts b/src/features/agent/infrastructure/tools/bash_tools.ts similarity index 97% rename from src/infrastructure/tools/bash_tools.ts rename to src/features/agent/infrastructure/tools/bash_tools.ts index 3c726d9..679ca16 100644 --- a/src/infrastructure/tools/bash_tools.ts +++ b/src/features/agent/infrastructure/tools/bash_tools.ts @@ -7,7 +7,7 @@ import * as path from "node:path"; import type { JsonValue } from "@zesdex/domain"; import { type Tool, type ToolCtx } from "./mod.ts"; import { argStr } from "./util.ts"; -import { bashControl } from "../bgbash/control.ts"; +import { bashControl } from "./bgbash/control.ts"; /** Get the output of a background bash job by ID. */ export class BashOutput implements Tool { diff --git a/src/infrastructure/best_practice/engine.ts b/src/features/agent/infrastructure/tools/best_practice/engine.ts similarity index 100% rename from src/infrastructure/best_practice/engine.ts rename to src/features/agent/infrastructure/tools/best_practice/engine.ts diff --git a/src/infrastructure/best_practice/tools.ts b/src/features/agent/infrastructure/tools/best_practice/tools.ts similarity index 98% rename from src/infrastructure/best_practice/tools.ts rename to src/features/agent/infrastructure/tools/best_practice/tools.ts index 71d1b57..3a1b57b 100644 --- a/src/infrastructure/best_practice/tools.ts +++ b/src/features/agent/infrastructure/tools/best_practice/tools.ts @@ -2,8 +2,8 @@ * Built-in best-practice tools. Mirrors `tools/best_practice.rs`. */ import type { JsonValue } from "@zesdex/domain"; -import { type Tool, type ToolCtx } from "../tools/mod.ts"; -import { argStr, optStr } from "../tools/util.ts"; +import { type Tool, type ToolCtx } from "../mod.ts"; +import { argStr, optStr } from "../util.ts"; import { BestPracticeEngine } from "./engine.ts"; const engine = new BestPracticeEngine(); diff --git a/src/infrastructure/bgbash/control.ts b/src/features/agent/infrastructure/tools/bgbash/control.ts similarity index 100% rename from src/infrastructure/bgbash/control.ts rename to src/features/agent/infrastructure/tools/bgbash/control.ts diff --git a/src/infrastructure/bgbash/index.ts b/src/features/agent/infrastructure/tools/bgbash/index.ts similarity index 100% rename from src/infrastructure/bgbash/index.ts rename to src/features/agent/infrastructure/tools/bgbash/index.ts diff --git a/src/infrastructure/bgbash/job.ts b/src/features/agent/infrastructure/tools/bgbash/job.ts similarity index 100% rename from src/infrastructure/bgbash/job.ts rename to src/features/agent/infrastructure/tools/bgbash/job.ts diff --git a/src/infrastructure/tools/context.ts b/src/features/agent/infrastructure/tools/context.ts similarity index 97% rename from src/infrastructure/tools/context.ts rename to src/features/agent/infrastructure/tools/context.ts index f254cec..b2d5207 100644 --- a/src/infrastructure/tools/context.ts +++ b/src/features/agent/infrastructure/tools/context.ts @@ -2,7 +2,7 @@ * Tool execution context — shared state passed to every `Tool.run` call. * Mirrors `apps/infrastructure/src/tools/context.rs`. */ -import type { Origin, TurnEvent } from "@zesdex/domain"; +import type { Origin, TurnEvent } from "@zesdex/agent"; /** Graduated check rule from project config. */ export interface GraduatedCheck { diff --git a/src/infrastructure/tools/event_sink.ts b/src/features/agent/infrastructure/tools/event_sink.ts similarity index 89% rename from src/infrastructure/tools/event_sink.ts rename to src/features/agent/infrastructure/tools/event_sink.ts index 48f7b13..fb9609b 100644 --- a/src/infrastructure/tools/event_sink.ts +++ b/src/features/agent/infrastructure/tools/event_sink.ts @@ -2,7 +2,7 @@ * Simple sink adapter that wraps a TurnEvent[] (array-based) into the * TurnEventSink interface, providing a `push` method and a no-op `drain`. */ -import type { TurnEvent, TurnEventSink } from "@zesdex/domain"; +import type { TurnEvent, TurnEventSink } from "@zesdex/agent"; /** * Create a TurnEventSink backed by a plain array. diff --git a/src/infrastructure/tools/executor.ts b/src/features/agent/infrastructure/tools/executor.ts similarity index 100% rename from src/infrastructure/tools/executor.ts rename to src/features/agent/infrastructure/tools/executor.ts diff --git a/src/infrastructure/tools/fs/delete.ts b/src/features/agent/infrastructure/tools/fs/delete.ts similarity index 100% rename from src/infrastructure/tools/fs/delete.ts rename to src/features/agent/infrastructure/tools/fs/delete.ts diff --git a/src/infrastructure/tools/fs/edit.ts b/src/features/agent/infrastructure/tools/fs/edit.ts similarity index 100% rename from src/infrastructure/tools/fs/edit.ts rename to src/features/agent/infrastructure/tools/fs/edit.ts diff --git a/src/infrastructure/tools/fs/read.ts b/src/features/agent/infrastructure/tools/fs/read.ts similarity index 100% rename from src/infrastructure/tools/fs/read.ts rename to src/features/agent/infrastructure/tools/fs/read.ts diff --git a/src/infrastructure/tools/fs/write.ts b/src/features/agent/infrastructure/tools/fs/write.ts similarity index 100% rename from src/infrastructure/tools/fs/write.ts rename to src/features/agent/infrastructure/tools/fs/write.ts diff --git a/src/infrastructure/tools/git/git_cred.ts b/src/features/agent/infrastructure/tools/git/git_cred.ts similarity index 100% rename from src/infrastructure/tools/git/git_cred.ts rename to src/features/agent/infrastructure/tools/git/git_cred.ts diff --git a/src/infrastructure/tools/git/git_operator.ts b/src/features/agent/infrastructure/tools/git/git_operator.ts similarity index 100% rename from src/infrastructure/tools/git/git_operator.ts rename to src/features/agent/infrastructure/tools/git/git_operator.ts diff --git a/src/infrastructure/tools/git/git_worktree.ts b/src/features/agent/infrastructure/tools/git/git_worktree.ts similarity index 100% rename from src/infrastructure/tools/git/git_worktree.ts rename to src/features/agent/infrastructure/tools/git/git_worktree.ts diff --git a/src/infrastructure/tools/graduated.ts b/src/features/agent/infrastructure/tools/graduated.ts similarity index 100% rename from src/infrastructure/tools/graduated.ts rename to src/features/agent/infrastructure/tools/graduated.ts diff --git a/src/infrastructure/tools/memory/forget.ts b/src/features/agent/infrastructure/tools/memory/forget.ts similarity index 91% rename from src/infrastructure/tools/memory/forget.ts rename to src/features/agent/infrastructure/tools/memory/forget.ts index 419462e..a983496 100644 --- a/src/infrastructure/tools/memory/forget.ts +++ b/src/features/agent/infrastructure/tools/memory/forget.ts @@ -2,7 +2,7 @@ * Delete a memory by name. Mirrors `tools/memory/forget.rs`. */ import type { JsonValue } from "@zesdex/domain"; -import { MarkdownMemoryRepository } from "../../persistence/cms/memory_repo.ts"; +import { MarkdownMemoryRepository } from "@zesdex/cms"; import { type Tool, type ToolCtx } from "../mod.ts"; import { argStr } from "../util.ts"; import { resolveMemoryDir } from "./mod.ts"; diff --git a/src/infrastructure/tools/memory/mod.ts b/src/features/agent/infrastructure/tools/memory/mod.ts similarity index 100% rename from src/infrastructure/tools/memory/mod.ts rename to src/features/agent/infrastructure/tools/memory/mod.ts diff --git a/src/infrastructure/tools/memory/recall.ts b/src/features/agent/infrastructure/tools/memory/recall.ts similarity index 96% rename from src/infrastructure/tools/memory/recall.ts rename to src/features/agent/infrastructure/tools/memory/recall.ts index 1d24b3a..1b3e57a 100644 --- a/src/infrastructure/tools/memory/recall.ts +++ b/src/features/agent/infrastructure/tools/memory/recall.ts @@ -2,7 +2,7 @@ * Recall previously saved memories. Mirrors `tools/memory/recall.rs`. */ import type { JsonValue } from "@zesdex/domain"; -import { MarkdownMemoryRepository } from "../../persistence/cms/memory_repo.ts"; +import { MarkdownMemoryRepository } from "@zesdex/cms"; import { type Tool, type ToolCtx } from "../mod.ts"; import { optStr } from "../util.ts"; import { resolveMemoryDir } from "./mod.ts"; diff --git a/src/infrastructure/tools/memory/remember.ts b/src/features/agent/infrastructure/tools/memory/remember.ts similarity index 95% rename from src/infrastructure/tools/memory/remember.ts rename to src/features/agent/infrastructure/tools/memory/remember.ts index 6163d50..7e447e3 100644 --- a/src/infrastructure/tools/memory/remember.ts +++ b/src/features/agent/infrastructure/tools/memory/remember.ts @@ -2,7 +2,7 @@ * Remember a lesson or fact as persistent memory. Mirrors `tools/memory/remember.rs`. */ import type { JsonValue } from "@zesdex/domain"; -import { MarkdownMemoryRepository } from "../../persistence/cms/memory_repo.ts"; +import { MarkdownMemoryRepository } from "@zesdex/cms"; import { type Tool, type ToolCtx } from "../mod.ts"; import { argStr, optStr } from "../util.ts"; import { resolveMemoryDir } from "./mod.ts"; diff --git a/src/infrastructure/tools/mod.ts b/src/features/agent/infrastructure/tools/mod.ts similarity index 100% rename from src/infrastructure/tools/mod.ts rename to src/features/agent/infrastructure/tools/mod.ts diff --git a/src/infrastructure/tools/parallel_delegate.ts b/src/features/agent/infrastructure/tools/parallel_delegate.ts similarity index 97% rename from src/infrastructure/tools/parallel_delegate.ts rename to src/features/agent/infrastructure/tools/parallel_delegate.ts index 8590bf6..f09a2c8 100644 --- a/src/infrastructure/tools/parallel_delegate.ts +++ b/src/features/agent/infrastructure/tools/parallel_delegate.ts @@ -59,7 +59,7 @@ export class ParallelDelegate implements Tool { // Delegate to subagent engine if available, else report the breakdown. try { - const { runParallelDelegation } = await import("../subagent/delegate.ts"); + const { runParallelDelegation } = await import("../../../subagent/infrastructure/delegate.ts"); return await runParallelDelegation(task, directives, synthesize, ctx); } catch (e) { const msg = (e as Error).message; diff --git a/src/infrastructure/tools/plan.ts b/src/features/agent/infrastructure/tools/plan.ts similarity index 95% rename from src/infrastructure/tools/plan.ts rename to src/features/agent/infrastructure/tools/plan.ts index 952e52f..f58f8e3 100644 --- a/src/infrastructure/tools/plan.ts +++ b/src/features/agent/infrastructure/tools/plan.ts @@ -1,7 +1,8 @@ /** Plan management tools — enter and mark ready. Mirrors `tools/plan.rs`. */ import * as fs from "node:fs"; import * as path from "node:path"; -import type { JsonValue, TurnEvent } from "@zesdex/domain"; +import type { JsonValue } from "@zesdex/domain"; +import type { TurnEvent } from "@zesdex/agent"; import { type Tool, type ToolCtx } from "./mod.ts"; import { argStr } from "./util.ts"; diff --git a/src/infrastructure/tools/registry.test.ts b/src/features/agent/infrastructure/tools/registry.test.ts similarity index 100% rename from src/infrastructure/tools/registry.test.ts rename to src/features/agent/infrastructure/tools/registry.test.ts diff --git a/src/infrastructure/tools/registry.ts b/src/features/agent/infrastructure/tools/registry.ts similarity index 97% rename from src/infrastructure/tools/registry.ts rename to src/features/agent/infrastructure/tools/registry.ts index a54a6f7..f6f84f7 100644 --- a/src/infrastructure/tools/registry.ts +++ b/src/features/agent/infrastructure/tools/registry.ts @@ -25,7 +25,7 @@ import { Cd, DirList, DirCacheUpdate, Pong, Todowrite, Todofinish } from "./util import { WebSearch } from "./web_search.ts"; import { SemanticSearch, RebuildIndex, ListSymbols } from "./semantic/index.ts"; import { ParallelDelegate } from "./parallel_delegate.ts"; -import { BestPractice, CommitConvention } from "../best_practice/tools.ts"; +import { BestPractice, CommitConvention } from "./best_practice/tools.ts"; /** Construct one instance of every built-in tool. */ export function allTools(): Tool[] { diff --git a/src/infrastructure/tools/search/glob.ts b/src/features/agent/infrastructure/tools/search/glob.ts similarity index 100% rename from src/infrastructure/tools/search/glob.ts rename to src/features/agent/infrastructure/tools/search/glob.ts diff --git a/src/infrastructure/tools/search/grep.ts b/src/features/agent/infrastructure/tools/search/grep.ts similarity index 100% rename from src/infrastructure/tools/search/grep.ts rename to src/features/agent/infrastructure/tools/search/grep.ts diff --git a/src/infrastructure/tools/semantic/index.ts b/src/features/agent/infrastructure/tools/semantic/index.ts similarity index 100% rename from src/infrastructure/tools/semantic/index.ts rename to src/features/agent/infrastructure/tools/semantic/index.ts diff --git a/src/infrastructure/tools/sequential_think.ts b/src/features/agent/infrastructure/tools/sequential_think.ts similarity index 100% rename from src/infrastructure/tools/sequential_think.ts rename to src/features/agent/infrastructure/tools/sequential_think.ts diff --git a/src/infrastructure/tools/shell/bash.ts b/src/features/agent/infrastructure/tools/shell/bash.ts similarity index 94% rename from src/infrastructure/tools/shell/bash.ts rename to src/features/agent/infrastructure/tools/shell/bash.ts index 120a2f9..b931651 100644 --- a/src/infrastructure/tools/shell/bash.ts +++ b/src/features/agent/infrastructure/tools/shell/bash.ts @@ -39,8 +39,8 @@ export class Bash implements Tool { if (runInBackground) { // Background jobs handled via bgbash registry - const { spawnBashJob } = await import("../../bgbash/job.ts"); - const { bashControl } = await import("../../bgbash/control.ts"); + const { spawnBashJob } = await import("../bgbash/job.ts"); + const { bashControl } = await import("../bgbash/control.ts"); const job = spawnBashJob(cmd); bashControl().register(job); return `Background job: ${job.id}`; diff --git a/src/infrastructure/tools/shell/credentials.ts b/src/features/agent/infrastructure/tools/shell/credentials.ts similarity index 100% rename from src/infrastructure/tools/shell/credentials.ts rename to src/features/agent/infrastructure/tools/shell/credentials.ts diff --git a/src/infrastructure/tools/shell/git.ts b/src/features/agent/infrastructure/tools/shell/git.ts similarity index 100% rename from src/infrastructure/tools/shell/git.ts rename to src/features/agent/infrastructure/tools/shell/git.ts diff --git a/src/infrastructure/tools/spawn.ts b/src/features/agent/infrastructure/tools/spawn.ts similarity index 93% rename from src/infrastructure/tools/spawn.ts rename to src/features/agent/infrastructure/tools/spawn.ts index 4b8803c..4f62635 100644 --- a/src/infrastructure/tools/spawn.ts +++ b/src/features/agent/infrastructure/tools/spawn.ts @@ -33,7 +33,7 @@ export class SpawnAgents implements Tool { async run(ctx: ToolCtx, args: JsonValue): Promise { const agents = reqArray(args, "agents"); try { - const { spawnAgents } = await import("../subagent/spawn_tools.ts"); + const { spawnAgents } = await import("../../../subagent/infrastructure/spawn_tools.ts"); return await spawnAgents(agents as Array<{ directive: string; access: string }>, ctx); } catch (e) { const msg = (e as Error).message; @@ -71,7 +71,7 @@ export class SpawnPipeline implements Tool { async run(ctx: ToolCtx, args: JsonValue): Promise { const stages = reqArray(args, "stages"); try { - const { spawnPipeline } = await import("../subagent/spawn_tools.ts"); + const { spawnPipeline } = await import("../../../subagent/infrastructure/spawn_tools.ts"); return await spawnPipeline(stages as Array<{ directive: string; access: string }>, ctx); } catch (e) { const msg = (e as Error).message; diff --git a/src/infrastructure/tools/util.ts b/src/features/agent/infrastructure/tools/util.ts similarity index 100% rename from src/infrastructure/tools/util.ts rename to src/features/agent/infrastructure/tools/util.ts diff --git a/src/infrastructure/tools/utility/cd.ts b/src/features/agent/infrastructure/tools/utility/cd.ts similarity index 100% rename from src/infrastructure/tools/utility/cd.ts rename to src/features/agent/infrastructure/tools/utility/cd.ts diff --git a/src/infrastructure/tools/utility/dir_cache_update.ts b/src/features/agent/infrastructure/tools/utility/dir_cache_update.ts similarity index 100% rename from src/infrastructure/tools/utility/dir_cache_update.ts rename to src/features/agent/infrastructure/tools/utility/dir_cache_update.ts diff --git a/src/infrastructure/tools/utility/dir_list.ts b/src/features/agent/infrastructure/tools/utility/dir_list.ts similarity index 100% rename from src/infrastructure/tools/utility/dir_list.ts rename to src/features/agent/infrastructure/tools/utility/dir_list.ts diff --git a/src/infrastructure/tools/utility/mod.ts b/src/features/agent/infrastructure/tools/utility/mod.ts similarity index 100% rename from src/infrastructure/tools/utility/mod.ts rename to src/features/agent/infrastructure/tools/utility/mod.ts diff --git a/src/infrastructure/tools/utility/pong.ts b/src/features/agent/infrastructure/tools/utility/pong.ts similarity index 100% rename from src/infrastructure/tools/utility/pong.ts rename to src/features/agent/infrastructure/tools/utility/pong.ts diff --git a/src/infrastructure/tools/utility/todofinish.ts b/src/features/agent/infrastructure/tools/utility/todofinish.ts similarity index 93% rename from src/infrastructure/tools/utility/todofinish.ts rename to src/features/agent/infrastructure/tools/utility/todofinish.ts index 3c61e0e..5d01d6b 100644 --- a/src/infrastructure/tools/utility/todofinish.ts +++ b/src/features/agent/infrastructure/tools/utility/todofinish.ts @@ -1,7 +1,8 @@ /** Mark a TODO item as finished. Mirrors `utility/todofinish.rs`. */ import * as fs from "node:fs"; import * as path from "node:path"; -import type { JsonValue, TurnEvent } from "@zesdex/domain"; +import type { JsonValue } from "@zesdex/domain"; +import type { TurnEvent } from "@zesdex/agent"; import { type Tool, type ToolCtx } from "../mod.ts"; import { argStr } from "../util.ts"; diff --git a/src/infrastructure/tools/utility/todowrite.ts b/src/features/agent/infrastructure/tools/utility/todowrite.ts similarity index 92% rename from src/infrastructure/tools/utility/todowrite.ts rename to src/features/agent/infrastructure/tools/utility/todowrite.ts index 2f5ec74..b277bc1 100644 --- a/src/infrastructure/tools/utility/todowrite.ts +++ b/src/features/agent/infrastructure/tools/utility/todowrite.ts @@ -1,7 +1,8 @@ /** Write a TODO item. Mirrors `utility/todowrite.rs`. */ import * as fs from "node:fs"; import * as path from "node:path"; -import type { JsonValue, TurnEvent } from "@zesdex/domain"; +import type { JsonValue } from "@zesdex/domain"; +import type { TurnEvent } from "@zesdex/agent"; import { type Tool, type ToolCtx } from "../mod.ts"; import { argStr, optStr } from "../util.ts"; diff --git a/src/infrastructure/tools/web_search.ts b/src/features/agent/infrastructure/tools/web_search.ts similarity index 100% rename from src/infrastructure/tools/web_search.ts rename to src/features/agent/infrastructure/tools/web_search.ts diff --git a/src/infrastructure/tools/workflow.ts b/src/features/agent/infrastructure/tools/workflow.ts similarity index 95% rename from src/infrastructure/tools/workflow.ts rename to src/features/agent/infrastructure/tools/workflow.ts index e9c4436..5e9a126 100644 --- a/src/infrastructure/tools/workflow.ts +++ b/src/features/agent/infrastructure/tools/workflow.ts @@ -26,7 +26,7 @@ export class WorkflowRun implements Tool { async run(ctx: ToolCtx, args: JsonValue): Promise { const yaml = argStr(args, "workflow_yaml"); try { - const { executeWorkflow } = await import("../workflow/index.ts"); + const { executeWorkflow } = await import("../../../workflow/infrastructure/index.ts"); return await executeWorkflow(yaml, ctx); } catch (e) { const msg = (e as Error).message; @@ -108,7 +108,7 @@ export class HiveMind implements Tool { async run(ctx: ToolCtx, args: JsonValue): Promise { try { - const { executeHiveMind } = await import("../workflow/hive_mind.ts"); + const { executeHiveMind } = await import("../../../workflow/infrastructure/hive_mind.ts"); return await executeHiveMind(args, ctx); } catch (e) { const msg = (e as Error).message; diff --git a/src/application/cms/conversation_service.ts b/src/features/cms/application/conversation_service.ts similarity index 95% rename from src/application/cms/conversation_service.ts rename to src/features/cms/application/conversation_service.ts index 6c4ac3e..9ae4659 100644 --- a/src/application/cms/conversation_service.ts +++ b/src/features/cms/application/conversation_service.ts @@ -2,7 +2,7 @@ * Conversation use-case. Mirrors `apps/application/src/cms/conversation_service.rs`. */ import * as path from "node:path"; -import { type Conversation, type ConversationRepository, type ChatMessage, pushMessage } from "@zesdex/domain"; +import { type Conversation, type ConversationRepository, type ChatMessage, pushMessage } from "@zesdex/cms"; /** Service implementation for conversation CRUD operations. */ export class ConversationServiceImpl { diff --git a/src/application/cms/index.ts b/src/features/cms/application/index.ts similarity index 100% rename from src/application/cms/index.ts rename to src/features/cms/application/index.ts diff --git a/src/application/cms/memory_service.ts b/src/features/cms/application/memory_service.ts similarity index 89% rename from src/application/cms/memory_service.ts rename to src/features/cms/application/memory_service.ts index 6a75609..90756aa 100644 --- a/src/application/cms/memory_service.ts +++ b/src/features/cms/application/memory_service.ts @@ -1,7 +1,7 @@ /** * Memory use-case. Mirrors `apps/application/src/cms/memory_service.rs`. */ -import { type Memory, type MemoryRepository } from "@zesdex/domain"; +import { type Memory, type MemoryRepository } from "@zesdex/cms"; /** Service implementation for memory CRUD operations. */ export class MemoryServiceImpl { diff --git a/src/application/cms/settings_service.ts b/src/features/cms/application/settings_service.ts similarity index 97% rename from src/application/cms/settings_service.ts rename to src/features/cms/application/settings_service.ts index ff2dd5c..eaa841b 100644 --- a/src/application/cms/settings_service.ts +++ b/src/features/cms/application/settings_service.ts @@ -7,7 +7,7 @@ import { type ProviderConfig, type Settings, type SettingsRepository, -} from "@zesdex/domain"; +} from "@zesdex/cms"; /** Service implementation for settings and app-config operations. */ export class SettingsServiceImpl { diff --git a/src/domain/cms/app_config.ts b/src/features/cms/domain/app_config.ts similarity index 96% rename from src/domain/cms/app_config.ts rename to src/features/cms/domain/app_config.ts index aada52d..09e1eea 100644 --- a/src/domain/cms/app_config.ts +++ b/src/features/cms/domain/app_config.ts @@ -1,7 +1,7 @@ /** * Application configuration entities. Mirrors `app_config.rs`. */ -import { DEFAULT_CONTEXT_WINDOW } from "../agent/defaults.ts"; +import { DEFAULT_CONTEXT_WINDOW } from "@zesdex/agent"; /** Top-level application configuration. */ export interface AppConfig { diff --git a/src/domain/cms/commands.ts b/src/features/cms/domain/commands.ts similarity index 100% rename from src/domain/cms/commands.ts rename to src/features/cms/domain/commands.ts diff --git a/src/features/cms/domain/conversation.ts b/src/features/cms/domain/conversation.ts new file mode 100644 index 0000000..30528a2 --- /dev/null +++ b/src/features/cms/domain/conversation.ts @@ -0,0 +1,7 @@ +/** + * Re-export of conversation types from core (matches Rust `cms/conversation.rs`). + */ +export type { Conversation } from "@zesdex/domain"; +export type { ChatMessage, Role } from "@zesdex/domain"; +export { newConversation, pushMessage, rebuildSystem, toApiMessages } from "@zesdex/domain"; +export { Roles } from "@zesdex/domain"; \ No newline at end of file diff --git a/src/domain/cms/edit_log.ts b/src/features/cms/domain/edit_log.ts similarity index 100% rename from src/domain/cms/edit_log.ts rename to src/features/cms/domain/edit_log.ts diff --git a/src/domain/cms/error.ts b/src/features/cms/domain/error.ts similarity index 95% rename from src/domain/cms/error.ts rename to src/features/cms/domain/error.ts index c81d982..cef6268 100644 --- a/src/domain/cms/error.ts +++ b/src/features/cms/domain/error.ts @@ -1,7 +1,7 @@ /** * Domain error types for the CMS module. Mirrors `cms/error.rs`. */ -import type { DomainError } from "../core/error.ts"; +import type { DomainError } from "@zesdex/domain"; /** Shared repository error type for CMS persistence. */ export type RepositoryError = DomainError; diff --git a/src/domain/cms/index.ts b/src/features/cms/domain/index.ts similarity index 100% rename from src/domain/cms/index.ts rename to src/features/cms/domain/index.ts diff --git a/src/domain/cms/memory.ts b/src/features/cms/domain/memory.ts similarity index 100% rename from src/domain/cms/memory.ts rename to src/features/cms/domain/memory.ts diff --git a/src/domain/cms/repository.ts b/src/features/cms/domain/repository.ts similarity index 97% rename from src/domain/cms/repository.ts rename to src/features/cms/domain/repository.ts index bba103d..1cbe134 100644 --- a/src/domain/cms/repository.ts +++ b/src/features/cms/domain/repository.ts @@ -7,7 +7,7 @@ import type { AppConfig } from "./app_config.ts"; import type { EditLog, EditLogEntry } from "./edit_log.ts"; import type { Memory } from "./memory.ts"; import type { Settings } from "./settings.ts"; -import type { Conversation } from "../core/conversation.ts"; +import type { Conversation } from "@zesdex/domain"; /** Persistence contract for `Settings`. */ export interface SettingsRepository { diff --git a/src/domain/cms/service.ts b/src/features/cms/domain/service.ts similarity index 90% rename from src/domain/cms/service.ts rename to src/features/cms/domain/service.ts index 1c0de05..6602a29 100644 --- a/src/domain/cms/service.ts +++ b/src/features/cms/domain/service.ts @@ -2,8 +2,8 @@ * Service trait definitions — use-case boundaries for CMS operations. * Mirrors `apps/domain/src/cms/service.rs`. Implemented by the application layer. */ -import type { Conversation } from "../core/conversation.ts"; -import type { ChatMessage } from "../core/message.ts"; +import type { Conversation } from "@zesdex/domain"; +import type { ChatMessage } from "@zesdex/domain"; import type { Memory } from "./memory.ts"; import type { Settings } from "./settings.ts"; import type { ProviderConfig } from "./app_config.ts"; diff --git a/src/domain/cms/settings.test.ts b/src/features/cms/domain/settings.test.ts similarity index 100% rename from src/domain/cms/settings.test.ts rename to src/features/cms/domain/settings.test.ts diff --git a/src/domain/cms/settings.ts b/src/features/cms/domain/settings.ts similarity index 100% rename from src/domain/cms/settings.ts rename to src/features/cms/domain/settings.ts diff --git a/src/features/cms/index.ts b/src/features/cms/index.ts new file mode 100644 index 0000000..5efe877 --- /dev/null +++ b/src/features/cms/index.ts @@ -0,0 +1,5 @@ +/** CMS feature — configuration, memory, conversation & settings persistence. + * Vertical slice: domain (types) → application (services) → infrastructure (repos). */ +export * from "./domain/index.ts"; +export * from "./application/index.ts"; +export * from "./infrastructure/persistence/index.ts"; diff --git a/src/infrastructure/persistence/cms/app_config_repo.ts b/src/features/cms/infrastructure/persistence/app_config_repo.ts similarity index 98% rename from src/infrastructure/persistence/cms/app_config_repo.ts rename to src/features/cms/infrastructure/persistence/app_config_repo.ts index 4f9ac9e..e41c14e 100644 --- a/src/infrastructure/persistence/cms/app_config_repo.ts +++ b/src/features/cms/infrastructure/persistence/app_config_repo.ts @@ -11,8 +11,8 @@ import { type ModelRole, type ProviderConfig, newAppConfig, -} from "@zesdex/domain"; -import { writeJsonAtomic } from "../../utils.ts"; +} from "@zesdex/cms"; +import { writeJsonAtomic } from "@zesdex/shared"; interface ClaudeEnv { ANTHROPIC_BASE_URL?: string; diff --git a/src/infrastructure/persistence/cms/conversation_repo.ts b/src/features/cms/infrastructure/persistence/conversation_repo.ts similarity index 92% rename from src/infrastructure/persistence/cms/conversation_repo.ts rename to src/features/cms/infrastructure/persistence/conversation_repo.ts index 0a4f341..0f4f62a 100644 --- a/src/infrastructure/persistence/cms/conversation_repo.ts +++ b/src/features/cms/infrastructure/persistence/conversation_repo.ts @@ -1,8 +1,8 @@ /** JSON file–backed `ConversationRepository`. Path: `/conversation.json`. */ import * as fs from "node:fs"; import * as path from "node:path"; -import { type Conversation, type ConversationRepository, newConversation } from "@zesdex/domain"; -import { writeJsonAtomic } from "../../utils.ts"; +import { type Conversation, type ConversationRepository, newConversation } from "@zesdex/cms"; +import { writeJsonAtomic } from "@zesdex/shared"; /** Persists `Conversation` as JSON at `/conversation.json`. */ export class JsonConversationRepository implements ConversationRepository { diff --git a/src/infrastructure/persistence/cms/edit_log_repo.ts b/src/features/cms/infrastructure/persistence/edit_log_repo.ts similarity index 98% rename from src/infrastructure/persistence/cms/edit_log_repo.ts rename to src/features/cms/infrastructure/persistence/edit_log_repo.ts index 4dc894b..7612519 100644 --- a/src/infrastructure/persistence/cms/edit_log_repo.ts +++ b/src/features/cms/infrastructure/persistence/edit_log_repo.ts @@ -6,7 +6,7 @@ import { type EditLogRepository, MAX_MEMORY_ENTRIES, EditLog, -} from "@zesdex/domain"; +} from "@zesdex/cms"; /** File-based `EditLogRepository` that reads/writes `edits.jsonl`. */ export class JsonlEditLogRepository implements EditLogRepository { diff --git a/src/infrastructure/persistence/cms/index.ts b/src/features/cms/infrastructure/persistence/index.ts similarity index 100% rename from src/infrastructure/persistence/cms/index.ts rename to src/features/cms/infrastructure/persistence/index.ts diff --git a/src/infrastructure/persistence/cms/memory_repo.ts b/src/features/cms/infrastructure/persistence/memory_repo.ts similarity index 99% rename from src/infrastructure/persistence/cms/memory_repo.ts rename to src/features/cms/infrastructure/persistence/memory_repo.ts index 9f6fde7..f15dc5e 100644 --- a/src/infrastructure/persistence/cms/memory_repo.ts +++ b/src/features/cms/infrastructure/persistence/memory_repo.ts @@ -4,7 +4,7 @@ */ import * as fs from "node:fs"; import * as path from "node:path"; -import { type Memory, type MemoryRepository, memoryPath } from "@zesdex/domain"; +import { type Memory, type MemoryRepository, memoryPath } from "@zesdex/cms"; import { randomUUID } from "node:crypto"; /** Escape newlines so they do not break line-oriented frontmatter. */ diff --git a/src/infrastructure/persistence/cms/rewind_blob_repo.ts b/src/features/cms/infrastructure/persistence/rewind_blob_repo.ts similarity index 97% rename from src/infrastructure/persistence/cms/rewind_blob_repo.ts rename to src/features/cms/infrastructure/persistence/rewind_blob_repo.ts index 4dd7a22..f136e20 100644 --- a/src/infrastructure/persistence/cms/rewind_blob_repo.ts +++ b/src/features/cms/infrastructure/persistence/rewind_blob_repo.ts @@ -5,7 +5,7 @@ import * as fs from "node:fs"; import * as path from "node:path"; import * as crypto from "node:crypto"; -import { type RewindBlobRepository } from "@zesdex/domain"; +import { type RewindBlobRepository } from "@zesdex/cms"; interface BlobIndexEntry { key: string; diff --git a/src/infrastructure/persistence/cms/settings_repo.ts b/src/features/cms/infrastructure/persistence/settings_repo.ts similarity index 93% rename from src/infrastructure/persistence/cms/settings_repo.ts rename to src/features/cms/infrastructure/persistence/settings_repo.ts index 81877c6..6bccaf0 100644 --- a/src/infrastructure/persistence/cms/settings_repo.ts +++ b/src/features/cms/infrastructure/persistence/settings_repo.ts @@ -1,8 +1,8 @@ /** JSON file–backed `SettingsRepository`. Path: `/settings.json`. */ import * as fs from "node:fs"; import * as path from "node:path"; -import { type Settings, type SettingsRepository, newSettings } from "@zesdex/domain"; -import { writeJsonAtomic } from "../../utils.ts"; +import { type Settings, type SettingsRepository, newSettings } from "@zesdex/cms"; +import { writeJsonAtomic } from "@zesdex/shared"; /** Persists `Settings` as pretty-printed JSON at `/settings.json`. */ export class JsonSettingsRepository implements SettingsRepository { diff --git a/src/domain/subagent/mod.ts b/src/features/subagent/domain/mod.ts similarity index 100% rename from src/domain/subagent/mod.ts rename to src/features/subagent/domain/mod.ts diff --git a/src/features/subagent/index.ts b/src/features/subagent/index.ts new file mode 100644 index 0000000..3d4eebc --- /dev/null +++ b/src/features/subagent/index.ts @@ -0,0 +1,4 @@ +/** Subagent feature — subagent orchestration (spawn/delegate), access-tier division, + * and the subagent runner engine. Depends on the agent feature's tool runtime. */ +export * from "./domain/mod.ts"; +export * from "./infrastructure/index.ts"; diff --git a/src/infrastructure/subagent/config_resolver.ts b/src/features/subagent/infrastructure/config_resolver.ts similarity index 93% rename from src/infrastructure/subagent/config_resolver.ts rename to src/features/subagent/infrastructure/config_resolver.ts index 7dc1e6a..1fd05a2 100644 --- a/src/infrastructure/subagent/config_resolver.ts +++ b/src/features/subagent/infrastructure/config_resolver.ts @@ -3,7 +3,7 @@ * Loads Settings + AppConfig from the store directory and resolves * provider, model, baseUrl, and apiKey. */ -import type { Settings, AppConfig } from "@zesdex/domain"; +import type { Settings, AppConfig } from "@zesdex/cms"; import { resolveSubagentProvider } from "./provider.ts"; /** Resolved LLM configuration for a subagent. */ @@ -19,7 +19,7 @@ export interface ResolvedLlmConfig { */ export async function resolveConfig(): Promise { const { newStore } = await import("@zesdex/domain"); - const { JsonSettingsRepository, JsonAppConfigRepository } = await import("../persistence/index.ts"); + const { JsonSettingsRepository, JsonAppConfigRepository } = await import("@zesdex/cms"); const store = newStore(); const settingsRepo = new JsonSettingsRepository(); const appConfigRepo = new JsonAppConfigRepository(); diff --git a/src/infrastructure/subagent/context.ts b/src/features/subagent/infrastructure/context.ts similarity index 92% rename from src/infrastructure/subagent/context.ts rename to src/features/subagent/infrastructure/context.ts index a254ffe..a7bf881 100644 --- a/src/infrastructure/subagent/context.ts +++ b/src/features/subagent/infrastructure/context.ts @@ -2,8 +2,8 @@ * Subagent execution context — wraps the shared state needed for a subagent. * Mirrors `apps/infrastructure/src/subagent/context.rs`. */ -import type { ToolCtx } from "../tools/context.ts"; -import type { AccessTier } from "@zesdex/domain"; +import type { ToolCtx } from "../../agent/infrastructure/tools/context.ts"; +import type { AccessTier } from "@zesdex/subagent"; /** * Context for a single subagent execution. diff --git a/src/infrastructure/subagent/delegate.ts b/src/features/subagent/infrastructure/delegate.ts similarity index 93% rename from src/infrastructure/subagent/delegate.ts rename to src/features/subagent/infrastructure/delegate.ts index e096f73..637fea2 100644 --- a/src/infrastructure/subagent/delegate.ts +++ b/src/features/subagent/infrastructure/delegate.ts @@ -2,8 +2,8 @@ * Parallel delegation helper used by parallel_delegate tool. Ported in 3c. * Mirrors `apps/infrastructure/src/subagent/delegate.rs`. */ -import type { ToolCtx } from "../tools/mod.ts"; -import { runAgent } from "../tools/engine.ts"; +import type { ToolCtx } from "../../agent/infrastructure/tools/mod.ts"; +import { runAgent } from "./engine.ts"; import { resolveConfig } from "./config_resolver.ts"; import { buildProviderService } from "./http_provider.ts"; diff --git a/src/infrastructure/tools/division.ts b/src/features/subagent/infrastructure/division.ts similarity index 88% rename from src/infrastructure/tools/division.ts rename to src/features/subagent/infrastructure/division.ts index 30a3991..ed013b9 100644 --- a/src/infrastructure/tools/division.ts +++ b/src/features/subagent/infrastructure/division.ts @@ -6,9 +6,9 @@ * subset of all built-in tools allowed at that tier → those tools are passed * to the engine for the subagent's tool-execution loop. */ -import type { Tool } from "./mod.ts"; -import { allTools } from "./registry.ts"; -import type { AccessTier } from "@zesdex/domain"; +import type { Tool } from "../../agent/infrastructure/tools/mod.ts"; +import { allTools } from "../../agent/infrastructure/tools/registry.ts"; +import type { AccessTier } from "@zesdex/subagent"; /** * Read-only tool names available at the `Read` access tier. diff --git a/src/infrastructure/tools/engine.ts b/src/features/subagent/infrastructure/engine.ts similarity index 97% rename from src/infrastructure/tools/engine.ts rename to src/features/subagent/infrastructure/engine.ts index 4dab54b..353df0e 100644 --- a/src/infrastructure/tools/engine.ts +++ b/src/features/subagent/infrastructure/engine.ts @@ -7,21 +7,23 @@ * tool calls) or the iteration limit is reached. */ import { - type AgentProgress, type ChatMessage, type JsonValue, type ToolCall, type ToolDef, - type TurnEvent, - type TurnEventSink, systemMessage, - errorRecoveryNote, - subagentDirective, Roles, } from "@zesdex/domain"; -import type { Tool } from "./mod.ts"; -import type { ToolCtx } from "./context.ts"; -import { toolDefs, toolIsParallelSafe } from "./registry.ts"; +import { + type AgentProgress, + type TurnEvent, + type TurnEventSink, + errorRecoveryNote, + subagentDirective, +} from "@zesdex/agent"; +import type { Tool } from "../../agent/infrastructure/tools/mod.ts"; +import type { ToolCtx } from "../../agent/infrastructure/tools/context.ts"; +import { toolDefs, toolIsParallelSafe } from "../../agent/infrastructure/tools/registry.ts"; import { toolsFor } from "./division.ts"; /** Maximum number of tool-call iterations before the engine gives up. */ diff --git a/src/infrastructure/subagent/http_provider.ts b/src/features/subagent/infrastructure/http_provider.ts similarity index 97% rename from src/infrastructure/subagent/http_provider.ts rename to src/features/subagent/infrastructure/http_provider.ts index a464cde..4a65ecf 100644 --- a/src/infrastructure/subagent/http_provider.ts +++ b/src/features/subagent/infrastructure/http_provider.ts @@ -4,7 +4,7 @@ * /chat/completions endpoint. */ import type { ChatMessage, Role, ToolCall } from "@zesdex/domain"; -import type { SubagentProviderService } from "../tools/engine.ts"; +import type { SubagentProviderService } from "./engine.ts"; interface RawToolCall { id: string; diff --git a/src/infrastructure/subagent/index.ts b/src/features/subagent/infrastructure/index.ts similarity index 81% rename from src/infrastructure/subagent/index.ts rename to src/features/subagent/infrastructure/index.ts index 82ea20a..e1bad00 100644 --- a/src/infrastructure/subagent/index.ts +++ b/src/features/subagent/infrastructure/index.ts @@ -2,8 +2,8 @@ * Subagent engine — ported in sub-phase 3c. * Mirrors `apps/infrastructure/src/subagent/mod.rs`. */ -export { runAgent, type SubagentProviderService, MAX_ITERATIONS, TOOL_OUTPUT_MAX_CHARS } from "../tools/engine.ts"; -export { toolsFor } from "../tools/division.ts"; +export { runAgent, type SubagentProviderService, MAX_ITERATIONS, TOOL_OUTPUT_MAX_CHARS } from "./engine.ts"; +export { toolsFor } from "./division.ts"; export { resolveSubagentProvider, resolveSubagentConfig } from "./provider.ts"; export { newSubagentContext, type SubagentContext } from "./context.ts"; export { buildProviderService } from "./http_provider.ts"; diff --git a/src/infrastructure/subagent/provider.ts b/src/features/subagent/infrastructure/provider.ts similarity index 99% rename from src/infrastructure/subagent/provider.ts rename to src/features/subagent/infrastructure/provider.ts index 703f86c..c19feca 100644 --- a/src/infrastructure/subagent/provider.ts +++ b/src/features/subagent/infrastructure/provider.ts @@ -7,7 +7,7 @@ * + model → `SubagentProvider` wraps that pair around a provider service * for use inside the subagent engine loop. */ -import type { Settings, AppConfig, ProviderConfig } from "@zesdex/domain"; +import type { Settings, AppConfig, ProviderConfig } from "@zesdex/cms"; /** Provider configuration resolved from settings + app_config. */ export interface SubagentProvider { diff --git a/src/infrastructure/subagent/spawn_tools.ts b/src/features/subagent/infrastructure/spawn_tools.ts similarity index 94% rename from src/infrastructure/subagent/spawn_tools.ts rename to src/features/subagent/infrastructure/spawn_tools.ts index 074b705..1fd1faf 100644 --- a/src/infrastructure/subagent/spawn_tools.ts +++ b/src/features/subagent/infrastructure/spawn_tools.ts @@ -2,8 +2,8 @@ * Subagent spawning helpers used by the spawn tools. Ported in 3c. * Mirrors `apps/infrastructure/src/subagent/spawn.rs`. */ -import type { ToolCtx } from "../tools/mod.ts"; -import { runAgent } from "../tools/engine.ts"; +import type { ToolCtx } from "../../agent/infrastructure/tools/mod.ts"; +import { runAgent } from "./engine.ts"; import { resolveConfig } from "./config_resolver.ts"; import { buildProviderService } from "./http_provider.ts"; diff --git a/src/domain/workflow/mod.ts b/src/features/workflow/domain/mod.ts similarity index 100% rename from src/domain/workflow/mod.ts rename to src/features/workflow/domain/mod.ts diff --git a/src/features/workflow/index.ts b/src/features/workflow/index.ts new file mode 100644 index 0000000..3743ef1 --- /dev/null +++ b/src/features/workflow/index.ts @@ -0,0 +1,3 @@ +/** Workflow feature — multi-phase YAML workflows + hive-mind orchestration. */ +export * from "./domain/mod.ts"; +export * from "./infrastructure/index.ts"; diff --git a/src/infrastructure/workflow/complexity.ts b/src/features/workflow/infrastructure/complexity.ts similarity index 100% rename from src/infrastructure/workflow/complexity.ts rename to src/features/workflow/infrastructure/complexity.ts diff --git a/src/infrastructure/workflow/cycle.ts b/src/features/workflow/infrastructure/cycle.ts similarity index 84% rename from src/infrastructure/workflow/cycle.ts rename to src/features/workflow/infrastructure/cycle.ts index c495fcc..6d3cb69 100644 --- a/src/infrastructure/workflow/cycle.ts +++ b/src/features/workflow/infrastructure/cycle.ts @@ -6,11 +6,11 @@ * with bounded concurrency (MAX_CONCURRENT_NODES=8) → collect NodeOutput. * Failed nodes are logged and replaced with [ERROR] output. */ -import type { CognitiveCycle, NodeOutput } from "@zesdex/domain"; -import type { ToolCtx } from "../tools/mod.ts"; -import { runAgent } from "../tools/engine.ts"; -import { resolveConfig } from "../subagent/config_resolver.ts"; -import { buildProviderService } from "../subagent/http_provider.ts"; +import type { CognitiveCycle, NodeOutput } from "@zesdex/workflow"; +import type { ToolCtx } from "../../agent/infrastructure/tools/mod.ts"; +import { runAgent } from "../../subagent/infrastructure/engine.ts"; +import { resolveConfig } from "../../subagent/infrastructure/config_resolver.ts"; +import { buildProviderService } from "../../subagent/infrastructure/http_provider.ts"; /** Maximum number of hive-mind nodes running concurrently per cycle. */ const MAX_CONCURRENT_NODES = 8; diff --git a/src/infrastructure/workflow/docs.ts b/src/features/workflow/infrastructure/docs.ts similarity index 96% rename from src/infrastructure/workflow/docs.ts rename to src/features/workflow/infrastructure/docs.ts index cacc085..c109c40 100644 --- a/src/infrastructure/workflow/docs.ts +++ b/src/features/workflow/infrastructure/docs.ts @@ -6,7 +6,7 @@ */ import * as fs from "node:fs"; import * as path from "node:path"; -import type { NodeOutput } from "@zesdex/domain"; +import type { NodeOutput } from "@zesdex/workflow"; /** * Write a deterministic audit trail for a hive-mind convergence. diff --git a/src/infrastructure/workflow/engine.ts b/src/features/workflow/infrastructure/engine.ts similarity index 82% rename from src/infrastructure/workflow/engine.ts rename to src/features/workflow/infrastructure/engine.ts index b818d0f..f6282c0 100644 --- a/src/infrastructure/workflow/engine.ts +++ b/src/features/workflow/infrastructure/engine.ts @@ -4,9 +4,9 @@ * * Flow: parse YAML → build WorkflowScript → for each phase → run as subagent → collect results. */ -import type { WorkflowScript } from "@zesdex/domain"; -import type { ToolCtx } from "../tools/mod.ts"; -import { runAgent } from "../tools/engine.ts"; +import type { WorkflowScript } from "@zesdex/workflow"; +import type { ToolCtx } from "../../agent/infrastructure/tools/mod.ts"; +import { runAgent } from "../../subagent/infrastructure/engine.ts"; /** Maximum characters of node output to feed into synthesis prompt per node. */ export const MAX_NODE_OUTPUT_CHARS = 4000; @@ -18,8 +18,8 @@ export const MAX_NODE_OUTPUT_CHARS = 4000; * Flow: load settings → resolve LLM credentials → run_agent → return output. */ export async function executePrimitive(directive: string, toolCtx: ToolCtx): Promise { - const { resolveConfig } = await import("../subagent/config_resolver.ts"); - const { buildProviderService } = await import("../subagent/http_provider.ts"); + const { resolveConfig } = await import("../../subagent/infrastructure/config_resolver.ts"); + const { buildProviderService } = await import("../../subagent/infrastructure/http_provider.ts"); const { baseUrl, apiKey, model } = await resolveConfig(); const svc = buildProviderService(baseUrl, apiKey, model); diff --git a/src/infrastructure/workflow/hive_mind.ts b/src/features/workflow/infrastructure/hive_mind.ts similarity index 100% rename from src/infrastructure/workflow/hive_mind.ts rename to src/features/workflow/infrastructure/hive_mind.ts diff --git a/src/infrastructure/workflow/index.ts b/src/features/workflow/infrastructure/index.ts similarity index 100% rename from src/infrastructure/workflow/index.ts rename to src/features/workflow/infrastructure/index.ts diff --git a/src/infrastructure/workflow/orchestrate.ts b/src/features/workflow/infrastructure/orchestrate.ts similarity index 94% rename from src/infrastructure/workflow/orchestrate.ts rename to src/features/workflow/infrastructure/orchestrate.ts index 9142f97..7cc9762 100644 --- a/src/infrastructure/workflow/orchestrate.ts +++ b/src/features/workflow/infrastructure/orchestrate.ts @@ -5,8 +5,9 @@ * Flow: parse cycles from args → execute each cycle → synthesize consensus * → write convergence doc → return formatted result. */ -import type { JsonValue, CognitiveCycle, NodeOutput, NodeDirective } from "@zesdex/domain"; -import type { ToolCtx } from "../tools/mod.ts"; +import type { JsonValue } from "@zesdex/domain"; +import type { CognitiveCycle, NodeOutput, NodeDirective } from "@zesdex/workflow"; +import type { ToolCtx } from "../../agent/infrastructure/tools/mod.ts"; import { parseWorkflowScript } from "./script.ts"; import { executeWorkflowScript, formatWorkflowResult } from "./engine.ts"; import { executeCycle } from "./cycle.ts"; diff --git a/src/infrastructure/workflow/script.ts b/src/features/workflow/infrastructure/script.ts similarity index 97% rename from src/infrastructure/workflow/script.ts rename to src/features/workflow/infrastructure/script.ts index a7ceed2..69e0cdc 100644 --- a/src/infrastructure/workflow/script.ts +++ b/src/features/workflow/infrastructure/script.ts @@ -6,7 +6,7 @@ * (name + ordered phases). Supports a minimal YAML subset: `name:` and * `phases:` with `- name:` / `- directive:` entries. */ -import type { WorkflowScript, WorkflowPhase } from "@zesdex/domain"; +import type { WorkflowScript, WorkflowPhase } from "@zesdex/workflow"; /** * Parse a YAML string into a WorkflowScript. diff --git a/src/infrastructure/workflow/synthesis.ts b/src/features/workflow/infrastructure/synthesis.ts similarity index 91% rename from src/infrastructure/workflow/synthesis.ts rename to src/features/workflow/infrastructure/synthesis.ts index b18f762..ba2fa34 100644 --- a/src/infrastructure/workflow/synthesis.ts +++ b/src/features/workflow/infrastructure/synthesis.ts @@ -6,8 +6,8 @@ * into a single consensus (conflicts, agreements, key findings) → return the * synthesized text. Falls back to plain concatenation if the LLM call fails. */ -import type { NodeOutput } from "@zesdex/domain"; -import type { ToolCtx } from "../tools/mod.ts"; +import type { NodeOutput } from "@zesdex/workflow"; +import type { ToolCtx } from "../../agent/infrastructure/tools/mod.ts"; import { MAX_NODE_OUTPUT_CHARS } from "./engine.ts"; /** @@ -25,8 +25,8 @@ export async function synthesizeConsensus( const combined = buildCombinedBody(nodes); - const { resolveConfig } = await import("../subagent/config_resolver.ts"); - const { buildProviderService } = await import("../subagent/http_provider.ts"); + const { resolveConfig } = await import("../../subagent/infrastructure/config_resolver.ts"); + const { buildProviderService } = await import("../../subagent/infrastructure/http_provider.ts"); const { baseUrl, apiKey, model } = await resolveConfig(); const svc = buildProviderService(baseUrl, apiKey, model); diff --git a/src/infrastructure/index.ts b/src/infrastructure/index.ts deleted file mode 100644 index f73b097..0000000 --- a/src/infrastructure/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Zesdex Infrastructure Layer — concrete adapters implementing domain/application - * ports. Mirrors the Rust `zesdex-infrastructure` crate. - */ -export * from "./utils.ts"; -export * from "./llm/index.ts"; -export * from "./persistence/index.ts"; -export * from "./tools/mod.ts"; -export * from "./bgbash/index.ts"; -export { InfrastructureToolExecutor } from "./tools/executor.ts"; -export { toolDefs, allTools, toolIsRisky, toolIsParallelSafe } from "./tools/registry.ts"; -export { BestPracticeEngine } from "./best_practice/engine.ts"; \ No newline at end of file diff --git a/src/infrastructure/persistence/index.ts b/src/infrastructure/persistence/index.ts deleted file mode 100644 index 25223c7..0000000 --- a/src/infrastructure/persistence/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -/** Persistence layer — CMS file repositories. */ -export * from "./cms/index.ts"; \ No newline at end of file diff --git a/src/interfaces/cli/bootstrap.ts b/src/interfaces/cli/bootstrap.ts index 67ff652..1fb56fd 100644 --- a/src/interfaces/cli/bootstrap.ts +++ b/src/interfaces/cli/bootstrap.ts @@ -3,7 +3,7 @@ * Mirrors the Rust `bootstrap` seed. */ import { newStore, ensureStoreDirs } from "@zesdex/domain"; -import { JsonSettingsRepository, JsonAppConfigRepository } from "@zesdex/infrastructure"; +import { JsonSettingsRepository, JsonAppConfigRepository } from "@zesdex/cms"; /** Seed default settings + app config into the store directory. */ export async function bootstrap(): Promise { diff --git a/src/interfaces/cli/compose.ts b/src/interfaces/cli/compose.ts index 705d962..6a53433 100644 --- a/src/interfaces/cli/compose.ts +++ b/src/interfaces/cli/compose.ts @@ -8,25 +8,29 @@ import { newStore, ensureStoreDirs, - type AgentTurnParams, - type TurnEvent, - type TurnEventSink, type ChatMessage, type Store, userMessage, - resolveEffectiveModel, } from "@zesdex/domain"; import { + type AgentTurnParams, + type TurnEvent, + type TurnEventSink, +} from "@zesdex/agent"; +import { + resolveEffectiveModel, JsonSettingsRepository, JsonAppConfigRepository, +} from "@zesdex/cms"; +import { LlmClient, resolveApiKey, InfrastructureToolExecutor, allTools, toolDefs, -} from "@zesdex/infrastructure"; -import type { ToolCtx } from "@zesdex/infrastructure"; -import { AgentTurnServiceImpl } from "@zesdex/application"; + type ToolCtx, +} from "@zesdex/agent-infra"; +import { AgentTurnServiceImpl } from "@zesdex/agent"; /** Wired runtime for single-process mode. */ export interface WiredRuntime { diff --git a/src/interfaces/cli/index.ts b/src/interfaces/cli/index.ts index 9e9ef35..640cc2c 100644 --- a/src/interfaces/cli/index.ts +++ b/src/interfaces/cli/index.ts @@ -45,7 +45,7 @@ async function runHeadless(prompt: string): Promise { const { runSingleProcess, buildTurnParams } = await import("./compose.ts"); const runtime = await runSingleProcess(); - const events: import("@zesdex/domain").TurnEvent[] = []; + const events: import("@zesdex/agent").TurnEvent[] = []; const abort = new AbortController(); const params = buildTurnParams(runtime, prompt, events, abort); diff --git a/src/interfaces/tui/run.ts b/src/interfaces/tui/run.ts index 51617b8..4359196 100644 --- a/src/interfaces/tui/run.ts +++ b/src/interfaces/tui/run.ts @@ -7,7 +7,8 @@ * turns against the LLM + tool executor, streaming events into the transcript. */ import * as fs from "node:fs"; -import { newStore, userMessage, type TurnEventSink } from "@zesdex/domain"; +import { newStore, userMessage } from "@zesdex/domain"; +import type { TurnEventSink } from "@zesdex/agent"; import { runSingleProcess, type WiredRuntime } from "../cli/compose.ts"; import { createTuiState, type AppStateRest, type TurnRunner } from "./state.ts"; import { bootTui } from "./ui.tsx"; diff --git a/src/interfaces/tui/state.ts b/src/interfaces/tui/state.ts index c2dbb97..27b7ec9 100644 --- a/src/interfaces/tui/state.ts +++ b/src/interfaces/tui/state.ts @@ -7,7 +7,8 @@ * unit-testable in Bun. */ -import { Roles, type Role, type TurnEvent } from "@zesdex/domain"; +import { Roles, type Role } from "@zesdex/domain"; +import type { TurnEvent } from "@zesdex/agent"; /** * Driver for executing a single agent turn in the TUI. Implemented by the diff --git a/src/domain/core/conversation.ts b/src/shared/domain/conversation.ts similarity index 100% rename from src/domain/core/conversation.ts rename to src/shared/domain/conversation.ts diff --git a/src/domain/core/error.ts b/src/shared/domain/error.ts similarity index 100% rename from src/domain/core/error.ts rename to src/shared/domain/error.ts diff --git a/src/domain/core/index.ts b/src/shared/domain/index.ts similarity index 69% rename from src/domain/core/index.ts rename to src/shared/domain/index.ts index d0e1bf5..724d65c 100644 --- a/src/domain/core/index.ts +++ b/src/shared/domain/index.ts @@ -1,5 +1,4 @@ -/** Core domain module — shared entities, value objects, and provider types. */ -export * from "./error.ts"; +/** Shared domain (fondasi bersama) — core entities, value objects, provider types. */ export * from "./message.ts"; export * from "./conversation.ts"; export * from "./tool_call.ts"; @@ -7,4 +6,4 @@ export * from "./provider.ts"; export * from "./tool_result.ts"; export * from "./usage.ts"; export * from "./store.ts"; -export * from "./error.ts"; \ No newline at end of file +export * from "./error.ts"; diff --git a/src/domain/core/message.ts b/src/shared/domain/message.ts similarity index 100% rename from src/domain/core/message.ts rename to src/shared/domain/message.ts diff --git a/src/domain/core/provider.test.ts b/src/shared/domain/provider.test.ts similarity index 100% rename from src/domain/core/provider.test.ts rename to src/shared/domain/provider.test.ts diff --git a/src/domain/core/provider.ts b/src/shared/domain/provider.ts similarity index 100% rename from src/domain/core/provider.ts rename to src/shared/domain/provider.ts diff --git a/src/domain/core/store.ts b/src/shared/domain/store.ts similarity index 100% rename from src/domain/core/store.ts rename to src/shared/domain/store.ts diff --git a/src/domain/core/tool_call.test.ts b/src/shared/domain/tool_call.test.ts similarity index 100% rename from src/domain/core/tool_call.test.ts rename to src/shared/domain/tool_call.test.ts diff --git a/src/domain/core/tool_call.ts b/src/shared/domain/tool_call.ts similarity index 100% rename from src/domain/core/tool_call.ts rename to src/shared/domain/tool_call.ts diff --git a/src/domain/core/tool_result.ts b/src/shared/domain/tool_result.ts similarity index 100% rename from src/domain/core/tool_result.ts rename to src/shared/domain/tool_result.ts diff --git a/src/domain/core/usage.ts b/src/shared/domain/usage.ts similarity index 100% rename from src/domain/core/usage.ts rename to src/shared/domain/usage.ts diff --git a/src/shared/index.ts b/src/shared/index.ts new file mode 100644 index 0000000..d1b1cc9 --- /dev/null +++ b/src/shared/index.ts @@ -0,0 +1,3 @@ +/** Shared layer — cross-cutting foundation used by all features. */ +export * from "./domain/index.ts"; +export * from "./utils.ts"; diff --git a/src/infrastructure/utils.ts b/src/shared/utils.ts similarity index 100% rename from src/infrastructure/utils.ts rename to src/shared/utils.ts diff --git a/tsconfig.json b/tsconfig.json index d636d0b..025b5cb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,9 +22,13 @@ "jsx": "react-jsx", "jsxImportSource": "@opentui/react", "paths": { - "@zesdex/domain": ["./src/domain/index.ts"], - "@zesdex/application": ["./src/application/index.ts"], - "@zesdex/infrastructure": ["./src/infrastructure/index.ts"], + "@zesdex/domain": ["./src/shared/domain/index.ts"], + "@zesdex/shared": ["./src/shared/index.ts"], + "@zesdex/agent": ["./src/features/agent/index.ts"], + "@zesdex/agent-infra": ["./src/features/agent/infrastructure/index.ts"], + "@zesdex/cms": ["./src/features/cms/index.ts"], + "@zesdex/subagent": ["./src/features/subagent/index.ts"], + "@zesdex/workflow": ["./src/features/workflow/index.ts"], "@zesdex/tui": ["./src/interfaces/tui/index.ts"] } },