fourmis-agents-sdk 0.3.0 → 0.4.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/dist/agent-loop.d.ts +21 -3
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +294 -90
- package/dist/agents/index.js +2798 -1857
- package/dist/agents/task-manager.js +15 -0
- package/dist/agents/tools.d.ts.map +1 -1
- package/dist/agents/tools.js +2798 -1857
- package/dist/agents/types.d.ts +4 -0
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/api.d.ts +8 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +2394 -886
- package/dist/auth/gemini-oauth.js +15 -0
- package/dist/auth/login-openai.js +15 -0
- package/dist/auth/openai-oauth.js +15 -0
- package/dist/hooks.d.ts +19 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +42 -2
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2407 -887
- package/dist/mcp/client.d.ts +7 -0
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/mcp/client.js +146 -12
- package/dist/mcp/index.js +146 -12
- package/dist/mcp/server.js +15 -0
- package/dist/mcp/types.d.ts +19 -1
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/memory/index.js +15 -0
- package/dist/memory/memory-handler.js +15 -0
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +22 -3
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +56 -2
- package/dist/providers/gemini.js +15 -0
- package/dist/providers/openai.js +15 -0
- package/dist/providers/registry.js +56 -2
- package/dist/providers/types.d.ts +4 -1
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/query.d.ts +21 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +84 -1
- package/dist/settings.js +15 -0
- package/dist/skills/frontmatter.d.ts +15 -0
- package/dist/skills/frontmatter.d.ts.map +1 -0
- package/dist/skills/frontmatter.js +66 -0
- package/dist/skills/index.d.ts +8 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +326 -0
- package/dist/skills/skills.d.ts +94 -0
- package/dist/skills/skills.d.ts.map +1 -0
- package/dist/skills/skills.js +324 -0
- package/dist/tools/ask-user-question.d.ts +7 -0
- package/dist/tools/ask-user-question.d.ts.map +1 -0
- package/dist/tools/ask-user-question.js +63 -0
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +62 -2
- package/dist/tools/config.d.ts +7 -0
- package/dist/tools/config.d.ts.map +1 -0
- package/dist/tools/config.js +129 -0
- package/dist/tools/edit.js +15 -0
- package/dist/tools/exit-plan-mode.d.ts +7 -0
- package/dist/tools/exit-plan-mode.d.ts.map +1 -0
- package/dist/tools/exit-plan-mode.js +49 -0
- package/dist/tools/glob.js +15 -0
- package/dist/tools/grep.js +15 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +521 -9
- package/dist/tools/mcp-resources.js +15 -0
- package/dist/tools/notebook-edit.d.ts +7 -0
- package/dist/tools/notebook-edit.d.ts.map +1 -0
- package/dist/tools/notebook-edit.js +98 -0
- package/dist/tools/presets.d.ts +2 -1
- package/dist/tools/presets.d.ts.map +1 -1
- package/dist/tools/presets.js +37 -4
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +27 -1
- package/dist/tools/registry.d.ts +2 -0
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +25 -0
- package/dist/tools/todo-write.d.ts +7 -0
- package/dist/tools/todo-write.d.ts.map +1 -0
- package/dist/tools/todo-write.js +84 -0
- package/dist/tools/web-fetch.d.ts +6 -0
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +100 -0
- package/dist/tools/web-search.d.ts +7 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +93 -0
- package/dist/tools/write.js +15 -0
- package/dist/types.d.ts +360 -42
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +15 -0
- package/dist/utils/cost.js +15 -0
- package/dist/utils/session-store.d.ts +1 -1
- package/dist/utils/session-store.d.ts.map +1 -1
- package/dist/utils/session-store.js +64 -2
- package/dist/utils/system-prompt.d.ts +4 -0
- package/dist/utils/system-prompt.d.ts.map +1 -1
- package/dist/utils/system-prompt.js +326 -6
- package/package.json +4 -2
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
2
4
|
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
3
18
|
var __export = (target, all) => {
|
|
4
19
|
for (var name in all)
|
|
5
20
|
__defProp(target, name, {
|
|
@@ -37,6 +52,13 @@ function mergeUsage(a, b) {
|
|
|
37
52
|
import { readFileSync, appendFileSync, mkdirSync, readdirSync, statSync } from "fs";
|
|
38
53
|
import { join } from "path";
|
|
39
54
|
import { homedir } from "os";
|
|
55
|
+
function safeStringify(value) {
|
|
56
|
+
try {
|
|
57
|
+
return JSON.stringify(value);
|
|
58
|
+
} catch {
|
|
59
|
+
return String(value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
40
62
|
function sanitizeCwd(cwd) {
|
|
41
63
|
return cwd.replace(/[/.]/g, "-");
|
|
42
64
|
}
|
|
@@ -100,7 +122,7 @@ function findLatestSession(cwd) {
|
|
|
100
122
|
return null;
|
|
101
123
|
}
|
|
102
124
|
}
|
|
103
|
-
function loadSessionMessages(cwd, sessionId) {
|
|
125
|
+
function loadSessionMessages(cwd, sessionId, resumeSessionAt) {
|
|
104
126
|
const dir = sessionsDir(cwd);
|
|
105
127
|
const filePath = join(dir, `${sessionId}.jsonl`);
|
|
106
128
|
let lines;
|
|
@@ -111,7 +133,10 @@ function loadSessionMessages(cwd, sessionId) {
|
|
|
111
133
|
return [];
|
|
112
134
|
}
|
|
113
135
|
const messages = [];
|
|
136
|
+
let reachedResumePoint = false;
|
|
114
137
|
for (const line of lines) {
|
|
138
|
+
if (resumeSessionAt && reachedResumePoint)
|
|
139
|
+
break;
|
|
115
140
|
try {
|
|
116
141
|
const entry = JSON.parse(line);
|
|
117
142
|
if (entry.type !== "user" && entry.type !== "assistant")
|
|
@@ -126,11 +151,48 @@ function loadSessionMessages(cwd, sessionId) {
|
|
|
126
151
|
if (typeof message.content === "string") {
|
|
127
152
|
content = message.content;
|
|
128
153
|
} else if (Array.isArray(message.content)) {
|
|
129
|
-
|
|
154
|
+
const normalizedBlocks = [];
|
|
155
|
+
for (const c of message.content) {
|
|
156
|
+
if (!c || typeof c !== "object")
|
|
157
|
+
continue;
|
|
158
|
+
const block = c;
|
|
159
|
+
if (typeof block.type !== "string")
|
|
160
|
+
continue;
|
|
161
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
162
|
+
normalizedBlocks.push({ type: "text", text: block.text });
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (block.type === "tool_use" && typeof block.id === "string" && typeof block.name === "string") {
|
|
166
|
+
normalizedBlocks.push({
|
|
167
|
+
type: "tool_use",
|
|
168
|
+
id: block.id,
|
|
169
|
+
name: block.name,
|
|
170
|
+
input: block.input ?? {}
|
|
171
|
+
});
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (block.type === "tool_result" && typeof block.tool_use_id === "string") {
|
|
175
|
+
normalizedBlocks.push({
|
|
176
|
+
type: "tool_result",
|
|
177
|
+
tool_use_id: block.tool_use_id,
|
|
178
|
+
content: typeof block.content === "string" ? block.content : safeStringify(block.content),
|
|
179
|
+
is_error: typeof block.is_error === "boolean" ? block.is_error : undefined
|
|
180
|
+
});
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
normalizedBlocks.push({
|
|
184
|
+
type: "text",
|
|
185
|
+
text: `[session:${block.type}] ${safeStringify(block)}`
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
content = normalizedBlocks;
|
|
130
189
|
} else {
|
|
131
190
|
continue;
|
|
132
191
|
}
|
|
133
192
|
messages.push({ role, content });
|
|
193
|
+
if (resumeSessionAt && entry.uuid === resumeSessionAt) {
|
|
194
|
+
reachedResumePoint = true;
|
|
195
|
+
}
|
|
134
196
|
} catch {}
|
|
135
197
|
}
|
|
136
198
|
return messages;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* System prompt builder — assembles the system prompt that makes the agent effective.
|
|
3
3
|
*/
|
|
4
|
+
import type { Skill } from "../skills/index.js";
|
|
4
5
|
export type SystemPromptContext = {
|
|
5
6
|
tools: string[];
|
|
6
7
|
cwd?: string;
|
|
8
|
+
additionalDirectories?: string[];
|
|
9
|
+
loadProjectInstructions?: boolean;
|
|
7
10
|
permissionMode?: string;
|
|
8
11
|
customPrompt?: string;
|
|
12
|
+
skills?: Skill[];
|
|
9
13
|
};
|
|
10
14
|
export declare function buildSystemPrompt(context: SystemPromptContext): string;
|
|
11
15
|
//# sourceMappingURL=system-prompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/utils/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/utils/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AA6DhD,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IACjC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CAClB,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CA8CtE"}
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
2
4
|
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
3
18
|
var __export = (target, all) => {
|
|
4
19
|
for (var name in all)
|
|
5
20
|
__defProp(target, name, {
|
|
@@ -12,9 +27,299 @@ var __export = (target, all) => {
|
|
|
12
27
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
13
28
|
var __require = import.meta.require;
|
|
14
29
|
|
|
30
|
+
// src/skills/frontmatter.ts
|
|
31
|
+
import { parse } from "yaml";
|
|
32
|
+
function normalizeNewlines(value) {
|
|
33
|
+
return value.replace(/\r\n/g, `
|
|
34
|
+
`).replace(/\r/g, `
|
|
35
|
+
`);
|
|
36
|
+
}
|
|
37
|
+
function extractFrontmatter(content) {
|
|
38
|
+
const normalized = normalizeNewlines(content);
|
|
39
|
+
if (!normalized.startsWith("---")) {
|
|
40
|
+
return { yamlString: null, body: normalized };
|
|
41
|
+
}
|
|
42
|
+
const endIndex = normalized.indexOf(`
|
|
43
|
+
---`, 3);
|
|
44
|
+
if (endIndex === -1) {
|
|
45
|
+
return { yamlString: null, body: normalized };
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
yamlString: normalized.slice(4, endIndex),
|
|
49
|
+
body: normalized.slice(endIndex + 4).trim()
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function parseFrontmatter(content) {
|
|
53
|
+
const { yamlString, body } = extractFrontmatter(content);
|
|
54
|
+
if (!yamlString) {
|
|
55
|
+
return { frontmatter: {}, body };
|
|
56
|
+
}
|
|
57
|
+
const parsed = parse(yamlString);
|
|
58
|
+
return { frontmatter: parsed ?? {}, body };
|
|
59
|
+
}
|
|
60
|
+
function stripFrontmatter(content) {
|
|
61
|
+
return parseFrontmatter(content).body;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/skills/skills.ts
|
|
65
|
+
import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "fs";
|
|
66
|
+
import { homedir } from "os";
|
|
67
|
+
import { basename, dirname, isAbsolute, join, resolve } from "path";
|
|
68
|
+
var MAX_NAME_LENGTH = 64;
|
|
69
|
+
var MAX_DESCRIPTION_LENGTH = 1024;
|
|
70
|
+
var MAX_COMPATIBILITY_LENGTH = 500;
|
|
71
|
+
var CONFIG_DIR_NAME = ".claude";
|
|
72
|
+
function shouldIgnore(name) {
|
|
73
|
+
return name.startsWith(".") || name === "node_modules";
|
|
74
|
+
}
|
|
75
|
+
function validateName(name, parentDirName) {
|
|
76
|
+
const errors = [];
|
|
77
|
+
if (name !== parentDirName) {
|
|
78
|
+
errors.push(`name "${name}" does not match parent directory "${parentDirName}"`);
|
|
79
|
+
}
|
|
80
|
+
if (name.length > MAX_NAME_LENGTH) {
|
|
81
|
+
errors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);
|
|
82
|
+
}
|
|
83
|
+
if (!/^[a-z0-9-]+$/.test(name)) {
|
|
84
|
+
errors.push(`name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)`);
|
|
85
|
+
}
|
|
86
|
+
if (name.startsWith("-") || name.endsWith("-")) {
|
|
87
|
+
errors.push(`name must not start or end with a hyphen`);
|
|
88
|
+
}
|
|
89
|
+
if (name.includes("--")) {
|
|
90
|
+
errors.push(`name must not contain consecutive hyphens`);
|
|
91
|
+
}
|
|
92
|
+
return errors;
|
|
93
|
+
}
|
|
94
|
+
function validateDescription(description) {
|
|
95
|
+
const errors = [];
|
|
96
|
+
if (!description || description.trim() === "") {
|
|
97
|
+
errors.push("description is required");
|
|
98
|
+
} else if (description.length > MAX_DESCRIPTION_LENGTH) {
|
|
99
|
+
errors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);
|
|
100
|
+
}
|
|
101
|
+
return errors;
|
|
102
|
+
}
|
|
103
|
+
function validateCompatibility(compatibility) {
|
|
104
|
+
if (!compatibility)
|
|
105
|
+
return [];
|
|
106
|
+
if (compatibility.length > MAX_COMPATIBILITY_LENGTH) {
|
|
107
|
+
return [`compatibility exceeds ${MAX_COMPATIBILITY_LENGTH} characters (${compatibility.length})`];
|
|
108
|
+
}
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
function loadSkillsFromDir(options) {
|
|
112
|
+
return loadSkillsFromDirInternal(options.dir, options.source, true);
|
|
113
|
+
}
|
|
114
|
+
function loadSkillsFromDirInternal(dir, source, includeRootFiles) {
|
|
115
|
+
const skills = [];
|
|
116
|
+
const diagnostics = [];
|
|
117
|
+
if (!existsSync(dir)) {
|
|
118
|
+
return { skills, diagnostics };
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
122
|
+
for (const entry of entries) {
|
|
123
|
+
if (shouldIgnore(entry.name)) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const fullPath = join(dir, entry.name);
|
|
127
|
+
let isDirectory = entry.isDirectory();
|
|
128
|
+
let isFile = entry.isFile();
|
|
129
|
+
if (entry.isSymbolicLink()) {
|
|
130
|
+
try {
|
|
131
|
+
const stats = statSync(fullPath);
|
|
132
|
+
isDirectory = stats.isDirectory();
|
|
133
|
+
isFile = stats.isFile();
|
|
134
|
+
} catch {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (isDirectory) {
|
|
139
|
+
const subResult = loadSkillsFromDirInternal(fullPath, source, false);
|
|
140
|
+
skills.push(...subResult.skills);
|
|
141
|
+
diagnostics.push(...subResult.diagnostics);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (!isFile)
|
|
145
|
+
continue;
|
|
146
|
+
const isRootMd = includeRootFiles && entry.name.endsWith(".md");
|
|
147
|
+
const isSkillMd = !includeRootFiles && entry.name === "SKILL.md";
|
|
148
|
+
if (!isRootMd && !isSkillMd)
|
|
149
|
+
continue;
|
|
150
|
+
const result = loadSkillFromFile(fullPath, source);
|
|
151
|
+
if (result.skill) {
|
|
152
|
+
skills.push(result.skill);
|
|
153
|
+
}
|
|
154
|
+
diagnostics.push(...result.diagnostics);
|
|
155
|
+
}
|
|
156
|
+
} catch {}
|
|
157
|
+
return { skills, diagnostics };
|
|
158
|
+
}
|
|
159
|
+
function loadSkillFromFile(filePath, source) {
|
|
160
|
+
const diagnostics = [];
|
|
161
|
+
try {
|
|
162
|
+
const rawContent = readFileSync(filePath, "utf-8");
|
|
163
|
+
const { frontmatter } = parseFrontmatter(rawContent);
|
|
164
|
+
const skillDir = dirname(filePath);
|
|
165
|
+
const parentDirName = basename(skillDir);
|
|
166
|
+
const descErrors = validateDescription(frontmatter.description);
|
|
167
|
+
for (const error of descErrors) {
|
|
168
|
+
diagnostics.push({ type: "warning", message: error, path: filePath });
|
|
169
|
+
}
|
|
170
|
+
const name = frontmatter.name || parentDirName;
|
|
171
|
+
const nameErrors = validateName(name, parentDirName);
|
|
172
|
+
for (const error of nameErrors) {
|
|
173
|
+
diagnostics.push({ type: "warning", message: error, path: filePath });
|
|
174
|
+
}
|
|
175
|
+
const compatErrors = validateCompatibility(frontmatter.compatibility);
|
|
176
|
+
for (const error of compatErrors) {
|
|
177
|
+
diagnostics.push({ type: "warning", message: error, path: filePath });
|
|
178
|
+
}
|
|
179
|
+
if (!frontmatter.description || frontmatter.description.trim() === "") {
|
|
180
|
+
return { skill: null, diagnostics };
|
|
181
|
+
}
|
|
182
|
+
const allowedToolsRaw = frontmatter["allowed-tools"];
|
|
183
|
+
const allowedTools = allowedToolsRaw ? allowedToolsRaw.split(/\s+/).filter(Boolean) : undefined;
|
|
184
|
+
return {
|
|
185
|
+
skill: {
|
|
186
|
+
name,
|
|
187
|
+
description: frontmatter.description,
|
|
188
|
+
filePath,
|
|
189
|
+
baseDir: skillDir,
|
|
190
|
+
source,
|
|
191
|
+
disableModelInvocation: frontmatter["disable-model-invocation"] === true,
|
|
192
|
+
license: frontmatter.license,
|
|
193
|
+
compatibility: frontmatter.compatibility,
|
|
194
|
+
metadata: frontmatter.metadata,
|
|
195
|
+
allowedTools
|
|
196
|
+
},
|
|
197
|
+
diagnostics
|
|
198
|
+
};
|
|
199
|
+
} catch (error) {
|
|
200
|
+
const message = error instanceof Error ? error.message : "failed to parse skill file";
|
|
201
|
+
diagnostics.push({ type: "warning", message, path: filePath });
|
|
202
|
+
return { skill: null, diagnostics };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function normalizePath(input) {
|
|
206
|
+
const trimmed = input.trim();
|
|
207
|
+
if (trimmed === "~")
|
|
208
|
+
return homedir();
|
|
209
|
+
if (trimmed.startsWith("~/"))
|
|
210
|
+
return join(homedir(), trimmed.slice(2));
|
|
211
|
+
if (trimmed.startsWith("~"))
|
|
212
|
+
return join(homedir(), trimmed.slice(1));
|
|
213
|
+
return trimmed;
|
|
214
|
+
}
|
|
215
|
+
function resolveSkillPath(p, cwd) {
|
|
216
|
+
const normalized = normalizePath(p);
|
|
217
|
+
return isAbsolute(normalized) ? normalized : resolve(cwd, normalized);
|
|
218
|
+
}
|
|
219
|
+
function loadSkills(options = {}) {
|
|
220
|
+
const { cwd = process.cwd(), skillPaths = [], includeDefaults = true } = options;
|
|
221
|
+
const skillMap = new Map;
|
|
222
|
+
const realPathSet = new Set;
|
|
223
|
+
const allDiagnostics = [];
|
|
224
|
+
const collisionDiagnostics = [];
|
|
225
|
+
function addSkills(result) {
|
|
226
|
+
allDiagnostics.push(...result.diagnostics);
|
|
227
|
+
for (const skill of result.skills) {
|
|
228
|
+
let realPath;
|
|
229
|
+
try {
|
|
230
|
+
realPath = realpathSync(skill.filePath);
|
|
231
|
+
} catch {
|
|
232
|
+
realPath = skill.filePath;
|
|
233
|
+
}
|
|
234
|
+
if (realPathSet.has(realPath))
|
|
235
|
+
continue;
|
|
236
|
+
const existing = skillMap.get(skill.name);
|
|
237
|
+
if (existing) {
|
|
238
|
+
collisionDiagnostics.push({
|
|
239
|
+
type: "collision",
|
|
240
|
+
message: `name "${skill.name}" collision`,
|
|
241
|
+
path: skill.filePath,
|
|
242
|
+
collision: {
|
|
243
|
+
resourceType: "skill",
|
|
244
|
+
name: skill.name,
|
|
245
|
+
winnerPath: existing.filePath,
|
|
246
|
+
loserPath: skill.filePath
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
} else {
|
|
250
|
+
skillMap.set(skill.name, skill);
|
|
251
|
+
realPathSet.add(realPath);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (includeDefaults) {
|
|
256
|
+
const userSkillsDir = join(homedir(), CONFIG_DIR_NAME, "skills");
|
|
257
|
+
const projectSkillsDir = resolve(cwd, CONFIG_DIR_NAME, "skills");
|
|
258
|
+
addSkills(loadSkillsFromDirInternal(userSkillsDir, "user", true));
|
|
259
|
+
addSkills(loadSkillsFromDirInternal(projectSkillsDir, "project", true));
|
|
260
|
+
}
|
|
261
|
+
for (const rawPath of skillPaths) {
|
|
262
|
+
const resolvedPath = resolveSkillPath(rawPath, cwd);
|
|
263
|
+
if (!existsSync(resolvedPath)) {
|
|
264
|
+
allDiagnostics.push({ type: "warning", message: "skill path does not exist", path: resolvedPath });
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
const stats = statSync(resolvedPath);
|
|
269
|
+
if (stats.isDirectory()) {
|
|
270
|
+
addSkills(loadSkillsFromDirInternal(resolvedPath, "path", true));
|
|
271
|
+
} else if (stats.isFile() && resolvedPath.endsWith(".md")) {
|
|
272
|
+
const result = loadSkillFromFile(resolvedPath, "path");
|
|
273
|
+
if (result.skill) {
|
|
274
|
+
addSkills({ skills: [result.skill], diagnostics: result.diagnostics });
|
|
275
|
+
} else {
|
|
276
|
+
allDiagnostics.push(...result.diagnostics);
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
allDiagnostics.push({ type: "warning", message: "skill path is not a markdown file", path: resolvedPath });
|
|
280
|
+
}
|
|
281
|
+
} catch (error) {
|
|
282
|
+
const message = error instanceof Error ? error.message : "failed to read skill path";
|
|
283
|
+
allDiagnostics.push({ type: "warning", message, path: resolvedPath });
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
skills: Array.from(skillMap.values()),
|
|
288
|
+
diagnostics: [...allDiagnostics, ...collisionDiagnostics]
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
function escapeXml(str) {
|
|
292
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
293
|
+
}
|
|
294
|
+
function formatSkillsForPrompt(skills) {
|
|
295
|
+
const visibleSkills = skills.filter((s) => !s.disableModelInvocation);
|
|
296
|
+
if (visibleSkills.length === 0) {
|
|
297
|
+
return "";
|
|
298
|
+
}
|
|
299
|
+
const lines = [
|
|
300
|
+
"The following skills provide specialized instructions for specific tasks.",
|
|
301
|
+
"Use the read tool to load a skill's file when the task matches its description.",
|
|
302
|
+
"When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.",
|
|
303
|
+
"",
|
|
304
|
+
"<available_skills>"
|
|
305
|
+
];
|
|
306
|
+
for (const skill of visibleSkills) {
|
|
307
|
+
lines.push(" <skill>");
|
|
308
|
+
lines.push(` <name>${escapeXml(skill.name)}</name>`);
|
|
309
|
+
lines.push(` <description>${escapeXml(skill.description)}</description>`);
|
|
310
|
+
lines.push(` <location>${escapeXml(skill.filePath)}</location>`);
|
|
311
|
+
if (skill.allowedTools?.length) {
|
|
312
|
+
lines.push(` <allowed-tools>${escapeXml(skill.allowedTools.join(" "))}</allowed-tools>`);
|
|
313
|
+
}
|
|
314
|
+
lines.push(" </skill>");
|
|
315
|
+
}
|
|
316
|
+
lines.push("</available_skills>");
|
|
317
|
+
return lines.join(`
|
|
318
|
+
`);
|
|
319
|
+
}
|
|
15
320
|
// src/utils/system-prompt.ts
|
|
16
|
-
import { readFileSync } from "fs";
|
|
17
|
-
import { join } from "path";
|
|
321
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
322
|
+
import { join as join2 } from "path";
|
|
18
323
|
var CORE_IDENTITY = `You are an AI coding agent. You help users with software engineering tasks by reading, writing, and modifying code. You have access to tools that let you interact with the filesystem and execute commands.
|
|
19
324
|
|
|
20
325
|
You are highly capable and can help users complete complex tasks that would otherwise be too difficult or time-consuming.`;
|
|
@@ -78,11 +383,26 @@ function buildSystemPrompt(context) {
|
|
|
78
383
|
sections.push(`# Environment
|
|
79
384
|
|
|
80
385
|
Working directory: ${context.cwd}`);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
386
|
+
if (context.additionalDirectories && context.additionalDirectories.length > 0) {
|
|
387
|
+
sections.push(`Additional allowed directories:
|
|
388
|
+
${context.additionalDirectories.map((d) => `- ${d}`).join(`
|
|
389
|
+
`)}`);
|
|
390
|
+
}
|
|
391
|
+
if (context.loadProjectInstructions) {
|
|
392
|
+
const instructions = readProjectInstructions(context.cwd);
|
|
393
|
+
if (instructions) {
|
|
394
|
+
sections.push(`# Project Instructions
|
|
84
395
|
|
|
85
396
|
${instructions}`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (context.skills && context.skills.length > 0) {
|
|
401
|
+
const skillsPrompt = formatSkillsForPrompt(context.skills);
|
|
402
|
+
if (skillsPrompt) {
|
|
403
|
+
sections.push(`# Skills
|
|
404
|
+
|
|
405
|
+
${skillsPrompt}`);
|
|
86
406
|
}
|
|
87
407
|
}
|
|
88
408
|
if (context.customPrompt) {
|
|
@@ -95,7 +415,7 @@ ${instructions}`);
|
|
|
95
415
|
function readProjectInstructions(cwd) {
|
|
96
416
|
for (const name of ["CLAUDE.md", "AGENTS.md"]) {
|
|
97
417
|
try {
|
|
98
|
-
const content =
|
|
418
|
+
const content = readFileSync2(join2(cwd, name), "utf-8").trim();
|
|
99
419
|
if (content)
|
|
100
420
|
return content;
|
|
101
421
|
} catch {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fourmis-agents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Multi-provider AI agent SDK with direct API access and in-process tool execution",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -58,13 +58,15 @@
|
|
|
58
58
|
"typecheck": "tsc --noEmit",
|
|
59
59
|
"test": "bun test",
|
|
60
60
|
"test:tools": "bun test tests/tools/",
|
|
61
|
-
"test:integration": "bun test tests/integration.test.ts"
|
|
61
|
+
"test:integration": "bun test tests/integration.test.ts",
|
|
62
|
+
"test:compat": "bun run tests/compat/run-compat.ts"
|
|
62
63
|
},
|
|
63
64
|
"dependencies": {
|
|
64
65
|
"@anthropic-ai/sdk": "^0.74.0",
|
|
65
66
|
"@google/genai": "^1.40.0",
|
|
66
67
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
67
68
|
"openai": "^6.21.0",
|
|
69
|
+
"yaml": "^2.8.2",
|
|
68
70
|
"zod": "^3.24.0"
|
|
69
71
|
},
|
|
70
72
|
"devDependencies": {
|