opencode-fs-plugin 1.4.2 → 1.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.
@@ -0,0 +1,40 @@
1
+ /*
2
+ * SPDX-License-Identifier: EPL-2.0
3
+ * license-wizard managed-header v1 EPL-2.0 short 73897e75828f
4
+ */
5
+
6
+ import { Type, type Static } from "@sinclair/typebox";
7
+ import { collect, inputStream, lines } from "../core/stream.js";
8
+ import { textResult, type ToolSpec } from "../core/types.js";
9
+
10
+ const Schema = Type.Object(
11
+ {
12
+ paths: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { description: "Files to read. Omit to read stdin." })),
13
+ },
14
+ { additionalProperties: false },
15
+ );
16
+
17
+ type Input = Static<typeof Schema>;
18
+
19
+ export const tacTool: ToolSpec<Input> = {
20
+ name: "tac",
21
+ description: "Print files or stdin with the line order reversed.",
22
+ schema: Schema,
23
+ pipeable: "source",
24
+ mutates: false,
25
+ async run(ctx, input, io) {
26
+ const targets = [];
27
+ for (const requested of input.paths ?? []) {
28
+ const target = await ctx.sandbox.resolveFollow(requested);
29
+ targets.push({ requested, full: target.full, target });
30
+ }
31
+ if (targets.length > 0) {
32
+ await ctx.permission.assert(targets.map(({ target }) => ({ target, boundary: target.full })));
33
+ }
34
+ const data = await collect(inputStream(targets.map((target) => target.full), io.stdin));
35
+ const rows: string[] = [];
36
+ for await (const line of lines({ async *[Symbol.asyncIterator]() { yield data; } })) rows.push(line.text);
37
+ rows.reverse();
38
+ return textResult(rows.length > 0 ? `${rows.join("\n")}\n` : "", { lines: rows.length });
39
+ },
40
+ };
@@ -5,7 +5,7 @@
5
5
 
6
6
  import * as fs from "node:fs/promises";
7
7
  import { Type, type Static } from "@sinclair/typebox";
8
- import { FsError, fromErrno, isMissing } from "../core/errors.js";
8
+ import { FsError, fromErrno } from "../core/errors.js";
9
9
  import { textResult, type ToolSpec } from "../core/types.js";
10
10
 
11
11
  const Schema = Type.Object(
@@ -0,0 +1,45 @@
1
+ /*
2
+ * SPDX-License-Identifier: EPL-2.0
3
+ * license-wizard managed-header v1 EPL-2.0 short 73897e75828f
4
+ */
5
+
6
+ import * as os from "node:os";
7
+ import { Type, type Static } from "@sinclair/typebox";
8
+ import { textResult, type ToolSpec } from "../core/types.js";
9
+
10
+ const Schema = Type.Object(
11
+ {
12
+ kernel: Type.Optional(Type.Boolean({ description: "Print the kernel name (`-s`)." })),
13
+ nodename: Type.Optional(Type.Boolean({ description: "Print the hostname (`-n`)." })),
14
+ release: Type.Optional(Type.Boolean({ description: "Print the kernel release (`-r`)." })),
15
+ version: Type.Optional(Type.Boolean({ description: "Print the kernel version (`-v`)." })),
16
+ machine: Type.Optional(Type.Boolean({ description: "Print the machine hardware name (`-m`)." })),
17
+ },
18
+ { additionalProperties: false },
19
+ );
20
+
21
+ type Input = Static<typeof Schema>;
22
+
23
+ export const unameTool: ToolSpec<Input> = {
24
+ name: "uname",
25
+ description: "Print system information (`-s`, `-n`, `-r`, `-v`, `-m`); default is all fields.",
26
+ schema: Schema,
27
+ pipeable: false,
28
+ mutates: false,
29
+ async run(ctx, input) {
30
+ await ctx.permission.assertTrusted(["*"]);
31
+ const selected = [input.kernel, input.nodename, input.release, input.version, input.machine];
32
+ const all = selected.every((value) => value !== true);
33
+ return textResult(`${values(input, all).join(" ")}\n`, {});
34
+ },
35
+ };
36
+
37
+ function values(input: Input, all: boolean): string[] {
38
+ const output: string[] = [];
39
+ if (all || input.kernel === true) output.push(os.type());
40
+ if (all || input.nodename === true) output.push(os.hostname());
41
+ if (all || input.release === true) output.push(os.release());
42
+ if (all || input.version === true) output.push(os.version());
43
+ if (all || input.machine === true) output.push(os.machine());
44
+ return output;
45
+ }
@@ -0,0 +1,46 @@
1
+ /*
2
+ * SPDX-License-Identifier: EPL-2.0
3
+ * license-wizard managed-header v1 EPL-2.0 short 73897e75828f
4
+ */
5
+
6
+ import * as os from "node:os";
7
+ import { Type, type Static } from "@sinclair/typebox";
8
+ import { textResult, type ToolSpec } from "../core/types.js";
9
+
10
+ const Schema = Type.Object(
11
+ {
12
+ pretty: Type.Optional(Type.Boolean({ description: "Human-readable duration instead of seconds (`-p`)." })),
13
+ loadAverage: Type.Optional(Type.Boolean({ description: "Append the 1/5/15-minute load averages." })),
14
+ },
15
+ { additionalProperties: false },
16
+ );
17
+
18
+ type Input = Static<typeof Schema>;
19
+
20
+ export const uptimeTool: ToolSpec<Input> = {
21
+ name: "uptime",
22
+ description: "Print system uptime in seconds or human-readable form, optionally with load averages.",
23
+ schema: Schema,
24
+ pipeable: false,
25
+ mutates: false,
26
+ async run(ctx, input) {
27
+ await ctx.permission.assertTrusted(["*"]);
28
+ const seconds = os.uptime();
29
+ const base = input.pretty === true ? pretty(seconds) : `${seconds.toFixed(2)} seconds`;
30
+ const load = input.loadAverage === true
31
+ ? ` load average: ${os.loadavg().map((value) => value.toFixed(2)).join(", ")}`
32
+ : "";
33
+ return textResult(`${base}${load}\n`, { seconds, load: os.loadavg() });
34
+ },
35
+ };
36
+
37
+ export function pretty(seconds: number): string {
38
+ const days = Math.floor(seconds / 86_400);
39
+ const hours = Math.floor((seconds % 86_400) / 3_600);
40
+ const minutes = Math.floor((seconds % 3_600) / 60);
41
+ const parts: string[] = [];
42
+ if (days > 0) parts.push(`${days} day${days === 1 ? "" : "s"}`);
43
+ if (hours > 0) parts.push(`${hours} hour${hours === 1 ? "" : "s"}`);
44
+ parts.push(`${minutes} minute${minutes === 1 ? "" : "s"}`);
45
+ return `up ${parts.join(", ")}`;
46
+ }