@zaly/agent 0.0.3 → 0.0.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/dist/{agent-GDLdDc2w.mjs → agent-EkPynZRJ.mjs} +7 -9
- package/dist/agent-EkPynZRJ.mjs.map +1 -0
- package/dist/{bash-QNMTQ1PD.mjs → bash-COgq4W7U.mjs} +2 -2
- package/dist/{bash-QNMTQ1PD.mjs.map → bash-COgq4W7U.mjs.map} +1 -1
- package/dist/compactions-3AjPqjeZ.mjs.map +1 -1
- package/dist/{fetch-D8cmmA3E.mjs → fetch-DknuSrSX.mjs} +2 -2
- package/dist/{fetch-D8cmmA3E.mjs.map → fetch-DknuSrSX.mjs.map} +1 -1
- package/dist/{grep-B2Ax7ewy.mjs → grep-B4GF0svc.mjs} +2 -2
- package/dist/{grep-B2Ax7ewy.mjs.map → grep-B4GF0svc.mjs.map} +1 -1
- package/dist/index-node-esm-D6YQRKEz.mjs.map +1 -1
- package/dist/index.d.mts +42 -42
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +28 -22
- package/dist/index.mjs.map +1 -1
- package/dist/{jsonl-Dw_VBp46.mjs → jsonl-CvgEOakL.mjs} +2 -2
- package/dist/jsonl-CvgEOakL.mjs.map +1 -0
- package/dist/{manager-D-lWBTHG.mjs → manager-f-WjFTMX.mjs} +2 -2
- package/dist/manager-f-WjFTMX.mjs.map +1 -0
- package/dist/masker-Bv9KjkDF.mjs.map +1 -1
- package/dist/notify-DpG_m9iP.mjs.map +1 -1
- package/dist/{registry-CFmR5G3J.mjs → registry-BVf0aZEA.mjs} +328 -48
- package/dist/registry-BVf0aZEA.mjs.map +1 -0
- package/dist/session/claude.d.mts +2 -3
- package/dist/session/claude.d.mts.map +1 -1
- package/dist/session/claude.mjs +1 -1
- package/dist/{session-CUUdWFC5.mjs → session-Bv8JiT8P.mjs} +4 -4
- package/dist/session-Bv8JiT8P.mjs.map +1 -0
- package/dist/session.d.mts +8 -8
- package/dist/session.d.mts.map +1 -1
- package/dist/session.mjs +3 -3
- package/dist/{subagent-baqzjRMc.mjs → subagent-CX7Zjcws.mjs} +3 -3
- package/dist/{subagent-baqzjRMc.mjs.map → subagent-CX7Zjcws.mjs.map} +1 -1
- package/dist/swarm-BJ3gQA1Z.mjs.map +1 -1
- package/dist/{tasks-D8rARHZ1.mjs → tasks-BA-PCeGa.mjs} +4 -3
- package/dist/{tasks-D8rARHZ1.mjs.map → tasks-BA-PCeGa.mjs.map} +1 -1
- package/dist/{tasks-WmC270X2.mjs → tasks-WdRAHsOL.mjs} +5 -4
- package/dist/tasks-WdRAHsOL.mjs.map +1 -0
- package/dist/{tools-DW1dbcCz.mjs → tools-Bl-YI890.mjs} +75 -25
- package/dist/tools-Bl-YI890.mjs.map +1 -0
- package/dist/truncate-BSMXgiXj.mjs.map +1 -1
- package/dist/{uuid-ByXP5SO5.mjs → uuid-CAdJg4l8.mjs} +2 -2
- package/dist/{uuid-ByXP5SO5.mjs.map → uuid-CAdJg4l8.mjs.map} +1 -1
- package/package.json +9 -9
- package/dist/agent-GDLdDc2w.mjs.map +0 -1
- package/dist/jsonl-Dw_VBp46.mjs.map +0 -1
- package/dist/manager-D-lWBTHG.mjs.map +0 -1
- package/dist/registry-CFmR5G3J.mjs.map +0 -1
- package/dist/session-CUUdWFC5.mjs.map +0 -1
- package/dist/tasks-WmC270X2.mjs.map +0 -1
- package/dist/tools-DW1dbcCz.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notify-DpG_m9iP.mjs","names":[
|
|
1
|
+
{"version":3,"file":"notify-DpG_m9iP.mjs","names":[],"sources":["../src/notify.ts"],"sourcesContent":["import type { Agent } from \"./agent.ts\"\n\nimport { formatDuration } from \"@zaly/shared\"\n\nexport type NotifyContext = {\n agent: Agent\n}\n\nexport type NotifyOptions = {\n idle?: number // seconds of idle time (1800 = 30m)\n periodic?: number // seconds of periodic time notifications (3600 = 1h)\n}\n\nexport class Notifier {\n #opts: Required<NotifyOptions>\n #lastTime?: number\n #lastStep?: number\n /** Highest pressure threshold (from `#pressureLevels`) we've already\n * notified for in this session. Reset to 0 when pressure drops back\n * below the lowest threshold (e.g. after compaction), so a later\n * refill can fire the same level again. */\n #pressureLevel = 0\n #ac?: AbortController\n\n constructor(opts: NotifyOptions = {}) {\n this.#opts = { idle: 30 * 60, periodic: 60 * 60, ...opts }\n }\n\n attach(agent: Agent) {\n agent.on(\"step-start\", () => this.check(agent))\n agent.ctx.on(\"session\", () => this.attachSession(agent))\n this.attachSession(agent)\n }\n\n attachSession(agent: Agent) {\n this.#ac?.abort()\n this.#ac = new AbortController()\n const opts = { signal: this.#ac.signal }\n agent.session\n .on(\n \"compact\",\n ({ node }) => {\n this.#pressureLevel = 0\n agent.notify(\"compacted\", {\n ...this.time(),\n messages_preserved: node.tail,\n trigger: node.trigger,\n })\n },\n opts\n )\n .on(\n \"session-resume\",\n () => {\n agent.notify(\"session-resume\", this.time())\n },\n opts\n )\n .on(\n \"session-start\",\n () => {\n agent.notify(\"session-start\", this.time())\n },\n opts\n )\n .on(\n \"cwd\",\n ({ cwd }) => {\n agent.notify(\"cwd-changed\", { cwd })\n },\n opts\n )\n .on(\n \"model\",\n ({ model, prev }) => {\n agent.notify(\"model-changed\", { current: model, prev })\n },\n opts\n )\n }\n\n time(now = Date.now()) {\n this.#lastTime = now\n return timeInfo(now)\n }\n\n check(agent: Agent) {\n const now = Date.now()\n const lastInfo = this.#lastTime ? timeInfo(this.#lastTime) : undefined\n\n this.#lastStep ??= now\n this.#lastTime ??= now\n\n if (lastInfo && timeInfo(now).date !== lastInfo.date) {\n agent.notify(\"new-day\", this.time(now))\n } else if (now - this.#lastStep > this.#opts.idle * 1000) {\n agent.notify(\"user-returned\", {\n idle: formatDuration(this.#lastStep, { to: now }),\n ...this.time(now),\n })\n } else if (now - this.#lastTime > this.#opts.periodic * 1000) {\n agent.notify(\"time\", this.time(now))\n }\n this.#lastStep = now\n\n // Context-window pressure — denominator is `limit.context` (full\n // window), NOT `maxTokens` (per-request output cap). Notification\n // fires once per discrete level crossing (75% / 85% / 95%) so the\n // model gets at most a few escalating signals per session, not one\n // per step. Resets if pressure drops below the lowest level (e.g.\n // after compaction) so the cycle can fire again later.\n const pressure = agent.pressure\n if (pressure.level > this.#pressureLevel) {\n agent.notify(\"context-pressure\", {\n limit: pressure.limit,\n pct: Math.round(pressure.ratio * 100),\n used: pressure.used,\n })\n this.#pressureLevel = pressure.level\n } else if (pressure.level === 0) this.#pressureLevel = 0\n }\n}\n\nfunction timeInfo(t = Date.now()): {\n day: string\n date: string\n time: string\n tz: string\n} {\n const now = new Date(t)\n const tz = Intl.DateTimeFormat().resolvedOptions().timeZone\n return {\n date: now.toLocaleDateString(\"sv-SE\", { timeZone: tz }),\n day: now.toLocaleDateString(\"en-US\", { timeZone: tz, weekday: \"long\" }),\n time: now.toLocaleTimeString(\"sv-SE\", {\n hour: \"2-digit\",\n minute: \"2-digit\",\n timeZone: tz,\n }),\n tz,\n }\n}\n"],"mappings":";;AAaA,IAAa,WAAb,MAAsB;CACpB;CACA;CACA;;;;;CAKA,iBAAiB;CACjB;CAEA,YAAY,OAAsB,CAAC,GAAG;EACpC,KAAK,QAAQ;GAAE,MAAM;GAAS,UAAU;GAAS,GAAG;EAAK;CAC3D;CAEA,OAAO,OAAc;EACnB,MAAM,GAAG,oBAAoB,KAAK,MAAM,KAAK,CAAC;EAC9C,MAAM,IAAI,GAAG,iBAAiB,KAAK,cAAc,KAAK,CAAC;EACvD,KAAK,cAAc,KAAK;CAC1B;CAEA,cAAc,OAAc;EAC1B,KAAK,KAAK,MAAM;EAChB,KAAK,MAAM,IAAI,gBAAgB;EAC/B,MAAM,OAAO,EAAE,QAAQ,KAAK,IAAI,OAAO;EACvC,MAAM,QACH,GACC,YACC,EAAE,WAAW;GACZ,KAAK,iBAAiB;GACtB,MAAM,OAAO,aAAa;IACxB,GAAG,KAAK,KAAK;IACb,oBAAoB,KAAK;IACzB,SAAS,KAAK;GAChB,CAAC;EACH,GACA,IACF,CAAC,CACA,GACC,wBACM;GACJ,MAAM,OAAO,kBAAkB,KAAK,KAAK,CAAC;EAC5C,GACA,IACF,CAAC,CACA,GACC,uBACM;GACJ,MAAM,OAAO,iBAAiB,KAAK,KAAK,CAAC;EAC3C,GACA,IACF,CAAC,CACA,GACC,QACC,EAAE,UAAU;GACX,MAAM,OAAO,eAAe,EAAE,IAAI,CAAC;EACrC,GACA,IACF,CAAC,CACA,GACC,UACC,EAAE,OAAO,WAAW;GACnB,MAAM,OAAO,iBAAiB;IAAE,SAAS;IAAO;GAAK,CAAC;EACxD,GACA,IACF;CACJ;CAEA,KAAK,MAAM,KAAK,IAAI,GAAG;EACrB,KAAK,YAAY;EACjB,OAAO,SAAS,GAAG;CACrB;CAEA,MAAM,OAAc;EAClB,MAAM,MAAM,KAAK,IAAI;EACrB,MAAM,WAAW,KAAK,YAAY,SAAS,KAAK,SAAS,IAAI,KAAA;EAE7D,KAAK,cAAc;EACnB,KAAK,cAAc;EAEnB,IAAI,YAAY,SAAS,GAAG,CAAC,CAAC,SAAS,SAAS,MAC9C,MAAM,OAAO,WAAW,KAAK,KAAK,GAAG,CAAC;OACjC,IAAI,MAAM,KAAK,YAAY,KAAK,MAAM,OAAO,KAClD,MAAM,OAAO,iBAAiB;GAC5B,MAAM,eAAe,KAAK,WAAW,EAAE,IAAI,IAAI,CAAC;GAChD,GAAG,KAAK,KAAK,GAAG;EAClB,CAAC;OACI,IAAI,MAAM,KAAK,YAAY,KAAK,MAAM,WAAW,KACtD,MAAM,OAAO,QAAQ,KAAK,KAAK,GAAG,CAAC;EAErC,KAAK,YAAY;EAQjB,MAAM,WAAW,MAAM;EACvB,IAAI,SAAS,QAAQ,KAAK,gBAAgB;GACxC,MAAM,OAAO,oBAAoB;IAC/B,OAAO,SAAS;IAChB,KAAK,KAAK,MAAM,SAAS,QAAQ,GAAG;IACpC,MAAM,SAAS;GACjB,CAAC;GACD,KAAK,iBAAiB,SAAS;EACjC,OAAO,IAAI,SAAS,UAAU,GAAG,KAAK,iBAAiB;CACzD;AACF;AAEA,SAAS,SAAS,IAAI,KAAK,IAAI,GAK7B;CACA,MAAM,MAAM,IAAI,KAAK,CAAC;CACtB,MAAM,KAAK,KAAK,eAAe,CAAC,CAAC,gBAAgB,CAAC,CAAC;CACnD,OAAO;EACL,MAAM,IAAI,mBAAmB,SAAS,EAAE,UAAU,GAAG,CAAC;EACtD,KAAK,IAAI,mBAAmB,SAAS;GAAE,UAAU;GAAI,SAAS;EAAO,CAAC;EACtE,MAAM,IAAI,mBAAmB,SAAS;GACpC,MAAM;GACN,QAAQ;GACR,UAAU;EACZ,CAAC;EACD;CACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as __toESM, n as parseBash, r as __commonJSMin, t as TOOLS } from "./tools-
|
|
1
|
+
import { a as __toESM, n as parseBash, r as __commonJSMin, t as TOOLS } from "./tools-Bl-YI890.mjs";
|
|
2
2
|
import { normPath, prettyPath } from "@zaly/shared";
|
|
3
3
|
import { createRegistry } from "@zaly/shared/registry";
|
|
4
4
|
import { dirname, isAbsolute, relative } from "pathe";
|
|
@@ -156,13 +156,15 @@ var import_ignore = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
156
156
|
const EMPTY = "";
|
|
157
157
|
const SPACE = " ";
|
|
158
158
|
const ESCAPE = "\\";
|
|
159
|
-
const
|
|
159
|
+
const REGEX_LITERAL_SPECIAL = /[.*+?()[\]{}^$|\\/]/;
|
|
160
|
+
const REGEX_TEST_BLANK_LINE = /^ +$/;
|
|
160
161
|
const REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
|
|
161
162
|
const REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
|
|
162
163
|
const REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
|
|
163
164
|
const REGEX_SPLITALL_CRLF = /\r?\n/g;
|
|
164
|
-
const
|
|
165
|
-
const
|
|
165
|
+
const DOUBLE_SLASH = "//";
|
|
166
|
+
const SLASH_CODE = 47;
|
|
167
|
+
const DOT_CODE = 46;
|
|
166
168
|
const SLASH = "/";
|
|
167
169
|
let TMP_KEY_IGNORE = "node-ignore";
|
|
168
170
|
/* istanbul ignore else */
|
|
@@ -172,38 +174,203 @@ var import_ignore = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
172
174
|
Object.defineProperty(object, key, { value });
|
|
173
175
|
return value;
|
|
174
176
|
};
|
|
175
|
-
const REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
|
|
176
177
|
const RETURN_FALSE = () => false;
|
|
177
|
-
const sanitizeRange = (range) => range.replace(REGEX_REGEXP_RANGE, (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match : EMPTY);
|
|
178
178
|
const cleanRangeBackSlash = (slashes) => {
|
|
179
179
|
const { length } = slashes;
|
|
180
180
|
return slashes.slice(0, length - length % 2);
|
|
181
181
|
};
|
|
182
|
+
const POSIX_CLASSES = {
|
|
183
|
+
alnum: "0-9A-Za-z",
|
|
184
|
+
alpha: "A-Za-z",
|
|
185
|
+
blank: " \\t",
|
|
186
|
+
cntrl: "\\x00-\\x1f\\x7f",
|
|
187
|
+
digit: "0-9",
|
|
188
|
+
graph: "!-.0-~",
|
|
189
|
+
lower: "a-z",
|
|
190
|
+
print: " -.0-~",
|
|
191
|
+
punct: "!-.:-@\\[-`{-~",
|
|
192
|
+
space: " \\t\\n\\r",
|
|
193
|
+
upper: "A-Z",
|
|
194
|
+
xdigit: "0-9A-Fa-f"
|
|
195
|
+
};
|
|
196
|
+
const CLASS_MEMBERS_TO_ESCAPE = "\\]^-[";
|
|
197
|
+
const escapeMember = (char) => CLASS_MEMBERS_TO_ESCAPE.indexOf(char) < 0 ? char : ESCAPE + char;
|
|
198
|
+
const NON_SLASH = "(?!\\/)";
|
|
199
|
+
const classSource = (negated, body) => {
|
|
200
|
+
if (negated) return `[^\\/${body}]`;
|
|
201
|
+
const source = `[${body}]`;
|
|
202
|
+
return new RegExp(source).test("/") ? NON_SLASH + source : source;
|
|
203
|
+
};
|
|
204
|
+
const scanBracket = (pattern, start) => {
|
|
205
|
+
const { length } = pattern;
|
|
206
|
+
let index = start + 1;
|
|
207
|
+
let negated = EMPTY;
|
|
208
|
+
const lead = pattern[index];
|
|
209
|
+
if (lead === "!" || lead === "^") {
|
|
210
|
+
negated = "^";
|
|
211
|
+
index++;
|
|
212
|
+
}
|
|
213
|
+
let body = EMPTY;
|
|
214
|
+
let prev = EMPTY;
|
|
215
|
+
for (;;) {
|
|
216
|
+
const char = pattern[index];
|
|
217
|
+
if (char === UNDEFINED) return null;
|
|
218
|
+
if (char === ESCAPE) {
|
|
219
|
+
const escaped = pattern[index + 1];
|
|
220
|
+
if (escaped === UNDEFINED) return null;
|
|
221
|
+
body += escapeMember(escaped);
|
|
222
|
+
prev = escaped;
|
|
223
|
+
index++;
|
|
224
|
+
} else if (char === "-" && prev && index + 1 < length && pattern[index + 1] !== "]") {
|
|
225
|
+
index++;
|
|
226
|
+
let to = pattern[index];
|
|
227
|
+
if (to === ESCAPE) to = pattern[index += 1];
|
|
228
|
+
if (prev <= to) body += `-${escapeMember(to)}`;
|
|
229
|
+
prev = EMPTY;
|
|
230
|
+
} else if (char === "[" && pattern[index + 1] === ":") {
|
|
231
|
+
const nameStart = index + 2;
|
|
232
|
+
let end = nameStart;
|
|
233
|
+
while (end < length && pattern[end] !== "]") end++;
|
|
234
|
+
if (end === length) return null;
|
|
235
|
+
if (end > nameStart && pattern[end - 1] === ":") {
|
|
236
|
+
const expanded = POSIX_CLASSES[pattern.slice(nameStart, end - 1)];
|
|
237
|
+
if (expanded === UNDEFINED) return null;
|
|
238
|
+
body += expanded;
|
|
239
|
+
prev = EMPTY;
|
|
240
|
+
index = end;
|
|
241
|
+
} else {
|
|
242
|
+
body += escapeMember("[");
|
|
243
|
+
prev = "[";
|
|
244
|
+
index = nameStart - 2;
|
|
245
|
+
}
|
|
246
|
+
} else {
|
|
247
|
+
body += escapeMember(char);
|
|
248
|
+
prev = char;
|
|
249
|
+
}
|
|
250
|
+
index++;
|
|
251
|
+
if (pattern[index] === "]") return {
|
|
252
|
+
end: index,
|
|
253
|
+
source: classSource(negated, body)
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
const NEVER_MATCH = "[]";
|
|
258
|
+
const PLACEHOLDER = "\0";
|
|
259
|
+
const REGEX_RESTORE_PLACEHOLDER = new RegExp(`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`, "g");
|
|
260
|
+
const TRAILING_WILDCARD = "";
|
|
261
|
+
const extractBrackets = (pattern) => {
|
|
262
|
+
const sources = [];
|
|
263
|
+
const hold = (source) => `${PLACEHOLDER}${sources.push(source) - 1}${PLACEHOLDER}`;
|
|
264
|
+
const { length } = pattern;
|
|
265
|
+
let out = EMPTY;
|
|
266
|
+
let index = 0;
|
|
267
|
+
while (index < length) {
|
|
268
|
+
const char = pattern[index];
|
|
269
|
+
if (char === ESCAPE) {
|
|
270
|
+
const escaped = pattern[index + 1];
|
|
271
|
+
if (escaped === "*" || escaped === "[" || escaped === SPACE || escaped === ESCAPE) out += pattern.slice(index, index + 2);
|
|
272
|
+
else out += hold(REGEX_LITERAL_SPECIAL.test(escaped) ? ESCAPE + escaped : escaped);
|
|
273
|
+
index += 2;
|
|
274
|
+
} else if (char === PLACEHOLDER) {
|
|
275
|
+
out += hold(`[${PLACEHOLDER}]`);
|
|
276
|
+
index++;
|
|
277
|
+
} else if (char === "[") {
|
|
278
|
+
const scanned = scanBracket(pattern, index);
|
|
279
|
+
if (scanned === null) {
|
|
280
|
+
out += hold(NEVER_MATCH);
|
|
281
|
+
index = length;
|
|
282
|
+
} else {
|
|
283
|
+
out += hold(scanned.source);
|
|
284
|
+
index = scanned.end + 1;
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
out += char;
|
|
288
|
+
index++;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
source: out,
|
|
293
|
+
sources
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
const DIRECT = null;
|
|
297
|
+
const REGEX_INNER_SLASH = /\/(?!$)/;
|
|
182
298
|
const REPLACERS = [
|
|
183
|
-
[
|
|
184
|
-
|
|
185
|
-
|
|
299
|
+
[
|
|
300
|
+
/^\uFEFF/,
|
|
301
|
+
() => EMPTY,
|
|
302
|
+
""
|
|
303
|
+
],
|
|
304
|
+
[/[\r\n]+$/, () => EMPTY],
|
|
305
|
+
[/((?:\\\\)*?)(\\? +)$/, (_, m1, m2) => m1 + (m2.indexOf("\\") === 0 ? SPACE : EMPTY)],
|
|
306
|
+
[/(\\+?) /g, (_, m1) => {
|
|
186
307
|
const { length } = m1;
|
|
187
308
|
return m1.slice(0, length - length % 2) + SPACE;
|
|
188
309
|
}],
|
|
189
310
|
[/[\\$.|*+(){^]/g, (match) => `\\${match}`],
|
|
190
|
-
[
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
311
|
+
[
|
|
312
|
+
/(?!\\)\?/g,
|
|
313
|
+
() => "[^/]",
|
|
314
|
+
"?"
|
|
315
|
+
],
|
|
316
|
+
[
|
|
317
|
+
/^\//,
|
|
318
|
+
() => "^",
|
|
319
|
+
SLASH
|
|
320
|
+
],
|
|
321
|
+
[
|
|
322
|
+
/\//g,
|
|
323
|
+
() => "\\/",
|
|
324
|
+
SLASH
|
|
325
|
+
],
|
|
326
|
+
[
|
|
327
|
+
/^\^*(?:\\\*\\\*\\\/)+/,
|
|
328
|
+
() => "^(?:.*\\/)?",
|
|
329
|
+
"*"
|
|
330
|
+
],
|
|
331
|
+
[DIRECT, (source, pattern) => {
|
|
332
|
+
if (!source || source[0] === "^") return source;
|
|
333
|
+
return (!REGEX_INNER_SLASH.test(pattern) ? "(?:^|\\/)" : "^") + source;
|
|
196
334
|
}],
|
|
197
|
-
[
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
[
|
|
203
|
-
|
|
204
|
-
|
|
335
|
+
[
|
|
336
|
+
/\\\/\\\*\\\*(?=\\\/|$)/g,
|
|
337
|
+
(_, index, str) => index + 6 < str.length ? str.slice(index + 6) === "\\/" ? "(?:\\/[^\\/]+)+" : "(?:\\/[^\\/]+)*" : "\\/.+",
|
|
338
|
+
"*"
|
|
339
|
+
],
|
|
340
|
+
[
|
|
341
|
+
/(^|[^\\]+)(\\\*)+(?=.+)/g,
|
|
342
|
+
(_, p1, p2) => {
|
|
343
|
+
return p1 + p2.replace(/\\\*/g, "[^\\/]*");
|
|
344
|
+
},
|
|
345
|
+
"*"
|
|
346
|
+
],
|
|
347
|
+
[
|
|
348
|
+
/(^|[^\\])((?:\\\\)*)\\\*$/,
|
|
349
|
+
(match, p1, p2) => p2.length / 2 % 2 === 0 ? p1 + p2 + TRAILING_WILDCARD : match,
|
|
350
|
+
"*"
|
|
351
|
+
],
|
|
352
|
+
[
|
|
353
|
+
/\\\\\\(?=[$.|*+(){^])/g,
|
|
354
|
+
() => ESCAPE,
|
|
355
|
+
"\\\\"
|
|
356
|
+
],
|
|
357
|
+
[
|
|
358
|
+
/\\\\/g,
|
|
359
|
+
() => ESCAPE,
|
|
360
|
+
"\\\\"
|
|
361
|
+
],
|
|
362
|
+
[
|
|
363
|
+
/\\\[([^\]/]*?)(\\*)($|\])/g,
|
|
364
|
+
(match, range, endEscape, close) => `\\[${range}${cleanRangeBackSlash(endEscape)}${close}`,
|
|
365
|
+
"["
|
|
366
|
+
],
|
|
367
|
+
[DIRECT, (source) => {
|
|
368
|
+
const last = source[source.length - 1];
|
|
369
|
+
if (!last || last === TRAILING_WILDCARD) return source;
|
|
370
|
+
return last === SLASH ? `${source}$` : `${source}(?=$|\\/$)`;
|
|
371
|
+
}]
|
|
205
372
|
];
|
|
206
|
-
const REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)
|
|
373
|
+
const REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\uE000$/;
|
|
207
374
|
const MODE_IGNORE = "regex";
|
|
208
375
|
const MODE_CHECK_IGNORE = "checkRegex";
|
|
209
376
|
const TRAILING_WILD_CARD_REPLACERS = {
|
|
@@ -214,7 +381,103 @@ var import_ignore = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
214
381
|
return `${p1 ? `${p1}[^/]*` : "[^/]*"}(?=$|\\/$)`;
|
|
215
382
|
}
|
|
216
383
|
};
|
|
217
|
-
const
|
|
384
|
+
const WILDCARD = "[^\\/]*";
|
|
385
|
+
const pinWildcards = (source) => {
|
|
386
|
+
if (source.indexOf(WILDCARD) < 0) return source;
|
|
387
|
+
const tokens = [];
|
|
388
|
+
const { length } = source;
|
|
389
|
+
let index = 0;
|
|
390
|
+
while (index < length) {
|
|
391
|
+
const char = source[index];
|
|
392
|
+
if (source.startsWith(WILDCARD, index)) {
|
|
393
|
+
tokens.push({ wildcard: true });
|
|
394
|
+
index += 6;
|
|
395
|
+
} else if (char === "[") {
|
|
396
|
+
let end = index + 1;
|
|
397
|
+
if (source[end] === "^") end++;
|
|
398
|
+
if (source[end] === "]") end++;
|
|
399
|
+
while (end < length && source[end] !== "]") end += source[end] === ESCAPE ? 2 : 1;
|
|
400
|
+
end++;
|
|
401
|
+
tokens.push({ single: source.slice(index, end) });
|
|
402
|
+
index = end;
|
|
403
|
+
} else if (char === ESCAPE) {
|
|
404
|
+
tokens.push({ single: source.slice(index, index + 2) });
|
|
405
|
+
index += 2;
|
|
406
|
+
} else if (char === "(") {
|
|
407
|
+
let depth = 0;
|
|
408
|
+
let end = index;
|
|
409
|
+
do {
|
|
410
|
+
if (source[end] === ESCAPE) end++;
|
|
411
|
+
else if (source[end] === "(") depth++;
|
|
412
|
+
else if (source[end] === ")") depth--;
|
|
413
|
+
end++;
|
|
414
|
+
} while (end < length && depth > 0);
|
|
415
|
+
if ("*+?".indexOf(source[end]) >= 0) end++;
|
|
416
|
+
tokens.push({ boundary: source.slice(index, end) });
|
|
417
|
+
index = end;
|
|
418
|
+
} else if (char === "^" || char === "$") {
|
|
419
|
+
tokens.push({ boundary: char });
|
|
420
|
+
index++;
|
|
421
|
+
} else {
|
|
422
|
+
tokens.push({ single: char });
|
|
423
|
+
index++;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
let out = EMPTY;
|
|
427
|
+
let run = [];
|
|
428
|
+
const flush = () => {
|
|
429
|
+
let lastWildcard;
|
|
430
|
+
run.forEach((token, at) => {
|
|
431
|
+
if (token.wildcard) lastWildcard = at;
|
|
432
|
+
});
|
|
433
|
+
run.forEach((token, at) => {
|
|
434
|
+
if (!token.wildcard) {
|
|
435
|
+
out += token.single;
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
out += at === lastWildcard ? WILDCARD : `(?:(?!${run[at + 1].single})[^\\/])*`;
|
|
439
|
+
});
|
|
440
|
+
run = [];
|
|
441
|
+
};
|
|
442
|
+
tokens.forEach((token) => {
|
|
443
|
+
if (token.boundary === void 0) {
|
|
444
|
+
run.push(token);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
flush();
|
|
448
|
+
out += token.boundary;
|
|
449
|
+
});
|
|
450
|
+
flush();
|
|
451
|
+
return out;
|
|
452
|
+
};
|
|
453
|
+
const makeRegexPrefix = (pattern) => {
|
|
454
|
+
const { source, sources } = extractBrackets(pattern);
|
|
455
|
+
const replaced = REPLACERS.reduce((prev, [matcher, replacer, required]) => {
|
|
456
|
+
if (matcher === DIRECT) return replacer(prev, pattern);
|
|
457
|
+
if (required !== UNDEFINED && prev.indexOf(required) < 0) return prev;
|
|
458
|
+
return matcher.test(prev) ? prev.replace(matcher, replacer.bind(pattern)) : prev;
|
|
459
|
+
}, source);
|
|
460
|
+
return sources.length ? replaced.replace(REGEX_RESTORE_PLACEHOLDER, (match, index) => sources[index]) : replaced;
|
|
461
|
+
};
|
|
462
|
+
const matchesBasename = (body) => {
|
|
463
|
+
const index = body.indexOf(SLASH);
|
|
464
|
+
return index < 0 || index === body.length - 1;
|
|
465
|
+
};
|
|
466
|
+
const basenameOf = (path) => {
|
|
467
|
+
const end = path.length - 1;
|
|
468
|
+
const index = path.lastIndexOf(SLASH, path[end] === SLASH ? end - 1 : end);
|
|
469
|
+
return index < 0 ? path : path.slice(index + 1);
|
|
470
|
+
};
|
|
471
|
+
const parentOf = (path) => {
|
|
472
|
+
if (path.charCodeAt(0) === SLASH_CODE || path.indexOf(DOUBLE_SLASH) >= 0) {
|
|
473
|
+
const slices = path.split(SLASH).filter(Boolean);
|
|
474
|
+
slices.pop();
|
|
475
|
+
return slices.length ? slices.join(SLASH) + SLASH : EMPTY;
|
|
476
|
+
}
|
|
477
|
+
const end = path.length - 1;
|
|
478
|
+
const cut = path.lastIndexOf(SLASH, path.charCodeAt(end) === SLASH_CODE ? end - 1 : end);
|
|
479
|
+
return cut < 0 ? EMPTY : path.slice(0, cut + 1);
|
|
480
|
+
};
|
|
218
481
|
const isString = (subject) => typeof subject === "string";
|
|
219
482
|
const checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) && pattern.indexOf("#") !== 0;
|
|
220
483
|
const splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
|
|
@@ -227,6 +490,9 @@ var import_ignore = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
227
490
|
define(this, "ignoreCase", ignoreCase);
|
|
228
491
|
define(this, "regexPrefix", prefix);
|
|
229
492
|
}
|
|
493
|
+
get _basenameOnly() {
|
|
494
|
+
return define(this, "_basenameOnly", matchesBasename(this.body));
|
|
495
|
+
}
|
|
230
496
|
get regex() {
|
|
231
497
|
const key = "_regex";
|
|
232
498
|
if (this[key]) return this[key];
|
|
@@ -238,7 +504,7 @@ var import_ignore = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
238
504
|
return this._make(MODE_CHECK_IGNORE, key);
|
|
239
505
|
}
|
|
240
506
|
_make(mode, key) {
|
|
241
|
-
const str = this.regexPrefix.replace(REGEX_REPLACE_TRAILING_WILDCARD, TRAILING_WILD_CARD_REPLACERS[mode]);
|
|
507
|
+
const str = pinWildcards(this.regexPrefix.replace(REGEX_REPLACE_TRAILING_WILDCARD, TRAILING_WILD_CARD_REPLACERS[mode]));
|
|
242
508
|
const regex = this.ignoreCase ? new RegExp(str, "i") : new RegExp(str);
|
|
243
509
|
return define(this, key, regex);
|
|
244
510
|
}
|
|
@@ -258,10 +524,12 @@ var import_ignore = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
258
524
|
constructor(ignoreCase) {
|
|
259
525
|
this._ignoreCase = ignoreCase;
|
|
260
526
|
this._rules = [];
|
|
527
|
+
this._basenameCount = 0;
|
|
261
528
|
}
|
|
262
529
|
_add(pattern) {
|
|
263
530
|
if (pattern && pattern[KEY_IGNORE]) {
|
|
264
531
|
this._rules = this._rules.concat(pattern._rules._rules);
|
|
532
|
+
this._basenameCount += pattern._rules._basenameCount;
|
|
265
533
|
this._added = true;
|
|
266
534
|
return;
|
|
267
535
|
}
|
|
@@ -270,6 +538,7 @@ var import_ignore = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
270
538
|
const rule = createRule(pattern, this._ignoreCase);
|
|
271
539
|
this._added = true;
|
|
272
540
|
this._rules.push(rule);
|
|
541
|
+
if (matchesBasename(rule.body)) this._basenameCount++;
|
|
273
542
|
}
|
|
274
543
|
}
|
|
275
544
|
add(pattern) {
|
|
@@ -281,14 +550,19 @@ var import_ignore = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
281
550
|
let ignored = false;
|
|
282
551
|
let unignored = false;
|
|
283
552
|
let matchedRule;
|
|
284
|
-
this._rules
|
|
553
|
+
const rules = this._rules;
|
|
554
|
+
const { length } = rules;
|
|
555
|
+
const shortcut = this._basenameCount * 2 >= length;
|
|
556
|
+
const basename = shortcut ? basenameOf(path) : path;
|
|
557
|
+
for (let index = 0; index < length; index++) {
|
|
558
|
+
const rule = rules[index];
|
|
285
559
|
const { negative } = rule;
|
|
286
|
-
if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored)
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
560
|
+
if (!(unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) && rule[mode].test(shortcut && rule._basenameOnly ? basename : path)) {
|
|
561
|
+
ignored = !negative;
|
|
562
|
+
unignored = negative;
|
|
563
|
+
matchedRule = negative ? UNDEFINED : rule;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
292
566
|
const ret = {
|
|
293
567
|
ignored,
|
|
294
568
|
unignored
|
|
@@ -306,7 +580,16 @@ var import_ignore = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
306
580
|
if (checkPath.isNotRelative(path)) return doThrow(`path should be a \`path.relative()\`d string, but got "${originalPath}"`, RangeError);
|
|
307
581
|
return true;
|
|
308
582
|
};
|
|
309
|
-
const isNotRelative = (path) =>
|
|
583
|
+
const isNotRelative = (path) => {
|
|
584
|
+
const first = path.charCodeAt(0);
|
|
585
|
+
if (first === SLASH_CODE) return true;
|
|
586
|
+
if (first !== DOT_CODE) return false;
|
|
587
|
+
if (path.length === 1) return true;
|
|
588
|
+
const second = path.charCodeAt(1);
|
|
589
|
+
if (second === SLASH_CODE) return true;
|
|
590
|
+
if (second !== DOT_CODE) return false;
|
|
591
|
+
return path.length === 2 || path.charCodeAt(2) === SLASH_CODE;
|
|
592
|
+
};
|
|
310
593
|
checkPath.isNotRelative = isNotRelative;
|
|
311
594
|
/* istanbul ignore next */
|
|
312
595
|
checkPath.convert = (p) => p;
|
|
@@ -328,28 +611,25 @@ var import_ignore = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
|
|
|
328
611
|
addPattern(pattern) {
|
|
329
612
|
return this.add(pattern);
|
|
330
613
|
}
|
|
331
|
-
_test(originalPath, cache, checkUnignored
|
|
614
|
+
_test(originalPath, cache, checkUnignored) {
|
|
332
615
|
const path = originalPath && checkPath.convert(originalPath);
|
|
333
616
|
checkPath(path, originalPath, this._strictPathCheck ? throwError : RETURN_FALSE);
|
|
334
|
-
return this._t(path, cache, checkUnignored
|
|
617
|
+
return this._t(path, cache, checkUnignored);
|
|
335
618
|
}
|
|
336
619
|
checkIgnore(path) {
|
|
337
|
-
if (
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const parent = this._t(slices.join(SLASH) + SLASH, this._testCache, true, slices);
|
|
620
|
+
if (path.charCodeAt(path.length - 1) !== SLASH_CODE) return this.test(path);
|
|
621
|
+
const parentPath = parentOf(path);
|
|
622
|
+
if (parentPath) {
|
|
623
|
+
const parent = this._t(parentPath, this._testCache, true);
|
|
342
624
|
if (parent.ignored) return parent;
|
|
343
625
|
}
|
|
344
626
|
return this._rules.test(path, false, MODE_CHECK_IGNORE);
|
|
345
627
|
}
|
|
346
|
-
_t(path, cache, checkUnignored
|
|
628
|
+
_t(path, cache, checkUnignored) {
|
|
347
629
|
if (path in cache) return cache[path];
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
const parent = this._t(slices.join(SLASH) + SLASH, cache, checkUnignored, slices);
|
|
352
|
-
return cache[path] = parent.ignored ? parent : this._rules.test(path, checkUnignored, MODE_IGNORE);
|
|
630
|
+
const parentPath = parentOf(path);
|
|
631
|
+
const parent = parentPath ? this._t(parentPath, cache, checkUnignored) : UNDEFINED;
|
|
632
|
+
return cache[path] = parent && parent.ignored ? parent : this._rules.test(path, checkUnignored, MODE_IGNORE);
|
|
353
633
|
}
|
|
354
634
|
ignores(path) {
|
|
355
635
|
return this._test(path, this._ignoreCache, false).ignored;
|
|
@@ -561,4 +841,4 @@ const handlerRegistry = createRegistry("scope").from({
|
|
|
561
841
|
//#endregion
|
|
562
842
|
export { handlerRegistry as t };
|
|
563
843
|
|
|
564
|
-
//# sourceMappingURL=registry-
|
|
844
|
+
//# sourceMappingURL=registry-BVf0aZEA.mjs.map
|