clanka 0.3.1 → 0.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.
Files changed (75) hide show
  1. package/dist/Acp.d.ts.map +1 -1
  2. package/dist/Acp.js +3 -0
  3. package/dist/Acp.js.map +1 -1
  4. package/dist/Acp.test.js +58 -0
  5. package/dist/Acp.test.js.map +1 -1
  6. package/dist/Agent.d.ts +2 -2
  7. package/dist/Agent.d.ts.map +1 -1
  8. package/dist/Agent.js +86 -8
  9. package/dist/Agent.js.map +1 -1
  10. package/dist/Agent.test.js +671 -0
  11. package/dist/Agent.test.js.map +1 -1
  12. package/dist/AgentExecutor.d.ts +15 -4
  13. package/dist/AgentExecutor.d.ts.map +1 -1
  14. package/dist/AgentExecutor.js +43 -7
  15. package/dist/AgentExecutor.js.map +1 -1
  16. package/dist/AgentOutput.d.ts +49 -4
  17. package/dist/AgentOutput.d.ts.map +1 -1
  18. package/dist/AgentOutput.js +45 -0
  19. package/dist/AgentOutput.js.map +1 -1
  20. package/dist/AgentSkills.d.ts +56 -0
  21. package/dist/AgentSkills.d.ts.map +1 -0
  22. package/dist/AgentSkills.js +126 -0
  23. package/dist/AgentSkills.js.map +1 -0
  24. package/dist/AgentSkills.test.d.ts +2 -0
  25. package/dist/AgentSkills.test.d.ts.map +1 -0
  26. package/dist/AgentSkills.test.js +356 -0
  27. package/dist/AgentSkills.test.js.map +1 -0
  28. package/dist/AgentTools.d.ts +32 -1
  29. package/dist/AgentTools.d.ts.map +1 -1
  30. package/dist/AgentTools.js +26 -10
  31. package/dist/AgentTools.js.map +1 -1
  32. package/dist/Codex.js +1 -1
  33. package/dist/Codex.js.map +1 -1
  34. package/dist/Compaction.d.ts +342 -0
  35. package/dist/Compaction.d.ts.map +1 -0
  36. package/dist/Compaction.js +566 -0
  37. package/dist/Compaction.js.map +1 -0
  38. package/dist/Compaction.test.d.ts +2 -0
  39. package/dist/Compaction.test.d.ts.map +1 -0
  40. package/dist/Compaction.test.js +576 -0
  41. package/dist/Compaction.test.js.map +1 -0
  42. package/dist/CompactionTransport.test.d.ts +2 -0
  43. package/dist/CompactionTransport.test.d.ts.map +1 -0
  44. package/dist/CompactionTransport.test.js +123 -0
  45. package/dist/CompactionTransport.test.js.map +1 -0
  46. package/dist/Copilot.d.ts.map +1 -1
  47. package/dist/Copilot.js +7 -2
  48. package/dist/Copilot.js.map +1 -1
  49. package/dist/OutputFormatter.d.ts.map +1 -1
  50. package/dist/OutputFormatter.js +9 -0
  51. package/dist/OutputFormatter.js.map +1 -1
  52. package/dist/cli.js +13 -4
  53. package/dist/cli.js.map +1 -1
  54. package/dist/index.d.ts +5 -0
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +5 -0
  57. package/dist/index.js.map +1 -1
  58. package/package.json +1 -1
  59. package/src/Acp.test.ts +85 -0
  60. package/src/Acp.ts +2 -0
  61. package/src/Agent.test.ts +994 -0
  62. package/src/Agent.ts +129 -7
  63. package/src/AgentExecutor.ts +76 -32
  64. package/src/AgentOutput.ts +58 -0
  65. package/src/AgentSkills.test.ts +652 -0
  66. package/src/AgentSkills.ts +155 -0
  67. package/src/AgentTools.ts +34 -10
  68. package/src/Codex.ts +3 -1
  69. package/src/Compaction.test.ts +824 -0
  70. package/src/Compaction.ts +788 -0
  71. package/src/CompactionTransport.test.ts +228 -0
  72. package/src/Copilot.ts +8 -1
  73. package/src/OutputFormatter.ts +9 -0
  74. package/src/cli.ts +26 -5
  75. package/src/index.ts +6 -0
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Discover Agent Skills (https://agentskills.io/specification) on the executor.
3
+ *
4
+ * @since 1.0.0
5
+ */
6
+ import * as Effect from "effect/Effect"
7
+ import * as FileSystem from "effect/FileSystem"
8
+ import * as Option from "effect/Option"
9
+ import * as Path from "effect/Path"
10
+ import * as Predicate from "effect/Predicate"
11
+ import * as Schema from "effect/Schema"
12
+ import * as Yaml from "effect/unstable/encoding/Yaml"
13
+
14
+ /**
15
+ * @since 1.0.0
16
+ * @category Models
17
+ */
18
+ export const SkillSource = Schema.Literals(["project", "user"])
19
+
20
+ /**
21
+ * @since 1.0.0
22
+ * @category Models
23
+ */
24
+ export type SkillSource = typeof SkillSource.Type
25
+
26
+ /**
27
+ * Skill metadata with an absolute executor-side `SKILL.md` path.
28
+ *
29
+ * @since 1.0.0
30
+ * @category Models
31
+ */
32
+ export class Skill extends Schema.Class<Skill>("Skill")({
33
+ name: Schema.String,
34
+ description: Schema.String,
35
+ location: Schema.String,
36
+ source: SkillSource,
37
+ }) {}
38
+
39
+ /**
40
+ * Scan project and user `.agents/skills/<dir>/SKILL.md` files.
41
+ *
42
+ * Project names override user names; the first name wins within each scope.
43
+ * Skip unreadable files, invalid frontmatter and missing or empty descriptions.
44
+ *
45
+ * @since 1.0.0
46
+ * @category Discovery
47
+ */
48
+ export const discover: (options: {
49
+ readonly directory: string
50
+ readonly homeDirectory: Option.Option<string>
51
+ }) => Effect.Effect<
52
+ ReadonlyArray<Skill>,
53
+ never,
54
+ FileSystem.FileSystem | Path.Path
55
+ > = Effect.fnUntraced(function* (options) {
56
+ const fs = yield* FileSystem.FileSystem
57
+ const path = yield* Path.Path
58
+
59
+ const roots: Array<{ readonly root: string; readonly source: SkillSource }> =
60
+ [{ root: options.directory, source: "project" }]
61
+ if (Option.isSome(options.homeDirectory)) {
62
+ roots.push({ root: options.homeDirectory.value, source: "user" })
63
+ }
64
+
65
+ const byName = new Map<string, Skill>()
66
+ for (const { root, source } of roots) {
67
+ const skillsDir = path.resolve(root, ".agents", "skills")
68
+ const entries = yield* fs
69
+ .readDirectory(skillsDir)
70
+ .pipe(Effect.orElseSucceed(() => []))
71
+ entries.sort()
72
+ for (const entry of entries) {
73
+ const location = path.join(skillsDir, entry, "SKILL.md")
74
+ const content = yield* Effect.option(
75
+ fs.stat(location).pipe(
76
+ Effect.filterOrFail((info) => info.type === "File"),
77
+ Effect.andThen(() => fs.readFileString(location)),
78
+ ),
79
+ )
80
+ if (Option.isNone(content)) continue
81
+ const frontmatter = parseFrontmatter(content.value)
82
+ if (Option.isNone(frontmatter)) continue
83
+ const description = singleLine(frontmatter.value.description)
84
+ if (description === "") continue
85
+ const name = Predicate.isString(frontmatter.value.name)
86
+ ? singleLine(frontmatter.value.name) || singleLine(entry)
87
+ : singleLine(entry)
88
+ if (byName.has(name)) continue
89
+ byName.set(name, new Skill({ name, description, location, source }))
90
+ }
91
+ }
92
+
93
+ return Array.from(byName.values())
94
+ })
95
+
96
+ /**
97
+ * Render the skills prompt section, or `None` for an empty catalog.
98
+ *
99
+ * @since 1.0.0
100
+ * @category Rendering
101
+ */
102
+ export const renderCatalog = (
103
+ skills: ReadonlyArray<Skill>,
104
+ ): Option.Option<string> => {
105
+ if (skills.length === 0) return Option.none()
106
+ const entries = skills
107
+ .map(
108
+ (skill) => `- ${skill.name}: ${skill.description}
109
+ location: ${renderLocation(skill.location)}`,
110
+ )
111
+ .join("\n")
112
+ return Option.some(`# Skills
113
+
114
+ The following skills are available. Each one is a folder with instructions for
115
+ a specific kind of task.
116
+
117
+ When a task matches a skill's description, use "readFile" to read the file at
118
+ its location BEFORE proceeding, then follow the instructions it contains.
119
+ Double-quoted locations are JSON strings; decode them to get the exact file
120
+ path. Unquoted locations are literal paths.
121
+ Relative paths mentioned inside a skill (such as "scripts/" or "references/")
122
+ are relative to the skill's directory (the parent of SKILL.md); use absolute
123
+ paths when accessing them.
124
+
125
+ ${entries}`)
126
+ }
127
+
128
+ const Frontmatter = Schema.Struct({
129
+ name: Schema.optional(Schema.Unknown),
130
+ description: Schema.String,
131
+ })
132
+
133
+ const decodeFrontmatter = Schema.decodeUnknownOption(Frontmatter)
134
+
135
+ const frontmatterPattern = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/
136
+
137
+ // Validate all frontmatter, including fields omitted from the catalog.
138
+ const parseFrontmatter = (
139
+ content: string,
140
+ ): Option.Option<typeof Frontmatter.Type> => {
141
+ const match = frontmatterPattern.exec(content)
142
+ if (match === null) return Option.none()
143
+ try {
144
+ return decodeFrontmatter(Yaml.parse(match[1]!))
145
+ } catch {
146
+ return Option.none()
147
+ }
148
+ }
149
+
150
+ const singleLine = (value: string): string => value.replace(/\s+/g, " ").trim()
151
+
152
+ const renderLocation = (location: string): string => {
153
+ const encoded = JSON.stringify(location)
154
+ return encoded.slice(1, -1) === location ? location : encoded
155
+ }
package/src/AgentTools.ts CHANGED
@@ -32,6 +32,15 @@ export class CurrentDirectory extends Context.Service<
32
32
  string
33
33
  >()("clanka/AgentTools/CurrentDirectory") {}
34
34
 
35
+ /**
36
+ * @since 1.0.0
37
+ * @category Context
38
+ */
39
+ export class DirectoryChanger extends Context.Service<
40
+ DirectoryChanger,
41
+ (directory: string) => Effect.Effect<string>
42
+ >()("clanka/AgentTools/DirectoryChanger") {}
43
+
35
44
  /**
36
45
  * @since 1.0.0
37
46
  * @category Context
@@ -57,6 +66,7 @@ export class SubagentExecutor extends Context.Service<
57
66
  export const makeContextNoop = (cwd?: string) =>
58
67
  SubagentExecutor.context(() => Effect.die("Not implemented")).pipe(
59
68
  Context.add(CurrentDirectory, cwd ?? "/"),
69
+ Context.add(DirectoryChanger, () => Effect.die("Not implemented")),
60
70
  Context.add(TaskCompleter, () => Effect.void),
61
71
  )
62
72
 
@@ -73,6 +83,13 @@ class TodoItem extends Schema.Opaque<TodoItem>()(
73
83
  * @category Toolkit
74
84
  */
75
85
  export const AgentTools = Toolkit.make(
86
+ Tool.make("changeDirectory", {
87
+ description:
88
+ "Change the executor's working directory to an existing directory and return its absolute path. Relative paths resolve from the current directory without shell expansion. Await this before dependent tools. The change persists across scripts and is shared with delegates using this executor. Startup AGENTS.md, skills, and the semantic-search index root remain fixed. Navigation does not survive a session reload.",
89
+ parameters: Schema.String.annotate({ identifier: "directory" }),
90
+ success: Schema.String,
91
+ dependencies: [DirectoryChanger],
92
+ }),
76
93
  Tool.make("readFile", {
77
94
  description:
78
95
  "Read a file and optionally filter the lines to return. Returns null if the file doesn't exist.",
@@ -284,6 +301,15 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
284
301
  }, Effect.scoped)
285
302
 
286
303
  return AgentToolsWithSearch.of({
304
+ changeDirectory: Effect.fn("AgentTools.changeDirectory")(
305
+ function* (directory) {
306
+ yield* Effect.logInfo(`Calling "changeDirectory"`).pipe(
307
+ Effect.annotateLogs({ directory }),
308
+ )
309
+ const changeDirectory = yield* DirectoryChanger
310
+ return yield* changeDirectory(directory)
311
+ },
312
+ ),
287
313
  readFile: Effect.fn("AgentTools.readFile")(function* (options) {
288
314
  yield* Effect.logInfo(`Calling "readFile"`).pipe(
289
315
  Effect.annotateLogs(options),
@@ -321,7 +347,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
321
347
  recursive: true,
322
348
  })
323
349
  yield* fs.writeFileString(path, options.content)
324
- yield* SemanticSearch.maybeUpdateFile(pathService.relative(cwd, path))
350
+ yield* SemanticSearch.maybeUpdateFile(path)
325
351
  }, Effect.orDie),
326
352
  removeFile: Effect.fn("AgentTools.removeFile")(function* (path) {
327
353
  yield* Effect.logInfo(`Calling "removeFile"`).pipe(
@@ -330,9 +356,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
330
356
  const cwd = yield* CurrentDirectory
331
357
  const absolutePath = pathService.resolve(cwd, path)
332
358
  yield* fs.remove(absolutePath, { force: true })
333
- yield* SemanticSearch.maybeRemoveFile(
334
- pathService.relative(cwd, absolutePath),
335
- )
359
+ yield* SemanticSearch.maybeRemoveFile(absolutePath)
336
360
  }, Effect.orDie),
337
361
  renameFile: Effect.fn("AgentTools.renameFile")(function* (options) {
338
362
  yield* Effect.logInfo(`Calling "renameFile"`).pipe(
@@ -345,8 +369,8 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
345
369
  recursive: true,
346
370
  })
347
371
  yield* fs.rename(from, to)
348
- yield* SemanticSearch.maybeRemoveFile(pathService.relative(cwd, from))
349
- yield* SemanticSearch.maybeUpdateFile(pathService.relative(cwd, to))
372
+ yield* SemanticSearch.maybeRemoveFile(from)
373
+ yield* SemanticSearch.maybeUpdateFile(to)
350
374
  }, Effect.orDie),
351
375
  ls: Effect.fn("AgentTools.ls")(function* (directory) {
352
376
  yield* Effect.logInfo(`Calling "ls"`).pipe(
@@ -597,7 +621,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
597
621
  recursive: true,
598
622
  })
599
623
  yield* fs.writeFileString(step.path, step.next)
600
- yield* SemanticSearch.maybeUpdateFile(rel(step.path))
624
+ yield* SemanticSearch.maybeUpdateFile(step.path)
601
625
  break
602
626
  }
603
627
  case "move": {
@@ -606,13 +630,13 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
606
630
  })
607
631
  yield* fs.writeFileString(step.movePath, step.next)
608
632
  yield* fs.remove(step.path)
609
- yield* SemanticSearch.maybeRemoveFile(rel(step.path))
610
- yield* SemanticSearch.maybeUpdateFile(rel(step.movePath))
633
+ yield* SemanticSearch.maybeRemoveFile(step.path)
634
+ yield* SemanticSearch.maybeUpdateFile(step.movePath)
611
635
  break
612
636
  }
613
637
  case "delete": {
614
638
  yield* fs.remove(step.path)
615
- yield* SemanticSearch.maybeRemoveFile(rel(step.path))
639
+ yield* SemanticSearch.maybeRemoveFile(step.path)
616
640
  break
617
641
  }
618
642
  }
package/src/Codex.ts CHANGED
@@ -67,7 +67,7 @@ const layerModel = (
67
67
  OpenAiLanguageModel.layer({
68
68
  model,
69
69
  config: {
70
- ...Struct.omit(options ?? {}, ["reasoning"]),
70
+ ...Struct.omit(options ?? {}, ["reasoning", "systemPromptTransform"]),
71
71
  store: false,
72
72
  reasoning: {
73
73
  effort: "medium",
@@ -83,5 +83,7 @@ const layerModel = (
83
83
  instructions: system,
84
84
  }),
85
85
  }),
86
+ // No Compaction.SummarizerTransform: Codex rejects max_output_tokens,
87
+ // so compaction summaries have no configured output-token cap.
86
88
  ),
87
89
  )