@wraith-ai/agents 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xFroty
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,36 @@
1
- # Temporary Holding Version
1
+ # @wraith-ai/agents
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Ready-made agents built on [`@wraith-ai/core`](https://www.npmjs.com/package/@wraith-ai/core).
4
+ `createCodingAgent` is the agent the `wraith` command runs, without the
5
+ terminal: file, shell and web tools, background tasks, sub-agents, the MCP
6
+ servers the config names, compaction, an approval mode, and the user's and a
7
+ trusted project's AGENTS.md. Runs on Node 22+ and Bun.
8
+
9
+ ```bash
10
+ npm i @wraith-ai/agents
11
+ ```
12
+
13
+ ```ts
14
+ import { createCodingAgent } from "@wraith-ai/agents";
15
+
16
+ const agent = await createCodingAgent({
17
+ cwd: "/work/repo",
18
+ model: "openrouter:anthropic/claude-opus-5",
19
+ mode: "ask", // "ask" | "auto" | "yolo"
20
+ approve: async () => "denied", // who answers what the policy leaves open
21
+ config: "remembered", // read ~/.wraith and the project as `wraith trust` decided
22
+ });
23
+
24
+ agent.conversation.subscribe((event) => {
25
+ if (event.type === "text-delta") process.stdout.write(event.text);
26
+ });
27
+ await agent.conversation.send("make the failing test pass");
28
+ await agent.close();
29
+ ```
30
+
31
+ `grep` needs [ripgrep](https://github.com/BurntSushi/ripgrep) on `PATH`.
32
+
33
+ What each option does, and what is read from disk when:
34
+ [USING-WRAITH.md](https://github.com/xFroty/wraith/blob/main/USING-WRAITH.md#a-coding-agent-in-one-call).
35
+
36
+ MIT
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Ready-made agents: the core's blocks, put together for one kind of work.
3
+ * Each preset only composes; behaviour it needs lands in the core first.
4
+ */
5
+ import { ApprovalHandler, ApprovalMode, ConfigInput, ConfiguredRegistry, Conversation, Instructions, McpServers, Model, ProjectInspection, ProjectTrust, SessionStore, Subagents, ToolRegistry, ToolSource } from "@wraith-ai/core";
6
+ /**
7
+ * An agent that works on code in one directory, from the blocks `wraith`
8
+ * itself is built from: the file and shell tools, the web tools, background
9
+ * tasks, agents it can start, MCP servers and compaction.
10
+ */
11
+ /** Higher than `createAgent`'s: a coding task takes more steps than an answer. */
12
+ export declare const CODING_AGENT_MAX_STEPS = 200;
13
+ /**
14
+ * Whether the project's own `.wraith/` files, `.env` settings and AGENTS.md
15
+ * files may configure the agent. The user's own config and AGENTS.md are read
16
+ * in every case but `undefined`.
17
+ *
18
+ * - `"trusted"`, `"untrusted"`: decided by the host.
19
+ * - `"remembered"`: what `wraith trust` stored for this repository; nothing stored is untrusted.
20
+ * - a function: asked with what the project brings, only when it brings something.
21
+ */
22
+ type ProjectConfig = ProjectTrust | "remembered" | ((project: ProjectInspection) => boolean | Promise<boolean>);
23
+ interface CodingAgentOptions {
24
+ /** The workspace. The file tools act inside it, and the shell starts there. */
25
+ cwd: string;
26
+ /**
27
+ * A model, or a name to look up: a profile or `"provider:model"`. Absent:
28
+ * the config's `defaultModel`. With none anywhere, creation fails with
29
+ * `model/not-configured`. A resumed session runs on this one too, not on the
30
+ * model it was started with.
31
+ */
32
+ model?: Model | string | undefined;
33
+ /**
34
+ * `"ask"`: what the policy does not allow goes to `approve`. `"auto"`: a model
35
+ * answers first, and passes what it is unsure of to `approve`. `"yolo"`: no
36
+ * questions; `deny` rules still hold. Absent: what the config says, else ask.
37
+ */
38
+ mode?: ApprovalMode | undefined;
39
+ /**
40
+ * Answers what the policy and the classifier left open. Absent: nobody is
41
+ * asked, and the call goes back to the model refused, saying so.
42
+ */
43
+ approve?: ApprovalHandler | undefined;
44
+ /**
45
+ * Absent: no file and no `WRAITH_*` variable is read; the config is the
46
+ * defaults with `overrides` on top. Given: the user's files and variables
47
+ * are read, and the project's as this says.
48
+ */
49
+ config?: ProjectConfig | undefined;
50
+ /** Anything a config file can set, over every other layer. */
51
+ overrides?: ConfigInput | undefined;
52
+ /** Sources beside the built-in tools. `tools.deny` takes a built-in one away. */
53
+ tools?: readonly ToolSource[] | undefined;
54
+ /** A directory to keep sessions in, or a store. Absent: in memory, gone at `close()`. */
55
+ sessions?: string | SessionStore | undefined;
56
+ /** A session to carry on, by id. One the store does not have fails with `session/not-found`. */
57
+ session?: string | undefined;
58
+ /** The agent's role. The environment and the permission guidance are always added. */
59
+ system?: string | undefined;
60
+ /** Where provider keys and MCP servers' variables come from. Absent: `process.env`. */
61
+ env?: Readonly<Record<string, string | undefined>> | undefined;
62
+ }
63
+ /** A setting that was written and not used, and why. */
64
+ interface SkippedSetting {
65
+ setting: string;
66
+ source: string;
67
+ reason: string;
68
+ }
69
+ interface CodingAgent {
70
+ /** Send prompts here, and subscribe to what happens. */
71
+ conversation: Conversation;
72
+ model: Model;
73
+ /** The mode it runs in, after the config had its say. */
74
+ mode: ApprovalMode;
75
+ tools: ToolRegistry;
76
+ subagents: Subagents;
77
+ /** Present when the config names MCP servers. */
78
+ mcp?: McpServers;
79
+ /** The config's providers: what a name in `model` was looked up in. */
80
+ providers: ConfiguredRegistry;
81
+ /**
82
+ * The AGENTS.md files the model is given: the user's, and a trusted
83
+ * project's from its root down to `cwd`. Absent when there were none, or
84
+ * when `config` was not given and no file was read at all.
85
+ */
86
+ instructions?: Instructions;
87
+ /** What the config said and this agent does not do. */
88
+ skipped: SkippedSetting[];
89
+ /** Stops the turn, the tasks, the agents and the servers, and removes the session's temp files. */
90
+ close(): Promise<void>;
91
+ }
92
+ export declare function createCodingAgent(options: CodingAgentOptions): Promise<CodingAgent>;
93
+ export type { CodingAgent, CodingAgentOptions, ProjectConfig, SkippedSetting };
package/dist/index.mjs ADDED
@@ -0,0 +1,314 @@
1
+ import { mkdir, rm } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { APP_NAME, AgentError, INHERIT_MODEL, SERVICE_KEY_ENV, TOOL_POLICY_GUIDANCE, approvalModes, builtinSubagents, builtinToolSource, catalogTables, chainApproval, composeSystemPrompt, createAgent, createClassifierApproval, createCompactor, createConversation, createFileSessionStore, createInbox, createMcpServers, createMemorySessionStore, createModelsDevCapabilities, createPermissionPolicy, createSubagents, createTaskRegistry, createToolRegistry, defaultCompactionPolicy, environmentBlock, fileCredentialStore, fileMcpAuthStore, inspectProject, loadConfig, loadInstructions, loadSubagents, parseConfig, permissiveCapabilities, readTrust, registryFromConfig, sessionSideDir, subagentSessionStore, toPosix, webToolSource } from "@wraith-ai/core";
5
+ import { capabilitySnapshot } from "@wraith-ai/core/snapshot";
6
+ // src/coding-agent.ts
7
+ /**
8
+ * An agent that works on code in one directory, from the blocks `wraith`
9
+ * itself is built from: the file and shell tools, the web tools, background
10
+ * tasks, agents it can start, MCP servers and compaction.
11
+ */
12
+ /** Higher than `createAgent`'s: a coding task takes more steps than an answer. */
13
+ const CODING_AGENT_MAX_STEPS = 200;
14
+ const DEFAULT_ROLE = "You are a coding agent working in the user's workspace. Read the code before you change it, make the change the task asks for, check it where you can, and say plainly what you did and what is left.";
15
+ /** Settings of `wraith` the preset has nothing for, with the reason it gives. */
16
+ const NOT_USED = {
17
+ "session.store": (config) => config.session.store,
18
+ "session.dir": (config) => config.session.dir,
19
+ "session.autoTitle": (config) => config.session.autoTitle,
20
+ "session.titleModel": (config) => config.session.titleModel,
21
+ logLevel: (config) => config.logLevel
22
+ };
23
+ const NOT_USED_REASON = {
24
+ "session.store": "sessions come from the sessions option",
25
+ "session.dir": "sessions come from the sessions option"
26
+ };
27
+ async function createCodingAgent(options) {
28
+ const { cwd } = options;
29
+ const env = options.env ?? process.env;
30
+ const read = await readConfig(options, env);
31
+ const { config, paths } = read;
32
+ const skipped = [...read.skipped, ...notUsed(config)];
33
+ const instructions = read.loaded === void 0 ? void 0 : await loadInstructions(read.loaded, { cwd });
34
+ for (const file of instructions?.files ?? []) {
35
+ if (!file.truncated) continue;
36
+ skipped.push({
37
+ setting: "instructions.maxBytes",
38
+ source: file.path,
39
+ reason: `the file was cut: the instruction files together may hold ${String(config.instructions.maxBytes)} bytes`
40
+ });
41
+ }
42
+ const capabilities = capabilitiesFor(config);
43
+ const providers = registryFromConfig(config, {
44
+ env: (variable) => env[variable],
45
+ capabilities,
46
+ credentials: fileCredentialStore(paths.userOAuthDir)
47
+ });
48
+ const model = typeof options.model === "object" ? options.model : await providers.resolve(options.model);
49
+ const auxiliary = (ref) => ref === INHERIT_MODEL ? Promise.resolve(model) : providers.resolve(ref);
50
+ const store = sessionStore(options.sessions);
51
+ const session = await openSession(store, options.session);
52
+ const mode = options.mode ?? approvalModes(config, {
53
+ yolo: false,
54
+ auto: false,
55
+ switchable: false
56
+ }).initial;
57
+ const classifier = config.permissions.classifier;
58
+ const approval = mode === "auto" ? chainApproval(createClassifierApproval({
59
+ model: await auxiliary(classifier.model),
60
+ cacheKey: `classifier:${session.id}`,
61
+ decides: classifier.decides,
62
+ onUnsure: classifier.onUnsure,
63
+ escalateAfter: classifier.escalateAfter,
64
+ ...classifier.environment.trim() === "" ? {} : { environment: classifier.environment },
65
+ blockRules: classifier.blockRules,
66
+ allowExceptions: classifier.allowExceptions
67
+ }), options.approve) : options.approve;
68
+ const compactionModel = config.compaction.enabled && model.contextLimit !== void 0 ? await auxiliary(config.compaction.model) : void 0;
69
+ const temp = sessionSideDir(join(tmpdir(), APP_NAME, "agents"), session.id);
70
+ await mkdir(temp, { recursive: true });
71
+ const scratchpad = join(temp, "scratchpad");
72
+ const tasksDir = join(temp, "tasks");
73
+ const resultsDir = typeof options.sessions === "string" ? join(sessionSideDir(options.sessions, session.id), "tool-results") : void 0;
74
+ const roots = [
75
+ {
76
+ path: scratchpad,
77
+ access: "write"
78
+ },
79
+ {
80
+ path: tasksDir,
81
+ access: "read"
82
+ },
83
+ ...resultsDir === void 0 ? [] : [{
84
+ path: resultsDir,
85
+ access: "read"
86
+ }]
87
+ ];
88
+ const sessionLines = [
89
+ `Scratch directory: ${toPosix(scratchpad)}`,
90
+ "Put temporary files there — clones, downloads, throwaway scripts — not in the project.",
91
+ `Background task logs: ${toPosix(tasksDir)}`,
92
+ "Read them with read_file or grep, without asking. A log stays after its task ends."
93
+ ];
94
+ const environment = (of) => environmentBlock({
95
+ cwd,
96
+ paths,
97
+ model: of.modelId,
98
+ session: sessionLines
99
+ });
100
+ const opened = [];
101
+ try {
102
+ const inbox = createInbox();
103
+ const tasks = createTaskRegistry({
104
+ dir: tasksDir,
105
+ inbox
106
+ });
107
+ opened.push(tasks);
108
+ const kinds = await subagentKinds(read);
109
+ skipped.push(...kinds.skipped);
110
+ const maxSteps = config.limits.maxSteps ?? 200;
111
+ const subagents = createSubagents({
112
+ agents: kinds.agents,
113
+ model,
114
+ models: providers,
115
+ ...typeof options.sessions === "string" ? { store: subagentSessionStore({
116
+ dir: options.sessions,
117
+ parentId: session.id
118
+ }) } : {},
119
+ maxSteps,
120
+ compaction: config.compaction.enabled ? { model: config.compaction.model } : false,
121
+ environment,
122
+ instructions: () => instructions?.text
123
+ });
124
+ opened.push(subagents);
125
+ const mcp = Object.keys(config.mcpServers).length === 0 ? void 0 : createMcpServers(config.mcpServers, {
126
+ cwd,
127
+ env,
128
+ jobDir: paths.cacheDir,
129
+ auth: fileMcpAuthStore(join(paths.userOAuthDir, "mcp"))
130
+ });
131
+ if (mcp !== void 0) opened.push(mcp);
132
+ const searchKey = env[SERVICE_KEY_ENV.exa] ?? read.serviceKeys.exa;
133
+ const tools = await createToolRegistry({
134
+ sources: [
135
+ builtinToolSource({
136
+ ...config.tools.bashPath === void 0 ? {} : { bashPath: config.tools.bashPath },
137
+ cacheDir: paths.cacheDir,
138
+ ripgrep: {
139
+ ...config.tools.ripgrepPath === void 0 ? {} : { configured: config.tools.ripgrepPath },
140
+ cacheDir: paths.cacheDir
141
+ }
142
+ }),
143
+ webToolSource(!config.web.search.enabled ? { search: false } : searchKey === void 0 || searchKey === "" ? {} : { exaApiKey: searchKey }),
144
+ subagents.toolSource(),
145
+ ...mcp === void 0 ? [] : [mcp.toolSource()],
146
+ ...options.tools ?? []
147
+ ],
148
+ cwd,
149
+ roots,
150
+ ...resultsDir === void 0 ? {} : { resultsDir },
151
+ policy: createPermissionPolicy({
152
+ ...config.permissions,
153
+ mode: mode === "yolo" ? "yolo" : config.permissions.mode === "deny" ? "deny" : "ask"
154
+ }, {
155
+ cwd,
156
+ roots
157
+ }),
158
+ ...approval === void 0 ? {} : { approval },
159
+ tasks,
160
+ ...config.tools.allow === void 0 ? {} : { allow: config.tools.allow },
161
+ deny: config.tools.deny
162
+ });
163
+ opened.push(tools);
164
+ const compactor = compactionModel === void 0 || model.contextLimit === void 0 ? void 0 : createCompactor({
165
+ model: compactionModel,
166
+ contextLimit: model.contextLimit,
167
+ policy: {
168
+ ...defaultCompactionPolicy,
169
+ keepLastTurns: config.compaction.keepLastTurns,
170
+ bufferTokens: config.compaction.bufferTokens
171
+ }
172
+ });
173
+ const agent = createAgent({
174
+ model,
175
+ system: composeSystemPrompt(options.system ?? DEFAULT_ROLE, await environment(model), TOOL_POLICY_GUIDANCE),
176
+ instructions: instructions?.text,
177
+ tools,
178
+ maxSteps,
179
+ ...compactor === void 0 ? {} : { compactor }
180
+ });
181
+ const conversation = createConversation({
182
+ agent,
183
+ session,
184
+ store,
185
+ inbox
186
+ });
187
+ return {
188
+ conversation,
189
+ model,
190
+ mode,
191
+ tools,
192
+ subagents,
193
+ ...mcp === void 0 ? {} : { mcp },
194
+ providers,
195
+ ...instructions === void 0 ? {} : { instructions },
196
+ skipped,
197
+ close: async () => {
198
+ await conversation.close();
199
+ await subagents.close();
200
+ tasks.close();
201
+ await tools.close();
202
+ await mcp?.close();
203
+ await rm(temp, {
204
+ recursive: true,
205
+ force: true
206
+ });
207
+ }
208
+ };
209
+ } catch (error) {
210
+ for (const resource of opened.reverse()) await Promise.resolve(resource.close()).catch(() => void 0);
211
+ await rm(temp, {
212
+ recursive: true,
213
+ force: true
214
+ });
215
+ throw error;
216
+ }
217
+ }
218
+ async function readConfig(options, env) {
219
+ const { cwd } = options;
220
+ const overrides = options.overrides ?? {};
221
+ if (options.config === void 0) {
222
+ const { paths } = inspectProject({
223
+ cwd,
224
+ env: { ...env }
225
+ });
226
+ return {
227
+ config: parseConfig(overrides),
228
+ paths,
229
+ serviceKeys: {},
230
+ skipped: []
231
+ };
232
+ }
233
+ const project = await projectTrust(options.config, cwd, env, overrides);
234
+ const loaded = loadConfig({
235
+ project,
236
+ cwd,
237
+ env: { ...env },
238
+ overrides
239
+ });
240
+ return {
241
+ config: loaded.config,
242
+ paths: loaded.paths,
243
+ loaded,
244
+ serviceKeys: loaded.serviceKeys,
245
+ skipped: loaded.ignored.map((item) => ({ ...item }))
246
+ };
247
+ }
248
+ async function projectTrust(decision, cwd, env, overrides) {
249
+ if (decision === "trusted" || decision === "untrusted") return decision;
250
+ const inspection = inspectProject({
251
+ cwd,
252
+ env: { ...env },
253
+ overrides
254
+ });
255
+ if (inspection.files.length === 0 && inspection.variables.length === 0) return "trusted";
256
+ if (decision === "remembered") return readTrust(inspection.paths.userDir, inspection.paths.repoRoot) ?? "untrusted";
257
+ return await decision(inspection) ? "trusted" : "untrusted";
258
+ }
259
+ /** Written and not used: told, not dropped. A default nobody wrote is not news. */
260
+ function notUsed(config) {
261
+ const defaults = parseConfig({});
262
+ return Object.entries(NOT_USED).filter(([, value]) => value(config) !== value(defaults)).map(([setting]) => ({
263
+ setting,
264
+ source: "config",
265
+ reason: NOT_USED_REASON[setting] ?? "createCodingAgent does not use it"
266
+ }));
267
+ }
268
+ /**
269
+ * The catalog the build carries, in memory: windows and prices without a
270
+ * request at start. `wraith models --refresh` is what updates the cache on disk.
271
+ */
272
+ function capabilitiesFor(config) {
273
+ if (config.capabilities.source === "off") return permissiveCapabilities;
274
+ const snapshot = capabilitySnapshot();
275
+ return createModelsDevCapabilities({
276
+ tables: catalogTables(config.providers),
277
+ ...snapshot === void 0 ? {} : { snapshot }
278
+ });
279
+ }
280
+ function sessionStore(sessions) {
281
+ if (sessions === void 0) return createMemorySessionStore({ newId: () => `session-${crypto.randomUUID()}` });
282
+ return typeof sessions === "string" ? createFileSessionStore({ dir: sessions }) : sessions;
283
+ }
284
+ async function openSession(store, id) {
285
+ if (id === void 0) return store.create();
286
+ const found = await store.get(id);
287
+ if (found === null) throw new AgentError("session/not-found", `No session with id "${id}" in this store.`, { details: { id } });
288
+ return found;
289
+ }
290
+ /**
291
+ * The two built in, then the user's files, then a trusted project's. With no
292
+ * config read, the built-in ones only.
293
+ */
294
+ async function subagentKinds(read) {
295
+ if (read.loaded === void 0) return {
296
+ agents: { ...builtinSubagents },
297
+ skipped: []
298
+ };
299
+ const { paths } = read.loaded;
300
+ const dirs = [paths.userAgentsDir, ...paths.projectAgentsDir === void 0 ? [] : [paths.projectAgentsDir]];
301
+ const { agents, skipped } = await loadSubagents(dirs);
302
+ return {
303
+ agents: {
304
+ ...builtinSubagents,
305
+ ...agents
306
+ },
307
+ skipped: skipped.map((file) => ({
308
+ setting: "agent",
309
+ source: file.path,
310
+ reason: file.reason
311
+ }))
312
+ };
313
+ }
314
+ export { CODING_AGENT_MAX_STEPS, createCodingAgent };
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "@wraith-ai/agents",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Ready-made agents built on @wraith-ai/core, starting with createCodingAgent.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/xFroty/wraith.git",
9
+ "directory": "packages/agents"
10
+ },
11
+ "homepage": "https://github.com/xFroty/wraith#readme",
12
+ "type": "module",
13
+ "sideEffects": false,
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.mts",
17
+ "default": "./dist/index.mjs"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "engines": {
24
+ "node": ">=22"
25
+ },
26
+ "dependencies": {
27
+ "@wraith-ai/core": "0.1.0"
28
+ }
29
+ }