@townco/agent 0.1.22 → 0.1.23

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.
Files changed (44) hide show
  1. package/dist/acp-server/adapter.d.ts +10 -14
  2. package/dist/acp-server/cli.d.ts +1 -3
  3. package/dist/acp-server/cli.js +5 -9
  4. package/dist/acp-server/http.d.ts +1 -3
  5. package/dist/bin.js +0 -0
  6. package/dist/definition/index.d.ts +6 -0
  7. package/dist/definition/index.js +9 -0
  8. package/dist/index.js +11 -5
  9. package/dist/runner/agent-runner.d.ts +6 -0
  10. package/dist/runner/index.d.ts +1 -3
  11. package/dist/runner/index.js +14 -18
  12. package/dist/runner/langchain/index.js +10 -0
  13. package/dist/runner/langchain/tools/todo.d.ts +32 -48
  14. package/dist/runner/langchain/tools/web_search.d.ts +1 -1
  15. package/dist/runner/tools.d.ts +16 -0
  16. package/dist/runner/tools.js +10 -1
  17. package/dist/scaffold/copy-gui.js +7 -81
  18. package/dist/scaffold/copy-tui.js +1 -65
  19. package/dist/scaffold/index.d.ts +2 -0
  20. package/dist/scaffold/index.js +26 -31
  21. package/dist/scaffold/project-scaffold.d.ts +12 -0
  22. package/dist/scaffold/project-scaffold.js +314 -0
  23. package/dist/storage/index.d.ts +5 -0
  24. package/dist/storage/index.js +60 -24
  25. package/dist/templates/index.d.ts +7 -2
  26. package/dist/templates/index.js +13 -16
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/dist/utils/index.d.ts +1 -0
  29. package/dist/utils/index.js +1 -0
  30. package/dist/utils/tool.d.ts +36 -0
  31. package/dist/utils/tool.js +33 -0
  32. package/index.ts +11 -7
  33. package/package.json +6 -5
  34. package/templates/index.ts +23 -18
  35. package/dist/definition/mcp.d.ts +0 -0
  36. package/dist/definition/mcp.js +0 -0
  37. package/dist/definition/tools/todo.d.ts +0 -49
  38. package/dist/definition/tools/todo.js +0 -80
  39. package/dist/definition/tools/web_search.d.ts +0 -4
  40. package/dist/definition/tools/web_search.js +0 -26
  41. package/dist/dev-agent/index.d.ts +0 -2
  42. package/dist/dev-agent/index.js +0 -18
  43. package/dist/example.d.ts +0 -2
  44. package/dist/example.js +0 -19
@@ -1 +1,2 @@
1
1
  export * from "./logger.js";
2
+ export * from "./tool.js";
@@ -1 +1,2 @@
1
1
  export * from "./logger.js";
2
+ export * from "./tool.js";
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ import type { CustomToolModule } from "../runner/tool-loader";
3
+ /**
4
+ * Direct tool type that can be passed to AgentDefinition.
5
+ * This is the resolved form of a custom tool that can be used directly
6
+ * in the tools array without requiring file path resolution.
7
+ */
8
+ export type DirectTool = {
9
+ type: "direct";
10
+ name: string;
11
+ description: string;
12
+ fn: (input: unknown) => unknown | Promise<unknown>;
13
+ schema: z.ZodTypeAny;
14
+ };
15
+ /**
16
+ * Transforms an imported custom tool module into a DirectTool that can be
17
+ * used in AgentDefinition.tools.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import * as addTwoNumbers from "./tools/add-two-numbers";
22
+ * import { createTool } from "@townco/agent/utils";
23
+ *
24
+ * const agent: AgentDefinition = {
25
+ * model: "claude-sonnet-4-5-20250929",
26
+ * systemPrompt: "You are a helpful assistant.",
27
+ * tools: [
28
+ * createTool(addTwoNumbers)
29
+ * ]
30
+ * };
31
+ * ```
32
+ *
33
+ * @param module - A custom tool module with default export (function), schema, name, and description
34
+ * @returns A DirectTool object ready to be used in AgentDefinition.tools
35
+ */
36
+ export declare function createTool(module: CustomToolModule): DirectTool;
@@ -0,0 +1,33 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Transforms an imported custom tool module into a DirectTool that can be
4
+ * used in AgentDefinition.tools.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import * as addTwoNumbers from "./tools/add-two-numbers";
9
+ * import { createTool } from "@townco/agent/utils";
10
+ *
11
+ * const agent: AgentDefinition = {
12
+ * model: "claude-sonnet-4-5-20250929",
13
+ * systemPrompt: "You are a helpful assistant.",
14
+ * tools: [
15
+ * createTool(addTwoNumbers)
16
+ * ]
17
+ * };
18
+ * ```
19
+ *
20
+ * @param module - A custom tool module with default export (function), schema, name, and description
21
+ * @returns A DirectTool object ready to be used in AgentDefinition.tools
22
+ */
23
+ export function createTool(module) {
24
+ // Resolve schema: if it's a function, call it with z injected
25
+ const schema = typeof module.schema === "function" ? module.schema(z) : module.schema;
26
+ return {
27
+ type: "direct",
28
+ name: module.name,
29
+ description: module.description,
30
+ fn: module.default,
31
+ schema,
32
+ };
33
+ }
package/index.ts CHANGED
@@ -1,13 +1,17 @@
1
- import { readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
1
  import { makeHttpTransport, makeStdioTransport } from "./acp-server";
4
2
  import type { AgentDefinition } from "./definition";
5
3
 
6
- // Load agent definition from shared JSON file at repo root
7
- const configPath = join(import.meta.dir, "../../agent.json");
8
- const exampleAgent: AgentDefinition = JSON.parse(
9
- readFileSync(configPath, "utf-8"),
10
- );
4
+ const exampleAgent: AgentDefinition = {
5
+ model: "claude-sonnet-4-5-20250929",
6
+ systemPrompt: "You are a helpful assistant.",
7
+ tools: [
8
+ "todo_write",
9
+ "get_weather",
10
+ "web_search",
11
+ { type: "filesystem", working_directory: "/Users/michael/code/town" },
12
+ ],
13
+ mcps: [],
14
+ };
11
15
 
12
16
  // Parse transport type from command line argument
13
17
  const transport = process.argv[2] || "stdio";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@townco/agent",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "type": "module",
5
5
  "module": "index.ts",
6
6
  "files": [
@@ -57,13 +57,14 @@
57
57
  "@langchain/core": "^1.0.3",
58
58
  "@langchain/exa": "^0.1.0",
59
59
  "@langchain/mcp-adapters": "^1.0.0",
60
- "@townco/gui-template": "0.1.14",
61
- "@townco/tui-template": "0.1.14",
62
- "@townco/tsconfig": "0.1.14",
63
- "@townco/ui": "0.1.17",
60
+ "@townco/gui-template": "0.1.15",
61
+ "@townco/tsconfig": "0.1.15",
62
+ "@townco/tui-template": "0.1.15",
63
+ "@townco/ui": "0.1.18",
64
64
  "exa-js": "^2.0.0",
65
65
  "hono": "^4.10.4",
66
66
  "langchain": "^1.0.3",
67
+ "prettier": "^3.6.2",
67
68
  "zod": "^4.1.12"
68
69
  },
69
70
  "devDependencies": {
@@ -1,3 +1,4 @@
1
+ import * as prettier from "prettier";
1
2
  import type { AgentDefinition } from "../definition";
2
3
 
3
4
  export interface TemplateVars {
@@ -7,6 +8,14 @@ export interface TemplateVars {
7
8
  | string
8
9
  | { type: "custom"; modulePath: string }
9
10
  | { type: "filesystem"; working_directory?: string | undefined }
11
+ | {
12
+ type: "direct";
13
+ name: string;
14
+ description: string;
15
+ // biome-ignore lint/suspicious/noExplicitAny: fn type is complex (Zod inferred)
16
+ fn: any;
17
+ schema: unknown;
18
+ }
10
19
  >;
11
20
  systemPrompt: string | null;
12
21
  hasWebSearch: boolean;
@@ -65,15 +74,18 @@ export function generatePackageJson(vars: TemplateVars): string {
65
74
  return JSON.stringify(pkg, null, 2);
66
75
  }
67
76
 
68
- export function generateIndexTs(): string {
69
- return `import { readFileSync } from "node:fs";
70
- import { join } from "node:path";
71
- import { makeHttpTransport, makeStdioTransport } from "@townco/agent/acp-server";
77
+ export async function generateIndexTs(vars: TemplateVars): Promise<string> {
78
+ const agentDef = {
79
+ model: vars.model,
80
+ systemPrompt: vars.systemPrompt,
81
+ tools: vars.tools,
82
+ };
83
+ return prettier.format(
84
+ `import { makeHttpTransport, makeStdioTransport } from "@townco/agent/acp-server";
72
85
  import type { AgentDefinition } from "@townco/agent/definition";
73
86
 
74
87
  // Load agent definition from JSON file
75
- const configPath = join(import.meta.dir, "agent.json");
76
- const agent: AgentDefinition = JSON.parse(readFileSync(configPath, "utf-8"));
88
+ const agent: AgentDefinition = ${JSON.stringify(agentDef)};
77
89
 
78
90
  const transport = process.argv[2] || "stdio";
79
91
 
@@ -85,22 +97,14 @@ if (transport === "http") {
85
97
  console.error(\`Invalid transport: \${transport}\`);
86
98
  process.exit(1);
87
99
  }
88
- `;
89
- }
90
-
91
- export function generateAgentJson(vars: TemplateVars): string {
92
- const agentDef = {
93
- model: vars.model,
94
- systemPrompt: vars.systemPrompt,
95
- tools: vars.tools,
96
- };
97
-
98
- return JSON.stringify(agentDef, null, 2);
100
+ `,
101
+ { parser: "typescript" },
102
+ );
99
103
  }
100
104
 
101
105
  export function generateBinTs(): string {
102
106
  return `#!/usr/bin/env bun
103
- import "./index.js";
107
+ import "./index.ts";
104
108
  `;
105
109
  }
106
110
 
@@ -142,6 +146,7 @@ export function generateReadme(vars: TemplateVars): string {
142
146
  if (tool.type === "custom") return tool.modulePath;
143
147
  if (tool.type === "filesystem")
144
148
  return `filesystem${tool.working_directory ? ` (${tool.working_directory})` : ""}`;
149
+ if (tool.type === "direct") return tool.name;
145
150
  return "";
146
151
  })
147
152
  .join(", ")
File without changes
File without changes
@@ -1,49 +0,0 @@
1
- import { z } from "zod";
2
- export declare const todoItemSchema: z.ZodObject<
3
- {
4
- content: z.ZodString;
5
- status: z.ZodEnum<{
6
- pending: "pending";
7
- in_progress: "in_progress";
8
- completed: "completed";
9
- }>;
10
- activeForm: z.ZodString;
11
- },
12
- z.core.$strip
13
- >;
14
- export declare const todoWrite: import("langchain").DynamicStructuredTool<
15
- z.ZodObject<
16
- {
17
- todos: z.ZodArray<
18
- z.ZodObject<
19
- {
20
- content: z.ZodString;
21
- status: z.ZodEnum<{
22
- pending: "pending";
23
- in_progress: "in_progress";
24
- completed: "completed";
25
- }>;
26
- activeForm: z.ZodString;
27
- },
28
- z.core.$strip
29
- >
30
- >;
31
- },
32
- z.core.$strip
33
- >,
34
- {
35
- todos: {
36
- content: string;
37
- status: "pending" | "in_progress" | "completed";
38
- activeForm: string;
39
- }[];
40
- },
41
- {
42
- todos: {
43
- content: string;
44
- status: "pending" | "in_progress" | "completed";
45
- activeForm: string;
46
- }[];
47
- },
48
- string
49
- >;
@@ -1,80 +0,0 @@
1
- import { tool } from "langchain";
2
- import { z } from "zod";
3
- export const todoItemSchema = z.object({
4
- content: z.string().min(1),
5
- status: z.enum(["pending", "in_progress", "completed"]),
6
- activeForm: z.string().min(1),
7
- });
8
- export const todoWrite = tool(
9
- ({ todos }) => {
10
- // Simple implementation that confirms the todos were written
11
- return `Successfully updated todo list with ${todos.length} items`;
12
- },
13
- {
14
- name: "todo_write",
15
- description: `Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
16
- It also helps the user understand the progress of the task and overall progress of their requests.
17
-
18
- ## When to Use This Tool
19
- Use this tool proactively in these scenarios:
20
-
21
- 1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
22
- 2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
23
- 3. User explicitly requests todo list - When the user directly asks you to use the todo list
24
- 4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
25
- 5. After receiving new instructions - Immediately capture user requirements as todos
26
- 6. When you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time
27
- 7. After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
28
-
29
- ## When NOT to Use This Tool
30
-
31
- Skip using this tool when:
32
- 1. There is only a single, straightforward task
33
- 2. The task is trivial and tracking it provides no organizational benefit
34
- 3. The task can be completed in less than 3 trivial steps
35
- 4. The task is purely conversational or informational
36
-
37
- NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
38
-
39
- ## Task States and Management
40
-
41
- 1. **Task States**: Use these states to track progress:
42
- - pending: Task not yet started
43
- - in_progress: Currently working on (limit to ONE task at a time)
44
- - completed: Task finished successfully
45
-
46
- **IMPORTANT**: Task descriptions must have two forms:
47
- - content: The imperative form describing what needs to be done (e.g., "Run tests", "Build the project")
48
- - activeForm: The present continuous form shown during execution (e.g., "Running tests", "Building the project")
49
-
50
- 2. **Task Management**:
51
- - Update task status in real-time as you work
52
- - Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
53
- - Exactly ONE task must be in_progress at any time (not less, not more)
54
- - Complete current tasks before starting new ones
55
- - Remove tasks that are no longer relevant from the list entirely
56
-
57
- 3. **Task Completion Requirements**:
58
- - ONLY mark a task as completed when you have FULLY accomplished it
59
- - If you encounter errors, blockers, or cannot finish, keep the task as in_progress
60
- - When blocked, create a new task describing what needs to be resolved
61
- - Never mark a task as completed if:
62
- - Tests are failing
63
- - Implementation is partial
64
- - You encountered unresolved errors
65
- - You couldn't find necessary files or dependencies
66
-
67
- 4. **Task Breakdown**:
68
- - Create specific, actionable items
69
- - Break complex tasks into smaller, manageable steps
70
- - Use clear, descriptive task names
71
- - Always provide both forms:
72
- - content: "Fix authentication bug"
73
- - activeForm: "Fixing authentication bug"
74
-
75
- When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.`,
76
- schema: z.object({
77
- todos: z.array(todoItemSchema),
78
- }),
79
- },
80
- );
@@ -1,4 +0,0 @@
1
- import { ExaSearchResults } from "@langchain/exa";
2
- export declare function makeWebSearchTool(): ExaSearchResults<{
3
- text: true;
4
- }>;
@@ -1,26 +0,0 @@
1
- import { ExaSearchResults } from "@langchain/exa";
2
- import Exa from "exa-js";
3
-
4
- let _webSearchInstance = null;
5
- export function makeWebSearchTool() {
6
- if (_webSearchInstance) {
7
- return _webSearchInstance;
8
- }
9
- const apiKey = process.env.EXA_API_KEY;
10
- if (!apiKey) {
11
- throw new Error(
12
- "EXA_API_KEY environment variable is required to use the web_search tool. " +
13
- "Please set it to your Exa API key from https://exa.ai",
14
- );
15
- }
16
- const client = new Exa(apiKey);
17
- _webSearchInstance = new ExaSearchResults({
18
- client,
19
- searchArgs: {
20
- numResults: 5,
21
- type: "auto",
22
- text: true,
23
- },
24
- });
25
- return _webSearchInstance;
26
- }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env bun
2
- export {};
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env bun
2
- import { readFileSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { makeHttpTransport, makeStdioTransport } from "../acp-server/index";
5
- // Load agent definition from JSON file
6
- const configPath = join(import.meta.dir, "agent.json");
7
- const agent = JSON.parse(readFileSync(configPath, "utf-8"));
8
- const transport = process.argv[2] || "stdio";
9
- if (transport === "http") {
10
- makeHttpTransport(agent);
11
- }
12
- else if (transport === "stdio") {
13
- makeStdioTransport(agent);
14
- }
15
- else {
16
- console.error(`Invalid transport: ${transport}`);
17
- process.exit(1);
18
- }
package/dist/example.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env bun
2
- export {};
package/dist/example.js DELETED
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env bun
2
- import { makeHttpTransport, makeStdioTransport } from "./acp-server/index.js";
3
-
4
- const exampleAgent = {
5
- model: "claude-sonnet-4-5-20250929",
6
- systemPrompt: "You are a helpful assistant.",
7
- tools: ["todo_write", "get_weather", "web_search"],
8
- };
9
- // Parse transport type from command line argument
10
- const transport = process.argv[2] || "stdio";
11
- if (transport === "http") {
12
- makeHttpTransport(exampleAgent);
13
- } else if (transport === "stdio") {
14
- makeStdioTransport(exampleAgent);
15
- } else {
16
- console.error(`Invalid transport: ${transport}`);
17
- console.error("Usage: bun run example.ts [stdio|http]");
18
- process.exit(1);
19
- }