clanka 0.10.0 → 0.10.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "clanka",
3
3
  "type": "module",
4
- "version": "0.10.0",
4
+ "version": "0.10.1",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
package/src/Agent.ts CHANGED
@@ -1390,6 +1390,7 @@ const [files, content] = await Promise.all([
1390
1390
  path: "package.json",
1391
1391
  startLine: 1,
1392
1392
  endLine: 10,
1393
+ lineNumbers: false,
1393
1394
  })
1394
1395
  ])
1395
1396
  console.log("files:", files)
package/src/AgentTools.ts CHANGED
@@ -287,6 +287,10 @@ export const AgentTools = Toolkit.make(
287
287
  path: Schema.String,
288
288
  startLine: Schema.optional(Schema.Number),
289
289
  endLine: Schema.optional(Schema.Number),
290
+ lineNumbers: Schema.optional(Schema.Boolean).annotate({
291
+ documentation:
292
+ "Prefix text lines with their line numbers (default: true)",
293
+ }),
290
294
  }),
291
295
  success: Schema.NullOr(Schema.String),
292
296
  dependencies: [CurrentDirectory, ImageAttacher],
@@ -603,6 +607,14 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
603
607
  )
604
608
  }
605
609
  return yield* Stream.runCollect(stream).pipe(
610
+ Effect.map((lines) =>
611
+ options.lineNumbers === false
612
+ ? lines
613
+ : lines.map(
614
+ (line, index) =>
615
+ `${(options.startLine ?? 1) + index}: ${line}`,
616
+ ),
617
+ ),
606
618
  Effect.map(Array.join("\n")),
607
619
  Effect.catchReason("PlatformError", "NotFound", () =>
608
620
  Effect.succeed(null),
@@ -0,0 +1,61 @@
1
+ import { assert, describe, it } from "@effect/vitest"
2
+ import * as NodeHttpClient from "@effect/platform-node/NodeHttpClient"
3
+ import * as NodeServices from "@effect/platform-node/NodeServices"
4
+ import * as Effect from "effect/Effect"
5
+ import * as FileSystem from "effect/FileSystem"
6
+ import * as Layer from "effect/Layer"
7
+ import * as Path from "effect/Path"
8
+ import * as AgentExecutor from "./AgentExecutor.ts"
9
+
10
+ describe("readFile line numbers", () => {
11
+ const cases = [
12
+ {
13
+ name: "numbers lines by default",
14
+ options: {},
15
+ expected: "1: alpha\n2: beta\n3: gamma\n4: delta",
16
+ },
17
+ {
18
+ name: "numbers lines when explicitly enabled",
19
+ options: { lineNumbers: true },
20
+ expected: "1: alpha\n2: beta\n3: gamma\n4: delta",
21
+ },
22
+ {
23
+ name: "returns unnumbered text when disabled",
24
+ options: { lineNumbers: false },
25
+ expected: "alpha\nbeta\ngamma\ndelta",
26
+ },
27
+ {
28
+ name: "preserves original line numbers for a selected range",
29
+ options: { lineNumbers: true, startLine: 2, endLine: 3 },
30
+ expected: "2: beta\n3: gamma",
31
+ },
32
+ ]
33
+
34
+ for (const { name, options, expected } of cases) {
35
+ it.effect(name, () =>
36
+ Effect.gen(function* () {
37
+ const fs = yield* FileSystem.FileSystem
38
+ const path = yield* Path.Path
39
+ const project = yield* fs.makeTempDirectoryScoped()
40
+ yield* fs.writeFileString(
41
+ path.join(project, "sample.txt"),
42
+ "alpha\nbeta\ngamma\ndelta",
43
+ )
44
+ const result = yield* Effect.gen(function* () {
45
+ const executor = yield* AgentExecutor.AgentExecutor
46
+ return yield* executor.executeUnsafe({
47
+ tool: "readFile",
48
+ params: { path: "sample.txt", ...options },
49
+ })
50
+ }).pipe(
51
+ Effect.provide(
52
+ AgentExecutor.layerLocal({ directory: project }).pipe(
53
+ Layer.provide(NodeHttpClient.layerUndici),
54
+ ),
55
+ ),
56
+ )
57
+ assert.strictEqual(result, expected)
58
+ }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
59
+ )
60
+ }
61
+ })