mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 05:47:10 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - An agent's runtime mounts only its own enabled skills; nothing tells
the model what else the company skill library holds
> - From inside a sandbox, "installed but not enabled for me" and "does
not exist" look identical, so agents tell users freshly installed skills
are not installed
> - This pull request renders the library as a deterministic markdown
section appended to claude-local agent instructions, and adds a
paperclipListSkills MCP tool
> - The benefit is that agents report the true state ("installed, not
enabled for me — ask an operator to enable it") instead of a false
negative
## Linked Issues or Issue Description
**What existing behavior does this improve?**
How agents reason about the company skill library at runtime.
**Subsystem affected**
`packages/adapter-utils` (new pure builder),
`packages/adapters/claude-local` (instructions append),
`packages/mcp-server` (new tool).
**Current behavior**
The runtime hands adapters the full library list, but only the agent's
enabled skills are mounted, and no prompt content or MCP tool describes
the rest. Agents inspect their sandbox, find nothing, and report
installed skills as not installed.
**Proposed behavior**
A "Company skill library" markdown section lists every skill as
`enabled`, `installed, not enabled for you`, or `enabled but
unavailable: <cause>`, with instructions to report the not-enabled state
accurately and ask an operator to enable it. claude-local appends it to
the agent instructions text. A `paperclipListSkills` MCP tool exposes
the same list on demand.
**Breaking changes**
None. Other adapters are untouched (they can adopt the builder later);
the manifest is deterministic, so the claude-local prompt-bundle cache
only busts when the library actually changes.
## What Changed
- New `packages/adapter-utils/src/skill-library-manifest.ts` with
`buildSkillLibraryManifestMarkdown` (pure, key-sorted, deterministic;
renders the missing-cause detail from #12146).
- `packages/adapters/claude-local/src/server/execute.ts` appends the
manifest to `combinedInstructionsContents` (creating it when no
instructions file is configured).
- `packages/mcp-server/src/tools.ts` adds `paperclipListSkills` hitting
`GET /companies/:companyId/skills`.
## Verification
- `npx vitest run
packages/adapter-utils/src/skill-library-manifest.test.ts` (from repo
root) — 3 tests: byte-identical output for shuffled input, state
rendering incl. the unavailable cause, change detection.
- `cd packages/mcp-server && npx vitest run` — new tool routing test
passes (13 passed; 1 pre-existing failure on my machine reproduces
unchanged at the branch base).
- `cd packages/adapters/claude-local && npx vitest run` — 244 passed, 1
skipped.
- `pnpm run typecheck` clean in adapter-utils, mcp-server, claude-local.
## Risks
- Prompt growth is one line per installed skill plus a five-line header
— bounded and only present when the library is non-empty. Stacked on
#12146 so the manifest's "enabled but unavailable" state reflects real
materialization failures.
## Model Used
- Claude Fable 5 (`claude-fable-5`, Anthropic) with extended thinking
and tool use, via Claude Code.
## 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 (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [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
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
58 lines
2.6 KiB
TypeScript
58 lines
2.6 KiB
TypeScript
import type { PaperclipSkillEntry } from "./server-utils.js";
|
|
|
|
/**
|
|
* Render the company skill library as a short markdown section for an agent's
|
|
* system context, marking each skill as enabled for this agent, installed but
|
|
* not enabled, or enabled but unavailable (with the failure cause).
|
|
*
|
|
* Why this exists: an agent's runtime only mounts its own desired skills, so
|
|
* from inside a sandbox an installed-but-not-enabled skill is
|
|
* indistinguishable from a skill that does not exist — agents then tell users
|
|
* a freshly installed skill "is not installed". This manifest gives the model
|
|
* the missing distinction without any extra tool call.
|
|
*
|
|
* The output must stay deterministic for identical inputs: claude-local hashes
|
|
* the instructions text into its prompt-bundle cache key, so nondeterministic
|
|
* text would defeat the cache and identical library states must produce
|
|
* byte-identical manifests.
|
|
*/
|
|
/**
|
|
* Flatten untrusted text to a single bounded line before it enters the
|
|
* manifest. Skill keys and missing-source details can embed skill-authored
|
|
* content (a hostile frontmatter name flows into materialization error
|
|
* messages); a newline in either would let a skill append arbitrary
|
|
* instruction lines to the agent's system context.
|
|
*/
|
|
function sanitizeManifestText(value: string, maxLength: number): string {
|
|
return value.replace(/\s+/g, " ").trim().slice(0, maxLength);
|
|
}
|
|
|
|
export function buildSkillLibraryManifestMarkdown(input: {
|
|
entries: readonly PaperclipSkillEntry[];
|
|
desiredSkillKeys: ReadonlySet<string>;
|
|
}): string | null {
|
|
if (input.entries.length === 0) return null;
|
|
const lines = [...input.entries]
|
|
.sort((left, right) => left.key.localeCompare(right.key))
|
|
.map((entry) => {
|
|
const enabled = input.desiredSkillKeys.has(entry.key);
|
|
const key = sanitizeManifestText(entry.key, 200);
|
|
if (enabled && entry.sourceStatus === "missing") {
|
|
const detail = entry.missingDetail ? sanitizeManifestText(entry.missingDetail, 200) : "";
|
|
return `- ${key} — enabled but unavailable${detail ? `: ${detail}` : ""}`;
|
|
}
|
|
return `- ${key} — ${enabled ? "enabled" : "installed, not enabled for you"}`;
|
|
});
|
|
return [
|
|
"## Company skill library",
|
|
"",
|
|
'Skills marked "enabled" are loaded into your runtime. Skills marked',
|
|
'"installed, not enabled for you" exist in this company\'s skill library but',
|
|
"are not attached to you — never report those as not installed; say they",
|
|
"are installed but not enabled for you, and ask an operator to enable them",
|
|
'for you (the skill page\'s "Add to agent" control) when you need one.',
|
|
"",
|
|
...lines,
|
|
].join("\n");
|
|
}
|