agentfootprint 7.12.0 → 7.13.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/core/Agent.js +39 -5
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/agent/AgentBuilder.js +59 -1
- package/dist/core/agent/AgentBuilder.js.map +1 -1
- package/dist/core/agent/buildAgentChart.js +6 -0
- package/dist/core/agent/buildAgentChart.js.map +1 -1
- package/dist/core/agent/buildDynamicAgentChart.js +14 -0
- package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/core/agent/stages/callLLM.js +10 -4
- package/dist/core/agent/stages/callLLM.js.map +1 -1
- package/dist/core/agent/stages/seed.js +16 -0
- package/dist/core/agent/stages/seed.js.map +1 -1
- package/dist/core/slots/buildSystemPromptSlot.js +2 -1
- package/dist/core/slots/buildSystemPromptSlot.js.map +1 -1
- package/dist/esm/core/Agent.d.ts +7 -3
- package/dist/esm/core/Agent.js +39 -5
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/agent/AgentBuilder.d.ts +48 -1
- package/dist/esm/core/agent/AgentBuilder.js +59 -1
- package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
- package/dist/esm/core/agent/buildAgentChart.js +6 -0
- package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildDynamicAgentChart.js +14 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/esm/core/agent/stages/callLLM.d.ts +9 -0
- package/dist/esm/core/agent/stages/callLLM.js +10 -4
- package/dist/esm/core/agent/stages/callLLM.js.map +1 -1
- package/dist/esm/core/agent/stages/seed.d.ts +10 -1
- package/dist/esm/core/agent/stages/seed.js +16 -0
- package/dist/esm/core/agent/stages/seed.js.map +1 -1
- package/dist/esm/core/agent/types.d.ts +44 -0
- package/dist/esm/core/slots/buildSystemPromptSlot.d.ts +19 -4
- package/dist/esm/core/slots/buildSystemPromptSlot.js +2 -1
- package/dist/esm/core/slots/buildSystemPromptSlot.js.map +1 -1
- package/dist/esm/lib/injection-engine/index.d.ts +1 -0
- package/dist/esm/lib/injection-engine/index.js +4 -0
- package/dist/esm/lib/injection-engine/index.js.map +1 -1
- package/dist/esm/lib/injection-engine/skillsFromDir.d.ts +80 -0
- package/dist/esm/lib/injection-engine/skillsFromDir.js +243 -0
- package/dist/esm/lib/injection-engine/skillsFromDir.js.map +1 -0
- package/dist/esm/lib/mcp/index.d.ts +6 -5
- package/dist/esm/lib/mcp/index.js +5 -4
- package/dist/esm/lib/mcp/index.js.map +1 -1
- package/dist/esm/lib/mcp/mcpClient.js +21 -9
- package/dist/esm/lib/mcp/mcpClient.js.map +1 -1
- package/dist/esm/lib/mcp/mcpServe.d.ts +70 -0
- package/dist/esm/lib/mcp/mcpServe.js +374 -0
- package/dist/esm/lib/mcp/mcpServe.js.map +1 -0
- package/dist/esm/lib/mcp/types.d.ts +130 -17
- package/dist/esm/lib/mcp/types.js +10 -10
- package/dist/esm/tool-providers/index.d.ts +8 -2
- package/dist/esm/tool-providers/index.js +7 -1
- package/dist/esm/tool-providers/index.js.map +1 -1
- package/dist/lib/injection-engine/index.js +6 -1
- package/dist/lib/injection-engine/index.js.map +1 -1
- package/dist/lib/injection-engine/skillsFromDir.js +270 -0
- package/dist/lib/injection-engine/skillsFromDir.js.map +1 -0
- package/dist/lib/mcp/index.js +7 -5
- package/dist/lib/mcp/index.js.map +1 -1
- package/dist/lib/mcp/mcpClient.js +21 -9
- package/dist/lib/mcp/mcpClient.js.map +1 -1
- package/dist/lib/mcp/mcpServe.js +401 -0
- package/dist/lib/mcp/mcpServe.js.map +1 -0
- package/dist/lib/mcp/types.js +10 -10
- package/dist/tool-providers/index.js +8 -1
- package/dist/tool-providers/index.js.map +1 -1
- package/dist/types/core/Agent.d.ts +7 -3
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/agent/AgentBuilder.d.ts +48 -1
- package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
- package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/stages/callLLM.d.ts +9 -0
- package/dist/types/core/agent/stages/callLLM.d.ts.map +1 -1
- package/dist/types/core/agent/stages/seed.d.ts +10 -1
- package/dist/types/core/agent/stages/seed.d.ts.map +1 -1
- package/dist/types/core/agent/types.d.ts +44 -0
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/core/slots/buildSystemPromptSlot.d.ts +19 -4
- package/dist/types/core/slots/buildSystemPromptSlot.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/index.d.ts +1 -0
- package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/skillsFromDir.d.ts +81 -0
- package/dist/types/lib/injection-engine/skillsFromDir.d.ts.map +1 -0
- package/dist/types/lib/mcp/index.d.ts +6 -5
- package/dist/types/lib/mcp/index.d.ts.map +1 -1
- package/dist/types/lib/mcp/mcpClient.d.ts.map +1 -1
- package/dist/types/lib/mcp/mcpServe.d.ts +71 -0
- package/dist/types/lib/mcp/mcpServe.d.ts.map +1 -0
- package/dist/types/lib/mcp/types.d.ts +130 -17
- package/dist/types/lib/mcp/types.d.ts.map +1 -1
- package/dist/types/tool-providers/index.d.ts +8 -2
- package/dist/types/tool-providers/index.d.ts.map +1 -1
- package/package.json +2 -1
|
@@ -34,6 +34,12 @@ export function buildCallLLMStage(deps) {
|
|
|
34
34
|
// `scope.messagesInjections` is read by ContextRecorder for
|
|
35
35
|
// observability; the LLM-wire path now reads scope.history directly.
|
|
36
36
|
const iteration = scope.iteration;
|
|
37
|
+
// The model for this run. `.configure()` resolved it at seed and
|
|
38
|
+
// COMMITTED it to scope, so what gets called, what the `llm_start`
|
|
39
|
+
// event reports and what cost is priced against are all one value —
|
|
40
|
+
// the one the trace records. Without `.configure()` this is the
|
|
41
|
+
// build-time model and scope is never touched.
|
|
42
|
+
const model = (deps.runConfigured ? scope.resolvedModel : undefined) ?? deps.model;
|
|
37
43
|
// Per-iteration boundary marker (was a dedicated `IterationStart` stage —
|
|
38
44
|
// folded here since emitting is passive observability, not work that needs
|
|
39
45
|
// its own execution stage). Fires FIRST, before the LLM call, so recorders
|
|
@@ -63,7 +69,7 @@ export function buildCallLLMStage(deps) {
|
|
|
63
69
|
typedEmit(scope, 'agentfootprint.stream.llm_start', {
|
|
64
70
|
iteration,
|
|
65
71
|
provider: deps.provider.name,
|
|
66
|
-
model
|
|
72
|
+
model,
|
|
67
73
|
systemPromptChars: systemPrompt.length,
|
|
68
74
|
messagesCount: messages.length,
|
|
69
75
|
toolsCount: activeToolSchemas.length,
|
|
@@ -80,7 +86,7 @@ export function buildCallLLMStage(deps) {
|
|
|
80
86
|
...(systemPrompt.length > 0 && { systemPrompt }),
|
|
81
87
|
messages,
|
|
82
88
|
...(activeToolSchemas.length > 0 && { tools: activeToolSchemas }),
|
|
83
|
-
model
|
|
89
|
+
model,
|
|
84
90
|
...(deps.temperature !== undefined && { temperature: deps.temperature }),
|
|
85
91
|
...(deps.maxTokens !== undefined && { maxTokens: deps.maxTokens }),
|
|
86
92
|
...(deps.thinkingBudget !== undefined && {
|
|
@@ -198,7 +204,7 @@ export function buildCallLLMStage(deps) {
|
|
|
198
204
|
}
|
|
199
205
|
let response;
|
|
200
206
|
if (deps.reliability) {
|
|
201
|
-
response = await executeWithReliability(scope, llmRequest, deps.reliability, deps.provider, deps.provider.name,
|
|
207
|
+
response = await executeWithReliability(scope, llmRequest, deps.reliability, deps.provider, deps.provider.name, model, singleProviderCall, postValidate);
|
|
202
208
|
// `executeWithReliability` returns `undefined` when it took the
|
|
203
209
|
// fail-fast path. It already wrote scope state and called
|
|
204
210
|
// `$break(reason)` — `Agent.run()` translates the propagated
|
|
@@ -231,7 +237,7 @@ export function buildCallLLMStage(deps) {
|
|
|
231
237
|
stopReason: response.stopReason,
|
|
232
238
|
durationMs,
|
|
233
239
|
});
|
|
234
|
-
emitCostTick(scope, deps.pricingTable, deps.costBudget,
|
|
240
|
+
emitCostTick(scope, deps.pricingTable, deps.costBudget, model, response.usage);
|
|
235
241
|
};
|
|
236
242
|
}
|
|
237
243
|
//# sourceMappingURL=callLLM.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callLLM.js","sourceRoot":"","sources":["../../../../../src/core/agent/stages/callLLM.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAYH,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAA2B,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAElB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"callLLM.js","sourceRoot":"","sources":["../../../../../src/core/agent/stages/callLLM.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAYH,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAA2B,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAElB,MAAM,2BAA2B,CAAC;AAuDnC;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,IAAsB;IAEtB,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE;QACrB,MAAM,sBAAsB,GACzB,KAAK,CAAC,sBAAqD,IAAI,EAAE,CAAC;QACrE,4DAA4D;QAC5D,qEAAqE;QACrE,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QAElC,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,GAAG,KAAK,CAAC,iBAAiB,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC;QAC1E,KAAK,CAAC,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC;QAC1C,KAAK,CAAC,kBAAkB,GAAG,QAAQ,CAAC,SAAS,CAAC;QAC9C,0DAA0D;QAC1D,+DAA+D;QAC/D,4DAA4D;QAC5D,+DAA+D;QAC/D,IAAI,QAAQ,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YACtC,KAA2D,CAAC,WAAW;gBACtE,QAAQ,CAAC,WAAW,CAAC;QACzB,CAAC;QAED,SAAS,CAAC,KAAK,EAAE,+BAA+B,EAAE;YAChD,SAAS;YACT,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,aAAa,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM;YACxC,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,UAAU;SACX,CAAC,CAAC;QAEH,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjF,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import type { TypedScope } from 'footprintjs';
|
|
20
20
|
import type { LLMMessage, LLMToolSchema } from '../../../adapters/types.js';
|
|
21
|
-
import type { AgentState } from '../types.js';
|
|
21
|
+
import type { AgentInput, AgentState, RunConfig } from '../types.js';
|
|
22
22
|
export interface SeedStageDeps {
|
|
23
23
|
/** Resolved `clampIterations(opts.maxIterations ?? 10)`. Frozen at
|
|
24
24
|
* chart-build time. */
|
|
@@ -44,6 +44,15 @@ export interface SeedStageDeps {
|
|
|
44
44
|
* Returns `undefined` only in degenerate (test) cases.
|
|
45
45
|
*/
|
|
46
46
|
readonly getCurrentRunId: () => string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Per-run config resolver from `.configure()`. Seed is where run-level
|
|
49
|
+
* facts are decided AND committed (identity, iteration budget, turn
|
|
50
|
+
* number all land here), so this rides the same commit rather than
|
|
51
|
+
* inventing a second place a run can change itself. Undefined when the
|
|
52
|
+
* consumer never called `.configure()` — and then nothing extra is
|
|
53
|
+
* written, so the commit log is byte-identical to earlier releases.
|
|
54
|
+
*/
|
|
55
|
+
readonly resolveRunConfig?: (input: AgentInput) => RunConfig | undefined;
|
|
47
56
|
}
|
|
48
57
|
/**
|
|
49
58
|
* Build the seed stage function for an Agent instance. Captures both
|
|
@@ -90,6 +90,22 @@ export function buildSeedStage(deps) {
|
|
|
90
90
|
// graph through the entry router (cold start). The Injection Engine advances
|
|
91
91
|
// it each iteration; undefined for agents without a skillGraph().
|
|
92
92
|
scope.currentSkillId = undefined;
|
|
93
|
+
// `.configure()` — resolved ONCE here (seed runs exactly once per run)
|
|
94
|
+
// and written to scope, which means the run's commit log records the
|
|
95
|
+
// model and instructions the run actually used. A run that changed its
|
|
96
|
+
// own model without committing that fact would produce a trace that
|
|
97
|
+
// reads as if the built-in default answered.
|
|
98
|
+
//
|
|
99
|
+
// Only what the resolver actually returned is written: an agent with no
|
|
100
|
+
// `.configure()`, or one whose resolver returned `{}`, commits nothing
|
|
101
|
+
// extra and behaves exactly as before.
|
|
102
|
+
if (deps.resolveRunConfig) {
|
|
103
|
+
const resolved = deps.resolveRunConfig(args);
|
|
104
|
+
if (resolved?.model !== undefined)
|
|
105
|
+
scope.resolvedModel = resolved.model;
|
|
106
|
+
if (resolved?.instructions !== undefined)
|
|
107
|
+
scope.resolvedInstructions = resolved.instructions;
|
|
108
|
+
}
|
|
93
109
|
typedEmit(scope, 'agentfootprint.agent.turn_start', {
|
|
94
110
|
turnIndex: 0,
|
|
95
111
|
userPrompt: args.message,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.js","sourceRoot":"","sources":["../../../../../src/core/agent/stages/seed.ts"],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,eAAe,CAAC;QAC7C,KAAK,CAAC,aAAa,GAAG,SAAS,CAAC;QAChC,KAAK,CAAC,YAAY,GAAG,EAAE,CAAC;QACxB,6EAA6E;QAC7E,6EAA6E;QAC7E,kEAAkE;QAClE,KAAK,CAAC,cAAc,GAAG,SAAS,CAAC;QAEjC,uEAAuE;QACvE,qEAAqE;QACrE,uEAAuE;QACvE,oEAAoE;QACpE,6CAA6C;QAC7C,EAAE;QACF,wEAAwE;QACxE,uEAAuE;QACvE,uCAAuC;QACvC,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YAC7C,IAAI,QAAQ,EAAE,KAAK,KAAK,SAAS;gBAAE,KAAK,CAAC,aAAa,GAAG,QAAQ,CAAC,KAAK,CAAC;YACxE,IAAI,QAAQ,EAAE,YAAY,KAAK,SAAS;gBAAE,KAAK,CAAC,oBAAoB,GAAG,QAAQ,CAAC,YAAY,CAAC;QAC/F,CAAC;QAED,SAAS,CAAC,KAAK,EAAE,iCAAiC,EAAE;YAClD,SAAS,EAAE,CAAC;YACZ,UAAU,EAAE,IAAI,CAAC,OAAO;SACzB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -256,6 +256,39 @@ export interface AgentOptions {
|
|
|
256
256
|
*/
|
|
257
257
|
readonly observerDeliveryOptions?: ObserverDeliveryOptions;
|
|
258
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* What `.configure(fn)` may change for one run. Both fields are
|
|
261
|
+
* optional; returning `{}` (or nothing) means "use the built defaults",
|
|
262
|
+
* which is exactly what an agent without `.configure()` does.
|
|
263
|
+
*
|
|
264
|
+
* Deliberately NOT the tools axis — `.toolProvider()` already owns that,
|
|
265
|
+
* and it is consulted every iteration rather than once per run.
|
|
266
|
+
*/
|
|
267
|
+
export interface RunConfig {
|
|
268
|
+
/** Model id for every LLM call in this run. */
|
|
269
|
+
readonly model?: string;
|
|
270
|
+
/** Replaces the base system prompt set by `.system(...)` for this run. */
|
|
271
|
+
readonly instructions?: string;
|
|
272
|
+
}
|
|
273
|
+
/** What a `.configure(fn)` resolver is given. */
|
|
274
|
+
export interface RunConfigContext {
|
|
275
|
+
/** The message this run was started with. */
|
|
276
|
+
readonly message: string;
|
|
277
|
+
/** The memory identity passed to `run({ identity })`, when there was one. */
|
|
278
|
+
readonly identity?: MemoryIdentity;
|
|
279
|
+
/** This run's id — the same one that stamps every typed event's `meta.runId`. */
|
|
280
|
+
readonly runId: string;
|
|
281
|
+
/** What the agent was BUILT with, so a resolver can decide relative to it. */
|
|
282
|
+
readonly defaults: {
|
|
283
|
+
readonly model: string;
|
|
284
|
+
readonly instructions: string;
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Per-run configuration resolver — see `AgentBuilder.configure`. Called
|
|
289
|
+
* exactly once per run, synchronously, at the start of the run.
|
|
290
|
+
*/
|
|
291
|
+
export type RunConfigFn = (ctx: RunConfigContext) => RunConfig | undefined;
|
|
259
292
|
export interface AgentInput {
|
|
260
293
|
readonly message: string;
|
|
261
294
|
/**
|
|
@@ -363,6 +396,17 @@ export interface AgentState {
|
|
|
363
396
|
/** Name of the entry scorer that produced `entryScores` (`'keyword'` /
|
|
364
397
|
* `'embedding'` / a custom scorer's name). */
|
|
365
398
|
entryScorer?: string;
|
|
399
|
+
/** The model `.configure()` resolved for THIS run, written by seed and read
|
|
400
|
+
* by CallLLM. Present only when a resolver returned one — a run that did
|
|
401
|
+
* not change its model records nothing here, so an agent without
|
|
402
|
+
* `.configure()` commits exactly what it always did. The point of writing
|
|
403
|
+
* it at all is that the trace must say which model actually answered:
|
|
404
|
+
* a run that switched models without recording it would be a trace that
|
|
405
|
+
* lies about its own most expensive fact. */
|
|
406
|
+
resolvedModel?: string;
|
|
407
|
+
/** The base system prompt `.configure()` resolved for THIS run, replacing
|
|
408
|
+
* `.system(...)`. Same rule: absent unless a resolver returned one. */
|
|
409
|
+
resolvedInstructions?: string;
|
|
366
410
|
/** Set when a `PermissionChecker` returns `{ result: 'halt', ... }`.
|
|
367
411
|
* `Agent.run()` reads these at the API boundary and throws a typed
|
|
368
412
|
* `PolicyHaltError` carrying the same context — the chart $break's
|
|
@@ -17,17 +17,32 @@ import type { FlowChart } from 'footprintjs';
|
|
|
17
17
|
* Function that produces the system prompt string given runtime scope
|
|
18
18
|
* context. Receives the subflow's $getArgs() payload.
|
|
19
19
|
*/
|
|
20
|
-
export type SystemPromptFn = (args:
|
|
20
|
+
export type SystemPromptFn = (args: SystemPromptSlotArgs) => string | Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* What the slot's `$getArgs()` carries. `instructions` is present only when
|
|
23
|
+
* the Agent's `.configure()` resolved a per-run system prompt — the mount's
|
|
24
|
+
* inputMapper omits the key entirely otherwise, so an unconfigured agent
|
|
25
|
+
* seeds this subflow with exactly the state it always did.
|
|
26
|
+
*/
|
|
27
|
+
export interface SystemPromptSlotArgs {
|
|
21
28
|
readonly userMessage?: string;
|
|
22
29
|
readonly iteration?: number;
|
|
23
|
-
|
|
30
|
+
readonly instructions?: string;
|
|
31
|
+
}
|
|
24
32
|
export interface SystemPromptSlotConfig {
|
|
25
33
|
/** Static string OR a function. Empty string → no injection, empty slot. */
|
|
26
34
|
readonly prompt: string | SystemPromptFn;
|
|
27
35
|
/** Budget cap (chars). Default: 4000. */
|
|
28
36
|
readonly budgetCap?: number;
|
|
29
|
-
/**
|
|
30
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Where this prompt originated, recorded on the base InjectionRecord
|
|
39
|
+
* (e.g. `"agent.system()"`). A function when the origin depends on the
|
|
40
|
+
* run — an Agent with `.configure()` reports `Agent.configure()` on the
|
|
41
|
+
* runs that actually overrode the prompt and `Agent.system()` on the rest,
|
|
42
|
+
* so the context record names the real author rather than a build-time
|
|
43
|
+
* guess.
|
|
44
|
+
*/
|
|
45
|
+
readonly reason?: string | ((args: SystemPromptSlotArgs) => string);
|
|
31
46
|
}
|
|
32
47
|
/**
|
|
33
48
|
* Build the System-Prompt slot subflow.
|
|
@@ -27,13 +27,14 @@ import { composeSlot, fnv1a, formatOverflowWarning, slotOverflow, truncate } fro
|
|
|
27
27
|
*/
|
|
28
28
|
export function buildSystemPromptSlot(config) {
|
|
29
29
|
const budgetCap = config.budgetCap ?? 4000;
|
|
30
|
-
const
|
|
30
|
+
const reasonSource = config.reason ?? 'static system prompt';
|
|
31
31
|
const promptSource = config.prompt;
|
|
32
32
|
// Dedup latch for the human-facing overflow warning (see buildToolsSlot).
|
|
33
33
|
let warnedOverflow = false;
|
|
34
34
|
return flowChart('Compose', async (scope) => {
|
|
35
35
|
const args = scope.$getArgs();
|
|
36
36
|
const resolved = typeof promptSource === 'function' ? await promptSource(args) : promptSource;
|
|
37
|
+
const reason = typeof reasonSource === 'function' ? reasonSource(args) : reasonSource;
|
|
37
38
|
const injections = [];
|
|
38
39
|
// Base prompt — `source: 'base'`. Configured at build time via
|
|
39
40
|
// Agent.create({...}).system('...') OR LLMCall config. Baseline
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSystemPromptSlot.js","sourceRoot":"","sources":["../../../../src/core/slots/buildSystemPromptSlot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"buildSystemPromptSlot.js","sourceRoot":"","sources":["../../../../src/core/slots/buildSystemPromptSlot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,E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,SAAS,IAAI,CAAC,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;QAC7F,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;QAE7D,kEAAkE;QAClE,MAAM,QAAQ,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;QAC3C,IAAI,QAAQ,EAAE,CAAC;YACb,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC9D,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,cAAc,GAAG,IAAI,CAAC;gBACtB,OAAO,CAAC,IAAI,CACV,qBAAqB,CAAC;oBACpB,QAAQ;oBACR,SAAS,EAAE,UAAU,CAAC,MAAM;oBAC5B,QAAQ,EAAE,iBAAiB;oBAC3B,WAAW,EAAE,WAAW;oBACxB,MAAM,EAAE,kEAAkE;iBAC3E,CAAC,CACH,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC,EACD,SAAS,EACT,EAAE,WAAW,EAAE,4BAA4B,EAAE,CAC9C,CAAC,KAAK,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -13,6 +13,7 @@ export { defineInstruction, type DefineInstructionOptions } from './factories/de
|
|
|
13
13
|
export { defineRelevanceHint, type RelevanceHintOptions } from './factories/defineRelevanceHint.js';
|
|
14
14
|
export { defineSkill, resolveSurfaceMode, type DefineSkillOptions, type SurfaceMode, type RefreshPolicy, type AutoActivateMode, } from './factories/defineSkill.js';
|
|
15
15
|
export { SkillRegistry, type SkillRegistryOptions } from './SkillRegistry.js';
|
|
16
|
+
export { skillsFromDir, type SkillsFromDirOptions } from './skillsFromDir.js';
|
|
16
17
|
export { buildListSkillsTool, buildReadSkillTool, type SkillToolPair } from './skillTools.js';
|
|
17
18
|
export { defineSteering, type DefineSteeringOptions } from './factories/defineSteering.js';
|
|
18
19
|
export { defineFact, type DefineFactOptions } from './factories/defineFact.js';
|
|
@@ -15,6 +15,10 @@ export { defineInstruction } from './factories/defineInstruction.js';
|
|
|
15
15
|
export { defineRelevanceHint } from './factories/defineRelevanceHint.js';
|
|
16
16
|
export { defineSkill, resolveSurfaceMode, } from './factories/defineSkill.js';
|
|
17
17
|
export { SkillRegistry } from './SkillRegistry.js';
|
|
18
|
+
// File-authored skills — a loader over `defineSkill`, not a second mechanism.
|
|
19
|
+
// Node-only (reads the filesystem); node:fs is imported lazily inside the call
|
|
20
|
+
// so this barrel stays safe to import from a browser bundle.
|
|
21
|
+
export { skillsFromDir } from './skillsFromDir.js';
|
|
18
22
|
// Skill-tool builders — used by SkillRegistry.toTools() and the Agent's
|
|
19
23
|
// auto-attach path. Exported so consumers building custom tool wiring
|
|
20
24
|
// (e.g., gatedTools chains) can compose the same `list_skills` /
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/injection-engine/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,+DAA+D;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,SAAS;AACT,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EACL,2BAA2B,GAE5B,MAAM,kCAAkC,CAAC;AAE1C,gFAAgF;AAChF,OAAO,EAAE,iBAAiB,EAAiC,MAAM,kCAAkC,CAAC;AACpG,OAAO,EAAE,mBAAmB,EAA6B,MAAM,oCAAoC,CAAC;AAEpG,OAAO,EACL,WAAW,EACX,kBAAkB,GAKnB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,aAAa,EAA6B,MAAM,oBAAoB,CAAC;AAE9E,wEAAwE;AACxE,sEAAsE;AACtE,iEAAiE;AACjE,+BAA+B;AAC/B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAsB,MAAM,iBAAiB,CAAC;AAE9F,OAAO,EAAE,cAAc,EAA8B,MAAM,+BAA+B,CAAC;AAE3F,OAAO,E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EAA0B,MAAM,2BAA2B,CAAC;AAE/E,6EAA6E;AAC7E,0EAA0E;AAC1E,qDAAqD;AACrD,OAAO,EACL,eAAe,GAGhB,MAAM,gCAAgC,CAAC;AAExC,4EAA4E;AAC5E,8EAA8E;AAC9E,OAAO,EACL,UAAU,EACV,WAAW,EACX,wBAAwB,GAoBzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,aAAa,EACb,eAAe,EACf,WAAW,GAIZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skillsFromDir — load Skills that were AUTHORED AS FILES.
|
|
3
|
+
*
|
|
4
|
+
* The just-in-time half of skills already ships: `defineSkill` produces an
|
|
5
|
+
* Injection whose `description` is all the model sees until it calls
|
|
6
|
+
* `read_skill(<id>)`, at which point the body enters the context. What did not
|
|
7
|
+
* ship was the other half — a way to keep those bodies where prose belongs, in
|
|
8
|
+
* files, next to the code they describe, reviewable in a diff.
|
|
9
|
+
*
|
|
10
|
+
* This is that loader, and nothing more. It reads a directory of `SKILL.md`
|
|
11
|
+
* files and hands each one to `defineSkill`. The progressive disclosure, the
|
|
12
|
+
* activation tool, the slot routing — all unchanged, all upstream of here.
|
|
13
|
+
*
|
|
14
|
+
* skills/
|
|
15
|
+
* billing/SKILL.md
|
|
16
|
+
* refunds/SKILL.md
|
|
17
|
+
*
|
|
18
|
+
* ---
|
|
19
|
+
* name: billing
|
|
20
|
+
* description: Use for refunds, charges and billing questions.
|
|
21
|
+
* ---
|
|
22
|
+
* When handling billing: confirm identity first, then …
|
|
23
|
+
*
|
|
24
|
+
* const skills = await skillsFromDir('./skills');
|
|
25
|
+
* const agent = Agent.create({ provider, model }).skills({ list: () => skills }).build();
|
|
26
|
+
*
|
|
27
|
+
* The frontmatter is the disclosure stub (`name` + `description` — what the
|
|
28
|
+
* model reads when deciding), and everything after the closing fence is the
|
|
29
|
+
* body (what it reads after deciding). That is the same file convention Claude
|
|
30
|
+
* Code made familiar, so a skill folder is portable between the two.
|
|
31
|
+
*
|
|
32
|
+
* ── Why authorship is decided here, at load time ─────────────────────────────
|
|
33
|
+
* A Skill body is *instructions to a model*. Where it came from is therefore a
|
|
34
|
+
* security property, not a convenience: content fetched at run time from
|
|
35
|
+
* somewhere else is content someone else can change after you reviewed it.
|
|
36
|
+
* This loader accepts a local directory and nothing else — a URL is refused BY
|
|
37
|
+
* NAME rather than fetched — because "these files are mine" is a claim you can
|
|
38
|
+
* only make about a path on your own disk at build time. Each file is read
|
|
39
|
+
* ONCE, here; a later edit does not reach a run already in flight.
|
|
40
|
+
*
|
|
41
|
+
* Node-only. `node:fs/promises` and `node:path` are imported lazily inside the
|
|
42
|
+
* call, the same gating `lib/tool-lint/cli.ts` uses: this module is reachable
|
|
43
|
+
* from the `agentfootprint/injection-engine` barrel, and a TOP-LEVEL node:fs
|
|
44
|
+
* import detonates a browser bundle at module-eval even when nothing calls it.
|
|
45
|
+
*/
|
|
46
|
+
import type { Injection } from './types.js';
|
|
47
|
+
import { type SurfaceMode } from './factories/defineSkill.js';
|
|
48
|
+
export interface SkillsFromDirOptions {
|
|
49
|
+
/**
|
|
50
|
+
* Override the activation tool name for every loaded skill. Defaults to
|
|
51
|
+
* `defineSkill`'s own default, `'read_skill'`.
|
|
52
|
+
*/
|
|
53
|
+
readonly viaToolName?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Where a loaded skill's body lands once activated. Defaults to
|
|
56
|
+
* `defineSkill`'s own default, `'auto'`. See {@link SurfaceMode}.
|
|
57
|
+
*/
|
|
58
|
+
readonly surfaceMode?: SurfaceMode;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Load every `SKILL.md` under `dir` as a Skill Injection.
|
|
62
|
+
*
|
|
63
|
+
* Two layouts are accepted, and they can be mixed:
|
|
64
|
+
* - `dir/<anything>/SKILL.md` — one folder per skill (the portable layout,
|
|
65
|
+
* and the one to prefer: the folder can hold the skill's other assets).
|
|
66
|
+
* - `dir/SKILL.md` — the directory IS one skill.
|
|
67
|
+
*
|
|
68
|
+
* The returned array is sorted by skill name, so a chart built from it is
|
|
69
|
+
* stable regardless of the order the filesystem happened to hand back.
|
|
70
|
+
*
|
|
71
|
+
* @param dir - A local filesystem path. A URL (or any `scheme://` string, or a
|
|
72
|
+
* UNC network path) is refused by name — see the module header for why.
|
|
73
|
+
* @param opts - Applied uniformly to every loaded skill.
|
|
74
|
+
*
|
|
75
|
+
* @throws when `dir` is not a local path, does not exist, is not a directory,
|
|
76
|
+
* or contains no `SKILL.md` at all; when a file's frontmatter is malformed
|
|
77
|
+
* (the message names the file); or when two files claim the same skill name
|
|
78
|
+
* (the message names both).
|
|
79
|
+
*/
|
|
80
|
+
export declare function skillsFromDir(dir: string, opts?: SkillsFromDirOptions): Promise<readonly Injection[]>;
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skillsFromDir — load Skills that were AUTHORED AS FILES.
|
|
3
|
+
*
|
|
4
|
+
* The just-in-time half of skills already ships: `defineSkill` produces an
|
|
5
|
+
* Injection whose `description` is all the model sees until it calls
|
|
6
|
+
* `read_skill(<id>)`, at which point the body enters the context. What did not
|
|
7
|
+
* ship was the other half — a way to keep those bodies where prose belongs, in
|
|
8
|
+
* files, next to the code they describe, reviewable in a diff.
|
|
9
|
+
*
|
|
10
|
+
* This is that loader, and nothing more. It reads a directory of `SKILL.md`
|
|
11
|
+
* files and hands each one to `defineSkill`. The progressive disclosure, the
|
|
12
|
+
* activation tool, the slot routing — all unchanged, all upstream of here.
|
|
13
|
+
*
|
|
14
|
+
* skills/
|
|
15
|
+
* billing/SKILL.md
|
|
16
|
+
* refunds/SKILL.md
|
|
17
|
+
*
|
|
18
|
+
* ---
|
|
19
|
+
* name: billing
|
|
20
|
+
* description: Use for refunds, charges and billing questions.
|
|
21
|
+
* ---
|
|
22
|
+
* When handling billing: confirm identity first, then …
|
|
23
|
+
*
|
|
24
|
+
* const skills = await skillsFromDir('./skills');
|
|
25
|
+
* const agent = Agent.create({ provider, model }).skills({ list: () => skills }).build();
|
|
26
|
+
*
|
|
27
|
+
* The frontmatter is the disclosure stub (`name` + `description` — what the
|
|
28
|
+
* model reads when deciding), and everything after the closing fence is the
|
|
29
|
+
* body (what it reads after deciding). That is the same file convention Claude
|
|
30
|
+
* Code made familiar, so a skill folder is portable between the two.
|
|
31
|
+
*
|
|
32
|
+
* ── Why authorship is decided here, at load time ─────────────────────────────
|
|
33
|
+
* A Skill body is *instructions to a model*. Where it came from is therefore a
|
|
34
|
+
* security property, not a convenience: content fetched at run time from
|
|
35
|
+
* somewhere else is content someone else can change after you reviewed it.
|
|
36
|
+
* This loader accepts a local directory and nothing else — a URL is refused BY
|
|
37
|
+
* NAME rather than fetched — because "these files are mine" is a claim you can
|
|
38
|
+
* only make about a path on your own disk at build time. Each file is read
|
|
39
|
+
* ONCE, here; a later edit does not reach a run already in flight.
|
|
40
|
+
*
|
|
41
|
+
* Node-only. `node:fs/promises` and `node:path` are imported lazily inside the
|
|
42
|
+
* call, the same gating `lib/tool-lint/cli.ts` uses: this module is reachable
|
|
43
|
+
* from the `agentfootprint/injection-engine` barrel, and a TOP-LEVEL node:fs
|
|
44
|
+
* import detonates a browser bundle at module-eval even when nothing calls it.
|
|
45
|
+
*/
|
|
46
|
+
import { defineSkill } from './factories/defineSkill.js';
|
|
47
|
+
/** The file name every skill folder is expected to use. */
|
|
48
|
+
const SKILL_FILE = 'SKILL.md';
|
|
49
|
+
/**
|
|
50
|
+
* Skill ids ride into `read_skill`'s `enum` and into the skill-graph's node
|
|
51
|
+
* ids. The house tool-name charset keeps them quotable in a prompt, comparable
|
|
52
|
+
* as plain strings, and safe as an object key.
|
|
53
|
+
*/
|
|
54
|
+
const SKILL_NAME_RE = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
55
|
+
/** Anything of the form `scheme://…` — http, https, s3, git+ssh, file, … */
|
|
56
|
+
const URL_LIKE_RE = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//;
|
|
57
|
+
/**
|
|
58
|
+
* Load every `SKILL.md` under `dir` as a Skill Injection.
|
|
59
|
+
*
|
|
60
|
+
* Two layouts are accepted, and they can be mixed:
|
|
61
|
+
* - `dir/<anything>/SKILL.md` — one folder per skill (the portable layout,
|
|
62
|
+
* and the one to prefer: the folder can hold the skill's other assets).
|
|
63
|
+
* - `dir/SKILL.md` — the directory IS one skill.
|
|
64
|
+
*
|
|
65
|
+
* The returned array is sorted by skill name, so a chart built from it is
|
|
66
|
+
* stable regardless of the order the filesystem happened to hand back.
|
|
67
|
+
*
|
|
68
|
+
* @param dir - A local filesystem path. A URL (or any `scheme://` string, or a
|
|
69
|
+
* UNC network path) is refused by name — see the module header for why.
|
|
70
|
+
* @param opts - Applied uniformly to every loaded skill.
|
|
71
|
+
*
|
|
72
|
+
* @throws when `dir` is not a local path, does not exist, is not a directory,
|
|
73
|
+
* or contains no `SKILL.md` at all; when a file's frontmatter is malformed
|
|
74
|
+
* (the message names the file); or when two files claim the same skill name
|
|
75
|
+
* (the message names both).
|
|
76
|
+
*/
|
|
77
|
+
export async function skillsFromDir(dir, opts = {}) {
|
|
78
|
+
assertLocalDirectoryArgument(dir);
|
|
79
|
+
// Lazy node imports (browser-compat) — see module header.
|
|
80
|
+
const { readdir, readFile, stat } = await import('node:fs/promises');
|
|
81
|
+
const { join } = await import('node:path');
|
|
82
|
+
let isDirectory = false;
|
|
83
|
+
try {
|
|
84
|
+
isDirectory = (await stat(dir)).isDirectory();
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
throw new Error(`skillsFromDir: '${dir}' does not exist. Pass the directory that holds your ` +
|
|
88
|
+
`${SKILL_FILE} folders.`);
|
|
89
|
+
}
|
|
90
|
+
if (!isDirectory) {
|
|
91
|
+
throw new Error(`skillsFromDir: '${dir}' is a file, not a directory. Pass the directory that holds ` +
|
|
92
|
+
`your ${SKILL_FILE} folders.`);
|
|
93
|
+
}
|
|
94
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
95
|
+
const files = [];
|
|
96
|
+
// `dir/SKILL.md` — the whole directory is one skill.
|
|
97
|
+
if (entries.some((e) => e.isFile() && e.name === SKILL_FILE)) {
|
|
98
|
+
files.push(join(dir, SKILL_FILE));
|
|
99
|
+
}
|
|
100
|
+
// `dir/<folder>/SKILL.md` — the portable layout.
|
|
101
|
+
for (const entry of entries) {
|
|
102
|
+
if (!entry.isDirectory())
|
|
103
|
+
continue;
|
|
104
|
+
const candidate = join(dir, entry.name, SKILL_FILE);
|
|
105
|
+
try {
|
|
106
|
+
if ((await stat(candidate)).isFile())
|
|
107
|
+
files.push(candidate);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// A subdirectory without a SKILL.md is not an error — a skill folder can
|
|
111
|
+
// sit next to assets, fixtures, or anything else the author keeps here.
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (files.length === 0) {
|
|
115
|
+
throw new Error(`skillsFromDir: no ${SKILL_FILE} found under '${dir}'. Expected '${dir}/<skill>/${SKILL_FILE}' ` +
|
|
116
|
+
`or '${dir}/${SKILL_FILE}'.`);
|
|
117
|
+
}
|
|
118
|
+
const parsed = [];
|
|
119
|
+
for (const file of files.sort()) {
|
|
120
|
+
parsed.push(parseSkillFile(await readFile(file, 'utf8'), file));
|
|
121
|
+
}
|
|
122
|
+
// Collisions are refused naming BOTH files: with only the id in the message
|
|
123
|
+
// you would know a duplicate exists and still have to go find the pair.
|
|
124
|
+
const byName = new Map();
|
|
125
|
+
for (const skill of parsed) {
|
|
126
|
+
const clash = byName.get(skill.name);
|
|
127
|
+
if (clash) {
|
|
128
|
+
throw new Error(`skillsFromDir: two files claim the skill name '${skill.name}' — '${clash.file}' and ` +
|
|
129
|
+
`'${skill.file}'. Skill ids must be unique (read_skill dispatches by id); rename one.`);
|
|
130
|
+
}
|
|
131
|
+
byName.set(skill.name, skill);
|
|
132
|
+
}
|
|
133
|
+
return parsed
|
|
134
|
+
.slice()
|
|
135
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
136
|
+
.map((skill) => defineSkill({
|
|
137
|
+
id: skill.name,
|
|
138
|
+
description: skill.description,
|
|
139
|
+
body: skill.body,
|
|
140
|
+
...(opts.viaToolName !== undefined && { viaToolName: opts.viaToolName }),
|
|
141
|
+
...(opts.surfaceMode !== undefined && { surfaceMode: opts.surfaceMode }),
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
// ─── Authorship guard ──────────────────────────────────────────────
|
|
145
|
+
/**
|
|
146
|
+
* Refuse anything that is not a local path, BY NAME. The message quotes what
|
|
147
|
+
* was passed, because the whole point is that the reader can see the thing
|
|
148
|
+
* that was rejected.
|
|
149
|
+
*/
|
|
150
|
+
function assertLocalDirectoryArgument(dir) {
|
|
151
|
+
if (typeof dir !== 'string' || dir.trim().length === 0) {
|
|
152
|
+
throw new Error(`skillsFromDir: expected a local directory path, got ${JSON.stringify(dir)}.`);
|
|
153
|
+
}
|
|
154
|
+
const scheme = URL_LIKE_RE.exec(dir);
|
|
155
|
+
if (scheme) {
|
|
156
|
+
throw new Error(`skillsFromDir: '${dir}' is a ${scheme[0].slice(0, -3)} URL, not a local directory. ` +
|
|
157
|
+
`Skill bodies are instructions to a model, so this loader only reads files you own ` +
|
|
158
|
+
`at build time — fetch remote content yourself, review it, and pass defineSkill(...) ` +
|
|
159
|
+
`the result.`);
|
|
160
|
+
}
|
|
161
|
+
if (dir.startsWith('\\\\')) {
|
|
162
|
+
throw new Error(`skillsFromDir: '${dir}' is a network (UNC) path, not a local directory. ` +
|
|
163
|
+
`Skill bodies are instructions to a model, so this loader only reads files you own ` +
|
|
164
|
+
`at build time.`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// ─── Frontmatter ───────────────────────────────────────────────────
|
|
168
|
+
/**
|
|
169
|
+
* Parse one `SKILL.md`. Every refusal names the file — a loader that says
|
|
170
|
+
* "malformed frontmatter" over a directory of forty files has told you nothing.
|
|
171
|
+
*
|
|
172
|
+
* The grammar is deliberately small: an opening `---` line, `key: value` lines
|
|
173
|
+
* (`#` comments and blank lines skipped, single/double quotes stripped), a
|
|
174
|
+
* closing `---` line, then the body. Keys other than `name` and `description`
|
|
175
|
+
* are IGNORED rather than rejected, so a file carrying extra frontmatter for
|
|
176
|
+
* another tool still loads here.
|
|
177
|
+
*/
|
|
178
|
+
function parseSkillFile(raw, file) {
|
|
179
|
+
// Strip a UTF-8 BOM — an editor artifact, not the author's intent.
|
|
180
|
+
const text = raw.charCodeAt(0) === 0xfeff ? raw.slice(1) : raw;
|
|
181
|
+
const lines = text.split(/\r?\n/);
|
|
182
|
+
if (lines[0]?.trim() !== '---') {
|
|
183
|
+
throw new Error(`skillsFromDir: '${file}' does not start with a '---' frontmatter block. ` +
|
|
184
|
+
`Expected:\n---\nname: my-skill\ndescription: When to use it.\n---\n<the body>`);
|
|
185
|
+
}
|
|
186
|
+
const closingIndex = lines.findIndex((line, i) => i > 0 && line.trim() === '---');
|
|
187
|
+
if (closingIndex === -1) {
|
|
188
|
+
throw new Error(`skillsFromDir: '${file}' opens a '---' frontmatter block that is never closed. ` +
|
|
189
|
+
`Add a '---' line after the last frontmatter key.`);
|
|
190
|
+
}
|
|
191
|
+
const fields = new Map();
|
|
192
|
+
for (let i = 1; i < closingIndex; i++) {
|
|
193
|
+
const line = lines[i] ?? '';
|
|
194
|
+
if (line.trim().length === 0 || line.trimStart().startsWith('#'))
|
|
195
|
+
continue;
|
|
196
|
+
const separator = line.indexOf(':');
|
|
197
|
+
if (separator === -1) {
|
|
198
|
+
throw new Error(`skillsFromDir: '${file}' frontmatter line ${i + 1} is not 'key: value' — got ` +
|
|
199
|
+
`${JSON.stringify(line)}.`);
|
|
200
|
+
}
|
|
201
|
+
const key = line.slice(0, separator).trim();
|
|
202
|
+
if (key.length === 0) {
|
|
203
|
+
throw new Error(`skillsFromDir: '${file}' frontmatter line ${i + 1} has an empty key — got ` +
|
|
204
|
+
`${JSON.stringify(line)}.`);
|
|
205
|
+
}
|
|
206
|
+
fields.set(key, unquote(line.slice(separator + 1).trim()));
|
|
207
|
+
}
|
|
208
|
+
const name = fields.get('name') ?? '';
|
|
209
|
+
const description = fields.get('description') ?? '';
|
|
210
|
+
const body = lines
|
|
211
|
+
.slice(closingIndex + 1)
|
|
212
|
+
.join('\n')
|
|
213
|
+
.trim();
|
|
214
|
+
if (name.length === 0) {
|
|
215
|
+
throw new Error(`skillsFromDir: '${file}' frontmatter is missing 'name'. It becomes the skill id the ` +
|
|
216
|
+
`model passes to read_skill.`);
|
|
217
|
+
}
|
|
218
|
+
if (!SKILL_NAME_RE.test(name)) {
|
|
219
|
+
throw new Error(`skillsFromDir: '${file}' frontmatter name '${name}' must match ` +
|
|
220
|
+
`/^[a-zA-Z0-9_-]{1,64}$/ — it is the id the model passes to read_skill.`);
|
|
221
|
+
}
|
|
222
|
+
if (description.length === 0) {
|
|
223
|
+
throw new Error(`skillsFromDir: '${file}' frontmatter is missing 'description'. It is the ONLY thing ` +
|
|
224
|
+
`the model reads when deciding whether to open this skill.`);
|
|
225
|
+
}
|
|
226
|
+
if (body.length === 0) {
|
|
227
|
+
throw new Error(`skillsFromDir: '${file}' has no body after the closing '---'. The body is what the ` +
|
|
228
|
+
`model reads once it activates the skill.`);
|
|
229
|
+
}
|
|
230
|
+
return { name, description, body, file };
|
|
231
|
+
}
|
|
232
|
+
/** Strip one layer of matching single or double quotes from a YAML-ish scalar. */
|
|
233
|
+
function unquote(value) {
|
|
234
|
+
if (value.length >= 2) {
|
|
235
|
+
const first = value[0];
|
|
236
|
+
const last = value[value.length - 1];
|
|
237
|
+
if ((first === '"' && last === '"') || (first === "'" && last === "'")) {
|
|
238
|
+
return value.slice(1, -1);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return value;
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=skillsFromDir.js.map
|