mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 14:35:17 +01:00
fix(runner): load assigned skills by their granted runtime name (#21445)
## Thinking Path > - Paperclip manages AI agents and their assigned skills. > - Runner copies each assigned skill into a private provider home. > - Paperclip gives company skills a unique runtime name. > - OpenCode reads the name from the skill document. > - The copied document kept the source name, so the assigned name failed to load. > - This change aligns the copied name with the granted name. > - Agents can then find the skill under the name in their assignment. ## Linked Issues or Issue Description **What happened?** OpenCode rejected an assigned review skill name with a generated suffix. It listed the source name instead. The agent made another lookup before the review continued. See the [Braintrust pattern](https://www.braintrust.dev/app/Paperclip/p/Paperclip%20Staging/patterns/27ff1ec9-4579-4ea1-ab6b-caae8d2a833d). **Deployment mode** Local Linux Runner with OpenCode 1.18.34. Staging recovery is not tested. **Expected behavior** The provider discovers each assigned skill under its granted runtime name. **Steps to reproduce** 1. Assign a company skill whose source document has `name: review`. 2. Give it the runtime name `review--abc123`. 3. Copy it into the provider home through `materializeNativeRuntimeSkills`. 4. Run OpenCode skill discovery in that home. Before this fix, it lists `review`. **Paperclip version or commit** The baseline snapshot was inspected at `43bdd773e901391e298415c5d039b2fc6a975bf7`. The current fix includes master `89e65754189a3d73832562cbd28b90edf6ff52b8`. Related-work search found no other repair for this name mismatch. PR #14427 changes gateway hints and does not repair this skill projection. ## What Changed - Align the top-level `name:` value in the disposable provider snapshot before its existing read-only seal. - Keep the admitted source, asset digest, runtime naming, collision checks, and access controls unchanged. - Support CRLF line endings, root mapping indentation, and complete literal or folded name values. - Cover unchanged source, bundled skill bytes, and documents without frontmatter. ## Hypothesis and thesis for a fix **Hypothesis:** Paperclip advertises the granted name, but OpenCode indexes the original frontmatter name. The raw trace and actual local OpenCode discovery confirm the mismatch. **Thesis for a fix:** The shared native skill materializer owns the provider copy. Align its name before sealing the copy. OpenCode, Codex, and ACPX use this boundary. Legacy direct adapters use other paths and are outside this change. Saved source assets carry forward without migration. New provider copies receive the aligned name. No saved session schema or authority contract changes. ## Verification - Added CRLF, literal, and folded regression cases. All three failed on the earlier implementation; the LF case passed. - `pnpm --filter @paperclipai/paperclip-runner exec vitest run src/drivers/runtime-context-skill-name.test.ts src/drivers/runtime-context-materializer.test.ts`: 24 tests pass. - `pnpm --filter @paperclipai/paperclip-runner exec tsc -p tsconfig.json --noEmit`: passes. - Actual installed OpenCode `debug skill --pure`, with an isolated HOME and XDG paths: without alignment it lists `review` and the granted-name assertion fails. With this fix it lists `review--abc123`. The source bytes stay unchanged. - `git diff --check`: passes. - ACPX and Copilot runtime-host suites: 84 tests pass. Total focused checks: 108 tests pass. - `pnpm verify` returned exit 2: the new test is outside the resolved dependency graphs. Required CI supplies broad coverage. - At `72b55119`, Greptile reached 5/5 with no unresolved threads. Typecheck, build, Runner suites and E2E passed. General server shard 9/12 exposed an outdated remote-staging assertion; two other shards were interrupted by runner shutdown. - Updated remote-staging assertions for the granted nested name and unchanged source. Reproduced the old assertion failure locally; all 35 remote-staging tests pass with standard umask 022. The default restrictive mask caused a separate exact-mode assertion failure on the initial local run. - Current head `059e7b26`: aggregate CI verify, typecheck, build, all server/Runner suites, E2E, Canary Dry Run, and Runner support pass. Greptile is 5/5 with all threads resolved; Snyk succeeds. No pending or failed checks. Superagent is neutral after a scan-workflow error, so no security scan pass is claimed. ## Risks The change affects native providers that share this materializer. Existing symlink, overlap, unsafe-name, and read-only controls still apply. The tests check those existing paths. The local proof runs real provider discovery and checks the staged file. It does not run a model or a staging agent task. Staging recovery remains unverified. No merge or deployment is included. ## Model Used OpenAI Codex, GPT-6, with tool use and code execution. Earlier work used Codex; its exact model ID is not retained in the task evidence. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes:` / `Closes:` / `Refs:` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links - [ ] My branch name describes the change and contains no internal ticket id (the existing branch is retained for continuity) - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes (this report describes the internal behavior) - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
c8f363ef47
commit
b4cef7c8c8
3 files changed
+118
-1
No files matched your search
@@ -8,6 +8,7 @@ import {
|
||||
mkdir,
|
||||
open,
|
||||
readdir,
|
||||
readFile,
|
||||
rename,
|
||||
rm,
|
||||
writeFile,
|
||||
@@ -83,6 +84,50 @@ function isWin32ReservedPathSegment(segment: string): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
function yamlNameValue(name: string): string {
|
||||
return /^[A-Za-z0-9._-]+$/u.test(name) ? name : JSON.stringify(name);
|
||||
}
|
||||
|
||||
async function alignSkillRuntimeName(
|
||||
skillRoot: string,
|
||||
runtimeName: string,
|
||||
): Promise<void> {
|
||||
const skillFile = join(skillRoot, "SKILL.md");
|
||||
const markdown = await readFile(skillFile, "utf8").catch(
|
||||
(error: NodeJS.ErrnoException) => {
|
||||
if (error.code === "ENOENT" || error.code === "EISDIR") return null;
|
||||
throw error;
|
||||
},
|
||||
);
|
||||
if (markdown === null) return;
|
||||
const opening = /^---\r?\n/u.exec(markdown);
|
||||
if (!opening) return;
|
||||
const rest = markdown.slice(opening[0].length);
|
||||
const closing = /^---(?:\r?\n|$)/mu.exec(rest);
|
||||
if (!closing) return;
|
||||
const lines = rest.slice(0, closing.index).match(/[^\n]*\n|[^\n]+$/gu) ?? [];
|
||||
const firstField = lines.find((line) => line.trim() && !line.trimStart().startsWith("#"));
|
||||
if (!firstField) return;
|
||||
const indent = firstField.match(/^ */u)![0];
|
||||
const nameIndex = lines.findIndex((line) =>
|
||||
line.startsWith(indent) && /^name[ \t]*:/u.test(line.slice(indent.length)),
|
||||
);
|
||||
if (nameIndex < 0) return;
|
||||
let nameEnd = nameIndex + 1;
|
||||
for (let index = nameEnd; index < lines.length; index += 1) {
|
||||
const line = lines[index]!;
|
||||
if (!line.trim() || line.trimStart().startsWith("#")) continue;
|
||||
if (line.match(/^ */u)![0].length <= indent.length) break;
|
||||
nameEnd = index + 1;
|
||||
}
|
||||
const eol = lines[nameIndex]!.endsWith("\r\n") ? "\r\n" : "\n";
|
||||
lines.splice(nameIndex, nameEnd - nameIndex, `${indent}name: ${yamlNameValue(runtimeName)}${eol}`);
|
||||
const aligned = opening[0] + lines.join("") + rest.slice(closing.index);
|
||||
if (aligned === markdown) return;
|
||||
await chmod(skillFile, 0o644);
|
||||
await writeFile(skillFile, aligned, { mode: 0o644 });
|
||||
}
|
||||
|
||||
function portableRuntimeNameKey(runtimeName: string): string {
|
||||
// Skill assignments must remain unambiguous when the same context is moved
|
||||
// between the case-sensitive Linux runner and the case-insensitive default
|
||||
@@ -271,6 +316,7 @@ export async function materializeNativeRuntimeSkills(
|
||||
verbatimSymlinks: true,
|
||||
});
|
||||
await assertSafeTree(target);
|
||||
await alignSkillRuntimeName(target, skill.runtimeName);
|
||||
await protectStagedTree(target);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
NATIVE_RUNTIME_ASSET_SCHEMA,
|
||||
type NativeRuntimeContextSnapshot,
|
||||
} from "../contracts/runtime-context.js";
|
||||
import {
|
||||
materializeNativeRuntimeSkills,
|
||||
releaseMaterializedNativeRuntimeSkills,
|
||||
} from "./runtime-context-materializer.js";
|
||||
|
||||
const digest = "0".repeat(64);
|
||||
const asset = (rootPath: string) => ({
|
||||
schema: NATIVE_RUNTIME_ASSET_SCHEMA,
|
||||
digest,
|
||||
manifestDigest: digest,
|
||||
rootPath,
|
||||
fileCount: 1,
|
||||
totalBytes: 1,
|
||||
});
|
||||
|
||||
it.each([
|
||||
["indented root", "---\n name: |-\n review\n description: Review work\n metadata:\n name: nested\n---\n# Review\n", "---\n name: review--abc123\n description: Review work\n metadata:\n name: nested\n---\n# Review\n"],
|
||||
["nested name first", "---\nmetadata:\n name: nested\nname: review\ndescription: Review work\n---\n# Review\n", "---\nmetadata:\n name: nested\nname: review--abc123\ndescription: Review work\n---\n# Review\n"],
|
||||
["LF", "---\nname: review\ndescription: Review work\n---\n# Review\n", "---\nname: review--abc123\ndescription: Review work\n---\n# Review\n"],
|
||||
["CRLF", "---\r\nname: review\r\ndescription: Review work\r\n---\r\n# Review\r\n", "---\r\nname: review--abc123\r\ndescription: Review work\r\n---\r\n# Review\r\n"],
|
||||
["literal name", "---\nname: |-\n review\ndescription: Review work\n---\n# Review\n", "---\nname: review--abc123\ndescription: Review work\n---\n# Review\n"],
|
||||
["folded name", "---\nname: >-\n review\ndescription: Review work\n---\n# Review\n", "---\nname: review--abc123\ndescription: Review work\n---\n# Review\n"],
|
||||
])("stages the granted name with %s frontmatter", async (_label, reviewMarkdown, stagedMarkdown) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "paperclip-skill-runtime-name-"));
|
||||
const skillsHome = join(root, "home");
|
||||
try {
|
||||
const review = join(root, "review");
|
||||
const plain = join(root, "plain");
|
||||
const bundled = join(root, "bundled");
|
||||
await Promise.all([mkdir(review), mkdir(plain), mkdir(bundled)]);
|
||||
await writeFile(join(review, "SKILL.md"), reviewMarkdown);
|
||||
await writeFile(join(plain, "SKILL.md"), "# Plain\n");
|
||||
const bundledMarkdown = "---\nname: bundled\ndescription: Built in\nmetadata:\n name: original\n---\n# Bundled\n";
|
||||
await writeFile(join(bundled, "SKILL.md"), bundledMarkdown);
|
||||
const context = {
|
||||
prompt: { revision: "test", text: "Test", digest },
|
||||
instructions: { entryPath: "AGENTS.md", bundle: asset(root) },
|
||||
skills: [
|
||||
{ key: "company/review", runtimeName: "review--abc123", versionId: null, bundle: asset(review) },
|
||||
{ key: "paperclipai/paperclip/bundled", runtimeName: "bundled", versionId: null, bundle: asset(bundled) },
|
||||
{ key: "company/plain", runtimeName: "plain", versionId: null, bundle: asset(plain) },
|
||||
],
|
||||
mcp: { assignmentSetId: "none", digest, bindingId: null },
|
||||
aggregateDigest: digest,
|
||||
} as unknown as NativeRuntimeContextSnapshot;
|
||||
|
||||
await materializeNativeRuntimeSkills(context, skillsHome);
|
||||
|
||||
await expect(readFile(join(skillsHome, "review--abc123", "SKILL.md"), "utf8"))
|
||||
.resolves.toBe(stagedMarkdown);
|
||||
await expect(readFile(join(skillsHome, "plain", "SKILL.md"), "utf8"))
|
||||
.resolves.toBe("# Plain\n");
|
||||
await expect(readFile(join(skillsHome, "bundled", "SKILL.md"), "utf8")).resolves.toBe(bundledMarkdown);
|
||||
await expect(readFile(join(review, "SKILL.md"), "utf8")).resolves.toBe(reviewMarkdown);
|
||||
} finally {
|
||||
await releaseMaterializedNativeRuntimeSkills(skillsHome).catch(() => undefined);
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -241,7 +241,10 @@ describe("remote launch asset staging", () => {
|
||||
await prepareIsolatedCodexHome({ context: f.source, codexHome: join(f.root, "codex-home") });
|
||||
await stageRemoteLaunchAssets(f.input);
|
||||
expect(readFileSync(join(f.remote, "skills", "test", "SKILL.md"), "utf8")).toContain("Use a native confirmation.");
|
||||
expect(readFileSync(join(f.remote, "skills", "group", "nested", "SKILL.md"), "utf8")).toBe(body);
|
||||
expect(readFileSync(join(f.remote, "skills", "group", "nested", "SKILL.md"), "utf8")).toBe(
|
||||
'---\nname: "group/nested"\ndescription: Nested selected skill\n---\nKeep the nested package.\n',
|
||||
);
|
||||
expect(readFileSync(join(nestedRoot, "SKILL.md"), "utf8")).toBe(body);
|
||||
expect(statSync(join(f.remote, "skills", "group", "nested", "SKILL.md")).mode & 0o222).toBe(0);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user