@ap3x/agent-core 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 +21 -0
- package/README.md +29 -0
- package/dist/agent-errors.d.ts +54 -0
- package/dist/agent-errors.d.ts.map +1 -0
- package/dist/agent-loop.d.ts +30 -0
- package/dist/agent-loop.d.ts.map +1 -0
- package/dist/agent.d.ts +160 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/backend.d.ts +67 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/compaction.d.ts +147 -0
- package/dist/compaction.d.ts.map +1 -0
- package/dist/concurrency.d.ts +32 -0
- package/dist/concurrency.d.ts.map +1 -0
- package/dist/conversation.d.ts +215 -0
- package/dist/conversation.d.ts.map +1 -0
- package/dist/env.d.ts +125 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/errors.d.ts +37 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/harness.d.ts +110 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4153 -0
- package/dist/loader.d.ts +142 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/logger.d.ts +36 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/output-formatter.d.ts +27 -0
- package/dist/output-formatter.d.ts.map +1 -0
- package/dist/prompt-templates.d.ts +78 -0
- package/dist/prompt-templates.d.ts.map +1 -0
- package/dist/result.d.ts +26 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/serialization.d.ts +75 -0
- package/dist/serialization.d.ts.map +1 -0
- package/dist/session-repo.d.ts +90 -0
- package/dist/session-repo.d.ts.map +1 -0
- package/dist/session.d.ts +251 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/shell-blocklist.d.ts +18 -0
- package/dist/shell-blocklist.d.ts.map +1 -0
- package/dist/skills.d.ts +95 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/system-prompt.d.ts +90 -0
- package/dist/system-prompt.d.ts.map +1 -0
- package/dist/tools.d.ts +61 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/types.d.ts +320 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/uuid.d.ts +23 -0
- package/dist/uuid.d.ts.map +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import type { ImageContent, TextContent } from "@ap3x/ai";
|
|
2
|
+
import type { AgentMessage } from "./types";
|
|
3
|
+
/** The kinds of entry that can appear in a session tree. */
|
|
4
|
+
export type SessionEntryType = "message" | "compaction" | "model_change" | "label" | "leaf" | "thinking_level_change" | "active_tools_change" | "branch_summary" | "session_info" | "custom" | "custom_message";
|
|
5
|
+
interface BaseEntry {
|
|
6
|
+
id: string;
|
|
7
|
+
parentId: string | null;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
type: SessionEntryType;
|
|
10
|
+
}
|
|
11
|
+
/** A transcript message persisted into the tree. */
|
|
12
|
+
export interface MessageEntry extends BaseEntry {
|
|
13
|
+
type: "message";
|
|
14
|
+
message: AgentMessage;
|
|
15
|
+
}
|
|
16
|
+
/** A compaction boundary: a summary replacing all history before a kept entry. */
|
|
17
|
+
export interface CompactionEntry extends BaseEntry {
|
|
18
|
+
type: "compaction";
|
|
19
|
+
summary: string;
|
|
20
|
+
firstKeptEntryId: string;
|
|
21
|
+
tokensBefore: number;
|
|
22
|
+
}
|
|
23
|
+
/** A record that the model changed at this point in the conversation. */
|
|
24
|
+
export interface ModelChangeEntry extends BaseEntry {
|
|
25
|
+
type: "model_change";
|
|
26
|
+
provider: string;
|
|
27
|
+
modelId: string;
|
|
28
|
+
}
|
|
29
|
+
/** A human-readable label attached to another entry. */
|
|
30
|
+
export interface LabelEntry extends BaseEntry {
|
|
31
|
+
type: "label";
|
|
32
|
+
targetId: string;
|
|
33
|
+
label: string;
|
|
34
|
+
}
|
|
35
|
+
/** A leaf marker repointing the conversation head to an existing entry. */
|
|
36
|
+
export interface LeafEntry extends BaseEntry {
|
|
37
|
+
type: "leaf";
|
|
38
|
+
targetId: string;
|
|
39
|
+
}
|
|
40
|
+
/** A record that the reasoning/thinking level changed at this point. */
|
|
41
|
+
export interface ThinkingLevelChangeEntry extends BaseEntry {
|
|
42
|
+
type: "thinking_level_change";
|
|
43
|
+
thinkingLevel: string;
|
|
44
|
+
}
|
|
45
|
+
/** A record that the set of active tool names changed at this point. */
|
|
46
|
+
export interface ActiveToolsChangeEntry extends BaseEntry {
|
|
47
|
+
type: "active_tools_change";
|
|
48
|
+
activeToolNames: string[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A summary of a branch the conversation returned from. When present on the
|
|
52
|
+
* current path it is folded into the reconstructed context as a summary message.
|
|
53
|
+
*/
|
|
54
|
+
export interface BranchSummaryEntry<TDetails = unknown> extends BaseEntry {
|
|
55
|
+
type: "branch_summary";
|
|
56
|
+
/** The entry the conversation moved back to (or "root"). */
|
|
57
|
+
fromId: string;
|
|
58
|
+
summary: string;
|
|
59
|
+
details?: TDetails;
|
|
60
|
+
fromHook?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** Session-level metadata carried in the tree (currently the session name). */
|
|
63
|
+
export interface SessionInfoEntry extends BaseEntry {
|
|
64
|
+
type: "session_info";
|
|
65
|
+
name?: string;
|
|
66
|
+
}
|
|
67
|
+
/** An arbitrary host-defined entry carrying a keyed, typed payload. */
|
|
68
|
+
export interface CustomEntry<TData = unknown> extends BaseEntry {
|
|
69
|
+
type: "custom";
|
|
70
|
+
customType: string;
|
|
71
|
+
data?: TData;
|
|
72
|
+
}
|
|
73
|
+
/** A message-like host-defined entry with model-visible content. */
|
|
74
|
+
export interface CustomMessageEntry<TDetails = unknown> extends BaseEntry {
|
|
75
|
+
type: "custom_message";
|
|
76
|
+
customType: string;
|
|
77
|
+
content: string | (TextContent | ImageContent)[];
|
|
78
|
+
display: boolean;
|
|
79
|
+
details?: TDetails;
|
|
80
|
+
}
|
|
81
|
+
export type SessionEntry = MessageEntry | CompactionEntry | ModelChangeEntry | LabelEntry | LeafEntry | ThinkingLevelChangeEntry | ActiveToolsChangeEntry | BranchSummaryEntry | SessionInfoEntry | CustomEntry | CustomMessageEntry;
|
|
82
|
+
/** The reconstructed conversation state for a path through the tree. */
|
|
83
|
+
export interface SessionContext {
|
|
84
|
+
messages: AgentMessage[];
|
|
85
|
+
/**
|
|
86
|
+
* The latest {@link CompactionEntry}'s summary along the branch, when one
|
|
87
|
+
* exists. Callers seeding a live run from this context thread it into the
|
|
88
|
+
* loop as `previousSummary` so the next compaction MERGES into it
|
|
89
|
+
* (UPDATE_SUMMARIZATION) instead of summarizing from scratch.
|
|
90
|
+
*/
|
|
91
|
+
compactionSummary?: string;
|
|
92
|
+
model?: {
|
|
93
|
+
provider: string;
|
|
94
|
+
modelId: string;
|
|
95
|
+
};
|
|
96
|
+
/** Last thinking-level along the branch, if any was recorded. */
|
|
97
|
+
thinkingLevel?: string;
|
|
98
|
+
/** Last active-tool-name set along the branch, if any was recorded. */
|
|
99
|
+
activeToolNames?: string[];
|
|
100
|
+
/** Current session name (last non-empty `session_info` along the branch). */
|
|
101
|
+
sessionName?: string;
|
|
102
|
+
}
|
|
103
|
+
/** Persistence backend for a session tree. All ids are tree-unique. */
|
|
104
|
+
export interface SessionStorage {
|
|
105
|
+
getMetadata(): SessionMetadata;
|
|
106
|
+
getLeafId(): string | null;
|
|
107
|
+
setLeafId(id: string | null): void;
|
|
108
|
+
createEntryId(): string;
|
|
109
|
+
appendEntry(entry: SessionEntry): void;
|
|
110
|
+
getEntry(id: string): SessionEntry | undefined;
|
|
111
|
+
getEntries(): SessionEntry[];
|
|
112
|
+
findEntries(type: SessionEntryType): SessionEntry[];
|
|
113
|
+
getLabel(id: string): string | undefined;
|
|
114
|
+
/** Root → leaf path of entries, throwing on a broken chain. */
|
|
115
|
+
getPathToRoot(leafId: string): SessionEntry[];
|
|
116
|
+
}
|
|
117
|
+
/** Header metadata for a session. */
|
|
118
|
+
export interface SessionMetadata {
|
|
119
|
+
id: string;
|
|
120
|
+
timestamp: number;
|
|
121
|
+
cwd: string;
|
|
122
|
+
parentSessionId?: string;
|
|
123
|
+
}
|
|
124
|
+
/** Generate a fresh session id. */
|
|
125
|
+
export declare function createSessionId(): string;
|
|
126
|
+
/**
|
|
127
|
+
* Whether an entry produces a message in {@link buildSessionContext}'s
|
|
128
|
+
* reconstructed context: transcript messages plus non-empty branch summaries
|
|
129
|
+
* (folded in as synthetic user messages). Anchor arithmetic that aligns a
|
|
130
|
+
* compaction's kept-message suffix with branch entries MUST filter with this
|
|
131
|
+
* predicate — an inline re-derivation counting `message` entries alone lands
|
|
132
|
+
* the anchor one entry early whenever a branch-summary synthetic sits in the
|
|
133
|
+
* kept tail. buildSessionContext itself folds through this predicate, so the
|
|
134
|
+
* counting rule cannot drift apart from the folding rule.
|
|
135
|
+
*/
|
|
136
|
+
export declare function producesContextMessage(entry: SessionEntry): boolean;
|
|
137
|
+
/** Pure reducer: collapse a root→leaf path into a {@link SessionContext}. */
|
|
138
|
+
export declare function buildSessionContext(path: SessionEntry[]): SessionContext;
|
|
139
|
+
/** A branchable session tree backed by a {@link SessionStorage}. */
|
|
140
|
+
export declare class Session {
|
|
141
|
+
private readonly storage;
|
|
142
|
+
constructor(storage: SessionStorage);
|
|
143
|
+
getStorage(): SessionStorage;
|
|
144
|
+
getMetadata(): SessionMetadata;
|
|
145
|
+
getLeafId(): string | null;
|
|
146
|
+
getEntry(id: string): SessionEntry | undefined;
|
|
147
|
+
getEntries(): SessionEntry[];
|
|
148
|
+
getLabel(id: string): string | undefined;
|
|
149
|
+
/** The root→leaf path of entries for the current (or a given) leaf. */
|
|
150
|
+
getBranch(fromId?: string): SessionEntry[];
|
|
151
|
+
/** Reconstruct the conversation context from the current branch. */
|
|
152
|
+
buildContext(): SessionContext;
|
|
153
|
+
private appendUnder;
|
|
154
|
+
/** Append a transcript message under the current leaf. Returns the new id. */
|
|
155
|
+
appendMessage(message: AgentMessage): string;
|
|
156
|
+
/** Append a compaction boundary. Returns the new id. */
|
|
157
|
+
appendCompaction(summary: string, firstKeptEntryId: string, tokensBefore: number): string;
|
|
158
|
+
/** Record a model change at the current leaf. Returns the new id. */
|
|
159
|
+
appendModelChange(provider: string, modelId: string): string;
|
|
160
|
+
/** Attach a label to a target entry. Returns the new id. */
|
|
161
|
+
appendLabel(targetId: string, label: string): string;
|
|
162
|
+
/**
|
|
163
|
+
* Branch the conversation: repoint the leaf to an existing entry. Subsequent
|
|
164
|
+
* appends grow a new branch from that point. Returns the new leaf id.
|
|
165
|
+
*/
|
|
166
|
+
branch(targetId: string): string;
|
|
167
|
+
/**
|
|
168
|
+
* Repoint the conversation head to an existing entry (or `null` to clear it),
|
|
169
|
+
* optionally recording a summary of the branch being left behind. When a
|
|
170
|
+
* summary is supplied the new leaf becomes that {@link BranchSummaryEntry}
|
|
171
|
+
* (parented to `entryId`) so it folds into the reconstructed context;
|
|
172
|
+
* otherwise the leaf is `entryId` itself. Returns the new branch-summary id,
|
|
173
|
+
* or `undefined` when no summary was recorded.
|
|
174
|
+
*/
|
|
175
|
+
moveTo(entryId: string | null, summary?: {
|
|
176
|
+
summary: string;
|
|
177
|
+
details?: unknown;
|
|
178
|
+
fromHook?: boolean;
|
|
179
|
+
}): string | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* Record (or update) the human-readable session name. Line breaks are
|
|
182
|
+
* collapsed to spaces and the value is trimmed. Returns the new id.
|
|
183
|
+
*/
|
|
184
|
+
appendSessionName(name: string): string;
|
|
185
|
+
}
|
|
186
|
+
/** An in-memory session storage. Useful for tests and ephemeral sessions. */
|
|
187
|
+
export declare class InMemorySessionStorage implements SessionStorage {
|
|
188
|
+
private readonly inner;
|
|
189
|
+
private readonly state;
|
|
190
|
+
constructor(options?: {
|
|
191
|
+
cwd?: string;
|
|
192
|
+
sessionId?: string;
|
|
193
|
+
});
|
|
194
|
+
getMetadata(): SessionMetadata;
|
|
195
|
+
getLeafId(): string | null;
|
|
196
|
+
setLeafId(id: string | null): void;
|
|
197
|
+
createEntryId(): string;
|
|
198
|
+
appendEntry(entry: SessionEntry): void;
|
|
199
|
+
getEntry(id: string): SessionEntry | undefined;
|
|
200
|
+
getEntries(): SessionEntry[];
|
|
201
|
+
findEntries(type: SessionEntryType): SessionEntry[];
|
|
202
|
+
getLabel(id: string): string | undefined;
|
|
203
|
+
getPathToRoot(leafId: string): SessionEntry[];
|
|
204
|
+
}
|
|
205
|
+
/** Minimal append-only file surface so JSONL storage stays env-agnostic. */
|
|
206
|
+
export interface JsonlFile {
|
|
207
|
+
/** Read the entire file. Returns "" when it does not exist. */
|
|
208
|
+
read(): string;
|
|
209
|
+
/** Append a line (the caller supplies the trailing newline). */
|
|
210
|
+
append(line: string): void;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Append-only JSONL session storage. Line 1 is a session header; each later
|
|
214
|
+
* line is one tree entry. The leaf is recomputed after each entry: a `leaf`
|
|
215
|
+
* entry repoints to its `targetId`, otherwise the entry becomes the leaf.
|
|
216
|
+
*/
|
|
217
|
+
export declare class JsonlSessionStorage implements SessionStorage {
|
|
218
|
+
private readonly file;
|
|
219
|
+
private readonly state;
|
|
220
|
+
private readonly inner;
|
|
221
|
+
private constructor();
|
|
222
|
+
/** Create a brand-new JSONL session, writing the header line. */
|
|
223
|
+
static create(file: JsonlFile, options?: {
|
|
224
|
+
cwd?: string;
|
|
225
|
+
sessionId?: string;
|
|
226
|
+
parentSessionId?: string;
|
|
227
|
+
}): JsonlSessionStorage;
|
|
228
|
+
/** Open an existing JSONL session, replaying entries to rebuild the tree. */
|
|
229
|
+
static open(file: JsonlFile): JsonlSessionStorage;
|
|
230
|
+
getMetadata(): SessionMetadata;
|
|
231
|
+
getLeafId(): string | null;
|
|
232
|
+
setLeafId(id: string | null): void;
|
|
233
|
+
createEntryId(): string;
|
|
234
|
+
appendEntry(entry: SessionEntry): void;
|
|
235
|
+
getEntry(id: string): SessionEntry | undefined;
|
|
236
|
+
getEntries(): SessionEntry[];
|
|
237
|
+
findEntries(type: SessionEntryType): SessionEntry[];
|
|
238
|
+
getLabel(id: string): string | undefined;
|
|
239
|
+
getPathToRoot(leafId: string): SessionEntry[];
|
|
240
|
+
}
|
|
241
|
+
/** An in-memory {@link JsonlFile} for tests (no disk). */
|
|
242
|
+
export declare class StringJsonlFile implements JsonlFile {
|
|
243
|
+
private buffer;
|
|
244
|
+
constructor(initial?: string);
|
|
245
|
+
read(): string;
|
|
246
|
+
append(line: string): void;
|
|
247
|
+
/** The current serialized contents (the JSONL text). */
|
|
248
|
+
toString(): string;
|
|
249
|
+
}
|
|
250
|
+
export {};
|
|
251
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,4DAA4D;AAC5D,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,YAAY,GACZ,cAAc,GACd,OAAO,GACP,MAAM,GACN,uBAAuB,GACvB,qBAAqB,GACrB,gBAAgB,GAChB,cAAc,GACd,QAAQ,GACR,gBAAgB,CAAC;AAErB,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,gBAAgB,CAAC;CACxB;AAED,oDAAoD;AACpD,MAAM,WAAW,YAAa,SAAQ,SAAS;IAC7C,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,YAAY,CAAC;CACvB;AAED,kFAAkF;AAClF,MAAM,WAAW,eAAgB,SAAQ,SAAS;IAChD,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,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AAE,MAAM,GAAG,YAAY,EAAE;CAG9C;AAED,0DAA0D;AAC1D,qBAAa,eAAgB,YAAW,SAAS;IAC/C,OAAO,CAAC,MAAM,CAAS;gBACX,OAAO,SAAK;IAGxB,IAAI,IAAI,MAAM;IAGd,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAG1B,wDAAwD;IACxD,QAAQ,IAAI,MAAM;CAGnB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cross-platform deny-list for shell commands. It rejects the most dangerous
|
|
3
|
+
* destructive operations across POSIX shells (bash/sh/zsh) AND Windows
|
|
4
|
+
* `cmd.exe` / PowerShell equivalents. This is a coarse safety net, not a
|
|
5
|
+
* sandbox: it raises the bar against accidental catastrophic commands while
|
|
6
|
+
* letting ordinary tooling through.
|
|
7
|
+
*/
|
|
8
|
+
export interface BlocklistMatch {
|
|
9
|
+
/** Human-readable reason the command was blocked. */
|
|
10
|
+
reason: string;
|
|
11
|
+
/** The pattern source that triggered the block. */
|
|
12
|
+
pattern: string;
|
|
13
|
+
}
|
|
14
|
+
/** Inspect a command; return a match when it is denied, or `undefined`. */
|
|
15
|
+
export declare function matchBlocklist(command: string): BlocklistMatch | undefined;
|
|
16
|
+
/** Convenience predicate over {@link matchBlocklist}. */
|
|
17
|
+
export declare function isBlockedCommand(command: string): boolean;
|
|
18
|
+
//# sourceMappingURL=shell-blocklist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-blocklist.d.ts","sourceRoot":"","sources":["../src/shell-blocklist.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,cAAc;IAC7B,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,OAAO,EAAE,MAAM,CAAC;CACjB;AA6ED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAQ1E;AAED,yDAAyD;AACzD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEzD"}
|
package/dist/skills.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skills: model-facing skill primitives.
|
|
3
|
+
*
|
|
4
|
+
* A skill is a Markdown file whose YAML frontmatter carries metadata (`name`,
|
|
5
|
+
* `description`) and whose body is the full instructions. Skills reach the model
|
|
6
|
+
* through progressive disclosure: a compact `<available_skills>` catalog (name /
|
|
7
|
+
* description / location) is placed in the system prompt via the S1 skills slot,
|
|
8
|
+
* and the model loads a skill's full body from its file with the read tool on
|
|
9
|
+
* demand when a task matches its description.
|
|
10
|
+
*
|
|
11
|
+
* This module is a standalone runtime primitive. It reuses
|
|
12
|
+
* {@link parseYamlFrontmatter} for the frontmatter split (loader.ts) and mirrors
|
|
13
|
+
* the {@link AgentRegistry} shape for the name-keyed store. Parsing is pure —
|
|
14
|
+
* deterministic, with no clock or randomness. A host composes the catalog into a
|
|
15
|
+
* system prompt with S1:
|
|
16
|
+
*
|
|
17
|
+
* builder.section(SYSTEM_PROMPT_SECTIONS.skills, formatSkillsForSystemPrompt(skills));
|
|
18
|
+
*/
|
|
19
|
+
/** A skill: named instructions the model can load on demand. */
|
|
20
|
+
export interface Skill {
|
|
21
|
+
/** Identifier — frontmatter `name`, else the file basename (without `.md`). */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Short description shown in the catalog so the model can match a task to it. */
|
|
24
|
+
description: string;
|
|
25
|
+
/** Source file path; shown in the catalog for the model to read on demand. */
|
|
26
|
+
location: string;
|
|
27
|
+
/** Full skill instructions (the Markdown body). */
|
|
28
|
+
body: string;
|
|
29
|
+
/**
|
|
30
|
+
* When true the skill is hidden from the model-facing catalog
|
|
31
|
+
* ({@link formatSkillsForSystemPrompt}) — it is invoked explicitly, never by
|
|
32
|
+
* the model.
|
|
33
|
+
*/
|
|
34
|
+
disableModelInvocation?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parse Markdown skill content into a {@link Skill}. Pure — no filesystem access.
|
|
38
|
+
*
|
|
39
|
+
* The frontmatter is split via {@link parseYamlFrontmatter}. The name is the
|
|
40
|
+
* frontmatter `name` when present, otherwise `fallbackName` (the loader passes
|
|
41
|
+
* the file basename). The description is the frontmatter `description` (else an
|
|
42
|
+
* empty string). The trimmed body becomes {@link Skill.body}.
|
|
43
|
+
* {@link Skill.disableModelInvocation} reflects the frontmatter
|
|
44
|
+
* `disable-model-invocation` flag.
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseSkill(fallbackName: string, content: string, location: string): Skill;
|
|
47
|
+
/**
|
|
48
|
+
* Load a Markdown skill file. The name falls back to the file's basename without
|
|
49
|
+
* the `.md` suffix (a frontmatter `name` overrides it); {@link Skill.location} is
|
|
50
|
+
* the file path.
|
|
51
|
+
*/
|
|
52
|
+
export declare function loadSkill(filePath: string): Promise<Skill>;
|
|
53
|
+
/** Load several skill files (concurrently), preserving input order. */
|
|
54
|
+
export declare function loadSkills(filePaths: string[]): Promise<Skill[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Finds skill files under `dir`: `<dir>/<name>/SKILL.md` and flat `<dir>/<name>.md`.
|
|
57
|
+
* Missing/unreadable dir returns []. Sorted for determinism.
|
|
58
|
+
*/
|
|
59
|
+
export declare function discoverSkillFiles(dir: string): Promise<string[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Loads every discovered skill. SKILL.md files fall back to their directory name;
|
|
62
|
+
* a loose SKILL.md in the scanned root falls back to "SKILL". Unreadable files are
|
|
63
|
+
* skipped; symlinked entries are not followed.
|
|
64
|
+
*/
|
|
65
|
+
export declare function discoverSkills(dir: string): Promise<Skill[]>;
|
|
66
|
+
/** A name-keyed store of {@link Skill}s (mirrors the AgentRegistry shape). */
|
|
67
|
+
export declare class SkillRegistry {
|
|
68
|
+
private readonly skills;
|
|
69
|
+
constructor(options?: {
|
|
70
|
+
skills?: Skill[];
|
|
71
|
+
});
|
|
72
|
+
/** Add a skill. Throws if the name is already registered. */
|
|
73
|
+
add(skill: Skill): void;
|
|
74
|
+
/** Add several skills. */
|
|
75
|
+
addMany(skills: Skill[]): void;
|
|
76
|
+
/** Get a skill by name. Throws if it does not exist. */
|
|
77
|
+
get(name: string): Skill;
|
|
78
|
+
/** Find a skill by name (undefined if absent). */
|
|
79
|
+
find(name: string): Skill | undefined;
|
|
80
|
+
/** List all registered skills. */
|
|
81
|
+
list(): Skill[];
|
|
82
|
+
/** Filter skills by a predicate (or return all when omitted). */
|
|
83
|
+
query(condition?: (skill: Skill) => boolean): Skill[];
|
|
84
|
+
/** Number of registered skills. */
|
|
85
|
+
get size(): number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Build the `<available_skills>` catalog string for the system prompt (the S1
|
|
89
|
+
* `skills` slot). Each visible skill contributes its name, description, and
|
|
90
|
+
* location. Skills flagged {@link Skill.disableModelInvocation} are filtered out
|
|
91
|
+
* so the model is never told to invoke them. Returns `""` when there is nothing
|
|
92
|
+
* to show (empty input, or every skill filtered) so S1 omits the slot cleanly.
|
|
93
|
+
*/
|
|
94
|
+
export declare function formatSkillsForSystemPrompt(skills: readonly Skill[]): string;
|
|
95
|
+
//# sourceMappingURL=skills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../src/skills.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAOH,gEAAgE;AAChE,MAAM,WAAW,KAAK;IACpB,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,kFAAkF;IAClF,WAAW,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED;;;;;;;;;GAS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G,MAAM,CAc5E"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composable system-prompt assembly.
|
|
3
|
+
*
|
|
4
|
+
* A runtime-level primitive for building the final `systemPrompt` string from an
|
|
5
|
+
* ordered list of NAMED sections. Any agent (not just a coding agent) composes
|
|
6
|
+
* its system prompt from the same standard slots: a base/persona section, an
|
|
7
|
+
* optional custom section, a skills-catalog slot (filled by the skills
|
|
8
|
+
* subsystem), and an environment section (date + working directory) that agents
|
|
9
|
+
* conventionally place last.
|
|
10
|
+
*
|
|
11
|
+
* Assembly is pure section concatenation — there is no template interpolation
|
|
12
|
+
* here; reusable prompt templates + variable substitution are a separate
|
|
13
|
+
* utility. This module only orders sections, omits empty ones cleanly, and
|
|
14
|
+
* renders deterministically.
|
|
15
|
+
*
|
|
16
|
+
* Additive: the produced string feeds the existing `systemPrompt` option. The
|
|
17
|
+
* builder is an optional producer of that string; nothing that already sets
|
|
18
|
+
* `systemPrompt` directly is affected.
|
|
19
|
+
*/
|
|
20
|
+
/** One named part of a system prompt. Empty/whitespace-only/absent → omitted. */
|
|
21
|
+
export interface SystemPromptSection {
|
|
22
|
+
/** Section identifier (for the standard slots and for later lookup). */
|
|
23
|
+
name: string;
|
|
24
|
+
/** Section body. Absent or blank after trimming means the section is omitted. */
|
|
25
|
+
content?: string;
|
|
26
|
+
}
|
|
27
|
+
/** Options controlling how sections are joined. */
|
|
28
|
+
export interface AssembleSystemPromptOptions {
|
|
29
|
+
/** Separator inserted between rendered sections. Default: a blank line. */
|
|
30
|
+
separator?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The standard section slots an agent's system prompt is assembled from. The
|
|
34
|
+
* skills catalog is a general slot the skills subsystem fills; it renders as an
|
|
35
|
+
* empty (omitted) section until then.
|
|
36
|
+
*/
|
|
37
|
+
export declare const SYSTEM_PROMPT_SECTIONS: {
|
|
38
|
+
/** Base persona / role instructions. */
|
|
39
|
+
readonly persona: "persona";
|
|
40
|
+
/** Caller-supplied extra instructions appended to the base. */
|
|
41
|
+
readonly custom: "custom";
|
|
42
|
+
/** Skills catalog slot — filled by the skills subsystem. */
|
|
43
|
+
readonly skills: "skills";
|
|
44
|
+
/** Runtime environment: current date + working directory (placed last). */
|
|
45
|
+
readonly environment: "environment";
|
|
46
|
+
};
|
|
47
|
+
/** A standard section slot name. */
|
|
48
|
+
export type SystemPromptSectionName = (typeof SYSTEM_PROMPT_SECTIONS)[keyof typeof SYSTEM_PROMPT_SECTIONS];
|
|
49
|
+
/**
|
|
50
|
+
* Assemble a system-prompt string from ordered named sections.
|
|
51
|
+
*
|
|
52
|
+
* Sections render in the given order. Empty, whitespace-only, or content-less
|
|
53
|
+
* sections are omitted with no stray separator. Each section's outer whitespace
|
|
54
|
+
* is trimmed so the join is clean and the render is deterministic (identical
|
|
55
|
+
* input → identical string).
|
|
56
|
+
*/
|
|
57
|
+
export declare function assembleSystemPrompt(sections: readonly SystemPromptSection[], options?: AssembleSystemPromptOptions): string;
|
|
58
|
+
/**
|
|
59
|
+
* A small chainable builder over {@link assembleSystemPrompt}. Register named
|
|
60
|
+
* sections in order, then `render()`. Adding an empty/absent section reserves
|
|
61
|
+
* its ordered slot without emitting anything (e.g. a `skills` slot the skills
|
|
62
|
+
* subsystem fills later).
|
|
63
|
+
*/
|
|
64
|
+
export declare class SystemPromptBuilder {
|
|
65
|
+
private readonly sections;
|
|
66
|
+
private readonly separator;
|
|
67
|
+
constructor(options?: AssembleSystemPromptOptions);
|
|
68
|
+
/** Append a named section in order. Chainable. */
|
|
69
|
+
section(name: string, content?: string): this;
|
|
70
|
+
/** Render the accumulated sections to a single system-prompt string. */
|
|
71
|
+
render(): string;
|
|
72
|
+
}
|
|
73
|
+
/** Inputs for the environment section. */
|
|
74
|
+
export interface EnvironmentSectionInput {
|
|
75
|
+
/** Current working directory (backslashes normalized to `/` on render). */
|
|
76
|
+
cwd?: string;
|
|
77
|
+
/**
|
|
78
|
+
* The date to stamp — REQUIRED so this section is a pure function of its
|
|
79
|
+
* inputs (deterministic). The caller supplies the current time at the call
|
|
80
|
+
* site, or a fixed date; the library never reads the wall clock itself.
|
|
81
|
+
*/
|
|
82
|
+
date: Date;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Build the environment section (current date + working directory) that agents
|
|
86
|
+
* conventionally place last in the system prompt. The date is stamped as
|
|
87
|
+
* `YYYY-MM-DD`; the working-directory line is omitted when no `cwd` is given.
|
|
88
|
+
*/
|
|
89
|
+
export declare function environmentSection(input: EnvironmentSectionInput): SystemPromptSection;
|
|
90
|
+
//# sourceMappingURL=system-prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../src/system-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,iFAAiF;AACjF,MAAM,WAAW,mBAAmB;IAClC,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,mDAAmD;AACnD,MAAM,WAAW,2BAA2B;IAC1C,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAKD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;IACjC,wCAAwC;;IAExC,+DAA+D;;IAE/D,4DAA4D;;IAE5D,2EAA2E;;CAEnE,CAAC;AAEX,oCAAoC;AACpC,MAAM,MAAM,uBAAuB,GACjC,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAC;AAQvE;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,EACxC,OAAO,GAAE,2BAAgC,GACxC,MAAM,CAQR;AAED;;;;;GAKG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;IACtD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEvB,OAAO,GAAE,2BAAgC;IAIrD,kDAAkD;IAClD,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAK7C,wEAAwE;IACxE,MAAM,IAAI,MAAM;CAGjB;AAED,0CAA0C;AAC1C,MAAM,WAAW,uBAAuB;IACtC,2EAA2E;IAC3E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,IAAI,EAAE,IAAI,CAAC;CACZ;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,mBAAmB,CAUtF"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type AssistantMessage, type TSchema, type ToolCall, type ToolResultMessage } from "@ap3x/ai";
|
|
2
|
+
import type { AgentContext, AgentHooks, AgentToolResult, AgentToolUpdate, AnyAgentTool } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Declare a tool from a plain object. The `parameters` schema is a TypeBox
|
|
5
|
+
* `TSchema` (re-exported from `@ap3x/ai` as `Type`), validated and coerced
|
|
6
|
+
* before `execute` runs.
|
|
7
|
+
*/
|
|
8
|
+
export declare function defineTool<TParameters extends TSchema, TDetails = unknown>(spec: {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
parameters: TParameters;
|
|
12
|
+
label?: string;
|
|
13
|
+
executionMode?: "sequential" | "parallel";
|
|
14
|
+
prepareArguments?: (rawArguments: Record<string, unknown>) => Record<string, unknown>;
|
|
15
|
+
execute: (toolCallId: string, args: Record<string, unknown>, signal?: AbortSignal, onUpdate?: (update: AgentToolUpdate<TDetails>) => void) => Promise<AgentToolResult<TDetails>> | AgentToolResult<TDetails>;
|
|
16
|
+
}): AnyAgentTool;
|
|
17
|
+
export interface ToolBatchResult {
|
|
18
|
+
/** Tool-result messages in source order (matching the tool-call order). */
|
|
19
|
+
messages: ToolResultMessage[];
|
|
20
|
+
/** True when EVERY result in the batch requested termination. */
|
|
21
|
+
terminate: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ExecuteToolCallsOptions {
|
|
24
|
+
toolCalls: ToolCall[];
|
|
25
|
+
tools: AnyAgentTool[];
|
|
26
|
+
hooks?: AgentHooks;
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
/** "sequential" or "parallel". Any per-tool sequential mode forces sequential. */
|
|
29
|
+
mode?: "sequential" | "parallel";
|
|
30
|
+
/** The assistant message that requested this batch (enriches the hook context). */
|
|
31
|
+
assistantMessage?: AssistantMessage;
|
|
32
|
+
/** The loop's working context at batch time (enriches the hook context). */
|
|
33
|
+
context?: AgentContext;
|
|
34
|
+
emit: (event: ToolExecutionEvent) => void | Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
/** Events emitted during tool execution, forwarded by the loop to its sink. */
|
|
37
|
+
export type ToolExecutionEvent = {
|
|
38
|
+
type: "tool_execution_start";
|
|
39
|
+
toolCallId: string;
|
|
40
|
+
toolName: string;
|
|
41
|
+
args: Record<string, unknown>;
|
|
42
|
+
} | {
|
|
43
|
+
type: "tool_execution_update";
|
|
44
|
+
toolCallId: string;
|
|
45
|
+
toolName: string;
|
|
46
|
+
update: AgentToolUpdate;
|
|
47
|
+
} | {
|
|
48
|
+
type: "tool_execution_end";
|
|
49
|
+
toolCallId: string;
|
|
50
|
+
toolName: string;
|
|
51
|
+
result: ToolResultMessage;
|
|
52
|
+
isError: boolean;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Execute a batch of tool calls. Sequential mode preserves strict order and
|
|
56
|
+
* breaks early on abort. Parallel mode runs all ready calls concurrently but
|
|
57
|
+
* emits `tool_execution_end` and the result messages in SOURCE order so the
|
|
58
|
+
* transcript stays deterministic.
|
|
59
|
+
*/
|
|
60
|
+
export declare function executeToolCalls(options: ExecuteToolCallsOptions): Promise<ToolBatchResult>;
|
|
61
|
+
//# sourceMapping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