@codeworksh/harness 0.3.0-canary.28.1.geeda473b → 0.3.0-canary.29.1.g334eb9ee
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/effect.mjs +270 -33
- package/effect.mjs.map +1 -1
- package/package.json +6 -4
package/effect.mjs
CHANGED
|
@@ -26,6 +26,8 @@ import { JsonGitHubCopilotAuthStorage, getGitHubCopilotApiKey } from "@codeworks
|
|
|
26
26
|
import { JsonOpenAICodexAuthStorage, getOpenAICodexApiKey } from "@codeworksh/aikit/oauth/openai/codex";
|
|
27
27
|
import { parse, printParseErrorCode } from "jsonc-parser";
|
|
28
28
|
import * as Section from "@codeworksh/plugin/plugin/section";
|
|
29
|
+
import ignore from "ignore";
|
|
30
|
+
import { parse as parse$1 } from "yaml";
|
|
29
31
|
import * as Diff from "diff";
|
|
30
32
|
import { FetchHttpClient, HttpClient } from "effect/http";
|
|
31
33
|
import npa from "npm-package-arg";
|
|
@@ -4464,7 +4466,8 @@ const up = Effect.fn("SandboxFileSystem.up")(function* (fs, options) {
|
|
|
4464
4466
|
const isDirectory$1 = Effect.fn("SandboxFileSystem.isDirectory")(function* (fs, path) {
|
|
4465
4467
|
return yield* fs.stat(path).pipe(Effect.map((stat) => stat.isDirectory), Effect.orElseSucceed(() => false));
|
|
4466
4468
|
});
|
|
4467
|
-
|
|
4469
|
+
/** True when `path` exists and is a regular file; false when it is absent or unreadable. */
|
|
4470
|
+
const isFile = Effect.fn("SandboxFileSystem.isFile")(function* (fs, path) {
|
|
4468
4471
|
return yield* fs.stat(path).pipe(Effect.map((stat) => stat.isFile), Effect.orElseSucceed(() => false));
|
|
4469
4472
|
});
|
|
4470
4473
|
/** Read a file, or `undefined` when it is missing or unreadable. */
|
|
@@ -5312,7 +5315,7 @@ var settings_exports = /* @__PURE__ */ __exportAll({
|
|
|
5312
5315
|
layer: () => layer$8,
|
|
5313
5316
|
load: () => load$3,
|
|
5314
5317
|
modules: () => modules,
|
|
5315
|
-
parse: () => parse$
|
|
5318
|
+
parse: () => parse$5,
|
|
5316
5319
|
paths: () => paths,
|
|
5317
5320
|
projectRoot: () => projectRoot,
|
|
5318
5321
|
userConfigDir: () => userConfigDir
|
|
@@ -5401,7 +5404,7 @@ const decodeFormatter = SchemaIssue.makeFormatterStandardSchemaV1({ leafHook: (i
|
|
|
5401
5404
|
const message = "annotations" in issue ? issue.annotations?.message : void 0;
|
|
5402
5405
|
return typeof message === "string" ? message.replaceAll(/\s*\n\s*/g, " ") : "invalid value";
|
|
5403
5406
|
} });
|
|
5404
|
-
const parse$
|
|
5407
|
+
const parse$5 = Effect.fn("Settings.parse")(function* (path, source) {
|
|
5405
5408
|
const errors = [];
|
|
5406
5409
|
const json = parse(source, errors, {
|
|
5407
5410
|
allowTrailingComma: true,
|
|
@@ -5449,7 +5452,7 @@ const attempt = (path) => fileSystem.readFileString(path).pipe(Effect.mapError((
|
|
|
5449
5452
|
path,
|
|
5450
5453
|
reason: "read",
|
|
5451
5454
|
detail: error.reason._tag
|
|
5452
|
-
})), Effect.flatMap((source) => parse$
|
|
5455
|
+
})), Effect.flatMap((source) => parse$5(path, source)));
|
|
5453
5456
|
/**
|
|
5454
5457
|
* One read of every layer. Exported for the harness constructor, which needs the plugin
|
|
5455
5458
|
* selection before any layer is built; everything else goes through `Service`.
|
|
@@ -5755,6 +5758,22 @@ const defaultPromptPlugin = (0, plugin_exports$1.define)({
|
|
|
5755
5758
|
})
|
|
5756
5759
|
});
|
|
5757
5760
|
//#endregion
|
|
5761
|
+
//#region src/plugin/builtin/prompt/walk.ts
|
|
5762
|
+
const stripBom$1 = (raw) => raw.charCodeAt(0) === 65279 ? raw.slice(1) : raw;
|
|
5763
|
+
/** `directory` and every ancestor up to the sandbox root, closest first. */
|
|
5764
|
+
const ancestors = (directory) => {
|
|
5765
|
+
const chain = [];
|
|
5766
|
+
for (let current = directory;; current = posix.dirname(current)) {
|
|
5767
|
+
chain.push(current);
|
|
5768
|
+
if (posix.dirname(current) === current) return chain;
|
|
5769
|
+
}
|
|
5770
|
+
};
|
|
5771
|
+
/**
|
|
5772
|
+
* Which of `paths` exist as the requested kind (`entry` takes either). Absence stays silent; any other failure
|
|
5773
|
+
* (permissions, a remote blip) is logged so a dropped entry is not a mystery, then counts as absent.
|
|
5774
|
+
*/
|
|
5775
|
+
const present$1 = (fs, paths, kind, label) => Effect.forEach(paths, (path) => fs.exists(path).pipe(Effect.filterOrElse((exists) => !exists || kind === "entry", () => fs.stat(path).pipe(Effect.map((stat) => kind === "file" ? stat.isFile : stat.isDirectory))), Effect.catch((error) => filesystem_exports.SandboxFileSystem.isNotFoundError(error.cause) ? Effect.succeed(false) : Effect.logWarning(`could not stat ${label} ${path}`, error.cause).pipe(Effect.as(false)))), { concurrency: "unbounded" }).pipe(Effect.map((hits) => new Set(paths.filter((_, index) => hits[index]))));
|
|
5776
|
+
//#endregion
|
|
5758
5777
|
//#region src/plugin/builtin/prompt/instruction.ts
|
|
5759
5778
|
/** First readable match per directory wins. */
|
|
5760
5779
|
const names = [
|
|
@@ -5766,22 +5785,9 @@ const names = [
|
|
|
5766
5785
|
"CLAUDE.MD"
|
|
5767
5786
|
];
|
|
5768
5787
|
const content = (raw) => {
|
|
5769
|
-
const text =
|
|
5788
|
+
const text = stripBom$1(raw);
|
|
5770
5789
|
return text.trim().length === 0 ? void 0 : text;
|
|
5771
5790
|
};
|
|
5772
|
-
/** `directory` and every ancestor up to the sandbox root, closest first. */
|
|
5773
|
-
const ancestors = (directory) => {
|
|
5774
|
-
const chain = [];
|
|
5775
|
-
for (let current = directory;; current = posix.dirname(current)) {
|
|
5776
|
-
chain.push(current);
|
|
5777
|
-
if (posix.dirname(current) === current) return chain;
|
|
5778
|
-
}
|
|
5779
|
-
};
|
|
5780
|
-
/**
|
|
5781
|
-
* Which of `paths` are files. Absence is the expected answer and stays silent; any other failure
|
|
5782
|
-
* (permissions, a remote blip) is logged so a dropped file is not a mystery, then counts as absent.
|
|
5783
|
-
*/
|
|
5784
|
-
const present$1 = (fs, paths) => Effect.forEach(paths, (path) => fs.exists(path).pipe(Effect.flatMap((exists) => exists ? fs.stat(path).pipe(Effect.map((stat) => stat.isFile)) : Effect.succeed(false)), Effect.catch((error) => filesystem_exports.SandboxFileSystem.isNotFoundError(error.cause) ? Effect.succeed(false) : Effect.logWarning(`could not stat instruction file ${path}`, error.cause).pipe(Effect.as(false)))), { concurrency: "unbounded" }).pipe(Effect.map((hits) => new Set(paths.filter((_, index) => hits[index]))));
|
|
5785
5791
|
/** A file that stats but does not read falls through to the next candidate. */
|
|
5786
5792
|
const first = Effect.fnUntraced(function* (fs, directory, files) {
|
|
5787
5793
|
for (const name of names) {
|
|
@@ -5809,9 +5815,9 @@ const shadowing = (location) => {
|
|
|
5809
5815
|
return location.space.location.startsWith(`${main}/`) ? main : void 0;
|
|
5810
5816
|
};
|
|
5811
5817
|
/** One file per directory from the sandbox root down to the cwd, closest last so it has the final word. */
|
|
5812
|
-
const discover = Effect.fnUntraced(function* (fs, location) {
|
|
5818
|
+
const discover$1 = Effect.fnUntraced(function* (fs, location) {
|
|
5813
5819
|
const chain = ancestors(location.directory);
|
|
5814
|
-
const files = yield* present$1(fs, chain.flatMap((directory) => names.map((name) => posix.join(directory, name))));
|
|
5820
|
+
const files = yield* present$1(fs, chain.flatMap((directory) => names.map((name) => posix.join(directory, name))), "file", "instruction file");
|
|
5815
5821
|
const found = yield* Effect.forEach(chain, (directory) => first(fs, directory, files), { concurrency: "unbounded" });
|
|
5816
5822
|
const main = shadowing(location);
|
|
5817
5823
|
const worktree = main === void 0 ? void 0 : found[chain.indexOf(location.space.location)];
|
|
@@ -5827,7 +5833,7 @@ const instructionPlugin = (0, plugin_exports$1.define)({
|
|
|
5827
5833
|
kind: "prompt",
|
|
5828
5834
|
setup: Effect.fn("InstructionPlugin.setup")(function* (ctx) {
|
|
5829
5835
|
const fs = yield* io_exports.SandboxIO.FileSystem;
|
|
5830
|
-
const files = (yield* discover(fs, ctx.location)).filter((file) => file.content !== void 0);
|
|
5836
|
+
const files = (yield* discover$1(fs, ctx.location)).filter((file) => file.content !== void 0);
|
|
5831
5837
|
if (files.length === 0) return;
|
|
5832
5838
|
const prompt = ctx.plugin.prompt;
|
|
5833
5839
|
prompt.sections.append(Section.ProjectContext, "Project-Specific Instructions & Guidelines:");
|
|
@@ -5835,6 +5841,236 @@ const instructionPlugin = (0, plugin_exports$1.define)({
|
|
|
5835
5841
|
})
|
|
5836
5842
|
});
|
|
5837
5843
|
//#endregion
|
|
5844
|
+
//#region src/plugin/builtin/prompt/skill.ts
|
|
5845
|
+
/** Max name length per Agent Skills spec. */
|
|
5846
|
+
const MAX_NAME_LENGTH = 64;
|
|
5847
|
+
/** Max description length per Agent Skills spec. */
|
|
5848
|
+
const MAX_DESCRIPTION_LENGTH = 1024;
|
|
5849
|
+
const IGNORE_FILE_NAMES = [
|
|
5850
|
+
".gitignore",
|
|
5851
|
+
".ignore",
|
|
5852
|
+
".fdignore"
|
|
5853
|
+
];
|
|
5854
|
+
const normalizeNewlines = (value) => value.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
|
|
5855
|
+
const extractFrontmatter = (content) => {
|
|
5856
|
+
const normalized = normalizeNewlines(stripBom$1(content));
|
|
5857
|
+
if (!normalized.startsWith("---")) return void 0;
|
|
5858
|
+
const endIndex = normalized.indexOf("\n---", 3);
|
|
5859
|
+
if (endIndex === -1) return void 0;
|
|
5860
|
+
return normalized.slice(4, endIndex);
|
|
5861
|
+
};
|
|
5862
|
+
const parseFrontmatter = (raw) => {
|
|
5863
|
+
const yamlString = extractFrontmatter(raw);
|
|
5864
|
+
if (yamlString === void 0) return { frontmatter: {} };
|
|
5865
|
+
try {
|
|
5866
|
+
const parsed = parse$1(yamlString);
|
|
5867
|
+
return { frontmatter: typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {} };
|
|
5868
|
+
} catch (error) {
|
|
5869
|
+
return {
|
|
5870
|
+
frontmatter: {},
|
|
5871
|
+
error
|
|
5872
|
+
};
|
|
5873
|
+
}
|
|
5874
|
+
};
|
|
5875
|
+
const validateName = (name) => {
|
|
5876
|
+
const errors = [];
|
|
5877
|
+
if (name.length > MAX_NAME_LENGTH) errors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);
|
|
5878
|
+
if (!/^[a-z0-9-]+$/.test(name)) errors.push("name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)");
|
|
5879
|
+
if (name.startsWith("-") || name.endsWith("-")) errors.push("name must not start or end with a hyphen");
|
|
5880
|
+
if (name.includes("--")) errors.push("name must not contain consecutive hyphens");
|
|
5881
|
+
return errors;
|
|
5882
|
+
};
|
|
5883
|
+
const validateDescription = (description) => {
|
|
5884
|
+
const errors = [];
|
|
5885
|
+
if (typeof description !== "string" || description.trim() === "") errors.push("description is required");
|
|
5886
|
+
else if (description.length > MAX_DESCRIPTION_LENGTH) errors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);
|
|
5887
|
+
return errors;
|
|
5888
|
+
};
|
|
5889
|
+
const prefixIgnorePattern = (line, prefix) => {
|
|
5890
|
+
const trimmed = line.trim();
|
|
5891
|
+
if (!trimmed) return void 0;
|
|
5892
|
+
if (trimmed.startsWith("#") && !trimmed.startsWith("\\#")) return void 0;
|
|
5893
|
+
let pattern = line;
|
|
5894
|
+
let negated = false;
|
|
5895
|
+
if (pattern.startsWith("!")) {
|
|
5896
|
+
negated = true;
|
|
5897
|
+
pattern = pattern.slice(1);
|
|
5898
|
+
} else if (pattern.startsWith("\\!")) pattern = pattern.slice(1);
|
|
5899
|
+
if (pattern.startsWith("/")) pattern = pattern.slice(1);
|
|
5900
|
+
const prefixed = prefix ? `${prefix}${pattern}` : pattern;
|
|
5901
|
+
return negated ? `!${prefixed}` : prefixed;
|
|
5902
|
+
};
|
|
5903
|
+
const addIgnoreRules = Effect.fnUntraced(function* (fs, ig, dir, root, entryNames) {
|
|
5904
|
+
const relativeDir = posix.relative(root, dir);
|
|
5905
|
+
const prefix = relativeDir && relativeDir !== "." ? `${relativeDir}/` : "";
|
|
5906
|
+
const presentIgnoreFiles = IGNORE_FILE_NAMES.filter((name) => entryNames.has(name));
|
|
5907
|
+
if (presentIgnoreFiles.length === 0) return;
|
|
5908
|
+
const contents = yield* Effect.forEach(presentIgnoreFiles, (filename) => fs.readFile(posix.join(dir, filename)).pipe(Effect.option), { concurrency: "unbounded" });
|
|
5909
|
+
for (const content of contents) {
|
|
5910
|
+
if (Option.isNone(content)) continue;
|
|
5911
|
+
const patterns = content.value.split(/\r?\n/).map((line) => prefixIgnorePattern(line, prefix)).filter((line) => line !== void 0);
|
|
5912
|
+
if (patterns.length > 0) ig.add(patterns);
|
|
5913
|
+
}
|
|
5914
|
+
});
|
|
5915
|
+
const loadSkillFromFile = Effect.fnUntraced(function* (fs, filePath) {
|
|
5916
|
+
const isDeclaredSkill = posix.basename(filePath) === "SKILL.md";
|
|
5917
|
+
const raw = yield* fs.readFile(filePath).pipe(Effect.tapError((error) => Effect.logWarning(`could not read skill file ${filePath}`, error.cause)), Effect.option);
|
|
5918
|
+
if (Option.isNone(raw)) return void 0;
|
|
5919
|
+
const { frontmatter, error } = parseFrontmatter(raw.value);
|
|
5920
|
+
if (error !== void 0) {
|
|
5921
|
+
if (isDeclaredSkill) yield* Effect.logWarning(`could not parse skill file ${filePath}`, error);
|
|
5922
|
+
return;
|
|
5923
|
+
}
|
|
5924
|
+
const description = frontmatter.description;
|
|
5925
|
+
const hasDescription = typeof description === "string" && description.trim() !== "";
|
|
5926
|
+
if (!isDeclaredSkill && !hasDescription) return void 0;
|
|
5927
|
+
const skillDir = posix.dirname(filePath);
|
|
5928
|
+
const parentDirName = posix.basename(skillDir);
|
|
5929
|
+
for (const error of validateDescription(description)) yield* Effect.logWarning(`skill ${filePath}: ${error}`);
|
|
5930
|
+
const name = (typeof frontmatter.name === "string" ? frontmatter.name : void 0) || parentDirName;
|
|
5931
|
+
for (const error of validateName(name)) yield* Effect.logWarning(`skill ${filePath}: ${error}`);
|
|
5932
|
+
if (!hasDescription) return void 0;
|
|
5933
|
+
return {
|
|
5934
|
+
name,
|
|
5935
|
+
description,
|
|
5936
|
+
filePath,
|
|
5937
|
+
baseDir: skillDir,
|
|
5938
|
+
disableModelInvocation: frontmatter["disable-model-invocation"] === true
|
|
5939
|
+
};
|
|
5940
|
+
});
|
|
5941
|
+
const scanDir = (fs, dir, mode, root, ig, visited) => Effect.gen(function* () {
|
|
5942
|
+
const realDir = yield* realpath(fs, dir);
|
|
5943
|
+
if (visited.has(realDir)) return [];
|
|
5944
|
+
const nextVisited = /* @__PURE__ */ new Set([...visited, realDir]);
|
|
5945
|
+
const listed = yield* fs.readdir(dir).pipe(Effect.tapError((error) => filesystem_exports.SandboxFileSystem.isNotFoundError(error.cause) ? Effect.void : Effect.logWarning(`could not read skill directory ${dir}`, error.cause)), Effect.option);
|
|
5946
|
+
if (Option.isNone(listed)) return [];
|
|
5947
|
+
const entries = [...listed.value].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
5948
|
+
const entrySet = new Set(entries);
|
|
5949
|
+
yield* addIgnoreRules(fs, ig, dir, root, entrySet);
|
|
5950
|
+
if (entrySet.has("SKILL.md")) {
|
|
5951
|
+
const fullPath = posix.join(dir, "SKILL.md");
|
|
5952
|
+
const relPath = posix.relative(root, fullPath);
|
|
5953
|
+
if ((yield* isFile(fs, fullPath)) && !ig.ignores(relPath)) {
|
|
5954
|
+
const skill = yield* loadSkillFromFile(fs, fullPath);
|
|
5955
|
+
return skill === void 0 ? [] : [skill];
|
|
5956
|
+
}
|
|
5957
|
+
}
|
|
5958
|
+
const visible = entries.filter((name) => !name.startsWith(".") && name !== "node_modules");
|
|
5959
|
+
const statted = yield* Effect.forEach(visible, (name) => {
|
|
5960
|
+
const fullPath = posix.join(dir, name);
|
|
5961
|
+
return fs.stat(fullPath).pipe(Effect.map((stat) => ({
|
|
5962
|
+
name,
|
|
5963
|
+
fullPath,
|
|
5964
|
+
stat
|
|
5965
|
+
})), Effect.option);
|
|
5966
|
+
}, { concurrency: "unbounded" });
|
|
5967
|
+
const skills = [];
|
|
5968
|
+
for (const item of statted) {
|
|
5969
|
+
if (Option.isNone(item)) continue;
|
|
5970
|
+
const { name, fullPath, stat } = item.value;
|
|
5971
|
+
const relPath = posix.relative(root, fullPath);
|
|
5972
|
+
if (ig.ignores(stat.isDirectory ? `${relPath}/` : relPath)) continue;
|
|
5973
|
+
if (stat.isDirectory) {
|
|
5974
|
+
const nested = yield* scanDir(fs, fullPath, mode, root, ig, nextVisited);
|
|
5975
|
+
skills.push(...nested);
|
|
5976
|
+
continue;
|
|
5977
|
+
}
|
|
5978
|
+
if (stat.isFile && name.endsWith(".md") && (mode === "codework" && dir === root || mode === "agents" && dir !== root)) {
|
|
5979
|
+
const skill = yield* loadSkillFromFile(fs, fullPath);
|
|
5980
|
+
if (skill !== void 0) skills.push(skill);
|
|
5981
|
+
}
|
|
5982
|
+
}
|
|
5983
|
+
return skills;
|
|
5984
|
+
});
|
|
5985
|
+
/**
|
|
5986
|
+
* Load skills from a single directory in the sandbox.
|
|
5987
|
+
*
|
|
5988
|
+
* Discovery rules:
|
|
5989
|
+
* - If a directory contains `SKILL.md`, treat it as a skill root and do not recurse further.
|
|
5990
|
+
* - In `"codework"` mode, direct `.md` children in the root are also loaded; in `"agents"` mode,
|
|
5991
|
+
* `.md` files in subdirectories are loaded while root `.md` files are ignored.
|
|
5992
|
+
* - Recurse into subdirectories (skipping dotfiles, `node_modules`, and ignored paths).
|
|
5993
|
+
*/
|
|
5994
|
+
const loadSkillsFromDir = (fs, dir, mode) => scanDir(fs, dir, mode, dir, ignore(), /* @__PURE__ */ new Set());
|
|
5995
|
+
/**
|
|
5996
|
+
* Discover skills inside the sandbox: `.codework/skills` at the cwd, then
|
|
5997
|
+
* `.agents/skills` from the cwd up to the git root (the closest ancestor holding `.git`), or up to
|
|
5998
|
+
* the sandbox root outside a repository. Earlier skills win name collisions.
|
|
5999
|
+
*/
|
|
6000
|
+
const discover = Effect.fnUntraced(function* (fs, location) {
|
|
6001
|
+
const chain = ancestors(location.directory);
|
|
6002
|
+
const own = posix.join(location.directory, appConfigDir, "skills");
|
|
6003
|
+
const agents = chain.map((directory) => posix.join(directory, ".agents", "skills"));
|
|
6004
|
+
const [dirs, gits] = yield* Effect.all([present$1(fs, [own, ...agents], "directory", "skill directory"), present$1(fs, chain.map((directory) => posix.join(directory, ".git")), "entry", "git marker")], { concurrency: "unbounded" });
|
|
6005
|
+
const root = chain.findIndex((directory) => gits.has(posix.join(directory, ".git")));
|
|
6006
|
+
const walked = root === -1 ? agents : agents.slice(0, root + 1);
|
|
6007
|
+
const sources = [{
|
|
6008
|
+
dir: own,
|
|
6009
|
+
mode: "codework"
|
|
6010
|
+
}, ...walked.map((dir) => ({
|
|
6011
|
+
dir,
|
|
6012
|
+
mode: "agents"
|
|
6013
|
+
}))].filter(({ dir }) => dirs.has(dir));
|
|
6014
|
+
const found = yield* Effect.forEach(sources, ({ dir, mode }) => loadSkillsFromDir(fs, dir, mode), { concurrency: "unbounded" });
|
|
6015
|
+
const skillMap = /* @__PURE__ */ new Map();
|
|
6016
|
+
const realPathSet = /* @__PURE__ */ new Set();
|
|
6017
|
+
for (const skill of found.flat()) {
|
|
6018
|
+
const realPath = yield* realpath(fs, skill.filePath);
|
|
6019
|
+
if (realPathSet.has(realPath)) continue;
|
|
6020
|
+
const existing = skillMap.get(skill.name);
|
|
6021
|
+
if (existing !== void 0) yield* Effect.logWarning(`skill ${skill.filePath}: name "${skill.name}" collision with ${existing.filePath}`);
|
|
6022
|
+
else {
|
|
6023
|
+
skillMap.set(skill.name, skill);
|
|
6024
|
+
realPathSet.add(realPath);
|
|
6025
|
+
}
|
|
6026
|
+
}
|
|
6027
|
+
return Array.from(skillMap.values());
|
|
6028
|
+
});
|
|
6029
|
+
const escapeXml = (str) => str.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
6030
|
+
/**
|
|
6031
|
+
* Format skills for inclusion in `Section.Skills` per the Agent Skills specification.
|
|
6032
|
+
* Skills with `disableModelInvocation: true` are excluded from the prompt.
|
|
6033
|
+
*/
|
|
6034
|
+
const formatSkillsForPrompt = (skills, fileReadTool = "read") => {
|
|
6035
|
+
const visibleSkills = skills.filter((s) => !s.disableModelInvocation);
|
|
6036
|
+
if (visibleSkills.length === 0) return "";
|
|
6037
|
+
const lines = [
|
|
6038
|
+
"The following skills provide specialized instructions for specific tasks.",
|
|
6039
|
+
fileReadTool === "read" ? "Use the read tool to load a skill's file when the task matches its description." : fileReadTool === "bash" ? "Use bash to load a skill's file when the task matches its description." : "Load a skill's file when the task matches its description.",
|
|
6040
|
+
"When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.",
|
|
6041
|
+
"",
|
|
6042
|
+
"<available_skills>"
|
|
6043
|
+
];
|
|
6044
|
+
for (const skill of visibleSkills) {
|
|
6045
|
+
lines.push(" <skill>");
|
|
6046
|
+
lines.push(` <name>${escapeXml(skill.name)}</name>`);
|
|
6047
|
+
lines.push(` <description>${escapeXml(skill.description)}</description>`);
|
|
6048
|
+
lines.push(` <location>${escapeXml(skill.filePath)}</location>`);
|
|
6049
|
+
lines.push(" </skill>");
|
|
6050
|
+
}
|
|
6051
|
+
lines.push("</available_skills>");
|
|
6052
|
+
return lines.join("\n");
|
|
6053
|
+
};
|
|
6054
|
+
const readers = ["read", "bash"];
|
|
6055
|
+
const skillPlugin = (0, plugin_exports$1.define)({
|
|
6056
|
+
id: "codework.prompt.skill",
|
|
6057
|
+
kind: "prompt",
|
|
6058
|
+
setup: Effect.fn("SkillPlugin.setup")(function* (ctx) {
|
|
6059
|
+
const tools = ctx.plugin.tools;
|
|
6060
|
+
const visible = (name) => {
|
|
6061
|
+
const tool = tools.get(name);
|
|
6062
|
+
return tool !== void 0 && tool.promptSnippet !== void 0 && tool.promptSnippet.length > 0;
|
|
6063
|
+
};
|
|
6064
|
+
const fileReadTool = readers.find(visible) ?? (readers.some((name) => tools.has(name)) ? "indirect" : void 0);
|
|
6065
|
+
if (fileReadTool === void 0) return;
|
|
6066
|
+
const fs = yield* io_exports.SandboxIO.FileSystem;
|
|
6067
|
+
const skills = yield* discover(fs, ctx.location);
|
|
6068
|
+
const formatted = formatSkillsForPrompt(skills, fileReadTool);
|
|
6069
|
+
if (formatted.length === 0) return;
|
|
6070
|
+
ctx.plugin.prompt.sections.append(Section.Skills, formatted);
|
|
6071
|
+
})
|
|
6072
|
+
});
|
|
6073
|
+
//#endregion
|
|
5838
6074
|
//#region src/tool/truncate.ts
|
|
5839
6075
|
/**
|
|
5840
6076
|
* Shared truncation utilities for tool outputs.
|
|
@@ -6165,7 +6401,7 @@ const script = (command, file, limits, pipeline, report) => [
|
|
|
6165
6401
|
"run 2>&1"
|
|
6166
6402
|
].join("\n");
|
|
6167
6403
|
const header = new RegExp(`^${HEADER} (\\d+) (\\d+) ([01])(?: (\\d+))?$`, "m");
|
|
6168
|
-
const parse$
|
|
6404
|
+
const parse$4 = (match) => ({
|
|
6169
6405
|
bytes: Number(match[1]),
|
|
6170
6406
|
newlines: Number(match[2]),
|
|
6171
6407
|
kept: match[3] === "1"
|
|
@@ -6184,7 +6420,7 @@ const report = (stderr) => {
|
|
|
6184
6420
|
rest: stderr
|
|
6185
6421
|
};
|
|
6186
6422
|
return {
|
|
6187
|
-
report: parse$
|
|
6423
|
+
report: parse$4(match),
|
|
6188
6424
|
rest: stderr.slice(0, match.index) + stderr.slice(match.index + match[0].length).replace(/^\n/, "")
|
|
6189
6425
|
};
|
|
6190
6426
|
};
|
|
@@ -6207,7 +6443,7 @@ const window = (stdout) => {
|
|
|
6207
6443
|
const match = header.exec(newline === -1 ? stdout : stdout.slice(0, newline));
|
|
6208
6444
|
if (match === null || match[4] === void 0) return void 0;
|
|
6209
6445
|
return {
|
|
6210
|
-
...parse$
|
|
6446
|
+
...parse$4(match),
|
|
6211
6447
|
text: stdout.slice(newline + 1),
|
|
6212
6448
|
textBytes: Number(match[4])
|
|
6213
6449
|
};
|
|
@@ -7282,7 +7518,7 @@ const pipeline = (argv, limit, errors) => [
|
|
|
7282
7518
|
].join("; ");
|
|
7283
7519
|
const STATUS = /^\{"type":"rc","code":(\d+)\}$/;
|
|
7284
7520
|
/** The pipeline's output: match events, ripgrep's status, and anything else, which is its stderr. */
|
|
7285
|
-
const parse$
|
|
7521
|
+
const parse$3 = (stdout, stderr) => {
|
|
7286
7522
|
const matches = [];
|
|
7287
7523
|
const errors = [];
|
|
7288
7524
|
let status;
|
|
@@ -7366,7 +7602,7 @@ const grepHandler = (params) => Effect.gen(function* () {
|
|
|
7366
7602
|
if (params.glob) argv.push("--glob", params.glob);
|
|
7367
7603
|
argv.push("-e", params.pattern, searchPath);
|
|
7368
7604
|
const result = yield* shell.exec(pipeline(argv, limit, errors));
|
|
7369
|
-
const parsed = parse$
|
|
7605
|
+
const parsed = parse$3(result.stdout, result.stderr);
|
|
7370
7606
|
return {
|
|
7371
7607
|
...parsed,
|
|
7372
7608
|
exitCode: parsed.status ?? result.exitCode
|
|
@@ -7931,7 +8167,8 @@ const builtins = Object.freeze([
|
|
|
7931
8167
|
findPlugin,
|
|
7932
8168
|
lsPlugin,
|
|
7933
8169
|
defaultPromptPlugin,
|
|
7934
|
-
instructionPlugin
|
|
8170
|
+
instructionPlugin,
|
|
8171
|
+
skillPlugin
|
|
7935
8172
|
]);
|
|
7936
8173
|
//#endregion
|
|
7937
8174
|
//#region src/plugin/error.ts
|
|
@@ -8371,7 +8608,7 @@ const isPath = (reference) => reference.startsWith("file:") || reference.startsW
|
|
|
8371
8608
|
* - a **CLI argument** anchors to the process's startup directory, because that is where the
|
|
8372
8609
|
* person typed it.
|
|
8373
8610
|
*/
|
|
8374
|
-
const parse$
|
|
8611
|
+
const parse$2 = (reference, from) => Effect.gen(function* () {
|
|
8375
8612
|
const fail = (reason, message) => new SourceError({
|
|
8376
8613
|
reason,
|
|
8377
8614
|
reference,
|
|
@@ -9047,7 +9284,7 @@ const inspect = Effect.fn("PluginLoader.inspect")(function* (reference, options)
|
|
|
9047
9284
|
reference,
|
|
9048
9285
|
file: options.file
|
|
9049
9286
|
};
|
|
9050
|
-
const target = yield* parse$
|
|
9287
|
+
const target = yield* parse$2(reference, options.hostDir);
|
|
9051
9288
|
const loaded = yield* load$2(target, origin, options);
|
|
9052
9289
|
return {
|
|
9053
9290
|
id: loaded.plugin.id,
|
|
@@ -9073,7 +9310,7 @@ const load$2 = Effect.fn("PluginLoader.load")(function* (target, origin, options
|
|
|
9073
9310
|
* are one package, and `./plugins/x.ts` is the file it resolves to from the directory that
|
|
9074
9311
|
* declared it. Pure -- nothing is installed, imported or read.
|
|
9075
9312
|
*/
|
|
9076
|
-
const canonical = (reference, hostDir) => Effect.map(parse$
|
|
9313
|
+
const canonical = (reference, hostDir) => Effect.map(parse$2(reference, hostDir), canonical$1);
|
|
9077
9314
|
//#endregion
|
|
9078
9315
|
//#region src/plugin/catalog.ts
|
|
9079
9316
|
/**
|
|
@@ -9135,7 +9372,7 @@ const load$1 = Effect.fn("PluginCatalog.load")(function* (references, options) {
|
|
|
9135
9372
|
remember(plugin, []);
|
|
9136
9373
|
continue;
|
|
9137
9374
|
}
|
|
9138
|
-
const target = yield* parse$
|
|
9375
|
+
const target = yield* parse$2(reference, options.hostDir);
|
|
9139
9376
|
const key = target.kind === "local" ? target.path : target.spec;
|
|
9140
9377
|
const already = seen.get(key);
|
|
9141
9378
|
if (already !== void 0) {
|
|
@@ -11337,7 +11574,7 @@ const layer = (options = {}) => Layer.unwrap(Effect.gen(function* () {
|
|
|
11337
11574
|
* `hostDir` led to; only the process view falls back to `hostCwd`.
|
|
11338
11575
|
*/
|
|
11339
11576
|
const hostDirOf = (root) => root ?? hostCwd;
|
|
11340
|
-
const filed = (reference, from) => parse$
|
|
11577
|
+
const filed = (reference, from) => parse$2(reference, from).pipe(Effect.flatMap((target) => target.kind === "local" ? fileSystem.exists(target.path).pipe(Effect.map((there) => there ? Option.some({}) : Option.none())) : resolve$2(target, paths.cache, from).pipe(Effect.map((entry) => Option.fromUndefinedOr(entry)))), Effect.orElseSucceed(() => Option.none()));
|
|
11341
11578
|
const resolveOnly = {
|
|
11342
11579
|
...catalogOptions,
|
|
11343
11580
|
install: required
|
|
@@ -11727,7 +11964,7 @@ var plugin_exports = /* @__PURE__ */ __exportAll({
|
|
|
11727
11964
|
inspect: () => inspect,
|
|
11728
11965
|
lendResolve: () => lendResolve,
|
|
11729
11966
|
localName: () => localName,
|
|
11730
|
-
parse: () => parse$
|
|
11967
|
+
parse: () => parse$2,
|
|
11731
11968
|
probe: () => probe,
|
|
11732
11969
|
resolve: () => resolve$2,
|
|
11733
11970
|
resolveCached: () => required,
|