@pinelabs/skills-cli 0.0.0-stage → 0.5.0
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/CHANGELOG.md +28 -0
- package/README.md +144 -2
- package/dist/agents.d.ts +26 -0
- package/dist/agents.js +74 -0
- package/dist/args.d.ts +5 -0
- package/dist/args.js +40 -0
- package/dist/artifacts.d.ts +16 -0
- package/dist/artifacts.js +206 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +86 -0
- package/dist/core.d.ts +111 -0
- package/dist/core.js +140 -0
- package/dist/engine.d.ts +18 -0
- package/dist/engine.js +275 -0
- package/dist/transaction.d.ts +19 -0
- package/dist/transaction.js +277 -0
- package/package.json +43 -4
- package/resources/pinelabs-architecture-0.5.0.skill.json +1 -0
- package/resources/registry.json +28 -0
- package/schemas/manifest-v1.schema.json +166 -0
- package/schemas/manifest-v2.schema.json +192 -0
- package/schemas/manifest-v3.schema.json +212 -0
- package/schemas/registry-v1.schema.json +130 -0
- package/schemas/skill-bundle-v1.schema.json +59 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.5.0 — 25 November 2026
|
|
4
|
+
|
|
5
|
+
- Added an unpublished, private npm CLI with TypeScript, a Node.js 24 LTS baseline and one shared engine for both command forms.
|
|
6
|
+
- Registered the existing architecture skill with explicit public-ID/canonical-name mapping; retained canonical source history and excluded historical evaluations from the validated runtime artifact.
|
|
7
|
+
- Added versioned registry, regular-file bundle and ownership schemas; configurable pinned sources, SHA-256 verification and strict metadata/path validation.
|
|
8
|
+
- Added shared Codex/Copilot discovery, documented configuration hints, explicit agent overrides and ownership-checked guidance sections.
|
|
9
|
+
- Added batch preflight, dry-run, local-change protection, version no-ops, safe offline removal, journaled rollback and guarded recovery.
|
|
10
|
+
- Added automated fault/security/behavior tests and a packed executable smoke test; documented limitations and prerequisites for future authorized publication.
|
|
11
|
+
|
|
12
|
+
### Review corrections
|
|
13
|
+
|
|
14
|
+
- Fixed bundled updates retaining paths from an older CLI/npm cache. Ownership schema v2 distinguishes bundled, explicit local and pinned remote sources. Existing v1 local provenance requires an explicit source selection; offline validation/removal remain supported.
|
|
15
|
+
- Persisted explicit source changes even when release bytes/version are unchanged, so subsequent updates honor the selected registry.
|
|
16
|
+
- Fixed recovery of dead-process locks without journals, including interruption before journal creation and after commit cleanup; preserved dry-run and fail-closed owner checks.
|
|
17
|
+
- Fixed Windows drive-letter paths being treated as URL schemes; made package smoke execution Windows-compatible and added SHA-pinned Node 24/26 CI across Windows, macOS and Ubuntu.
|
|
18
|
+
- Added ten lifecycle/source/platform regression cases. Local verification: build/type checks, 39 passing tests and the packed CLI smoke test (23 allowlisted files). Native Windows/Node 26 CI results remain pending.
|
|
19
|
+
|
|
20
|
+
### Boundary corrections
|
|
21
|
+
|
|
22
|
+
- Separated strict incoming artifact paths from native project-file enumeration. Normal user filenames, empty directories and unowned links are preserved/reported without adoption or traversal. Explicit/persisted agent selections bypass detection.
|
|
23
|
+
- Applied the recovery journal validator to creation before any lock or project write, including dry-run. Rejected batches over 10,000 operations; verified process-interruption recovery at exactly 10,000 operations.
|
|
24
|
+
- Built resources in clean staging, replaced output after validation and preserved prior output on failed builds. Package smoke now requires resources to match registry references exactly.
|
|
25
|
+
- Recorded per-skill agent capabilities in ownership schema v3 and checked the complete resulting skill set before changing guidance. Read compatibility remains for v1/v2; unknown legacy capabilities require metadata refresh before agent guidance can be changed.
|
|
26
|
+
- Added eight boundary regressions, including the actual four-by-2,500-file reproduction and obsolete-artifact npm packaging check. Local checks: build/type checks, 47 passing tests, five valid schemas and package smoke with 24 allowlisted files. The pre-fix copy fails seven of the eight new cases; the accepted-limit recovery control passes. Native Windows and Node 26 CI execution remains pending.
|
|
27
|
+
|
|
28
|
+
This release does not publish a package, establish a production registry, fabricate additional skills or claim organizational approval.
|
package/README.md
CHANGED
|
@@ -1,3 +1,145 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Pine Labs Skills CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Version **0.5.0**. npm package: `@pinelabs/skills-cli`. Includes the bundled `pine-labs-architecture-design` skill and a project-local installer. No separately hosted skill registry or backend service is required.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npx @pinelabs/skills-cli@0.5.0 add skills pinelabs-architecture
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Run in an existing project using Node.js 24 or 26. The package retains its `UNLICENSED` designation; public package availability does not grant an open-source license.
|
|
10
|
+
|
|
11
|
+
## Develop and exercise locally
|
|
12
|
+
|
|
13
|
+
Use **Node.js 24 LTS**, the tested baseline. Engines also permit Node.js 26 LTS, which has not been exercised here. Other majors are rejected by the executable. See the [official release schedule](https://nodejs.org/en/about/previous-releases).
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
cd pine-labs-skills-cli
|
|
17
|
+
npm ci --ignore-scripts
|
|
18
|
+
npm run build
|
|
19
|
+
npm run check
|
|
20
|
+
npm test
|
|
21
|
+
npm run pack:smoke
|
|
22
|
+
node dist/cli.js --help
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Build from this checkout: the authoring catalog reads the adjacent `../pine-labs-architecture-design` source. `dist/` and release `resources/` are generated. Builds validate metadata, artifact digests and runtime Markdown file references. No lifecycle script builds or publishes the package automatically. Run build before pack. Resources are built in a fresh staging directory and replace the generated directory only after validation; obsolete releases are discarded and validation failure preserves the prior output. The smoke test requires tarball resources to equal registry references exactly and checks reproducibility against source and installs the resulting tarball in a temporary consumer with dependency scripts disabled.
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
node dist/cli.js list
|
|
29
|
+
node dist/cli.js add skills pinelabs-architecture --project /existing/project --agent both
|
|
30
|
+
node dist/cli.js add pinelabs-architecture --project /existing/project --dry-run --json
|
|
31
|
+
node dist/cli.js add skills all --project /existing/project --non-interactive
|
|
32
|
+
node dist/cli.js update --project /existing/project
|
|
33
|
+
node dist/cli.js validate --project /existing/project --json
|
|
34
|
+
node dist/cli.js remove skills pinelabs-architecture --project /existing/project
|
|
35
|
+
node dist/cli.js recover --project /existing/project --dry-run
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The executable name is `pinelabs-skills`. Both `add [skills]` and `remove [skills]` forms share one implementation. Multiple IDs and aliases are accepted; `all` must appear alone. There are no prompts; `--non-interactive` and `--yes` document that intent and never override conflicts. Options use separate values (no `--option=value` syntax). `--project-dir` aliases `--project`; the directory must already exist. Help and version do not require a project.
|
|
39
|
+
|
|
40
|
+
The public command is `npx @pinelabs/skills-cli add skills pinelabs-architecture`. No `pinelabs-security` skill exists: requesting it, including after a valid ID in the same request, fails before any project write.
|
|
41
|
+
|
|
42
|
+
## Identity, discovery and guidance
|
|
43
|
+
|
|
44
|
+
| Public ID | Accepted alias / canonical SKILL.md name | Single installed directory |
|
|
45
|
+
| --- | --- | --- |
|
|
46
|
+
| `pinelabs-architecture` | `pine-labs-architecture-design` | `.agents/skills/pine-labs-architecture-design/` |
|
|
47
|
+
|
|
48
|
+
The source skill's name, instructions and references are copied as release bytes; installation never rewrites its frontmatter to match the public ID. Version metadata and a source-level distribution note were added explicitly for 0.5.0. Runtime payload includes `SKILL.md`, runtime `references/`, `templates/` and `examples/`. Historical evaluation trees, reports and changelog stay in the canonical source checkout. Source-only references are explicitly identified in the source documentation, rather than silently removed by the bundler. Existing skill evaluations and architecture controls are retained.
|
|
49
|
+
|
|
50
|
+
Both [Codex skills](https://developers.openai.com/codex/skills/) and [GitHub Copilot agent skills](https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/add-skills) document `.agents/skills/` discovery. One canonical tree serves both. Detection is a repository hint, not proof of agent installation, activation or surface support:
|
|
51
|
+
|
|
52
|
+
- Codex hint: `.codex/config.toml`, a documented [project configuration location](https://developers.openai.com/codex/config-basic/). Its presence does not establish that Codex trusts or loads it.
|
|
53
|
+
- Copilot hints: `.github/copilot-instructions.md` or `.github/instructions/*.instructions.md`, documented [repository instruction locations](https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/add-custom-instructions/add-repository-instructions).
|
|
54
|
+
- `AGENTS.md` alone is ambiguous because agents share it. No hints means shared skill installation with no guidance edits. Use `--agent codex`, `copilot`, `both` or `none` to override. Recorded selection persists across subsequent operations.
|
|
55
|
+
|
|
56
|
+
Adapters add small marked sections to `AGENTS.md` and/or `.github/copilot-instructions.md` with appropriate relative links. Existing bytes and permissions outside the section survive; edits to the owned section block mutation. Skills remain subject to repository policy, instruction precedence and user authorization; see [Codex AGENTS.md](https://developers.openai.com/codex/guides/agents-md/). Nested overrides or agent-specific availability can affect actual discovery. Installation does not establish organizational approval.
|
|
57
|
+
|
|
58
|
+
## Trusted registry and artifact contract
|
|
59
|
+
|
|
60
|
+
The default is the **bundled skill registry** shipped with this package. `registry/catalog.json` is build input, distinct from the distributable registry. Add a real skill to the catalog and build, or publish a validated registry entry and artifact to an approved source; installer logic needs no new skill-specific branches. Tests use clearly synthetic `demo-*` fixtures and do not register fictional production skills.
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
node dist/cli.js list --registry /trusted/local/registry.json
|
|
64
|
+
node dist/cli.js add all --registry https://approved.example/registry.json --registry-sha256 <trusted-lowercase-sha256> --project /existing/project
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Equivalent environment variables: `PINELABS_SKILLS_REGISTRY`, `PINELABS_SKILLS_REGISTRY_SHA256`; explicit flags win. Local paths and `file:` URLs are explicitly trusted by the caller. Local artifacts must be bounded regular files under the resolved registry directory, without linked artifact paths. Remote registries require a digest obtained through an independent trusted channel. HTTPS artifacts must share the registry origin. Redirects, URL credentials, query strings and fragments are refused. A pinned registry may be replayed; hashes prove selected bytes, not freshness, authorship or approval. Rotate pins deliberately when approving new releases. `update` preserves explicit local/remote selections unless overridden, and an advancing remote registry requires its new pin. Bundled selections resolve through the currently running CLI, not a previous npm installation directory. Use `--registry bundled` to explicitly select that source. Windows drive-letter paths, UNC paths and `file:` URLs are classified as filesystem sources before URL scheme checks.
|
|
68
|
+
|
|
69
|
+
Versioned JSON Schemas live in `schemas/`; runtime validation also enforces cross-field constraints, file closure, safe integers, case collisions and ownership. Registries declare schema version, minimum installer version, maximum installer major, ID/aliases, canonical name, description, stable `x.y.z` version, artifact format/location/SHA-256 and compatible agents. A future incompatible *unselected* entry can coexist with compatible entries. `all` and `skills` are reserved IDs/aliases.
|
|
70
|
+
|
|
71
|
+
Artifacts use bounded `pinelabs-skill-bundle-v1` JSON containing canonical base64 regular files and an optional executable bit. Tar/zip archives, symlinks, special files and hook fields are rejected; no archive extractor is needed. Files are verified before activation, with strict YAML frontmatter parsing, matching identity/version/description and relative Markdown file-target checks. Downloaded scripts are data and are never executed by the installer. The current skill has no runtime scripts; a future skill can include them as regular files. Runtime file validation recognizes inline Markdown links, not every possible Markdown/HTML construct or heading anchor. Authors must review additional reference forms.
|
|
72
|
+
|
|
73
|
+
Limits: registry 1 MiB; encoded artifact and decoded payload each 16 MiB; 3,000 files per skill; 1,000 registry entries; 15-second HTTPS request timeout. Portable ASCII paths exclude traversal, Windows reserved devices, case collisions and selected credential/cache names. This is an installer validation boundary, not a sandbox for skill instructions or scripts later run by an agent.
|
|
74
|
+
|
|
75
|
+
## Ownership, updates and removal
|
|
76
|
+
|
|
77
|
+
`.pinelabs/skills.json` schema v3 records versioned ownership, canonical paths, SHA-256 file hashes and executable flags, pinned source, artifact digest, configured agents, exact managed sections and timestamps. Treat it as trusted local bookkeeping, not a signed security record. Validate checks the installed tracked files, executable flags, metadata, runtime references and managed guidance without network access. It reports user additions without adopting them.
|
|
78
|
+
|
|
79
|
+
Source records distinguish `bundled` (digest only, no machine-specific path), `local` (explicit path and digest), and `remote` (URL and trust pin). Schema v1 remains readable for offline validation/removal. Its local sources cannot reliably distinguish bundled from explicitly selected registries: update fails with `ELEGACYSOURCE` and makes no writes until the caller chooses `--registry bundled` or `--registry <trusted-path>`. An explicit selection migrates ownership to the current schema even when the release version is unchanged. Unselected legacy local sources are carried forward as `legacy-local` until resolved; their original path remains for inspection. Legacy remote sources retain their URL and pin automatically. The v1 and v2 ownership schemas remain included for read compatibility; new writes use v3 with per-skill agent compatibility. Legacy capabilities are recorded as unknown until an update refreshes trusted registry metadata. If retained skills have unknown capabilities, use an ordinary full update before generating agent guidance, or `--agent none` to retain offline operations without asserting agent support.
|
|
80
|
+
|
|
81
|
+
Every requested artifact is resolved and validated in memory before project writes. Unmanaged directories, edited/missing owned files, edited sections and new release files colliding with user additions stop updates. Same-version content replacement and downgrades are refused. Unchanged versions and repeated installs are no-ops when source provenance and adapter selection are also unchanged. An explicit source change is recorded even when the selected release bytes are identical. Dry-run performs the same planning and validation with **no project writes**, including no lock, manifest or journal creation. It may read sources or use network access for explicit remote sources.
|
|
82
|
+
|
|
83
|
+
Removal works offline and deletes only unchanged tracked files and exact owned guidance. User additions and modified files remain and are reported, with exit status 3. Enumeration permits normal native filenames, including parentheses, apostrophes and Unicode, without adopting them. Unowned links are reported without following their targets; tracked-file and installer-target links remain refused. Their ownership is relinquished: a retained modified `SKILL.md` may remain discoverable, and a later add will report the remaining directory as unmanaged. Other installed skills keep their guidance. No force/adopt flag bypasses these checks.
|
|
84
|
+
|
|
85
|
+
## Transactions and recovery
|
|
86
|
+
|
|
87
|
+
Both real and dry-run mutations validate the complete journal contract before any project writes: at most 10,000 operations including guidance/manifest, at most 64 MiB encoded journal, bounded canonical images, unique permitted targets and valid modes. Oversized batches are rejected; the installer does not split them into partial commits. Agent compatibility is checked across the complete resulting set before guidance changes. Explicit or persisted agent selections bypass repository detection.
|
|
88
|
+
|
|
89
|
+
Mutations take an exclusive local process lock, write a journal of before/after bytes and permissions, replace individual files atomically, and commit the ownership manifest last. Ordinary failures trigger rollback. If an unrelated concurrent edit prevents safe rollback, the journal and unknown edit remain for inspection. Another normal operation refuses a pending journal.
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
node dist/cli.js recover --project /existing/project --dry-run
|
|
93
|
+
node dist/cli.js recover --project /existing/project
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Recovery also inspects locks when no journal exists. It clears only demonstrably dead local owners, covering interruption after lock acquisition and after journal deletion. A lock-only recovery keeps a completed installation intact; dry-run validates and reports the lock without writing. Malformed, foreign-host, invalid-PID, live and inaccessible owners are refused.
|
|
97
|
+
|
|
98
|
+
Recovery validates target paths and all current files against known before/after images before restoring the previous state. It refuses unknown edits and live or unverifiable lock owners. Inspect conflicts, preserve your edits elsewhere, and reconcile files manually before retrying. A stale recovery guardian (`.pinelabs/skills-recovery.lock`) requires manual removal only after verifying its owner has stopped. Do not delete ownership or transaction records to bypass a conflict.
|
|
99
|
+
|
|
100
|
+
This provides process-interruption recovery, **not simultaneous visibility across multiple files or guaranteed power-loss durability**. Pause agents and other writers during changes. File synchronization is used, but directory-entry synchronization and crash consistency across all filesystems are not certified. A kill inside a low-level temporary-file write can leave an orphan `.pinelabs-*.tmp` requiring inspection. Hostile concurrent filesystem writers are outside the security boundary; path checks cannot eliminate all filesystem races. Local tests run on macOS with Node 24. A SHA-pinned GitHub Actions matrix covers macOS, Ubuntu and Windows on Node 24/26, including packed default list/install/update/removal and lifecycle regressions. That workflow has been added but has not been executed here; native Windows and Node 26 results remain pending. POSIX executable-bit checks are skipped on Windows. Do not use on concurrently mounted/shared network filesystems.
|
|
101
|
+
|
|
102
|
+
## Results and exit codes
|
|
103
|
+
|
|
104
|
+
`--json` emits one success result to stdout or one error object to stderr. Mutations report `status`, `changes`, `retained` and `warnings`; a dry-run lists its plan. Diagnostics do not print artifact contents or credentials. Human output uses the same results.
|
|
105
|
+
|
|
106
|
+
| Code | Meaning |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| 0 | Success, no-op or valid dry-run |
|
|
109
|
+
| 2 | Usage, unknown selection, unsupported runtime or invalid project |
|
|
110
|
+
| 3 | Local conflict or partial removal with retained content |
|
|
111
|
+
| 4 | Source, integrity, metadata, compatibility or ordinary I/O error |
|
|
112
|
+
| 5 | Transaction, lock or recovery intervention required |
|
|
113
|
+
|
|
114
|
+
## Checks and publication prerequisites
|
|
115
|
+
|
|
116
|
+
`npm test` covers command forms, batch preflight, agent hints, identity, repeat/no-op behavior, dry-run, ownership conflicts, safe updates/removal, malicious payloads, symlinks, integrity, rollback, subprocess interruption and recovery. `npm run pack:smoke` checks the tarball allowlist and executable, installs it into a temporary consumer, then exercises the packed CLI against temporary projects, including both agent guidance files and the real bundled skill. It does not install globally or alter global agent configuration.
|
|
117
|
+
|
|
118
|
+
Before a public `npx` command can work: confirm npm scope/name ownership and publication authority; approve redistribution of the skill and licensing (`UNLICENSED` currently); review registry governance, pin distribution and artifact provenance; add Node 24/26 and target OS CI; review the packed artifact and dependencies; deliberately change `private: true` under an authorized release process; then publish the verified package and establish approved versioned registry hosting if remote distribution is wanted. No step here grants permission to publish, deploy or perform financial actions.
|
|
119
|
+
|
|
120
|
+
## Initial verification record — 25 November 2026
|
|
121
|
+
|
|
122
|
+
Verified locally on macOS with Node.js **24.22.3**:
|
|
123
|
+
|
|
124
|
+
- `npm run build` and `npm run check`: passed; one registered real skill, 30 runtime files, metadata/integrity/reference closure validated.
|
|
125
|
+
- `npm test`: **29 passed, 0 failed, 0 skipped**, including synthetic pinned HTTPS responses (no live production registry was exercised).
|
|
126
|
+
- `npm run pack:smoke`: passed; **22 allowlisted tarball files**, local consumer installation, packed executable and real-skill lifecycle verified.
|
|
127
|
+
- All three JSON Schemas pass Draft 2020-12 schema checks; generated registry, bundle and real installed manifest validate against them.
|
|
128
|
+
- Canonical skill checks: 37 Markdown files, 295 relative links, 37 unique controls and nine profiles; no errors. Frontmatter/scaffold validator passed.
|
|
129
|
+
- Of 225 preexisting canonical skill files, **222 remain byte-identical**. The three explicit edits are version/distribution metadata in `SKILL.md`, governance and the prepended changelog entry. One new distribution reference was added. All prior changelog entries, historical evaluations, frozen rubrics and safety reference files were preserved.
|
|
130
|
+
|
|
131
|
+
Packaging uses a temporary npm cache by default and may fetch the locked runtime dependency. `PINELABS_SMOKE_NPM_CACHE` can select an existing cache; local verification used an isolated cache outside user npm configuration. No global installation, package publication, external repository write or production deployment was performed. Prior architecture behavioral evaluations were preserved; they were not rerun for this distribution change. Node 26, Windows, editor integration and power-loss behavior remain unverified.
|
|
132
|
+
|
|
133
|
+
## Review corrections — 25 November 2026
|
|
134
|
+
|
|
135
|
+
Accepted all three lifecycle/platform findings and fixed them without changing architecture skill content:
|
|
136
|
+
|
|
137
|
+
- Portable bundled provenance plus explicit local/remote identities in ownership schema v2; tested update through a second CLI copy after deleting the first, same-version source rebinding, legacy migration and remote pin preservation.
|
|
138
|
+
- Lock-only recovery for both real subprocess interruption windows; live/foreign/malformed/unverifiable owner refusal and write-free dry-run.
|
|
139
|
+
- Filesystem-first registry classification for Windows drive letters/UNC; shell-free npm invocation in the packaging harness and Windows-compatible permission assertions. Windows package commands use the installed npm executable shim through `npm exec`, following Node's [Windows child-process guidance](https://nodejs.org/api/child_process.html#spawning-bat-and-cmd-files-on-windows).
|
|
140
|
+
|
|
141
|
+
Local Node 24.22.3 checks: build and TypeScript passed; **39 tests passed, zero failed or skipped**; package smoke passed with **23 allowlisted files**, including four schemas. Draft 2020-12 checks cover all four schemas and real schema-v2 ownership. The six-job GitHub Actions matrix is configured; no remote CI or native Windows result is claimed. The package remains private and unpublished.
|
|
142
|
+
|
|
143
|
+
## Boundary regression verification — 25 November 2026
|
|
144
|
+
|
|
145
|
+
Build/type checks and all **47 tests** pass locally on Node 24.22.3. The eight added cases were also run against an isolated pre-fix copy: seven failed; the accepted 10,000-operation recovery case passed as a positive boundary control. Tests exercise actual four-by-2,500-file batching, native user filenames, full resulting-set compatibility and npm-packed resources after successive/failed builds. Package smoke passes with **24 allowlisted files**, and five JSON Schemas validate, including real schema-v3 ownership. Native Windows and Node 26 CI execution remain pending; no publication was performed.
|
package/dist/agents.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Agent, type Guidance, type OwnedSkill } from './core.js';
|
|
2
|
+
export declare const ADAPTERS: Record<Agent, {
|
|
3
|
+
guidance: string;
|
|
4
|
+
signals: string[];
|
|
5
|
+
}>;
|
|
6
|
+
export declare function detectAgents(root: string): Promise<{
|
|
7
|
+
agents: Agent[];
|
|
8
|
+
signals: Record<string, string[]>;
|
|
9
|
+
warnings: string[];
|
|
10
|
+
}>;
|
|
11
|
+
export declare function parseAgents(input: string): Agent[];
|
|
12
|
+
export declare function sectionRange(content: string, previous: Guidance): {
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function guidanceChange(agent: Agent, content: Buffer | null, previous: Guidance | undefined, skills: OwnedSkill[]): {
|
|
17
|
+
after: Buffer<ArrayBuffer> | null;
|
|
18
|
+
guidance: {
|
|
19
|
+
path: string;
|
|
20
|
+
created: boolean;
|
|
21
|
+
section: string;
|
|
22
|
+
} | undefined;
|
|
23
|
+
} | {
|
|
24
|
+
after: Buffer<ArrayBufferLike> | null;
|
|
25
|
+
guidance: undefined;
|
|
26
|
+
};
|
package/dist/agents.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { ensure, read, safe, START, END } from './core.js';
|
|
3
|
+
import * as fs from 'node:fs/promises';
|
|
4
|
+
export const ADAPTERS = {
|
|
5
|
+
codex: { guidance: 'AGENTS.md', signals: ['.codex/config.toml'] },
|
|
6
|
+
copilot: { guidance: '.github/copilot-instructions.md', signals: ['.github/copilot-instructions.md'] },
|
|
7
|
+
};
|
|
8
|
+
export async function detectAgents(root) {
|
|
9
|
+
const found = [], signals = {};
|
|
10
|
+
for (const agent of ['codex', 'copilot']) {
|
|
11
|
+
const matched = [];
|
|
12
|
+
for (const signal of ADAPTERS[agent].signals)
|
|
13
|
+
if (await read(root, signal) !== null)
|
|
14
|
+
matched.push(signal);
|
|
15
|
+
if (agent === 'copilot') {
|
|
16
|
+
const directory = await safe(root, '.github/instructions');
|
|
17
|
+
let names = [];
|
|
18
|
+
try {
|
|
19
|
+
names = await fs.readdir(directory);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
if (e.code !== 'ENOENT')
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
for (const name of names.filter(n => n.endsWith('.instructions.md'))) {
|
|
26
|
+
if (await read(root, `.github/instructions/${name}`) !== null)
|
|
27
|
+
matched.push(`.github/instructions/${name}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (matched.length) {
|
|
31
|
+
found.push(agent);
|
|
32
|
+
signals[agent] = matched;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { agents: found, signals, warnings: found.length ? ['Agent detection uses repository configuration hints, not proof of installed/enabled agent support.'] : ['No agent-specific configuration detected. Shared skill discovery will be used without editing guidance; select --agent explicitly if needed.'] };
|
|
36
|
+
}
|
|
37
|
+
export function parseAgents(input) {
|
|
38
|
+
if (input === 'none')
|
|
39
|
+
return [];
|
|
40
|
+
const values = input === 'both' ? ['codex', 'copilot'] : input.split(',');
|
|
41
|
+
ensure(values.length > 0 && values.every(a => a === 'codex' || a === 'copilot') && new Set(values).size === values.length, 'Use --agent codex, copilot, both or none', 'EUSAGE', 2);
|
|
42
|
+
return values.sort();
|
|
43
|
+
}
|
|
44
|
+
function body(agent, skills) {
|
|
45
|
+
const dir = path.posix.dirname(ADAPTERS[agent].guidance);
|
|
46
|
+
const links = [...skills].sort((a, b) => a.id.localeCompare(b.id)).map(s => `- [${s.id}](${path.posix.relative(dir, `${s.path}/SKILL.md`)})`).join('\n');
|
|
47
|
+
return `${START}\n## Installed Pine Labs skills\n\n${links}\n\nUse relevant skills within repository policy and existing user authorization. Installation grants no deployment or financial-action authority.\n${END}\n`;
|
|
48
|
+
}
|
|
49
|
+
export function sectionRange(content, previous) {
|
|
50
|
+
const count = (needle) => content.split(needle).length - 1;
|
|
51
|
+
ensure(count(START) === 1 && count(END) === 1, `Managed guidance markers changed in ${previous.path}; restore the recorded section or resolve manually.`, 'ECONFLICT', 3);
|
|
52
|
+
const start = content.indexOf(START) - previous.section.indexOf(START);
|
|
53
|
+
ensure(start >= 0 && content.slice(start, start + previous.section.length) === previous.section, `Installer-managed section edited in ${previous.path}; no forced overwrite.`, 'ECONFLICT', 3);
|
|
54
|
+
return { start, end: start + previous.section.length };
|
|
55
|
+
}
|
|
56
|
+
export function guidanceChange(agent, content, previous, skills) {
|
|
57
|
+
const current = content?.toString('utf8') ?? '', filename = ADAPTERS[agent].guidance;
|
|
58
|
+
if (content)
|
|
59
|
+
ensure(Buffer.from(current).equals(content), `Guidance must be UTF-8: ${filename}`, 'ECONFLICT', 3);
|
|
60
|
+
if (previous) {
|
|
61
|
+
const range = sectionRange(current, previous);
|
|
62
|
+
const prefix = current.slice(0, range.start), suffix = current.slice(range.end);
|
|
63
|
+
const leading = previous.section.slice(0, previous.section.indexOf(START));
|
|
64
|
+
const section = skills.length ? leading + body(agent, skills) : '';
|
|
65
|
+
const next = prefix + section + suffix;
|
|
66
|
+
return { after: next.length === 0 && previous.created ? null : Buffer.from(next), guidance: skills.length ? { ...previous, section } : undefined };
|
|
67
|
+
}
|
|
68
|
+
if (skills.length === 0)
|
|
69
|
+
return { after: content, guidance: undefined };
|
|
70
|
+
ensure(!current.includes(START) && !current.includes(END), `Unmanaged installer markers already exist in ${filename}`, 'ECONFLICT', 3);
|
|
71
|
+
const separator = current.length === 0 || current.endsWith('\n\n') ? '' : current.endsWith('\n') ? '\n' : '\n\n';
|
|
72
|
+
const section = separator + body(agent, skills);
|
|
73
|
+
return { after: Buffer.from(current + section), guidance: { path: filename, section, created: content === null } };
|
|
74
|
+
}
|
package/dist/args.d.ts
ADDED
package/dist/args.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ensure } from './core.js';
|
|
2
|
+
import { parseAgents } from './agents.js';
|
|
3
|
+
export function parseArgs(argv) {
|
|
4
|
+
const words = [], flags = new Map();
|
|
5
|
+
const names = { '--project-dir': 'project', '--project': 'project', '--registry': 'registry', '--registry-sha256': 'pin', '--agent': 'agent', '--agents': 'agent', '--json': 'json', '--dry-run': 'dryRun', '--non-interactive': 'nonInteractive', '--yes': 'nonInteractive', '--help': 'help', '-h': 'help', '--version': 'version' };
|
|
6
|
+
for (let i = 0; i < argv.length; i++) {
|
|
7
|
+
const value = argv[i];
|
|
8
|
+
if (!value.startsWith('-')) {
|
|
9
|
+
words.push(value);
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const key = names[value];
|
|
13
|
+
ensure(key, `Unknown option ${value}`, 'EUSAGE', 2);
|
|
14
|
+
ensure(!flags.has(key), `Repeated option ${value}`, 'EUSAGE', 2);
|
|
15
|
+
if (['project', 'registry', 'pin', 'agent'].includes(key)) {
|
|
16
|
+
const next = argv[++i];
|
|
17
|
+
ensure(next && !next.startsWith('-'), `Missing value for ${value}`, 'EUSAGE', 2);
|
|
18
|
+
flags.set(key, next);
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
flags.set(key, true);
|
|
22
|
+
}
|
|
23
|
+
if (flags.has('help'))
|
|
24
|
+
return { command: 'help', ids: [], flags };
|
|
25
|
+
if (flags.has('version'))
|
|
26
|
+
return { command: 'version', ids: [], flags };
|
|
27
|
+
const command = words.shift();
|
|
28
|
+
ensure(command && ['list', 'add', 'update', 'remove', 'validate', 'recover'].includes(command), 'Choose list, add, update, remove, validate or recover. See --help.', 'EUSAGE', 2);
|
|
29
|
+
if ((command === 'add' || command === 'remove') && words[0] === 'skills')
|
|
30
|
+
words.shift();
|
|
31
|
+
if (command === 'add' || command === 'remove')
|
|
32
|
+
ensure(words.length > 0, 'Specify one or more skill IDs, or all', 'EUSAGE', 2);
|
|
33
|
+
else
|
|
34
|
+
ensure(words.length === 0, `Unexpected arguments for ${command}`, 'EUSAGE', 2);
|
|
35
|
+
if (flags.has('agent'))
|
|
36
|
+
parseAgents(flags.get('agent'));
|
|
37
|
+
if (!['add', 'update', 'remove', 'recover'].includes(command))
|
|
38
|
+
ensure(!flags.has('dryRun'), '--dry-run is for modifying commands and recovery', 'EUSAGE', 2);
|
|
39
|
+
return { command, ids: words, flags };
|
|
40
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Entry, type Source, type FileValue } from './core.js';
|
|
2
|
+
export declare const BUNDLED_REGISTRY: string;
|
|
3
|
+
export declare function compatible(minimum: unknown, major: unknown): void;
|
|
4
|
+
export declare function parseRegistry(bytes: Buffer): Entry[];
|
|
5
|
+
/** Classify paths before URL schemes: C:\registry and C:/registry are filesystem paths. */
|
|
6
|
+
export declare function registryKind(location: string): 'local' | 'remote' | 'bundled';
|
|
7
|
+
export declare function loadRegistry(location?: string, pin?: string): Promise<{
|
|
8
|
+
entries: Entry[];
|
|
9
|
+
source: Source;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function resolveRequested(entries: Entry[], ids: string[]): Entry[];
|
|
12
|
+
export declare function metadata(bytes: Buffer): Record<string, unknown>;
|
|
13
|
+
/** All declared Markdown relative targets must be present, not just SKILL.md links. */
|
|
14
|
+
export declare function validateReferences(files: Map<string, FileValue>): void;
|
|
15
|
+
export declare function decodeBundle(bytes: Buffer, entry: Pick<Entry, 'name' | 'version' | 'description'>): Map<string, FileValue>;
|
|
16
|
+
export declare function stageArtifact(source: Source, entry: Entry): Promise<Map<string, FileValue>>;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { parseDocument } from 'yaml';
|
|
5
|
+
import { CliError, ensure, object, keys, text, identifier, version, compare, digest, json, portable, sha, VERSION, LIMIT } from './core.js';
|
|
6
|
+
export const BUNDLED_REGISTRY = fileURLToPath(new URL('../resources/registry.json', import.meta.url));
|
|
7
|
+
async function boundedFetch(url, limit) {
|
|
8
|
+
const u = new URL(url);
|
|
9
|
+
ensure(u.protocol === 'https:' && !u.username && !u.password && !u.hash && !u.search, 'Only credential-free HTTPS sources are supported');
|
|
10
|
+
const response = await fetch(u, { redirect: 'error', signal: AbortSignal.timeout(15000) }).catch(() => { throw new CliError('ESOURCE', 'HTTPS source request failed (no redirects; check connectivity/source)', 4); });
|
|
11
|
+
ensure(response.ok && response.body, `Source HTTP status ${response.status}`);
|
|
12
|
+
const reader = response.body.getReader();
|
|
13
|
+
let total = 0;
|
|
14
|
+
const chunks = [];
|
|
15
|
+
try {
|
|
16
|
+
while (true) {
|
|
17
|
+
const { done, value } = await reader.read();
|
|
18
|
+
if (done)
|
|
19
|
+
break;
|
|
20
|
+
total += value.length;
|
|
21
|
+
ensure(total <= limit, 'Downloaded source exceeds size limit');
|
|
22
|
+
chunks.push(value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
await reader.cancel().catch(() => undefined);
|
|
27
|
+
}
|
|
28
|
+
return Buffer.concat(chunks);
|
|
29
|
+
}
|
|
30
|
+
async function localFile(location, limit) {
|
|
31
|
+
const st = await fs.lstat(location);
|
|
32
|
+
ensure(st.isFile() && !st.isSymbolicLink() && st.size <= limit, 'Source must be a bounded regular file, not a link');
|
|
33
|
+
return fs.readFile(location);
|
|
34
|
+
}
|
|
35
|
+
export function compatible(minimum, major) {
|
|
36
|
+
version(minimum);
|
|
37
|
+
ensure(Number.isInteger(major) && Number(major) >= 0 && Number(major) <= 1000, 'Invalid installer major compatibility');
|
|
38
|
+
ensure(compare(VERSION, minimum) >= 0 && Number(VERSION.split('.')[0]) <= Number(major), `Registry/artifact requires incompatible installer ${minimum}..major ${major}`, 'EINCOMPATIBLE');
|
|
39
|
+
}
|
|
40
|
+
export function parseRegistry(bytes) {
|
|
41
|
+
const value = json(bytes);
|
|
42
|
+
object(value);
|
|
43
|
+
keys(value, ['schemaVersion', 'minimumInstallerVersion', 'maximumInstallerMajor', 'label', 'skills']);
|
|
44
|
+
ensure(value.schemaVersion === 1, 'Unsupported registry schema version', 'EINCOMPATIBLE');
|
|
45
|
+
compatible(value.minimumInstallerVersion, value.maximumInstallerMajor);
|
|
46
|
+
text(value.label, 'registry label');
|
|
47
|
+
ensure(Array.isArray(value.skills) && value.skills.length <= 1000, 'Invalid registry skills');
|
|
48
|
+
const used = new Set(), names = new Set();
|
|
49
|
+
return value.skills.map(raw => {
|
|
50
|
+
object(raw);
|
|
51
|
+
keys(raw, ['id', 'aliases', 'name', 'description', 'version', 'minimumInstallerVersion', 'maximumInstallerMajor', 'artifact', 'agents']);
|
|
52
|
+
identifier(raw.id);
|
|
53
|
+
identifier(raw.name);
|
|
54
|
+
text(raw.description, 'description');
|
|
55
|
+
version(raw.version);
|
|
56
|
+
ensure(raw.description.length <= 1024, 'Description too long');
|
|
57
|
+
version(raw.minimumInstallerVersion);
|
|
58
|
+
ensure(Number.isInteger(raw.maximumInstallerMajor) && Number(raw.maximumInstallerMajor) >= 0 && Number(raw.maximumInstallerMajor) <= 1000, 'Invalid entry compatibility');
|
|
59
|
+
ensure(Array.isArray(raw.aliases) && raw.aliases.length <= 30, 'Invalid aliases');
|
|
60
|
+
for (const id of [raw.id, ...raw.aliases]) {
|
|
61
|
+
identifier(id);
|
|
62
|
+
ensure(id !== 'all' && id !== 'skills', `Reserved registry ID/alias ${id}`);
|
|
63
|
+
ensure(!used.has(id), `Duplicate registry ID/alias ${id}`);
|
|
64
|
+
used.add(id);
|
|
65
|
+
}
|
|
66
|
+
ensure(!names.has(raw.name), 'Two registry entries share a canonical name');
|
|
67
|
+
names.add(raw.name);
|
|
68
|
+
object(raw.artifact);
|
|
69
|
+
keys(raw.artifact, ['location', 'sha256', 'format']);
|
|
70
|
+
text(raw.artifact.location, 'artifact location');
|
|
71
|
+
digest(raw.artifact.sha256);
|
|
72
|
+
ensure(raw.artifact.format === 'pinelabs-skill-bundle-v1', 'Unsupported artifact format');
|
|
73
|
+
ensure(Array.isArray(raw.agents) && raw.agents.length > 0 && new Set(raw.agents).size === raw.agents.length && raw.agents.every(a => a === 'codex' || a === 'copilot'), 'Invalid agent compatibility');
|
|
74
|
+
return raw;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** Classify paths before URL schemes: C:\registry and C:/registry are filesystem paths. */
|
|
78
|
+
export function registryKind(location) {
|
|
79
|
+
if (location === 'bundled')
|
|
80
|
+
return 'bundled';
|
|
81
|
+
if (/^[a-z]:[\\/]/i.test(location) || location.startsWith('\\\\') || path.isAbsolute(location))
|
|
82
|
+
return 'local';
|
|
83
|
+
if (/^https?:/i.test(location))
|
|
84
|
+
return 'remote';
|
|
85
|
+
ensure(!/^[a-z][a-z0-9+.-]*:/i.test(location) || /^file:/i.test(location), 'Unsupported registry source');
|
|
86
|
+
return 'local';
|
|
87
|
+
}
|
|
88
|
+
export async function loadRegistry(location = 'bundled', pin) {
|
|
89
|
+
const kind = registryKind(location);
|
|
90
|
+
if (pin !== undefined)
|
|
91
|
+
digest(pin);
|
|
92
|
+
if (kind === 'remote')
|
|
93
|
+
ensure(pin, 'Remote registry requires --registry-sha256 (obtain the digest from a trusted channel)');
|
|
94
|
+
const resolved = kind === 'bundled' ? BUNDLED_REGISTRY : kind === 'remote' ? new URL(location).href : path.resolve(/^file:/i.test(location) ? fileURLToPath(location) : location);
|
|
95
|
+
const bytes = kind === 'remote' ? await boundedFetch(resolved, 1024 * 1024) : await localFile(resolved, 1024 * 1024);
|
|
96
|
+
if (pin)
|
|
97
|
+
ensure(sha(bytes) === pin, 'Registry integrity mismatch', 'EINTEGRITY');
|
|
98
|
+
const source = kind === 'bundled' ? { kind, sha256: sha(bytes) } : { kind, location: resolved, sha256: sha(bytes) };
|
|
99
|
+
return { entries: parseRegistry(bytes), source };
|
|
100
|
+
}
|
|
101
|
+
export function resolveRequested(entries, ids) {
|
|
102
|
+
ensure(ids.length > 0, 'Specify skill IDs or all', 'EUSAGE', 2);
|
|
103
|
+
if (ids.includes('all')) {
|
|
104
|
+
ensure(ids.length === 1, 'Use all by itself', 'EUSAGE', 2);
|
|
105
|
+
return [...entries];
|
|
106
|
+
}
|
|
107
|
+
return [...new Map(ids.map(id => {
|
|
108
|
+
const entry = entries.find(e => e.id === id || e.aliases.includes(id));
|
|
109
|
+
ensure(entry, `Unknown skill '${id}'. Run list to see existing skills.`, 'EUNKNOWN', 2);
|
|
110
|
+
return [entry.id, entry];
|
|
111
|
+
})).values()];
|
|
112
|
+
}
|
|
113
|
+
export function metadata(bytes) {
|
|
114
|
+
const value = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
115
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(value);
|
|
116
|
+
ensure(match && match[1].length <= 65536, 'Missing/bounded YAML frontmatter in SKILL.md');
|
|
117
|
+
const doc = parseDocument(match[1], { uniqueKeys: true, strict: true });
|
|
118
|
+
ensure(doc.errors.length === 0 && doc.warnings.length === 0, 'Invalid/unsupported YAML frontmatter');
|
|
119
|
+
const data = doc.toJS({ maxAliasCount: 0 });
|
|
120
|
+
object(data);
|
|
121
|
+
identifier(data.name);
|
|
122
|
+
text(data.description, 'SKILL description');
|
|
123
|
+
ensure(data.description.length <= 1024, 'SKILL description too long');
|
|
124
|
+
if (data.metadata !== undefined)
|
|
125
|
+
object(data.metadata);
|
|
126
|
+
return data;
|
|
127
|
+
}
|
|
128
|
+
/** All declared Markdown relative targets must be present, not just SKILL.md links. */
|
|
129
|
+
export function validateReferences(files) {
|
|
130
|
+
for (const [name, value] of files) {
|
|
131
|
+
if (!name.endsWith('.md'))
|
|
132
|
+
continue;
|
|
133
|
+
const body = value.bytes.toString('utf8').replace(/^---\n[\s\S]*?\n---\n/, '').replace(/```[^\n]*\n[\s\S]*?```/g, '');
|
|
134
|
+
for (const m of body.matchAll(/!?\[[^\]\n]*\]\(<?([^\s)>]+)>?(?:\s+"[^"]*")?\)/g)) {
|
|
135
|
+
const href = m[1];
|
|
136
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith('#'))
|
|
137
|
+
continue;
|
|
138
|
+
let target;
|
|
139
|
+
try {
|
|
140
|
+
target = decodeURIComponent(href.split('#')[0]);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
throw new CliError('EVALIDATION', 'Malformed relative reference');
|
|
144
|
+
}
|
|
145
|
+
if (!target)
|
|
146
|
+
continue;
|
|
147
|
+
ensure(!target.startsWith('/') && !target.includes('\\'), `Nonportable reference in ${name}`);
|
|
148
|
+
const resolved = path.posix.normalize(path.posix.join(path.posix.dirname(name), target));
|
|
149
|
+
ensure(!resolved.startsWith('../') && files.has(resolved), `Unresolved/escaping relative reference ${name} -> ${href}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export function decodeBundle(bytes, entry) {
|
|
154
|
+
const value = json(bytes);
|
|
155
|
+
object(value);
|
|
156
|
+
keys(value, ['format', 'name', 'version', 'files']);
|
|
157
|
+
ensure(value.format === 'pinelabs-skill-bundle-v1' && value.name === entry.name && value.version === entry.version, 'Artifact name/version/format mismatch');
|
|
158
|
+
ensure(Array.isArray(value.files) && value.files.length > 0 && value.files.length <= 3000, 'Invalid artifact files');
|
|
159
|
+
const files = new Map(), seen = new Set();
|
|
160
|
+
let size = 0;
|
|
161
|
+
for (const raw of value.files) {
|
|
162
|
+
object(raw);
|
|
163
|
+
keys(raw, ['path', 'type', 'content', 'executable']);
|
|
164
|
+
portable(raw.path);
|
|
165
|
+
ensure(raw.type === 'file' && typeof raw.content === 'string' && (raw.executable === undefined || typeof raw.executable === 'boolean'), 'Only regular-file artifact entries are supported (no symlinks/hooks)');
|
|
166
|
+
ensure(!raw.path.split('/').some(p => /^\.(git|env|aws|ssh|npmrc)$|^node_modules$|\.pem$|\.key$/i.test(p)), 'Forbidden sensitive/cache artifact path');
|
|
167
|
+
ensure(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(raw.content), 'Invalid base64 file');
|
|
168
|
+
const bytes = Buffer.from(raw.content, 'base64');
|
|
169
|
+
size += bytes.length;
|
|
170
|
+
ensure(size <= LIMIT && bytes.toString('base64') === raw.content, 'Artifact size/base64 limit');
|
|
171
|
+
const lower = raw.path.toLowerCase();
|
|
172
|
+
ensure(!seen.has(lower), 'Duplicate/case-colliding artifact paths');
|
|
173
|
+
seen.add(lower);
|
|
174
|
+
files.set(raw.path, { bytes, executable: raw.executable === true });
|
|
175
|
+
}
|
|
176
|
+
for (const name of seen)
|
|
177
|
+
for (const ancestor of name.split('/').slice(0, -1).map((_, i) => name.split('/').slice(0, i + 1).join('/')))
|
|
178
|
+
ensure(!seen.has(ancestor), 'File/directory artifact collision');
|
|
179
|
+
const skill = files.get('SKILL.md');
|
|
180
|
+
ensure(skill, 'Artifact has no SKILL.md');
|
|
181
|
+
const meta = metadata(skill.bytes);
|
|
182
|
+
ensure(meta.name === entry.name && meta.description === entry.description, 'SKILL metadata differs from registry');
|
|
183
|
+
const metaVersion = meta.metadata?.version;
|
|
184
|
+
if (metaVersion !== undefined)
|
|
185
|
+
ensure(metaVersion === entry.version, 'SKILL metadata version mismatch');
|
|
186
|
+
validateReferences(files);
|
|
187
|
+
return files;
|
|
188
|
+
}
|
|
189
|
+
export async function stageArtifact(source, entry) {
|
|
190
|
+
compatible(entry.minimumInstallerVersion, entry.maximumInstallerMajor);
|
|
191
|
+
let bytes;
|
|
192
|
+
ensure(source.kind !== 'legacy-local', 'Choose an explicit registry for this legacy source', 'ELEGACYSOURCE', 3);
|
|
193
|
+
if (source.kind === 'remote') {
|
|
194
|
+
const url = new URL(entry.artifact.location, source.location), origin = new URL(source.location);
|
|
195
|
+
ensure(url.origin === origin.origin && url.protocol === 'https:', 'Remote artifact must use registry HTTPS origin');
|
|
196
|
+
bytes = await boundedFetch(url.href, LIMIT);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
portable(entry.artifact.location);
|
|
200
|
+
const root = await fs.realpath(path.dirname(source.kind === 'bundled' ? BUNDLED_REGISTRY : source.location)), target = path.resolve(root, entry.artifact.location), real = await fs.realpath(target);
|
|
201
|
+
ensure(real === target && (real === root || real.startsWith(root + path.sep)), 'Artifact link/path escapes local registry');
|
|
202
|
+
bytes = await localFile(real, LIMIT);
|
|
203
|
+
}
|
|
204
|
+
ensure(sha(bytes) === entry.artifact.sha256, `Integrity check failed for ${entry.id}`, 'EINTEGRITY');
|
|
205
|
+
return decodeBundle(bytes, entry);
|
|
206
|
+
}
|
package/dist/cli.d.ts
ADDED