@saturn-universe/protocol 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/dist/diagnostic-results.d.ts +57 -0
- package/dist/diagnostic-results.js +54 -0
- package/dist/endpoint.d.ts +11 -0
- package/dist/endpoint.js +73 -0
- package/dist/host-results.d.ts +102 -0
- package/dist/host-results.js +105 -0
- package/dist/host-status.d.ts +181 -0
- package/dist/host-status.js +102 -0
- package/dist/index.d.ts +839 -0
- package/dist/index.js +342 -0
- package/dist/ipc-framing.d.ts +10 -0
- package/dist/ipc-framing.js +29 -0
- package/dist/mcp-config.d.ts +34 -0
- package/dist/mcp-config.js +268 -0
- package/dist/provider-credentials.d.ts +18 -0
- package/dist/provider-credentials.js +140 -0
- package/dist/redaction.d.ts +1 -0
- package/dist/redaction.js +43 -0
- package/dist/run-event-results.d.ts +89 -0
- package/dist/run-event-results.js +107 -0
- package/dist/run-query-result.d.ts +66 -0
- package/dist/run-query-result.js +69 -0
- package/dist/session-results.d.ts +215 -0
- package/dist/session-results.js +174 -0
- package/dist/skills.d.ts +68 -0
- package/dist/skills.js +447 -0
- package/dist/team-results.d.ts +86 -0
- package/dist/team-results.js +61 -0
- package/dist/wire-shapes.d.ts +44 -0
- package/dist/wire-shapes.js +40 -0
- package/package.json +17 -3
- package/README.md +0 -3
package/dist/skills.js
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import { readdir, readFile, realpath, stat } from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { saturnHomeDir } from './provider-credentials.js';
|
|
5
|
+
export const skillNamePattern = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/;
|
|
6
|
+
export function userSkillsDir(env = process.env) {
|
|
7
|
+
return path.join(saturnHomeDir(env), 'skills');
|
|
8
|
+
}
|
|
9
|
+
export function agentsSkillsDir(env = process.env) {
|
|
10
|
+
const customAgents = env.SATURN_AGENTS_HOME?.trim();
|
|
11
|
+
if (customAgents)
|
|
12
|
+
return path.join(path.resolve(customAgents), 'skills');
|
|
13
|
+
const customSaturnHome = env.SATURN_HOME?.trim();
|
|
14
|
+
if (customSaturnHome)
|
|
15
|
+
return path.join(path.dirname(path.resolve(customSaturnHome)), '.agents', 'skills');
|
|
16
|
+
return path.join(os.homedir(), '.agents', 'skills');
|
|
17
|
+
}
|
|
18
|
+
export function projectSkillsDir(workspaceRoot) {
|
|
19
|
+
return path.join(workspaceRoot, '.saturn', 'skills');
|
|
20
|
+
}
|
|
21
|
+
export function projectSkillsDirs(workspaceRoot) {
|
|
22
|
+
return [
|
|
23
|
+
{ dir: projectSkillsDir(workspaceRoot), source: 'project:.saturn/skills' },
|
|
24
|
+
{ dir: path.join(workspaceRoot, '.agents', 'skills'), source: 'project:.agents/skills' },
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
export function localSkillSearchDirectories(workspaceRoot, env = process.env) {
|
|
28
|
+
return [
|
|
29
|
+
...projectSkillsDirs(workspaceRoot).map((directory) => ({ ...directory, scope: 'project' })),
|
|
30
|
+
{ dir: userSkillsDir(env), scope: 'user', source: 'user:.saturn/skills' },
|
|
31
|
+
{ dir: agentsSkillsDir(env), scope: 'user', source: 'user:.agents/skills' },
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
export function isInsideSkillDir(rootDir, targetPath) {
|
|
35
|
+
const rel = path.relative(rootDir, targetPath);
|
|
36
|
+
if (!rel || path.isAbsolute(rel))
|
|
37
|
+
return false;
|
|
38
|
+
return rel !== '..' && !rel.startsWith(`..${path.sep}`) && !rel.startsWith('../');
|
|
39
|
+
}
|
|
40
|
+
export function validateRelativeSkillResourcePath(rawPath) {
|
|
41
|
+
if (typeof rawPath !== 'string' || !rawPath.trim()) {
|
|
42
|
+
return { ok: false, code: 'INVALID_PATH', message: 'Resource path must be a non-empty relative path.' };
|
|
43
|
+
}
|
|
44
|
+
if (rawPath.includes('\0')) {
|
|
45
|
+
return { ok: false, code: 'INVALID_PATH', message: 'Resource path must not contain null bytes.' };
|
|
46
|
+
}
|
|
47
|
+
const trimmed = rawPath.trim();
|
|
48
|
+
if (path.isAbsolute(trimmed) || /^[a-zA-Z]:/.test(trimmed) || trimmed.startsWith('\\\\')) {
|
|
49
|
+
return { ok: false, code: 'PATH_TRAVERSAL_DENIED', message: 'Absolute resource paths are not allowed.' };
|
|
50
|
+
}
|
|
51
|
+
const segments = trimmed.split(/[\\/]+/).filter(Boolean);
|
|
52
|
+
if (!segments.length) {
|
|
53
|
+
return { ok: false, code: 'INVALID_PATH', message: 'Resource path must point to a file.' };
|
|
54
|
+
}
|
|
55
|
+
if (segments.some((segment) => segment === '..' || /^\.env(?:\..*)?$/i.test(segment) || segment === '.git')) {
|
|
56
|
+
return { ok: false, code: 'PATH_TRAVERSAL_DENIED', message: 'Invalid or restricted path segment.' };
|
|
57
|
+
}
|
|
58
|
+
return { ok: true, normalized: segments.join('/') };
|
|
59
|
+
}
|
|
60
|
+
function unquoteYamlScalar(raw) {
|
|
61
|
+
const value = raw.trim();
|
|
62
|
+
if (value.length >= 2 && value.startsWith("'") && value.endsWith("'")) {
|
|
63
|
+
return value.slice(1, -1).replaceAll("''", "'");
|
|
64
|
+
}
|
|
65
|
+
if (value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
|
|
66
|
+
return value.slice(1, -1).replace(/\\(["\\ntr])/g, (_, ch) => {
|
|
67
|
+
if (ch === 'n')
|
|
68
|
+
return '\n';
|
|
69
|
+
if (ch === 't')
|
|
70
|
+
return '\t';
|
|
71
|
+
if (ch === 'r')
|
|
72
|
+
return '\r';
|
|
73
|
+
return ch;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
function splitSkillMarkdown(markdown) {
|
|
79
|
+
const text = markdown.replace(/^\uFEFF/, '');
|
|
80
|
+
const match = /^---[ \t]*\r?\n([\s\S]*?)\r?\n(---|\.\.\.)[ \t]*(\r?\n|$)/.exec(text);
|
|
81
|
+
if (!match)
|
|
82
|
+
return { body: text };
|
|
83
|
+
return {
|
|
84
|
+
body: text.slice(match[0].length),
|
|
85
|
+
frontmatter: {
|
|
86
|
+
lines: match[1].split(/\r?\n/),
|
|
87
|
+
closingDelimiter: match[2],
|
|
88
|
+
closingLineBreak: match[3],
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function parseSkillFrontmatterLines(lines) {
|
|
93
|
+
const result = {};
|
|
94
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
95
|
+
const line = lines[i];
|
|
96
|
+
if (!line.trim() || /^\s*#/.test(line))
|
|
97
|
+
continue;
|
|
98
|
+
const keyMatch = /^([a-zA-Z0-9_-]+)[ \t]*:[ \t]*(.*)$/.exec(line);
|
|
99
|
+
if (!keyMatch)
|
|
100
|
+
continue;
|
|
101
|
+
const key = keyMatch[1];
|
|
102
|
+
const rest = keyMatch[2].trim();
|
|
103
|
+
if (/^[|>][+-]?$/.test(rest)) {
|
|
104
|
+
const folded = rest.startsWith('>');
|
|
105
|
+
const blockLines = [];
|
|
106
|
+
let indent = null;
|
|
107
|
+
while (i + 1 < lines.length) {
|
|
108
|
+
const nextLine = lines[i + 1];
|
|
109
|
+
if (!nextLine.trim()) {
|
|
110
|
+
blockLines.push('');
|
|
111
|
+
i += 1;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const leading = /^([ \t]+)/.exec(nextLine)?.[1]?.length ?? 0;
|
|
115
|
+
if (leading === 0)
|
|
116
|
+
break;
|
|
117
|
+
if (indent === null)
|
|
118
|
+
indent = leading;
|
|
119
|
+
blockLines.push(nextLine.slice(Math.min(indent, leading)));
|
|
120
|
+
i += 1;
|
|
121
|
+
}
|
|
122
|
+
result[key] = (folded ? blockLines.join(' ') : blockLines.join('\n')).trim();
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
result[key] = unquoteYamlScalar(rest);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
export function parseSkillFrontmatter(markdown) {
|
|
131
|
+
return parseSkillFrontmatterLines(splitSkillMarkdown(markdown).frontmatter?.lines ?? []);
|
|
132
|
+
}
|
|
133
|
+
export function rewriteSkillFrontmatterName(markdown, alias) {
|
|
134
|
+
const { body, frontmatter } = splitSkillMarkdown(markdown);
|
|
135
|
+
const eol = markdown.includes('\r\n') ? '\r\n' : '\n';
|
|
136
|
+
const nameLine = `name: ${alias}`;
|
|
137
|
+
if (!frontmatter)
|
|
138
|
+
return `---${eol}${nameLine}${eol}---${eol}${body}`;
|
|
139
|
+
let replaced = false;
|
|
140
|
+
const lines = frontmatter.lines.map((line) => {
|
|
141
|
+
if (!/^name[ \t]*:/.test(line))
|
|
142
|
+
return line;
|
|
143
|
+
replaced = true;
|
|
144
|
+
return nameLine;
|
|
145
|
+
});
|
|
146
|
+
if (!replaced)
|
|
147
|
+
lines.unshift(nameLine);
|
|
148
|
+
return `---${eol}${lines.join(eol)}${eol}${frontmatter.closingDelimiter}${frontmatter.closingLineBreak}${body}`;
|
|
149
|
+
}
|
|
150
|
+
function firstFallbackDescription(body) {
|
|
151
|
+
for (const rawLine of body.split(/\r?\n/)) {
|
|
152
|
+
const line = rawLine.trim();
|
|
153
|
+
if (!line || line.startsWith('#'))
|
|
154
|
+
continue;
|
|
155
|
+
return line;
|
|
156
|
+
}
|
|
157
|
+
return 'Agent skill.';
|
|
158
|
+
}
|
|
159
|
+
function parseSkillMetadata(markdown) {
|
|
160
|
+
const { body, frontmatter: block } = splitSkillMarkdown(markdown);
|
|
161
|
+
const frontmatter = parseSkillFrontmatterLines(block?.lines ?? []);
|
|
162
|
+
const description = (frontmatter.description?.trim() || firstFallbackDescription(body))
|
|
163
|
+
.replace(/\s+/g, ' ')
|
|
164
|
+
.trim();
|
|
165
|
+
return { frontmatter, description };
|
|
166
|
+
}
|
|
167
|
+
async function listSubtreeFiles(skillRootReal, subdirName) {
|
|
168
|
+
const subdirPath = path.join(skillRootReal, subdirName);
|
|
169
|
+
let subdirReal;
|
|
170
|
+
try {
|
|
171
|
+
subdirReal = await realpath(subdirPath);
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
if (!isInsideSkillDir(skillRootReal, subdirReal))
|
|
177
|
+
return [];
|
|
178
|
+
try {
|
|
179
|
+
if (!(await stat(subdirReal)).isDirectory())
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
const collected = [];
|
|
186
|
+
async function walk(currentDir) {
|
|
187
|
+
let entries;
|
|
188
|
+
try {
|
|
189
|
+
entries = await readdir(currentDir, { withFileTypes: true });
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
195
|
+
for (const entry of entries) {
|
|
196
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules')
|
|
197
|
+
continue;
|
|
198
|
+
const candidate = path.join(currentDir, entry.name);
|
|
199
|
+
let candidateReal;
|
|
200
|
+
try {
|
|
201
|
+
candidateReal = await realpath(candidate);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (!isInsideSkillDir(skillRootReal, candidateReal))
|
|
207
|
+
continue;
|
|
208
|
+
let info;
|
|
209
|
+
try {
|
|
210
|
+
info = await stat(candidateReal);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (info.isDirectory()) {
|
|
216
|
+
await walk(candidateReal);
|
|
217
|
+
}
|
|
218
|
+
else if (info.isFile()) {
|
|
219
|
+
const rel = path.relative(skillRootReal, candidate).split(path.sep).join('/');
|
|
220
|
+
collected.push(rel);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
await walk(subdirReal);
|
|
225
|
+
return collected;
|
|
226
|
+
}
|
|
227
|
+
async function listTopLevelSiblingFiles(skillRootReal) {
|
|
228
|
+
let entries;
|
|
229
|
+
try {
|
|
230
|
+
entries = await readdir(skillRootReal, { withFileTypes: true });
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
236
|
+
const siblings = [];
|
|
237
|
+
for (const entry of entries) {
|
|
238
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'SKILL.md') {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const candidate = path.join(skillRootReal, entry.name);
|
|
242
|
+
let candidateReal;
|
|
243
|
+
try {
|
|
244
|
+
candidateReal = await realpath(candidate);
|
|
245
|
+
if (!isInsideSkillDir(skillRootReal, candidateReal))
|
|
246
|
+
continue;
|
|
247
|
+
if (!(await stat(candidateReal)).isFile())
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
siblings.push(entry.name);
|
|
254
|
+
}
|
|
255
|
+
return siblings;
|
|
256
|
+
}
|
|
257
|
+
export async function inspectSkillDirectory(skillDir) {
|
|
258
|
+
const rootRealDir = await realpath(skillDir);
|
|
259
|
+
const dirInfo = await stat(rootRealDir);
|
|
260
|
+
if (!dirInfo.isDirectory()) {
|
|
261
|
+
throw new Error(`Skill path is not a directory: ${skillDir}`);
|
|
262
|
+
}
|
|
263
|
+
const skillMdPath = path.join(rootRealDir, 'SKILL.md');
|
|
264
|
+
const skillMdReal = await realpath(skillMdPath);
|
|
265
|
+
if (!isInsideSkillDir(rootRealDir, skillMdReal)) {
|
|
266
|
+
throw new Error('SKILL.md resolves outside the skill directory.');
|
|
267
|
+
}
|
|
268
|
+
const mdInfo = await stat(skillMdReal);
|
|
269
|
+
if (!mdInfo.isFile()) {
|
|
270
|
+
throw new Error(`Missing SKILL.md in ${skillDir}`);
|
|
271
|
+
}
|
|
272
|
+
const markdown = await readFile(skillMdReal, 'utf8');
|
|
273
|
+
if (markdown.includes('\0')) {
|
|
274
|
+
throw new Error(`SKILL.md contains invalid null bytes in ${skillDir}`);
|
|
275
|
+
}
|
|
276
|
+
const { frontmatter, description } = parseSkillMetadata(markdown);
|
|
277
|
+
const name = frontmatter.name?.trim() || path.basename(skillDir);
|
|
278
|
+
if (!skillNamePattern.test(name)) {
|
|
279
|
+
throw new Error(`Invalid skill name "${name}" in ${skillMdPath}`);
|
|
280
|
+
}
|
|
281
|
+
const siblings = await listTopLevelSiblingFiles(rootRealDir);
|
|
282
|
+
const refs = await listSubtreeFiles(rootRealDir, 'references');
|
|
283
|
+
const scripts = await listSubtreeFiles(rootRealDir, 'scripts');
|
|
284
|
+
return {
|
|
285
|
+
name,
|
|
286
|
+
description,
|
|
287
|
+
rootDir: rootRealDir,
|
|
288
|
+
skillFilePath: skillMdReal,
|
|
289
|
+
resources: [...siblings, ...refs, ...scripts],
|
|
290
|
+
frontmatter,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
async function scanSkillsDirectory(directory) {
|
|
294
|
+
let entries;
|
|
295
|
+
try {
|
|
296
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
return [];
|
|
300
|
+
}
|
|
301
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
302
|
+
const found = [];
|
|
303
|
+
for (const entry of entries) {
|
|
304
|
+
if (entry.name.startsWith('.'))
|
|
305
|
+
continue;
|
|
306
|
+
const candidate = path.join(directory, entry.name);
|
|
307
|
+
try {
|
|
308
|
+
const inspected = await inspectSkillDirectory(candidate);
|
|
309
|
+
const allowedTools = inspected.frontmatter['allowed-tools']?.trim() || inspected.frontmatter.allowed_tools?.trim();
|
|
310
|
+
found.push({
|
|
311
|
+
name: inspected.name,
|
|
312
|
+
description: inspected.description,
|
|
313
|
+
resources: inspected.resources,
|
|
314
|
+
rootDir: inspected.rootDir,
|
|
315
|
+
skillFilePath: inspected.skillFilePath,
|
|
316
|
+
...(inspected.frontmatter.license?.trim() ? { license: inspected.frontmatter.license.trim() } : {}),
|
|
317
|
+
...(inspected.frontmatter.compatibility?.trim()
|
|
318
|
+
? { compatibility: inspected.frontmatter.compatibility.trim() }
|
|
319
|
+
: {}),
|
|
320
|
+
...(allowedTools ? { allowedTools } : {}),
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
// Ignore entries without a valid SKILL.md manifest.
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return found;
|
|
328
|
+
}
|
|
329
|
+
export async function discoverAgentSkills(workspaceRoot, options = {}) {
|
|
330
|
+
const env = options.env ?? process.env;
|
|
331
|
+
const byName = new Map();
|
|
332
|
+
const scannedDirs = new Map();
|
|
333
|
+
const registerFromDir = async (dir, scope, source, indexedBySecurityPlugin, allowedSkills) => {
|
|
334
|
+
let resolvedDir;
|
|
335
|
+
try {
|
|
336
|
+
resolvedDir = await realpath(dir);
|
|
337
|
+
}
|
|
338
|
+
catch {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const dirKey = process.platform === 'win32' ? resolvedDir.toLowerCase() : resolvedDir;
|
|
342
|
+
const previous = scannedDirs.get(dirKey);
|
|
343
|
+
if (previous && !indexedBySecurityPlugin)
|
|
344
|
+
return;
|
|
345
|
+
const candidates = previous ?? (await scanSkillsDirectory(resolvedDir));
|
|
346
|
+
if (!previous)
|
|
347
|
+
scannedDirs.set(dirKey, candidates);
|
|
348
|
+
const allowSet = allowedSkills ? new Set(allowedSkills) : undefined;
|
|
349
|
+
for (const skill of candidates) {
|
|
350
|
+
if (allowSet && !allowSet.has(skill.name) && !allowSet.has(path.basename(skill.rootDir))) {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
const existing = byName.get(skill.name);
|
|
354
|
+
if (!existing) {
|
|
355
|
+
if (!previous) {
|
|
356
|
+
byName.set(skill.name, {
|
|
357
|
+
...skill,
|
|
358
|
+
scope,
|
|
359
|
+
source,
|
|
360
|
+
...(indexedBySecurityPlugin ? { indexedBySecurityPlugin: true } : {}),
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
else if (indexedBySecurityPlugin && !existing.indexedBySecurityPlugin) {
|
|
365
|
+
byName.set(skill.name, { ...existing, indexedBySecurityPlugin: true });
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
// Precedence: 1. Project (.saturn/skills, .agents/skills) > 2. User (~/.saturn/skills, ~/.agents/skills) > 3. Active Mode > 4. Legacy config [skills]
|
|
370
|
+
for (const { dir, scope, source } of localSkillSearchDirectories(workspaceRoot, env)) {
|
|
371
|
+
await registerFromDir(dir, scope, source);
|
|
372
|
+
}
|
|
373
|
+
for (const modeDir of options.modeSkillDirs ?? []) {
|
|
374
|
+
await registerFromDir(modeDir.dir, 'mode', modeDir.source, modeDir.indexedBySecurityPlugin, modeDir.allowedSkills);
|
|
375
|
+
}
|
|
376
|
+
for (const [ref, entry] of Object.entries(options.explicitSkills ?? {}).sort(([a], [b]) => a.localeCompare(b))) {
|
|
377
|
+
const skillName = ref.split('@')[0];
|
|
378
|
+
if (byName.has(skillName))
|
|
379
|
+
continue;
|
|
380
|
+
try {
|
|
381
|
+
const workspaceReal = await realpath(workspaceRoot);
|
|
382
|
+
const manifestPath = path.resolve(workspaceRoot, entry.path);
|
|
383
|
+
const manifestReal = await realpath(manifestPath);
|
|
384
|
+
if (!isInsideSkillDir(workspaceReal, manifestReal))
|
|
385
|
+
continue;
|
|
386
|
+
if (path.basename(manifestReal) !== 'SKILL.md')
|
|
387
|
+
continue;
|
|
388
|
+
const rootDir = path.dirname(manifestReal);
|
|
389
|
+
const markdown = await readFile(manifestReal, 'utf8');
|
|
390
|
+
const { description } = parseSkillMetadata(markdown);
|
|
391
|
+
byName.set(skillName, {
|
|
392
|
+
name: skillName,
|
|
393
|
+
description,
|
|
394
|
+
scope: 'config',
|
|
395
|
+
source: `config:${ref}`,
|
|
396
|
+
ref,
|
|
397
|
+
resources: [...(entry.resources ?? [])],
|
|
398
|
+
rootDir,
|
|
399
|
+
skillFilePath: manifestReal,
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
// Skip invalid or missing legacy skill manifest during discovery.
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
407
|
+
}
|
|
408
|
+
function escapeXmlText(value) {
|
|
409
|
+
return String(value ?? '')
|
|
410
|
+
.replaceAll('&', '&')
|
|
411
|
+
.replaceAll('<', '<')
|
|
412
|
+
.replaceAll('>', '>')
|
|
413
|
+
.replace(/\s+/g, ' ')
|
|
414
|
+
.trim();
|
|
415
|
+
}
|
|
416
|
+
export function formatCompactSkillIndex(skills, options = {}) {
|
|
417
|
+
if (!skills.length)
|
|
418
|
+
return '';
|
|
419
|
+
const maxTotalChars = options.maxTotalChars ?? 4000;
|
|
420
|
+
const maxDescriptionChars = options.maxDescriptionChars ?? 200;
|
|
421
|
+
const header = [
|
|
422
|
+
'<available_skills>',
|
|
423
|
+
'Available agent skills (progressive disclosure: call `skill` with `action="load"` and `skill="<name>"` to load full instructions, or `action="list"` / `action="read_resource"` for sibling references/scripts):',
|
|
424
|
+
];
|
|
425
|
+
const footer = '</available_skills>';
|
|
426
|
+
const lines = [...header];
|
|
427
|
+
let totalChars = header.join('\n').length + footer.length + 2;
|
|
428
|
+
let included = 0;
|
|
429
|
+
for (const item of skills) {
|
|
430
|
+
const rawDesc = escapeXmlText(item.description);
|
|
431
|
+
const desc = rawDesc.length > maxDescriptionChars
|
|
432
|
+
? `${rawDesc.slice(0, Math.max(1, maxDescriptionChars - 1)).trimEnd()}…`
|
|
433
|
+
: rawDesc;
|
|
434
|
+
const line = `- ${escapeXmlText(item.name)} [${item.scope}]: ${desc}`;
|
|
435
|
+
const reserveNotice = included < skills.length - 1 ? 80 : 0;
|
|
436
|
+
if (totalChars + line.length + 1 + reserveNotice > maxTotalChars && included > 0) {
|
|
437
|
+
const remaining = skills.length - included;
|
|
438
|
+
lines.push(`- ... (+${remaining} more skills; call skill(action="list") to inspect all)`);
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
lines.push(line);
|
|
442
|
+
totalChars += line.length + 1;
|
|
443
|
+
included += 1;
|
|
444
|
+
}
|
|
445
|
+
lines.push(footer);
|
|
446
|
+
return lines.join('\n');
|
|
447
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { HostCommand, Id, TeamState } from '@saturn-universe/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { Assert, Equal, Wire } from './wire-shapes.js';
|
|
4
|
+
export type TeamQueryResult = Pick<TeamState, 'runId' | 'concurrency' | 'members' | 'tasks'> & Partial<Pick<TeamState, 'inbox' | 'plan'>> & {
|
|
5
|
+
readonly sessionId?: string | undefined;
|
|
6
|
+
};
|
|
7
|
+
export type TeamInboxResult = Pick<TeamState, 'runId' | 'inbox'>;
|
|
8
|
+
declare const teamInbox: z.ZodObject<{
|
|
9
|
+
runId: z.ZodPipe<z.ZodString, z.ZodTransform<Id<"run">, string>>;
|
|
10
|
+
inbox: z.ZodArray<z.ZodObject<{
|
|
11
|
+
messageId: z.ZodString;
|
|
12
|
+
from: z.ZodString;
|
|
13
|
+
to: z.ZodString;
|
|
14
|
+
text: z.ZodString;
|
|
15
|
+
sentAt: z.ZodString;
|
|
16
|
+
readAt: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, z.core.$strip>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
declare const teamQuery: z.ZodObject<{
|
|
20
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
21
|
+
concurrency: z.ZodNumber;
|
|
22
|
+
members: z.ZodArray<z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
parent: z.ZodNullable<z.ZodString>;
|
|
25
|
+
agentSessionId: z.ZodPipe<z.ZodString, z.ZodTransform<Id<"agent-session">, string>>;
|
|
26
|
+
turnId: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<Id<"turn">, string>>>;
|
|
27
|
+
status: z.ZodEnum<{
|
|
28
|
+
completed: "completed";
|
|
29
|
+
waiting: "waiting";
|
|
30
|
+
queued: "queued";
|
|
31
|
+
running: "running";
|
|
32
|
+
paused: "paused";
|
|
33
|
+
failed: "failed";
|
|
34
|
+
interrupted: "interrupted";
|
|
35
|
+
}>;
|
|
36
|
+
}, z.core.$strip>>;
|
|
37
|
+
tasks: z.ZodArray<z.ZodObject<{
|
|
38
|
+
memberId: z.ZodString;
|
|
39
|
+
task: z.ZodString;
|
|
40
|
+
turnId: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<Id<"turn">, string>>>;
|
|
41
|
+
status: z.ZodEnum<{
|
|
42
|
+
completed: "completed";
|
|
43
|
+
waiting: "waiting";
|
|
44
|
+
queued: "queued";
|
|
45
|
+
running: "running";
|
|
46
|
+
paused: "paused";
|
|
47
|
+
failed: "failed";
|
|
48
|
+
interrupted: "interrupted";
|
|
49
|
+
}>;
|
|
50
|
+
resultMessageId: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<Id<"message">, string>>>;
|
|
51
|
+
}, z.core.$strip>>;
|
|
52
|
+
plan: z.ZodOptional<z.ZodObject<{
|
|
53
|
+
plannerAgentSessionId: z.ZodPipe<z.ZodString, z.ZodTransform<Id<"agent-session">, string>>;
|
|
54
|
+
decision: z.ZodEnum<{
|
|
55
|
+
single: "single";
|
|
56
|
+
team: "team";
|
|
57
|
+
}>;
|
|
58
|
+
reason: z.ZodString;
|
|
59
|
+
summary: z.ZodOptional<z.ZodString>;
|
|
60
|
+
fallback: z.ZodOptional<z.ZodBoolean>;
|
|
61
|
+
evidence: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
62
|
+
executionSteps: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
63
|
+
verificationCriteria: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
64
|
+
plannedAt: z.ZodString;
|
|
65
|
+
}, z.core.$strip>>;
|
|
66
|
+
runId: z.ZodPipe<z.ZodString, z.ZodTransform<Id<"run">, string>>;
|
|
67
|
+
inbox: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
68
|
+
messageId: z.ZodString;
|
|
69
|
+
from: z.ZodString;
|
|
70
|
+
to: z.ZodString;
|
|
71
|
+
text: z.ZodString;
|
|
72
|
+
sentAt: z.ZodString;
|
|
73
|
+
readAt: z.ZodOptional<z.ZodString>;
|
|
74
|
+
}, z.core.$strip>>>;
|
|
75
|
+
}, z.core.$strip>;
|
|
76
|
+
export declare function validTeamQueryResult(command: Extract<HostCommand, {
|
|
77
|
+
type: 'team.query';
|
|
78
|
+
}>, value: unknown): boolean;
|
|
79
|
+
export declare function validTeamInboxResult(command: Extract<HostCommand, {
|
|
80
|
+
type: 'team.inbox';
|
|
81
|
+
}>, value: unknown): boolean;
|
|
82
|
+
export type TeamResultSchemasMatchContracts = [
|
|
83
|
+
Assert<Equal<Wire<z.output<typeof teamQuery>>, Wire<TeamQueryResult>>>,
|
|
84
|
+
Assert<Equal<Wire<z.output<typeof teamInbox>>, Wire<TeamInboxResult>>>
|
|
85
|
+
];
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { turnStatuses } from '@saturn-universe/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
const id = z.string().min(1);
|
|
4
|
+
const brandedId = () => id.transform((value) => value);
|
|
5
|
+
const runId = brandedId();
|
|
6
|
+
const workStatus = z.enum(['waiting', ...turnStatuses]);
|
|
7
|
+
const member = z.object({
|
|
8
|
+
id,
|
|
9
|
+
parent: id.nullable(),
|
|
10
|
+
agentSessionId: brandedId(),
|
|
11
|
+
turnId: brandedId().optional(),
|
|
12
|
+
status: workStatus,
|
|
13
|
+
});
|
|
14
|
+
const task = z.object({
|
|
15
|
+
memberId: id,
|
|
16
|
+
task: z.string(),
|
|
17
|
+
turnId: brandedId().optional(),
|
|
18
|
+
status: workStatus,
|
|
19
|
+
resultMessageId: brandedId().optional(),
|
|
20
|
+
});
|
|
21
|
+
const message = z.object({
|
|
22
|
+
messageId: id,
|
|
23
|
+
from: id,
|
|
24
|
+
to: id,
|
|
25
|
+
text: z.string(),
|
|
26
|
+
sentAt: z.string(),
|
|
27
|
+
readAt: z.string().optional(),
|
|
28
|
+
});
|
|
29
|
+
const plan = z.object({
|
|
30
|
+
plannerAgentSessionId: brandedId(),
|
|
31
|
+
decision: z.enum(['single', 'team']),
|
|
32
|
+
reason: z.string(),
|
|
33
|
+
summary: z.string().optional(),
|
|
34
|
+
fallback: z.boolean().optional(),
|
|
35
|
+
evidence: z.array(z.string()).optional(),
|
|
36
|
+
executionSteps: z.array(z.string()).optional(),
|
|
37
|
+
verificationCriteria: z.array(z.string()).optional(),
|
|
38
|
+
plannedAt: z.string(),
|
|
39
|
+
});
|
|
40
|
+
const teamInbox = z.object({ runId, inbox: z.array(message) });
|
|
41
|
+
const teamQuery = z.object({
|
|
42
|
+
...teamInbox.partial({ inbox: true }).shape,
|
|
43
|
+
sessionId: id.optional(),
|
|
44
|
+
concurrency: z.number().int().positive(),
|
|
45
|
+
members: z.array(member),
|
|
46
|
+
tasks: z.array(task),
|
|
47
|
+
plan: plan.optional(),
|
|
48
|
+
});
|
|
49
|
+
export function validTeamQueryResult(command, value) {
|
|
50
|
+
const result = teamQuery.safeParse(value);
|
|
51
|
+
if (!result.success || result.data.runId !== command.runId)
|
|
52
|
+
return false;
|
|
53
|
+
const { members } = result.data;
|
|
54
|
+
return new Set(members.map(({ id }) => id)).size === members.length;
|
|
55
|
+
}
|
|
56
|
+
export function validTeamInboxResult(command, value) {
|
|
57
|
+
const result = teamInbox.safeParse(value);
|
|
58
|
+
return (result.success &&
|
|
59
|
+
result.data.runId === command.runId &&
|
|
60
|
+
(command.memberId === undefined || result.data.inbox.every(({ to }) => to === command.memberId)));
|
|
61
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { EventPosition, ModelPricing, RunStopDetails } from '@saturn-universe/core';
|
|
3
|
+
export declare const runResultIdentity: {
|
|
4
|
+
runId: z.ZodString;
|
|
5
|
+
status: z.ZodString;
|
|
6
|
+
};
|
|
7
|
+
export declare const eventPositionSchema: z.ZodPipe<z.ZodCustom<string, string>, z.ZodTransform<EventPosition, string>>;
|
|
8
|
+
export declare const runStopDetailsSchema: z.ZodObject<{
|
|
9
|
+
pauseReason: z.ZodOptional<z.ZodString>;
|
|
10
|
+
pluginBlock: z.ZodOptional<z.ZodObject<{
|
|
11
|
+
code: z.ZodString;
|
|
12
|
+
message: z.ZodString;
|
|
13
|
+
}, z.core.$strip>>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export type RunStopDetailsSchemaMatchesCore = Assert<Equal<Wire<z.output<typeof runStopDetailsSchema>>, Wire<RunStopDetails>>>;
|
|
16
|
+
export declare const approvalIdentity: {
|
|
17
|
+
approvalId: z.ZodString;
|
|
18
|
+
toolCallId: z.ZodString;
|
|
19
|
+
};
|
|
20
|
+
export declare const approvalSummary: {
|
|
21
|
+
approvalId: z.ZodString;
|
|
22
|
+
resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
|
|
23
|
+
reason: z.ZodString;
|
|
24
|
+
};
|
|
25
|
+
export declare function toolApprovalIdentitiesAreUnique(targets: readonly {
|
|
26
|
+
readonly toolCallId: string;
|
|
27
|
+
readonly approvalId?: string | undefined;
|
|
28
|
+
}[]): boolean;
|
|
29
|
+
export declare const modelDisplaySchema: z.ZodObject<{
|
|
30
|
+
modelId: z.ZodString;
|
|
31
|
+
reasoningEffort: z.ZodOptional<z.ZodString>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
export type ModelDisplay = Readonly<Wire<z.output<typeof modelDisplaySchema>>>;
|
|
34
|
+
export declare const modelPricingSchema: z.ZodObject<{
|
|
35
|
+
inputPerMillion: z.ZodNumber;
|
|
36
|
+
cachedInputPerMillion: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
outputPerMillion: z.ZodNumber;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
export type ModelPricingSchemaMatchesContract = Assert<Equal<Wire<z.output<typeof modelPricingSchema>>, Wire<ModelPricing>>>;
|
|
40
|
+
export type Wire<T> = T extends string ? T : T extends readonly (infer V)[] ? Wire<V>[] : T extends object ? {
|
|
41
|
+
-readonly [K in keyof T]: Wire<Exclude<T[K], undefined>>;
|
|
42
|
+
} : T;
|
|
43
|
+
export type Assert<T extends true> = T;
|
|
44
|
+
export type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isEventPosition } from '@saturn-universe/core';
|
|
3
|
+
export const runResultIdentity = { runId: z.string().min(1), status: z.string().min(1) };
|
|
4
|
+
export const eventPositionSchema = z
|
|
5
|
+
.custom(isEventPosition)
|
|
6
|
+
.transform((value) => value);
|
|
7
|
+
export const runStopDetailsSchema = z.object({
|
|
8
|
+
pauseReason: z.string().optional(),
|
|
9
|
+
pluginBlock: z.object({ code: z.string(), message: z.string() }).optional(),
|
|
10
|
+
});
|
|
11
|
+
export const approvalIdentity = {
|
|
12
|
+
approvalId: z.string().min(1),
|
|
13
|
+
toolCallId: z.string().min(1),
|
|
14
|
+
};
|
|
15
|
+
export const approvalSummary = {
|
|
16
|
+
approvalId: approvalIdentity.approvalId,
|
|
17
|
+
resources: z.array(z.string()).readonly(),
|
|
18
|
+
reason: z.string(),
|
|
19
|
+
};
|
|
20
|
+
export function toolApprovalIdentitiesAreUnique(targets) {
|
|
21
|
+
const calls = new Set();
|
|
22
|
+
const approvals = new Set();
|
|
23
|
+
for (const { toolCallId, approvalId } of targets) {
|
|
24
|
+
if (calls.has(toolCallId) || (approvalId !== undefined && approvals.has(approvalId)))
|
|
25
|
+
return false;
|
|
26
|
+
calls.add(toolCallId);
|
|
27
|
+
if (approvalId !== undefined)
|
|
28
|
+
approvals.add(approvalId);
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
export const modelDisplaySchema = z.object({
|
|
33
|
+
modelId: z.string(),
|
|
34
|
+
reasoningEffort: z.string().optional(),
|
|
35
|
+
});
|
|
36
|
+
export const modelPricingSchema = z.object({
|
|
37
|
+
inputPerMillion: z.number(),
|
|
38
|
+
cachedInputPerMillion: z.number().optional(),
|
|
39
|
+
outputPerMillion: z.number(),
|
|
40
|
+
});
|