@reddb-io/red-skills 4.4.0 → 4.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/bin/build-info.mjs +87 -0
- package/bin/cli-frontdoor.mjs +14 -0
- package/bin/red-skills-brain.mjs +17 -22
- package/bin/red-skills-content.mjs +17 -0
- package/bin/red-skills-hook.mjs +45 -0
- package/bin/red-skills-memory.mjs +17 -22
- package/bin/red-skills-redskilled-mcp.mjs +2 -0
- package/bin/red-skills-resource.mjs +21 -0
- package/bin/runtime-compatibility.mjs +17 -0
- package/bin/runtime-paths.mjs +13 -0
- package/dist/code-nav.bundle.min.mjs +1 -1
- package/dist/opencode-host.bundle.min.mjs +1 -1
- package/dist/redskilled-mcp.bundle.min.mjs +36 -36
- package/dist/redskilled.bundle.min.mjs +234 -230
- package/dist/release.bundle.min.mjs +1 -1
- package/dist/rsp-core.bundle.min.mjs +1 -1
- package/dist/rsp.bundle.min.mjs +1 -1
- package/dist/statusline.bundle.min.mjs +1 -1
- package/package.json +9 -4
- package/runtime/hook-routes.json +125 -0
- package/runtime/plugins/brain/scripts/bootstrap.mjs +656 -0
- package/runtime/plugins/brain/scripts/structural-smoke.sh +7 -0
- package/runtime/plugins/dev/hooks/branch-lock-codex.sh +105 -0
- package/runtime/plugins/dev/hooks/code-nav-mcp.sh +63 -0
- package/runtime/plugins/dev/hooks/command-guard.sh +893 -0
- package/runtime/plugins/dev/hooks/ensure-codex-statusline.mjs +144 -0
- package/runtime/plugins/dev/hooks/red-fetch.mjs +38 -0
- package/runtime/plugins/dev/hooks/redskilled-mcp.sh +64 -0
- package/runtime/plugins/dev/hooks/rsp-hook.sh +343 -0
- package/runtime/plugins/dev/hooks/tests/command-guard.test.sh +378 -0
- package/runtime/plugins/dev/hooks/tests/rsp-hook.test.sh +229 -0
- package/runtime/plugins/dev/scripts/memory-bridge.sh +230 -0
- package/runtime/plugins/dev/scripts/structural-smoke.sh +7 -0
- package/runtime/plugins/dev/scripts/tests/memory-bridge.test.sh +555 -0
- package/runtime/plugins/dev/skills/engineering/afk/defaults/cargo-pre-worktree.sh +37 -0
- package/runtime/plugins/dev/skills/engineering/afk/defaults/envelope-post-attempt.sh +47 -0
- package/runtime/plugins/dev/skills/engineering/afk/defaults/gradle-pre-worktree.sh +45 -0
- package/runtime/plugins/dev/skills/engineering/afk/defaults/heartbeat-post-attempt.sh +43 -0
- package/runtime/plugins/dev/skills/engineering/afk/defaults/validation-post-merge.sh +77 -0
- package/runtime/plugins/dev/skills/engineering/afk/detectors/cargo.sh +27 -0
- package/runtime/plugins/dev/skills/engineering/afk/detectors/gradle.sh +38 -0
- package/runtime/plugins/dev/skills/engineering/afk/examples/only-mine.sh +32 -0
- package/runtime/plugins/dev/skills/engineering/afk/examples/red-afk-attempt-action.yml +53 -0
- package/runtime/plugins/dev/skills/engineering/afk/examples/rs-afk-attempt.yml +76 -0
- package/runtime/plugins/dev/skills/engineering/afk/hooks/red-cargo +38 -0
- package/runtime/plugins/dev/skills/engineering/afk/hooks/red-envelope +50 -0
- package/runtime/plugins/dev/skills/engineering/afk/hooks/red-gradle +42 -0
- package/runtime/plugins/dev/skills/engineering/afk/hooks/red-heartbeat +46 -0
- package/runtime/plugins/dev/skills/engineering/afk/hooks/red-validation +79 -0
- package/runtime/plugins/dev/skills/engineering/diagnose/scripts/hitl-loop.template.sh +41 -0
- package/runtime/plugins/dev/skills/engineering/red-setup/scripts/install-runtime-shim.sh +181 -0
- package/runtime/plugins/dev/skills/engineering/red-setup/workflows/red-issues-needs-triage.yml +36 -0
- package/runtime/plugins/dev/skills/engineering/wizard/template.sh +211 -0
- package/runtime/plugins/dev/skills/engineering/zoom-out/scripts/graph-mode-plumbing.sh +36 -0
- package/runtime/plugins/dev/skills/engineering/zoom-out/scripts/tests/contract.test.sh +168 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/branch-lock-hook.sh +113 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/branch-lock-session-start.sh +81 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/branch-lock.sh +68 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/lib/dev-config.sh +126 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/lib/git-command-classifier.sh +198 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/lib/lock-store.sh +67 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/lib/scope-resolver.sh +43 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/tests/branch-lock-cli.test.sh +114 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/tests/claude-plugin-hook.test.sh +117 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/tests/codex-hook.test.sh +230 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/tests/dev-config.test.sh +99 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/tests/git-command-classifier.test.sh +187 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/tests/lock-store.test.sh +90 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/tests/scope-resolver.test.sh +63 -0
- package/runtime/plugins/dev/skills/misc/branch-lock/scripts/tests/session-start.test.sh +123 -0
- package/runtime/plugins/dev/skills/misc/git-guardrails-claude-code/scripts/block-dangerous-git.sh +231 -0
- package/runtime/plugins/dev/skills/misc/git-guardrails-claude-code/scripts/tests/block-dangerous-git.test.sh +143 -0
- package/runtime/plugins/internal/scripts/structural-smoke.sh +7 -0
- package/runtime/plugins/internal/skills/maintainer/create-plugin/scripts/create-plugin.sh +308 -0
- package/runtime/plugins/memory/scripts/bootstrap.mjs +659 -0
- package/runtime/plugins/memory/scripts/structural-smoke.sh +7 -0
- package/scripts/check-skills-boundary.mjs +32 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// RedSkills · Codex statusline ensure (session_start hook)
|
|
3
|
+
//
|
|
4
|
+
// Codex's footer is global config (`~/.codex/config.toml` -> `[tui].status_line`,
|
|
5
|
+
// builtin widgets) with no command hook, so the RedSkills line cannot be injected
|
|
6
|
+
// the way it is on Claude Code. Worse: when Codex re-syncs plugin `[hooks.state]`
|
|
7
|
+
// on update it can rewrite config.toml and drop the `[tui]` section, blanking the
|
|
8
|
+
// footer. This hook re-asserts `status_line` at every session start.
|
|
9
|
+
//
|
|
10
|
+
// Safety contract (do not weaken):
|
|
11
|
+
// - ADDITIVE ONLY: insert `status_line` solely when it is absent. Never clobber
|
|
12
|
+
// an existing value — the operator's own choice always wins.
|
|
13
|
+
// - ATOMIC WRITE: temp file + rename, so a race with Codex's own writer can lose
|
|
14
|
+
// the update but can never corrupt config.toml.
|
|
15
|
+
// - BEST EFFORT: any error is swallowed; the hook still emits `{}` so Codex's
|
|
16
|
+
// session start is never blocked.
|
|
17
|
+
//
|
|
18
|
+
// The default widget set matches the statusline SKILL.md Codex recommendation.
|
|
19
|
+
|
|
20
|
+
import { readFileSync, writeFileSync, renameSync, existsSync } from "node:fs";
|
|
21
|
+
import { homedir } from "node:os";
|
|
22
|
+
import { dirname, join } from "node:path";
|
|
23
|
+
|
|
24
|
+
const DEFAULT_STATUS_LINE =
|
|
25
|
+
'["project", "git-branch", "model-with-reasoning", "context-remaining", "task-progress"]';
|
|
26
|
+
const HOOK_TIMEOUT_MS = Number(process.env.RED_SKILLS_HOOK_TIMEOUT_MS || 5000);
|
|
27
|
+
const STDIN_TIMEOUT_MS = Number(process.env.RED_SKILLS_HOOK_STDIN_TIMEOUT_MS || 5000);
|
|
28
|
+
|
|
29
|
+
function emitAndExit() {
|
|
30
|
+
// Codex hook contract: pass the context through unchanged.
|
|
31
|
+
process.stdout.write("{}");
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const hookDeadline = setTimeout(emitAndExit, Number.isFinite(HOOK_TIMEOUT_MS) ? HOOK_TIMEOUT_MS : 5000);
|
|
36
|
+
hookDeadline.unref();
|
|
37
|
+
|
|
38
|
+
async function drainStdin() {
|
|
39
|
+
const timeoutMs = Number.isFinite(STDIN_TIMEOUT_MS) ? STDIN_TIMEOUT_MS : 5000;
|
|
40
|
+
await new Promise((resolve) => {
|
|
41
|
+
const done = () => {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
process.stdin.off("data", onData);
|
|
44
|
+
process.stdin.off("end", done);
|
|
45
|
+
process.stdin.off("error", done);
|
|
46
|
+
process.stdin.pause();
|
|
47
|
+
resolve();
|
|
48
|
+
};
|
|
49
|
+
const onData = () => {};
|
|
50
|
+
const timer = setTimeout(done, timeoutMs);
|
|
51
|
+
timer.unref();
|
|
52
|
+
process.stdin.on("data", onData);
|
|
53
|
+
process.stdin.once("end", done);
|
|
54
|
+
process.stdin.once("error", done);
|
|
55
|
+
process.stdin.resume();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ── Per-directory plugin gate (ADR 0067) ─────────────────────────────────────
|
|
60
|
+
// This hook mutates the user's GLOBAL ~/.codex/config.toml, so it must never run
|
|
61
|
+
// for a project that did not opt into the dev plugin. Mirror of
|
|
62
|
+
// packages/shared/plugin-gate.ts (strict opt-in over the constrained YAML).
|
|
63
|
+
function flatConfigValue(text, dottedKey) {
|
|
64
|
+
const stack = [];
|
|
65
|
+
for (const rawLine of text.split("\n")) {
|
|
66
|
+
const line = rawLine.replace(/\r$/, "");
|
|
67
|
+
const trimmed = line.trim();
|
|
68
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
69
|
+
const colon = line.indexOf(":");
|
|
70
|
+
if (colon < 0) continue;
|
|
71
|
+
const indent = line.length - line.trimStart().length;
|
|
72
|
+
const key = line.slice(0, colon).trim();
|
|
73
|
+
if (!key) continue;
|
|
74
|
+
let value = line.slice(colon + 1).trim();
|
|
75
|
+
const hash = value.indexOf(" #");
|
|
76
|
+
if (hash >= 0) value = value.slice(0, hash).trim();
|
|
77
|
+
while (stack.length && stack[stack.length - 1].indent >= indent) stack.pop();
|
|
78
|
+
stack.push({ indent, key });
|
|
79
|
+
if (value && stack.map((s) => s.key).join(".") === dottedKey) return value;
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
function devEnabled(cwd) {
|
|
84
|
+
let dir = cwd;
|
|
85
|
+
for (let i = 0; i < 16; i++) {
|
|
86
|
+
const candidate = join(dir, ".red", "config.yaml");
|
|
87
|
+
if (existsSync(candidate)) {
|
|
88
|
+
try {
|
|
89
|
+
return flatConfigValue(readFileSync(candidate, "utf8"), "plugins.dev.enabled") === "true";
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const parent = dirname(dir);
|
|
95
|
+
if (parent === dir) break;
|
|
96
|
+
dir = parent;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Drain stdin with a deadline so the producer never blocks; ignore the payload.
|
|
102
|
+
await drainStdin();
|
|
103
|
+
|
|
104
|
+
// Gate before touching any global config: dormant unless dev is enabled here.
|
|
105
|
+
if (!devEnabled(process.cwd())) emitAndExit();
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const cfgPath = join(homedir(), ".codex", "config.toml");
|
|
109
|
+
if (!existsSync(cfgPath)) emitAndExit();
|
|
110
|
+
|
|
111
|
+
const text = readFileSync(cfgPath, "utf8");
|
|
112
|
+
const lines = text.split("\n");
|
|
113
|
+
|
|
114
|
+
// Locate the [tui] table header.
|
|
115
|
+
let tuiHeader = -1;
|
|
116
|
+
for (let i = 0; i < lines.length; i++) {
|
|
117
|
+
if (/^\s*\[tui\]\s*(#.*)?$/.test(lines[i])) {
|
|
118
|
+
tuiHeader = i;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (tuiHeader >= 0) {
|
|
124
|
+
// Scan the [tui] table body (until the next table header or EOF) for an
|
|
125
|
+
// existing status_line key. If present, respect it and do nothing.
|
|
126
|
+
for (let i = tuiHeader + 1; i < lines.length; i++) {
|
|
127
|
+
if (/^\s*\[/.test(lines[i])) break; // next table — key not found
|
|
128
|
+
if (/^\s*status_line\s*=/.test(lines[i])) emitAndExit(); // already set
|
|
129
|
+
}
|
|
130
|
+
lines.splice(tuiHeader + 1, 0, `status_line = ${DEFAULT_STATUS_LINE}`);
|
|
131
|
+
} else {
|
|
132
|
+
// No [tui] table at all — append one.
|
|
133
|
+
if (lines.length && lines[lines.length - 1] !== "") lines.push("");
|
|
134
|
+
lines.push("[tui]", `status_line = ${DEFAULT_STATUS_LINE}`, "");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const tmpPath = `${cfgPath}.redskills.tmp`;
|
|
138
|
+
writeFileSync(tmpPath, lines.join("\n"));
|
|
139
|
+
renameSync(tmpPath, cfgPath); // atomic on the same filesystem
|
|
140
|
+
} catch {
|
|
141
|
+
/* best effort — never block session start */
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
emitAndExit();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
3
|
+
import{pathToFileURL as qr}from"node:url";import{spawn as Gr,spawnSync as Yr}from"node:child_process";import{createHash as Qr}from"node:crypto";import{existsSync as Xr,readFileSync as Zr}from"node:fs";import{appendFile as ei,mkdir as Ge,readFile as ti,readdir as ni,rename as ln,writeFile as ri}from"node:fs/promises";import{homedir as dn}from"node:os";import{dirname as ii,join as q}from"node:path";var D="@reddb-io/red-skills",bn="https://registry.npmjs.org",nt="canary",T=class extends Error{kind;cause;constructor(t,n,r){super(n),this.name="BundleFetchError",this.kind=t,this.cause=r}},wn=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/;function G(e){return typeof e=="string"&&wn.test(e.trim())}function rt(e){return`${e}-.bundle.min.mjs`}var xn=".unversioned";function Sn(e,t,n="stable"){if(n==="canary")return`${e}-canary.bundle.min.mjs`;if(!G(t))throw new T("invalid-version",`refusing to key the ${e} bundle cache on ${JSON.stringify(t??"")}: it would mint ${rt(e)}, a name no resolver prefers and one whose mere existence satisfies the cache-first test forever (#3153)`);return`${e}-${t.trim()}.bundle.min.mjs`}function N(e){let{plugin:t,version:n,cacheDir:r,channel:i}=e;return j(r,Sn(t,n,i))}var U="redskilled";function ie(e){return e===U?["rsp","rsp-core"]:[]}function On(e){return`${e}.bundle.min.mjs`}function it(e){return j("dist",On(e))}function An(e,t,n){if(!G(t))throw new T("invalid-version",`refusing to resolve the installed ${e} bundle for ${JSON.stringify(t??"")}`);let r=j(j(n,"versions"),`v${t.trim()}`);return j(r,it(e))}function Ze(e,t="stable"){return`${D}@${t==="canary"?nt:e}`}var kn=new Set(["code-nav",U,...ie(U)]);function st(e){return kn.has(e)?D:`${D}-${e}`}function et(e,t,n="stable"){let r=n==="canary"?nt:t;return`${st(e)}@${r}`}function En(e=D){return`${bn}/${e.replace("/","%2F")}`}async function se(e,t){let{plugin:n,version:r,cacheDir:i,installRoot:o,channel:s="stable"}=t,c=N({plugin:n,version:r,cacheDir:i,channel:s}),u=ie(n),a=u.map(y=>N({plugin:y,version:r,cacheDir:i,channel:s}));if(s!=="canary"&&o){let y=An(n,r,o);if(await e.exists(y))return y}if(s!=="canary"&&await e.exists(c)&&await $n(e,a))return c;let l=st(n),d=et(n,r,s),f=j(i,`.staging-${n}-${s==="canary"?"canary":r}`),m,p;if(s==="canary"&&l!==D){p=Ze(r,s);try{m=await e.materialize(p,`${f}-core`);let y=JSON.parse(new TextDecoder().decode(await e.readFile(j(m,"package.json"))));if(typeof y.version!="string"||!G(y.version))throw new Error("package.json has no cacheable version");d=et(n,y.version)}catch(y){throw y instanceof T?y:re(y,p)}}let b;try{b=await e.materialize(d,f)}catch(y){throw re(y,d)}let _=new Map([[n,{root:b,spec:d}]]);if(u.length>0&&l!==D&&!m){p=Ze(r,s);try{m=await e.materialize(p,`${f}-core`)}catch(y){throw re(y,p)}}if(m&&p)for(let y of u)_.set(y,{root:m,spec:p});for(let y of[n,...u]){let C=_.get(y)??{root:b,spec:d},M=it(y),ne=j(C.root,M);if(!await e.exists(ne))throw new T("bundle-missing",`npm package ${C.spec} has no ${M}`);let gn=y===n?c:N({plugin:y,version:r,cacheDir:i,channel:s});await e.writeFile(gn,await e.readFile(ne))}return await Tn(e,i,[n,...u]),c}async function Tn(e,t,n){if(e.rename)for(let r of n){let i=j(t,rt(r));try{if(!await e.exists(i))continue;await e.rename(i,`${i}${xn}`)}catch{}}}async function $n(e,t){for(let n of t)if(!await e.exists(n))return!1;return!0}async function ot(e,t,n=D){let r;try{r=await e.fetchText(En(n))}catch(i){throw re(i,n)}return Cn(Rn(r),t)}function Rn(e){let t;try{t=JSON.parse(e)}catch{return[]}if(typeof t!="object"||t===null)return[];let n=t.versions;return typeof n!="object"||n===null?[]:Object.keys(n)}function Cn(e,t){let n=tt(t);if(n===null)return null;let r=null;for(let i of e)tt(i)===n&&(r===null||Ln(i,r)>0)&&(r=i);return r}function tt(e){let t=/^(\d+)\.(\d+)\.(\d+)/.exec(String(e).trim());return t?Number(t[1]):null}function Ln(e,t){let n=/^(\d+)\.(\d+)\.(\d+)/.exec(e.trim()),r=/^(\d+)\.(\d+)\.(\d+)/.exec(t.trim());return!n||!r?0:Number(n[1])-Number(r[1])||Number(n[2])-Number(r[2])||Number(n[3])-Number(r[3])}function re(e,t){let n=e instanceof Error?e.message:String(e);return/ENOENT|command not found|spawn npm/i.test(n)?new T("npm-unavailable",`npm is unavailable while resolving ${t}: ${n}`,e):/\b404\b|E404|not found|no matching version|notarget/i.test(n)?new T("package-missing",`npm could not resolve ${t}: ${n}`,e):new T("network",`failed to resolve ${t}: ${n}`,e)}function j(e,t){return e.endsWith("/")?`${e}${t}`:`${e}/${t}`}var In=["stable","canary"],jn="stable",Dn="RED_SKILLS_CHANNEL";function ct(e){if(typeof e!="string")return null;let t=e.trim().toLowerCase();return In.includes(t)?t:null}function ut(e={}){let t=ct(e.env?.[Dn]);if(t)return t;let n=ct(e.configValue);return n||jn}import{existsSync as Mn,readFileSync as Nn}from"node:fs";import{dirname as Fn,join as at}from"node:path";function be(e,t){let n=e;for(let r=0;r<16;r++){let i=at(n,t);if(Mn(i))return i;let o=Fn(n);if(o===n)break;n=o}return null}function Pn(e){let t=e.indexOf(" #");return(t>=0?e.slice(0,t):e).trim()}function oe(e,t){let n=[];for(let r of e.split(`
|
|
4
|
+
`)){let i=r.replace(/\r$/,""),o=i.trim();if(!o||o.startsWith("#"))continue;let s=i.indexOf(":");if(s<0)continue;let c=i.length-i.trimStart().length,u=i.slice(0,s).trim();if(!u)continue;let a=i.slice(s+1).trim();for(;n.length&&n[n.length-1].indent>=c;)n.pop();if(n.push({indent:c,key:u}),a&&n.map(d=>d.key).join(".")===t)return Pn(a)}}function vn(e,t){return oe(e,`plugins.${t}.enabled`)==="true"}function we(e,t){let n=be(e,at(".red","config.yaml"));if(!n)return!1;let r;try{r=Nn(n,"utf8")}catch{return!1}return vn(r,t)}var B=class extends SyntaxError{line;source;reason;constructor(t,n={}){let r=n.line===void 0||n.line===0?"":`Line ${n.line}: `;super(r+t,n.cause===void 0?void 0:{cause:n.cause}),this.name="ToonDecodeError",this.line=n.line,this.source=n.source,this.reason=t}},F=class extends SyntaxError{line;source;reason;constructor(t,n,r={}){super(t===0?n:`line ${t}: ${n}`,r.cause===void 0?void 0:{cause:r.cause}),this.name="ToonError",this.line=t,this.source=r.source,this.reason=n}};function h(e,t,n={}){return new F(e,t,n)}var _n=/(?:^\uFEFF?|\n) *#/,xe=class{value;constructor(t){if(_n.test(t))throw new TypeError(`Raw string must not contain a line starting with "#": ${JSON.stringify(t)}`);this.value=t}};function P(e){return e instanceof xe}function L(e){return h(e,"invalid quoted string")}function k(e,t){if(e==="")return"";if(e.startsWith('"'))return ft(e,t);if(e.includes('"'))throw L(t);if(e==="true")return!0;if(e==="false")return!1;if(e==="null")return null;if(Un(e)){let n=Number(e);return Object.is(n,-0)?0:n}return e}function V(e,t){let n=e.trim();if(n.startsWith('"'))return[ft(n,t),!0];if(n.includes('"')||/\s/.test(n))throw h(t,"expected non-empty field name");return[n,!1]}var lt=/["\\\u0000-\u0008\u000a-\u001f]/g;function ft(e,t){if(e.charCodeAt(0)!==34)throw L(t);let n="",r=1;for(;r<e.length;){lt.lastIndex=r;let i=lt.exec(e);if(i===null)break;if(i[0]==='"'){if(e.slice(i.index+1).trim()==="")return n+e.slice(r,i.index);throw L(t)}if(i[0]!=="\\")throw L(t);n+=e.slice(r,i.index);let o=e[i.index+1];switch(r=i.index+2,o){case'"':n+='"';break;case"\\":n+="\\";break;case"n":n+=`
|
|
5
|
+
`;break;case"r":n+="\r";break;case"t":n+=" ";break;case"u":{let s=e.slice(r,r+4);if(!/^[0-9a-fA-F]{4}$/.test(s))throw L(t);let c=Number.parseInt(s,16);if(c>=55296&&c<=57343)throw L(t);n+=String.fromCharCode(c),r+=4;break}default:throw L(t)}}throw L(t)}function ht(e,t,n){for(;;){let r=e.indexOf('"',t),i=e.indexOf("\\",t);if(i!==-1&&(r===-1||i<r)){if(i===e.length-1)throw L(n);t=i+2;continue}if(r===-1)throw L(n);return r+1}}function Y(e,t,n){if(e==="")return[];let r=[],i=0,o=0;for(;o<e.length;){let s=e.indexOf('"',o),c=e.indexOf(t,o);if(c!==-1&&(s===-1||c<s))r.push(e.slice(i,c).trim()),i=c+1,o=c+1;else if(s!==-1)o=ht(e,s+1,n);else break}return r.push(e.slice(i).trim()),r}function $(e,t,n){let r=0;for(;r<e.length;){let i=e.indexOf('"',r),o=e.indexOf(t,r);if(o!==-1&&(i===-1||o<i))return o;if(i===-1)return-1;r=ht(e,i+1,n)}return-1}function Un(e){return/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/.test(e)}function Bn(e){return/^[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/.test(e)}function Vn(e){if(Object.is(e,-0))return"0";if(!Number.isFinite(e))throw h(0,"number is not representable in TOON");return String(e)}function ce(e){return e===null||typeof e=="boolean"||typeof e=="number"||typeof e=="string"}function O(e,t){if(P(e))return e.value;if(e===null)return"null";if(typeof e=="boolean")return e?"true":"false";if(typeof e=="number")return Vn(e);if(typeof e=="string")return Hn(e,t);throw h(0,"not a primitive")}function Wn(e){return/^[A-Za-z_][A-Za-z0-9_.]*$/.test(e)}function S(e){return Wn(e)?e:ue(e)}function Hn(e,t){return Se(e,t)?ue(e):e}function Se(e,t){return e===""||/^[ \t]|[ \t]$/.test(e)||e==="true"||e==="false"||e==="null"||Bn(e)||/[:"\\[\]{}]/.test(e)||/[\u0000-\u001f]/.test(e)||e.includes(t)||e.startsWith("-")||e.startsWith("#")}var dt=/["\\\u0000-\u001f]/g;function ue(e){return`"${mt(e)}"`}function mt(e){let t="",n=0;dt.lastIndex=0;let r;for(;(r=dt.exec(e))!==null;){let i=e.charCodeAt(r.index),o;i===34?o='\\"':i===92?o="\\\\":i===10?o="\\n":i===13?o="\\r":i===9?o="\\t":o=`\\u${i.toString(16).padStart(4,"0")}`,t+=e.slice(n,r.index)+o,n=r.index+1}return`${t}${e.slice(n)}`}function W(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}var pt={comma:",",tab:" ",pipe:"|"},zn=pt.comma;var Q=1e3,yt=["type","kind","event"],v="|",gt=new Set(["order","discriminator","rows","common"]);function*wt(e,t,n,r,i,o,s){yield*xt(n,e,r,t,{index:0},i,s,!0,o)}function*xt(e,t,n,r,i,o,s,c,u){let a=At(e,t,n,r,i.index,o,s),l=0;for(;l<e;){let f=r[i.index];if(f===void 0||f.depth<o)break;if(f.depth>o)throw h(f.number,"invalid indentation");if(f.blankBefore&&s.strict)throw h(f.number,"blank line inside array");if(!ae(f.content,n,f.number))break;let m=Y(f.content,n,f.number),p={cellIndex:0,nextIndex:i.index+1,flatWidth:le(t),childTableFields:a};if(c&&t.length===1&&t[0].fixedLength!==void 0?yield*Ot(t[0],m,p,f.number):(yield{type:"startObject",line:f.number},yield*St(t,m,f,r,p,o+1,n,s),yield{type:"endObject",line:f.number}),p.cellIndex!==m.length)throw h(f.number,"array row length mismatch");i.index=p.nextIndex,l++}if(l!==e)throw Gn(r,i.index,u);let d=r[i.index];if(d!==void 0&&d.depth>=o&&ae(d.content,n,d.number))throw h(d.number,"array length mismatch")}function*St(e,t,n,r,i,o,s,c){for(let u=0;u<e.length;u++){let a=e[u];yield{type:"key",key:a.name,line:n.number},yield*Kn(a,e.slice(u+1),t,n,r,i,o,s,c)}}function*Kn(e,t,n,r,i,o,s,c,u){if(e.fixedLength!==void 0){yield*Ot(e,n,o,r.number);return}if(e.listDelimiter!==void 0){let l=bt(n,o,r.number),d=Y(l,e.listDelimiter,r.number);yield{type:"startArray",length:d.length,line:r.number};for(let f of d)yield{type:"primitive",value:k(f,r.number),line:r.number};yield{type:"endArray",line:r.number};return}if(e.children!==void 0){let l=le(e.children),d=n[o.cellIndex],f=Et(d),m=n.length-o.cellIndex-1,p=i[o.nextIndex],b=p!==void 0&&p.depth===s;if(o.childTableFields?.has(e)??(f!==void 0&&(b||n.length!==o.flatWidth&&m<l+qn(t)))){if(!u.objectArrayColumns||f===void 0)throw h(r.number,"array row length mismatch");o.cellIndex++,yield{type:"startArray",length:f,line:r.number};let C={index:o.nextIndex};yield*xt(f,e.children,c,i,C,s,u,!1,r.number),o.nextIndex=C.index,yield{type:"endArray",line:i[o.nextIndex-1]?.number??r.number};return}yield{type:"startObject",line:r.number},yield*St(e.children,n,r,i,o,s,c,u),yield{type:"endObject",line:r.number};return}let a=bt(n,o,r.number);yield{type:"primitive",value:k(a,r.number),line:r.number}}function*Ot(e,t,n,r){let i=e.fixedLength;if(n.cellIndex+i>t.length)throw h(r,"array row length mismatch");yield{type:"startArray",length:i,line:r};for(let o of t.slice(n.cellIndex,n.cellIndex+i))yield{type:"primitive",value:k(o,r),line:r};n.cellIndex+=i,yield{type:"endArray",line:r}}function bt(e,t,n){let r=e[t.cellIndex];if(r===void 0)throw h(n,"array row length mismatch");return t.cellIndex++,r}function At(e,t,n,r,i,o,s){let c=t.filter(a=>a.children!==void 0);if(c.length===0)return new Set;if(c.length>12)return;let u;for(let a=0;a<1<<c.length;a++){let l=new Set;c.forEach((f,m)=>{a&1<<m&&l.add(f)});let d=kt(e,t,l,n,r,i,o,s);d!==void 0&&(u===void 0||d.consumed>u.consumed||d.consumed===u.consumed&&l.size<u.fields.size)&&(u={fields:l,consumed:d.consumed})}return u?.fields}function kt(e,t,n,r,i,o,s,c){let u=o,a=0;try{for(let d=0;d<e;d++){let f=i[u];if(f===void 0||f.depth!==s||f.blankBefore&&c.strict||!ae(f.content,r,f.number))return;let m=Jn(t,n,Y(f.content,r,f.number),r,i,u+1,s+1,c);if(m===void 0||i[m.nextIndex]?.depth>s)return;u=m.nextIndex,a+=m.consumed}let l=i[u];if(l!==void 0&&l.depth>=s&&ae(l.content,r,l.number))return}catch{return}return{nextIndex:u,consumed:a}}function Jn(e,t,n,r,i,o,s,c){let u=0,a=o,l=0;for(let d of e){if(d.fixedLength!==void 0)u+=d.fixedLength;else if(d.children!==void 0)if(t.has(d)){let f=Et(n[u]);if(f===void 0)return;u++;let m=At(f,d.children,r,i,a,s,c);if(m===void 0)return;let p=kt(f,d.children,m,r,i,a,s,c);if(p===void 0)return;a=p.nextIndex,l+=f+p.consumed}else u+=le(d.children);else u++;if(u>n.length)return}return u===n.length?{nextIndex:a,consumed:l}:void 0}function Et(e){return e!==void 0&&/^(0|[1-9][0-9]*)$/.test(e)?Number(e):void 0}function le(e){return e.reduce((t,n)=>t+Tt(n),0)}function Tt(e){return e.fixedLength!==void 0?e.fixedLength:e.children!==void 0?le(e.children):1}function qn(e){return e.reduce((t,n)=>t+(n.children===void 0?Tt(n):1),0)}function ae(e,t,n){let r=$(e,":",n);if(r===-1)return!0;let i=$(e,t,n);return i!==-1&&i<r}function Gn(e,t,n){return h(e[t]?.number??e[e.length-1]?.number??n,"array length mismatch")}function Yn(e){let t=0;for(;t<e.length&&e[t]===" ";)t++;return e[t]==="#"}var fe=class{ctx;sourceByLine=new Map;number=0;blankPending=!1;firstLine=!0;constructor(t){this.ctx=t}push(t){let n=t;if(this.number++,this.sourceByLine.set(this.number,t),this.firstLine&&(n.startsWith("\uFEFF")&&(n=n.slice(1)),this.firstLine=!1),n.endsWith("\r")&&(n=n.slice(0,-1)),n=n.replace(/ +$/,""),n.trim()===""){this.blankPending=!0;return}if(Yn(n))return;let r=0,i=0,o=0;for(;r<n.length&&(n[r]===" "||n[r]===" ");){if(n[r]===" "){if(this.ctx.strict)throw h(this.number,"tab used as indentation");i++}else o++;r++}let s;if(o%this.ctx.indentSize===0)s=o/this.ctx.indentSize;else{if(this.ctx.strict)throw h(this.number,"invalid indentation");s=Math.floor(o/this.ctx.indentSize)}s+=i,Pt(s,this.number,this.ctx);let c={number:this.number,depth:s,content:n.slice(r),blankBefore:this.blankPending};return this.blankPending=!1,c}};function*Qn(e,t){for(let n of e){let r=t.push(n);r!==void 0&&(yield r)}}async function*Xn(e,t){for await(let n of e){let r=t.push(n);r!==void 0&&(yield r)}}var Zn=/^(0|[1-9]\d*)$/;function Te(e,t){let n=$(e,"[",t);if(n===-1)return null;let r=$(e,":",t);if(r!==-1&&r<n)return null;let i=e.slice(0,n);if(i!==""&&/\s$/.test(i))throw h(t,"whitespace between key and bracket segment");let o=e.indexOf("]",n);if(o===-1)return null;let s=e.slice(n+1,o),c=!1,u=",",a=s.indexOf(":");if(a!==-1){let b=s.slice(a+1);if(s=s.slice(0,a),c=!0,b===" "||b==="|")u=b;else if(b!=="")throw h(t,"malformed bracket segment")}else(s.endsWith(" ")||s.endsWith("|"))&&(u=s.slice(-1),s=s.slice(0,-1));if(!Zn.test(s))throw h(t,"malformed array header length");let l=Number(s),d=e.slice(o+1),f;if(d.startsWith("{")){let b=Rt(d,t);f=er(d.slice(1,b),u,t),d=d.slice(b+1)}if(c&&f===void 0)throw h(t,"keyed header requires a field list");if(!d.startsWith(":"))throw h(t,"expected colon after array header");let m=I(d.slice(1));if((f!==void 0||c)&&m!=="")throw h(t,"unexpected content after fields-bearing header colon");return{key:i===""?void 0:V(i,t)[0],length:l,delimiter:u,fields:f,keyed:c,inline:m===""?void 0:m}}function Rt(e,t){let n=0,r=!1;for(let i=0;i<e.length;i++){let o=e[i];if(r){o==="\\"?i++:o==='"'&&(r=!1);continue}if(o==='"')r=!0;else if(o==="{")n++;else if(o==="}"&&(n--,n===0))return i}throw h(t,"malformed tabular header fields")}function er(e,t,n){if(t!==","&&e.includes(",")&&(e.includes("[")||e.includes("{")))return de(e,",",t,n);try{return de(e,t,t,n)}catch(r){if(t===",")throw r;return de(e,",",t,n)}}function de(e,t,n,r){let i=[],o=0,s=0,c=0,u=!1,a=l=>{i.push(tr(l,t,n,r))};for(let l=0;l<e.length;l++){let d=e[l];if(u){d==="\\"?l++:d==='"'&&(u=!1);continue}d==='"'?u=!0:d==="{"?s++:d==="}"?s--:d==="["?c++:d==="]"?c--:d===t&&s===0&&c===0&&(a(e.slice(o,l)),o=l+1)}return a(e.slice(o)),i}function tr(e,t,n,r){let i=I(e);if(i==="")throw h(r,"empty field entry in header");let o=i.startsWith('"')?nr(i,r)+1:0,s=i.indexOf("{",o),c=i.indexOf("[",o),u=s===-1?c:c===-1?s:Math.min(s,c);if(u===-1)return{name:V(i,r)[0]};let a=V(i.slice(0,u),r)[0];if(u===c){let f=i.indexOf("]",c);if(f===-1||f!==i.length-1)throw h(r,"invalid array header");let m=i.slice(c+1,f),p=/^(0|[1-9]\d*)(\t|\|)?$/.exec(m);if(p!==null){if((p[2]??",")!==n)throw h(r,"invalid array header");return{name:a,fixedLength:Number(p[1])}}if(m.length!==1||m===n||/[ \t\r\n"[\]{}:]/.test(m))throw h(r,"invalid array header");return{name:a,listDelimiter:m}}let l=Rt(i.slice(s),r)+s;if(l!==i.length-1)throw h(r,"malformed tabular header fields");if(l===s+1)throw h(r,"invalid array header");let d=de(i.slice(s+1,l),t,n,r);return{name:a,children:d}}function nr(e,t){for(let n=1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;throw h(t,"invalid quoted string")}function $e(e){let t=0;for(let n of e)t+=n.children===void 0?1:$e(n.children);return t}function Re(e,t,n){let r=new Set;for(let i of e){if(r.has(i.name)&&n.strict)throw h(t,"duplicate field name in header");r.add(i.name),i.children!==void 0&&Re(i.children,t,n)}}function I(e){let t=0,n=e.length;for(;t<n&&e[t]===" ";)t++;for(;n>t&&e[n-1]===" ";)n--;return e.slice(t,n)}function Ce(e,t,n){if(I(e)==="")return[];let r=[],i=0,o=!1;for(let s=0;s<e.length;s++){let c=e[s];if(o){c==="\\"?s++:c==='"'&&(o=!1);continue}c==='"'?o=!0:c===t&&(r.push(I(e.slice(i,s))),i=s+1)}return r.push(I(e.slice(i))),r}var Le=Symbol("need line"),$t=2,Ae=class{lines=[];ended=!1;previous;spanActive=0;*peek(t=0){if(t>=$t)throw new Error(`decoder lookahead exceeds ${$t} classified lines`);for(;!this.ended&&this.lines.length<=t;){let n=yield Le;n===void 0?this.ended=!0:this.lines.push(n)}return this.lines[t]}*take(t){let n=yield*this.peek();if(n===void 0)throw new Error("decoder attempted to read past end of input");if(this.lines.shift(),t.strict&&this.spanActive>0&&n.blankBefore)throw h(n.number,"blank line inside a header span");return this.previous=n,n}lastNumber(t){return this.previous===void 0?t:this.previous.number}stop(){this.lines.length=0,this.ended=!0}};function Ct(e,t){return $(e,":",t)!==-1}function Lt(e,t){try{return V(e,t)[0]}catch(n){if(e.startsWith('"'))throw n;return e}}function It(e){let t=e?.maxDepth??Q;return{indentSize:e?.indentSize??e?.indent??2,strict:e?.strict??!0,objectArrayColumns:e?.objectArrayColumns??!0,maxDepth:t===Number.POSITIVE_INFINITY?0:Math.max(0,Math.floor(t))}}function*jt(e){let t=new Ae,n=yield*t.peek();if(n===void 0){yield{type:"startObject",line:1},yield{type:"endObject",line:1};return}if(n.depth!==0)throw h(n.number,"invalid indentation");if(yield*t.peek(1),n.content==="[]"){yield*t.take(e),yield{type:"startArray",length:0,line:n.number},yield{type:"endArray",line:n.number},yield*Oe(t,e);return}let r=null,i=!1;try{r=Te(n.content,n.number)}catch(o){if(e.strict)throw o;i=!0}if(r!=null&&he(r.fields,n.number,e),r!=null&&!i&&r.key===void 0){yield*t.take(e),r.keyed?yield*Ft(t,n,r,e):yield*Ie(t,n,r,e),yield*Oe(t,e);return}if((r===null||i)&&!Ct(n.content,n.number)&&(yield*t.peek(1))===void 0){yield*t.take(e),yield{type:"primitive",value:k(I(n.content),n.number),line:n.number};return}yield*Dt(t,0,n.number,e),yield*Oe(t,e)}function*Oe(e,t){let n=yield*e.peek();if(n!==void 0&&t.strict)throw h(n.number,"expected end of document");e.stop()}function*Dt(e,t,n,r){yield{type:"startObject",line:n};let i=new Set;for(;;){let o=yield*e.peek();if(o===void 0||o.depth<t)break;if(o.depth>t)throw h(o.number,"over-indented line");yield*e.take(r),yield*ke(e,o,o.content,t,r,i)}yield{type:"endObject",line:e.lastNumber(n)}}function*ke(e,t,n,r,i,o){let s=null;try{s=Te(n,t.number)}catch(l){if(i.strict)throw l;s=null}if(s!=null)if(he(s.fields,t.number,i),s.key===void 0){if(i.strict)throw h(t.number,"keyless header is only valid at the root or as a list item");s=null}else{Ee(o,s.key,t.number,i),yield{type:"key",key:s.key,line:t.number},s.keyed?yield*Ft(e,{...t,depth:r},s,i):yield*Ie(e,{...t,depth:r},s,i);return}let c=$(n,":",t.number);if(c===-1)throw h(t.number,"expected key-value line");let u=Lt(I(n.slice(0,c)),t.number),a=I(n.slice(c+1));if(Ee(o,u,t.number,i),yield{type:"key",key:u,line:t.number},a===""){let l=yield*e.peek();if(l!==void 0&&l.depth>r){if(l.depth!==r+1)throw h(l.number,"over-indented line");yield*Dt(e,r+1,l.number,i)}else yield{type:"startObject",line:t.number},yield{type:"endObject",line:t.number};return}if(a==="[]"){yield{type:"startArray",length:0,line:t.number},yield{type:"endArray",line:t.number};return}yield{type:"primitive",value:k(a,t.number),line:t.number}}function Ee(e,t,n,r){if(e.has(t)&&r.strict)throw h(n,"duplicate object key");e.add(t)}function*Ie(e,t,n,r){if(yield{type:"startArray",length:n.length,line:t.number},n.fields!==void 0){if(Re(n.fields,t.number,r),Mt(n.fields,r)){if(!r.objectArrayColumns&&Nt(n.fields))throw h(t.number,"invalid array header");let s=[];for(;;){let c=yield*e.peek();if(c===void 0||c.depth<=t.depth)break;s.push(yield*e.take(r))}yield*wt(n.fields,s,n.length,n.delimiter,t.depth+1,t.number,r),yield{type:"endArray",line:e.lastNumber(t.number)};return}yield*ir(e,t,n,r);return}if(n.inline!==void 0){let s=Ce(n.inline,n.delimiter,t.number);De(s.length,n.length,t.number,"inline-form values",r);for(let c of s)yield{type:"primitive",value:k(c,t.number),line:t.number};yield{type:"endArray",line:t.number};return}let i=0;for(;;){let s=yield*e.peek();if(s===void 0||s.depth<=t.depth)break;if(s.depth!==t.depth+1)throw h(s.number,"over-indented line");if(!s.content.startsWith("- ")&&s.content!=="-")break;yield*e.take(r),i===0&&e.spanActive++,i++,yield*rr(e,s,r)}i>0&&e.spanActive--;let o=e.lastNumber(t.number);if(r.strict&&i!==n.length)throw h(o,`expected ${n.length} list items, but got ${i}`);yield{type:"endArray",line:o}}function Mt(e,t){return e.some(n=>n.listDelimiter!==void 0||n.fixedLength!==void 0||t.objectArrayColumns&&n.children!==void 0||n.children!==void 0&&Mt(n.children,t))}function Nt(e){return e.some(t=>t.fixedLength!==void 0||t.children!==void 0&&Nt(t.children))}function*rr(e,t,n){if(t.content==="-"){yield{type:"startObject",line:t.number},yield{type:"endObject",line:t.number};return}let r=I(t.content.slice(2));if(r==="[]"){yield{type:"startArray",length:0,line:t.number},yield{type:"endArray",line:t.number};return}let i=null;try{i=Te(r,t.number)}catch(o){if(n.strict)throw o;i=null}if(i!=null&&i.key===void 0){if(he(i.fields,t.number,n),i.keyed||i.fields!==void 0){if(n.strict)throw h(t.number,"keyless fields-bearing header is only valid at the root");yield{type:"primitive",value:k(r,t.number),line:t.number};return}yield*Ie(e,t,i,n);return}if(i!=null&&i.key!==void 0||Ct(r,t.number)){yield{type:"startObject",line:t.number};let o=new Set;for(yield*ke(e,t,r,t.depth+1,n,o);;){let s=yield*e.peek();if(s===void 0||s.depth!==t.depth+1||s.content.startsWith("- ")||s.content==="-")break;yield*e.take(n),yield*ke(e,s,s.content,t.depth+1,n,o)}yield{type:"endObject",line:e.lastNumber(t.number)};return}yield{type:"primitive",value:k(r,t.number),line:t.number}}function*ir(e,t,n,r){let i=n.fields,o=$e(i),s=t.depth+1,c=0;for(;;){let a=yield*e.peek();if(a===void 0||a.depth<=t.depth)break;if(a.depth!==s)throw h(a.number,"over-indented line");if(!sr(a.content,n.delimiter,a.number))break;yield*e.take(r),c===0&&e.spanActive++,c++;let l=Ce(a.content,n.delimiter,a.number);De(l.length,o,a.number,"row cells",r),yield*je(i,l,{next:0},a.number)}c>0&&e.spanActive--;let u=e.lastNumber(t.number);if(r.strict&&c!==n.length)throw h(u,`expected ${n.length} tabular rows, but got ${c}`);yield{type:"endArray",line:u}}function sr(e,t,n){let r=$(e,":",n);if(r===-1)return!0;let i=$(e,t,n);return i===-1?!1:i<r}function*je(e,t,n,r){yield{type:"startObject",line:r};for(let i of e)if(yield{type:"key",key:i.name,line:r},i.children===void 0){let o=t[n.next++]??"";yield{type:"primitive",value:k(o,r),line:r}}else yield*je(i.children,t,n,r);yield{type:"endObject",line:r}}function*Ft(e,t,n,r){let i=n.fields;Re(i,t.number,r);let o=$e(i),s=t.depth+1;yield{type:"startObject",line:t.number};let c=new Set,u=0;for(;;){let l=yield*e.peek();if(l===void 0||l.depth<=t.depth)break;if(l.depth!==s)throw h(l.number,"over-indented line");let d=$(l.content,":",l.number);if(d===-1){if(r.strict)throw h(l.number,"expected a keyed entry row");yield*e.take(r);continue}yield*e.take(r),u===0&&e.spanActive++,u++;let f=Lt(I(l.content.slice(0,d)),l.number);Ee(c,f,l.number,r),yield{type:"key",key:f,line:l.number};let m=Ce(l.content.slice(d+1),n.delimiter,l.number);De(m.length,o,l.number,"entry row cells",r),yield*je(i,m,{next:0},l.number)}u>0&&e.spanActive--;let a=e.lastNumber(t.number);if(r.strict&&u!==n.length)throw h(a,`expected ${n.length} entry rows, but got ${u}`);yield{type:"endObject",line:a}}function De(e,t,n,r,i){if(i.strict&&e!==t)throw h(n,`expected ${t} ${r}, but got ${e}`)}function Pt(e,t,n){if(n.maxDepth!==0&&e>n.maxDepth)throw h(t,`maximum nesting depth exceeded (maxDepth ${n.maxDepth})`)}function he(e,t,n,r=1){if(e!==void 0){Pt(r,t,n);for(let i of e)i.children!==void 0&&he(i.children,t,n,r+1)}}function*vt(e,t){let n=It(t),r=new fe(n),i=Qn(e,r),o=jt(n),s=o.next();try{for(;!s.done;)if(s.value===Le){let c=i.next();s=o.next(c.done?void 0:c.value)}else yield s.value,s=o.next()}catch(c){throw Ut(c,r)}finally{o.return(),i.return(void 0)}}async function*_t(e,t){let n=It(t),r=new fe(n),i=Xn(e,r),o=jt(n),s=o.next();try{for(;!s.done;)if(s.value===Le){let c=await i.next();s=o.next(c.done?void 0:c.value)}else yield s.value,s=o.next()}catch(c){throw Ut(c,r)}finally{o.return(),await i.return(void 0)}}function Ut(e,t){return!(e instanceof F)||e.source!==void 0?e:new B(e.reason,{line:e.line,source:t.sourceByLine.get(e.line),cause:e})}function Me(e,t){return Symbol.asyncIterator in e?_t(e,t):vt(e,t)}var or=/[\uD800-\uDFFF]/;function A(e){if(e===null)return null;if(P(e))return e;if(typeof e=="object"&&e!==null&&"toJSON"in e&&typeof e.toJSON=="function"){let t=e.toJSON();if(t!==e)return A(t)}if(typeof e=="string")return Bt(e,"string value"),e;if(typeof e=="boolean")return e;if(typeof e=="number")return Object.is(e,-0)?0:Number.isFinite(e)?e:null;if(typeof e=="bigint")return e>=Number.MIN_SAFE_INTEGER&&e<=Number.MAX_SAFE_INTEGER?Number(e):e.toString();if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(A);if(e instanceof Set)return Array.from(e,A);if(e instanceof Map){let t={};for(let[n,r]of e)H(t,String(n),A(r));return t}if(g(e)){let t={};for(let n of Object.keys(e))Bt(n,"object key"),H(t,n,A(e[n]));return t}return null}function Bt(e,t){if(or.test(e))for(let n=0;n<e.length;n+=1){let r=e.charCodeAt(n);if(r<55296||r>57343)continue;let i=e.charCodeAt(n+1);if(r<=56319&&i>=56320&&i<=57343){n+=1;continue}throw new TypeError(`Cannot encode ${t} containing an unpaired surrogate U+${r.toString(16).toUpperCase()} at index ${n}`)}}function g(e){if(e===null||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function E(e){return e===null||P(e)||["string","number","boolean"].includes(typeof e)}function H(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Ht(e){if(!g(e)||Object.keys(e).length===0)return e;let t={};for(let[n,r]of Object.entries(e)){let i=cr(r,1);if(i===void 0)return e;W(t,n,i)}return t}function cr(e,t){if(!g(e)||!ur(e))return;let{order:n,discriminator:r,rows:i}=e;if(typeof n!="string"||typeof r!="string"||!Number.isSafeInteger(i)||i<0)throw x(t);let o=ar(n,i,t),s=e.common,c=s===void 0?Array.from({length:i},()=>({})):s;if(!Array.isArray(c)||c.length!==i||!c.every(g))throw zt(t);let u=new Map;for(let[d,f]of Object.entries(e))if(!gt.has(d)){if(!Array.isArray(f)||!f.every(g))throw x(t);u.set(d,f)}if(u.size===0)throw x(t);let a=new Map,l=o.map((d,f)=>{let m=u.get(d);if(m===void 0)throw Ne(t);let p=a.get(d)??0,b=m[p];if(b===void 0)throw Ne(t);return a.set(d,p+1),lr(r,d,c[f],b,t)});for(let[d,f]of u)if((a.get(d)??0)!==f.length)throw Ne(t);return l}function ur(e){return Object.prototype.hasOwnProperty.call(e,"order")||Object.prototype.hasOwnProperty.call(e,"discriminator")||Object.prototype.hasOwnProperty.call(e,"rows")}function ar(e,t,n){if(!e.startsWith("cycle("))throw x(n);let r=e.slice(6),i=r.indexOf(")*");if(i===-1)throw x(n);let o=r.slice(0,i),s=r.slice(i+2);if(o===""||s.includes("+tail("))throw x(n);let c=o.split(",").map(l=>mr(l,n));if(c.some(l=>l===""))throw x(n);let u=hr(s,n),a=c.length*u;if(!Number.isSafeInteger(a))throw x(n);if(a!==t)throw zt(n);return Array.from({length:a},(l,d)=>c[d%c.length])}function lr(e,t,n,r,i){let o={};W(o,e,t);for(let[s,c]of Object.entries(n??{})){if(s===e||Object.prototype.hasOwnProperty.call(o,s))throw x(i);W(o,s,c)}for(let[s,c]of Object.entries(dr(r,i))){if(s===e||Object.prototype.hasOwnProperty.call(o,s))throw x(i);W(o,s,c)}return o}function dr(e,t){let n={};for(let[r,i]of Object.entries(e))fr(n,r.split("."),i,t);return me(n,t)}function fr(e,t,n,r){if(t.some(o=>o===""))throw x(r);let i=e;for(let o=0;o<t.length;o+=1){let s=t[o];if(o===t.length-1){i[s]=n;return}if(i[s]??={},i=i[s],!g(i))throw x(r)}}function me(e,t){return Array.isArray(e)?e.map(n=>me(n,t)):g(e)?Number.isSafeInteger(e.length)&&e.length>=0?Array.from({length:e.length},(n,r)=>{if(!Object.prototype.hasOwnProperty.call(e,String(r)))throw x(t);return me(e[String(r)],t)}):Object.fromEntries(Object.entries(e).map(([n,r])=>[n,me(r,t)])):e}function hr(e,t){if(e===""||e.length>1&&e.startsWith("0")||!/^[0-9]+$/.test(e))throw x(t);let n=Number(e);if(!Number.isSafeInteger(n))throw x(t);return n}function mr(e,t){try{return decodeURIComponent(e)}catch{throw x(t)}}function Vt(e){return encodeURIComponent(e)}function x(e){return h(e,"invalid cyclic array wire")}function zt(e){return h(e,"cyclic array length mismatch")}function Ne(e){return h(e,"cyclic array group length mismatch")}function Kt(e){if(!g(e))return;let t=Object.entries(e);if(t.length===0)return;let n=[];for(let[i,o]of t){let s=pr(o);if(s===void 0)return;n.push([i,s])}let r=[];for(let[i,o]of n)wr(r,i,o);return r.join("")}function pr(e){if(!Array.isArray(e)||e.length===0||!e.every(g))return;let t=yr(e);if(t===void 0)return;let n=e.map(c=>c[t]),r=gr(n);if(r===void 0)return;let i=br(e,t),o=new Map;for(let c of e){let u=c[t];o.has(u)||o.set(u,[]);let a={};for(let[l,d]of Object.entries(c))if(l!==t&&!i.includes(l)&&!Fe(d,l,a))return;o.get(u).push(a)}let s=[];for(let c of r.cycle){let u=o.get(c),a=Sr(u);if(a===void 0||a.length===0)return;s.push({fields:a,label:c,rows:u})}return{common:i,commonRows:e.map(c=>Object.fromEntries(i.map(u=>[u,c[u]]))),discriminator:t,groups:s,order:r,rows:e}}function yr(e){return yt.find(t=>e.every(n=>typeof n[t]=="string"))}function gr(e){if(!(e.length<12))for(let t=2;t<=Math.min(8,Math.floor(e.length/3));t+=1){if(e.length%t!==0)continue;let n=e.slice(0,t);if(new Set(n).size<2||!e.every((s,c)=>s===n[c%t]))continue;let r=e.length/t;if(r<3)continue;let i=e.map(Vt).join(","),o=`cycle(${n.map(Vt).join(",")})*${r}`;if(o.length<=i.length*.4)return{cycle:n,encoded:o,repeats:r}}}function br(e,t){let n=[],r=Object.keys(e[0]),i=r.indexOf(t)+1;for(let o of r.slice(i).filter(s=>s!==t)){if(!xr(o)||!e.every(s=>Object.prototype.hasOwnProperty.call(s,o))||!e.every(s=>ce(s[o])))break;n.push(o)}return n}function wr(e,t,n){e.push(S(t),`:
|
|
6
|
+
`),e.push(" order: ",O(n.order.encoded,v),`
|
|
7
|
+
`),e.push(" discriminator: ",O(n.discriminator,v),`
|
|
8
|
+
`),e.push(" rows: ",String(n.rows.length),`
|
|
9
|
+
`),n.common.length>0&&Wt(e,"common",n.common,n.commonRows);for(let r of n.groups)Wt(e,r.label,r.fields,r.rows)}function Wt(e,t,n,r){e.push(" ",S(t),"[",String(r.length),v,"]{",n.map(S).join(v),`}:
|
|
10
|
+
`);for(let i of r)e.push(" ",n.map(o=>O(i[o],v)).join(v),`
|
|
11
|
+
`)}function xr(e){return e!==""&&Pe(e)}function Fe(e,t,n,r=new Set){if(!Pe(t))return!1;if(ce(e))return n[t]=e,!0;if(Array.isArray(e)){if(r.has(e))return!1;r.add(e),n[`${t}.length`]=e.length;let i=e.every((o,s)=>Fe(o,`${t}.${s}`,n,r));return r.delete(e),i}if(g(e)){if(r.has(e))return!1;r.add(e);let i=Object.entries(e).every(([o,s])=>!o.includes(".")&&Fe(s,`${t}.${o}`,n,r));return r.delete(e),i}return!1}function Sr(e){let t=Object.keys(e[0]??{});if(e.every(n=>Or(Object.keys(n),t)))return t.every(Pe)?t:void 0}function Or(e,t){return e.length===t.length&&e.every((n,r)=>n===t[r])}function Pe(e){return e.split(".").every(t=>/^[A-Za-z_][A-Za-z0-9_]*$|^(?:0|[1-9][0-9]*)$/.test(t))}function ve(e,t){let n=_e(e,t,[]),r=t("",n,[]);return r===void 0?n:A(r)}function _e(e,t,n){return Array.isArray(e)?kr(e,t,n):g(e)?Ar(e,t,n):e}function Ar(e,t,n){let r={};for(let[i,o]of Object.entries(e)){if(o===void 0)continue;let s=[...n,i],c=t(i,_e(o,t,s),s);c!==void 0&&H(r,i,A(c))}return r}function kr(e,t,n){let r=[];for(let i=0;i<e.length;i+=1){let o=[...n,i],s=t(String(i),_e(e[i],t,o),o);s!==void 0&&r.push(A(s))}return r}var Jt=Symbol("unset");function qt(e){let t=[],n,r=Jt,i=o=>{let s=t[t.length-1];s===void 0?r=o:Array.isArray(s)?s.push(o):Object.defineProperty(s,n,{value:o,enumerable:!0,writable:!0,configurable:!0})};for(let o of e)switch(o.type){case"startObject":{let s={};i(s),t.push(s);break}case"startArray":{let s=[];i(s),t.push(s);break}case"endObject":case"endArray":t.pop();break;case"key":n=o.key;break;case"primitive":i(o.value);break}return r===Jt?{}:r}function Gt(e,t){let n=qt(Me(e,t));return t?.reviver?ve(n,t.reviver):n}function Ue(e,t){let{reviver:n,...r}=t??{},i=Gt(Er(e),r),o=t?.cyclicDiscriminatedArrays===!0?Ht(i):i;return n?ve(o,n):o}function*Er(e){let t=0;for(;;){let n=e.indexOf(`
|
|
12
|
+
`,t);if(n===-1){yield e.slice(t);return}yield e.slice(t,n),t=n+1}}function Yt(e,t){let n=t("",e,[]);return n===void 0?Be(e,t,[]):Ve(e,n,t,[])}function Ve(e,t,n,r){return P(t)&&(Array.isArray(e)||g(e))?Be(e,n,r):Be(A(t),n,r)}function Be(e,t,n){return Array.isArray(e)?$r(e,t,n):g(e)?Tr(e,t,n):e}function Tr(e,t,n){let r={};for(let[i,o]of Object.entries(e)){let s=[...n,i],c=t(i,o,s);c!==void 0&&H(r,i,Ve(o,c,t,s))}return r}function $r(e,t,n){let r=[];for(let i=0;i<e.length;i+=1){let o=[...n,i],s=t(String(i),e[i],o);s!==void 0&&r.push(Ve(e[i],s,t,o))}return r}function z(e,t={}){if(t.objectArrayColumns===!0){let i=Qt(e);if(i!==void 0)return[{name:"values",fixedLength:i,self:!0}]}let n=Object.keys(e[0]??{});if(n.length===0)return;for(let i of e)if(!g(i)||Object.keys(i).length!==n.length||n.some(o=>!Object.prototype.hasOwnProperty.call(i,o)))return;let r=[];for(let i of n){let o=e.map(c=>c[i]);if(o.every(E)){r.push({name:i});continue}if(t.primitiveArrayColumns===!0&&o.every(c=>Array.isArray(c)&&c.every(E))){r.push({name:i,listDelimiter:";"});continue}if(t.objectArrayColumns===!0&&o.every(Array.isArray)){let c=Qt(o);if(c!==void 0){r.push({name:i,fixedLength:c});continue}let u=o.flat(),a=z(u,t);if(a!==void 0){r.push({name:i,children:a,childTable:!0});continue}}if(!o.every(c=>g(c)&&Object.keys(c).length>0))return;let s=z(o,t);if(s===void 0)return;r.push({name:i,children:s})}return r}function pe(e,t={}){let n=Object.values(e);if(!(n.length<2)&&n.every(r=>g(r)&&Object.keys(r).length>0))return z(n,t)}function Qt(e){let t=Array.isArray(e[0])?e[0].length:0;if(t!==0)return e.every(n=>Array.isArray(n)&&n.length===t&&n.every(E))?t:void 0}function Z(e,t={}){return Array.from(Xt(e,t)).join(`
|
|
13
|
+
`)}function Xt(e,t={}){let n=t.delimiter??",";if(![",","|"," "].includes(n))throw new TypeError("invalid delimiter");let r=t.indentSize??t.indent??2,i=t.maxDepth??Q,o=i===Number.POSITIVE_INFINITY?0:Math.max(0,Math.floor(i)),s=A(e),c=t.replacer?Yt(s,t.replacer):s,u={delimiter:n,indentSize:r,maxDepth:o,primitiveArrayColumns:t.primitiveArrayColumns===!0,objectArrayColumns:t.objectArrayColumns===!0};if(t.cyclicDiscriminatedArrays===!0){let a=Kt(c);if(a!==void 0)return a.trimEnd().split(`
|
|
14
|
+
`)}return Rr(c,u)}function Rr(e,t){if(E(e))return[O(e,t.delimiter)];if(Array.isArray(e))return en(void 0,e,0,t);let n=pe(e,t);return n===void 0?ye(e,0,t):Zt(void 0,e,n,0,t)}function ye(e,t,n){return J(t,n),Object.entries(e).flatMap(([r,i])=>Cr(r,i,t,n))}function Cr(e,t,n,r){let i=w(n,r)+S(e);if(E(t))return[`${i}: ${O(t,r.delimiter)}`];if(Array.isArray(t))return en(e,t,n,r);let o=pe(t,r);if(o!==void 0)return Zt(e,t,o,n,r);let s=[`${i}:`];return Object.keys(t).length>0&&s.push(...ye(t,n+1,r)),s}function Zt(e,t,n,r,i){J(r,i);let o=Object.entries(t);X(n,r+1,i);let s=[w(r,i)+R(e,o.length,n,i.delimiter,!0)];for(let[c,u]of o){let a=K(u,n,r+2,i);s.push(w(r+1,i)+S(c)+": "+a.cells),s.push(...a.children)}return s}function en(e,t,n,r){J(n,r);let i=w(n,r);if(t.length===0)return[e===void 0?`${i}[]`:`${i}${S(e)}: []`];if(t.every(E))return[i+R(e,t.length,void 0,r.delimiter)+" "+He(t,r.delimiter)];let o=z(t,r);if(o!==void 0)return Lr(e,t,o,n,r);let s=[i+R(e,t.length,void 0,r.delimiter)];for(let c of t)s.push(...We(c,n+1,r));return s}function Lr(e,t,n,r,i){X(n,r+1,i);let o=[w(r,i)+R(e,t.length,n,i.delimiter)];for(let s of t){let c=K(s,n,r+2,i);o.push(w(r+1,i)+c.cells),o.push(...c.children)}return o}function We(e,t,n){J(t,n);let r=w(t,n)+"-";if(E(e))return[`${r} ${O(e,n.delimiter)}`];if(Array.isArray(e)){if(e.length===0)return[`${r} ${R(void 0,0,void 0,n.delimiter)}`];if(e.every(E))return[`${r} ${R(void 0,e.length,void 0,n.delimiter)} ${He(e,n.delimiter)}`];let i=[`${r} ${R(void 0,e.length,void 0,n.delimiter)}`];for(let o of e)i.push(...We(o,t+1,n));return i}return Ir(e,t,n)}function Ir(e,t,n){J(t,n);let r=Object.entries(e);if(r.length===0)return[w(t,n)+"-"];let[[i,o],...s]=r,c=jr(i,o,t,n),u;if(c!==void 0)u=c;else if(E(o))u=[w(t,n)+"- "+S(i)+": "+O(o,n.delimiter)];else if(Array.isArray(o))if(o.length===0)u=[w(t,n)+"- "+S(i)+": []"];else{u=[w(t,n)+"- "+R(i,o.length,void 0,n.delimiter)];for(let a of o)u.push(...We(a,t+2,n))}else u=[w(t,n)+"- "+S(i)+":"],Object.keys(o).length>0&&u.push(...ye(o,t+2,n));return s.length>0&&u.push(...ye(Object.fromEntries(s),t+1,n)),u}function jr(e,t,n,r){if(Array.isArray(t)&&t.length>0&&t.every(E))return[w(n,r)+"- "+R(e,t.length,void 0,r.delimiter)+" "+He(t,r.delimiter)];if(Array.isArray(t)&&t.every(g)){let i=z(t,r);if(i!==void 0){X(i,n+1,r);let o=[w(n,r)+"- "+R(e,t.length,i,r.delimiter)];for(let s of t){let c=K(s,i,n+3,r);o.push(w(n+2,r)+c.cells),o.push(...c.children)}return o}}if(g(t)){let i=pe(t,r);if(i!==void 0){X(i,n+1,r);let o=Object.entries(t),s=[w(n,r)+"- "+R(e,o.length,i,r.delimiter,!0)];for(let[c,u]of o){let a=K(u,i,n+3,r);s.push(w(n+2,r)+S(c)+": "+a.cells),s.push(...a.children)}return s}}}function R(e,t,n,r,i=!1){let o=e===void 0?"":S(e),s=i?":":"",c=r===","?"":r,u=n===void 0?"":`{${tn(n,r)}}`;return`${o}[${t}${s}${c}]${u}:`}function tn(e,t){return e.map(n=>{let r=S(n.name);if(n.listDelimiter!==void 0)return`${r}[${n.listDelimiter}]`;if(n.fixedLength!==void 0){let i=t===","?"":t;return`${r}[${n.fixedLength}${i}]`}return r+(n.children===void 0?"":`{${tn(n.children,t)}}`)}).join(t)}function K(e,t,n,r){let i=[],o=[];for(let s of t){let c=s.self===!0?e:e[s.name];if(s.childTable===!0){i.push(String(c.length));for(let u of c){let a=K(u,s.children??[],n+1,r);o.push(w(n,r)+a.cells,...a.children)}}else if(s.fixedLength!==void 0)i.push(...c.map(u=>O(u,r.delimiter)));else if(s.listDelimiter!==void 0)i.push(c.map(u=>Dr(u,r.delimiter,s.listDelimiter)).join(s.listDelimiter));else if(s.children!==void 0){let u=K(c,s.children,n,r);i.push(u.cells),o.push(...u.children)}else i.push(O(c,r.delimiter))}return{cells:i.join(r.delimiter),children:o}}function Dr(e,t,n){return typeof e!="string"?O(e,t):Se(e,t)||e.includes(n)?ue(e):e}function He(e,t){return e.map(n=>O(n,t)).join(t)}function w(e,t){return" ".repeat(e*t.indentSize)}function J(e,t){if(t.maxDepth!==0&&e>t.maxDepth)throw h(0,`maximum nesting depth exceeded (maxDepth ${t.maxDepth})`)}function X(e,t,n){J(t,n);for(let r of e)r.children!==void 0&&X(r.children,t+1,n)}var Ss=new TextEncoder,Os=new TextDecoder;var nn=Ue;function ee(e){let t=/^(\d+)\.(\d+)\.(\d+)/.exec(String(e).trim());return t?{major:Number(t[1]),minor:Number(t[2]),patch:Number(t[3])}:null}function te(e,t){let n=ee(e),r=ee(t);return!n||!r?0:n.major-r.major||n.minor-r.minor||n.patch-r.patch}function qe(e,t){let n=ee(e),r=ee(t);return!!n&&!!r&&n.major===r.major}function Nr(e){let{installed:t,current:n,candidate:r,channel:i}=e;return i!=="stable"||!qe(t,r)||te(r,n)<=0?null:r}function Fr(e){return`${e}-stable.current`}function rn(e,t){return an(e,Fr(t))}function Pr(e){return`${e}-stable.self-update.json`}function sn(e,t){return an(e,Pr(t))}function vr(e){return new TextEncoder().encode(JSON.stringify({version:e}))}function _r(e){let t=e.trim();try{let n=JSON.parse(t);if(n&&typeof n.version=="string")return n.version.trim()}catch{}return/^\d+\.\d+\.\d+/.test(t)?t:""}function Ur(e){try{let t=e.trim();if(!t)return{};let n;try{n=JSON.parse(t)}catch{let i=nn(t);n=i&&typeof i=="object"&&!Array.isArray(i)?i:{}}let r={};return Number.isFinite(n.lastCheckAtMs)&&(r.lastCheckAtMs=Number(n.lastCheckAtMs)),Number.isFinite(n.lastSuccessAtMs)&&(r.lastSuccessAtMs=Number(n.lastSuccessAtMs)),Number.isFinite(n.lastFailureAtMs)&&(r.lastFailureAtMs=Number(n.lastFailureAtMs)),typeof n.lastError=="string"&&(r.lastError=n.lastError),(n.lastStatus==="updated"||n.lastStatus==="up-to-date"||n.lastStatus==="skipped-channel"||n.lastStatus==="error")&&(r.lastStatus=n.lastStatus),r}catch{return{}}}async function on(e,t,n){let r=sn(t,n);try{return await e.exists(r)?Ur(new TextDecoder().decode(await e.readFile(r))):{}}catch{return{}}}async function Br(e,t,n,r){let i=await on(e,t,n);await e.writeFile(sn(t,n),new TextEncoder().encode(`${Z(Je({...i,...r}))}
|
|
15
|
+
`))}async function ze(e,t,n,r){try{await Br(e,t,n,r)}catch{}}var Vr=4*60*60*1e3;async function Wr(e,t){return(await Hr(e,t)).version}async function Hr(e,t,n={}){let{plugin:r,installedVersion:i,cacheDir:o,channel:s}=t;if(s!=="stable"||!i)return{version:i,logNotes:[]};let c=rn(o,r),u="";try{await e.exists(c)&&(u=_r(new TextDecoder().decode(await e.readFile(c))))}catch{u=""}let a=i,l;if(u&&qe(i,u)&&te(u,i)>=0){let ne=N({plugin:r,version:u,cacheDir:o,channel:s});await e.exists(ne)&&(a=u,l=u)}let d=[],f=await Kr(e,{plugin:r,installedVersion:i,cacheDir:o}),m;f&&te(f,a)>0&&(await un(e,o,r,f),m={from:l,to:f},d.push(`self-update reconciled pointer ${l??"none"} -> ${f} from cached lane`),a=f,l=f);let p=await on(e,o,r),b=n.nowMs??Date.now(),_=n.staleAfterMs??Vr,y=p.lastStatus!==void 0&&p.lastCheckAtMs!==void 0?{status:p.lastStatus,checkedAtMs:p.lastCheckAtMs,ageMs:Math.max(0,b-p.lastCheckAtMs)}:void 0,C;p.lastFailureAtMs!==void 0&&p.lastFailureAtMs>(p.lastSuccessAtMs??0)&&b-p.lastFailureAtMs>_&&(C={ageMs:b-p.lastFailureAtMs,lastError:p.lastError},d.push(`self-update stale: last check failed ${Ke(C.ageMs)} ago`));let M;return y!==void 0&&(y.status==="updated"||y.status==="up-to-date")&&(d.push(`self-update ${y.status}: checked ${Ke(y.ageMs)} ago`),y.ageMs>_&&(M={status:y.status,ageMs:y.ageMs},d.push(`self-update stale: last successful check was ${Ke(M.ageMs)} ago`))),{version:a,...l?{pointerVersion:l}:{},...f?{laneNewestVersion:f}:{},...m?{reconciled:m}:{},...C?{staleFailure:C}:{},...y?{selfUpdateStatus:y}:{},...M?{staleSuccess:M}:{},logNotes:d}}async function zr(e,t,n={}){let{plugin:r,installedVersion:i,repo:o,cacheDir:s,channel:c}=t,u=n.nowMs??Date.now;if(c!=="stable"||!ee(i))return{status:"skipped-channel"};try{let a=await Wr(e,{plugin:r,installedVersion:i,cacheDir:s,channel:c}),l=await ot(e,i),d=l?Nr({installed:i,current:a,candidate:l,channel:c}):null;return d?(await se(e,{plugin:r,version:d,repo:o,cacheDir:s,channel:c}),await un(e,s,r,d),await ze(e,s,r,{lastCheckAtMs:u(),lastSuccessAtMs:u(),lastStatus:"updated",lastFailureAtMs:void 0,lastError:void 0}),{status:"updated",version:d}):(await ze(e,s,r,{lastCheckAtMs:u(),lastSuccessAtMs:u(),lastStatus:"up-to-date",lastFailureAtMs:void 0,lastError:void 0}),{status:"up-to-date",version:a})}catch(a){let l=a instanceof Error?a.message:String(a);return await ze(e,s,r,{lastCheckAtMs:u(),lastFailureAtMs:u(),lastError:l,lastStatus:"error"}),{status:"error",error:l}}}async function cn(e,t,n={}){let r=Math.max(1,Math.floor(n.maxAttempts??4)),i=Math.max(0,Math.floor(n.initialDelayMs??3e4)),o=Math.max(i,Math.floor(n.maxDelayMs??15*6e4)),s=n.sleep??(a=>new Promise(l=>setTimeout(l,a))),c=1,u=i;for(;;){let a=await zr(e,t,n);if(a.status!=="error"||c>=r)return{...a,attempts:c};await n.onRetry?.({attempt:c,nextAttempt:c+1,delayMs:u,error:a.error}),await s(u),u=Math.min(o,Math.max(u*2,i)),c+=1}}async function un(e,t,n,r){let i=rn(t,n),o=`${i}.${r}.tmp`;await e.writeFile(o,vr(r)),await e.rename(o,i)}async function Kr(e,t){let n,r;try{r=await e.readdir(t.cacheDir)}catch{return}let i=new RegExp(`^${Jr(t.plugin)}-(\\d+\\.\\d+\\.\\d+(?:[-+][A-Za-z0-9.-]+)?)\\.bundle\\.min\\.mjs$`);for(let o of r){let s=i.exec(o);if(!s)continue;let c=s[1];qe(t.installedVersion,c)&&(te(c,t.installedVersion)<=0||(n===void 0||te(c,n)>0)&&(n=c))}return n}function Jr(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Je(e){if(e==null)return null;if(typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:null;if(Array.isArray(e))return e.map(t=>Je(t));if(typeof e=="object"){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=Je(r));return t}return String(e)}function Ke(e){let t=Math.floor(Math.max(0,e)/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m`:`${Math.floor(n/60)}h`}function an(e,t){return e.endsWith("/")?`${e}${t}`:`${e}/${t}`}var fn="reddb-io/red-skills";function si(){try{return"fetch"}catch{return""}}function hn(e){return e||(process.env.RED_SKILLS_CACHE_DIR?process.env.RED_SKILLS_CACHE_DIR:process.env.XDG_CACHE_HOME?q(process.env.XDG_CACHE_HOME,"red-skills","bundles"):q(dn(),".cache","red-skills","bundles"))}function oi(){return process.env.RED_SKILLS_INSTALL_ROOT||q(dn(),".red","skills")}var mn={async materialize(e,t){await Ge(t,{recursive:!0});let n=Yr("npm",["install",e,"--prefix",t,"--no-save","--no-audit","--no-fund","--ignore-scripts","--loglevel=error"],{stdio:["ignore","ignore","pipe"],encoding:"utf8"});if(n.error)throw n.error;if(n.status!==0)throw new Error(`npm install ${e} -> ${n.status}: ${(n.stderr||"").trim()}`);let r=e.lastIndexOf("@"),i=e.slice(0,r);return q(t,"node_modules",...i.split("/"))},async readFile(e){return new Uint8Array(await ti(e))},async writeFile(e,t){await Ge(ii(e),{recursive:!0}),await ri(e,t)},async exists(e){return Xr(e)},sha256(e){return Qr("sha256").update(e).digest("hex")},async fetchText(e){let t=await fetch(e,{redirect:"follow"});if(!t.ok)throw new Error(`GET ${e} -> ${t.status}`);return await t.text()},async rename(e,t){await ln(e,t)}},ci={...mn,async readdir(e){return await ni(e)},async rename(e,t){await ln(e,t)}};async function ge(e,t){try{await Ge(e,{recursive:!0}),await ei(q(e,"red-fetch.log"),`[${new Date().toISOString()}] ${t}
|
|
16
|
+
`)}catch{}process.stderr.write(`entrypoint: ${t}
|
|
17
|
+
`)}function Ye(e){let t={mode:"fetch",repo:fn,help:!1},n=[];for(let r=0;r<e.length;r++){let i=e[r];i==="--help"||i==="-h"?t.help=!0:i==="--repo"?t.repo=e[++r]??t.repo:i==="--cache-dir"?t.cacheDir=e[++r]:i.startsWith("-")||n.push(i)}return t.plugin=n[0],t.version=n[1],t}function ui(e,t){return e[0]==="fetch"?Ye(e.slice(1)):Ye(e)}function ai(e){return oe(e,"plugins.dev.afk.release.channel")??oe(e,"afk.release.channel")}function Qe(e,t){return ut({env:e,configValue:t?ai(t):void 0})}function Xe(){let e=be(process.cwd(),q(".red","config.yaml"));if(e)try{return Zr(e,"utf8")}catch{return}}var li=new Set(["code-nav",U,...ie(U)]);function pn(e){return li.has(e)?"dev":e}var di=`entrypoint (fetch) \u2014 resolve a plugin's built bundle from the ${D} npm package into a local cache.
|
|
18
|
+
|
|
19
|
+
Usage:
|
|
20
|
+
node <entrypoint> fetch <plugin> <version> [--repo owner/name] [--cache-dir DIR]
|
|
21
|
+
node red-fetch.mjs <plugin> <version> [--repo owner/name] [--cache-dir DIR]
|
|
22
|
+
|
|
23
|
+
Arguments:
|
|
24
|
+
<plugin> plugin name (e.g. dev, memory)
|
|
25
|
+
<version> plugin version without the leading v (e.g. 1.140.0)
|
|
26
|
+
|
|
27
|
+
Options:
|
|
28
|
+
--repo GitHub repo publishing the release (default: ${fn})
|
|
29
|
+
--cache-dir override the bundle cache dir
|
|
30
|
+
-h, --help show this help
|
|
31
|
+
|
|
32
|
+
Best-effort: never blocks session start. On any failure it logs to
|
|
33
|
+
<cache-dir>/red-fetch.log and exits 0.`;async function fi(e){let t=hn(e.cacheDir);(e.help||!e.plugin||!e.version)&&(process.stdout.write(`${di}
|
|
34
|
+
`),!e.help&&(!e.plugin||!e.version)&&process.stdout.write(`
|
|
35
|
+
entrypoint: missing <plugin> and/or <version>; nothing to do.
|
|
36
|
+
`),process.exit(0));let{plugin:n,version:r}=e;we(process.cwd(),pn(n))||process.exit(0);let i=Qe(process.env,Xe()),o=G(r)||i==="canary"?N({plugin:n,version:r,cacheDir:t,channel:i}):`${t}/${n}-<version>.bundle.min.mjs`;try{let s=await se(mn,{plugin:n,version:r,repo:e.repo,cacheDir:t,installRoot:oi(),channel:i});process.stdout.write(`entrypoint: bundle ready at ${s} (${i})
|
|
37
|
+
`)}catch(s){let c=s instanceof T?s.kind:"unknown",u=s instanceof Error?s.message:String(s);await ge(t,`${c}: ${u} (fetch plugin=${n} version=${r} channel=${i})`),process.stdout.write(`entrypoint: could not fetch ${n}@${r} (${c}); expected cache path ${o}. Continuing \u2014 fetch is best-effort.
|
|
38
|
+
`)}hi(n,r,e.repo,e.cacheDir),process.exit(0)}var yn="__self-update";function hi(e,t,n,r){if(Qe(process.env,Xe())!=="stable"||!t)return;let o=process.argv[1];if(o)try{let s=[o,yn,e,t,"--repo",n];r&&s.push("--cache-dir",r),Gr(process.execPath,s,{detached:!0,stdio:"ignore"}).unref()}catch{}}async function mi(e){let t=Ye(e),n=t.plugin,r=t.version??"",i=hn(t.cacheDir);(!n||!we(process.cwd(),pn(n)))&&process.exit(0);let o=Qe(process.env,Xe()),s=await cn(ci,{plugin:n,installedVersion:r,repo:t.repo,cacheDir:i,channel:o},{onRetry:async({attempt:c,nextAttempt:u,delayMs:a,error:l})=>{await ge(i,`self-update: ${n} check failed on attempt ${c} (${l}); retry ${u} in ${Math.round(a/1e3)}s`)}});s.status==="updated"?await ge(i,`self-update: ${n} swapped to ${s.version} for next boot after ${s.attempts??1} attempt(s)`):s.status==="error"&&await ge(i,`self-update: ${n} check failed after ${s.attempts??1} attempt(s) (${s.error}); cached bundle keeps serving`),process.exit(0)}async function pi(){let e=process.argv.slice(2);if(e[0]===yn){await mi(e.slice(1));return}await fi(ui(e,si()))}process.argv[1]!=null&&import.meta.url===qr(process.argv[1]).href&&pi();export{ai as configuredChannelValue,pn as gatePluginName,ui as parseEntrypoint,Qe as resolveLauncherChannel};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -u
|
|
3
|
+
|
|
4
|
+
root="${CODEX_PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT:-}}"
|
|
5
|
+
project_root="${RED_SKILLS_PROJECT_ROOT:-${CLAUDE_PROJECT_DIR:-${CODEX_PROJECT_DIR:-${OPENCODE_PROJECT_DIR:-}}}}"
|
|
6
|
+
|
|
7
|
+
if [ -n "$project_root" ]; then
|
|
8
|
+
export RED_SKILLS_PROJECT_ROOT="$project_root"
|
|
9
|
+
fi
|
|
10
|
+
|
|
11
|
+
if [ -z "$root" ]; then
|
|
12
|
+
for candidate in \
|
|
13
|
+
"$PWD/plugins/dev" \
|
|
14
|
+
"$HOME/.codex/.tmp/marketplaces/red-skills/plugins/dev"; do
|
|
15
|
+
if [ -f "$candidate/.codex-plugin/plugin.json" ] || [ -f "$candidate/.claude-plugin/plugin.json" ]; then
|
|
16
|
+
root="$candidate"
|
|
17
|
+
break
|
|
18
|
+
fi
|
|
19
|
+
done
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
plugin_json=""
|
|
23
|
+
if [ -n "$root" ] && [ -f "$root/.codex-plugin/plugin.json" ]; then
|
|
24
|
+
plugin_json="$root/.codex-plugin/plugin.json"
|
|
25
|
+
elif [ -n "$root" ] && [ -f "$root/.claude-plugin/plugin.json" ]; then
|
|
26
|
+
plugin_json="$root/.claude-plugin/plugin.json"
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
ver=""
|
|
30
|
+
if [ -n "$plugin_json" ]; then
|
|
31
|
+
ver="$(node -e "process.stdout.write(require(process.argv[1]).version)" "$plugin_json" 2>/dev/null || true)"
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
# red-dev moves this pointer only after it verifies and expands the complete
|
|
35
|
+
# package set. Once present, that resident bundle is the fastest and strongest
|
|
36
|
+
# identity available: no registry resolution belongs on every MCP handshake.
|
|
37
|
+
current_dist="$HOME/.red/skills/current/dist"
|
|
38
|
+
current_bundle="$current_dist/redskilled-mcp.bundle.min.mjs"
|
|
39
|
+
if [ -f "$current_bundle" ]; then
|
|
40
|
+
# `current` is an atomic symlink. Execute the physical path because the
|
|
41
|
+
# bundle's direct-entry guard compares argv[1] with its resolved import URL.
|
|
42
|
+
physical_dist="$(cd "$current_dist" 2>/dev/null && pwd -P)"
|
|
43
|
+
if [ -n "$physical_dist" ]; then
|
|
44
|
+
exec node "$physical_dist/redskilled-mcp.bundle.min.mjs" "$@"
|
|
45
|
+
fi
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# Source-checkout fallback for development before a workstation set is installed.
|
|
49
|
+
repo="$PWD"
|
|
50
|
+
if [ -f "$repo/pnpm-workspace.yaml" ] && \
|
|
51
|
+
[ -f "$repo/apps/plugin-dev/package.json" ] && \
|
|
52
|
+
[ -f "$repo/dist/redskilled-mcp.bundle.min.mjs" ]; then
|
|
53
|
+
exec node "$repo/dist/redskilled-mcp.bundle.min.mjs" "$@"
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
# A standalone plugin installation has no red-dev package set. Preserve the
|
|
57
|
+
# published, version-pinned npm path for that host, but keep it off the resident
|
|
58
|
+
# workstation path above.
|
|
59
|
+
if [ -n "$ver" ]; then
|
|
60
|
+
exec npx -y -p "@reddb-io/red-skills@$ver" red-skills-redskilled-mcp "$@"
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
printf 'redskilled: could not locate the redskilled-mcp bundle\n' >&2
|
|
64
|
+
exit 1
|