clanka 0.3.1 → 0.4.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.
- package/dist/Acp.d.ts.map +1 -1
- package/dist/Acp.js +3 -0
- package/dist/Acp.js.map +1 -1
- package/dist/Acp.test.js +58 -0
- package/dist/Acp.test.js.map +1 -1
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +86 -8
- package/dist/Agent.js.map +1 -1
- package/dist/Agent.test.js +671 -0
- package/dist/Agent.test.js.map +1 -1
- package/dist/AgentExecutor.d.ts +5 -0
- package/dist/AgentExecutor.d.ts.map +1 -1
- package/dist/AgentExecutor.js +22 -0
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentOutput.d.ts +49 -4
- package/dist/AgentOutput.d.ts.map +1 -1
- package/dist/AgentOutput.js +45 -0
- package/dist/AgentOutput.js.map +1 -1
- package/dist/AgentSkills.d.ts +56 -0
- package/dist/AgentSkills.d.ts.map +1 -0
- package/dist/AgentSkills.js +126 -0
- package/dist/AgentSkills.js.map +1 -0
- package/dist/AgentSkills.test.d.ts +2 -0
- package/dist/AgentSkills.test.d.ts.map +1 -0
- package/dist/AgentSkills.test.js +356 -0
- package/dist/AgentSkills.test.js.map +1 -0
- package/dist/Codex.js +1 -1
- package/dist/Codex.js.map +1 -1
- package/dist/Compaction.d.ts +342 -0
- package/dist/Compaction.d.ts.map +1 -0
- package/dist/Compaction.js +566 -0
- package/dist/Compaction.js.map +1 -0
- package/dist/Compaction.test.d.ts +2 -0
- package/dist/Compaction.test.d.ts.map +1 -0
- package/dist/Compaction.test.js +576 -0
- package/dist/Compaction.test.js.map +1 -0
- package/dist/CompactionTransport.test.d.ts +2 -0
- package/dist/CompactionTransport.test.d.ts.map +1 -0
- package/dist/CompactionTransport.test.js +123 -0
- package/dist/CompactionTransport.test.js.map +1 -0
- package/dist/Copilot.d.ts.map +1 -1
- package/dist/Copilot.js +7 -2
- package/dist/Copilot.js.map +1 -1
- package/dist/OutputFormatter.d.ts.map +1 -1
- package/dist/OutputFormatter.js +9 -0
- package/dist/OutputFormatter.js.map +1 -1
- package/dist/cli.js +13 -4
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +85 -0
- package/src/Acp.ts +2 -0
- package/src/Agent.test.ts +994 -0
- package/src/Agent.ts +127 -6
- package/src/AgentExecutor.ts +27 -0
- package/src/AgentOutput.ts +58 -0
- package/src/AgentSkills.test.ts +652 -0
- package/src/AgentSkills.ts +155 -0
- package/src/Codex.ts +3 -1
- package/src/Compaction.test.ts +824 -0
- package/src/Compaction.ts +788 -0
- package/src/CompactionTransport.test.ts +228 -0
- package/src/Copilot.ts +8 -1
- package/src/OutputFormatter.ts +9 -0
- package/src/cli.ts +26 -5
- 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/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
|
)
|