Files
PaperClipAI/ui/storybook/fixtures/githubSkillSources.ts
T
Dotta a9830414c7 Preserve repository dependencies when importing GitHub skills (#15731)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Its Skills library imports reusable instructions from GitHub.
> - Some skills depend on shared files and sibling skills outside their
folders.
> - Directory-only imports lose those dependencies.
> - This pull request keeps repository files together and lets users
select which skills appear in the library.
> - Agents receive the original files and paths through the existing
skill delivery system.

## Linked Issues or Issue Description

Refs #14713. Related: #13656.

**Current behavior**

GitHub imports copy independent skill directories. Shared scripts,
policies, helper skills, and credit files can be omitted. One
shared-file error can block every skill.

**Proposed behavior**

New imports keep repository files together at the scanned commit. Show
all skills with their folders and select every skill by default.
Collapse individual package files. Omit unsupported or oversized files
with a warning. Import available content without repair choices or an
extra confirmation. Keep warnings on the saved source.

**Reason and benefit**

Skills can read their shared repository files after Paperclip delivers
them to an agent. Original instructions stay unchanged. Users can
inspect included files and understand omissions before and after import.

## What Changed

- Store immutable company-scoped repository snapshots and associate them
with skill versions. Regenerate the migration after merging master.
- Preserve original bytes, binary encoding, and executable modes.
Shared-file changes version each usable selected skill. Pinned versions
retain their original files.
- Deliver a discovery wrapper with the original tree under
`.paperclip-repository/`. Preserve invocation policy when present. Fork
and create-from-existing retain repository files.
- Keep repository files together for new UI imports. Show every skill,
select all by default, and collapse package files. Remove the
packaging-mode menu. Keep the mobile import footer visible.
- Warn about symlinks, submodules, oversized files, missing references,
and invalid optional manifests. A malformed skill remains selected with
a Needs setup warning. Usable skills still publish, and its original
file remains repository support content. Source warnings persist through
refresh. Unsafe execution and secret-disclosure findings omit the
affected files before snapshot publication.
- Expose saved repository files in the installed skill viewer, including
binary encoding and executable flags. Reads use the immutable
company-scoped snapshot; relative instruction links resolve from their
original repository directory.
- Audit delivered inventories and derive trust from all repository
files. Accept evaluation prose while retaining dynamic-execution
findings. Read blobs in one bounded Git batch and check budgets before
reading support files. Imports never execute setup commands.
- Add scanner, database, delivery, UI, and browser regressions. Update
Storybooks, screenshots, and documentation.

## Verification

- 69 focused scanner, Git snapshot, delivery, and PostgreSQL lifecycle
tests passed. They cover partial imports, warning persistence, missing
references, binary files, executable modes, copies, pinned versions,
cancellation, company isolation, and batched Git reads.
- 110 import, skill-detail, selection-tree, saved-file link, and
Markdown renderer tests passed. A file-switch regression failed before
the resolver fix and passed afterward. Browser walkthroughs cover the
all-selected open tree, repository preview, non-blocking warnings,
missing references, setup problems, warning persistence, and mobile
layout.
- Full workspace typecheck and build passed. Runner E2E TypeScript
checks and design-token gates passed. The full serial local suite was
attempted and stopped after over an hour. The existing 40,000-file Git
streaming stress test failed after 303 seconds on macOS; the broad local
suite is not counted as passed. All 55 applicable PR checks passed on
the final commit, including the full sharded CI suite. Two optional
Storybook workflows were skipped; the five local Storybook walkthroughs
passed.
- On October 12, live campaigns imported the private Poteto repository
through the production GitHub Sources UI, selected architect and bro,
and invoked them with native Codex on local and Daytona. The source
connection was disabled before invocation. Independent filesystem
inspections matched every supported Git blob, size, and executable mode.
Both tasks completed and cleanup passed. Campaigns:
`local-2026-10-12T15-07-39-504Z` (both environments),
`local-2026-10-12T16-08-39-682Z` (local), and
`local-2026-10-12T16-03-33-938Z` (Daytona). Each of the two selected
skills received all 234 supported repository files. Later changes only
affect the installed-file viewer and documentation. This qualifies skill
delivery and instruction reads, not every Poteto workflow or adapter.
- A manual source-checkout test drive imported a synthetic private
GitHub repository with a symlink, an oversized file, a missing
reference, and malformed skill metadata. Available skills published with
their shared checklist. The walkthrough found duplicate warning text
after import; the final UI fix removes that duplicate. The file viewer
exposes saved repository dependencies and resolves authored relative
links without changing the instructions. A follow-up live refresh
omitted unsafe helper files with warnings, preserved every safe file
byte, and survived a server restart.

Screenshots below use the production UI with Storybook fixtures. They do
not replace the live GitHub and runtime checks.

<details>
<summary>All skills visible and selected by default</summary>

![Default repository
import](https://github.com/paperclipai/paperclip/blob/codex/skill-repository-packages/docs/pr-screenshots/pr-15731/repository-import.png?raw=true)

</details>

<details>
<summary>Import stays available with warnings</summary>

![Import
warnings](https://github.com/paperclipai/paperclip/blob/codex/skill-repository-packages/docs/pr-screenshots/pr-15731/repository-warning-details.png?raw=true)

</details>

<details>
<summary>Repository file inspector</summary>

![Repository
files](https://github.com/paperclipai/paperclip/blob/codex/skill-repository-packages/docs/pr-screenshots/pr-15731/repository-files.png?raw=true)

</details>

<details>
<summary>Mobile import</summary>

![Mobile
import](https://github.com/paperclipai/paperclip/blob/codex/skill-repository-packages/docs/pr-screenshots/pr-15731/repository-mobile.png?raw=true)

</details>

## Risks

- Each selected skill carries a repository copy in the runtime. The
database stores each snapshot once. Runtime transfer and storage
increase with the number of assigned skills.
- Runtime budgets remain: 9,990 repository entries, 1 MiB per file, and
61 MiB total. File omissions are recorded as warnings. Source-access or
download failures retain installed versions.
- Import success does not prove that every skill can run. Environment
dependencies, credentials, delegation tools, and schedules still need
configuration. Imported setup scripts are not executed.
- Live runtime coverage is native Codex on local and Daytona. Other
adapters use the shared delivery path but were not exercised in these
campaigns.

The roadmap marks Skills Manager as shipped. This extends the existing
importer. Related pull requests were checked.

## Model Used

OpenAI Codex, based on GPT-6, with repository inspection, code
execution, automated tests, and browser tools. The exact deployment
identifier and context-window size were not exposed in this session.

## 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
- [ ] 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
- [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
2026-10-12 11:30:20 -05:00

300 lines
24 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { parseGitHubSkillRepositoryUrl } from "@paperclipai/shared";
import type { AgentDesiredSkillEntry, CompanySkillDetail, CompanySkillListItem, CompanySkillVersion, CompanySkill, SkillSource, SkillPackageInspection, SkillSourceCandidate, SkillSourceEntry, SkillSourceRefreshResult, SkillRepositoryPackage } from "@paperclipai/shared";
import { companySkillsApi } from "@/api/companySkills";
import { agentsApi } from "@/api/agents";
import { foldersApi } from "@/api/folders";
import { storybookAgents } from "./paperclipData";
import { skillSourcesApi } from "@/api/skillSources";
export const COMPANY_ID = "company-storybook";
export const SOURCE_ID = "source-team-skills";
export const COMMIT = "a17d36c9e4521f06b932ac670854d1293f24bc18";
const fixtureSkillId = (entryId: string) => `00000000-0000-4000-8000-${entryId.replace('entry-', '').padStart(12, '0')}`;
const packageContents: Record<string, Record<string, string | null>> = {
'SKILL.md': { 'SKILL.md': '---\nname: Team handbook\ndescription: Shared team conventions\n---\nRead [team conventions](references/conventions.md) before starting.\n', 'references/conventions.md': '# Team conventions\n\nKeep changes company-scoped. Report evidence with each review.\n', 'LICENSE': 'Example license text' },
'.agents/skills/review/SKILL.md': { 'SKILL.md': '---\nname: Code review\ndescription: Review code changes\ncompatibility: Requires Python 3.11 and git.\n---\nRead [the checklist](references/checklist.md). Run `scripts/review.py` when a diff is ready.\n', 'references/checklist.md': '# Review checklist\n\n- Check company boundaries.\n- Test failure handling.\n- Verify migrations.\n', 'scripts/review.py': '#!/usr/bin/env python3\nprint("Ready to review the diff")\n', 'assets/diagram.png': null, 'LICENSE': 'Example license text' },
'.agents/skills/review/security/SKILL.md': { 'SKILL.md': '---\nname: Security review\ndescription: Review authentication boundaries\ncompatibility: Requires Python 3.11.\n---\nRead [policy](../../shared/policy.md) and [threat model](references/threat-model.md).\n', 'scripts/check.py': '#!/usr/bin/env python3\nprint("Check company boundaries")\n', 'references/checklist.md': '# Security checklist\n\n- Validate caller access.\n- Preserve company boundaries.\n' },
'skills/research/SKILL.md': { 'SKILL.md': '---\nname: Research\ndescription: Gather primary sources\n---\nRead [method](references/method.md).\n', 'references/method.md': '# Research method\n\nStart with primary sources.\n' },
'experimental/deploy/SKILL.md': { 'SKILL.md': '---\nname: Deploy preview\n---\nDeploy the app.', 'README.md': '# Deployment notes' },
};
function inspection(skillPath: string): SkillPackageInspection {
return {
commitSha: COMMIT,
files: Object.entries(packageContents[skillPath]!).map(([path, content]) => ({ path, kind: path === 'SKILL.md' ? 'skill' : path.startsWith('scripts/') ? 'script' : path.startsWith('assets/') ? 'asset' : 'reference', encoding: content === null ? 'base64' : 'utf8', sizeBytes: content === null ? 2048 : new TextEncoder().encode(content).length, executable: path.startsWith('scripts/') })),
requirements: skillPath.includes('/security/') ? 'Requires Python 3.11.' : skillPath.includes('/review/') ? 'Requires Python 3.11 and git.' : null,
references: skillPath.includes('/security/') ? [
{ fromPath: 'SKILL.md', target: '../../shared/policy.md', resolvedPath: '.agents/skills/shared/policy.md', kind: 'outside_package' },
{ fromPath: 'SKILL.md', target: 'references/threat-model.md', resolvedPath: '.agents/skills/review/security/references/threat-model.md', kind: 'missing' },
] : [],
warnings: skillPath.includes('/review/') ? ['Skill includes a script file.'] : [],
};
}
export const candidates: SkillSourceCandidate[] = [
{ path: "SKILL.md", name: "Team handbook", description: "Shared conventions and context for every agent.", error: null },
{ path: ".agents/skills/review/SKILL.md", name: "Code review", description: "Review changes for correctness and maintainability.", error: null },
{ path: ".agents/skills/review/security/SKILL.md", name: "Security review", description: "Inspect authentication and company boundaries.", error: null },
{ path: "skills/research/SKILL.md", name: "Research", description: "Gather primary sources and write a concise brief.", error: null },
{ path: "experimental/deploy/SKILL.md", name: "Deploy preview", description: null, error: "Missing required description in SKILL.md frontmatter." },
].map(candidate => ({ ...candidate, inspection: inspection(candidate.path), fileCount: Object.keys(packageContents[candidate.path]!).length, warnings: [] }));
export const repositoryContents: Record<string, string | null> = Object.fromEntries(
Object.entries(packageContents).filter(([root]) => !root.startsWith('experimental/')).flatMap(([root, files]) =>
Object.entries(files).map(([file, content]) => [root.replace(/SKILL.md$/, '') + file, content])),
);
Object.assign(repositoryContents, {
'.agents/skills/shared/policy.md': '# Shared policy\n\nCheck company boundaries before changing access.',
'.agents/skills/review/security/references/threat-model.md': '# Threat model\n\nReview caller authorization.',
'NOTICE.md': 'Example upstream credits are preserved with this repository.',
'paperclip.skills.json': JSON.stringify({ version: 1, skills: ['.agents/skills/review/SKILL.md', 'skills/research/SKILL.md'], requirements: 'Python 3.11 and Git. Configure GitHub access for agents that review pull requests.' }, null, 2),
});
export type PackageScenario = 'ready' | 'warnings' | 'missing' | 'setup';
export function repositoryFixture(scenario: PackageScenario = 'ready'): SkillRepositoryPackage {
const contents = Object.entries(scenario === 'setup' ? { ...repositoryContents, 'experimental/deploy/SKILL.md': packageContents['experimental/deploy/SKILL.md']!['SKILL.md']!, 'experimental/deploy/README.md': '# Deployment notes' } : repositoryContents).filter(([path]) => scenario !== 'missing' || path !== '.agents/skills/review/security/references/threat-model.md');
return { files: contents.map(([path, content]) => ({ path, kind: path.endsWith('SKILL.md') ? 'skill' : path.endsWith('.py') ? 'script' : content === null ? 'asset' : 'reference', encoding: content === null ? 'base64' : 'utf8', sizeBytes: content?.length ?? 2048, executable: path.endsWith('.py') })),
skillPaths: ['.agents/skills/review/SKILL.md', 'skills/research/SKILL.md'], requirements: 'Python 3.11 and Git. Configure GitHub access for agents that review pull requests.',
error: null, warnings: scenario === 'warnings' ? ['shared/tools — Submodule couldn’t be included.', 'assets/demo.mov — Exceeds the 1 MB file limit; not included.'] : [] };
}
export function repositoryCandidates(scenario: PackageScenario = 'ready'): SkillSourceCandidate[] {
return candidates.filter(candidate => scenario === 'setup' || !candidate.error).map(candidate => ({ ...candidate,
inspection: candidate.inspection ? { ...candidate.inspection, references: scenario === 'missing' && candidate.path.includes('/security/') ? candidate.inspection.references.filter(reference => reference.kind === 'missing') : [] } : undefined }));
}
export function sourceFixture(): SkillSource {
return {
id: SOURCE_ID, companyId: COMPANY_ID, repositoryId: "123456",
repositoryUrl: "https://github.com/acme/team-skills", fullName: "acme/team-skills",
trackingRef: "main", connectionId: "github-storybook", excludedFolders: ["experimental"],
enabled: true, revision: 1, lastAttemptAt: new Date(), lastSuccessAt: new Date(),
lastScanCommit: COMMIT, lastError: null,
entries: candidates.map((candidate, index) => ({
id: `entry-${index}`, sourceId: SOURCE_ID, path: candidate.path, name: candidate.name,
description: candidate.description, inspection: candidate.inspection, error: candidate.error, present: true,
skillId: index < 2 ? fixtureSkillId(`entry-${index}`) : null,
selection: index < 2 ? "selected" : index === 4 ? "excluded" : "new",
})),
};
}
export function importedSkill(source: SkillSource, entry: SkillSourceEntry): CompanySkill {
return {
id: entry.skillId!, companyId: COMPANY_ID, key: `github/${source.id}/${entry.path}`,
slug: entry.name.toLowerCase().replaceAll(" ", "-"), name: entry.name, description: entry.description,
markdown: `---\nname: ${entry.name}\ndescription: ${entry.description}\n---\n\n# ${entry.name}\n\n${entry.description}\n\n## Workflow\n\n1. Read the task and the relevant project context.\n2. Follow the checklist in references/checklist.md.\n3. Report findings with evidence and clear next steps.\n`, sourceType: "github", sourceLocator: source.repositoryUrl, sourceRef: COMMIT,
trustLevel: source.packageMode === "repository" || entry.inspection?.files.some(file => file.kind === "script" || file.executable) ? "scripts_executables" : "markdown_only", compatibility: "compatible", fileInventory: [{ path: "SKILL.md", kind: "skill" }, { path: "references/checklist.md", kind: "reference" }],
iconUrl: null, color: null, tagline: null, authorName: null, homepageUrl: null,
categories: [], sharingScope: "company", publicShareToken: null, forkedFromSkillId: null,
forkedFromCompanyId: null, starCount: 0, installCount: 0, forkCount: 0,
currentVersionId: `version-${entry.id}`, metadata: { skillSourceId: source.id, skillSourcePath: entry.path, skillSourceState: "synced" }, createdAt: new Date(), updatedAt: new Date(),
};
}
export type RepositoryScenario = 'single' | 'multiple' | 'none' | 'empty' | 'partial-error' | 'error' | 'loading';
/** Scoped API fixtures keep the production page interactive without contacting GitHub. */
export function installFixtures(empty: boolean, needsConnection: boolean, options: { packageScenario?: PackageScenario; journey?: boolean; refreshed?: boolean; assigned?: boolean; repositories?: RepositoryScenario; scan?: "live" | "large" | "interrupted"; saving?: boolean } = {}) {
const fixtureController = new AbortController();
const wait = (ms: number, signal = fixtureController.signal) => new Promise<void>((resolve, reject) => {
signal.throwIfAborted();
const stop = () => { clearTimeout(timer); reject(new DOMException('Scan cancelled', 'AbortError')); };
const timer = setTimeout(() => { signal.removeEventListener('abort', stop); resolve(); }, ms);
signal.addEventListener('abort', stop, { once: true });
});
const original = { ...skillSourcesApi };
const sources = empty ? [] : [sourceFixture()];
const originalSkills = { ...companySkillsApi };
const originalAgents = { ...agentsApi };
const originalFolders = { ...foldersApi };
const discoveryCandidates = options.packageScenario ? repositoryCandidates() : options.journey ? candidates.filter(candidate => !candidate.path.includes('/security/')) : candidates;
const assigned = new Map<string, AgentDesiredSkillEntry[]>();
const demoAgents = storybookAgents.slice(0, 3).map(agent => ({ ...agent, adapterType: 'codex_local' }));
if (options.journey && sources[0]) {
sources[0].entries = sources[0].entries.filter(entry => options.refreshed || !entry.path.includes('/security/')).map(entry => ({
...entry,
skillId: entry.error || entry.path.includes('/security/') ? null : fixtureSkillId(entry.id),
selection: entry.error ? 'excluded' : entry.path.includes('/security/') ? 'new' : 'selected',
}));
}
const sourceSkills = () => sources.flatMap(source => source.entries.filter(entry => entry.skillId).map(entry => importedSkill(source, entry)));
if (options.assigned && demoAgents[0]) {
const review = sourceSkills().find(skill => skill.slug === 'code-review');
if (review) assigned.set(demoAgents[0].id, [{ key: review.key, versionId: null }]);
}
function detail(id: string): CompanySkillDetail {
const skill = sourceSkills().find(skill => skill.id === id);
if (!skill) throw new Error('This skill is not installed in the preview.');
const usedByAgents = demoAgents.filter(agent => assigned.get(agent.id)?.some(entry => entry.key === skill.key)).map(agent => ({
id: agent.id, name: agent.name, urlKey: agent.urlKey, adapterType: agent.adapterType,
desired: true, actualState: null, versionId: assigned.get(agent.id)?.find(entry => entry.key === skill.key)?.versionId ?? null,
}));
return { ...skill, attachedAgentCount: usedByAgents.length, usedByAgents, existingForks: [], editable: false,
editableReason: 'This skill is synced from GitHub. Make a copy to edit it.', sourceLabel: 'GitHub', sourceBadge: 'github',
sourcePath: String(skill.metadata?.skillSourcePath), currentVersion: version(skill), starredByCurrentActor: false };
}
function version(skill: CompanySkill): CompanySkillVersion {
return { id: skill.currentVersionId!, companyId: COMPANY_ID, companySkillId: skill.id, revisionNumber: 1,
label: null, releaseId: null, releaseName: null, releasedAt: null, authorAgentId: null, authorUserId: 'user-board', createdAt: skill.createdAt,
fileInventory: [{ path: 'SKILL.md', kind: 'skill', content: skill.markdown }, { path: 'references/checklist.md', kind: 'reference', content: '# Checklist\n\n- Check company boundaries.\n- Verify failure handling.\n- Include evidence in the review.' }],
};
}
if (options.journey) {
companySkillsApi.list = async () => sourceSkills().map(skill => ({ ...detail(skill.id), catalogKind: null, originHash: null, packageName: null, packageVersion: null } satisfies CompanySkillListItem));
companySkillsApi.detail = async (_companyId, id) => detail(id);
companySkillsApi.categories = async () => [];
companySkillsApi.catalogList = async () => [];
companySkillsApi.versions = async (_companyId, id) => [version(detail(id))];
companySkillsApi.file = async (_companyId, id, path) => ({ skillId: id, path, kind: path === 'SKILL.md' ? 'skill' : 'reference',
content: version(detail(id)).fileInventory.find(file => file.path === path)?.content ?? '', language: 'markdown', markdown: true, editable: false });
companySkillsApi.updateStatus = async () => ({ supported: true, reason: null, trackingRef: 'main', currentRef: COMMIT, latestRef: COMMIT,
hasUpdate: false, installedHash: null, originHash: null, userModifiedAt: null, updateHoldReason: null, auditVerdict: null, auditCodes: [] });
companySkillsApi.comments = async () => [];
companySkillsApi.testInputs = async () => [];
companySkillsApi.testRuns = async () => [];
companySkillsApi.testRunTemplates = async () => [];
companySkillsApi.forkPrecheck = async (_companyId, id) => {
const skill = detail(id);
return { skillId: id, original: { id, name: skill.name, slug: skill.slug, sourceType: skill.sourceType, sourceLocator: skill.sourceLocator, sourceRef: skill.sourceRef }, agentUsageCount: skill.attachedAgentCount, usedByAgents: skill.usedByAgents, existingForks: [] };
};
foldersApi.list = async () => ({ kind: 'skill', folders: [], allCount: sourceSkills().length, unfiledCount: sourceSkills().length });
agentsApi.list = async () => structuredClone(demoAgents);
agentsApi.skills = async id => ({ adapterType: 'codex_local', supported: true, mode: 'persistent', desiredSkills: (assigned.get(id) ?? []).map(entry => entry.key), desiredSkillEntries: assigned.get(id) ?? [], entries: [], warnings: [] });
agentsApi.syncSkills = async (id, entries) => {
assigned.set(id, entries.map(entry => typeof entry === 'string' ? { key: entry, versionId: null } : entry));
return agentsApi.skills(id);
};
}
if (needsConnection && sources[0]) sources[0].lastError = "GitHub access is no longer available. Reconnect GitHub or choose another connection.";
function save(source: SkillSource, selectedPaths: string[], excludedFolders: string[]): SkillSourceRefreshResult {
const imported: CompanySkill[] = [];
const warnings: string[] = [...(source.repositoryPackage?.warnings ?? [])];
let unchanged = 0;
source.entries = source.entries.map(entry => {
const selected = selectedPaths.includes(entry.path);
const next: SkillSourceEntry = { ...entry, selection: selected ? "selected" : "excluded" };
if (selected && entry.error) warnings.push(`${entry.path}: ${entry.error}`);
else if (selected && !entry.skillId) {
next.skillId = fixtureSkillId(entry.id);
imported.push(importedSkill(source, next));
} else if (selected) unchanged++;
return next;
});
Object.assign(source, { excludedFolders, enabled: true, revision: source.revision + 1, lastAttemptAt: new Date(), lastSuccessAt: new Date(), lastError: null });
return structuredClone({ source, imported, updated: [], unchanged, warnings });
}
skillSourcesApi.list = async () => structuredClone(sources);
const repositoryScenario = options.repositories ?? 'single';
skillSourcesApi.repositories = async () => {
if (repositoryScenario === 'loading') return new Promise(() => {});
if (repositoryScenario === 'error') throw new Error('GitHub is temporarily unavailable. Try again.');
const personal = { id: 'github-storybook', name: 'My GitHub account' };
const shared = { id: 'github-acme', name: 'Acme engineering' };
const connections = repositoryScenario === 'none' ? [] : repositoryScenario === 'multiple' || repositoryScenario === 'partial-error' ? [personal, shared] : [personal];
const repo = (id: string, fullName: string, privateRepo: boolean, accounts = [personal]) => ({
id, fullName, private: privateRepo, url: `https://github.com/${fullName}`,
connections: accounts.map(account => account.name), connectionIds: accounts.map(account => account.id),
});
return {
connections, connectionCount: connections.length, failedConnectionCount: repositoryScenario === 'partial-error' ? 1 : 0,
repositories: ['none', 'empty'].includes(repositoryScenario) ? [] : repositoryScenario === 'multiple' ? [
repo('234567', 'acme/agent-playbooks', true, [shared]),
repo('345678', 'acme/design-system', false, [shared]),
repo('456789', 'acme/engineering', true, [shared]),
// One row even though two authorized connections can access this repository.
repo('123456', 'acme/team-skills', true, [personal, shared]),
repo('567890', 'maya/research-skills', false),
repo('678901', 'maya/writing-tools', true),
] : [repo('123456', 'acme/team-skills', true)],
};
};
skillSourcesApi.discover = async (_companyId, input) => {
const parsed = parseGitHubSkillRepositoryUrl(input.repositoryUrl);
if (!parsed) throw new Error('Enter an HTTPS GitHub repository or branch URL.');
return {
repositoryId: '123456', repositoryUrl: parsed.repositoryUrl, fullName: parsed.fullName,
trackingRef: input.trackingRef || parsed.trackingRef || 'main', commitSha: COMMIT, candidates: input.packageMode === 'repository' && options.packageScenario ? repositoryCandidates(options.packageScenario) : discoveryCandidates, warnings: [],
packageMode: input.packageMode, ...(input.packageMode === 'repository' ? { repositoryPackage: repositoryFixture(options.packageScenario) } : {}),
};
};
skillSourcesApi.discoverStream = async (companyId, input, onProgress, signal) => {
const active = signal ? AbortSignal.any([signal, fixtureController.signal]) : fixtureController.signal;
const result = await skillSourcesApi.discover(companyId, input);
const progress = { type: 'progress' as const, phase: 'connecting' as 'connecting' | 'downloading' | 'listing' | 'checking', totalSkills: null as number | null, checkedSkills: 0, currentPath: null as string | null, checkedFiles: 0, totalFiles: null as number | null };
onProgress({ ...progress });
await wait(options.scan ? 900 : 100, active);
progress.phase = 'downloading';
for (const percent of [12, 38, 64, 88, 100]) {
onProgress({ ...progress, download: { stage: 'receiving', percent, receivedBytes: Math.round(percent / 100 * 28 * 1024 * 1024) } });
await wait(options.scan ? 500 : 20, active);
}
onProgress({ ...progress, download: { stage: 'resolving', percent: 70 } });
await wait(options.scan ? 600 : 20, active);
progress.phase = 'listing'; onProgress({ ...progress });
await wait(options.scan ? 1200 : 100, active);
progress.phase = 'checking'; progress.totalSkills = options.scan === 'large' ? 128 : result.candidates.length;
for (const candidate of result.candidates) {
progress.currentPath = candidate.path; progress.checkedFiles = 0; progress.totalFiles = candidate.fileCount;
onProgress({ ...progress });
for (const file of candidate.inspection?.files ?? []) {
progress.currentPath = `${candidate.path.replace(/SKILL.md$/, '')}${file.path}`;
onProgress({ ...progress });
await wait(options.scan ? 350 : 50, active);
progress.checkedFiles++;
}
onProgress({ type: 'candidate', candidate });
progress.checkedSkills++; onProgress({ ...progress });
if (options.scan === 'interrupted' && progress.checkedSkills === 2) throw new Error('GitHub is temporarily unavailable. Try again.');
}
if (options.scan === 'large') {
progress.totalFiles = 72; progress.checkedFiles = 0;
for (let file = 0; file < 72; file++) {
progress.currentPath = `skills/document-processing/references/guide-${file + 1}.md`;
progress.checkedFiles = file; onProgress({ ...progress }); await wait(1000, active);
}
await wait(3600000, active);
}
return result;
};
skillSourcesApi.preview = async (_companyId, input) => {
const file = (input.packageMode === 'repository' ? repositoryFixture(options.packageScenario).files : inspection(input.skillPath).files).find(file => file.path === input.filePath);
if (!file) throw new Error('File is not included in this package.');
return { file, content: input.packageMode === 'repository' ? repositoryContents[input.filePath]! : packageContents[input.skillPath]![input.filePath]!, truncated: false, commitSha: input.commitSha };
};
skillSourcesApi.create = async (_companyId, input) => {
if (options.saving) await wait(3600000);
const source = sourceFixture();
Object.assign(source, { id: `source-${sources.length + 1}`, packageMode: input.packageMode, repositoryPackage: input.packageMode === 'repository' ? repositoryFixture(options.packageScenario) : null, repositoryUrl: input.repositoryUrl, fullName: input.repositoryUrl.replace("https://github.com/", ""), trackingRef: input.trackingRef || "main", connectionId: input.connectionId ?? null });
source.entries = repositoryCandidates(options.packageScenario).filter(entry => discoveryCandidates.some(candidate => candidate.path === entry.path)).map((entry, index) => ({ ...entry, id: `entry-${index}`, sourceId: source.id, present: true, selection: 'new', skillId: null }));
sources.push(source);
return save(source, input.selectedPaths, input.excludedFolders ?? []);
};
skillSourcesApi.select = async (_companyId, id, input) => {
const source = sources.find(item => item.id === id)!;
source.connectionId = input.connectionId ?? null;
source.packageMode = input.packageMode ?? source.packageMode;
source.repositoryPackage = source.packageMode === 'repository' ? repositoryFixture(options.packageScenario) : null;
return save(source, input.selectedPaths, input.excludedFolders);
};
skillSourcesApi.refresh = async (_companyId, id) => {
const source = sources.find(item => item.id === id)!;
if (needsConnection) throw new Error(source.lastError ?? "Reconnect GitHub to refresh this source.");
if (options.journey && !source.entries.some(entry => entry.path.includes('/security/'))) {
source.entries.push({ ...sourceFixture().entries[2]!, sourceId: source.id });
source.revision++;
}
source.lastAttemptAt = new Date();
source.lastSuccessAt = new Date();
return structuredClone({ source, imported: [], updated: [], unchanged: source.entries.filter(entry => entry.selection === "selected").length, warnings: [] });
};
skillSourcesApi.disconnect = async (_companyId, id) => {
const source = sources.find(item => item.id === id)!;
source.enabled = false;
return structuredClone(source);
};
return () => {
fixtureController.abort();
Object.assign(skillSourcesApi, original);
Object.assign(companySkillsApi, originalSkills);
Object.assign(agentsApi, originalAgents);
Object.assign(foldersApi, originalFolders);
};
}