experimental-ash 0.6.2 → 0.7.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/README.md +3 -4
- package/dist/docs/internals/discovery.md +2 -2
- package/dist/docs/internals/mechanical-invariants.md +1 -1
- package/dist/docs/internals/testing.md +1 -1
- package/dist/docs/public/README.md +1 -1
- package/dist/docs/public/agent-ts.md +2 -2
- package/dist/docs/public/channels/README.md +1 -1
- package/dist/docs/public/context-control.md +20 -20
- package/dist/docs/public/getting-started.md +1 -1
- package/dist/docs/public/project-layout.md +21 -21
- package/dist/docs/public/schedules.md +1 -1
- package/dist/docs/public/skills.md +3 -3
- package/dist/docs/public/subagents.md +3 -3
- package/dist/docs/public/typescript-api.md +2 -2
- package/dist/src/chunks/{dev-authored-source-watcher-MDHwWfTE.js → dev-authored-source-watcher-HzOplr1S.js} +1 -1
- package/dist/src/chunks/{host-CDvE1sV_.js → host-Ca8xvEQ1.js} +2 -2
- package/dist/src/chunks/paths-BiY7uVwD.js +88 -0
- package/dist/src/chunks/{prewarm-CCU5VjXa.js → prewarm-DiZ_sYLy.js} +1 -1
- package/dist/src/cli/commands/info.js +1 -1
- package/dist/src/cli/run.js +1 -1
- package/dist/src/compiler/compile-agent.js +10 -0
- package/dist/src/compiler/manifest.d.ts +8 -7
- package/dist/src/compiler/manifest.js +5 -5
- package/dist/src/compiler/normalize-instructions.d.ts +12 -0
- package/dist/src/compiler/normalize-instructions.js +28 -0
- package/dist/src/compiler/normalize-manifest.js +3 -3
- package/dist/src/discover/discover-agent.d.ts +2 -2
- package/dist/src/discover/discover-agent.js +5 -5
- package/dist/src/discover/discover-subagent.js +4 -4
- package/dist/src/discover/filesystem.d.ts +4 -4
- package/dist/src/discover/filesystem.js +30 -0
- package/dist/src/discover/grammar.d.ts +21 -7
- package/dist/src/discover/grammar.js +79 -21
- package/dist/src/discover/manifest.d.ts +11 -8
- package/dist/src/discover/manifest.js +2 -2
- package/dist/src/evals/cli/eval.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/authored-definition/core.d.ts +7 -6
- package/dist/src/internal/authored-definition/core.js +6 -5
- package/dist/src/internal/nitro/routes/home-page/build-home-page-response.d.ts +5 -5
- package/dist/src/internal/nitro/routes/home-page/build-home-page-response.js +16 -15
- package/dist/src/internal/nitro/routes/home-page/load-home-page-data.d.ts +2 -2
- package/dist/src/internal/nitro/routes/web-ui/assets/{index-z8flAc4k.js → index-BQa8fbHJ.js} +1 -1
- package/dist/src/internal/nitro/routes/web-ui/index.html +1 -1
- package/dist/src/public/definitions/instructions.d.ts +29 -0
- package/dist/src/public/definitions/instructions.js +12 -0
- package/dist/src/public/helpers/markdown.d.ts +5 -5
- package/dist/src/public/helpers/markdown.js +7 -7
- package/dist/src/public/instructions/index.d.ts +8 -0
- package/dist/src/public/instructions/index.js +6 -0
- package/dist/src/runtime/agent/bootstrap.js +3 -3
- package/dist/src/runtime/prompt/compose.d.ts +5 -4
- package/dist/src/runtime/prompt/compose.js +6 -6
- package/dist/src/runtime/resolve-agent.js +10 -10
- package/dist/src/runtime/types.d.ts +10 -7
- package/package.json +9 -4
- package/dist/src/chunks/paths-D1gMcyWw.js +0 -88
- package/dist/src/compiler/normalize-system.d.ts +0 -11
- package/dist/src/compiler/normalize-system.js +0 -27
- package/dist/src/public/definitions/system.d.ts +0 -16
- package/dist/src/public/definitions/system.js +0 -7
- package/dist/src/public/system/index.d.ts +0 -4
- package/dist/src/public/system/index.js +0 -4
- /package/dist/src/cli/templates/init-app/agent/{system.md → instructions.md} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{D as e,b as t,t as n,v as r,y as i}from"../../chunks/paths-
|
|
1
|
+
import{D as e,b as t,t as n,v as r,y as i}from"../../chunks/paths-BiY7uVwD.js";import{d as a,f as o,g as s}from"../../chunks/types-D9Uv7nU4.js";import{createCliTheme as c,renderCliBanner as l,renderCliSection as u}from"../ui/output.js";async function d(e){let t=await f(e);return{application:n(t?.project.appRoot??e),compiledState:t,messaging:{createSessionRoutePath:o,continueSessionRoutePattern:a,streamRoutePattern:s}}}async function f(n){try{return await i({startPath:n})}catch(n){if(n instanceof r)return n.result;if(n instanceof e||n instanceof t)return null;throw n}}function p(e,t){return`${e} ${t}${e===1?``:`s`}`}function m(e,t){return`${`${e} error${e===1?``:`s`}`}, ${`${t} warning${t===1?``:`s`}`}`}function h(e){switch(e){case`ready`:return`success`;case`failed`:return`danger`;default:return`warning`}}async function g(e,t){let n=await d(t),r=n.compiledState,i=n.application,a=c(),o=[{label:`App Root`,value:i.appRoot}],s=[{label:`Workflow Build`,value:i.workflowBuildDir},{label:`Output`,value:i.outputDir}],f=[];r===null?o.push({label:`Compile`,tone:`warning`,value:`unavailable`}):(o.push({label:`Agent Root`,value:r.project.agentRoot},{label:`Layout`,value:r.project.layout},{label:`Compile`,tone:h(r.metadata.status),value:r.metadata.status},{label:`Diagnostics`,tone:r.metadata.discovery.summary.errors>0?`danger`:r.metadata.discovery.summary.warnings>0?`warning`:`success`,value:m(r.metadata.discovery.summary.errors,r.metadata.discovery.summary.warnings)},{label:`Instructions`,value:r.manifest.instructions?.logicalPath??`none`},{label:`Skills`,value:p(r.manifest.skills.length,`skill`)}),s.unshift({label:`Compiled Manifest`,value:r.paths.compiledManifestPath},{label:`Discovery Manifest`,value:r.paths.discoveryManifestPath},{label:`Diagnostics`,value:r.paths.diagnosticsPath},{label:`Module Map`,value:r.paths.moduleMapPath},{label:`Metadata`,value:r.paths.compileMetadataPath}),f.push(r.manifest.instructions===void 0?{label:`Instructions`,value:`No instructions prompt discovered.`}:{label:`Instructions`,value:r.manifest.instructions.logicalPath})),e.log([l(a,{subtitle:`Resolved application paths and the active message contract.`,title:`Ash Info`}),``,u(a,{rows:o,title:`Application`}),``,u(a,{rows:s,title:`Artifacts`}),...r===null?[]:[``,u(a,{rows:f,title:`Instructions`})],``,u(a,{rows:[{label:`Workflow ID`,value:i.workflowId},{label:`Source Dir`,value:i.workflowSourceDir},{label:`Create`,tone:`info`,value:`POST ${n.messaging.createSessionRoutePath}`},{label:`Continue`,tone:`info`,value:`POST ${n.messaging.continueSessionRoutePattern}`},{label:`Stream`,tone:`info`,value:`GET ${n.messaging.streamRoutePattern}`}],title:`Messaging`})].join(`
|
|
2
2
|
`))}export{g as printApplicationInfo};
|
package/dist/src/cli/run.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{t as e}from"../chunks/package-DmsQgn4v.js";import{createCliTheme as t,renderCliTaggedLine as n}from"./ui/output.js";import{i as r,n as i,r as a,t as o}from"../chunks/url-BVRhVE2O.js";import{resolve as s}from"node:path";async function c(){return(await import(`../chunks/host-
|
|
1
|
+
import{t as e}from"../chunks/package-DmsQgn4v.js";import{createCliTheme as t,renderCliTaggedLine as n}from"./ui/output.js";import{i as r,n as i,r as a,t as o}from"../chunks/url-BVRhVE2O.js";import{resolve as s}from"node:path";async function c(){return(await import(`../chunks/host-Ca8xvEQ1.js`).then(e=>e.t)).buildHost}async function l(){return(await import(`./commands/init.js`)).initializeApplication}async function u(){return(await import(`./commands/info.js`)).printApplicationInfo}async function d(){return(await import(`./dev/repl.js`)).runDevelopmentRepl}async function f(){return(await import(`../evals/cli/eval.js`)).runEvalCommand}async function p(){return(await import(`../chunks/host-Ca8xvEQ1.js`).then(e=>e.t)).startHost}function m(e=process.cwd()){return s(e)}function h(e){return`Ash (v${e})`}function g(e){return e.name()===`info`||e.name()===`dev`}async function _(e){await new Promise((t,n)=>{let r=!1,i=()=>{process.off(`SIGINT`,a),process.off(`SIGTERM`,a)},a=()=>{r||(r=!0,i(),e.close().then(t,n))};process.once(`SIGINT`,a),process.once(`SIGTERM`,a)})}function v(e){if(!/^-?\d+$/.test(e))throw new r(`Expected a numeric port, received "${e}".`);let t=Number(e);if(!Number.isInteger(t))throw new r(`Expected a numeric port, received "${e}".`);if(t<0||t>65535)throw new r(`Expected a port between 0 and 65535, received "${e}".`);return t}function y(){return!!(process.stdin.isTTY&&process.stdout.isTTY)}function b(e){let t=e[1];return e[0]!==`dev`||e.length!==2||t===void 0||t.startsWith(`-`)?[...e]:[`dev`,`--url`,t]}function x(e){if(e.url){if(e.host!==void 0)throw new r(`The --host option cannot be used with --url.`);if(e.port!==void 0)throw new r(`The --port option cannot be used with --url.`);if(e.repl===!1)throw new r(`The --no-repl option cannot be used with --url.`);return e.url}}function S(r,a){let s=m(),b=e().version,S=new i,C=t();return S.name(`ash`).description(`Build and run an Ash application.`).version(b).showHelpAfterError().exitOverride().hook(`preAction`,(e,t)=>{g(t)&&r.log(h(b))}).configureOutput({writeErr:e=>{r.error(e.trimEnd())},writeOut:e=>{r.log(e.trimEnd())}}),S.command(`build`).description(`Build the current Ash application.`).action(async()=>{let e=await(a.buildHost??await c())(s);r.log(n(C,{message:`built output at ${e}`,tag:`build`,tone:`success`}))}),S.command(`init`).description(`Scaffold a new Ash application.`).argument(`<name>`,`Directory name for the new Ash application`).action(async e=>{await(a.initializeApplication??await l())({logger:r,parentDirectoryPath:s,targetName:e})}),S.command(`dev`).description(`Start the Ash development server or connect the REPL to an existing URL.`).option(`--host <host>`,`Host interface to bind`).option(`--no-repl`,`Start the server without the interactive REPL`).option(`--port <port>`,`Port to listen on (defaults to $PORT, then 3000)`,v).option(`--schedules`,`Run scheduled tasks during development (off by default)`).option(`-u, --url <url>`,`Connect the REPL to an existing server URL`,o).addHelpText(`after`,`
|
|
2
2
|
You can also pass a bare URL as the only argument, for example: ash dev https://example.com
|
|
3
3
|
`).action(async e=>{let t=x(e),{loadDevelopmentEnvironmentFiles:i}=await import(`./dev/environment.js`);if(i(s),t){if(r.log(n(C,{message:`REPL connecting to ${t}`,tag:`dev`,tone:`info`})),!y()){r.log(n(C,{message:`Interactive REPL disabled because the current terminal is not a TTY.`,tag:`dev`,tone:`warning`}));return}r.log(``),await(a.runDevelopmentRepl??await d())({serverUrl:t});return}let o=await(a.startHost??await p())(s,{host:e.host,port:e.port,schedules:e.schedules===!0}),c=!1,l=async()=>{c||(c=!0,await o.close())};try{if(r.log(n(C,{message:`server listening at ${o.url}`,tag:`dev`,tone:`success`})),e.repl===!1)return await _({close:l});if(!y())return r.log(n(C,{message:`Interactive REPL disabled because the current terminal is not a TTY.`,tag:`dev`,tone:`warning`})),await _({close:l});r.log(``),await(a.runDevelopmentRepl??await d())({serverUrl:o.url})}finally{await l()}}),S.command(`info`).description(`Print resolved application information.`).action(async()=>{await(a.printApplicationInfo??await u())(r,s)}),S.command(`eval`).description(`Run eval suites against an Ash agent.`).option(`--suite <id...>`,`Suite IDs to run (repeatable)`).option(`--all`,`Run all discovered suites`).option(`--url <url>`,`Remote agent URL (skip local host startup)`).option(`--timeout <ms>`,`Per-case timeout in milliseconds`).option(`--max-concurrency <n>`,`Max concurrent case executions per suite`).option(`--json`,`Output results as JSON`).option(`--list-suites`,`List discovered suites and exit`).option(`--skip-report`,`Skip suite-defined reporters (e.g. Braintrust)`).action(async e=>{await(a.runEvalCommand??await f())(e,r)}),S}async function C(e=process.argv.slice(2),t=console,n={}){let r=S(t,n),i=e.length===0?[`info`]:b(e);try{await r.parseAsync(i,{from:`user`})}catch(e){if(e instanceof a){if(e.exitCode===0)return;throw Error(e.message)}throw e}}export{C as runCli};
|
|
@@ -41,8 +41,18 @@ export async function compileAgent(input = {}) {
|
|
|
41
41
|
if (hasDiscoverErrors(discoveryResult.diagnostics)) {
|
|
42
42
|
throw new CompileAgentError(result);
|
|
43
43
|
}
|
|
44
|
+
reportDiscoverWarnings(discoveryResult.diagnostics);
|
|
44
45
|
return result;
|
|
45
46
|
}
|
|
47
|
+
function reportDiscoverWarnings(diagnostics) {
|
|
48
|
+
const warnings = diagnostics.filter((diagnostic) => diagnostic.severity === "warning");
|
|
49
|
+
if (warnings.length === 0) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
for (const warning of warnings) {
|
|
53
|
+
console.warn(`Warning [${warning.code}]: ${warning.message}\n source: ${warning.sourcePath}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
46
56
|
function formatCompileAgentErrorMessage(input) {
|
|
47
57
|
const summary = summarizeDiscoverDiagnostics(input.diagnostics);
|
|
48
58
|
const lines = [
|
|
@@ -62,9 +62,10 @@ export type CompiledAgentCompactionDefinition = InternalAgentCompactionDefinitio
|
|
|
62
62
|
*/
|
|
63
63
|
export type CompiledAgentDefinition = InternalAgentDefinition;
|
|
64
64
|
/**
|
|
65
|
-
* Normalized authored
|
|
65
|
+
* Normalized authored instructions prompt preserved in the compiled
|
|
66
|
+
* manifest.
|
|
66
67
|
*/
|
|
67
|
-
export type
|
|
68
|
+
export type CompiledInstructions = z.infer<typeof compiledInstructionsSchema>;
|
|
68
69
|
/**
|
|
69
70
|
* Normalized authored skill preserved in the compiled manifest.
|
|
70
71
|
*/
|
|
@@ -144,7 +145,7 @@ export interface CompiledSubagentEdge {
|
|
|
144
145
|
* Versioned compiled manifest emitted by the compiler and loaded by runtime.
|
|
145
146
|
*/
|
|
146
147
|
export type CompiledAgentManifest = z.infer<typeof compiledAgentManifestSchema>;
|
|
147
|
-
declare const
|
|
148
|
+
declare const compiledInstructionsSchema: z.ZodObject<{
|
|
148
149
|
name: z.ZodString;
|
|
149
150
|
logicalPath: z.ZodString;
|
|
150
151
|
markdown: z.ZodString;
|
|
@@ -242,7 +243,7 @@ export declare const compiledAgentNodeManifestSchema: z.ZodObject<{
|
|
|
242
243
|
sourceKind: z.ZodUnion<readonly [z.ZodLiteral<"markdown">, z.ZodLiteral<"module">]>;
|
|
243
244
|
}, z.core.$strict>>;
|
|
244
245
|
skills: z.ZodReadonly<z.ZodArray<z.ZodType<CompiledSkillDefinition, unknown, z.core.$ZodTypeInternals<CompiledSkillDefinition, unknown>>>>;
|
|
245
|
-
|
|
246
|
+
instructions: z.ZodOptional<z.ZodObject<{
|
|
246
247
|
name: z.ZodString;
|
|
247
248
|
logicalPath: z.ZodString;
|
|
248
249
|
markdown: z.ZodString;
|
|
@@ -327,7 +328,7 @@ export declare const compiledAgentManifestSchema: z.ZodObject<{
|
|
|
327
328
|
name: string;
|
|
328
329
|
rootPath: string;
|
|
329
330
|
}>, unknown>>>;
|
|
330
|
-
|
|
331
|
+
instructions: z.ZodOptional<z.ZodObject<{
|
|
331
332
|
name: z.ZodString;
|
|
332
333
|
logicalPath: z.ZodString;
|
|
333
334
|
markdown: z.ZodString;
|
|
@@ -365,7 +366,7 @@ export declare function createCompiledAgentNodeManifest(input: {
|
|
|
365
366
|
readonly sandboxWorkspaces?: readonly CompiledSandboxWorkspace[];
|
|
366
367
|
readonly schedules?: readonly CompiledScheduleDefinition[];
|
|
367
368
|
readonly skills?: readonly CompiledSkillDefinition[];
|
|
368
|
-
readonly
|
|
369
|
+
readonly instructions?: CompiledInstructions;
|
|
369
370
|
readonly tools?: readonly CompiledToolDefinition[];
|
|
370
371
|
readonly workspaceResourceRoot?: CompiledWorkspaceResourceRoot;
|
|
371
372
|
}): CompiledAgentNodeManifest;
|
|
@@ -404,7 +405,7 @@ export declare function createCompiledAgentManifest(input: {
|
|
|
404
405
|
readonly skills?: readonly CompiledSkillDefinition[];
|
|
405
406
|
readonly subagentEdges?: readonly CompiledSubagentEdge[];
|
|
406
407
|
readonly subagents?: readonly CompiledSubagentNode[];
|
|
407
|
-
readonly
|
|
408
|
+
readonly instructions?: CompiledInstructions;
|
|
408
409
|
readonly tools?: readonly CompiledToolDefinition[];
|
|
409
410
|
}): CompiledAgentManifest;
|
|
410
411
|
export {};
|
|
@@ -81,7 +81,7 @@ const compiledAgentConfigSchema = z
|
|
|
81
81
|
source: moduleSourceRefSchema.optional(),
|
|
82
82
|
})
|
|
83
83
|
.strict();
|
|
84
|
-
const
|
|
84
|
+
const compiledInstructionsSchema = z
|
|
85
85
|
.object({
|
|
86
86
|
name: z.string(),
|
|
87
87
|
logicalPath: z.string(),
|
|
@@ -214,7 +214,7 @@ export const compiledAgentNodeManifestSchema = z
|
|
|
214
214
|
sandboxWorkspaces: z.array(compiledSandboxWorkspaceSchema),
|
|
215
215
|
schedules: z.array(compiledScheduleDefinitionSchema),
|
|
216
216
|
skills: z.array(compiledSkillSourceSchema).readonly(),
|
|
217
|
-
|
|
217
|
+
instructions: compiledInstructionsSchema.optional(),
|
|
218
218
|
tools: z.array(compiledToolDefinitionSchema),
|
|
219
219
|
workspaceResourceRoot: compiledWorkspaceResourceRootSchema,
|
|
220
220
|
})
|
|
@@ -259,7 +259,7 @@ export const compiledAgentManifestSchema = z
|
|
|
259
259
|
skills: z.array(compiledSkillSourceSchema).readonly(),
|
|
260
260
|
subagentEdges: z.array(compiledSubagentEdgeSchema),
|
|
261
261
|
subagents: z.array(compiledSubagentNodeSchema),
|
|
262
|
-
|
|
262
|
+
instructions: compiledInstructionsSchema.optional(),
|
|
263
263
|
tools: z.array(compiledToolDefinitionSchema),
|
|
264
264
|
version: z.literal(COMPILED_AGENT_MANIFEST_VERSION),
|
|
265
265
|
workspaceResourceRoot: compiledWorkspaceResourceRootSchema,
|
|
@@ -319,8 +319,8 @@ export function createCompiledAgentNodeManifest(input) {
|
|
|
319
319
|
}),
|
|
320
320
|
},
|
|
321
321
|
};
|
|
322
|
-
if (input.
|
|
323
|
-
node.
|
|
322
|
+
if (input.instructions !== undefined) {
|
|
323
|
+
node.instructions = input.instructions;
|
|
324
324
|
}
|
|
325
325
|
return node;
|
|
326
326
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InstructionsSourceRef } from "#discover/manifest.js";
|
|
2
|
+
import type { CompiledInstructions } from "#compiler/manifest.js";
|
|
3
|
+
/**
|
|
4
|
+
* Compiles one authored instructions prompt source (markdown or
|
|
5
|
+
* module-backed `defineInstructions`) into the normalized shape consumed
|
|
6
|
+
* by the runtime.
|
|
7
|
+
*
|
|
8
|
+
* Module-backed instructions sources execute once at build time — the
|
|
9
|
+
* resulting markdown is captured into the compiled manifest. There is no
|
|
10
|
+
* per-session re-evaluation at runtime.
|
|
11
|
+
*/
|
|
12
|
+
export declare function compileInstructions(agentRoot: string, source: InstructionsSourceRef): Promise<CompiledInstructions>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { stripLogicalPathExtension } from "#discover/filesystem.js";
|
|
2
|
+
import { normalizeInstructionsDefinition } from "#internal/authored-definition/core.js";
|
|
3
|
+
import { loadModuleBackedDefinition } from "#compiler/normalize-helpers.js";
|
|
4
|
+
/**
|
|
5
|
+
* Compiles one authored instructions prompt source (markdown or
|
|
6
|
+
* module-backed `defineInstructions`) into the normalized shape consumed
|
|
7
|
+
* by the runtime.
|
|
8
|
+
*
|
|
9
|
+
* Module-backed instructions sources execute once at build time — the
|
|
10
|
+
* resulting markdown is captured into the compiled manifest. There is no
|
|
11
|
+
* per-session re-evaluation at runtime.
|
|
12
|
+
*/
|
|
13
|
+
export async function compileInstructions(agentRoot, source) {
|
|
14
|
+
const definition = source.sourceKind === "markdown"
|
|
15
|
+
? normalizeInstructionsDefinition(source.definition, `Expected the compiled instructions definition at "${source.logicalPath}" to match the public Ash shape.`)
|
|
16
|
+
: normalizeInstructionsDefinition(await loadModuleBackedDefinition({
|
|
17
|
+
agentRoot,
|
|
18
|
+
kind: "instructions",
|
|
19
|
+
source,
|
|
20
|
+
}), `Expected the instructions export "${source.exportName ?? "default"}" from "${source.logicalPath}" to match the public Ash shape.`);
|
|
21
|
+
return {
|
|
22
|
+
name: stripLogicalPathExtension(source.logicalPath),
|
|
23
|
+
logicalPath: source.logicalPath,
|
|
24
|
+
markdown: definition.markdown,
|
|
25
|
+
sourceId: source.sourceId,
|
|
26
|
+
sourceKind: source.sourceKind,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -5,7 +5,7 @@ import { compileChannelDefinition } from "#compiler/normalize-channel.js";
|
|
|
5
5
|
import { compileConnectionDefinition } from "#compiler/normalize-connection.js";
|
|
6
6
|
import { compileHookEntry } from "#compiler/normalize-hook.js";
|
|
7
7
|
import { compileSandboxDefinition } from "#compiler/normalize-sandbox.js";
|
|
8
|
-
import {
|
|
8
|
+
import { compileInstructions } from "#compiler/normalize-instructions.js";
|
|
9
9
|
import { compileScheduleDefinition } from "#compiler/normalize-schedule.js";
|
|
10
10
|
import { buildChannelRouteIdentityMap } from "#compiler/normalize-channel.js";
|
|
11
11
|
import { compileSkillSource } from "#compiler/normalize-skill.js";
|
|
@@ -77,9 +77,9 @@ async function compileAgentNodeManifest(manifest, context) {
|
|
|
77
77
|
})),
|
|
78
78
|
schedules: await Promise.all(manifest.schedules.map((scheduleSource) => compileScheduleDefinition(manifest.agentRoot, scheduleSource, channelRouteIdentityMap))),
|
|
79
79
|
skills: await Promise.all(manifest.skills.map((skillSource) => compileSkillSource(manifest.agentRoot, skillSource))),
|
|
80
|
-
|
|
80
|
+
instructions: manifest.instructions === undefined
|
|
81
81
|
? undefined
|
|
82
|
-
: await
|
|
82
|
+
: await compileInstructions(manifest.agentRoot, manifest.instructions),
|
|
83
83
|
tools,
|
|
84
84
|
});
|
|
85
85
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DiscoverDiagnostic } from "#discover/diagnostics.js";
|
|
2
|
-
import { DISCOVER_CHANNEL_NAME_INVALID, DISCOVER_HOOK_NAME_INVALID, DISCOVER_MODULE_SLOT_COLLISION,
|
|
2
|
+
import { DISCOVER_CHANNEL_NAME_INVALID, DISCOVER_HOOK_NAME_INVALID, DISCOVER_DEPRECATED_SYSTEM_SLOT, DISCOVER_MODULE_SLOT_COLLISION, DISCOVER_REQUIRED_INSTRUCTIONS_MISSING, DISCOVER_SANDBOX_NAME_INVALID, DISCOVER_SANDBOX_DIRECTORY_INVALID, DISCOVER_SLOT_COLLISION, DISCOVER_TOOL_NAME_INVALID, DISCOVER_TOOLS_DIRECTORY_INVALID, DISCOVER_UNSUPPORTED_DIRECTORY } from "#discover/grammar.js";
|
|
3
3
|
import { type AgentSourceManifest } from "#discover/manifest.js";
|
|
4
4
|
import { type ProjectSource } from "#discover/project-source.js";
|
|
5
5
|
export { DISCOVER_CONNECTION_FILE_FOLDER_COLLISION, DISCOVER_CONNECTION_FOLDER_EMPTY, DISCOVER_CONNECTIONS_DIRECTORY_INVALID, } from "#discover/connections.js";
|
|
@@ -8,7 +8,7 @@ export { DISCOVER_SANDBOX_FOLDER_EMPTY, DISCOVER_SANDBOX_WORKSPACE_SKILLS_RESERV
|
|
|
8
8
|
* Diagnostics emitted while discovering the non-skill core authored agent
|
|
9
9
|
* grammar.
|
|
10
10
|
*/
|
|
11
|
-
export { DISCOVER_CHANNEL_NAME_INVALID, DISCOVER_HOOK_NAME_INVALID, DISCOVER_MODULE_SLOT_COLLISION,
|
|
11
|
+
export { DISCOVER_CHANNEL_NAME_INVALID, DISCOVER_DEPRECATED_SYSTEM_SLOT, DISCOVER_HOOK_NAME_INVALID, DISCOVER_MODULE_SLOT_COLLISION, DISCOVER_REQUIRED_INSTRUCTIONS_MISSING, DISCOVER_SANDBOX_NAME_INVALID, DISCOVER_SANDBOX_DIRECTORY_INVALID, DISCOVER_SLOT_COLLISION, DISCOVER_TOOL_NAME_INVALID, DISCOVER_TOOLS_DIRECTORY_INVALID, DISCOVER_UNSUPPORTED_DIRECTORY, };
|
|
12
12
|
export declare const DISCOVER_CHANNELS_DIRECTORY_INVALID = "discover/channels-directory-invalid";
|
|
13
13
|
export declare const DISCOVER_HOOKS_DIRECTORY_INVALID = "discover/hooks-directory-invalid";
|
|
14
14
|
export { DISCOVER_SCHEDULE_FILE_UNSUPPORTED, DISCOVER_SCHEDULES_DIRECTORY_INVALID, } from "#discover/schedules.js";
|
|
@@ -2,7 +2,7 @@ import { join, resolve } from "node:path";
|
|
|
2
2
|
import { discoverConnectionSources } from "#discover/connections.js";
|
|
3
3
|
import { discoverSubagents } from "#discover/discover-subagent.js";
|
|
4
4
|
import { classifyAgentRootEntry } from "#discover/filesystem.js";
|
|
5
|
-
import { createChannelNameDiagnostic, createHookNameDiagnostic, createToolNameDiagnostic, createUnsupportedRootDirectoryDiagnostics, DISCOVER_CHANNEL_NAME_INVALID, DISCOVER_HOOK_NAME_INVALID, DISCOVER_MODULE_SLOT_COLLISION,
|
|
5
|
+
import { createChannelNameDiagnostic, createHookNameDiagnostic, createToolNameDiagnostic, createUnsupportedRootDirectoryDiagnostics, DISCOVER_CHANNEL_NAME_INVALID, DISCOVER_HOOK_NAME_INVALID, DISCOVER_DEPRECATED_SYSTEM_SLOT, DISCOVER_MODULE_SLOT_COLLISION, DISCOVER_REQUIRED_INSTRUCTIONS_MISSING, DISCOVER_SANDBOX_NAME_INVALID, DISCOVER_SANDBOX_DIRECTORY_INVALID, DISCOVER_SLOT_COLLISION, DISCOVER_TOOL_NAME_INVALID, DISCOVER_TOOLS_DIRECTORY_INVALID, DISCOVER_UNSUPPORTED_DIRECTORY, discoverFlatModuleSource, discoverInstructionsSource, discoverNamedSourceDirectory, readSortedDirectoryEntries, } from "#discover/grammar.js";
|
|
6
6
|
import { discoverLibSources } from "#discover/lib.js";
|
|
7
7
|
import { createAgentSourceManifest, } from "#discover/manifest.js";
|
|
8
8
|
import { createDiskProjectSource } from "#discover/project-source.js";
|
|
@@ -15,7 +15,7 @@ export { DISCOVER_SANDBOX_FOLDER_EMPTY, DISCOVER_SANDBOX_WORKSPACE_SKILLS_RESERV
|
|
|
15
15
|
* Diagnostics emitted while discovering the non-skill core authored agent
|
|
16
16
|
* grammar.
|
|
17
17
|
*/
|
|
18
|
-
export { DISCOVER_CHANNEL_NAME_INVALID, DISCOVER_HOOK_NAME_INVALID, DISCOVER_MODULE_SLOT_COLLISION,
|
|
18
|
+
export { DISCOVER_CHANNEL_NAME_INVALID, DISCOVER_DEPRECATED_SYSTEM_SLOT, DISCOVER_HOOK_NAME_INVALID, DISCOVER_MODULE_SLOT_COLLISION, DISCOVER_REQUIRED_INSTRUCTIONS_MISSING, DISCOVER_SANDBOX_NAME_INVALID, DISCOVER_SANDBOX_DIRECTORY_INVALID, DISCOVER_SLOT_COLLISION, DISCOVER_TOOL_NAME_INVALID, DISCOVER_TOOLS_DIRECTORY_INVALID, DISCOVER_UNSUPPORTED_DIRECTORY, };
|
|
19
19
|
export const DISCOVER_CHANNELS_DIRECTORY_INVALID = "discover/channels-directory-invalid";
|
|
20
20
|
export const DISCOVER_HOOKS_DIRECTORY_INVALID = "discover/hooks-directory-invalid";
|
|
21
21
|
export { DISCOVER_SCHEDULE_FILE_UNSUPPORTED, DISCOVER_SCHEDULES_DIRECTORY_INVALID, } from "#discover/schedules.js";
|
|
@@ -38,12 +38,12 @@ export async function discoverAgent(input) {
|
|
|
38
38
|
rootEntries,
|
|
39
39
|
rootPath: agentRoot,
|
|
40
40
|
}));
|
|
41
|
-
const
|
|
41
|
+
const instructionsResult = await discoverInstructionsSource({
|
|
42
42
|
rootEntries,
|
|
43
43
|
rootPath: agentRoot,
|
|
44
44
|
source,
|
|
45
45
|
});
|
|
46
|
-
diagnostics.push(...
|
|
46
|
+
diagnostics.push(...instructionsResult.diagnostics);
|
|
47
47
|
const configModuleResult = discoverFlatModuleSource({
|
|
48
48
|
rootEntries,
|
|
49
49
|
rootPath: agentRoot,
|
|
@@ -127,7 +127,7 @@ export async function discoverAgent(input) {
|
|
|
127
127
|
diagnostics,
|
|
128
128
|
hooks: hooksResult.sources,
|
|
129
129
|
lib: libResult.lib,
|
|
130
|
-
|
|
130
|
+
instructions: instructionsResult.instructions,
|
|
131
131
|
sandbox: sandboxResult.sandbox,
|
|
132
132
|
sandboxWorkspaces: sandboxResult.sandboxWorkspace === null ? [] : [sandboxResult.sandboxWorkspace],
|
|
133
133
|
schedules: schedulesResult.schedules,
|
|
@@ -2,7 +2,7 @@ import { join, relative, resolve } from "node:path";
|
|
|
2
2
|
import { discoverConnectionSources } from "#discover/connections.js";
|
|
3
3
|
import { createDiscoverErrorDiagnostic } from "#discover/diagnostics.js";
|
|
4
4
|
import { classifyLocalSubagentEntry, getDirectoryEntryType, normalizeLogicalPath, } from "#discover/filesystem.js";
|
|
5
|
-
import { createHookNameDiagnostic, createToolNameDiagnostic, createUnsupportedRootDirectoryDiagnostics, DISCOVER_TOOLS_DIRECTORY_INVALID, discoverFlatModuleSource,
|
|
5
|
+
import { createHookNameDiagnostic, createToolNameDiagnostic, createUnsupportedRootDirectoryDiagnostics, DISCOVER_TOOLS_DIRECTORY_INVALID, discoverFlatModuleSource, discoverInstructionsSource, discoverNamedSourceDirectory, readSortedDirectoryEntries, } from "#discover/grammar.js";
|
|
6
6
|
import { DISCOVER_HOOKS_DIRECTORY_INVALID } from "#discover/discover-agent.js";
|
|
7
7
|
import { discoverLibSources } from "#discover/lib.js";
|
|
8
8
|
import { createAgentSourceManifest, createLocalSubagentSourceRef, } from "#discover/manifest.js";
|
|
@@ -76,12 +76,12 @@ async function discoverLocalSubagentPackage(input) {
|
|
|
76
76
|
rootEntries,
|
|
77
77
|
rootPath: input.subagentRoot,
|
|
78
78
|
}));
|
|
79
|
-
const
|
|
79
|
+
const instructionsResult = await discoverInstructionsSource({
|
|
80
80
|
rootEntries,
|
|
81
81
|
rootPath: input.subagentRoot,
|
|
82
82
|
source: input.source,
|
|
83
83
|
});
|
|
84
|
-
diagnostics.push(...
|
|
84
|
+
diagnostics.push(...instructionsResult.diagnostics);
|
|
85
85
|
const configModuleResult = discoverFlatModuleSource({
|
|
86
86
|
missingDiagnostic: {
|
|
87
87
|
code: DISCOVER_REQUIRED_SUBAGENT_CONFIG_MODULE_MISSING,
|
|
@@ -151,7 +151,7 @@ async function discoverLocalSubagentPackage(input) {
|
|
|
151
151
|
diagnostics,
|
|
152
152
|
hooks: hooksResult.sources,
|
|
153
153
|
lib: libResult.lib,
|
|
154
|
-
|
|
154
|
+
instructions: instructionsResult.instructions,
|
|
155
155
|
sandbox: sandboxResult.sandbox,
|
|
156
156
|
sandboxWorkspaces: sandboxResult.sandboxWorkspace === null ? [] : [sandboxResult.sandboxWorkspace],
|
|
157
157
|
skills: skillsResult.skills,
|
|
@@ -11,7 +11,7 @@ export declare const PROJECT_MARKER_FILE_NAMES: readonly ["package.json", "verce
|
|
|
11
11
|
/**
|
|
12
12
|
* Supported root-level files inside an agent package.
|
|
13
13
|
*/
|
|
14
|
-
export declare const AGENT_ROOT_FILE_NAMES: readonly ["agent.ts", "agent.cts", "agent.mts", "agent.js", "agent.cjs", "agent.mjs", "system.md", "system.ts", "system.cts", "system.mts", "system.js", "system.cjs", "system.mjs"];
|
|
14
|
+
export declare const AGENT_ROOT_FILE_NAMES: readonly ["agent.ts", "agent.cts", "agent.mts", "agent.js", "agent.cjs", "agent.mjs", "instructions.md", "instructions.ts", "instructions.cts", "instructions.mts", "instructions.js", "instructions.cjs", "instructions.mjs", "system.md", "system.ts", "system.cts", "system.mts", "system.js", "system.cjs", "system.mjs"];
|
|
15
15
|
/**
|
|
16
16
|
* Supported root-level directories inside an agent package.
|
|
17
17
|
*/
|
|
@@ -20,7 +20,7 @@ export declare const AGENT_ROOT_DIRECTORY_NAMES: readonly ["channels", "connecti
|
|
|
20
20
|
* Supported local-subagent entry file names. Subagents reuse the root
|
|
21
21
|
* agent's `agent.{ts,...}` config slot.
|
|
22
22
|
*/
|
|
23
|
-
export declare const LOCAL_SUBAGENT_FILE_NAMES: readonly ["agent.ts", "agent.cts", "agent.mts", "agent.js", "agent.cjs", "agent.mjs", "system.md", "system.ts", "system.cts", "system.mts", "system.js", "system.cjs", "system.mjs"];
|
|
23
|
+
export declare const LOCAL_SUBAGENT_FILE_NAMES: readonly ["agent.ts", "agent.cts", "agent.mts", "agent.js", "agent.cjs", "agent.mjs", "instructions.md", "instructions.ts", "instructions.cts", "instructions.mts", "instructions.js", "instructions.cjs", "instructions.mjs", "system.md", "system.ts", "system.cts", "system.mts", "system.js", "system.cjs", "system.mjs"];
|
|
24
24
|
/**
|
|
25
25
|
* Supported local-subagent subdirectories.
|
|
26
26
|
*/
|
|
@@ -40,11 +40,11 @@ export type DirectoryEntryType = "directory" | "file" | "other";
|
|
|
40
40
|
/**
|
|
41
41
|
* Classified root-level agent entry.
|
|
42
42
|
*/
|
|
43
|
-
export type AgentRootEntryKind = "agent-config-module" | "channels-directory" | "connections-directory" | "hooks-directory" | "lib-directory" | "sandbox-directory" | "schedules-directory" | "skills-directory" | "system-markdown" | "system-module" | "tools-directory" | "unknown" | "subagents-directory";
|
|
43
|
+
export type AgentRootEntryKind = "agent-config-module" | "channels-directory" | "connections-directory" | "hooks-directory" | "instructions-markdown" | "instructions-module" | "lib-directory" | "sandbox-directory" | "schedules-directory" | "skills-directory" | "system-markdown" | "system-module" | "tools-directory" | "unknown" | "subagents-directory";
|
|
44
44
|
/**
|
|
45
45
|
* Classified local-subagent root entry.
|
|
46
46
|
*/
|
|
47
|
-
export type LocalSubagentEntryKind = "agent-config-module" | "connections-directory" | "hooks-directory" | "invalid-schedules-directory" | "lib-directory" | "sandbox-directory" | "skills-directory" | "system-markdown" | "system-module" | "tools-directory" | "unknown" | "subagents-directory";
|
|
47
|
+
export type LocalSubagentEntryKind = "agent-config-module" | "connections-directory" | "hooks-directory" | "instructions-markdown" | "instructions-module" | "invalid-schedules-directory" | "lib-directory" | "sandbox-directory" | "skills-directory" | "system-markdown" | "system-module" | "tools-directory" | "unknown" | "subagents-directory";
|
|
48
48
|
/**
|
|
49
49
|
* Classified Agent Skills package entry.
|
|
50
50
|
*/
|
|
@@ -25,6 +25,15 @@ export const AGENT_ROOT_FILE_NAMES = [
|
|
|
25
25
|
"agent.js",
|
|
26
26
|
"agent.cjs",
|
|
27
27
|
"agent.mjs",
|
|
28
|
+
"instructions.md",
|
|
29
|
+
"instructions.ts",
|
|
30
|
+
"instructions.cts",
|
|
31
|
+
"instructions.mts",
|
|
32
|
+
"instructions.js",
|
|
33
|
+
"instructions.cjs",
|
|
34
|
+
"instructions.mjs",
|
|
35
|
+
// The `system` files are deprecated and will be removed soon.
|
|
36
|
+
// TODO: Clean up in the near future.
|
|
28
37
|
"system.md",
|
|
29
38
|
"system.ts",
|
|
30
39
|
"system.cts",
|
|
@@ -58,6 +67,15 @@ export const LOCAL_SUBAGENT_FILE_NAMES = [
|
|
|
58
67
|
"agent.js",
|
|
59
68
|
"agent.cjs",
|
|
60
69
|
"agent.mjs",
|
|
70
|
+
"instructions.md",
|
|
71
|
+
"instructions.ts",
|
|
72
|
+
"instructions.cts",
|
|
73
|
+
"instructions.mts",
|
|
74
|
+
"instructions.js",
|
|
75
|
+
"instructions.cjs",
|
|
76
|
+
"instructions.mjs",
|
|
77
|
+
// The `system` files are deprecated and will be removed soon.
|
|
78
|
+
// TODO: Clean up in the near future.
|
|
61
79
|
"system.md",
|
|
62
80
|
"system.ts",
|
|
63
81
|
"system.cts",
|
|
@@ -118,6 +136,12 @@ export function classifyAgentRootEntry(name, entryType) {
|
|
|
118
136
|
if (matchesSupportedModuleBaseName(name, "agent")) {
|
|
119
137
|
return "agent-config-module";
|
|
120
138
|
}
|
|
139
|
+
if (name === "instructions.md") {
|
|
140
|
+
return "instructions-markdown";
|
|
141
|
+
}
|
|
142
|
+
if (matchesSupportedModuleBaseName(name, "instructions")) {
|
|
143
|
+
return "instructions-module";
|
|
144
|
+
}
|
|
121
145
|
if (name === "system.md") {
|
|
122
146
|
return "system-markdown";
|
|
123
147
|
}
|
|
@@ -165,6 +189,12 @@ export function classifyLocalSubagentEntry(name, entryType) {
|
|
|
165
189
|
if (matchesSupportedModuleBaseName(name, "agent")) {
|
|
166
190
|
return "agent-config-module";
|
|
167
191
|
}
|
|
192
|
+
if (name === "instructions.md") {
|
|
193
|
+
return "instructions-markdown";
|
|
194
|
+
}
|
|
195
|
+
if (matchesSupportedModuleBaseName(name, "instructions")) {
|
|
196
|
+
return "instructions-module";
|
|
197
|
+
}
|
|
168
198
|
if (name === "system.md") {
|
|
169
199
|
return "system-markdown";
|
|
170
200
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Dirent } from "node:fs";
|
|
2
2
|
import type { MarkdownSourceRef, ModuleSourceRef } from "#shared/source-ref.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { InstructionsDefinition } from "#public/definitions/instructions.js";
|
|
4
4
|
import { type DiscoverDiagnostic } from "#discover/diagnostics.js";
|
|
5
5
|
import { type DirectoryEntryType } from "#discover/filesystem.js";
|
|
6
6
|
import type { ProjectSource, ProjectSourceEntry } from "#discover/project-source.js";
|
|
@@ -9,9 +9,17 @@ import type { ProjectSource, ProjectSourceEntry } from "#discover/project-source
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const DISCOVER_MODULE_SLOT_COLLISION = "discover/module-slot-collision";
|
|
11
11
|
/**
|
|
12
|
-
* Shared diagnostic emitted when the required
|
|
12
|
+
* Shared diagnostic emitted when the required instructions prompt source
|
|
13
|
+
* is missing.
|
|
13
14
|
*/
|
|
14
|
-
export declare const
|
|
15
|
+
export declare const DISCOVER_REQUIRED_INSTRUCTIONS_MISSING = "discover/required-instructions-missing";
|
|
16
|
+
/**
|
|
17
|
+
* Shared diagnostic emitted when discovery falls back to the deprecated
|
|
18
|
+
* `system.{md,ts,...}` slot because no `instructions.{md,ts,...}` source
|
|
19
|
+
* was found. The fallback resolves successfully; the warning prompts the
|
|
20
|
+
* author to rename the file.
|
|
21
|
+
*/
|
|
22
|
+
export declare const DISCOVER_DEPRECATED_SYSTEM_SLOT = "discover/deprecated-system-slot";
|
|
15
23
|
/**
|
|
16
24
|
* Shared diagnostic emitted when a slot has both markdown and module sources.
|
|
17
25
|
*/
|
|
@@ -100,7 +108,7 @@ export declare const DISCOVER_UNSUPPORTED_DIRECTORY = "discover/unsupported-dire
|
|
|
100
108
|
* {@link createDiskProjectSource} returns them directly.
|
|
101
109
|
*/
|
|
102
110
|
export type StringDirent = Dirent<string>;
|
|
103
|
-
type
|
|
111
|
+
type InstructionsSourceRef = MarkdownSourceRef<InstructionsDefinition> | ModuleSourceRef;
|
|
104
112
|
/**
|
|
105
113
|
* Reads one directory through `source` and returns its entries sorted by name.
|
|
106
114
|
*/
|
|
@@ -110,15 +118,21 @@ export declare function readSortedDirectoryEntries(source: ProjectSource, direct
|
|
|
110
118
|
*/
|
|
111
119
|
export declare function getPathType(source: ProjectSource, targetPath: string): Promise<"directory" | "file" | "missing" | "other">;
|
|
112
120
|
/**
|
|
113
|
-
* Discovers one required `
|
|
121
|
+
* Discovers one required `instructions.md|ts|cts|mts|js|cjs|mjs` source
|
|
122
|
+
* from a root directory.
|
|
123
|
+
*
|
|
124
|
+
* For backwards compatibility, falls back to the deprecated
|
|
125
|
+
* `system.{md,ts,...}` slot when no `instructions.*` source is present —
|
|
126
|
+
* with a {@link DISCOVER_DEPRECATED_SYSTEM_SLOT} warning prompting the
|
|
127
|
+
* author to rename the file.
|
|
114
128
|
*/
|
|
115
|
-
export declare function
|
|
129
|
+
export declare function discoverInstructionsSource(input: {
|
|
116
130
|
rootEntries: readonly ProjectSourceEntry[];
|
|
117
131
|
rootPath: string;
|
|
118
132
|
source: ProjectSource;
|
|
119
133
|
}): Promise<{
|
|
120
134
|
diagnostics: DiscoverDiagnostic[];
|
|
121
|
-
|
|
135
|
+
instructions?: InstructionsSourceRef;
|
|
122
136
|
}>;
|
|
123
137
|
/**
|
|
124
138
|
* Discovers one flat module slot such as `agent.ts` or `subagent.cjs`.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import {
|
|
2
|
+
import { lowerInstructionsMarkdown } from "#public/helpers/markdown.js";
|
|
3
3
|
import { createDiscoverErrorDiagnostic, createDiscoverWarningDiagnostic, } from "#discover/diagnostics.js";
|
|
4
4
|
import { getDirectoryEntryType } from "#discover/filesystem.js";
|
|
5
5
|
import { createModuleSourceRef } from "#discover/manifest.js";
|
|
@@ -10,9 +10,17 @@ import { collectFlatSlotCandidates } from "#discover/slots.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export const DISCOVER_MODULE_SLOT_COLLISION = "discover/module-slot-collision";
|
|
12
12
|
/**
|
|
13
|
-
* Shared diagnostic emitted when the required
|
|
13
|
+
* Shared diagnostic emitted when the required instructions prompt source
|
|
14
|
+
* is missing.
|
|
14
15
|
*/
|
|
15
|
-
export const
|
|
16
|
+
export const DISCOVER_REQUIRED_INSTRUCTIONS_MISSING = "discover/required-instructions-missing";
|
|
17
|
+
/**
|
|
18
|
+
* Shared diagnostic emitted when discovery falls back to the deprecated
|
|
19
|
+
* `system.{md,ts,...}` slot because no `instructions.{md,ts,...}` source
|
|
20
|
+
* was found. The fallback resolves successfully; the warning prompts the
|
|
21
|
+
* author to rename the file.
|
|
22
|
+
*/
|
|
23
|
+
export const DISCOVER_DEPRECATED_SYSTEM_SLOT = "discover/deprecated-system-slot";
|
|
16
24
|
/**
|
|
17
25
|
* Shared diagnostic emitted when a slot has both markdown and module sources.
|
|
18
26
|
*/
|
|
@@ -106,17 +114,75 @@ export async function getPathType(source, targetPath) {
|
|
|
106
114
|
return await source.stat(targetPath);
|
|
107
115
|
}
|
|
108
116
|
/**
|
|
109
|
-
* Discovers one required `
|
|
117
|
+
* Discovers one required `instructions.md|ts|cts|mts|js|cjs|mjs` source
|
|
118
|
+
* from a root directory.
|
|
119
|
+
*
|
|
120
|
+
* For backwards compatibility, falls back to the deprecated
|
|
121
|
+
* `system.{md,ts,...}` slot when no `instructions.*` source is present —
|
|
122
|
+
* with a {@link DISCOVER_DEPRECATED_SYSTEM_SLOT} warning prompting the
|
|
123
|
+
* author to rename the file.
|
|
110
124
|
*/
|
|
111
|
-
export async function
|
|
112
|
-
const
|
|
125
|
+
export async function discoverInstructionsSource(input) {
|
|
126
|
+
const result = await discoverSlotSource({
|
|
127
|
+
markdownFileName: "instructions.md",
|
|
128
|
+
moduleBaseName: "instructions",
|
|
129
|
+
rootEntries: input.rootEntries,
|
|
130
|
+
rootPath: input.rootPath,
|
|
131
|
+
slotLabel: "instructions",
|
|
132
|
+
source: input.source,
|
|
133
|
+
});
|
|
134
|
+
if (result.diagnostics.length > 0 || result.source !== undefined) {
|
|
135
|
+
return {
|
|
136
|
+
diagnostics: result.diagnostics,
|
|
137
|
+
instructions: result.source,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const legacyResult = await discoverSlotSource({
|
|
113
141
|
markdownFileName: "system.md",
|
|
114
142
|
moduleBaseName: "system",
|
|
143
|
+
rootEntries: input.rootEntries,
|
|
144
|
+
rootPath: input.rootPath,
|
|
145
|
+
slotLabel: "system",
|
|
146
|
+
source: input.source,
|
|
147
|
+
});
|
|
148
|
+
if (legacyResult.source !== undefined) {
|
|
149
|
+
const fileName = legacyResult.source.sourceKind === "markdown" ? "system.md" : legacyResult.source.logicalPath;
|
|
150
|
+
return {
|
|
151
|
+
diagnostics: [
|
|
152
|
+
createDiscoverWarningDiagnostic({
|
|
153
|
+
code: DISCOVER_DEPRECATED_SYSTEM_SLOT,
|
|
154
|
+
message: `The "${fileName}" slot is deprecated. Rename it to "${fileName.replace(/^system/, "instructions")}" — the runtime still loads the legacy slot for now, but support will be removed in a future release.`,
|
|
155
|
+
sourcePath: join(input.rootPath, fileName),
|
|
156
|
+
}),
|
|
157
|
+
...legacyResult.diagnostics,
|
|
158
|
+
],
|
|
159
|
+
instructions: legacyResult.source,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (legacyResult.diagnostics.length > 0) {
|
|
163
|
+
return {
|
|
164
|
+
diagnostics: legacyResult.diagnostics,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
diagnostics: [
|
|
169
|
+
createDiscoverErrorDiagnostic({
|
|
170
|
+
code: DISCOVER_REQUIRED_INSTRUCTIONS_MISSING,
|
|
171
|
+
message: 'Expected one authored instructions prompt source at "instructions.md", "instructions.ts", "instructions.cts", "instructions.mts", "instructions.js", "instructions.cjs", or "instructions.mjs".',
|
|
172
|
+
sourcePath: input.rootPath,
|
|
173
|
+
}),
|
|
174
|
+
],
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
async function discoverSlotSource(input) {
|
|
178
|
+
const candidates = collectFlatSlotCandidates(input.rootEntries, {
|
|
179
|
+
markdownFileName: input.markdownFileName,
|
|
180
|
+
moduleBaseName: input.moduleBaseName,
|
|
115
181
|
});
|
|
116
182
|
if (candidates.markdownFileName !== undefined && candidates.moduleFileNames.length > 0) {
|
|
117
183
|
return {
|
|
118
184
|
diagnostics: [
|
|
119
|
-
createSlotCollisionDiagnostic(input.rootPath,
|
|
185
|
+
createSlotCollisionDiagnostic(input.rootPath, input.slotLabel, [
|
|
120
186
|
candidates.markdownFileName,
|
|
121
187
|
...candidates.moduleFileNames,
|
|
122
188
|
]),
|
|
@@ -126,16 +192,16 @@ export async function discoverSystemSource(input) {
|
|
|
126
192
|
if (candidates.moduleFileNames.length > 1) {
|
|
127
193
|
return {
|
|
128
194
|
diagnostics: [
|
|
129
|
-
createModuleSlotCollisionDiagnostic(input.rootPath,
|
|
195
|
+
createModuleSlotCollisionDiagnostic(input.rootPath, input.slotLabel, candidates.moduleFileNames),
|
|
130
196
|
],
|
|
131
197
|
};
|
|
132
198
|
}
|
|
133
199
|
if (candidates.markdownFileName !== undefined) {
|
|
134
200
|
return {
|
|
135
201
|
diagnostics: [],
|
|
136
|
-
|
|
137
|
-
logicalPath:
|
|
138
|
-
lower:
|
|
202
|
+
source: await discoverMarkdownSource({
|
|
203
|
+
logicalPath: input.markdownFileName,
|
|
204
|
+
lower: lowerInstructionsMarkdown,
|
|
139
205
|
source: input.source,
|
|
140
206
|
sourcePath: join(input.rootPath, candidates.markdownFileName),
|
|
141
207
|
}),
|
|
@@ -145,20 +211,12 @@ export async function discoverSystemSource(input) {
|
|
|
145
211
|
if (logicalPath !== undefined) {
|
|
146
212
|
return {
|
|
147
213
|
diagnostics: [],
|
|
148
|
-
|
|
214
|
+
source: createModuleSourceRef({
|
|
149
215
|
logicalPath,
|
|
150
216
|
}),
|
|
151
217
|
};
|
|
152
218
|
}
|
|
153
|
-
return {
|
|
154
|
-
diagnostics: [
|
|
155
|
-
createDiscoverErrorDiagnostic({
|
|
156
|
-
code: DISCOVER_REQUIRED_SYSTEM_MISSING,
|
|
157
|
-
message: 'Expected one authored system prompt source at "system.md", "system.ts", "system.cts", "system.mts", "system.js", "system.cjs", or "system.mjs".',
|
|
158
|
-
sourcePath: input.rootPath,
|
|
159
|
-
}),
|
|
160
|
-
],
|
|
161
|
-
};
|
|
219
|
+
return { diagnostics: [] };
|
|
162
220
|
}
|
|
163
221
|
/**
|
|
164
222
|
* Discovers one flat module slot such as `agent.ts` or `subagent.cjs`.
|