@dot-skill/core 0.4.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 +21 -0
- package/dist/compile.d.ts +52 -0
- package/dist/compile.js +588 -0
- package/dist/hash.d.ts +8 -0
- package/dist/hash.js +52 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +8 -0
- package/dist/migrate.d.ts +8 -0
- package/dist/migrate.js +116 -0
- package/dist/mint.d.ts +37 -0
- package/dist/mint.js +250 -0
- package/dist/pack.d.ts +20 -0
- package/dist/pack.js +191 -0
- package/dist/paths.d.ts +5 -0
- package/dist/paths.js +22 -0
- package/dist/validate.d.ts +32 -0
- package/dist/validate.js +215 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bharat Dudeja
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CompletenessPart, CompletenessReport, CompilationReport, GenerationUsage, Recipe, SkillCompileProfile, SkillPackageFiles, SkillSource } from "@dot-skill/protocol";
|
|
2
|
+
/** Scrub likely secrets from text before packaging. */
|
|
3
|
+
export declare function redactSecrets(text: string): string;
|
|
4
|
+
export declare class CompileRefusalError extends Error {
|
|
5
|
+
readonly kind: "compile_refused";
|
|
6
|
+
readonly profile: SkillCompileProfile;
|
|
7
|
+
readonly missing: CompletenessPart[];
|
|
8
|
+
readonly hints: string[];
|
|
9
|
+
readonly completeness: CompletenessReport;
|
|
10
|
+
constructor(report: CompletenessReport);
|
|
11
|
+
}
|
|
12
|
+
export interface CompileOptions {
|
|
13
|
+
skill_id?: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
provenance_mode?: "full" | "redacted" | "proof_only";
|
|
18
|
+
profile?: SkillCompileProfile;
|
|
19
|
+
/** When true, inferred inputs are marked approved (human already reviewed). */
|
|
20
|
+
approve_inferred_inputs?: boolean;
|
|
21
|
+
approve_permissions?: boolean;
|
|
22
|
+
generation_usage?: GenerationUsage;
|
|
23
|
+
/**
|
|
24
|
+
* Continuity may emit partial packages.
|
|
25
|
+
* Release refuses unless complete — set true only in tests that assert refusal.
|
|
26
|
+
*/
|
|
27
|
+
allow_incomplete?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface CompileResult {
|
|
30
|
+
files: SkillPackageFiles;
|
|
31
|
+
report: CompilationReport;
|
|
32
|
+
packageBytes: Uint8Array;
|
|
33
|
+
pending_approvals: string[];
|
|
34
|
+
completeness: CompletenessReport;
|
|
35
|
+
}
|
|
36
|
+
export declare function assessCompleteness(source: SkillSource, opts: {
|
|
37
|
+
profile: SkillCompileProfile;
|
|
38
|
+
hasWorkflowAction: boolean;
|
|
39
|
+
hasKnowledge: boolean;
|
|
40
|
+
hasInputsDeclared: boolean;
|
|
41
|
+
pendingApprovals: string[];
|
|
42
|
+
}): CompletenessReport;
|
|
43
|
+
export declare function compileSkillSource(source: SkillSource, opts?: CompileOptions): CompileResult;
|
|
44
|
+
/** Skillerr / legacy adapter entry — converts Recipe then compiles. */
|
|
45
|
+
export declare function compileRecipeToSkill(recipe: Recipe, opts?: CompileOptions & {
|
|
46
|
+
host?: string;
|
|
47
|
+
model?: string;
|
|
48
|
+
}): CompileResult;
|
|
49
|
+
export declare function approveCompilation(result: CompileResult, approvals: {
|
|
50
|
+
inputs?: string[];
|
|
51
|
+
permissions?: boolean;
|
|
52
|
+
}): CompileResult;
|
package/dist/compile.js
ADDED
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { DEFAULT_SKILL_POLICY, CONTAINER_VERSION, PROTOCOL_VERSION, WORKFLOW_DIALECT_VERSION, isValidAgentHost, recipeToSkillSource, } from "@dot-skill/protocol";
|
|
3
|
+
import { packSkill, finalizeManifest, buildFileMap } from "./pack.js";
|
|
4
|
+
const PLACEHOLDER_RE = /\{\{([a-zA-Z_][a-zA-Z0-9_]*)\}\}|<([A-Z][A-Z0-9_]+)>|\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;
|
|
5
|
+
const SECRET_PATTERNS = [
|
|
6
|
+
/\b(?:sk|pk|api)[_-][A-Za-z0-9]{8,}\b/g,
|
|
7
|
+
/\bBearer\s+[A-Za-z0-9\-._~+/]+=*/gi,
|
|
8
|
+
/\b[A-Za-z0-9+/]{40,}={0,2}\b/g,
|
|
9
|
+
];
|
|
10
|
+
const GENERALIZABLE_PATTERNS = [
|
|
11
|
+
{
|
|
12
|
+
re: /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi,
|
|
13
|
+
name: "email",
|
|
14
|
+
reason: "Email addresses vary per deployment",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
re: /\bhttps?:\/\/[^\s)]+/gi,
|
|
18
|
+
name: "base_url",
|
|
19
|
+
reason: "Service URLs are environment-specific",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
re: /\b(?:sk|pk|api)[_-][A-Za-z0-9]{8,}\b/g,
|
|
23
|
+
name: "api_credential_ref",
|
|
24
|
+
reason: "Credentials must be secret refs, never embedded",
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
function shortId(prefix) {
|
|
28
|
+
return `${prefix}_${createHash("sha256").update(randomUUID()).digest("hex").slice(0, 12)}`;
|
|
29
|
+
}
|
|
30
|
+
function knowledgeTypeFor(section) {
|
|
31
|
+
switch (section.type) {
|
|
32
|
+
case "decision":
|
|
33
|
+
return "decision";
|
|
34
|
+
case "tradeoff":
|
|
35
|
+
return "tradeoff";
|
|
36
|
+
case "lesson":
|
|
37
|
+
return "lesson";
|
|
38
|
+
case "correction_note":
|
|
39
|
+
return "correction";
|
|
40
|
+
case "requirement":
|
|
41
|
+
case "intent":
|
|
42
|
+
return "constraint";
|
|
43
|
+
case "reference":
|
|
44
|
+
case "resource":
|
|
45
|
+
case "doc":
|
|
46
|
+
return "reference";
|
|
47
|
+
default:
|
|
48
|
+
return "rule";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function slug(name) {
|
|
52
|
+
return (name
|
|
53
|
+
.toLowerCase()
|
|
54
|
+
.replace(/[^a-z0-9]+/g, "_")
|
|
55
|
+
.replace(/^_|_$/g, "")
|
|
56
|
+
.slice(0, 40) || "value");
|
|
57
|
+
}
|
|
58
|
+
/** Scrub likely secrets from text before packaging. */
|
|
59
|
+
export function redactSecrets(text) {
|
|
60
|
+
let out = text;
|
|
61
|
+
for (const re of SECRET_PATTERNS) {
|
|
62
|
+
re.lastIndex = 0;
|
|
63
|
+
out = out.replace(re, "{{secret_ref}}");
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
export class CompileRefusalError extends Error {
|
|
68
|
+
kind = "compile_refused";
|
|
69
|
+
profile;
|
|
70
|
+
missing;
|
|
71
|
+
hints;
|
|
72
|
+
completeness;
|
|
73
|
+
constructor(report) {
|
|
74
|
+
super(`compile_refused (${report.profile}): missing [${report.missing.join(", ")}]. ${report.hints.join(" ")}`);
|
|
75
|
+
this.name = "CompileRefusalError";
|
|
76
|
+
this.profile = report.profile;
|
|
77
|
+
this.missing = report.missing;
|
|
78
|
+
this.hints = report.hints;
|
|
79
|
+
this.completeness = report;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const HINTS = {
|
|
83
|
+
agent_context: "Set SKILL_HOST to an AI host (cursor, ollama, lmstudio, llama-cpp, custom-agent, …). This is asserted provenance, not cryptographic proof.",
|
|
84
|
+
intent: "Add an intent/summary section describing what this skill is for.",
|
|
85
|
+
sections: "Agent must propose at least one section (decision, integration, workflow, …).",
|
|
86
|
+
workflow: "Need actionable workflow content (integration, prompt, implementation, or workflow_note).",
|
|
87
|
+
knowledge_or_prompts: "Need knowledge sections or prompt templates — not an empty package.",
|
|
88
|
+
inputs_declared: "Declare typed inputs or set SkillSource.inputs_declared='none'. Placeholders like {{base_url}} become inputs.",
|
|
89
|
+
journey: "Provide a redacted journey summary of the human+AI work (no raw chat, no secrets).",
|
|
90
|
+
generation_usage: "Optional but recommended: report token usage used to create this skill.",
|
|
91
|
+
human_approvals: "Human must approve inferred inputs/permissions before release mint.",
|
|
92
|
+
};
|
|
93
|
+
export function assessCompleteness(source, opts) {
|
|
94
|
+
const present = [];
|
|
95
|
+
const missing = [];
|
|
96
|
+
const check = (part, ok) => {
|
|
97
|
+
if (ok)
|
|
98
|
+
present.push(part);
|
|
99
|
+
else
|
|
100
|
+
missing.push(part);
|
|
101
|
+
};
|
|
102
|
+
check("agent_context", isValidAgentHost(source.agent.host));
|
|
103
|
+
check("intent", Boolean((source.intent ?? source.summary ?? source.title)?.trim().length));
|
|
104
|
+
check("sections", source.sections.length >= 1);
|
|
105
|
+
check("knowledge_or_prompts", opts.hasKnowledge || source.prompts.length > 0);
|
|
106
|
+
check("workflow", opts.hasWorkflowAction);
|
|
107
|
+
check("inputs_declared", opts.hasInputsDeclared);
|
|
108
|
+
check("journey", Boolean(source.journey?.summary?.trim()) && source.journey.redacted !== false);
|
|
109
|
+
if (source.generation_usage?.total_tokens || source.generation_usage?.input_tokens) {
|
|
110
|
+
present.push("generation_usage");
|
|
111
|
+
}
|
|
112
|
+
if (opts.profile === "release") {
|
|
113
|
+
check("human_approvals", opts.pendingApprovals.length === 0);
|
|
114
|
+
// generation_usage recommended but not hard-required for release
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// continuity: drop soft requirements from missing
|
|
118
|
+
const soft = new Set([
|
|
119
|
+
"workflow",
|
|
120
|
+
"inputs_declared",
|
|
121
|
+
"human_approvals",
|
|
122
|
+
"generation_usage",
|
|
123
|
+
]);
|
|
124
|
+
for (let i = missing.length - 1; i >= 0; i--) {
|
|
125
|
+
if (soft.has(missing[i]))
|
|
126
|
+
missing.splice(i, 1);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const requiredMissing = opts.profile === "continuity"
|
|
130
|
+
? missing.filter((m) => ["agent_context", "sections", "intent", "journey", "knowledge_or_prompts"].includes(m))
|
|
131
|
+
: missing.filter((m) => m !== "generation_usage");
|
|
132
|
+
return {
|
|
133
|
+
kind: "completeness_report",
|
|
134
|
+
profile: opts.profile,
|
|
135
|
+
complete: requiredMissing.length === 0,
|
|
136
|
+
present,
|
|
137
|
+
missing: requiredMissing,
|
|
138
|
+
hints: requiredMissing.map((m) => HINTS[m]),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function sectionHasWorkflowAction(sections) {
|
|
142
|
+
return sections.some((s) => ["integration", "prompt", "implementation_note", "workflow_note", "code", "config"].includes(s.type));
|
|
143
|
+
}
|
|
144
|
+
export function compileSkillSource(source, opts = {}) {
|
|
145
|
+
const profile = opts.profile ?? "release";
|
|
146
|
+
const skillId = opts.skill_id ?? shortId("skl");
|
|
147
|
+
const version = opts.version ?? "1.0.0";
|
|
148
|
+
const issues = [];
|
|
149
|
+
const mappings = [];
|
|
150
|
+
const knowledge = [];
|
|
151
|
+
const steps = [];
|
|
152
|
+
const inferredInputs = [];
|
|
153
|
+
const inputNames = new Set();
|
|
154
|
+
const constraints = [];
|
|
155
|
+
if (!isValidAgentHost(source.agent.host)) {
|
|
156
|
+
const completeness = assessCompleteness(source, {
|
|
157
|
+
profile,
|
|
158
|
+
hasWorkflowAction: false,
|
|
159
|
+
hasKnowledge: false,
|
|
160
|
+
hasInputsDeclared: true,
|
|
161
|
+
pendingApprovals: ["agent_context"],
|
|
162
|
+
});
|
|
163
|
+
completeness.missing = ["agent_context"];
|
|
164
|
+
completeness.complete = false;
|
|
165
|
+
completeness.hints = [HINTS.agent_context];
|
|
166
|
+
throw new CompileRefusalError(completeness);
|
|
167
|
+
}
|
|
168
|
+
const addInput = (slot) => {
|
|
169
|
+
if (inputNames.has(slot.name)) {
|
|
170
|
+
const existing = inferredInputs.find((i) => i.name === slot.name);
|
|
171
|
+
if (existing && slot.sensitivity === "secret") {
|
|
172
|
+
existing.sensitivity = "secret";
|
|
173
|
+
existing.source = "secret";
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
inputNames.add(slot.name);
|
|
178
|
+
inferredInputs.push(slot);
|
|
179
|
+
};
|
|
180
|
+
for (const section of source.sections) {
|
|
181
|
+
let body = redactSecrets(section.body);
|
|
182
|
+
PLACEHOLDER_RE.lastIndex = 0;
|
|
183
|
+
let m;
|
|
184
|
+
while ((m = PLACEHOLDER_RE.exec(section.body))) {
|
|
185
|
+
const rawName = m[1] || m[2] || m[3] || "value";
|
|
186
|
+
const name = slug(rawName);
|
|
187
|
+
const isSecret = /secret|credential|token|password|key/i.test(name);
|
|
188
|
+
addInput({
|
|
189
|
+
name,
|
|
190
|
+
schema: { type: "string" },
|
|
191
|
+
description: `Value for ${name} generalized from section ${section.title}`,
|
|
192
|
+
source: isSecret ? "secret" : "human",
|
|
193
|
+
required: true,
|
|
194
|
+
sensitivity: isSecret ? "secret" : "private",
|
|
195
|
+
ask_when: "if_missing",
|
|
196
|
+
provenance: [{ kind: "section", id: section.id, revision: section.revision }],
|
|
197
|
+
generalization_reason: "Explicit placeholder in approved text",
|
|
198
|
+
approved: opts.approve_inferred_inputs === true,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
for (const pat of GENERALIZABLE_PATTERNS) {
|
|
202
|
+
pat.re.lastIndex = 0;
|
|
203
|
+
if (pat.re.test(section.body)) {
|
|
204
|
+
const name = pat.name;
|
|
205
|
+
addInput({
|
|
206
|
+
name,
|
|
207
|
+
schema: { type: "string" },
|
|
208
|
+
description: pat.reason,
|
|
209
|
+
source: name.includes("credential") ? "secret" : "human",
|
|
210
|
+
required: true,
|
|
211
|
+
sensitivity: name.includes("credential") ? "secret" : "private",
|
|
212
|
+
ask_when: "if_missing",
|
|
213
|
+
provenance: [{ kind: "section", id: section.id, revision: section.revision }],
|
|
214
|
+
generalization_reason: pat.reason,
|
|
215
|
+
approved: opts.approve_inferred_inputs === true,
|
|
216
|
+
});
|
|
217
|
+
if (name.includes("credential")) {
|
|
218
|
+
body = body.replace(pat.re, "{{api_credential_ref}}");
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const kid = `k_${section.id.replace(/[^a-zA-Z0-9]/g, "").slice(0, 16)}`;
|
|
223
|
+
const item = {
|
|
224
|
+
kind: "knowledge",
|
|
225
|
+
id: kid,
|
|
226
|
+
type: knowledgeTypeFor(section),
|
|
227
|
+
title: section.title,
|
|
228
|
+
body,
|
|
229
|
+
fidelity: "exact",
|
|
230
|
+
pinned: true,
|
|
231
|
+
sensitivity: section.sensitivity === "public" ? "public" : "private",
|
|
232
|
+
provenance: [
|
|
233
|
+
{ kind: "section", id: section.id, revision: section.revision, hash: source.hash },
|
|
234
|
+
],
|
|
235
|
+
};
|
|
236
|
+
knowledge.push(item);
|
|
237
|
+
mappings.push({
|
|
238
|
+
from: { kind: "section", id: section.id, revision: section.revision },
|
|
239
|
+
to: { kind: "knowledge", id: kid },
|
|
240
|
+
});
|
|
241
|
+
if (section.type === "prompt") {
|
|
242
|
+
const stepId = `s_prompt_${kid}`;
|
|
243
|
+
steps.push({
|
|
244
|
+
id: stepId,
|
|
245
|
+
kind: "prompt",
|
|
246
|
+
title: section.title,
|
|
247
|
+
template: body,
|
|
248
|
+
knowledge_refs: [kid],
|
|
249
|
+
provenance: [{ kind: "section", id: section.id, revision: section.revision }],
|
|
250
|
+
});
|
|
251
|
+
mappings.push({
|
|
252
|
+
from: { kind: "section", id: section.id, revision: section.revision },
|
|
253
|
+
to: { kind: "step", id: stepId },
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
else if (section.type === "integration" ||
|
|
257
|
+
section.type === "implementation_note" ||
|
|
258
|
+
section.type === "workflow_note") {
|
|
259
|
+
const stepId = `s_instruct_${kid}`;
|
|
260
|
+
steps.push({
|
|
261
|
+
id: stepId,
|
|
262
|
+
kind: "instruct",
|
|
263
|
+
title: section.title,
|
|
264
|
+
text: body,
|
|
265
|
+
knowledge_refs: [kid],
|
|
266
|
+
provenance: [{ kind: "section", id: section.id, revision: section.revision }],
|
|
267
|
+
});
|
|
268
|
+
mappings.push({
|
|
269
|
+
from: { kind: "section", id: section.id, revision: section.revision },
|
|
270
|
+
to: { kind: "step", id: stepId },
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
else if (section.type === "question") {
|
|
274
|
+
issues.push({
|
|
275
|
+
severity: "warning",
|
|
276
|
+
code: "unresolved_question",
|
|
277
|
+
message: `Section ${section.title} is a question — may need an input slot or human_decision`,
|
|
278
|
+
related: [section.id],
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
for (const s of source.steering) {
|
|
283
|
+
const cid = `c_${s.id.replace(/[^a-zA-Z0-9]/g, "").slice(0, 16)}`;
|
|
284
|
+
const effect = s.verb === "affirm" ? "invariant" : s.verb === "reject" ? "forbidden" : "decision_rule";
|
|
285
|
+
const statement = s.note?.trim() || `${s.verb} on ${s.target_kind} ${s.target_id}`;
|
|
286
|
+
constraints.push({
|
|
287
|
+
kind: "steering_constraint",
|
|
288
|
+
id: cid,
|
|
289
|
+
verb: s.verb,
|
|
290
|
+
effect,
|
|
291
|
+
statement,
|
|
292
|
+
source_steering_id: s.id,
|
|
293
|
+
targets: [s.target_id],
|
|
294
|
+
provenance: [{ kind: "steering", id: s.id }],
|
|
295
|
+
});
|
|
296
|
+
mappings.push({
|
|
297
|
+
from: { kind: "steering", id: s.id },
|
|
298
|
+
to: { kind: "constraint", id: cid },
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
if (steps.length === 0 && knowledge.length > 0) {
|
|
302
|
+
steps.push({
|
|
303
|
+
id: "s_apply_knowledge",
|
|
304
|
+
kind: "instruct",
|
|
305
|
+
title: "Apply captured knowledge",
|
|
306
|
+
text: "Follow the pinned knowledge items and steering constraints exactly. Ask only for declared inputs. Resume from journey provenance when continuing prior work.",
|
|
307
|
+
knowledge_refs: knowledge.map((k) => k.id),
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
for (let i = 0; i < steps.length - 1; i++) {
|
|
311
|
+
if (!steps[i].next)
|
|
312
|
+
steps[i].next = steps[i + 1].id;
|
|
313
|
+
}
|
|
314
|
+
if (steps.length > 0) {
|
|
315
|
+
const last = steps[steps.length - 1];
|
|
316
|
+
const verifyId = "s_verify";
|
|
317
|
+
const emitId = "s_emit";
|
|
318
|
+
last.next = verifyId;
|
|
319
|
+
steps.push({
|
|
320
|
+
id: verifyId,
|
|
321
|
+
kind: "verify",
|
|
322
|
+
title: "Verify constraints",
|
|
323
|
+
assertions: [
|
|
324
|
+
"all_required_inputs_resolved",
|
|
325
|
+
...constraints
|
|
326
|
+
.filter((c) => c.effect === "invariant")
|
|
327
|
+
.map((c) => `constraint_present:${c.id}`),
|
|
328
|
+
],
|
|
329
|
+
next: emitId,
|
|
330
|
+
});
|
|
331
|
+
steps.push({
|
|
332
|
+
id: emitId,
|
|
333
|
+
kind: "emit",
|
|
334
|
+
title: "Emit result",
|
|
335
|
+
output: "result",
|
|
336
|
+
from: last.id,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
const pending = [];
|
|
340
|
+
for (const slot of inferredInputs) {
|
|
341
|
+
if (!slot.approved)
|
|
342
|
+
pending.push(`input:${slot.name}`);
|
|
343
|
+
mappings.push({
|
|
344
|
+
from: slot.provenance?.[0] ?? { kind: "author", id: "compiler" },
|
|
345
|
+
to: { kind: "input", id: slot.name },
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
const needsCodeWrite = source.sections.some((i) => i.type === "code");
|
|
349
|
+
const permissions = needsCodeWrite
|
|
350
|
+
? [
|
|
351
|
+
{
|
|
352
|
+
side_effect_class: "write",
|
|
353
|
+
description: "May modify project files when applying code knowledge",
|
|
354
|
+
requires_consent: true,
|
|
355
|
+
},
|
|
356
|
+
]
|
|
357
|
+
: [];
|
|
358
|
+
if (needsCodeWrite && !opts.approve_permissions) {
|
|
359
|
+
pending.push("permission:write");
|
|
360
|
+
issues.push({
|
|
361
|
+
severity: "warning",
|
|
362
|
+
code: "permission_approval",
|
|
363
|
+
message: "Write permission inferred from code sections — requires human approval",
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
// Explicit "no inputs" declaration when none inferred
|
|
367
|
+
const hasInputsDeclared = inferredInputs.length > 0 || source.inputs_declared === "none";
|
|
368
|
+
const safeJourney = {
|
|
369
|
+
...source.journey,
|
|
370
|
+
summary: redactSecrets(source.journey.summary),
|
|
371
|
+
open_questions: source.journey.open_questions?.map(redactSecrets),
|
|
372
|
+
decisions: source.journey.decisions?.map(redactSecrets),
|
|
373
|
+
redacted: true,
|
|
374
|
+
};
|
|
375
|
+
const usage = opts.generation_usage ?? source.generation_usage;
|
|
376
|
+
const completeness = assessCompleteness(source, {
|
|
377
|
+
profile,
|
|
378
|
+
hasWorkflowAction: sectionHasWorkflowAction(source.sections) || source.prompts.length > 0,
|
|
379
|
+
hasKnowledge: knowledge.length > 0,
|
|
380
|
+
hasInputsDeclared,
|
|
381
|
+
pendingApprovals: pending,
|
|
382
|
+
});
|
|
383
|
+
if (!completeness.complete && !opts.allow_incomplete && profile === "release") {
|
|
384
|
+
throw new CompileRefusalError(completeness);
|
|
385
|
+
}
|
|
386
|
+
if (!completeness.complete && profile === "continuity") {
|
|
387
|
+
// continuity still requires hard parts
|
|
388
|
+
const hard = completeness.missing.filter((m) => ["agent_context", "sections", "intent", "journey", "knowledge_or_prompts"].includes(m));
|
|
389
|
+
if (hard.length && !opts.allow_incomplete) {
|
|
390
|
+
throw new CompileRefusalError({ ...completeness, missing: hard, complete: false });
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (inferredInputs.some((i) => !i.approved)) {
|
|
394
|
+
issues.push({
|
|
395
|
+
severity: "info",
|
|
396
|
+
code: "pending_input_approval",
|
|
397
|
+
message: "Inferred input slots require human approval before release mint",
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
if (!steps.length) {
|
|
401
|
+
// continuity with only questions etc.
|
|
402
|
+
steps.push({
|
|
403
|
+
id: "s_resume",
|
|
404
|
+
kind: "instruct",
|
|
405
|
+
title: "Resume continuity",
|
|
406
|
+
text: source.journey.summary || "Continue from open questions in provenance.",
|
|
407
|
+
knowledge_refs: knowledge.map((k) => k.id),
|
|
408
|
+
});
|
|
409
|
+
steps.push({
|
|
410
|
+
id: "s_emit",
|
|
411
|
+
kind: "emit",
|
|
412
|
+
title: "Emit result",
|
|
413
|
+
output: "result",
|
|
414
|
+
from: "s_resume",
|
|
415
|
+
});
|
|
416
|
+
steps[0].next = "s_emit";
|
|
417
|
+
}
|
|
418
|
+
const entrypoint = steps[0].id;
|
|
419
|
+
const report = {
|
|
420
|
+
kind: "compilation_report",
|
|
421
|
+
skill_id: skillId,
|
|
422
|
+
source_id: source.id,
|
|
423
|
+
recipe_id: source.source_refs?.find((r) => r.kind === "recipe")?.id,
|
|
424
|
+
profile,
|
|
425
|
+
created_at: new Date().toISOString(),
|
|
426
|
+
mappings,
|
|
427
|
+
inferred_inputs: inferredInputs,
|
|
428
|
+
issues,
|
|
429
|
+
pending_approvals: pending,
|
|
430
|
+
approved: pending.length === 0,
|
|
431
|
+
completeness,
|
|
432
|
+
};
|
|
433
|
+
const files = {
|
|
434
|
+
manifest: {
|
|
435
|
+
kind: "dot-skill",
|
|
436
|
+
id: skillId,
|
|
437
|
+
version,
|
|
438
|
+
title: opts.title ?? source.title,
|
|
439
|
+
description: opts.description ??
|
|
440
|
+
source.summary ??
|
|
441
|
+
`Skill compiled from source ${source.id}`,
|
|
442
|
+
intent: source.intent ?? source.summary,
|
|
443
|
+
triggers: [source.title],
|
|
444
|
+
authors: source.actor ? [source.actor] : undefined,
|
|
445
|
+
container_version: CONTAINER_VERSION,
|
|
446
|
+
protocol_version: PROTOCOL_VERSION,
|
|
447
|
+
entrypoint,
|
|
448
|
+
inputs: inferredInputs,
|
|
449
|
+
outputs: [
|
|
450
|
+
{
|
|
451
|
+
name: "result",
|
|
452
|
+
description: "Primary textual or structured result of the skill",
|
|
453
|
+
schema: { type: "string" },
|
|
454
|
+
required: true,
|
|
455
|
+
},
|
|
456
|
+
],
|
|
457
|
+
capabilities: needsCodeWrite
|
|
458
|
+
? [
|
|
459
|
+
{
|
|
460
|
+
name: "filesystem.write",
|
|
461
|
+
description: "Write files in the workspace",
|
|
462
|
+
side_effect_class: "write",
|
|
463
|
+
fallback: "ask_human",
|
|
464
|
+
required: false,
|
|
465
|
+
adapters: [{ kind: "host", name: "workspace" }],
|
|
466
|
+
},
|
|
467
|
+
]
|
|
468
|
+
: [],
|
|
469
|
+
permissions,
|
|
470
|
+
policy: { ...DEFAULT_SKILL_POLICY },
|
|
471
|
+
content: [],
|
|
472
|
+
package_digest: "sha256:" + "0".repeat(64),
|
|
473
|
+
provenance_mode: opts.provenance_mode ?? (profile === "continuity" ? "redacted" : "full"),
|
|
474
|
+
compile_profile: profile,
|
|
475
|
+
completeness,
|
|
476
|
+
package_sensitivity: source.sensitivity,
|
|
477
|
+
mint: { mint_status: "draft" },
|
|
478
|
+
needs_human_review: pending.length > 0 || profile === "continuity",
|
|
479
|
+
},
|
|
480
|
+
workflow: {
|
|
481
|
+
kind: "workflow",
|
|
482
|
+
dialect_version: WORKFLOW_DIALECT_VERSION,
|
|
483
|
+
entrypoint,
|
|
484
|
+
steps,
|
|
485
|
+
constraints,
|
|
486
|
+
},
|
|
487
|
+
knowledge,
|
|
488
|
+
prompts: source.prompts.length
|
|
489
|
+
? Object.fromEntries(source.prompts.map((prompt) => [
|
|
490
|
+
`${prompt.id}.txt`,
|
|
491
|
+
redactSecrets(prompt.body),
|
|
492
|
+
]))
|
|
493
|
+
: undefined,
|
|
494
|
+
provenance: {
|
|
495
|
+
source: opts.provenance_mode === "proof_only"
|
|
496
|
+
? undefined
|
|
497
|
+
: {
|
|
498
|
+
id: source.id,
|
|
499
|
+
hash: source.hash,
|
|
500
|
+
title: source.title,
|
|
501
|
+
agent: {
|
|
502
|
+
...source.agent,
|
|
503
|
+
endpoint: source.agent.endpoint
|
|
504
|
+
? redactSecrets(source.agent.endpoint)
|
|
505
|
+
: undefined,
|
|
506
|
+
},
|
|
507
|
+
sensitivity: source.sensitivity,
|
|
508
|
+
section_ids: source.sections.map((s) => `${s.id}@${s.revision}`),
|
|
509
|
+
source_refs: source.source_refs,
|
|
510
|
+
},
|
|
511
|
+
journey: safeJourney,
|
|
512
|
+
generation_usage: usage,
|
|
513
|
+
proof: {
|
|
514
|
+
source_id: source.id,
|
|
515
|
+
source_hash: source.hash,
|
|
516
|
+
section_ids: source.sections.map((s) => `${s.id}@${s.revision}`),
|
|
517
|
+
agent_host: source.agent.host,
|
|
518
|
+
},
|
|
519
|
+
compilation_report: report,
|
|
520
|
+
},
|
|
521
|
+
};
|
|
522
|
+
const fileMap = buildFileMap(files);
|
|
523
|
+
files.manifest = finalizeManifest(files.manifest, fileMap);
|
|
524
|
+
const packageBytes = packSkill(files);
|
|
525
|
+
return {
|
|
526
|
+
files,
|
|
527
|
+
report,
|
|
528
|
+
packageBytes,
|
|
529
|
+
pending_approvals: pending,
|
|
530
|
+
completeness,
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
/** Skillerr / legacy adapter entry — converts Recipe then compiles. */
|
|
534
|
+
export function compileRecipeToSkill(recipe, opts = {}) {
|
|
535
|
+
const source = recipeToSkillSource(recipe, {
|
|
536
|
+
agent: {
|
|
537
|
+
host: opts.host ?? recipe.provenance.hosts[0],
|
|
538
|
+
model: opts.model ?? recipe.provenance.models[0],
|
|
539
|
+
},
|
|
540
|
+
});
|
|
541
|
+
if (opts.generation_usage)
|
|
542
|
+
source.generation_usage = opts.generation_usage;
|
|
543
|
+
return compileSkillSource(source, opts);
|
|
544
|
+
}
|
|
545
|
+
export function approveCompilation(result, approvals) {
|
|
546
|
+
const files = structuredClone(result.files);
|
|
547
|
+
for (const slot of files.manifest.inputs) {
|
|
548
|
+
if (!approvals.inputs ||
|
|
549
|
+
approvals.inputs.includes(slot.name) ||
|
|
550
|
+
approvals.inputs.includes("*")) {
|
|
551
|
+
slot.approved = true;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
const pending = files.manifest.inputs
|
|
555
|
+
.filter((i) => !i.approved)
|
|
556
|
+
.map((i) => `input:${i.name}`);
|
|
557
|
+
if (files.manifest.permissions.some((p) => p.requires_consent) && !approvals.permissions) {
|
|
558
|
+
pending.push(...files.manifest.permissions
|
|
559
|
+
.filter((p) => p.requires_consent)
|
|
560
|
+
.map((p) => `permission:${p.side_effect_class}`));
|
|
561
|
+
}
|
|
562
|
+
files.manifest.needs_human_review =
|
|
563
|
+
pending.length > 0 || files.manifest.compile_profile === "continuity";
|
|
564
|
+
if (files.provenance?.compilation_report) {
|
|
565
|
+
files.provenance.compilation_report.pending_approvals = pending;
|
|
566
|
+
files.provenance.compilation_report.approved = pending.length === 0;
|
|
567
|
+
files.provenance.compilation_report.inferred_inputs = files.manifest.inputs;
|
|
568
|
+
if (files.provenance.compilation_report.completeness) {
|
|
569
|
+
const c = files.provenance.compilation_report.completeness;
|
|
570
|
+
if (pending.length === 0) {
|
|
571
|
+
c.missing = c.missing.filter((m) => m !== "human_approvals");
|
|
572
|
+
if (!c.present.includes("human_approvals"))
|
|
573
|
+
c.present.push("human_approvals");
|
|
574
|
+
c.complete = c.missing.length === 0;
|
|
575
|
+
}
|
|
576
|
+
files.manifest.completeness = c;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
const fileMap = buildFileMap(files);
|
|
580
|
+
files.manifest = finalizeManifest(files.manifest, fileMap);
|
|
581
|
+
return {
|
|
582
|
+
files,
|
|
583
|
+
report: files.provenance.compilation_report,
|
|
584
|
+
packageBytes: packSkill(files),
|
|
585
|
+
pending_approvals: pending,
|
|
586
|
+
completeness: files.manifest.completeness,
|
|
587
|
+
};
|
|
588
|
+
}
|
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** RFC 8785-inspired JSON Canonicalization for I-JSON-compatible objects. */
|
|
2
|
+
export declare function canonicalize(value: unknown): string;
|
|
3
|
+
export declare function sha256Hex(data: string | Uint8Array): string;
|
|
4
|
+
export declare function sha256Digest(data: string | Uint8Array): string;
|
|
5
|
+
export declare function packageDigestFromContent(content: Array<{
|
|
6
|
+
path: string;
|
|
7
|
+
digest: string;
|
|
8
|
+
}>): string;
|