@xynogen/pix-skills 0.7.4 → 0.7.6

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 CHANGED
@@ -164,7 +164,7 @@ as `/skill:<name>` slash commands.
164
164
  | `task` | Task orchestration and ambiguity resolution |
165
165
  | `test` | Test execution, analysis, and failure resolution via TDD |
166
166
  | `tldr` | Maximum-density technical summary, zero filler |
167
- | `toon` | Handle information-dense JSON with jq + TOON compression |
167
+ | `toon-json` | On-demand jq + TOON workflow for information-dense JSON |
168
168
  | `ui` | UI/UX design and implementation guidance for frontends |
169
169
  | `verify` | Verification before completion — confirm it's actually fixed |
170
170
  | `subagent` | Plan, decompose, and fan out independent units to cheaper parallel subagent workers |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-skills",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "description": "Pi extension — agent skill loader (skill tool + skills bundle)",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -49,6 +49,6 @@
49
49
  "@xynogen/pix-data": "^0.4.0",
50
50
  "@xynogen/pix-gate": "^0.2.0",
51
51
  "@xynogen/pix-pretty": "^1.7.20",
52
- "@xynogen/pix-runtime": "^0.3.0"
52
+ "@xynogen/pix-runtime": "^0.4.0"
53
53
  }
54
54
  }
@@ -1,17 +1,18 @@
1
1
  ---
2
- name: toon
3
- description: Manipulate information-dense JSON efficiently with jq + TOON. Use when fetching/reading large or repetitive JSON (LLM schemas, OpenAPI specs, API responses, datasets, config dumps) into context. Query/reshape with jq, compress to TOON to cut tokens, decode back to JSON only when a strict contract needs it.
2
+ name: toon-json
3
+ description: Manipulate information-dense JSON efficiently with jq + TOON. Use when fetching or reading large, repetitive JSON such as LLM schemas, OpenAPI specs, API responses, datasets, and config dumps. Query and reshape with jq, compress to TOON for context, and decode back only when a strict JSON contract requires it.
4
4
  disable-model-invocation: true
5
5
  ---
6
6
 
7
7
  # TOON + jq: Dense JSON Workflow
8
8
 
9
9
  ## Goal
10
+
10
11
  Carry only the JSON slice you need, in the cheapest encoding. Query with `jq`,
11
12
  compress with `toon`, and round-trip back to JSON **only** when a contract
12
13
  requires strict JSON.
13
14
 
14
- TOON (Token-Oriented Object Notation, https://github.com/toon-format/spec) is a
15
+ TOON (Token-Oriented Object Notation, <https://github.com/toon-format/spec>) is a
15
16
  line-oriented encoding of the JSON data model. Uniform arrays of objects declare
16
17
  their keys once and stream bare rows, so token cost drops sharply on tabular and
17
18
  dense data.
@@ -37,6 +38,7 @@ cat data.toon | toon --decode
37
38
  or `-d` (decode TOON→JSON).
38
39
 
39
40
  ### Useful flags
41
+
40
42
  - `--stats` — print token/byte statistics for the conversion
41
43
  - `--delimiter=,|\t|"|"` — array delimiter (comma default; tab/pipe can tokenize better)
42
44
  - `--keyFolding=safe` — collapse single-key nesting chains
@@ -58,6 +60,7 @@ TOON is not always smaller. Pick based on shape:
58
60
  Rule of thumb: **TOON for reading dense data into context. JSON for contracts.**
59
61
 
60
62
  ## When NOT to use TOON
63
+
61
64
  - Anything sent to or stored by an API that expects JSON.
62
65
  - Data a downstream tool/parser must consume as strict JSON.
63
66
  - Deeply nested config trees or highly irregular structures.
@@ -73,6 +76,7 @@ LLM model list (uniform array → great TOON candidate):
73
76
  ```bash
74
77
  curl -s https://api.example.com/v1/models | jq '.data | map({id, owned_by, context})' | toon
75
78
  ```
79
+
76
80
  ```
77
81
  [3]{id,owned_by,context}:
78
82
  gpt-x,acme,128000
@@ -96,6 +100,7 @@ curl -s -X POST https://api.example.com/ingest -d "$RESHAPED"
96
100
  ```
97
101
 
98
102
  ## Checklist
103
+
99
104
  1. **Query** — narrow with `jq` to the exact slice needed.
100
105
  2. **Decide** — uniform/tabular/shallow → TOON; nested/array-of-arrays/contract → JSON.
101
106
  3. **Compress** — `| toon` (add `--stats` to confirm savings).
package/src/index.test.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { afterEach, describe, expect, it } from "bun:test";
1
+ import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test";
2
2
  import { mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
+ import { pixRuntime } from "@xynogen/pix-runtime/config";
6
+ import { ioSection } from "@xynogen/pix-runtime/sections";
5
7
 
6
8
  import registerSkills, {
7
9
  copySkillResource,
@@ -37,6 +39,18 @@ description: Split, write, and maintain commits.
37
39
  # Commit Directive
38
40
  body...`;
39
41
 
42
+ describe("bundled TOON skill", () => {
43
+ it("is model-discoverable on demand and owns the jq + TOON workflow", async () => {
44
+ const skill = await Bun.file(new URL("../skills/toon-json.md", import.meta.url)).text();
45
+
46
+ expect(extractName(skill)).toBe("toon-json");
47
+ expect(extractDescription(skill)).toContain("information-dense JSON");
48
+ expect(skill).toContain("disable-model-invocation: true");
49
+ expect(skill).toContain("jq '.data'");
50
+ expect(skill).toContain("toon -d");
51
+ });
52
+ });
53
+
40
54
  describe("extractName", () => {
41
55
  it("reads name from YAML frontmatter", () => {
42
56
  expect(extractName(FRONTMATTER)).toBe("commit");
@@ -164,6 +178,41 @@ describe("formatCollapsedSkillResult", () => {
164
178
  });
165
179
  });
166
180
 
181
+ describe("remote skill timeout config", () => {
182
+ beforeEach(async () => {
183
+ await pixRuntime().update(ioSection, { timeoutSec: 30 });
184
+ });
185
+
186
+ it("passes the configured timeout and tool cancellation signal to fetch", async () => {
187
+ await pixRuntime().update(ioSection, { timeoutSec: 120 });
188
+ const controller = new AbortController();
189
+ let seenRequest: RequestInit | undefined;
190
+ const originalFetch = globalThis.fetch;
191
+ globalThis.fetch = mock((_input: string | URL | Request, init?: RequestInit) => {
192
+ seenRequest = init;
193
+ return Promise.resolve(new Response(JSON.stringify({ skills: [] }), { status: 200 }));
194
+ }) as unknown as typeof fetch;
195
+ try {
196
+ let registered: Record<string, unknown> = {};
197
+ registerSkills({
198
+ registerTool(tool: unknown) {
199
+ registered = tool as Record<string, unknown>;
200
+ },
201
+ on() {},
202
+ } as never);
203
+ const execute = registered.execute as (...args: unknown[]) => Promise<unknown>;
204
+ await execute("call", { search: "typescript" }, controller.signal, undefined, {});
205
+ const requestSignal = seenRequest?.signal;
206
+ expect(requestSignal).toBeDefined();
207
+ expect(requestSignal).not.toBe(controller.signal);
208
+ expect(requestSignal?.aborted).toBe(false);
209
+ } finally {
210
+ globalThis.fetch = originalFetch;
211
+ await pixRuntime().update(ioSection, { timeoutSec: 30 });
212
+ }
213
+ });
214
+ });
215
+
167
216
  describe("skill renderer", () => {
168
217
  it("uses the self-rendered shell so the compact status mark has no box padding", () => {
169
218
  let registered: Record<string, unknown> = {};
package/src/index.ts CHANGED
@@ -20,6 +20,7 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
20
20
  import { Text } from "@earendil-works/pi-tui";
21
21
  import { formatCollapsedToolRow, hideCollapsedToolCall } from "@xynogen/pix-pretty/utils";
22
22
  import { type CollapseState, tickCollapse } from "@xynogen/pix-runtime/collapse";
23
+ import { ioTimeoutMs } from "@xynogen/pix-runtime/io";
23
24
  import { once } from "@xynogen/pix-runtime/once";
24
25
  import { Type } from "typebox";
25
26
  import {
@@ -487,7 +488,7 @@ function registerSkillLoader(pi: ExtensionAPI): void {
487
488
  executionMode: "sequential",
488
489
  parameters: ParamsSchema,
489
490
 
490
- async execute(_toolCallId, params, _signal, _upd, toolCtx) {
491
+ async execute(_toolCallId, params, signal, _upd, toolCtx) {
491
492
  const ok = (text: string, details: SkillResultDetails) => ({
492
493
  content: [{ type: "text" as const, text }],
493
494
  details,
@@ -510,7 +511,10 @@ function registerSkillLoader(pi: ExtensionAPI): void {
510
511
 
511
512
  if (search) {
512
513
  try {
513
- const results = await searchRemoteSkills(search);
514
+ const results = await searchRemoteSkills(search, fetch, {
515
+ signal,
516
+ timeoutMs: ioTimeoutMs(),
517
+ });
514
518
  return ok(formatRemoteSkillSearch(search, results), {
515
519
  mode: "search",
516
520
  query: search,
@@ -542,7 +546,11 @@ function registerSkillLoader(pi: ExtensionAPI): void {
542
546
  let remoteCached: boolean | undefined;
543
547
  if (source) {
544
548
  try {
545
- const remote = await fetchRemoteSkill(source, name, { refresh });
549
+ const remote = await fetchRemoteSkill(source, name, {
550
+ refresh,
551
+ signal,
552
+ timeoutMs: ioTimeoutMs(),
553
+ });
546
554
  entry = { name: remote.name, path: remote.path, root: remote.root };
547
555
  remoteSource = remote.source;
548
556
  remoteCached = remote.cached;
@@ -50,6 +50,23 @@ describe("Skills.sh search", () => {
50
50
  it("rejects undersized queries", async () => {
51
51
  expect(searchRemoteSkills("x")).rejects.toThrow("between 2 and 200");
52
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
+ });
53
70
  });
54
71
 
55
72
  describe("remote skill fetching", () => {
@@ -112,6 +129,32 @@ describe("remote skill fetching", () => {
112
129
  expect(calls).toHaveLength(callCount);
113
130
  });
114
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
+
115
158
  it("requires the selected skill name to match frontmatter", async () => {
116
159
  const root = await mkdtemp(join(tmpdir(), "pix-remote-skill-"));
117
160
  roots.push(root);
package/src/remote.ts CHANGED
@@ -28,6 +28,45 @@ export interface RemoteSkillEntry {
28
28
 
29
29
  type FetchLike = typeof fetch;
30
30
 
31
+ type RemoteRequestOptions = {
32
+ signal?: AbortSignal;
33
+ timeoutMs?: number;
34
+ };
35
+
36
+ async function withRemoteDeadline<T>(
37
+ options: RemoteRequestOptions,
38
+ operation: (signal: AbortSignal) => Promise<T>,
39
+ ): Promise<T> {
40
+ const timeoutMs = options.timeoutMs ?? 30_000;
41
+ const controller = new AbortController();
42
+ let timedOut = false;
43
+ const cancel = () => controller.abort(options.signal?.reason);
44
+
45
+ if (options.signal?.aborted) cancel();
46
+ else options.signal?.addEventListener("abort", cancel, { once: true });
47
+
48
+ const timer = setTimeout(() => {
49
+ timedOut = true;
50
+ controller.abort();
51
+ }, timeoutMs);
52
+ timer.unref?.();
53
+
54
+ try {
55
+ if (controller.signal.aborted) throw new Error("Remote request cancelled");
56
+ return await operation(controller.signal);
57
+ } catch (error) {
58
+ if (timedOut) {
59
+ const duration = timeoutMs % 1000 === 0 ? `${timeoutMs / 1000} seconds` : `${timeoutMs} ms`;
60
+ throw new Error(`Remote request timed out after ${duration}`);
61
+ }
62
+ if (options.signal?.aborted) throw new Error("Remote request cancelled");
63
+ throw error;
64
+ } finally {
65
+ clearTimeout(timer);
66
+ options.signal?.removeEventListener("abort", cancel);
67
+ }
68
+ }
69
+
31
70
  function validatePart(value: string, label: string): string {
32
71
  const trimmed = value.trim();
33
72
  if (!SLUG.test(trimmed) || trimmed === "." || trimmed === "..") {
@@ -58,38 +97,44 @@ export function remoteSkillsCacheRoot(): string {
58
97
  export async function searchRemoteSkills(
59
98
  query: string,
60
99
  fetcher: FetchLike = fetch,
100
+ options: RemoteRequestOptions = {},
61
101
  ): Promise<RemoteSkillSearchResult[]> {
62
102
  const trimmed = query.trim();
63
103
  if (trimmed.length < 2 || trimmed.length > 200) {
64
104
  throw new Error("Skills.sh search query must be between 2 and 200 characters");
65
105
  }
66
- const url = `${SKILLS_SH}/api/search?${new URLSearchParams({ q: trimmed, limit: "10" })}`;
67
- const response = await fetcher(url, { headers: { Accept: "application/json" } });
68
- if (!response.ok) throw new Error(`Skills.sh search failed (${response.status})`);
69
- const data = (await response.json()) as {
70
- skills?: Array<{ id?: unknown; name?: unknown; installs?: unknown; source?: unknown }>;
71
- };
72
- return (data.skills ?? []).flatMap((skill) => {
73
- if (
74
- typeof skill.id !== "string" ||
75
- typeof skill.name !== "string" ||
76
- typeof skill.source !== "string"
77
- )
78
- return [];
79
- try {
80
- parseGitHubSource(skill.source);
81
- validatePart(skill.name, "skill name");
82
- return [
83
- {
84
- name: skill.name,
85
- slug: skill.id,
86
- source: skill.source,
87
- installs: typeof skill.installs === "number" ? skill.installs : 0,
88
- },
89
- ];
90
- } catch {
91
- return [];
92
- }
106
+ return withRemoteDeadline(options, async (signal) => {
107
+ const url = `${SKILLS_SH}/api/search?${new URLSearchParams({ q: trimmed, limit: "10" })}`;
108
+ const response = await fetcher(url, {
109
+ headers: { Accept: "application/json" },
110
+ signal,
111
+ });
112
+ if (!response.ok) throw new Error(`Skills.sh search failed (${response.status})`);
113
+ const data = (await response.json()) as {
114
+ skills?: Array<{ id?: unknown; name?: unknown; installs?: unknown; source?: unknown }>;
115
+ };
116
+ return (data.skills ?? []).flatMap((skill) => {
117
+ if (
118
+ typeof skill.id !== "string" ||
119
+ typeof skill.name !== "string" ||
120
+ typeof skill.source !== "string"
121
+ )
122
+ return [];
123
+ try {
124
+ parseGitHubSource(skill.source);
125
+ validatePart(skill.name, "skill name");
126
+ return [
127
+ {
128
+ name: skill.name,
129
+ slug: skill.id,
130
+ source: skill.source,
131
+ installs: typeof skill.installs === "number" ? skill.installs : 0,
132
+ },
133
+ ];
134
+ } catch {
135
+ return [];
136
+ }
137
+ });
93
138
  });
94
139
  }
95
140
 
@@ -102,9 +147,13 @@ function frontmatterName(content: string): string | null {
102
147
  async function fetchBytes(
103
148
  fetcher: FetchLike,
104
149
  url: string,
150
+ signal: AbortSignal,
105
151
  maxBytes = MAX_FILE_BYTES,
106
152
  ): Promise<Buffer> {
107
- const response = await fetcher(url, { headers: { Accept: "application/vnd.github+json" } });
153
+ const response = await fetcher(url, {
154
+ headers: { Accept: "application/vnd.github+json" },
155
+ signal,
156
+ });
108
157
  if (!response.ok) throw new Error(`Remote request failed (${response.status}): ${url}`);
109
158
  const declared = Number(response.headers.get("content-length") ?? "0");
110
159
  if (declared > maxBytes) throw new Error(`Remote file exceeds ${maxBytes} byte limit`);
@@ -116,9 +165,10 @@ async function fetchBytes(
116
165
  async function fetchText(
117
166
  fetcher: FetchLike,
118
167
  url: string,
168
+ signal: AbortSignal,
119
169
  maxBytes = MAX_FILE_BYTES,
120
170
  ): Promise<string> {
121
- return (await fetchBytes(fetcher, url, maxBytes)).toString("utf-8");
171
+ return (await fetchBytes(fetcher, url, signal, maxBytes)).toString("utf-8");
122
172
  }
123
173
 
124
174
  function safeDestination(root: string, relativePath: string): string {
@@ -128,10 +178,11 @@ function safeDestination(root: string, relativePath: string): string {
128
178
  return destination;
129
179
  }
130
180
 
131
- export async function fetchRemoteSkill(
181
+ async function fetchRemoteSkillWithSignal(
132
182
  source: string,
133
183
  name: string,
134
- options: { refresh?: boolean; fetcher?: FetchLike; cacheRoot?: string } = {},
184
+ options: { refresh?: boolean; fetcher?: FetchLike; cacheRoot?: string },
185
+ signal: AbortSignal,
135
186
  ): Promise<RemoteSkillEntry> {
136
187
  const { owner, repo } = parseGitHubSource(source);
137
188
  const skillName = validatePart(name, "skill name");
@@ -152,6 +203,7 @@ export async function fetchRemoteSkill(
152
203
  const treeText = await fetchText(
153
204
  fetcher,
154
205
  `${GITHUB_API}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/git/trees/HEAD?recursive=1`,
206
+ signal,
155
207
  MAX_BUNDLE_BYTES,
156
208
  );
157
209
  let tree: {
@@ -181,7 +233,7 @@ export async function fetchRemoteSkill(
181
233
  .split("/")
182
234
  .map(encodeURIComponent)
183
235
  .join("/")}`;
184
- const content = await fetchText(fetcher, raw);
236
+ const content = await fetchText(fetcher, raw, signal);
185
237
  if (frontmatterName(content) === skillName) {
186
238
  skillPath = candidate.path;
187
239
  skillContent = content;
@@ -215,6 +267,7 @@ export async function fetchRemoteSkill(
215
267
  let writtenBytes = 0;
216
268
  try {
217
269
  for (const file of allowed) {
270
+ signal.throwIfAborted();
218
271
  const rel = file.path.slice(prefix.length);
219
272
  const destination = safeDestination(temporary, rel);
220
273
  await mkdir(dirname(destination), { recursive: true });
@@ -225,7 +278,7 @@ export async function fetchRemoteSkill(
225
278
  .split("/")
226
279
  .map(encodeURIComponent)
227
280
  .join("/")}`;
228
- content = await fetchBytes(fetcher, raw);
281
+ content = await fetchBytes(fetcher, raw, signal);
229
282
  }
230
283
  writtenBytes += content.byteLength;
231
284
  if (writtenBytes > MAX_BUNDLE_BYTES) {
@@ -251,3 +304,19 @@ export async function fetchRemoteSkill(
251
304
  cached: false,
252
305
  };
253
306
  }
307
+
308
+ export async function fetchRemoteSkill(
309
+ source: string,
310
+ name: string,
311
+ options: {
312
+ refresh?: boolean;
313
+ fetcher?: FetchLike;
314
+ cacheRoot?: string;
315
+ signal?: AbortSignal;
316
+ timeoutMs?: number;
317
+ } = {},
318
+ ): Promise<RemoteSkillEntry> {
319
+ return withRemoteDeadline(options, (signal) =>
320
+ fetchRemoteSkillWithSignal(source, name, options, signal),
321
+ );
322
+ }