@darkrymit/crunes-cli 0.13.0 → 0.14.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.
Files changed (26) hide show
  1. package/dist/chunks/{benchmark-2TVN6HDF.js → benchmark-HBIZCVFR.js} +3 -3
  2. package/dist/chunks/{chunk-THGPCLJD.js → chunk-2N6X32LY.js} +5 -3
  3. package/dist/chunks/{chunk-TXCUSUZ6.js → chunk-32GEHGUV.js} +2500 -2347
  4. package/dist/chunks/{chunk-CBWT3DFR.js → chunk-5L2GJWCD.js} +4 -0
  5. package/dist/chunks/{chunk-ATI5HNNC.js → chunk-C3FADOZT.js} +2 -2
  6. package/dist/chunks/{chunk-3VFNNPQI.js → chunk-PICTIOYJ.js} +3 -3
  7. package/dist/chunks/{chunk-QAP63JIK.js → chunk-WUNDVEEL.js} +5 -5
  8. package/dist/chunks/chunk-XPEVUBUK.js +40 -0
  9. package/dist/chunks/{chunk-KP4EW2DS.js → chunk-ZFIRPZPE.js} +153 -15
  10. package/dist/chunks/{doctor-SXKAEYUF.js → doctor-HLQE7TVE.js} +1 -1
  11. package/dist/chunks/{install-FSJAC3CL.js → install-2K5BNXDO.js} +1 -1
  12. package/dist/chunks/{intro-PN7LT6ZG.js → intro-L5WBDL2P.js} +1 -1
  13. package/dist/chunks/{kill-Z7ZDY5MB.js → kill-IX7HNMVP.js} +12 -4
  14. package/dist/chunks/{list-45SHVKXO.js → list-BJTV6SPK.js} +1 -1
  15. package/dist/chunks/{repl-PSADU3MJ.js → repl-GNA342PP.js} +4 -4
  16. package/dist/chunks/{resolver-YEUZSOS4.js → resolver-II54EHPA.js} +2 -2
  17. package/dist/chunks/{run-CYGL3HTA.js → run-PXTN5GYH.js} +3 -3
  18. package/dist/chunks/{rune-OQX5EYSQ.js → rune-7YEZJTHK.js} +5 -4
  19. package/dist/chunks/{runner-VUSHR2OR.js → runner-OKVKI7FP.js} +3 -2
  20. package/dist/chunks/{uninstall-MSCIWDWV.js → uninstall-X75QTERD.js} +1 -1
  21. package/dist/chunks/{update-IHCYA3JW.js → update-HHIDPHGX.js} +1 -1
  22. package/dist/chunks/{utils-DJ3BXOQC.js → utils-K7DAKWGS.js} +1 -1
  23. package/dist/chunks/{version-SBE7LQ5C.js → version-RZVOIMQG.js} +1 -1
  24. package/dist/cli.js +14 -14
  25. package/dist/test/index.js +135 -3
  26. package/package.json +1 -1
@@ -9,7 +9,7 @@ import "./chunk-PRCVJ727.js";
9
9
  import "./chunk-AFAVAB5Q.js";
10
10
  import {
11
11
  describeRunBlock
12
- } from "./chunk-ATI5HNNC.js";
12
+ } from "./chunk-C3FADOZT.js";
13
13
  import {
14
14
  assertNotMissedRename,
15
15
  onPath,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-Z4W3ZDFC.js";
4
4
  import {
5
5
  installPlugin
6
- } from "./chunk-THGPCLJD.js";
6
+ } from "./chunk-2N6X32LY.js";
7
7
  import "./chunk-GBUZOC3O.js";
8
8
  import "./chunk-J33GQMPV.js";
9
9
  import {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  utils_api_default
3
- } from "./chunk-TXCUSUZ6.js";
3
+ } from "./chunk-32GEHGUV.js";
4
4
  import {
5
5
  globals_api_default
6
6
  } from "./chunk-V35LVVNV.js";
@@ -1,8 +1,12 @@
1
+ import {
2
+ killWindowsShellJob
3
+ } from "./chunk-XPEVUBUK.js";
1
4
  import {
2
5
  deleteJob,
3
6
  listJobs,
4
7
  resolveJobId
5
- } from "./chunk-CBWT3DFR.js";
8
+ } from "./chunk-5L2GJWCD.js";
9
+ import "./chunk-ZT4QFTQM.js";
6
10
  import "./chunk-7YY3GPPK.js";
7
11
  import {
8
12
  init_require_shim
@@ -20,9 +24,13 @@ async function handler({ id, projectDir }) {
20
24
  process.exit(1);
21
25
  }
22
26
  const record = jobs.find((j) => j.id === resolvedId);
23
- try {
24
- process.kill(record.pid, "SIGTERM");
25
- } catch {
27
+ if (process.platform === "win32" && record.type === "shell") {
28
+ await killWindowsShellJob(projectDir, record);
29
+ } else {
30
+ try {
31
+ process.kill(record.pid, "SIGTERM");
32
+ } catch {
33
+ }
26
34
  }
27
35
  await deleteJob(projectDir, record.id);
28
36
  console.log(`Sent SIGTERM to job ${record.id.slice(0, 8)} (${record.runeKey ?? "unknown"})`);
@@ -2,7 +2,7 @@ import {
2
2
  cleanJobs,
3
3
  isAlive,
4
4
  listJobs
5
- } from "./chunk-CBWT3DFR.js";
5
+ } from "./chunk-5L2GJWCD.js";
6
6
  import "./chunk-7YY3GPPK.js";
7
7
  import {
8
8
  init_require_shim
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  parseSegment,
3
3
  permissionHint
4
- } from "./chunk-3VFNNPQI.js";
4
+ } from "./chunk-PICTIOYJ.js";
5
5
  import {
6
6
  tailStdin
7
7
  } from "./chunk-OV4WBJT3.js";
@@ -13,10 +13,10 @@ import "./chunk-PRCVJ727.js";
13
13
  import "./chunk-AFAVAB5Q.js";
14
14
  import {
15
15
  describeConfigLayers
16
- } from "./chunk-QAP63JIK.js";
16
+ } from "./chunk-WUNDVEEL.js";
17
17
  import {
18
18
  formatSection
19
- } from "./chunk-ATI5HNNC.js";
19
+ } from "./chunk-C3FADOZT.js";
20
20
  import "./chunk-UKAIACRQ.js";
21
21
  import "./chunk-HQUMVDQE.js";
22
22
  import {
@@ -157,7 +157,7 @@ async function handler({
157
157
  output.info("Run `crunes init` to create a config file.");
158
158
  process.exit(1);
159
159
  }
160
- const { resolveRuneEntry } = await import("./resolver-YEUZSOS4.js");
160
+ const { resolveRuneEntry } = await import("./resolver-II54EHPA.js");
161
161
  let runeEntry;
162
162
  try {
163
163
  runeEntry = await resolveRuneEntry(projectRoot, config, key, configRoot);
@@ -4,8 +4,8 @@ import {
4
4
  resolveRuneEntry,
5
5
  resolveRuneFromPlugins,
6
6
  runRune
7
- } from "./chunk-QAP63JIK.js";
8
- import "./chunk-ATI5HNNC.js";
7
+ } from "./chunk-WUNDVEEL.js";
8
+ import "./chunk-C3FADOZT.js";
9
9
  import "./chunk-UKAIACRQ.js";
10
10
  import "./chunk-HQUMVDQE.js";
11
11
  import {
@@ -4,12 +4,12 @@ import {
4
4
  parseBracketKey,
5
5
  parseRunArgs,
6
6
  parseSegment
7
- } from "./chunk-3VFNNPQI.js";
7
+ } from "./chunk-PICTIOYJ.js";
8
8
  import "./chunk-RQ6KHY6W.js";
9
9
  import "./chunk-PRCVJ727.js";
10
10
  import "./chunk-AFAVAB5Q.js";
11
- import "./chunk-QAP63JIK.js";
12
- import "./chunk-ATI5HNNC.js";
11
+ import "./chunk-WUNDVEEL.js";
12
+ import "./chunk-C3FADOZT.js";
13
13
  import "./chunk-UKAIACRQ.js";
14
14
  import "./chunk-HQUMVDQE.js";
15
15
  import "./chunk-YUI5RTLD.js";
@@ -5,9 +5,10 @@ import {
5
5
  getArgsSchema,
6
6
  getPluginRunePath,
7
7
  getReplSchema
8
- } from "./chunk-KP4EW2DS.js";
8
+ } from "./chunk-ZFIRPZPE.js";
9
9
  import "./chunk-HYPUZ5DT.js";
10
- import "./chunk-CBWT3DFR.js";
10
+ import "./chunk-XPEVUBUK.js";
11
+ import "./chunk-5L2GJWCD.js";
11
12
  import "./chunk-BAIIJ4OC.js";
12
13
  import "./chunk-OV4WBJT3.js";
13
14
  import {
@@ -18,7 +19,7 @@ import "./chunk-AFAVAB5Q.js";
18
19
  import {
19
20
  resolvePluginRune,
20
21
  resolveRuneFromPlugins
21
- } from "./chunk-QAP63JIK.js";
22
+ } from "./chunk-WUNDVEEL.js";
22
23
  import {
23
24
  describeRunBlock,
24
25
  flattenCommands,
@@ -27,7 +28,7 @@ import {
27
28
  formatRuneIndex,
28
29
  getRunBlockSchema,
29
30
  selectNode
30
- } from "./chunk-ATI5HNNC.js";
31
+ } from "./chunk-C3FADOZT.js";
31
32
  import {
32
33
  resolveInterpreter
33
34
  } from "./chunk-UKAIACRQ.js";
@@ -7,9 +7,10 @@ import {
7
7
  runPluginRune,
8
8
  runRuneInIsolate,
9
9
  runRuneInRepl
10
- } from "./chunk-KP4EW2DS.js";
10
+ } from "./chunk-ZFIRPZPE.js";
11
11
  import "./chunk-HYPUZ5DT.js";
12
- import "./chunk-CBWT3DFR.js";
12
+ import "./chunk-XPEVUBUK.js";
13
+ import "./chunk-5L2GJWCD.js";
13
14
  import "./chunk-BAIIJ4OC.js";
14
15
  import "./chunk-OV4WBJT3.js";
15
16
  import "./chunk-RQ6KHY6W.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  uninstallPlugin
3
- } from "./chunk-THGPCLJD.js";
3
+ } from "./chunk-2N6X32LY.js";
4
4
  import "./chunk-GBUZOC3O.js";
5
5
  import "./chunk-J33GQMPV.js";
6
6
  import {
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-Z4W3ZDFC.js";
4
4
  import {
5
5
  installPlugin
6
- } from "./chunk-THGPCLJD.js";
6
+ } from "./chunk-2N6X32LY.js";
7
7
  import "./chunk-GBUZOC3O.js";
8
8
  import "./chunk-J33GQMPV.js";
9
9
  import {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  utils_api_default
3
- } from "./chunk-TXCUSUZ6.js";
3
+ } from "./chunk-32GEHGUV.js";
4
4
  import {
5
5
  formatNode,
6
6
  walk
@@ -16,7 +16,7 @@ import path from "node:path";
16
16
  // package.json
17
17
  var package_default = {
18
18
  name: "@darkrymit/crunes-cli",
19
- version: "0.13.0",
19
+ version: "0.14.0",
20
20
  description: "CLI tool for querying crunes enrichers",
21
21
  type: "module",
22
22
  bin: {
package/dist/cli.js CHANGED
@@ -3397,7 +3397,7 @@ var program = new Command();
3397
3397
  // src/cli/program.js
3398
3398
  function buildProgram() {
3399
3399
  const program3 = new Command();
3400
- program3.name("crunes").description("CLI tool for managing context runes").version("0.13.0", "-v, --version").enablePositionalOptions().option("-y, --yes", "assume yes to all prompts and skip interactive mode (also auto-detected in non-TTY environments)").option("-p, --plain", "plain output: no colors, no box-drawing, plain symbols \u2014 optimised for AI/pipe use").option("--cwd <path>", "project root to use instead of the current working directory").option("--ccd <path>", "config directory \u2014 where .crunes/config.json and local rune files live (default: --cwd)").option("--verbose", "print full error stack traces and other verbose output");
3400
+ program3.name("crunes").description("CLI tool for managing context runes").version("0.14.0", "-v, --version").enablePositionalOptions().option("-y, --yes", "assume yes to all prompts and skip interactive mode (also auto-detected in non-TTY environments)").option("-p, --plain", "plain output: no colors, no box-drawing, plain symbols \u2014 optimised for AI/pipe use").option("--cwd <path>", "project root to use instead of the current working directory").option("--ccd <path>", "config directory \u2014 where .crunes/config.json and local rune files live (default: --cwd)").option("--verbose", "print full error stack traces and other verbose output");
3401
3401
  program3.hook("preAction", (_thisCommand, actionCommand) => {
3402
3402
  const opts = { ...program3.opts(), ...actionCommand.opts() };
3403
3403
  configure({ plain: !!opts.plain, verbose: !!opts.verbose });
@@ -3417,7 +3417,7 @@ function buildProgram() {
3417
3417
  "after",
3418
3418
  '\nImportant: Global flags (e.g. --cwd) MUST appear before the "run" command.\n\nSyntax:\n [run-flags] <key>[-s s1,s2] [rune-args...]\n -b [run-flags] <key1>[-s s1] [rune-args1] + <key2>[-s s2] [rune-args2]\n\nCommand flags:\n -b, --batch enable batching multiple runes with +\n --format text|jsonl output format (default: text)\n --fail-fast stop on first error\n\nPer-rune bracket flags (inside key[...]):\n -s, --section s1,s2 filter output sections for this rune\n\nKey prefixes:\n project:name resolve from project config only\n plugin:name resolve directly from an enabled plugin\n name auto-resolve: project config first, then plugins\n\nFor rune argument documentation: crunes docs rune <key>'
3419
3419
  ).allowUnknownOption().passThroughOptions().action(async (args, _opts, _command) => {
3420
- const { handler, parseRunArgs } = await import("./chunks/run-CYGL3HTA.js");
3420
+ const { handler, parseRunArgs } = await import("./chunks/run-PXTN5GYH.js");
3421
3421
  const { segments, format, failFast, isBatch } = parseRunArgs(args);
3422
3422
  await handler({ segments, format, failFast, isBatch, projectRoot: projectRoot(), configRoot: configRoot() });
3423
3423
  });
@@ -3425,7 +3425,7 @@ function buildProgram() {
3425
3425
  "after",
3426
3426
  '\nImportant: Global flags (e.g. --cwd) MUST appear before the "repl" command.\n\nSyntax:\n [--format text|jsonl] <key>[-s s1,s2] [rune-args...]\n\nPer-rune bracket flags (inside key[...]):\n -s, --section s1,s2 filter output sections for this rune\n\nThe rune must export repl(args) and/or inputRepl(input).\nFor rune argument documentation: crunes docs rune <key>'
3427
3427
  ).allowUnknownOption().passThroughOptions().action(async (args, _opts, _command) => {
3428
- const { handler, parseReplArgs } = await import("./chunks/repl-PSADU3MJ.js");
3428
+ const { handler, parseReplArgs } = await import("./chunks/repl-GNA342PP.js");
3429
3429
  const { key, runeArgs, sections, format } = parseReplArgs(args);
3430
3430
  await handler({ key, runeArgs, sections, format, projectRoot: projectRoot(), configRoot: configRoot() });
3431
3431
  });
@@ -3434,11 +3434,11 @@ function buildProgram() {
3434
3434
  "after",
3435
3435
  "\n crunes docs rune index of every rune and its commands\n crunes docs rune <key> command index for one rune\n crunes docs rune <key> <cmd>... detail for one command path\n"
3436
3436
  ).addOption(new Option("--format <format>", "output format").choices(["text", "json"]).default("text")).action(async (key, path3, opts) => {
3437
- const { handler } = await import("./chunks/rune-OQX5EYSQ.js");
3437
+ const { handler } = await import("./chunks/rune-7YEZJTHK.js");
3438
3438
  await handler({ key, path: path3, format: opts.format, projectRoot: projectRoot(), configRoot: configRoot() });
3439
3439
  });
3440
3440
  helpGroup.command("utils [namespaces...]").description("Show function signatures and parameter docs for utils.* namespaces").addOption(new Option("--format <format>", "output format").choices(["text", "json"]).default("text")).action(async (namespaces, opts) => {
3441
- const { handler } = await import("./chunks/utils-DJ3BXOQC.js");
3441
+ const { handler } = await import("./chunks/utils-K7DAKWGS.js");
3442
3442
  await handler({ namespaces, format: opts.format });
3443
3443
  });
3444
3444
  helpGroup.command("globals").description("Show injected sandbox globals and ES2020 builtins available in rune scripts").addOption(new Option("--format <format>", "output format").choices(["text", "json"]).default("text")).action(async (opts) => {
@@ -3446,7 +3446,7 @@ function buildProgram() {
3446
3446
  await handler({ format: opts.format });
3447
3447
  });
3448
3448
  helpGroup.command("intro").description("Generate a comprehensive introduction to Crunes: rune anatomy, calling conventions, config, permissions and the full @utils API. Generic \u2014 for this project's own runes use `crunes list` and `crunes docs rune`").option("--out <path>", "output file path (defaults to stdout)").action(async (opts) => {
3449
- const { handler } = await import("./chunks/intro-PN7LT6ZG.js");
3449
+ const { handler } = await import("./chunks/intro-L5WBDL2P.js");
3450
3450
  await handler({ out: opts.out });
3451
3451
  });
3452
3452
  helpGroup.command("args").description("Show detailed documentation, conventions, and examples for the args(builder) export").action(async () => {
@@ -3482,18 +3482,18 @@ function buildProgram() {
3482
3482
  await handler();
3483
3483
  });
3484
3484
  program3.command("version").description("Print the installed version and check for updates").option("--no-check", "skip the npm update check").action(async (opts) => {
3485
- const { handler } = await import("./chunks/version-SBE7LQ5C.js");
3485
+ const { handler } = await import("./chunks/version-RZVOIMQG.js");
3486
3486
  await handler({ check: opts.check, plain: !!program3.opts().plain });
3487
3487
  });
3488
3488
  program3.command("doctor").description("Verify environment and project setup").option("-p, --plain", "plain output: no colors, no box-drawing, plain symbols \u2014 optimised for AI/pipe use").action(async () => {
3489
- const { handler } = await import("./chunks/doctor-SXKAEYUF.js");
3489
+ const { handler } = await import("./chunks/doctor-HLQE7TVE.js");
3490
3490
  await handler({ projectRoot: projectRoot() });
3491
3491
  });
3492
3492
  program3.command("bench [args...]").description("Time rune execution and report fast, ok, or slow.").addHelpText(
3493
3493
  "after",
3494
3494
  '\nImportant: Global flags (e.g. --cwd) MUST appear before the "bench" command.\n\nSyntax:\n [--runs <n>] [--warmup] <key>[--runs <n>] [--warmup] [-s s1,s2] [rune-args...]\n\nCommand flags:\n -b, --batch enable batching multiple runes with +\n --format text|jsonl output format (default: text)\n --fail-fast stop on first error\n --runs <n> default number of runs for all runes (default: 1)\n --warmup default warmup run for all runes\n\nPer-rune bracket flags (inside key[...]):\n --runs <n> override run count for this rune\n --warmup override warmup for this rune\n -s, --section s1,s2 filter output sections for this rune'
3495
3495
  ).allowUnknownOption().passThroughOptions().action(async (args, _opts, _command) => {
3496
- const { handler, parseBenchArgs } = await import("./chunks/benchmark-2TVN6HDF.js");
3496
+ const { handler, parseBenchArgs } = await import("./chunks/benchmark-HBIZCVFR.js");
3497
3497
  const parsed = parseBenchArgs(args);
3498
3498
  if (!parsed.segments[0]?.key) {
3499
3499
  const { output } = await import("./chunks/output-JVJFXQPF.js");
@@ -3508,11 +3508,11 @@ function buildProgram() {
3508
3508
  });
3509
3509
  const jobs = program3.command("job").description("Manage background jobs");
3510
3510
  jobs.command("list").description("List background jobs for the current project").action(async () => {
3511
- const { handler } = await import("./chunks/list-45SHVKXO.js");
3511
+ const { handler } = await import("./chunks/list-BJTV6SPK.js");
3512
3512
  await handler({ projectDir: projectRoot() });
3513
3513
  });
3514
3514
  jobs.command("kill <id>").description("Send SIGTERM to a background job and remove its record").action(async (id) => {
3515
- const { handler } = await import("./chunks/kill-Z7ZDY5MB.js");
3515
+ const { handler } = await import("./chunks/kill-IX7HNMVP.js");
3516
3516
  await handler({ id, projectDir: projectRoot() });
3517
3517
  });
3518
3518
  const shell = program3.command("shell").description("Inspect how commands are parsed and permission-checked");
@@ -3573,11 +3573,11 @@ function buildProgram() {
3573
3573
  });
3574
3574
  const plugin = program3.command("plugin").description("Manage rune plugins");
3575
3575
  plugin.command("install <source>").description("Install a plugin from a configured marketplace in the format <marketplace>@<plugin>").option("-g, --global", "enable in the global config (~/.crunes/config.json) instead of the project").action(async (source, opts) => {
3576
- const { handler } = await import("./chunks/install-FSJAC3CL.js");
3576
+ const { handler } = await import("./chunks/install-2K5BNXDO.js");
3577
3577
  await handler({ source, projectRoot: projectRoot(), configRoot: configRoot(), yes: !!program3.opts().yes, global: !!opts.global });
3578
3578
  });
3579
3579
  plugin.command("uninstall <plugin>").description("Uninstall an installed plugin").option("-g, --global", "also drop the plugin from the global config (~/.crunes/config.json)").action(async (name, opts) => {
3580
- const { handler } = await import("./chunks/uninstall-MSCIWDWV.js");
3580
+ const { handler } = await import("./chunks/uninstall-X75QTERD.js");
3581
3581
  await handler({ name, yes: !!program3.opts().yes, projectRoot: projectRoot(), configRoot: configRoot(), global: !!opts.global });
3582
3582
  });
3583
3583
  plugin.command("list").description("List installed plugins").addOption(new Option("--format <format>", "output format").choices(["text", "json"]).default("text")).option("-p, --plain", "plain output: no colors, no box-drawing, plain symbols \u2014 optimised for AI/pipe use").action(async (opts) => {
@@ -3585,7 +3585,7 @@ function buildProgram() {
3585
3585
  await handler({ format: opts.format, projectRoot: projectRoot() });
3586
3586
  });
3587
3587
  plugin.command("update [plugin]").description("Update one or all installed plugins").action(async (name) => {
3588
- const { handler } = await import("./chunks/update-IHCYA3JW.js");
3588
+ const { handler } = await import("./chunks/update-HHIDPHGX.js");
3589
3589
  await handler({ name, projectRoot: projectRoot(), configRoot: configRoot() });
3590
3590
  });
3591
3591
  plugin.command("trust <plugin> [rune]").description("Review a plugin's native runes \u2014 scripts that run outside the sandbox \u2014 and trust them to run").action(async (name, rune) => {
@@ -70087,6 +70087,105 @@ function sliceLines(content, from, to) {
70087
70087
  if (sliced.length === 0) return "";
70088
70088
  return sliced.join("\n") + (hadTrailing ? "\n" : "");
70089
70089
  }
70090
+ var RANGE_CHUNK_BYTES = 64 * 1024;
70091
+ async function readTailBytes(handle, size, count) {
70092
+ const chunks = [];
70093
+ let pos = size;
70094
+ let seen = 0;
70095
+ while (pos > 0) {
70096
+ const length = Math.min(RANGE_CHUNK_BYTES, pos);
70097
+ pos -= length;
70098
+ const chunk = Buffer.alloc(length);
70099
+ const { bytesRead } = await handle.read(chunk, 0, length, pos);
70100
+ if (bytesRead !== length) return null;
70101
+ let at = pos + length === size && chunk[length - 1] === 10 ? length - 1 : length;
70102
+ while (at > 0 && (at = chunk.lastIndexOf(10, at - 1)) !== -1) {
70103
+ if (++seen === count) {
70104
+ chunks.unshift(chunk.subarray(at + 1));
70105
+ return { bytes: Buffer.concat(chunks), whole: false };
70106
+ }
70107
+ }
70108
+ chunks.unshift(chunk);
70109
+ }
70110
+ return { bytes: Buffer.concat(chunks), whole: true };
70111
+ }
70112
+ async function readHeadBytes(handle, size, count) {
70113
+ const chunks = [];
70114
+ let pos = 0;
70115
+ let seen = 0;
70116
+ while (pos < size) {
70117
+ const length = Math.min(RANGE_CHUNK_BYTES, size - pos);
70118
+ const chunk = Buffer.alloc(length);
70119
+ const { bytesRead } = await handle.read(chunk, 0, length, pos);
70120
+ if (bytesRead !== length) return null;
70121
+ pos += length;
70122
+ let at = -1;
70123
+ while ((at = chunk.indexOf(10, at + 1)) !== -1) {
70124
+ if (++seen === count) {
70125
+ chunks.push(chunk.subarray(0, at));
70126
+ return { bytes: Buffer.concat(chunks), whole: false };
70127
+ }
70128
+ }
70129
+ chunks.push(chunk);
70130
+ }
70131
+ return { bytes: Buffer.concat(chunks), whole: true };
70132
+ }
70133
+ async function readEdgeLines(abs, from, to) {
70134
+ const isTail = Number.isInteger(from) && from < 0 && to == null;
70135
+ const isHead = Number.isInteger(to) && to >= 1 && (from == null || Number.isInteger(from) && from >= 1);
70136
+ if (!isTail && !isHead) return void 0;
70137
+ const handle = await fsPromises.open(abs, "r");
70138
+ try {
70139
+ const stat6 = await handle.stat();
70140
+ if (!stat6.isFile() || stat6.size === 0) return void 0;
70141
+ const part = isTail ? await readTailBytes(handle, stat6.size, -from) : await readHeadBytes(handle, stat6.size, to);
70142
+ if (!part) return void 0;
70143
+ if (part.whole) return sliceLines(stripBom(part.bytes.toString("utf8")), from, to);
70144
+ if (isTail) return part.bytes.toString("utf8");
70145
+ const last = Buffer.alloc(1);
70146
+ await handle.read(last, 0, 1, stat6.size - 1);
70147
+ const lines = stripBom(part.bytes.toString("utf8")).split("\n").slice(from == null ? 0 : from - 1);
70148
+ if (lines.length === 0) return "";
70149
+ return lines.join("\n") + (last[0] === 10 ? "\n" : "");
70150
+ } finally {
70151
+ await handle.close();
70152
+ }
70153
+ }
70154
+ var LINE_BATCH_BYTES = 256 * 1024;
70155
+ async function* readLineBatches(abs, needles) {
70156
+ let batch = [];
70157
+ let batchBytes = 0;
70158
+ let pending = [];
70159
+ let isFirst = true;
70160
+ const take = (line) => {
70161
+ if (isFirst) {
70162
+ isFirst = false;
70163
+ if (line[0] === 239 && line[1] === 187 && line[2] === 191) line = line.subarray(3);
70164
+ }
70165
+ if (line.at(-1) === 13) line = line.subarray(0, -1);
70166
+ if (needles && !needles.some((n) => line.includes(n))) return;
70167
+ batch.push(line.toString("utf8"));
70168
+ batchBytes += line.length + 1;
70169
+ };
70170
+ for await (const chunk of createReadStream(abs, { highWaterMark: 1024 * 1024 })) {
70171
+ let start = 0;
70172
+ let nl;
70173
+ while ((nl = chunk.indexOf(10, start)) !== -1) {
70174
+ const piece = chunk.subarray(start, nl);
70175
+ take(pending.length ? Buffer.concat([...pending, piece]) : piece);
70176
+ pending = [];
70177
+ start = nl + 1;
70178
+ if (batchBytes >= LINE_BATCH_BYTES) {
70179
+ yield batch;
70180
+ batch = [];
70181
+ batchBytes = 0;
70182
+ }
70183
+ }
70184
+ if (start < chunk.length) pending.push(chunk.subarray(start));
70185
+ }
70186
+ if (pending.length) take(Buffer.concat(pending));
70187
+ if (batch.length) yield batch;
70188
+ }
70090
70189
  function createFsUtils(dir, checkPermission, pluginDir = null, pluginId = null, storeDir = null) {
70091
70190
  const ctx = () => ({ dir, pluginDir, pluginId, storeDir });
70092
70191
  return {
@@ -70094,6 +70193,8 @@ function createFsUtils(dir, checkPermission, pluginDir = null, pluginId = null,
70094
70193
  const abs = resolvePath(relPath, ctx());
70095
70194
  if (checkPermission) checkPermission("fs.read", relPath);
70096
70195
  try {
70196
+ const edge = await readEdgeLines(abs, from, to);
70197
+ if (edge !== void 0) return edge;
70097
70198
  const content = stripBom(await fsPromises.readFile(abs, "utf8"));
70098
70199
  return sliceLines(content, from, to);
70099
70200
  } catch (err) {
@@ -70235,6 +70336,12 @@ function createFsUtils(dir, checkPermission, pluginDir = null, pluginId = null,
70235
70336
  if (checkPermission) checkPermission("fs.read", relPath);
70236
70337
  return createReadStream(abs);
70237
70338
  },
70339
+ readLinesIter(relPath, { contains } = {}) {
70340
+ if (contains != null && !Array.isArray(contains)) throw new TypeError("fs.readLinesStream: contains must be an array of strings");
70341
+ const abs = resolvePath(relPath, ctx());
70342
+ if (checkPermission) checkPermission("fs.read", relPath);
70343
+ return readLineBatches(abs, contains?.map((s) => Buffer.from(s, "utf8")) ?? null);
70344
+ },
70238
70345
  async appendStreamRef(relPath) {
70239
70346
  const abs = resolvePath(relPath, ctx());
70240
70347
  if (checkPermission) checkPermission("fs.write", relPath);
@@ -71509,7 +71616,7 @@ function createShellUtils(dir, checkPermission) {
71509
71616
  checkShellCommand(cmd, resolveShell(opts.shell).kind, checkPermission);
71510
71617
  return new ShellSession(cmd, { dir, ...opts, activeSessions });
71511
71618
  }
71512
- async function createShellJob(cmd, opts, { createJob, updateJobPid, jobStdoutPath, jobStderrPath, jobStdinPath, spawnedBy, projectDir: jobProjectDir }) {
71619
+ async function createShellJob(cmd, opts, { createJob, updateJobPid, jobStdoutPath, jobStderrPath, jobStdinPath, jobPgidPath, spawnedBy, projectDir: jobProjectDir }) {
71513
71620
  const repl = opts?.repl ?? false;
71514
71621
  checkShellCommand(cmd, resolveShell(opts?.shell).kind, checkPermission);
71515
71622
  const { id } = await createJob(null, {
@@ -71525,12 +71632,15 @@ function createShellUtils(dir, checkPermission) {
71525
71632
  if (repl) {
71526
71633
  const stdinLog = jobStdinPath(jobProjectDir, id);
71527
71634
  fs.writeFileSync(stdinLog, "");
71635
+ const jobShell = resolveShell(opts?.shell);
71636
+ const recordGroup = process.platform === "win32" && jobShell.kind !== "cmd";
71528
71637
  const wrapperEnv = {
71529
71638
  ...childEnv,
71530
- CRUNES_SHELL_CMD: cmd,
71639
+ CRUNES_SHELL_CMD: recordGroup ? `cat /proc/$$/pgid > "$CRUNES_JOB_PGID"; ${cmd}` : cmd,
71531
71640
  CRUNES_SHELL_CWD: jobProjectDir,
71532
71641
  CRUNES_STDIN_LOG: stdinLog,
71533
- CRUNES_SHELL_PATH: resolveShell(opts?.shell).path
71642
+ CRUNES_SHELL_PATH: jobShell.path,
71643
+ ...recordGroup ? { CRUNES_JOB_PGID: jobPgidPath(jobProjectDir, id) } : {}
71534
71644
  };
71535
71645
  const wrapper = `
71536
71646
  const {spawn}=require('child_process'),{openSync,closeSync,statSync,readSync}=require('fs')
@@ -75812,6 +75922,27 @@ function createTestRune() {
75812
75922
  }
75813
75923
  };
75814
75924
  }
75925
+ function createTestFs(fs5) {
75926
+ return {
75927
+ ...fs5,
75928
+ readLinesStream(path16, opts) {
75929
+ let iter;
75930
+ return new ReadableStream({
75931
+ async start() {
75932
+ iter = fs5.readLinesIter(path16, opts);
75933
+ },
75934
+ async pull(controller) {
75935
+ const { value, done } = await iter.next();
75936
+ if (done) controller.close();
75937
+ else for (const line of value) controller.enqueue(line);
75938
+ },
75939
+ async cancel() {
75940
+ await iter.return();
75941
+ }
75942
+ });
75943
+ }
75944
+ };
75945
+ }
75815
75946
  function setupCrunesTest({
75816
75947
  cwd = process.cwd(),
75817
75948
  projectRoot = cwd,
@@ -75843,6 +75974,7 @@ function setupCrunesTest({
75843
75974
  );
75844
75975
  const merged = {
75845
75976
  ...utils,
75977
+ fs: createTestFs(utils.fs),
75846
75978
  crypt: createTestCrypt(),
75847
75979
  codec: { ...codec_exports },
75848
75980
  time: { after: (ms) => new Promise((resolve6) => setTimeout(resolve6, ms)) },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkrymit/crunes-cli",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "CLI tool for querying crunes enrichers",
5
5
  "type": "module",
6
6
  "bin": {